From 080f55e2537f906124fd967c58e41342ad0b4617 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 25 Jun 2021 15:05:05 +0200 Subject: [PATCH] JPERF-273: Expose NFS or Samba shared homes for DC --- CHANGELOG.md | 1 + .../jira/instance/DefaultClusterProperties.kt | 18 +++++++++++++++ .../api/jira/instance/JiraDataCenterPlan.kt | 23 ++++++++++++++----- .../NfsSharedHome.kt} | 14 +++++------ .../SambaSharedHome.kt} | 14 +++++------ .../jira/instance/ClusterProperties.kt | 13 +++++++++++ .../jira/sharedhome/SharedHomeProperty.kt | 14 +++++++++++ .../api/jira/instance/JiraDataCenterPlanIT.kt | 15 ++++++++---- 8 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{instance/NfsSharedHomeHook.kt => sharedhome/NfsSharedHome.kt} (86%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{instance/SambaSharedHomeHook.kt => sharedhome/SambaSharedHome.kt} (89%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/instance/ClusterProperties.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/sharedhome/SharedHomeProperty.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a0a81e..42eb669f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Fix [JPERF-273]: - Hook into Jira start via `PreStartHooks` and `PostStartHooks`. - Let hooks insert new hooks. - Locate and download any logs, charts, profiles and other reports via `Report` (rather than hardcoding the paths). +- Expose preset `NfsSharedHome` or `SambaSharedHome` for Data Center. [JPERF-273]: https://ecosystem.atlassian.net/browse/JPERF-273 diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt new file mode 100644 index 00000000..1e2bbbb3 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt @@ -0,0 +1,18 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.instance + +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.report.Reports +import com.atlassian.performance.tools.infrastructure.jira.instance.ClusterProperties +import com.atlassian.performance.tools.ssh.api.SshConnection + +class DefaultClusterProperties : PostInstallHook { + + override fun call(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks, reports: Reports) { + ClusterProperties(jira).apply { + set("jira.node.id", jira.host.name, ssh) + set("ehcache.object.port", "40011", ssh) + } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlan.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlan.kt index 0d1d926c..2e2057a2 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlan.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlan.kt @@ -2,10 +2,12 @@ package com.atlassian.performance.tools.infrastructure.api.jira.instance import com.atlassian.performance.tools.infrastructure.api.Infrastructure import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.node.JiraNode import com.atlassian.performance.tools.infrastructure.api.jira.node.JiraNodePlan import com.atlassian.performance.tools.infrastructure.api.jira.report.Reports import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira +import com.atlassian.performance.tools.infrastructure.api.loadbalancer.ApacheProxyPlan import com.atlassian.performance.tools.infrastructure.api.loadbalancer.LoadBalancer import com.atlassian.performance.tools.infrastructure.api.loadbalancer.LoadBalancerPlan import java.net.URI @@ -13,7 +15,7 @@ import java.time.Duration import kotlin.streams.asStream import kotlin.streams.toList -class JiraDataCenterPlan constructor( +class JiraDataCenterPlan private constructor( private val nodePlans: List, private val instanceHooks: PreInstanceHooks, private val balancerPlan: LoadBalancerPlan, @@ -74,10 +76,19 @@ class JiraDataCenterPlan constructor( class Builder( private var infrastructure: Infrastructure ) { - private var nodePlans: List = listOf(1, 2).map { JiraNodePlan.Builder().build() } -// TODO private var instanceHooks: PreInstanceHooks = -// PreInstanceHooks(listOf(1..2).map { PreInstallHooks.default() }) // TODO two lists in sync? gotta be a better way -// -// fun build(): Supplier = JiraDataCenterPlan(nodePlans, infrastructure) + private var nodePlans: List = listOf(1, 2).map { + JiraNodePlan.Builder() + .hooks(PreInstallHooks.default().apply { postInstall.insert(DefaultClusterProperties()) }) + .build() + } + private var instanceHooks: PreInstanceHooks = PreInstanceHooks.default() + private var balancerPlan: LoadBalancerPlan = ApacheProxyPlan(infrastructure) + + fun infrastructure(infrastructure: Infrastructure) = apply { this.infrastructure = infrastructure } + fun nodePlans(nodePlans: List) = apply { this.nodePlans = nodePlans } + fun instanceHooks(instanceHooks: PreInstanceHooks) = apply { this.instanceHooks = instanceHooks } + fun balancerPlan(balancerPlan: LoadBalancerPlan) = apply { this.balancerPlan = balancerPlan } + + fun build(): JiraInstancePlan = JiraDataCenterPlan(nodePlans, instanceHooks, balancerPlan, infrastructure) } } \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/NfsSharedHomeHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/sharedhome/NfsSharedHome.kt similarity index 86% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/NfsSharedHomeHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/sharedhome/NfsSharedHome.kt index 467af37c..cded91ed 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/NfsSharedHomeHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/sharedhome/NfsSharedHome.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.instance +package com.atlassian.performance.tools.infrastructure.api.jira.sharedhome import com.atlassian.performance.tools.infrastructure.api.Infrastructure import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource @@ -6,12 +6,15 @@ import com.atlassian.performance.tools.infrastructure.api.jira.install.Installed import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.instance.PreInstanceHook +import com.atlassian.performance.tools.infrastructure.api.jira.instance.PreInstanceHooks import com.atlassian.performance.tools.infrastructure.api.jira.report.Reports import com.atlassian.performance.tools.infrastructure.api.os.RemotePath import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.infrastructure.jira.sharedhome.SharedHomeProperty import com.atlassian.performance.tools.ssh.api.SshConnection -internal class NfsSharedHomeHook( +class NfsSharedHome( private val jiraHomeSource: JiraHomeSource, private val infrastructure: Infrastructure ) : PreInstanceHook { @@ -52,11 +55,8 @@ internal class NfsSharedHomeHook( ssh.execute("mkdir -p $mountTarget") ssh.execute("sudo mount -o soft,intr,rsize=8192,wsize=8192 $mountSource $mountTarget") ssh.execute("sudo chown ubuntu:ubuntu $mountTarget") - val mountedPath = "`realpath $mountTarget`" - val jiraHome = jira.home.path - ssh.execute("echo ehcache.object.port = 40011 >> $jiraHome/cluster.properties") - ssh.execute("echo jira.node.id = ${jira.host.name} >> $jiraHome/cluster.properties") - ssh.execute("echo jira.shared.home = $mountedPath >> $jiraHome/cluster.properties") + val mounted = "`realpath $mountTarget`" + SharedHomeProperty(jira).set(mounted, ssh) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/SambaSharedHomeHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/sharedhome/SambaSharedHome.kt similarity index 89% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/SambaSharedHomeHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/sharedhome/SambaSharedHome.kt index 4406fe05..f98a4757 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/SambaSharedHomeHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/sharedhome/SambaSharedHome.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.instance +package com.atlassian.performance.tools.infrastructure.api.jira.sharedhome import com.atlassian.performance.tools.infrastructure.api.Infrastructure import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource @@ -7,12 +7,15 @@ import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpHost import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.instance.PreInstanceHook +import com.atlassian.performance.tools.infrastructure.api.jira.instance.PreInstanceHooks import com.atlassian.performance.tools.infrastructure.api.jira.report.Reports import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.infrastructure.jira.sharedhome.SharedHomeProperty import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* -internal class SambaSharedHomeHook( +class SambaSharedHome( private val jiraHomeSource: JiraHomeSource, private val infrastructure: Infrastructure ) : PreInstanceHook { @@ -76,11 +79,8 @@ internal class SambaSharedHomeHook( val localUser = ssh.execute("whoami").output.trim() ssh.execute("sudo chown $localUser:$localUser $mountTarget") ssh.execute("sudo mount -t cifs -o $credentials $mountSource $mountTarget") - val sharedHome = "`realpath $mountTarget`" - val nodeHome = jira.home.path - ssh.execute("echo ehcache.object.port = 40011 >> $nodeHome/cluster.properties") - ssh.execute("echo jira.node.id = ${jira.host.name} >> $nodeHome/cluster.properties") - ssh.execute("echo jira.shared.home = $sharedHome >> $nodeHome/cluster.properties") + val mounted = "`realpath $mountTarget`" + SharedHomeProperty(jira).set(mounted, ssh) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/instance/ClusterProperties.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/instance/ClusterProperties.kt new file mode 100644 index 00000000..f0a4f310 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/instance/ClusterProperties.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.jira.instance + +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.ssh.api.SshConnection + +internal class ClusterProperties( + private val jira: InstalledJira +) { + + fun set(key: String, value: String, ssh: SshConnection) { + ssh.execute("echo '$key = $value' >> ${jira.home.path}/cluster.properties") + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/sharedhome/SharedHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/sharedhome/SharedHomeProperty.kt new file mode 100644 index 00000000..d6bda38b --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/sharedhome/SharedHomeProperty.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.jira.sharedhome + +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.jira.instance.ClusterProperties +import com.atlassian.performance.tools.ssh.api.SshConnection + +internal class SharedHomeProperty( + private val jira: InstalledJira +) { + + fun set(mounted: String, ssh: SshConnection) { + ClusterProperties(jira).set("jira.shared.home", mounted, ssh) + } +} diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt index 3d9dcca7..834b39d7 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt @@ -9,6 +9,7 @@ import com.atlassian.performance.tools.infrastructure.api.jira.install.ParallelI import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.node.JiraNodePlan import com.atlassian.performance.tools.infrastructure.api.jira.report.Reports +import com.atlassian.performance.tools.infrastructure.api.jira.sharedhome.SambaSharedHome import com.atlassian.performance.tools.infrastructure.api.jira.start.JiraLaunchScript import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PostStartHook @@ -59,9 +60,12 @@ class JiraDataCenterPlanIT { } val instanceHooks = PreInstanceHooks.default() .also { Datasets.JiraSevenDataset.hookMysql(it, infrastructure) } - .also { it.insert(SambaSharedHomeHook(jiraHomeSource, infrastructure)) } - val balancerPlan = ApacheProxyPlan(infrastructure) - val dcPlan = JiraDataCenterPlan(nodePlans, instanceHooks, balancerPlan, infrastructure) + .also { it.insert(SambaSharedHome(jiraHomeSource, infrastructure)) } + val dcPlan = JiraDataCenterPlan.Builder(infrastructure) + .nodePlans(nodePlans) + .instanceHooks(instanceHooks) + .balancerPlan(ApacheProxyPlan(infrastructure)) + .build() // when val dataCenter = dcPlan.materialize() @@ -106,8 +110,9 @@ class JiraDataCenterPlanIT { .hooks(PreInstallHooks.default().also { it.postStart.insert(FailingHook()) }) .build() } - val balancerPlan = ApacheProxyPlan(infrastructure) - val dcPlan = JiraDataCenterPlan(nodePlans, PreInstanceHooks.default(), balancerPlan, infrastructure) + val dcPlan = JiraDataCenterPlan.Builder(infrastructure) + .nodePlans(nodePlans) + .build() // when val thrown = catchThrowable {