Skip to content

Commit

Permalink
JPERF-273: Expose NFS or Samba shared homes for DC
Browse files Browse the repository at this point in the history
  • Loading branch information
dagguh committed Jun 25, 2021
1 parent a7a55f3 commit 080f55e
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ 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
import java.time.Duration
import kotlin.streams.asStream
import kotlin.streams.toList

class JiraDataCenterPlan constructor(
class JiraDataCenterPlan private constructor(
private val nodePlans: List<JiraNodePlan>,
private val instanceHooks: PreInstanceHooks,
private val balancerPlan: LoadBalancerPlan,
Expand Down Expand Up @@ -74,10 +76,19 @@ class JiraDataCenterPlan constructor(
class Builder(
private var infrastructure: Infrastructure
) {
private var nodePlans: List<JiraNodePlan> = 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<JiraInstance> = JiraDataCenterPlan(nodePlans, infrastructure)
private var nodePlans: List<JiraNodePlan> = 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<JiraNodePlan>) = 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)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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
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.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 {
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 080f55e

Please sign in to comment.