From 0a4e1f0fa0b8b48330d2689d8440628347dd6639 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 22 Jan 2021 14:26:25 +0100 Subject: [PATCH 01/28] Reduce test flakiness on WSL Fix errors, when running integration tests on Windows Subsystem for Linux: ``` java.lang.Exception: Error while executing lftp -c 'set net:timeout 15; set net:max-retries 10; pget -n 32 -c "https://product-downloads.atlassian.com/software/jira/downloads/atlassian-jira-software-7.2.0.tar.gz" -o test/atlassian-jira-software-7.2.0.tar.gz'. Exit status code SshResult(exitStatus=1, output=, errorOutput=pget: /software/jira/downloads/atlassian-jira-software-7.2.0.tar.gz: Fatal error: max-retries exceeded) ``` I don't know why [Ubuntu on Docker on WSL] requires more retries than [Ubuntu on Docker on OSX]. --- CHANGELOG.md | 3 +++ .../atlassian/performance/tools/infrastructure/HttpResource.kt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6f0b8a7..1f5f92da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ Dropping a requirement of a major version of a dependency is a new contract. ## [Unreleased] [Unreleased]: https://github.com/atlassian/infrastructure/compare/release-4.17.5...master +### Fixed +- Increase network-level retries for Jira/browser downloads. Decrease flakiness of such downloads on Ubuntu on WSL2. + ## [4.17.5] - 2020-12-15 [4.17.5]: https://github.com/atlassian/infrastructure/compare/release-4.17.4...release-4.17.5 diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/HttpResource.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/HttpResource.kt index f4326c94..01edbfae 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/HttpResource.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/HttpResource.kt @@ -27,7 +27,7 @@ class HttpResource( ) { Ubuntu().install(ssh, listOf("lftp"), Duration.ofMinutes(2)) ssh.execute( - """lftp -c 'set net:timeout 15; set net:max-retries 10; pget -n 32 -c "$uri" -o $destination'""", + """lftp -c 'set net:timeout 15; set net:max-retries 50; pget -n 32 -c "$uri" -o $destination'""", timeout ) } From 2d91665029c090a8250baaf664eabef045926e83 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 29 Mar 2019 18:18:56 +0100 Subject: [PATCH 02/28] JPERF-273: Very very very early WIP --- .../api/jira/DataCenterNodeFormula.kt | 40 ++++ .../tools/infrastructure/api/jira/JiraNode.kt | 153 ++++++++++++++ .../api/jira/ServerNodeFormula.kt | 198 ++++++++++++++++++ .../infrastructure/api/jira/StartedNode.kt | 76 +++++++ .../infrastructure/api/jira/StoppedNode.kt | 10 + .../api/profiler/AsyncProfiler.kt | 2 +- 6 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt new file mode 100644 index 00000000..bb015f68 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt @@ -0,0 +1,40 @@ +package com.atlassian.performance.tools.infrastructure.api.jira + +import com.atlassian.performance.tools.awsinfrastructure.api.jira.StartedNode +import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome +import java.util.concurrent.Future + +internal class DataCenterNodeFormula( + private val nodeIndex: Int, + private val sharedHome: Future, + private val base: NodeFormula +) : NodeFormula by base { + + override fun provision(): StoppedNode { + + val provisionedNode = base.provision() + val localSharedHome = sharedHome.get().localSharedHome + + provisionedNode.ssh.newConnection().use { + sharedHome.get().mount(it) + val jiraHome = provisionedNode.jiraHome + + it.execute("echo ehcache.object.port = 40011 >> $jiraHome/cluster.properties") + it.execute("echo jira.node.id = node$nodeIndex >> $jiraHome/cluster.properties") + it.execute("echo jira.shared.home = `realpath $localSharedHome` >> $jiraHome/cluster.properties") + } + + return object : StoppedNode by provisionedNode { + override fun start(): StartedNode { + return provisionedNode.start().copy( + name = name, + analyticLogs = localSharedHome + ) + } + + override fun toString() = "node #$nodeIndex" + } + } + + override fun toString() = "node formula #$nodeIndex" +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt new file mode 100644 index 00000000..eb7bb5d0 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt @@ -0,0 +1,153 @@ +package com.atlassian.performance.tools.infrastructure.api.jira + +import com.atlassian.performance.tools.aws.api.Storage +import com.atlassian.performance.tools.awsinfrastructure.api.jira.StartedNode +import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts +import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit +import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump +import com.atlassian.performance.tools.infrastructure.api.os.OsMetric +import com.atlassian.performance.tools.infrastructure.api.process.RemoteMonitoringProcess +import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler +import com.atlassian.performance.tools.ssh.api.Ssh +import com.atlassian.performance.tools.ssh.api.SshConnection +import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.Logger +import java.net.URI +import java.time.Duration +import java.time.Duration.ofMinutes +import java.time.Duration.ofSeconds +import java.time.Instant.now + +internal data class JiraNode( + private val name: String, + override val jiraHome: String, + private val analyticLogs: String, + private val resultsTransport: Storage, + private val unpackedProduct: String, + private val osMetrics: List, + private val launchTimeouts: JiraLaunchTimeouts, + private val jdk: JavaDevelopmentKit, + private val profiler: Profiler, + override val ssh: Ssh, + private val adminUser : String = "admin", + private val adminPwd : String = "admin" +) : StoppedNode { + private val logger: Logger = LogManager.getLogger(this::class.java) + + override fun start(): StartedNode { + logger.info("Starting '$name'...") + val monitoringProcesses = mutableListOf() + + ssh.newConnection().use { sshConnection -> + osMetrics.forEach { metric -> + monitoringProcesses.add(metric.start(sshConnection)) + } + startJira(sshConnection) + val pid = pid(sshConnection) + monitoringProcesses.add(jdk.jstatMonitoring.start(sshConnection, pid)) + profiler.start(sshConnection, pid)?.let { monitoringProcesses.add(it) } + val threadDump = ThreadDump(pid, jdk) + try { + waitForUpgrades(sshConnection, threadDump) + } catch (exception: Exception) { + StartedNode( + name = name, + jiraHome = jiraHome, + analyticLogs = analyticLogs, + resultsTransport = resultsTransport, + unpackedProduct = unpackedProduct, + monitoringProcesses = monitoringProcesses, + ssh = ssh + ).gatherResults() + throw Exception("Failed to start the Jira node.", exception) + } + } + + logger.info("'$name' is started") + + return StartedNode( + name = name, + jiraHome = jiraHome, + analyticLogs = analyticLogs, + resultsTransport = resultsTransport, + unpackedProduct = unpackedProduct, + monitoringProcesses = monitoringProcesses, + ssh = ssh + ) + } + + private fun startJira( + ssh: SshConnection + ) { + ssh.execute( + """ + |${jdk.use()} + |./$unpackedProduct/bin/start-jira.sh + """.trimMargin(), + ofMinutes(1) + ) + } + + private fun pid( + ssh: SshConnection + ): Int { + return ssh.execute("cat $unpackedProduct/work/catalina.pid").output.trim().toInt() + } + + private fun waitForUpgrades( + ssh: SshConnection, + threadDump: ThreadDump + ) { + val upgradesEndpoint = URI("http://$adminUser:$adminPwd@localhost:8080/rest/api/2/upgrade") + waitForStatusToChange( + statusQuo = "000", + timeout = launchTimeouts.offlineTimeout, + ssh = ssh, + uri = upgradesEndpoint, + threadDump = threadDump + ) + waitForStatusToChange( + statusQuo = "503", + timeout = launchTimeouts.initTimeout, + ssh = ssh, + uri = upgradesEndpoint, + threadDump = threadDump + ) + ssh.execute( + cmd = "curl --silent --retry 6 -X POST $upgradesEndpoint", + timeout = ofSeconds(15) + ) + waitForStatusToChange( + statusQuo = "303", + timeout = launchTimeouts.upgradeTimeout, + ssh = ssh, + uri = upgradesEndpoint, + threadDump = threadDump + ) + } + + private fun waitForStatusToChange( + statusQuo: String, + uri: URI, + timeout: Duration, + ssh: SshConnection, + threadDump: ThreadDump + ) { + val backoff = ofSeconds(10) + val deadline = now() + timeout + while (true) { + val currentStatus = ssh.safeExecute( + cmd = "curl --silent --write-out '%{http_code}' --output /dev/null -X GET $uri", + timeout = launchTimeouts.unresponsivenessTimeout + ).output + if (currentStatus != statusQuo) { + break + } + if (deadline < now()) { + throw Exception("$uri failed to get out of $statusQuo status within $timeout") + } + threadDump.gather(ssh, "thread-dumps") + Thread.sleep(backoff.toMillis()) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt new file mode 100644 index 00000000..3692caf9 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt @@ -0,0 +1,198 @@ +package com.atlassian.performance.tools.infrastructure.api.jira + +import com.atlassian.performance.tools.infrastructure.api.Sed +import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution +import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit +import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.jvmtasks.api.Backoff +import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction +import com.atlassian.performance.tools.jvmtasks.api.TaskTimer +import com.atlassian.performance.tools.ssh.api.Ssh +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.time.Duration + +internal class ServerNodeFormula( + private val jiraHomeSource: JiraHomeSource, + private val hook: JiraNodeInstallationHook, + private val resultsTransport: Storage, + private val databaseIp: String, + private val productDistribution: ProductDistribution, + private val ssh: Ssh, + private val config: JiraNodeConfig, + private val dbType: DbType = DbType.MySql, + private val adminUser: String = "admin", + private val adminPwd: String = "admin" +) { + private val jdk = config.jdk + private val ubuntu: Ubuntu = Ubuntu() + + fun provision(): JiraNode { + ssh.newConnection().use { connection -> + val unpackedProduct = productDistribution.install(connection, ".") + val jiraHome = TaskTimer.time("download Jira home") { + jiraHomeSource.download(connection) + } + replaceDbconfigUrl(connection, "$jiraHome/dbconfig.xml") + connection.execute("echo jira.home=`realpath $jiraHome` > $unpackedProduct/atlassian-jira/WEB-INF/classes/jira-application.properties") + val bareJiraNode = BareJiraNode( + connection, + jiraHome, + unpackedProduct, + ssh.host.ipAddress + ) + val results = hook.hook(bareJiraNode) + +// AwsCli().download(pluginsTransport.location, connection, target = "$home/plugins/installed-plugins") + + val osMetrics = ubuntu.metrics(connection) + + config.splunkForwarder.jsonifyLog4j( + connection, + log4jPropertiesPath = "$unpackedProduct/atlassian-jira/WEB-INF/classes/log4j.properties" + ) + config.splunkForwarder.run(connection, name, "/home/ubuntu/jirahome/log") + config.profiler.install(connection) + + return JiraNode( + results = results, + jiraHome = jiraHome, + analyticLogs = jiraHome, + resultsTransport = resultsTransport, + unpackedProduct = unpackedProduct, + osMetrics = osMetrics, + ssh = ssh, + launchTimeouts = config.launchTimeouts, + jdk = jdk, + profiler = config.profiler, + adminUser = adminUser, + adminPwd = adminPwd + ) + } + } + + private fun replaceDbconfigUrl( + connection: SshConnection, + dbconfigXml: String + ) { + Sed().replace( + connection = connection, + expression = "(.*(@(//)?|//))" + "([^:/]+)" + "(.*)", + output = """\1$databaseIp\5""", + file = dbconfigXml + ) + } + + +} + +private class StaticBackoff( + private val backOff: Duration +) : Backoff { + override fun backOff(attempt: Int): Duration = backOff +} + +interface JiraNodeInstallationHook { + + fun hook(jira: BareJiraNode): RemoteResult +} + +class JiraNodeInstallationHookChain( + private val hooks: List +) : JiraNodeInstallationHook { + + override fun hook(jira: BareJiraNode): RemoteResult { + val results = hooks.map { it.hook(jira) } + return RemoteResultChain(results) + } +} + +interface RemoteResult { + + fun locate(): List +} + +class StaticRemoteResult( + private val remotePaths: List +) : RemoteResult { + override fun locate(): List = remotePaths +} + +class EmptyRemoteResult : RemoteResult { + override fun locate(): List = emptyList() +} + +class RemoteResultChain( + private val results: List +) : RemoteResult { + + override fun locate(): List { + return results.flatMap { it.locate() } + } +} + +class BareJiraNode( + val ssh: SshConnection, + val home: String, + val installation: String, + val ip: String +) + +class GcAndJmx( + private val config: JiraNodeConfig +) : JiraNodeInstallationHook { + + override fun hook( + jira: BareJiraNode + ): RemoteResult { + val gcLog = JiraGcLog(jira.installation) + SetenvSh(jira.installation).setup( + connection = jira.ssh, + config = config, + gcLog = gcLog, + jiraIp = jira.ip + ) + return StaticRemoteResult(listOf(gcLog.path())) + } +} + +class DisabledAutoBackup : JiraNodeInstallationHook { + + override fun hook(jira: BareJiraNode): RemoteResult { + jira.ssh.execute("echo jira.autoexport=false > ${jira.home}/jira-config.properties") + return EmptyRemoteResult() + } +} + +class MysqlConnector : JiraNodeInstallationHook { + override fun hook(jira: BareJiraNode): RemoteResult { + val ssh = jira.ssh + val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" + IdempotentAction( + description = "Download MySQL connector", + action = { ssh.execute("wget -q $connector") } + ).retry( + maxAttempts = 3, + backoff = StaticBackoff(Duration.ofSeconds(5)) + ) + ssh.execute("tar -xzf mysql-connector-java-5.1.40.tar.gz") + ssh.execute("cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar ${jira.installation}/lib") + return EmptyRemoteResult() + } +} + +class JdkInstall( + private val jdk: JavaDevelopmentKit +) : JiraNodeInstallationHook { + override fun hook(jira: BareJiraNode): RemoteResult { + jdk.install(jira.ssh) + return EmptyRemoteResult() + } +} + +class UbuntuSysstat : JiraNodeInstallationHook { + override fun hook(jira: BareJiraNode): RemoteResult { + val osMetrics = Ubuntu().metrics(jira.ssh) + // when do we `osMetrics.map { it.start }` ?? + return TODO() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt new file mode 100644 index 00000000..8f1eb805 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt @@ -0,0 +1,76 @@ +package com.atlassian.performance.tools.infrastructure.api.jira + +import com.atlassian.performance.tools.aws.api.Storage +import com.atlassian.performance.tools.awsinfrastructure.AwsCli +import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog +import com.atlassian.performance.tools.infrastructure.api.process.RemoteMonitoringProcess +import com.atlassian.performance.tools.ssh.api.Ssh +import java.time.Duration + +class StartedNode( + private val name: String, + private val jiraHome: String, + private val analyticLogs: String, + private val resultsTransport: Storage, + private val unpackedProduct: String, + private val monitoringProcesses: List, + private val ssh: Ssh +) { + private val resultsDirectory = "results" + + fun gatherResults() { + ssh.newConnection().use { shell -> + monitoringProcesses.forEach { it.stop(shell) } + val nodeResultsDirectory = "$resultsDirectory/'$name'" + val threadDumpsFolder = "thread-dumps" + listOf( + "mkdir -p $nodeResultsDirectory", + "cp $unpackedProduct/logs/catalina.out $nodeResultsDirectory", + "cp $unpackedProduct/logs/*access* $nodeResultsDirectory", + "mkdir -p $nodeResultsDirectory/$threadDumpsFolder", + "cp $threadDumpsFolder/* $nodeResultsDirectory/$threadDumpsFolder", + "cp $jiraHome/log/atlassian-jira.log $nodeResultsDirectory", + "cp ${JiraGcLog(unpackedProduct).path()} $nodeResultsDirectory", + "cp /var/log/syslog $nodeResultsDirectory", + "cp /var/log/cloud-init.log $nodeResultsDirectory", + "cp /var/log/cloud-init-output.log $nodeResultsDirectory" + ) + .plus(monitoringProcesses.map { "cp ${it.getResultPath()} $nodeResultsDirectory" }) + .plus("find $nodeResultsDirectory -empty -type f -delete") + .forEach { shell.safeExecute(it) } + AwsCli().upload( + location = resultsTransport.location, + ssh = shell, + source = resultsDirectory, + timeout = Duration.ofMinutes(10) + ) + } + } + + fun gatherAnalyticLogs() { + ssh.newConnection().use { + it.execute("cp -r $analyticLogs/analytics-logs $resultsDirectory") + it.execute("find $resultsDirectory/analytics-logs/ -maxdepth 1 -type f -name '*.gz' -exec gunzip {} +") + AwsCli().upload( + location = resultsTransport.location, + ssh = it, + source = resultsDirectory, + timeout = Duration.ofMinutes(2) + ) + } + } + + internal fun copy(name: String, analyticLogs: String): StartedNode { + return StartedNode( + name = name, + jiraHome = this.jiraHome, + analyticLogs = analyticLogs, + resultsTransport = this.resultsTransport, + unpackedProduct = this.unpackedProduct, + monitoringProcesses = this.monitoringProcesses, + ssh = this.ssh + ) + } + + override fun toString() = name +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt new file mode 100644 index 00000000..5c74dc24 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt @@ -0,0 +1,10 @@ +package com.atlassian.performance.tools.infrastructure.api.jira + +import com.atlassian.performance.tools.awsinfrastructure.api.jira.StartedNode +import com.atlassian.performance.tools.ssh.api.Ssh + +internal interface StoppedNode { + val jiraHome: String + val ssh: Ssh + fun start(): StartedNode +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt index e2f3f23e..484d1c6c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt @@ -19,7 +19,7 @@ class AsyncProfiler : Profiler { ssh: SshConnection, pid: Int ): RemoteMonitoringProcess { - ssh.execute("./async-profiler/profiler.sh -b 20000000 start $pid") + ssh.execute("./sync-profiler/profiler.sha -b 20000000 start $pid") return ProfilerProcess(pid) } From 1946c5110b6cb58f42a0338c08b0a3f6d6814950 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Mon, 1 Apr 2019 17:31:06 +0200 Subject: [PATCH 03/28] JPERF-273: Model the Jira node flow --- .../api/database/InstallableDatabase.kt | 8 + .../api/database/MySqlDatabase.kt | 60 +++++- .../tools/infrastructure/api/jira/JiraNode.kt | 164 ++++---------- .../api/jira/ServerNodeFormula.kt | 200 ++---------------- .../infrastructure/api/jira/StartedNode.kt | 55 +---- .../api/jira/flow/install/DefaultInstall.kt | 29 +++ .../jira/flow/install/DisabledAutoBackup.kt | 14 ++ .../api/jira/flow/install/Install.kt | 17 ++ .../api/jira/flow/install/InstallSequence.kt | 13 ++ .../api/jira/flow/install/InstalledJira.kt | 10 + .../api/jira/flow/install/JiraHomeProperty.kt | 14 ++ .../api/jira/flow/install/JvmConfig.kt | 27 +++ .../api/jira/flow/install/PassingInstall.kt | 27 +++ .../api/jira/flow/install/ProfilerInstall.kt | 41 ++++ .../flow/install/SplunkForwarderInstall.kt | 20 ++ .../api/jira/flow/install/SystemLog.kt | 13 ++ .../api/jira/flow/install/UbuntuSysstat.kt | 33 +++ .../api/jira/flow/report/EmptyReport.kt | 7 + .../api/jira/flow/report/Report.kt | 10 + .../api/jira/flow/report/ReportSequence.kt | 9 + .../api/jira/flow/report/StaticReport.kt | 16 ++ .../api/jira/flow/serve/PassingServe.kt | 9 + .../api/jira/flow/serve/Serve.kt | 11 + .../api/jira/flow/serve/ServeSequence.kt | 12 ++ .../api/jira/flow/start/JiraLogs.kt | 20 ++ .../api/jira/flow/start/PassingStart.kt | 20 ++ .../api/jira/flow/start/Start.kt | 16 ++ .../api/jira/flow/start/StartSequence.kt | 14 ++ .../api/jira/flow/upgrade/JstatUpgrade.kt | 17 ++ .../api/jira/flow/upgrade/PassingUpgrade.kt | 13 ++ .../api/jira/flow/upgrade/RestUpgrade.kt | 74 +++++++ .../api/jira/flow/upgrade/Upgrade.kt | 21 ++ .../api/jira/flow/upgrade/UpgradeSequence.kt | 13 ++ .../infrastructure/api/jvm/ThreadDump.kt | 2 +- .../api/virtualusers/SshVirtualUsers.kt | 4 - .../flow/RemoteMonitoringProcessReport.kt | 14 ++ 36 files changed, 682 insertions(+), 365 deletions(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/RemoteMonitoringProcessReport.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt new file mode 100644 index 00000000..8ea2ed03 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt @@ -0,0 +1,8 @@ +package com.atlassian.performance.tools.infrastructure.api.database + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install + +interface InstallableDatabase : Database { + + fun installInJira(databaseIp: String): Install +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt index 7746d94e..6d1c93a3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt @@ -1,8 +1,17 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.DockerImage +import com.atlassian.performance.tools.infrastructure.api.Sed import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstallSequence +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.jvmtasks.api.Backoff +import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger @@ -16,7 +25,8 @@ import java.time.Instant class MySqlDatabase( private val source: DatasetPackage, private val maxConnections: Int -) : Database { +) : InstallableDatabase { + private val logger: Logger = LogManager.getLogger(this::class.java) private val image: DockerImage = DockerImage( @@ -61,4 +71,50 @@ class MySqlDatabase( Thread.sleep(Duration.ofSeconds(10).toMillis()) } } -} \ No newline at end of file + + override fun installInJira(databaseIp: String): Install { + return InstallSequence(listOf( + MysqlJdbc(databaseIp), + MysqlConnector() + )) + } +} + +private class MysqlConnector : Install { + override fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start { + val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" + IdempotentAction( + description = "Download MySQL connector", + action = { ssh.execute("wget -q $connector") } + ).retry( + maxAttempts = 3, + backoff = StaticBackoff(Duration.ofSeconds(5)) + ) + ssh.execute("tar -xzf mysql-connector-java-5.1.40.tar.gz") + ssh.execute("cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar ${jira.installation}/lib") + return PassingStart(EmptyReport()) + } +} + +private class MysqlJdbc( + private val databaseIp: String +) : Install { + override fun install(ssh: SshConnection, jira: InstalledJira): Start { + Sed().replace( + connection = ssh, + expression = "(.*(@(//)?|//))" + "([^:/]+)" + "(.*)", + output = """\1$databaseIp\5""", + file = "${jira.home}/dbconfig.xml" + ) + return PassingStart(EmptyReport()) + } +} + +private class StaticBackoff( + private val backOff: Duration +) : Backoff { + override fun backOff(attempt: Int): Duration = backOff +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt index eb7bb5d0..e13efb64 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt @@ -1,89 +1,60 @@ package com.atlassian.performance.tools.infrastructure.api.jira -import com.atlassian.performance.tools.aws.api.Storage -import com.atlassian.performance.tools.awsinfrastructure.api.jira.StartedNode -import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit -import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump -import com.atlassian.performance.tools.infrastructure.api.os.OsMetric -import com.atlassian.performance.tools.infrastructure.api.process.RemoteMonitoringProcess -import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler import com.atlassian.performance.tools.ssh.api.Ssh import com.atlassian.performance.tools.ssh.api.SshConnection import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger -import java.net.URI -import java.time.Duration import java.time.Duration.ofMinutes -import java.time.Duration.ofSeconds -import java.time.Instant.now -internal data class JiraNode( +class JiraNode( + private val installed: InstalledJira, + private val start: Start, private val name: String, - override val jiraHome: String, private val analyticLogs: String, - private val resultsTransport: Storage, - private val unpackedProduct: String, - private val osMetrics: List, - private val launchTimeouts: JiraLaunchTimeouts, + private val installation: String, private val jdk: JavaDevelopmentKit, - private val profiler: Profiler, - override val ssh: Ssh, - private val adminUser : String = "admin", - private val adminPwd : String = "admin" -) : StoppedNode { + private val ssh: Ssh +) { private val logger: Logger = LogManager.getLogger(this::class.java) - override fun start(): StartedNode { - logger.info("Starting '$name'...") - val monitoringProcesses = mutableListOf() - - ssh.newConnection().use { sshConnection -> - osMetrics.forEach { metric -> - monitoringProcesses.add(metric.start(sshConnection)) - } - startJira(sshConnection) - val pid = pid(sshConnection) - monitoringProcesses.add(jdk.jstatMonitoring.start(sshConnection, pid)) - profiler.start(sshConnection, pid)?.let { monitoringProcesses.add(it) } - val threadDump = ThreadDump(pid, jdk) - try { - waitForUpgrades(sshConnection, threadDump) - } catch (exception: Exception) { - StartedNode( - name = name, - jiraHome = jiraHome, - analyticLogs = analyticLogs, - resultsTransport = resultsTransport, - unpackedProduct = unpackedProduct, - monitoringProcesses = monitoringProcesses, - ssh = ssh - ).gatherResults() - throw Exception("Failed to start the Jira node.", exception) - } + fun start(): Serve { + val serve = ssh.newConnection().use { shell -> + logger.info("Starting $name ...") + val upgrade = start.start(shell, installed) + startJira(shell) + val pid = pid(shell) + val started = StartedJira(installed, pid) + logger.info("Upgrading $name ...") + return@use upgrade(upgrade, shell, started) } + logger.info("$name is ready to serve") + return serve + } - logger.info("'$name' is started") - - return StartedNode( - name = name, - jiraHome = jiraHome, - analyticLogs = analyticLogs, - resultsTransport = resultsTransport, - unpackedProduct = unpackedProduct, - monitoringProcesses = monitoringProcesses, - ssh = ssh - ) + private fun upgrade( + upgrade: Upgrade, + sshConnection: SshConnection, + started: StartedJira + ): Serve { + try { + return upgrade.upgrade(sshConnection, started) + } catch (exception: Exception) { + TODO("Somehow download partial reports") + throw Exception("Failed to start the Jira node.", exception) + } } private fun startJira( ssh: SshConnection ) { ssh.execute( - """ - |${jdk.use()} - |./$unpackedProduct/bin/start-jira.sh - """.trimMargin(), + "${jdk.use()}; ./$installation/bin/start-installed.sh", ofMinutes(1) ) } @@ -91,63 +62,10 @@ internal data class JiraNode( private fun pid( ssh: SshConnection ): Int { - return ssh.execute("cat $unpackedProduct/work/catalina.pid").output.trim().toInt() - } - - private fun waitForUpgrades( - ssh: SshConnection, - threadDump: ThreadDump - ) { - val upgradesEndpoint = URI("http://$adminUser:$adminPwd@localhost:8080/rest/api/2/upgrade") - waitForStatusToChange( - statusQuo = "000", - timeout = launchTimeouts.offlineTimeout, - ssh = ssh, - uri = upgradesEndpoint, - threadDump = threadDump - ) - waitForStatusToChange( - statusQuo = "503", - timeout = launchTimeouts.initTimeout, - ssh = ssh, - uri = upgradesEndpoint, - threadDump = threadDump - ) - ssh.execute( - cmd = "curl --silent --retry 6 -X POST $upgradesEndpoint", - timeout = ofSeconds(15) - ) - waitForStatusToChange( - statusQuo = "303", - timeout = launchTimeouts.upgradeTimeout, - ssh = ssh, - uri = upgradesEndpoint, - threadDump = threadDump - ) - } - - private fun waitForStatusToChange( - statusQuo: String, - uri: URI, - timeout: Duration, - ssh: SshConnection, - threadDump: ThreadDump - ) { - val backoff = ofSeconds(10) - val deadline = now() + timeout - while (true) { - val currentStatus = ssh.safeExecute( - cmd = "curl --silent --write-out '%{http_code}' --output /dev/null -X GET $uri", - timeout = launchTimeouts.unresponsivenessTimeout - ).output - if (currentStatus != statusQuo) { - break - } - if (deadline < now()) { - throw Exception("$uri failed to get out of $statusQuo status within $timeout") - } - threadDump.gather(ssh, "thread-dumps") - Thread.sleep(backoff.toMillis()) - } + return ssh + .execute("cat $installation/work/catalina.pid") + .output + .trim() + .toInt() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt index 3692caf9..885bc969 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt @@ -1,198 +1,28 @@ package com.atlassian.performance.tools.infrastructure.api.jira -import com.atlassian.performance.tools.infrastructure.api.Sed import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit -import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu -import com.atlassian.performance.tools.jvmtasks.api.Backoff -import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction -import com.atlassian.performance.tools.jvmtasks.api.TaskTimer +import com.atlassian.performance.tools.jvmtasks.api.TaskTimer.time import com.atlassian.performance.tools.ssh.api.Ssh -import com.atlassian.performance.tools.ssh.api.SshConnection -import java.time.Duration -internal class ServerNodeFormula( +class ServerNodeFormula( + private val name: String, private val jiraHomeSource: JiraHomeSource, - private val hook: JiraNodeInstallationHook, - private val resultsTransport: Storage, - private val databaseIp: String, + private val install: Install, private val productDistribution: ProductDistribution, private val ssh: Ssh, - private val config: JiraNodeConfig, - private val dbType: DbType = DbType.MySql, - private val adminUser: String = "admin", - private val adminPwd: String = "admin" + private val jdk: JavaDevelopmentKit ) { - private val jdk = config.jdk - private val ubuntu: Ubuntu = Ubuntu() - - fun provision(): JiraNode { - ssh.newConnection().use { connection -> - val unpackedProduct = productDistribution.install(connection, ".") - val jiraHome = TaskTimer.time("download Jira home") { - jiraHomeSource.download(connection) - } - replaceDbconfigUrl(connection, "$jiraHome/dbconfig.xml") - connection.execute("echo jira.home=`realpath $jiraHome` > $unpackedProduct/atlassian-jira/WEB-INF/classes/jira-application.properties") - val bareJiraNode = BareJiraNode( - connection, - jiraHome, - unpackedProduct, - ssh.host.ipAddress - ) - val results = hook.hook(bareJiraNode) - -// AwsCli().download(pluginsTransport.location, connection, target = "$home/plugins/installed-plugins") - - val osMetrics = ubuntu.metrics(connection) - - config.splunkForwarder.jsonifyLog4j( - connection, - log4jPropertiesPath = "$unpackedProduct/atlassian-jira/WEB-INF/classes/log4j.properties" - ) - config.splunkForwarder.run(connection, name, "/home/ubuntu/jirahome/log") - config.profiler.install(connection) - - return JiraNode( - results = results, - jiraHome = jiraHome, - analyticLogs = jiraHome, - resultsTransport = resultsTransport, - unpackedProduct = unpackedProduct, - osMetrics = osMetrics, - ssh = ssh, - launchTimeouts = config.launchTimeouts, - jdk = jdk, - profiler = config.profiler, - adminUser = adminUser, - adminPwd = adminPwd - ) + fun install(): JiraNode { + ssh.newConnection().use { shell -> + val installation = productDistribution.install(shell, ".") + val home = time("download Jira home") { jiraHomeSource.download(shell) } + jdk.install(shell) + val jira = InstalledJira(home, installation, name, jdk) + val start = install.install(shell, jira) + return JiraNode(jira, start, name, home, installation, jdk, ssh) } } - - private fun replaceDbconfigUrl( - connection: SshConnection, - dbconfigXml: String - ) { - Sed().replace( - connection = connection, - expression = "(.*(@(//)?|//))" + "([^:/]+)" + "(.*)", - output = """\1$databaseIp\5""", - file = dbconfigXml - ) - } - - -} - -private class StaticBackoff( - private val backOff: Duration -) : Backoff { - override fun backOff(attempt: Int): Duration = backOff -} - -interface JiraNodeInstallationHook { - - fun hook(jira: BareJiraNode): RemoteResult -} - -class JiraNodeInstallationHookChain( - private val hooks: List -) : JiraNodeInstallationHook { - - override fun hook(jira: BareJiraNode): RemoteResult { - val results = hooks.map { it.hook(jira) } - return RemoteResultChain(results) - } -} - -interface RemoteResult { - - fun locate(): List -} - -class StaticRemoteResult( - private val remotePaths: List -) : RemoteResult { - override fun locate(): List = remotePaths -} - -class EmptyRemoteResult : RemoteResult { - override fun locate(): List = emptyList() -} - -class RemoteResultChain( - private val results: List -) : RemoteResult { - - override fun locate(): List { - return results.flatMap { it.locate() } - } -} - -class BareJiraNode( - val ssh: SshConnection, - val home: String, - val installation: String, - val ip: String -) - -class GcAndJmx( - private val config: JiraNodeConfig -) : JiraNodeInstallationHook { - - override fun hook( - jira: BareJiraNode - ): RemoteResult { - val gcLog = JiraGcLog(jira.installation) - SetenvSh(jira.installation).setup( - connection = jira.ssh, - config = config, - gcLog = gcLog, - jiraIp = jira.ip - ) - return StaticRemoteResult(listOf(gcLog.path())) - } -} - -class DisabledAutoBackup : JiraNodeInstallationHook { - - override fun hook(jira: BareJiraNode): RemoteResult { - jira.ssh.execute("echo jira.autoexport=false > ${jira.home}/jira-config.properties") - return EmptyRemoteResult() - } -} - -class MysqlConnector : JiraNodeInstallationHook { - override fun hook(jira: BareJiraNode): RemoteResult { - val ssh = jira.ssh - val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" - IdempotentAction( - description = "Download MySQL connector", - action = { ssh.execute("wget -q $connector") } - ).retry( - maxAttempts = 3, - backoff = StaticBackoff(Duration.ofSeconds(5)) - ) - ssh.execute("tar -xzf mysql-connector-java-5.1.40.tar.gz") - ssh.execute("cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar ${jira.installation}/lib") - return EmptyRemoteResult() - } } - -class JdkInstall( - private val jdk: JavaDevelopmentKit -) : JiraNodeInstallationHook { - override fun hook(jira: BareJiraNode): RemoteResult { - jdk.install(jira.ssh) - return EmptyRemoteResult() - } -} - -class UbuntuSysstat : JiraNodeInstallationHook { - override fun hook(jira: BareJiraNode): RemoteResult { - val osMetrics = Ubuntu().metrics(jira.ssh) - // when do we `osMetrics.map { it.start }` ?? - return TODO() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt index 8f1eb805..a79e1b1e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt @@ -1,50 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.jira -import com.atlassian.performance.tools.aws.api.Storage -import com.atlassian.performance.tools.awsinfrastructure.AwsCli -import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog -import com.atlassian.performance.tools.infrastructure.api.process.RemoteMonitoringProcess +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.ssh.api.Ssh import java.time.Duration class StartedNode( - private val name: String, - private val jiraHome: String, + private val serve: Serve, private val analyticLogs: String, - private val resultsTransport: Storage, - private val unpackedProduct: String, - private val monitoringProcesses: List, private val ssh: Ssh ) { private val resultsDirectory = "results" - fun gatherResults() { - ssh.newConnection().use { shell -> - monitoringProcesses.forEach { it.stop(shell) } - val nodeResultsDirectory = "$resultsDirectory/'$name'" - val threadDumpsFolder = "thread-dumps" - listOf( - "mkdir -p $nodeResultsDirectory", - "cp $unpackedProduct/logs/catalina.out $nodeResultsDirectory", - "cp $unpackedProduct/logs/*access* $nodeResultsDirectory", - "mkdir -p $nodeResultsDirectory/$threadDumpsFolder", - "cp $threadDumpsFolder/* $nodeResultsDirectory/$threadDumpsFolder", - "cp $jiraHome/log/atlassian-jira.log $nodeResultsDirectory", - "cp ${JiraGcLog(unpackedProduct).path()} $nodeResultsDirectory", - "cp /var/log/syslog $nodeResultsDirectory", - "cp /var/log/cloud-init.log $nodeResultsDirectory", - "cp /var/log/cloud-init-output.log $nodeResultsDirectory" - ) - .plus(monitoringProcesses.map { "cp ${it.getResultPath()} $nodeResultsDirectory" }) - .plus("find $nodeResultsDirectory -empty -type f -delete") - .forEach { shell.safeExecute(it) } - AwsCli().upload( - location = resultsTransport.location, - ssh = shell, - source = resultsDirectory, - timeout = Duration.ofMinutes(10) - ) - } + fun serve(): Report { + return serve.report() } fun gatherAnalyticLogs() { @@ -59,18 +28,4 @@ class StartedNode( ) } } - - internal fun copy(name: String, analyticLogs: String): StartedNode { - return StartedNode( - name = name, - jiraHome = this.jiraHome, - analyticLogs = analyticLogs, - resultsTransport = this.resultsTransport, - unpackedProduct = this.unpackedProduct, - monitoringProcesses = this.monitoringProcesses, - ssh = this.ssh - ) - } - - override fun toString() = name } \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt new file mode 100644 index 00000000..d3ae0ca7 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt @@ -0,0 +1,29 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.JiraLogs +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.JstatUpgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.RestUpgrade +import com.atlassian.performance.tools.ssh.api.SshConnection + +class DefaultInstall( + private val config: JiraNodeConfig +) : Install { + override fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start = InstallSequence(listOf( + JiraHomeProperty(), + SystemLog(), + PassingInstall(JiraLogs()), + JvmConfig(config), + DisabledAutoBackup(), + UbuntuSysstat(), + SplunkForwarderInstall(config.splunkForwarder), + ProfilerInstall(config.profiler), + PassingInstall(JiraLogs()), + PassingInstall(JstatUpgrade()), + PassingInstall(RestUpgrade(config.launchTimeouts, "admin", "admin")) + )).install(ssh, jira) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt new file mode 100644 index 00000000..c7c7844a --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.ssh.api.SshConnection + +class DisabledAutoBackup : Install { + + override fun install(ssh: SshConnection, jira: InstalledJira): Start { + ssh.execute("echo jira.autoexport=false > ${jira.home}/jira-config.properties") + return PassingStart(EmptyReport()) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt new file mode 100644 index 00000000..7d539755 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt @@ -0,0 +1,17 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.ssh.api.SshConnection + +/** + * Hooks in after installing Jira. + * We recommend install dependencies here rather than deferring it to later phases like [Start] or [Serve]. + */ +interface Install { + + fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start +} + diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt new file mode 100644 index 00000000..1a8a7014 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartSequence +import com.atlassian.performance.tools.ssh.api.SshConnection + +class InstallSequence( + private val installs: List +) : Install { + override fun install(ssh: SshConnection, jira: InstalledJira): Start { + return StartSequence(installs.map { it.install(ssh, jira) }) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt new file mode 100644 index 00000000..be8b8eb8 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt @@ -0,0 +1,10 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit + +class InstalledJira( + val home: String, + val installation: String, + val name: String, + val jdk: JavaDevelopmentKit +) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt new file mode 100644 index 00000000..a0ef8bb8 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.ssh.api.SshConnection + +class JiraHomeProperty : Install { + override fun install(ssh: SshConnection, jira: InstalledJira): Start { + val properties = "${jira.installation}/atlassian-jira/WEB-INF/classes/jira-application.properties" + ssh.execute("echo jira.home=`realpath ${jira.home}` > $properties") + return PassingStart(EmptyReport()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt new file mode 100644 index 00000000..a1bf3cdc --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt @@ -0,0 +1,27 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog +import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.ssh.api.SshConnection + +class JvmConfig( + private val config: JiraNodeConfig +) : Install { + override fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start { + val gcLog = JiraGcLog(jira.installation) + SetenvSh(jira.installation).setup( + connection = ssh, + config = config, + gcLog = gcLog, + jiraIp = jira.name + ) + return PassingStart(StaticReport(gcLog.path())) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt new file mode 100644 index 00000000..177319d9 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt @@ -0,0 +1,27 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.ssh.api.SshConnection + +class PassingInstall( + private val start: Start +) : Install { + + constructor( + upgrade: Upgrade + ) : this( + PassingStart(upgrade) + ) + + constructor( + report: Report + ) : this( + PassingUpgrade(report) + ) + + override fun install(ssh: SshConnection, jira: InstalledJira): Start = start +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt new file mode 100644 index 00000000..42928b23 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt @@ -0,0 +1,41 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler +import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.ssh.api.SshConnection + +class ProfilerInstall( + private val profiler: Profiler +) : Install { + override fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start { + profiler.install(ssh) + return PassingStart(ProfilerUpgrade(profiler)) + } +} + +private class ProfilerUpgrade( + private val profiler: Profiler +) : Upgrade { + + override fun upgrade( + ssh: SshConnection, + jira: StartedJira + ): Serve { + val process = profiler.start(ssh, jira.pid) + val report = when (process) { + null -> EmptyReport() + else -> RemoteMonitoringProcessReport(process) + } + return PassingServe(report) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt new file mode 100644 index 00000000..12dd6714 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt @@ -0,0 +1,20 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.splunk.SplunkForwarder +import com.atlassian.performance.tools.ssh.api.SshConnection + +class SplunkForwarderInstall( + private val splunk: SplunkForwarder +) : Install { + override fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start { + splunk.jsonifyLog4j(ssh, "${jira.installation}/atlassian-jira/WEB-INF/classes/log4j.properties") + splunk.run(ssh, jira.name, "/home/ubuntu/jirahome/log") + return PassingStart(EmptyReport()) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt new file mode 100644 index 00000000..26e78699 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.ssh.api.SshConnection + +class SystemLog : Install { + override fun install(ssh: SshConnection, jira: InstalledJira): Start { + return PassingStart(StaticReport("/var/log/syslog")) + } + +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt new file mode 100644 index 00000000..83c31cb7 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt @@ -0,0 +1,33 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.infrastructure.api.os.OsMetric +import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.ssh.api.SshConnection + +class UbuntuSysstat : Install { + override fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start = Ubuntu() + .metrics(ssh) + .let { OsMetricStart(it) } +} + +private class OsMetricStart( + private val metrics: List +) : Start { + + override fun start( + ssh: SshConnection, + jira: InstalledJira + ): Upgrade = metrics + .map { it.start(ssh) } + .map { RemoteMonitoringProcessReport(it) } + .let { ReportSequence(it) } + .let { PassingUpgrade(it) } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt new file mode 100644 index 00000000..a292838b --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt @@ -0,0 +1,7 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.report + +import com.atlassian.performance.tools.ssh.api.SshConnection + +class EmptyReport : Report { + override fun locate(ssh: SshConnection): List = emptyList() +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt new file mode 100644 index 00000000..1b742766 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt @@ -0,0 +1,10 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.report + +import com.atlassian.performance.tools.ssh.api.SshConnection + +/** + * Locates local report files after [Serve]. + */ +interface Report { + fun locate(ssh: SshConnection): List +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt new file mode 100644 index 00000000..3fd01037 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt @@ -0,0 +1,9 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.report + +import com.atlassian.performance.tools.ssh.api.SshConnection + +class ReportSequence( + private val reports: List +) : Report { + override fun locate(ssh: SshConnection): List = reports.flatMap { it.locate(ssh) } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt new file mode 100644 index 00000000..d429bdd2 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt @@ -0,0 +1,16 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.report + +import com.atlassian.performance.tools.ssh.api.SshConnection + +class StaticReport( + private val remoteLocations: List +) : Report { + + constructor( + remoteLocation: String + ) : this( + listOf(remoteLocation) + ) + + override fun locate(ssh: SshConnection): List = remoteLocations +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt new file mode 100644 index 00000000..b8fc6dac --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt @@ -0,0 +1,9 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report + +class PassingServe( + private val report: Report +) : Serve { + override fun report(): Report = report +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt new file mode 100644 index 00000000..c3210450 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt @@ -0,0 +1,11 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report + +/** + * Hooks in before Jira starts serving to clients after [Upgrade]. + */ +interface Serve { + + fun report(): Report +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt new file mode 100644 index 00000000..080a223f --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt @@ -0,0 +1,12 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence + +class ServeSequence( + private val serves: List +) : Serve { + override fun report(): Report { + return ReportSequence(serves.map { it.report() }) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt new file mode 100644 index 00000000..74cd52cc --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt @@ -0,0 +1,20 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.ssh.api.SshConnection + +class JiraLogs : Start { + override fun start( + ssh: SshConnection, + jira: InstalledJira + ): Upgrade { + return PassingUpgrade(StaticReport(listOf( + "${jira.home}/log/atlassian-jira.log", + "${jira.installation}/logs/catalina.out", + "${jira.installation}/logs/*access*" + ))) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt new file mode 100644 index 00000000..1cc23ed3 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt @@ -0,0 +1,20 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.ssh.api.SshConnection + +class PassingStart( + private val upgrade: Upgrade +) : Start { + + constructor( + report: Report + ) : this( + PassingUpgrade(report) + ) + + override fun start(ssh: SshConnection, jira: InstalledJira): Upgrade = upgrade +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt new file mode 100644 index 00000000..f8e8e29e --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt @@ -0,0 +1,16 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.ssh.api.SshConnection + +/** + * Hooks in before Jira starts after [Install]. + */ +interface Start { + + fun start( + ssh: SshConnection, + jira: InstalledJira + ): Upgrade +} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt new file mode 100644 index 00000000..d368b772 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.UpgradeSequence +import com.atlassian.performance.tools.ssh.api.SshConnection + +class StartSequence( + private val starts: List +) : Start { + override fun start(ssh: SshConnection, jira: InstalledJira): Upgrade { + return UpgradeSequence(starts.map { it.start(ssh, jira) }) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt new file mode 100644 index 00000000..ee54846b --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt @@ -0,0 +1,17 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.ssh.api.SshConnection + +class JstatUpgrade : Upgrade { + + override fun upgrade( + ssh: SshConnection, + jira: StartedJira + ): Serve { + val process = jira.installed.jdk.jstatMonitoring.start(ssh, jira.pid) + return PassingServe(RemoteMonitoringProcessReport(process)) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt new file mode 100644 index 00000000..99bf6419 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.ssh.api.SshConnection + +class PassingUpgrade( + private val report: Report +) : Upgrade { + + override fun upgrade(ssh: SshConnection, jira: StartedJira): Serve = PassingServe(report) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt new file mode 100644 index 00000000..87dae964 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt @@ -0,0 +1,74 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade + +import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.net.URI +import java.time.Duration +import java.time.Instant + +class RestUpgrade( + private val timeouts: JiraLaunchTimeouts, + private val adminUsername: String, + private val adminPassword: String +) : Upgrade { + + override fun upgrade(ssh: SshConnection, jira: StartedJira): Serve { + val threadDump = ThreadDump(jira.pid, jira.installed.jdk) + val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:8080/rest/api/2/upgrade") + waitForStatusToChange( + statusQuo = "000", + timeout = timeouts.offlineTimeout, + ssh = ssh, + uri = upgradesEndpoint, + threadDump = threadDump + ) + waitForStatusToChange( + statusQuo = "503", + timeout = timeouts.initTimeout, + ssh = ssh, + uri = upgradesEndpoint, + threadDump = threadDump + ) + ssh.execute( + cmd = "curl --silent --retry 6 -X POST $upgradesEndpoint", + timeout = Duration.ofSeconds(15) + ) + waitForStatusToChange( + statusQuo = "303", + timeout = timeouts.upgradeTimeout, + ssh = ssh, + uri = upgradesEndpoint, + threadDump = threadDump + ) + return PassingServe(StaticReport("thread-dumps")) + } + + private fun waitForStatusToChange( + statusQuo: String, + uri: URI, + timeout: Duration, + ssh: SshConnection, + threadDump: ThreadDump + ) { + val backoff = Duration.ofSeconds(10) + val deadline = Instant.now() + timeout + while (true) { + val currentStatus = ssh.safeExecute( + cmd = "curl --silent --write-out '%{http_code}' --output /dev/null -X GET $uri", + timeout = timeouts.unresponsivenessTimeout + ).output + if (currentStatus != statusQuo) { + break + } + if (deadline < Instant.now()) { + throw Exception("$uri failed to get out of $statusQuo status within $timeout") + } + threadDump.gather(ssh, "thread-dumps") + Thread.sleep(backoff.toMillis()) + } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt new file mode 100644 index 00000000..623eccb0 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt @@ -0,0 +1,21 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.ssh.api.SshConnection + +/** + * Hooks into the upgrade process after [Start]. + */ +interface Upgrade { + + fun upgrade( + ssh: SshConnection, + jira: StartedJira + ): Serve +} + +class StartedJira( + val installed: InstalledJira, + val pid: Int +) \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt new file mode 100644 index 00000000..98141486 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.ServeSequence +import com.atlassian.performance.tools.ssh.api.SshConnection + +class UpgradeSequence( + private val upgrades: List +) : Upgrade { + override fun upgrade(ssh: SshConnection, jira: StartedJira): Serve { + return ServeSequence(upgrades.map { it.upgrade(ssh, jira) }) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/ThreadDump.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/ThreadDump.kt index 18a6d361..8932d469 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/ThreadDump.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/ThreadDump.kt @@ -26,7 +26,7 @@ class ThreadDump( */ fun gather(connection: SshConnection, destination: String) { val threadDumpName = Instant.now().toEpochMilli() - val command = "${jdk.use()}; jcmd $pid Thread.print > $destination/${threadDumpName}" + val command = "${jdk.use()}; jcmd $pid Thread.print > $destination/$threadDumpName" connection.execute("mkdir -p $destination") connection.execute(command) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/virtualusers/SshVirtualUsers.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/virtualusers/SshVirtualUsers.kt index e5589fe1..5e0da2aa 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/virtualusers/SshVirtualUsers.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/virtualusers/SshVirtualUsers.kt @@ -89,8 +89,4 @@ class SshVirtualUsers( } } } - - override fun toString(): String { - return "SshVirtualUsers(name='$name', nodeOrder=$nodeOrder, resultsTransport=$resultsTransport, jarName='$jarName', ssh=$ssh, logger=$logger, jdk=$jdk)" - } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/RemoteMonitoringProcessReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/RemoteMonitoringProcessReport.kt new file mode 100644 index 00000000..cf1100b9 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/RemoteMonitoringProcessReport.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.process.RemoteMonitoringProcess +import com.atlassian.performance.tools.ssh.api.SshConnection + +internal class RemoteMonitoringProcessReport( + private val process: RemoteMonitoringProcess +) : Report { + override fun locate(ssh: SshConnection): List { + process.stop(ssh) + return listOf(process.getResultPath()) + } +} From 41b1f871fdfea1aaafb90d876b8bea78567b48c2 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Tue, 2 Apr 2019 13:28:28 +0200 Subject: [PATCH 04/28] JPERF-273: Test `InstallableJiraIT` --- .editorconfig | 5 +- .../api/database/MySqlDatabase.kt | 2 +- .../api/jira/DataCenterNodeFormula.kt | 72 ++++++++--------- .../tools/infrastructure/api/jira/JiraNode.kt | 71 ---------------- .../infrastructure/api/jira/JiraNodeConfig.kt | 8 +- .../api/jira/ServerNodeFormula.kt | 28 ------- .../infrastructure/api/jira/StartedNode.kt | 31 ------- .../infrastructure/api/jira/StoppedNode.kt | 10 --- .../api/jira/flow/InstallableJira.kt | 28 +++++++ .../jira/flow/{install => }/InstalledJira.kt | 5 +- .../api/jira/flow/ReportableJira.kt | 14 ++++ .../api/jira/flow/ServeableJira.kt | 16 ++++ .../api/jira/flow/StartableJira.kt | 53 ++++++++++++ .../api/jira/flow/StartedJira.kt | 6 ++ .../infrastructure/api/jira/flow/TcpServer.kt | 7 ++ .../jira/flow/install/AsyncProfilerInstall.kt | 55 +++++++++++++ .../api/jira/flow/install/DefaultInstall.kt | 9 +-- .../jira/flow/install/DisabledAutoBackup.kt | 1 + .../api/jira/flow/install/Install.kt | 3 +- .../api/jira/flow/install/InstallSequence.kt | 1 + .../api/jira/flow/install/JiraHomeProperty.kt | 3 +- .../api/jira/flow/install/JvmConfig.kt | 7 +- .../api/jira/flow/install/PassingInstall.kt | 1 + .../api/jira/flow/install/ProfilerInstall.kt | 7 +- .../flow/install/SplunkForwarderInstall.kt | 1 + .../api/jira/flow/install/SystemLog.kt | 1 + .../api/jira/flow/install/UbuntuSysstat.kt | 1 + .../api/jira/flow/report/FileListing.kt | 15 ++++ .../api/jira/flow/report/Report.kt | 5 +- .../api/jira/flow/report/StaticReport.kt | 10 +-- .../api/jira/flow/serve/PassingServe.kt | 4 +- .../api/jira/flow/serve/Serve.kt | 10 ++- .../api/jira/flow/serve/ServeSequence.kt | 6 +- .../api/jira/flow/start/JiraLogs.kt | 16 ++-- .../api/jira/flow/start/PassingStart.kt | 4 +- .../api/jira/flow/start/Start.kt | 5 +- .../api/jira/flow/start/StartSequence.kt | 2 +- .../api/jira/flow/upgrade/JstatUpgrade.kt | 1 + .../api/jira/flow/upgrade/PassingUpgrade.kt | 1 + .../api/jira/flow/upgrade/RestUpgrade.kt | 4 +- .../api/jira/flow/upgrade/Upgrade.kt | 8 +- .../api/jira/flow/upgrade/UpgradeSequence.kt | 1 + .../api/profiler/AsyncProfiler.kt | 3 +- .../infrastructure/SshUbuntuExtensions.kt | 6 +- .../api/jira/InstallableJiraIT.kt | 81 +++++++++++++++++++ 45 files changed, 390 insertions(+), 238 deletions(-) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstallableJira.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{install => }/InstalledJira.kt (79%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartedJira.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerInstall.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt create mode 100644 src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/InstallableJiraIT.kt diff --git a/.editorconfig b/.editorconfig index 2b991f50..6fd134e2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,2 +1,3 @@ -[*.{kt,kts}] -indent_size = 4 \ No newline at end of file +[*.{kt, kts}] +indent_size = 4 +insert_final_newline = true diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt index 6d1c93a3..a2f1883c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt @@ -5,7 +5,7 @@ import com.atlassian.performance.tools.infrastructure.api.Sed import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstallSequence -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt index bb015f68..07421c07 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt @@ -1,40 +1,36 @@ package com.atlassian.performance.tools.infrastructure.api.jira -import com.atlassian.performance.tools.awsinfrastructure.api.jira.StartedNode -import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome -import java.util.concurrent.Future - -internal class DataCenterNodeFormula( - private val nodeIndex: Int, - private val sharedHome: Future, - private val base: NodeFormula -) : NodeFormula by base { - - override fun provision(): StoppedNode { - - val provisionedNode = base.provision() - val localSharedHome = sharedHome.get().localSharedHome - - provisionedNode.ssh.newConnection().use { - sharedHome.get().mount(it) - val jiraHome = provisionedNode.jiraHome - - it.execute("echo ehcache.object.port = 40011 >> $jiraHome/cluster.properties") - it.execute("echo jira.node.id = node$nodeIndex >> $jiraHome/cluster.properties") - it.execute("echo jira.shared.home = `realpath $localSharedHome` >> $jiraHome/cluster.properties") - } - - return object : StoppedNode by provisionedNode { - override fun start(): StartedNode { - return provisionedNode.start().copy( - name = name, - analyticLogs = localSharedHome - ) - } - - override fun toString() = "node #$nodeIndex" - } - } - - override fun toString() = "node formula #$nodeIndex" -} \ No newline at end of file +//internal class DataCenterNodeFormula( +// private val nodeIndex: Int, +// private val sharedHome: Future, +// private val base: NodeFormula +//) : NodeFormula by base { +// +// override fun provision(): StoppedNode { +// +// val provisionedNode = base.provision() +// val localSharedHome = sharedHome.get().localSharedHome +// +// provisionedNode.ssh.newConnection().use { +// sharedHome.get().mount(it) +// val jiraHome = provisionedNode.jiraHome +// +// it.execute("echo ehcache.object.port = 40011 >> $jiraHome/cluster.properties") +// it.execute("echo jira.node.id = node$nodeIndex >> $jiraHome/cluster.properties") +// it.execute("echo jira.shared.home = `realpath $localSharedHome` >> $jiraHome/cluster.properties") +// } +// +// return object : StoppedNode by provisionedNode { +// override fun start(): StartedNode { +// return provisionedNode.start().copy( +// name = name, +// analyticLogs = localSharedHome +// ) +// } +// +// override fun toString() = "node #$nodeIndex" +// } +// } +// +// override fun toString() = "node formula #$nodeIndex" +//} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt deleted file mode 100644 index e13efb64..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNode.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade -import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit -import com.atlassian.performance.tools.ssh.api.Ssh -import com.atlassian.performance.tools.ssh.api.SshConnection -import org.apache.logging.log4j.LogManager -import org.apache.logging.log4j.Logger -import java.time.Duration.ofMinutes - -class JiraNode( - private val installed: InstalledJira, - private val start: Start, - private val name: String, - private val analyticLogs: String, - private val installation: String, - private val jdk: JavaDevelopmentKit, - private val ssh: Ssh -) { - private val logger: Logger = LogManager.getLogger(this::class.java) - - fun start(): Serve { - val serve = ssh.newConnection().use { shell -> - logger.info("Starting $name ...") - val upgrade = start.start(shell, installed) - startJira(shell) - val pid = pid(shell) - val started = StartedJira(installed, pid) - logger.info("Upgrading $name ...") - return@use upgrade(upgrade, shell, started) - } - logger.info("$name is ready to serve") - return serve - } - - private fun upgrade( - upgrade: Upgrade, - sshConnection: SshConnection, - started: StartedJira - ): Serve { - try { - return upgrade.upgrade(sshConnection, started) - } catch (exception: Exception) { - TODO("Somehow download partial reports") - throw Exception("Failed to start the Jira node.", exception) - } - } - - private fun startJira( - ssh: SshConnection - ) { - ssh.execute( - "${jdk.use()}; ./$installation/bin/start-installed.sh", - ofMinutes(1) - ) - } - - private fun pid( - ssh: SshConnection - ): Int { - return ssh - .execute("cat $installation/work/catalina.pid") - .output - .trim() - .toInt() - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNodeConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNodeConfig.kt index a759d080..1a0877cf 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNodeConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/JiraNodeConfig.kt @@ -1,10 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira -import com.atlassian.performance.tools.infrastructure.api.jvm.DisabledJvmDebug -import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit -import com.atlassian.performance.tools.infrastructure.api.jvm.VersionedJavaDevelopmentKit -import com.atlassian.performance.tools.infrastructure.api.jvm.JvmDebug -import com.atlassian.performance.tools.infrastructure.api.jvm.OracleJDK +import com.atlassian.performance.tools.infrastructure.api.jvm.* import com.atlassian.performance.tools.infrastructure.api.jvm.jmx.DisabledRemoteJmx import com.atlassian.performance.tools.infrastructure.api.jvm.jmx.RemoteJmx import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler @@ -157,4 +153,4 @@ class JiraNodeConfig private constructor( JiraNodeConfig::class.java.getResource("/collectd/conf/jira-default.conf").toURI() ) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt deleted file mode 100644 index 885bc969..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/ServerNodeFormula.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira - -import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit -import com.atlassian.performance.tools.jvmtasks.api.TaskTimer.time -import com.atlassian.performance.tools.ssh.api.Ssh - -class ServerNodeFormula( - private val name: String, - private val jiraHomeSource: JiraHomeSource, - private val install: Install, - private val productDistribution: ProductDistribution, - private val ssh: Ssh, - private val jdk: JavaDevelopmentKit -) { - fun install(): JiraNode { - ssh.newConnection().use { shell -> - val installation = productDistribution.install(shell, ".") - val home = time("download Jira home") { jiraHomeSource.download(shell) } - jdk.install(shell) - val jira = InstalledJira(home, installation, name, jdk) - val start = install.install(shell, jira) - return JiraNode(jira, start, name, home, installation, jdk, ssh) - } - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt deleted file mode 100644 index a79e1b1e..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StartedNode.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.ssh.api.Ssh -import java.time.Duration - -class StartedNode( - private val serve: Serve, - private val analyticLogs: String, - private val ssh: Ssh -) { - private val resultsDirectory = "results" - - fun serve(): Report { - return serve.report() - } - - fun gatherAnalyticLogs() { - ssh.newConnection().use { - it.execute("cp -r $analyticLogs/analytics-logs $resultsDirectory") - it.execute("find $resultsDirectory/analytics-logs/ -maxdepth 1 -type f -name '*.gz' -exec gunzip {} +") - AwsCli().upload( - location = resultsTransport.location, - ssh = it, - source = resultsDirectory, - timeout = Duration.ofMinutes(2) - ) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt deleted file mode 100644 index 5c74dc24..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/StoppedNode.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira - -import com.atlassian.performance.tools.awsinfrastructure.api.jira.StartedNode -import com.atlassian.performance.tools.ssh.api.Ssh - -internal interface StoppedNode { - val jiraHome: String - val ssh: Ssh - fun start(): StartedNode -} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstallableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstallableJira.kt new file mode 100644 index 00000000..4fede638 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstallableJira.kt @@ -0,0 +1,28 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution +import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install +import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit +import com.atlassian.performance.tools.jvmtasks.api.TaskTimer.time +import com.atlassian.performance.tools.ssh.api.SshConnection + +class InstallableJira( + private val name: String, + private val jiraHomeSource: JiraHomeSource, // TODO add database too, but how to handle databaseIp? + private val installHook: Install, + private val productDistribution: ProductDistribution, + private val jdk: JavaDevelopmentKit +) { + fun install( + ssh: SshConnection, + server: TcpServer + ): StartableJira { + val installation = productDistribution.install(ssh, ".") + val home = time("download Jira home") { jiraHomeSource.download(ssh) } + jdk.install(ssh) + val installed = InstalledJira(home, installation, name, jdk, server) + val startHook = installHook.install(ssh, installed) + return StartableJira(installed, startHook) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt similarity index 79% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt index be8b8eb8..8c0e8558 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.flow import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit @@ -6,5 +6,6 @@ class InstalledJira( val home: String, val installation: String, val name: String, - val jdk: JavaDevelopmentKit + val jdk: JavaDevelopmentKit, + val server: TcpServer ) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt new file mode 100644 index 00000000..6b4d5b25 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.ssh.api.SshConnection + +class ReportableJira( + private val reportHook: Report +) { + fun report( + ssh: SshConnection + ): List { + return reportHook.locate(ssh) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt new file mode 100644 index 00000000..0640eb59 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt @@ -0,0 +1,16 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.ssh.api.SshConnection + +class ServeableJira( + private val started: StartedJira, + private val serveHook: Serve +) { + fun serve( + ssh: SshConnection + ): ReportableJira { + val reportHook = serveHook.serve(ssh, started) + return ReportableJira(reportHook) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt new file mode 100644 index 00000000..f2556a9d --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt @@ -0,0 +1,53 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.time.Duration.ofMinutes + +class StartableJira( + private val installed: InstalledJira, + private val startHook: Start +) { + fun start( + ssh: SshConnection + ): ServeableJira { + val upgradeHook = startHook.start(ssh, installed) + val pid = startJira(ssh) + val started = StartedJira(installed, pid) + val serveHook = upgrade(upgradeHook, ssh, started) + return ServeableJira(started, serveHook) + } + + private fun upgrade( + upgrade: Upgrade, + sshConnection: SshConnection, + started: StartedJira + ): Serve { + try { + return upgrade.upgrade(sshConnection, started) + } catch (exception: Exception) { + TODO("Somehow download partial reports") + throw Exception("Failed to startHook the Jira node.", exception) + } + } + + private fun startJira( + ssh: SshConnection + ): Int { + ssh.execute( + "${installed.jdk.use()}; ${installed.installation}/bin/start-jira.sh", + ofMinutes(1) + ) + return pid(ssh) + } + + private fun pid( + ssh: SshConnection + ): Int = ssh + .execute("cat ${installed.installation}/work/catalina.pid") + .output + .trim() + .toInt() +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartedJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartedJira.kt new file mode 100644 index 00000000..582de84a --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartedJira.kt @@ -0,0 +1,6 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +class StartedJira( + val installed: InstalledJira, + val pid: Int +) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt new file mode 100644 index 00000000..ae441e1e --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt @@ -0,0 +1,7 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +class TcpServer( + val ip: String, + val publicPort: Int, + val privatePort: Int +) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerInstall.kt new file mode 100644 index 00000000..01e76b78 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerInstall.kt @@ -0,0 +1,55 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.net.URI + +class AsyncProfilerInstall : Install { + override fun install( + ssh: SshConnection, + jira: InstalledJira + ): Start { + val directory = "async-profiler" + val downloads = URI("https://github.com/jvm-profiling-tools/async-profiler/releases/download/") + val distribution = downloads.resolve("v1.4/async-profiler-1.4-linux-x64.tar.gz") + ssh.execute("wget -q $distribution") + ssh.execute("mkdir $directory") + ssh.execute("tar -xzf async-profiler-1.4-linux-x64.tar.gz -C $directory") + ssh.execute("sudo sh -c 'echo 1 > /proc/sys/kernel/perf_event_paranoid'") + ssh.execute("sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'") + val profilerPath = "./$directory/profiler.sh" + return PassingStart(AsyncProfilerUpgrade(profilerPath)) + } +} + +private class AsyncProfilerUpgrade( + private val profilerPath: String +) : Upgrade { + + override fun upgrade( + ssh: SshConnection, + jira: StartedJira + ): Serve { + ssh.execute("$profilerPath -b 20000000 start ${jira.pid}") + val report = AsyncProfilerReport(jira.pid, profilerPath) + return PassingServe(report) + } +} + +private class AsyncProfilerReport( + private val pid: Int, + private val profilerPath: String +) : Report { + override fun locate(ssh: SshConnection): List { + val flameGraphFile = "flamegraph.svg" + ssh.execute("$profilerPath stop $pid -o svg > $flameGraphFile") + return listOf(flameGraphFile) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt index d3ae0ca7..f283c4cf 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt @@ -1,10 +1,10 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.JiraLogs import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.JstatUpgrade -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.RestUpgrade import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultInstall( @@ -15,15 +15,14 @@ class DefaultInstall( jira: InstalledJira ): Start = InstallSequence(listOf( JiraHomeProperty(), - SystemLog(), - PassingInstall(JiraLogs()), +// SystemLog(), JvmConfig(config), DisabledAutoBackup(), UbuntuSysstat(), SplunkForwarderInstall(config.splunkForwarder), ProfilerInstall(config.profiler), PassingInstall(JiraLogs()), - PassingInstall(JstatUpgrade()), - PassingInstall(RestUpgrade(config.launchTimeouts, "admin", "admin")) + PassingInstall(JstatUpgrade()) +// PassingInstall(RestUpgrade(config.launchTimeouts, "admin", "admin")) TODO("This always fails if the DB is not set up") )).install(ssh, jira) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt index c7c7844a..fcef475c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt index 7d539755..d39a9889 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt @@ -1,5 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.ssh.api.SshConnection @@ -14,4 +16,3 @@ interface Install { jira: InstalledJira ): Start } - diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt index 1a8a7014..78e540c4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartSequence import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt index a0ef8bb8..e6e8e551 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start @@ -11,4 +12,4 @@ class JiraHomeProperty : Install { ssh.execute("echo jira.home=`realpath ${jira.home}` > $properties") return PassingStart(EmptyReport()) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt index a1bf3cdc..eac77c19 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt @@ -3,7 +3,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.ssh.api.SshConnection @@ -22,6 +23,6 @@ class JvmConfig( gcLog = gcLog, jiraIp = jira.name ) - return PassingStart(StaticReport(gcLog.path())) + return PassingStart(FileListing(gcLog.path("*"))) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt index 177319d9..f839a6f1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt index 42928b23..4a5252a6 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt @@ -1,16 +1,21 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection +/** + * Bridges the [Profiler] SPI with the [Install] SPI. + * In general any [Profiler] can be rewritten as an [Install] (or any other `api.jira.flow`) without this bridge. + */ class ProfilerInstall( private val profiler: Profiler ) : Install { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt index 12dd6714..eede4a8c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt index 26e78699..ddf28116 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt index 83c31cb7..782de7c4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt new file mode 100644 index 00000000..461fa75f --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt @@ -0,0 +1,15 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.report + +import com.atlassian.performance.tools.ssh.api.SshConnection + +class FileListing( + private val pattern: String +) : Report { + override fun locate( + ssh: SshConnection + ): List = ssh + .safeExecute("ls $pattern") + .output + .lines() + .filter { it.isNotBlank() } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt index 1b742766..82fbd813 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt @@ -1,10 +1,11 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.ssh.api.SshConnection /** - * Locates local report files after [Serve]. + * Locates local serve files after [Serve]. */ interface Report { fun locate(ssh: SshConnection): List -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt index d429bdd2..bec01d7b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt @@ -3,14 +3,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.report import com.atlassian.performance.tools.ssh.api.SshConnection class StaticReport( - private val remoteLocations: List + private val remotePath: String ) : Report { - constructor( - remoteLocation: String - ) : this( - listOf(remoteLocation) - ) - - override fun locate(ssh: SshConnection): List = remoteLocations + override fun locate(ssh: SshConnection): List = listOf(remotePath) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt index b8fc6dac..a1ea6171 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt @@ -1,9 +1,11 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.ssh.api.SshConnection class PassingServe( private val report: Report ) : Serve { - override fun report(): Report = report + override fun serve(ssh: SshConnection, jira: StartedJira): Report = report } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt index c3210450..abf79821 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt @@ -1,11 +1,17 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.ssh.api.SshConnection /** * Hooks in before Jira starts serving to clients after [Upgrade]. */ interface Serve { - fun report(): Report -} \ No newline at end of file + fun serve( + ssh: SshConnection, + jira: StartedJira + ): Report +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt index 080a223f..327f00ee 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt @@ -1,12 +1,14 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence +import com.atlassian.performance.tools.ssh.api.SshConnection class ServeSequence( private val serves: List ) : Serve { - override fun report(): Report { - return ReportSequence(serves.map { it.report() }) + override fun serve(ssh: SshConnection, jira: StartedJira): Report { + return ReportSequence(serves.map { it.serve(ssh, jira) }) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt index 74cd52cc..c4a67f1e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt @@ -1,6 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade @@ -10,11 +12,9 @@ class JiraLogs : Start { override fun start( ssh: SshConnection, jira: InstalledJira - ): Upgrade { - return PassingUpgrade(StaticReport(listOf( - "${jira.home}/log/atlassian-jira.log", - "${jira.installation}/logs/catalina.out", - "${jira.installation}/logs/*access*" - ))) - } + ): Upgrade = PassingUpgrade(ReportSequence(listOf( + StaticReport("${jira.home}/log/atlassian-jira.log"), + StaticReport("${jira.installation}/logs/catalina.out"), + FileListing("${jira.installation}/logs/*access*") + ))) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt index 1cc23ed3..b65fbbbb 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt @@ -1,6 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade @@ -17,4 +17,4 @@ class PassingStart( ) override fun start(ssh: SshConnection, jira: InstalledJira): Upgrade = upgrade -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt index f8e8e29e..56517e0b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt @@ -1,6 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade import com.atlassian.performance.tools.ssh.api.SshConnection @@ -13,4 +14,4 @@ interface Start { ssh: SshConnection, jira: InstalledJira ): Upgrade -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt index d368b772..26022ada 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt @@ -1,6 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.UpgradeSequence import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt index ee54846b..0ee4c9af 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt index 99bf6419..5e35e1cc 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt index 87dae964..11d29f80 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt @@ -1,6 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve @@ -18,7 +19,8 @@ class RestUpgrade( override fun upgrade(ssh: SshConnection, jira: StartedJira): Serve { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) - val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:8080/rest/api/2/upgrade") + val privatePort = jira.installed.server.privatePort + val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:$privatePort/rest/api/2/upgrade") waitForStatusToChange( statusQuo = "000", timeout = timeouts.offlineTimeout, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt index 623eccb0..7a4bb2c1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt @@ -1,7 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.ssh.api.SshConnection /** @@ -14,8 +15,3 @@ interface Upgrade { jira: StartedJira ): Serve } - -class StartedJira( - val installed: InstalledJira, - val pid: Int -) \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt index 98141486..47a6950a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.ServeSequence import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt index 484d1c6c..6dab41d9 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt @@ -6,6 +6,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection /** * Asynchronous profiler. See https://github.com/jvm-profiling-tools/async-profiler#basic-usage */ +@Deprecated("Use AsyncProfilerInstall") class AsyncProfiler : Profiler { override fun install(ssh: SshConnection) { ssh.execute("wget -q https://github.com/jvm-profiling-tools/async-profiler/releases/download/v1.4/async-profiler-1.4-linux-x64.tar.gz") @@ -19,7 +20,7 @@ class AsyncProfiler : Profiler { ssh: SshConnection, pid: Int ): RemoteMonitoringProcess { - ssh.execute("./sync-profiler/profiler.sha -b 20000000 start $pid") + ssh.execute("./async-profiler/profiler.sh -b 20000000 start $pid") return ProfilerProcess(pid) } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt index 73d3a946..e022dcbd 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt @@ -1,15 +1,17 @@ package com.atlassian.performance.tools.infrastructure import com.atlassian.performance.tools.ssh.api.Ssh +import com.atlassian.performance.tools.ssh.api.SshHost +import com.atlassian.performance.tools.ssh.api.auth.PublicKeyAuthentication import com.atlassian.performance.tools.sshubuntu.api.SshUbuntu import java.time.Duration internal fun SshUbuntu.toSsh(): Ssh { val ssh = Ssh(with(this.ssh) { - com.atlassian.performance.tools.ssh.api.SshHost( + SshHost( ipAddress = ipAddress, userName = userName, - authentication = com.atlassian.performance.tools.ssh.api.auth.PublicKeyAuthentication(privateKey), + authentication = PublicKeyAuthentication(privateKey), port = port ) }) diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/InstallableJiraIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/InstallableJiraIT.kt new file mode 100644 index 00000000..3e9cb6ae --- /dev/null +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/InstallableJiraIT.kt @@ -0,0 +1,81 @@ +package com.atlassian.performance.tools.infrastructure.api.jira + +import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstallableJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultInstall +import com.atlassian.performance.tools.infrastructure.api.jvm.OracleJDK +import com.atlassian.performance.tools.infrastructure.toSsh +import com.atlassian.performance.tools.ssh.api.SshConnection +import com.atlassian.performance.tools.sshubuntu.api.SshUbuntuContainer +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import java.io.File +import java.nio.file.Files +import java.util.function.Consumer + +class InstallableJiraIT { + + @Test + fun shouldFlowThroughAllSteps() { + val installHook = DefaultInstall(JiraNodeConfig.Builder().build()) + val formula = InstallableJira( + name = "test", + jiraHomeSource = EmptyJiraHome(), + installHook = installHook, + productDistribution = PublicJiraSoftwareDistribution("7.13.0"), + jdk = OracleJDK() + ) + val privatePort = 8080 + val container = SshUbuntuContainer(Consumer { + it.addExposedPort(privatePort) + }) + + val remoteReports = container.start().use { sshUbuntu -> + val server = TcpServer( + "localhost", + sshUbuntu.container.getMappedPort(privatePort), + privatePort + ) + val remoteReports = sshUbuntu.toSsh().newConnection().use { ssh -> + formula + .install(ssh, server) + .start(ssh) + .serve(ssh) + .report(ssh) + } + sshUbuntu.toSsh().newConnection().use { ssh -> + download(remoteReports, ssh) + } + return@use remoteReports + } + + assertThat(remoteReports).contains( + "~/jpt-vmstat.log", + "~/jpt-iostat.log", + "jira-home/log/atlassian-jira.log", + "./atlassian-jira-software-7.13.0-standalone/logs/catalina.out", + "~/jpt-jstat.log" + ) + } + + private fun download( + remotes: List, + ssh: SshConnection + ): List { + val downloads = Files.createTempDirectory("apt-infra-test") + return remotes.map { remote -> + val path = downloads.resolve(remote) + ssh.download(remote, path) + return@map path.toFile() + } + } +} + +private class EmptyJiraHome : JiraHomeSource { + override fun download(ssh: SshConnection): String { + val jiraHome = "jira-home" + ssh.execute("mkdir $jiraHome") + return jiraHome + } +} From 6d1ffeff7f29d1186e3a661183fd56b95b7d322b Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 5 Apr 2019 14:15:51 +0200 Subject: [PATCH 05/28] JPERF-273: Refactor the Jira lifecycle Allow reports to be contributed from arbitrary phase of the lifecycle. It means we can download partial results if the lifecycle fails mid-way. --- .../tools/infrastructure/Iostat.kt | 4 +- .../api/database/InstallableDatabase.kt | 4 +- .../api/database/MySqlDatabase.kt | 33 +++++----- .../api/jira/flow/InstalledJira.kt | 1 - .../api/jira/flow/ReportableJira.kt | 14 ----- .../api/jira/flow/ServeableJira.kt | 16 ----- .../api/jira/flow/StartableJira.kt | 53 ---------------- .../infrastructure/api/jira/flow/TcpServer.kt | 3 +- ...rofilerInstall.kt => AsyncProfilerHook.kt} | 39 ++++++------ .../api/jira/flow/install/DefaultInstall.kt | 28 --------- .../DefaultJiraInstallation.kt} | 29 +++++---- .../flow/install/DefaultPostInstallHook.kt | 28 +++++++++ .../jira/flow/install/DisabledAutoBackup.kt | 13 ++-- .../flow/install/HookedJiraInstallation.kt | 22 +++++++ .../api/jira/flow/install/Install.kt | 18 ------ .../api/jira/flow/install/InstallSequence.kt | 14 ----- .../api/jira/flow/install/JiraHomeProperty.kt | 14 +++-- .../JiraInstallation.kt} | 20 +++--- .../api/jira/flow/install/JvmConfig.kt | 18 +++--- .../api/jira/flow/install/PassingInstall.kt | 28 --------- .../Serve.kt => install/PostInstallHook.kt} | 20 +++--- .../flow/install/PostInstallHookSequence.kt | 18 ++++++ .../api/jira/flow/install/PreInstallHook.kt | 13 ++++ .../api/jira/flow/install/ProfilerInstall.kt | 46 -------------- .../api/jira/flow/install/SystemLog.kt | 12 ++-- .../api/jira/flow/install/UbuntuSysstat.kt | 44 +++++++------ .../api/jira/flow/report/EmptyReport.kt | 7 --- .../api/jira/flow/report/FileListing.kt | 2 +- .../api/jira/flow/report/Report.kt | 4 -- .../api/jira/flow/report/ReportSequence.kt | 9 --- .../api/jira/flow/report/ReportTrack.kt | 18 ++++++ .../ServeSequence.kt => start/AccessLogs.kt} | 15 +++-- .../jira/flow/start/DefaultPostStartHook.kt | 20 ++++++ .../api/jira/flow/start/HookedJiraStart.kt | 22 +++++++ .../api/jira/flow/start/JiraLaunchScript.kt | 27 ++++++++ .../api/jira/flow/start/JiraLogs.kt | 27 ++++---- .../flow/start/{Start.kt => JiraStart.kt} | 14 ++--- .../JstatUpgrade.kt => start/JstatHook.kt} | 16 ++--- .../api/jira/flow/start/PassingStart.kt | 20 ------ .../PostStartHook.kt} | 14 +++-- .../api/jira/flow/start/PreStartHook.kt | 13 ++++ .../flow/{upgrade => start}/RestUpgrade.kt | 11 ++-- .../api/jira/flow/start/StartSequence.kt | 14 ----- .../api/jira/flow/upgrade/PassingUpgrade.kt | 14 ----- .../api/jira/flow/upgrade/UpgradeSequence.kt | 14 ----- .../tools/infrastructure/api/jvm/Jstat.kt | 4 +- .../tools/infrastructure/api/os/Vmstat.kt | 4 +- .../api/profiler/AsyncProfiler.kt | 4 +- .../jira/flow/install/ProfilerHook.kt | 39 ++++++++++++ .../flow/install/SplunkForwarderHook.kt} | 22 +++---- .../infrastructure/api/jira/EmptyJiraHome.kt | 11 ++++ .../start/HookedJiraStartIT.kt} | 61 ++++++++++--------- 52 files changed, 457 insertions(+), 521 deletions(-) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/{AsyncProfilerInstall.kt => AsyncProfilerHook.kt} (68%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{InstallableJira.kt => install/DefaultJiraInstallation.kt} (55%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{upgrade/Upgrade.kt => install/JiraInstallation.kt} (64%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{serve/Serve.kt => install/PostInstallHook.kt} (50%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportTrack.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{serve/ServeSequence.kt => start/AccessLogs.kt} (56%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/{Start.kt => JiraStart.kt} (71%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{upgrade/JstatUpgrade.kt => start/JstatHook.kt} (62%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{serve/PassingServe.kt => start/PostStartHook.kt} (61%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{upgrade => start}/RestUpgrade.kt (90%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/{api/jira/flow/install/SplunkForwarderInstall.kt => jira/flow/install/SplunkForwarderHook.kt} (55%) create mode 100644 src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt rename src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{InstallableJiraIT.kt => flow/start/HookedJiraStartIT.kt} (57%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/Iostat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/Iostat.kt index 7a7ed2c9..c82e0790 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/Iostat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/Iostat.kt @@ -10,7 +10,7 @@ import java.time.temporal.ChronoUnit internal class Iostat : OsMetric { companion object { private val DELAY: Duration = Duration.ofSeconds(2) - private val LOG_PATH: String = "~/jpt-iostat.log" + private val LOG_PATH: String = "./jpt-iostat.log" private val TIME = "date -u \"+%d-%m-%Y %H:%M:%S UTC\"" private val ADD_TIME = @@ -32,4 +32,4 @@ internal class Iostat : OsMetric { val process = connection.startProcess("iostat -d $seconds -x | $ADD_TIME > $LOG_PATH") return MonitoringProcess(process, LOG_PATH) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt index 8ea2ed03..038bb75a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.database -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook interface InstallableDatabase : Database { - fun installInJira(databaseIp: String): Install + fun installInJira(databaseIp: String): PostInstallHook } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt index a2f1883c..c1aa31e1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt @@ -3,12 +3,10 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.DockerImage import com.atlassian.performance.tools.infrastructure.api.Sed import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstallSequence import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHookSequence +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu import com.atlassian.performance.tools.jvmtasks.api.Backoff import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction @@ -72,19 +70,21 @@ class MySqlDatabase( } } - override fun installInJira(databaseIp: String): Install { - return InstallSequence(listOf( + override fun installInJira(databaseIp: String): PostInstallHook { + return PostInstallHookSequence(listOf( MysqlJdbc(databaseIp), MysqlConnector() )) } } -private class MysqlConnector : Install { - override fun install( +private class MysqlConnector : PostInstallHook { + + override fun hook( ssh: SshConnection, - jira: InstalledJira - ): Start { + jira: InstalledJira, + track: ReportTrack + ) { val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" IdempotentAction( description = "Download MySQL connector", @@ -95,21 +95,24 @@ private class MysqlConnector : Install { ) ssh.execute("tar -xzf mysql-connector-java-5.1.40.tar.gz") ssh.execute("cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar ${jira.installation}/lib") - return PassingStart(EmptyReport()) } } private class MysqlJdbc( private val databaseIp: String -) : Install { - override fun install(ssh: SshConnection, jira: InstalledJira): Start { +) : PostInstallHook { + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + track: ReportTrack + ) { Sed().replace( connection = ssh, expression = "(.*(@(//)?|//))" + "([^:/]+)" + "(.*)", output = """\1$databaseIp\5""", file = "${jira.home}/dbconfig.xml" ) - return PassingStart(EmptyReport()) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt index 8c0e8558..6bd4df9d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt @@ -5,7 +5,6 @@ import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit class InstalledJira( val home: String, val installation: String, - val name: String, val jdk: JavaDevelopmentKit, val server: TcpServer ) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt deleted file mode 100644 index 6b4d5b25..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ReportableJira.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.ssh.api.SshConnection - -class ReportableJira( - private val reportHook: Report -) { - fun report( - ssh: SshConnection - ): List { - return reportHook.locate(ssh) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt deleted file mode 100644 index 0640eb59..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/ServeableJira.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.ssh.api.SshConnection - -class ServeableJira( - private val started: StartedJira, - private val serveHook: Serve -) { - fun serve( - ssh: SshConnection - ): ReportableJira { - val reportHook = serveHook.serve(ssh, started) - return ReportableJira(reportHook) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt deleted file mode 100644 index f2556a9d..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartableJira.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade -import com.atlassian.performance.tools.ssh.api.SshConnection -import java.time.Duration.ofMinutes - -class StartableJira( - private val installed: InstalledJira, - private val startHook: Start -) { - fun start( - ssh: SshConnection - ): ServeableJira { - val upgradeHook = startHook.start(ssh, installed) - val pid = startJira(ssh) - val started = StartedJira(installed, pid) - val serveHook = upgrade(upgradeHook, ssh, started) - return ServeableJira(started, serveHook) - } - - private fun upgrade( - upgrade: Upgrade, - sshConnection: SshConnection, - started: StartedJira - ): Serve { - try { - return upgrade.upgrade(sshConnection, started) - } catch (exception: Exception) { - TODO("Somehow download partial reports") - throw Exception("Failed to startHook the Jira node.", exception) - } - } - - private fun startJira( - ssh: SshConnection - ): Int { - ssh.execute( - "${installed.jdk.use()}; ${installed.installation}/bin/start-jira.sh", - ofMinutes(1) - ) - return pid(ssh) - } - - private fun pid( - ssh: SshConnection - ): Int = ssh - .execute("cat ${installed.installation}/work/catalina.pid") - .output - .trim() - .toInt() -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt index ae441e1e..6bdc69b1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt @@ -3,5 +3,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow class TcpServer( val ip: String, val publicPort: Int, - val privatePort: Int + val privatePort: Int, + val name: String ) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt similarity index 68% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerInstall.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt index 01e76b78..d62c56ef 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerInstall.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt @@ -1,21 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI -class AsyncProfilerInstall : Install { - override fun install( +class AsyncProfilerHook : PreInstallHook { + override fun hook( ssh: SshConnection, - jira: InstalledJira - ): Start { + server: TcpServer, + track: ReportTrack + ) { val directory = "async-profiler" val downloads = URI("https://github.com/jvm-profiling-tools/async-profiler/releases/download/") val distribution = downloads.resolve("v1.4/async-profiler-1.4-linux-x64.tar.gz") @@ -25,25 +23,28 @@ class AsyncProfilerInstall : Install { ssh.execute("sudo sh -c 'echo 1 > /proc/sys/kernel/perf_event_paranoid'") ssh.execute("sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'") val profilerPath = "./$directory/profiler.sh" - return PassingStart(AsyncProfilerUpgrade(profilerPath)) + val profiler = InstalledAsyncProfiler(profilerPath) + track.postStartHooks.add(profiler) } + } -private class AsyncProfilerUpgrade( +private class InstalledAsyncProfiler( private val profilerPath: String -) : Upgrade { +) : PostStartHook { - override fun upgrade( + override fun hook( ssh: SshConnection, - jira: StartedJira - ): Serve { + jira: StartedJira, + track: ReportTrack + ) { ssh.execute("$profilerPath -b 20000000 start ${jira.pid}") - val report = AsyncProfilerReport(jira.pid, profilerPath) - return PassingServe(report) + val profiler = StartedAsyncProfiler(jira.pid, profilerPath) + track.reports.add(profiler) } } -private class AsyncProfilerReport( +private class StartedAsyncProfiler( private val pid: Int, private val profilerPath: String ) : Report { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt deleted file mode 100644 index f283c4cf..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultInstall.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.JiraLogs -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.JstatUpgrade -import com.atlassian.performance.tools.ssh.api.SshConnection - -class DefaultInstall( - private val config: JiraNodeConfig -) : Install { - override fun install( - ssh: SshConnection, - jira: InstalledJira - ): Start = InstallSequence(listOf( - JiraHomeProperty(), -// SystemLog(), - JvmConfig(config), - DisabledAutoBackup(), - UbuntuSysstat(), - SplunkForwarderInstall(config.splunkForwarder), - ProfilerInstall(config.profiler), - PassingInstall(JiraLogs()), - PassingInstall(JstatUpgrade()) -// PassingInstall(RestUpgrade(config.launchTimeouts, "admin", "admin")) TODO("This always fails if the DB is not set up") - )).install(ssh, jira) -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstallableJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt similarity index 55% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstallableJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt index 4fede638..df932996 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstallableJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt @@ -1,28 +1,27 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit -import com.atlassian.performance.tools.jvmtasks.api.TaskTimer.time import com.atlassian.performance.tools.ssh.api.SshConnection -class InstallableJira( - private val name: String, - private val jiraHomeSource: JiraHomeSource, // TODO add database too, but how to handle databaseIp? - private val installHook: Install, +class DefaultJiraInstallation( + private val jiraHomeSource: JiraHomeSource, // TODO add database too, but how to handle databaseIp? Perhaps as a wrapper, which could be applied by the "DB installing" code? private val productDistribution: ProductDistribution, private val jdk: JavaDevelopmentKit -) { - fun install( +) : JiraInstallation { + + override fun install( ssh: SshConnection, - server: TcpServer - ): StartableJira { + server: TcpServer, + track: ReportTrack + ): InstalledJira { val installation = productDistribution.install(ssh, ".") - val home = time("download Jira home") { jiraHomeSource.download(ssh) } + val home = jiraHomeSource.download(ssh) jdk.install(ssh) - val installed = InstalledJira(home, installation, name, jdk, server) - val startHook = installHook.install(ssh, installed) - return StartableJira(installed, startHook) + return InstalledJira(home, installation, jdk, server) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt new file mode 100644 index 00000000..0f17be94 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt @@ -0,0 +1,28 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.jira.flow.install.ProfilerHook +import com.atlassian.performance.tools.infrastructure.jira.flow.install.SplunkForwarderHook +import com.atlassian.performance.tools.ssh.api.SshConnection + +class DefaultPostInstallHook( + private val config: JiraNodeConfig +) : PostInstallHook { + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + track: ReportTrack + ) { + listOf( + JiraHomeProperty(), + DisabledAutoBackup(), + JvmConfig(config), + ProfilerHook(config.profiler), + SplunkForwarderHook(config.splunkForwarder), + UbuntuSysstat() + ).forEach { it.hook(ssh, jira, track) } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt index fcef475c..b9958c1c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt @@ -1,15 +1,16 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection -class DisabledAutoBackup : Install { +class DisabledAutoBackup : PostInstallHook { - override fun install(ssh: SshConnection, jira: InstalledJira): Start { + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + track: ReportTrack + ) { ssh.execute("echo jira.autoexport=false > ${jira.home}/jira-config.properties") - return PassingStart(EmptyReport()) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt new file mode 100644 index 00000000..6825309e --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt @@ -0,0 +1,22 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.ssh.api.SshConnection + +class HookedJiraInstallation( + private val installation: JiraInstallation +) : JiraInstallation { + + override fun install( + ssh: SshConnection, + server: TcpServer, + track: ReportTrack + ): InstalledJira { + track.preInstallHooks.forEach { it.hook(ssh, server, track) } + val installed = installation.install(ssh, server, track) + track.postInstallHooks.forEach { it.hook(ssh, installed, track) } + return installed + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt deleted file mode 100644 index d39a9889..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/Install.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.ssh.api.SshConnection - -/** - * Hooks in after installing Jira. - * We recommend install dependencies here rather than deferring it to later phases like [Start] or [Serve]. - */ -interface Install { - - fun install( - ssh: SshConnection, - jira: InstalledJira - ): Start -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt deleted file mode 100644 index 78e540c4..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstallSequence.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartSequence -import com.atlassian.performance.tools.ssh.api.SshConnection - -class InstallSequence( - private val installs: List -) : Install { - override fun install(ssh: SshConnection, jira: InstalledJira): Start { - return StartSequence(installs.map { it.install(ssh, jira) }) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt index e6e8e551..997dc02c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt @@ -1,15 +1,17 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection -class JiraHomeProperty : Install { - override fun install(ssh: SshConnection, jira: InstalledJira): Start { +class JiraHomeProperty : PostInstallHook { + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + track: ReportTrack + ) { val properties = "${jira.installation}/atlassian-jira/WEB-INF/classes/jira-application.properties" ssh.execute("echo jira.home=`realpath ${jira.home}` > $properties") - return PassingStart(EmptyReport()) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt similarity index 64% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt index 7a4bb2c1..aa9826b9 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/Upgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt @@ -1,17 +1,15 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection -/** - * Hooks into the upgrade process after [Start]. - */ -interface Upgrade { +interface JiraInstallation { - fun upgrade( + fun install( ssh: SshConnection, - jira: StartedJira - ): Serve + server: TcpServer, + track: ReportTrack + ): InstalledJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt index eac77c19..c98954b5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt @@ -5,24 +5,26 @@ import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection class JvmConfig( private val config: JiraNodeConfig -) : Install { - override fun install( +) : PostInstallHook { + + override fun hook( ssh: SshConnection, - jira: InstalledJira - ): Start { + jira: InstalledJira, + track: ReportTrack + ) { val gcLog = JiraGcLog(jira.installation) SetenvSh(jira.installation).setup( connection = ssh, config = config, gcLog = gcLog, - jiraIp = jira.name + jiraIp = jira.server.ip ) - return PassingStart(FileListing(gcLog.path("*"))) + val report = FileListing(gcLog.path("*")) + track.reports.add(report) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt deleted file mode 100644 index f839a6f1..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PassingInstall.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade -import com.atlassian.performance.tools.ssh.api.SshConnection - -class PassingInstall( - private val start: Start -) : Install { - - constructor( - upgrade: Upgrade - ) : this( - PassingStart(upgrade) - ) - - constructor( - report: Report - ) : this( - PassingUpgrade(report) - ) - - override fun install(ssh: SshConnection, jira: InstalledJira): Start = start -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt similarity index 50% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt index abf79821..55a05df4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/Serve.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt @@ -1,17 +1,13 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection -/** - * Hooks in before Jira starts serving to clients after [Upgrade]. - */ -interface Serve { - - fun serve( +interface PostInstallHook { + fun hook( ssh: SshConnection, - jira: StartedJira - ): Report + jira: InstalledJira, + track: ReportTrack + ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt new file mode 100644 index 00000000..90a013e6 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt @@ -0,0 +1,18 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.ssh.api.SshConnection + +class PostInstallHookSequence( + private val hooks: List +) : PostInstallHook { + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + track: ReportTrack + ) { + hooks.forEach { it.hook(ssh, jira, track) } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt new file mode 100644 index 00000000..04b71b35 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.ssh.api.SshConnection + +interface PreInstallHook { + fun hook( + ssh: SshConnection, + server: TcpServer, + track: ReportTrack + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt deleted file mode 100644 index 4a5252a6..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ProfilerInstall.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade -import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler -import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport -import com.atlassian.performance.tools.ssh.api.SshConnection - -/** - * Bridges the [Profiler] SPI with the [Install] SPI. - * In general any [Profiler] can be rewritten as an [Install] (or any other `api.jira.flow`) without this bridge. - */ -class ProfilerInstall( - private val profiler: Profiler -) : Install { - override fun install( - ssh: SshConnection, - jira: InstalledJira - ): Start { - profiler.install(ssh) - return PassingStart(ProfilerUpgrade(profiler)) - } -} - -private class ProfilerUpgrade( - private val profiler: Profiler -) : Upgrade { - - override fun upgrade( - ssh: SshConnection, - jira: StartedJira - ): Serve { - val process = profiler.start(ssh, jira.pid) - val report = when (process) { - null -> EmptyReport() - else -> RemoteMonitoringProcessReport(process) - } - return PassingServe(report) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt index ddf28116..bbeaed7c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt @@ -1,14 +1,12 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start import com.atlassian.performance.tools.ssh.api.SshConnection -class SystemLog : Install { - override fun install(ssh: SshConnection, jira: InstalledJira): Start { - return PassingStart(StaticReport("/var/log/syslog")) +class SystemLog : PreInstallHook { + override fun hook(ssh: SshConnection, server: TcpServer, track: ReportTrack) { + track.reports.add(StaticReport("/var/log/syslog")) } - } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt index 782de7c4..3014c076 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt @@ -1,34 +1,38 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection -class UbuntuSysstat : Install { - override fun install( +class UbuntuSysstat : PostInstallHook { + + override fun hook( ssh: SshConnection, - jira: InstalledJira - ): Start = Ubuntu() - .metrics(ssh) - .let { OsMetricStart(it) } + jira: InstalledJira, + track: ReportTrack + ) { + val postStartHooks = Ubuntu() + .metrics(ssh) + .map { InstalledOsMetric(it) } + track.postStartHooks.addAll(postStartHooks) + } } -private class OsMetricStart( - private val metrics: List -) : Start { +private class InstalledOsMetric( + private val metric: OsMetric +) : PostStartHook { - override fun start( + override fun hook( ssh: SshConnection, - jira: InstalledJira - ): Upgrade = metrics - .map { it.start(ssh) } - .map { RemoteMonitoringProcessReport(it) } - .let { ReportSequence(it) } - .let { PassingUpgrade(it) } + jira: StartedJira, + track: ReportTrack + ) { + val process = metric.start(ssh) + track.reports.add(RemoteMonitoringProcessReport(process)) + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt deleted file mode 100644 index a292838b..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/EmptyReport.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.report - -import com.atlassian.performance.tools.ssh.api.SshConnection - -class EmptyReport : Report { - override fun locate(ssh: SshConnection): List = emptyList() -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt index 461fa75f..c63f91a2 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt @@ -8,7 +8,7 @@ class FileListing( override fun locate( ssh: SshConnection ): List = ssh - .safeExecute("ls $pattern") + .execute("ls $pattern") .output .lines() .filter { it.isNotBlank() } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt index 82fbd813..44a79d79 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt @@ -1,11 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.ssh.api.SshConnection -/** - * Locates local serve files after [Serve]. - */ interface Report { fun locate(ssh: SshConnection): List } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt deleted file mode 100644 index 3fd01037..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportSequence.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.report - -import com.atlassian.performance.tools.ssh.api.SshConnection - -class ReportSequence( - private val reports: List -) : Report { - override fun locate(ssh: SshConnection): List = reports.flatMap { it.locate(ssh) } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportTrack.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportTrack.kt new file mode 100644 index 00000000..a5d9225c --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportTrack.kt @@ -0,0 +1,18 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.report + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PreStartHook +import net.jcip.annotations.ThreadSafe +import java.util.concurrent.CopyOnWriteArrayList + +@ThreadSafe +class ReportTrack { + + val preInstallHooks: MutableList = CopyOnWriteArrayList() + val postInstallHooks: MutableList = CopyOnWriteArrayList() + val preStartHooks: MutableList = CopyOnWriteArrayList() + val postStartHooks: MutableList = CopyOnWriteArrayList() + val reports: MutableList = CopyOnWriteArrayList() +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt similarity index 56% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt index 327f00ee..ec78542d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/ServeSequence.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt @@ -1,14 +1,13 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection -class ServeSequence( - private val serves: List -) : Serve { - override fun serve(ssh: SshConnection, jira: StartedJira): Report { - return ReportSequence(serves.map { it.serve(ssh, jira) }) +class AccessLogs : PostStartHook { + + override fun hook(ssh: SshConnection, jira: StartedJira, track: ReportTrack) { + track.reports.add(FileListing("${jira.installed.installation}/logs/*access*")) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt new file mode 100644 index 00000000..bb8c68e3 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt @@ -0,0 +1,20 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.ssh.api.SshConnection + +class DefaultPostStartHook : PostStartHook { + + override fun hook( + ssh: SshConnection, + jira: StartedJira, + track: ReportTrack + ) { + listOf( + JiraLogs(), + JstatHook() + //,RestUpgrade(config.launchTimeouts, "admin", "admin") TODO requires database to work + ).forEach { it.hook(ssh, jira, track) } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt new file mode 100644 index 00000000..0e40caf8 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt @@ -0,0 +1,22 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.ssh.api.SshConnection + +class HookedJiraStart( + private val start: JiraStart +) : JiraStart { + + override fun start( + ssh: SshConnection, + installed: InstalledJira, + track: ReportTrack + ): StartedJira { + track.preStartHooks.forEach { it.hook(ssh, installed, track) } + val started = start.start(ssh, installed, track) + track.postStartHooks.forEach { it.hook(ssh, started, track) } + return started + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt new file mode 100644 index 00000000..47466229 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt @@ -0,0 +1,27 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.time.Duration + +class JiraLaunchScript : JiraStart { + + override fun start( + ssh: SshConnection, + installed: InstalledJira, + track: ReportTrack + ): StartedJira { + ssh.execute( + "${installed.jdk.use()}; ${installed.installation}/bin/start-jira.sh", + Duration.ofMinutes(1) + ) + val pid = ssh + .execute("cat ${installed.installation}/work/catalina.pid") + .output + .trim() + .toInt() + return StartedJira(installed, pid) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt index c4a67f1e..2127e3d7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt @@ -1,20 +1,21 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportSequence +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade import com.atlassian.performance.tools.ssh.api.SshConnection -class JiraLogs : Start { - override fun start( - ssh: SshConnection, - jira: InstalledJira - ): Upgrade = PassingUpgrade(ReportSequence(listOf( - StaticReport("${jira.home}/log/atlassian-jira.log"), - StaticReport("${jira.installation}/logs/catalina.out"), - FileListing("${jira.installation}/logs/*access*") - ))) +class JiraLogs : PreStartHook, PostStartHook { + + override fun hook(ssh: SshConnection, jira: InstalledJira, track: ReportTrack) { + listOf( + StaticReport("${jira.home}/log/atlassian-jira.log"), + StaticReport("${jira.installation}/logs/catalina.out") + ).forEach { track.reports.add(it) } + } + + override fun hook(ssh: SshConnection, jira: StartedJira, track: ReportTrack) { + hook(ssh, jira.installed, track) + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt similarity index 71% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt index 56517e0b..b97cfcce 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/Start.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt @@ -1,17 +1,15 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection -/** - * Hooks in before Jira starts after [Install]. - */ -interface Start { +interface JiraStart { fun start( ssh: SshConnection, - jira: InstalledJira - ): Upgrade + installed: InstalledJira, + track: ReportTrack + ): StartedJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt similarity index 62% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt index 0ee4c9af..65b39160 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/JstatUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt @@ -1,18 +1,18 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection -class JstatUpgrade : Upgrade { +class JstatHook : PostStartHook { - override fun upgrade( + override fun hook( ssh: SshConnection, - jira: StartedJira - ): Serve { + jira: StartedJira, + track: ReportTrack + ) { val process = jira.installed.jdk.jstatMonitoring.start(ssh, jira.pid) - return PassingServe(RemoteMonitoringProcessReport(process)) + track.reports.add(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt deleted file mode 100644 index b65fbbbb..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PassingStart.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.PassingUpgrade -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade -import com.atlassian.performance.tools.ssh.api.SshConnection - -class PassingStart( - private val upgrade: Upgrade -) : Start { - - constructor( - report: Report - ) : this( - PassingUpgrade(report) - ) - - override fun start(ssh: SshConnection, jira: InstalledJira): Upgrade = upgrade -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt similarity index 61% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt index a1ea6171..5a57bd49 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/serve/PassingServe.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt @@ -1,11 +1,13 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.serve +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.ssh.api.SshConnection -class PassingServe( - private val report: Report -) : Serve { - override fun serve(ssh: SshConnection, jira: StartedJira): Report = report +interface PostStartHook { + fun hook( + ssh: SshConnection, + jira: StartedJira, + track: ReportTrack + ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt new file mode 100644 index 00000000..314b2532 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.ssh.api.SshConnection + +interface PreStartHook { + fun hook( + ssh: SshConnection, + jira: InstalledJira, + track: ReportTrack + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt similarity index 90% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt index 11d29f80..b3d07a7c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt @@ -1,10 +1,9 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI @@ -15,12 +14,13 @@ class RestUpgrade( private val timeouts: JiraLaunchTimeouts, private val adminUsername: String, private val adminPassword: String -) : Upgrade { +) : PostStartHook { - override fun upgrade(ssh: SshConnection, jira: StartedJira): Serve { + override fun hook(ssh: SshConnection, jira: StartedJira, track: ReportTrack) { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) val privatePort = jira.installed.server.privatePort val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:$privatePort/rest/api/2/upgrade") + track.reports.add(StaticReport("thread-dumps")) waitForStatusToChange( statusQuo = "000", timeout = timeouts.offlineTimeout, @@ -46,7 +46,6 @@ class RestUpgrade( uri = upgradesEndpoint, threadDump = threadDump ) - return PassingServe(StaticReport("thread-dumps")) } private fun waitForStatusToChange( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt deleted file mode 100644 index 26022ada..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartSequence.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.Upgrade -import com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade.UpgradeSequence -import com.atlassian.performance.tools.ssh.api.SshConnection - -class StartSequence( - private val starts: List -) : Start { - override fun start(ssh: SshConnection, jira: InstalledJira): Upgrade { - return UpgradeSequence(starts.map { it.start(ssh, jira) }) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt deleted file mode 100644 index 5e35e1cc..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/PassingUpgrade.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.PassingServe -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.ssh.api.SshConnection - -class PassingUpgrade( - private val report: Report -) : Upgrade { - - override fun upgrade(ssh: SshConnection, jira: StartedJira): Serve = PassingServe(report) -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt deleted file mode 100644 index 47a6950a..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/upgrade/UpgradeSequence.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.upgrade - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.Serve -import com.atlassian.performance.tools.infrastructure.api.jira.flow.serve.ServeSequence -import com.atlassian.performance.tools.ssh.api.SshConnection - -class UpgradeSequence( - private val upgrades: List -) : Upgrade { - override fun upgrade(ssh: SshConnection, jira: StartedJira): Serve { - return ServeSequence(upgrades.map { it.upgrade(ssh, jira) }) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/Jstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/Jstat.kt index f0d01e0c..34a3e467 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/Jstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/Jstat.kt @@ -11,7 +11,7 @@ class Jstat( companion object { val LOG_FILE_NAME = "jpt-jstat.log" private val INTERVAL: Duration = Duration.ofSeconds(2) - private val LOG_PATH: String = "~/$LOG_FILE_NAME" + private val LOG_PATH: String = "./$LOG_FILE_NAME" private val TIME = "date -Iseconds" private val ADD_TIME = @@ -48,4 +48,4 @@ class Jstat( val process = connection.startProcess("${jvmBin}jstat $option -t $pid $interval | $ADD_TIME > $LOG_PATH") return MonitoringProcess(process, LOG_PATH) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/os/Vmstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/os/Vmstat.kt index 2d8f8005..84c6aaab 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/os/Vmstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/os/Vmstat.kt @@ -9,7 +9,7 @@ class Vmstat : OsMetric { companion object { val LOG_FILE_NAME = "jpt-vmstat.log" - private val LOG_PATH: String = "~/$LOG_FILE_NAME" + private val LOG_PATH: String = "./$LOG_FILE_NAME" private val DELAY: Duration = Duration.ofSeconds(2) } @@ -26,4 +26,4 @@ class Vmstat : OsMetric { val process = connection.startProcess("vmstat -t $delayInSeconds > $LOG_PATH") return MonitoringProcess(process, LOG_PATH) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt index 6dab41d9..c2850884 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/profiler/AsyncProfiler.kt @@ -6,7 +6,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection /** * Asynchronous profiler. See https://github.com/jvm-profiling-tools/async-profiler#basic-usage */ -@Deprecated("Use AsyncProfilerInstall") +@Deprecated("Use AsyncProfilerHook") class AsyncProfiler : Profiler { override fun install(ssh: SshConnection) { ssh.execute("wget -q https://github.com/jvm-profiling-tools/async-profiler/releases/download/v1.4/async-profiler-1.4-linux-x64.tar.gz") @@ -35,4 +35,4 @@ class AsyncProfiler : Profiler { return flameGraphFile } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt new file mode 100644 index 00000000..5dd08d54 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt @@ -0,0 +1,39 @@ +package com.atlassian.performance.tools.infrastructure.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler +import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.ssh.api.SshConnection + +/** + * Bridges the [Profiler] SPI with the [PostInstallHook] SPI. + * In general any [Profiler] can be rewritten as an [PostInstallHook] or any other hook without this bridge. + */ +class ProfilerHook( + private val profiler: Profiler +) : PostInstallHook { + override fun hook(ssh: SshConnection, jira: InstalledJira, track: ReportTrack) { + profiler.install(ssh) + track.postStartHooks.add(InstalledProfiler(profiler)) + } +} + +private class InstalledProfiler( + private val profiler: Profiler +) : PostStartHook { + + override fun hook( + ssh: SshConnection, + jira: StartedJira, + track: ReportTrack + ) { + val process = profiler.start(ssh, jira.pid) + if (process != null) { + track.reports.add(RemoteMonitoringProcessReport(process)) + } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt similarity index 55% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt index eede4a8c..c9aa8761 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SplunkForwarderInstall.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt @@ -1,21 +1,21 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.EmptyReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PassingStart -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.api.splunk.SplunkForwarder import com.atlassian.performance.tools.ssh.api.SshConnection -class SplunkForwarderInstall( +internal class SplunkForwarderHook( private val splunk: SplunkForwarder -) : Install { - override fun install( +) : PostInstallHook { + + override fun hook( ssh: SshConnection, - jira: InstalledJira - ): Start { + jira: InstalledJira, + track: ReportTrack + ) { splunk.jsonifyLog4j(ssh, "${jira.installation}/atlassian-jira/WEB-INF/classes/log4j.properties") - splunk.run(ssh, jira.name, "/home/ubuntu/jirahome/log") - return PassingStart(EmptyReport()) + splunk.run(ssh, jira.server.name, "/home/ubuntu/jirahome/log") } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt new file mode 100644 index 00000000..0ea7f794 --- /dev/null +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt @@ -0,0 +1,11 @@ +package com.atlassian.performance.tools.infrastructure.api.jira + +import com.atlassian.performance.tools.ssh.api.SshConnection + +class EmptyJiraHome : JiraHomeSource { + override fun download(ssh: SshConnection): String { + val jiraHome = "jira-home" + ssh.execute("mkdir $jiraHome") + return jiraHome + } +} diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/InstallableJiraIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt similarity index 57% rename from src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/InstallableJiraIT.kt rename to src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index 3e9cb6ae..c5f3675f 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/InstallableJiraIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -1,9 +1,13 @@ -package com.atlassian.performance.tools.infrastructure.api.jira +package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstallableJira +import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome +import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultInstall +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultJiraInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.HookedJiraInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack import com.atlassian.performance.tools.infrastructure.api.jvm.OracleJDK import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.ssh.api.SshConnection @@ -14,36 +18,41 @@ import java.io.File import java.nio.file.Files import java.util.function.Consumer -class InstallableJiraIT { +class HookedJiraStartIT { @Test - fun shouldFlowThroughAllSteps() { - val installHook = DefaultInstall(JiraNodeConfig.Builder().build()) - val formula = InstallableJira( - name = "test", + fun shouldStartJiraWithDefaultHooks() { + // given + val config = JiraNodeConfig.Builder().build() + val track = ReportTrack() + track.postStartHooks.add(DefaultPostStartHook()) + track.postInstallHooks.add(DefaultPostInstallHook(config)) + val jiraInstallation = HookedJiraInstallation(DefaultJiraInstallation( jiraHomeSource = EmptyJiraHome(), - installHook = installHook, productDistribution = PublicJiraSoftwareDistribution("7.13.0"), jdk = OracleJDK() - ) + )) + val jiraStart = HookedJiraStart(JiraLaunchScript()) val privatePort = 8080 val container = SshUbuntuContainer(Consumer { it.addExposedPort(privatePort) }) + // when val remoteReports = container.start().use { sshUbuntu -> val server = TcpServer( "localhost", sshUbuntu.container.getMappedPort(privatePort), - privatePort + privatePort, + "my-jira" ) val remoteReports = sshUbuntu.toSsh().newConnection().use { ssh -> - formula - .install(ssh, server) - .start(ssh) - .serve(ssh) - .report(ssh) + val installed = jiraInstallation.install(ssh, server, track) + jiraStart.start(ssh, installed, track) + track.reports.flatMap { it.locate(ssh) } } + + // then sshUbuntu.toSsh().newConnection().use { ssh -> download(remoteReports, ssh) } @@ -51,11 +60,11 @@ class InstallableJiraIT { } assertThat(remoteReports).contains( - "~/jpt-vmstat.log", - "~/jpt-iostat.log", + "./jpt-vmstat.log", + "./jpt-iostat.log", "jira-home/log/atlassian-jira.log", "./atlassian-jira-software-7.13.0-standalone/logs/catalina.out", - "~/jpt-jstat.log" + "./jpt-jstat.log" ) } @@ -65,17 +74,9 @@ class InstallableJiraIT { ): List { val downloads = Files.createTempDirectory("apt-infra-test") return remotes.map { remote -> - val path = downloads.resolve(remote) - ssh.download(remote, path) - return@map path.toFile() + val local = downloads.resolve("./$remote") + ssh.download(remote, local) + return@map local.toFile() } } } - -private class EmptyJiraHome : JiraHomeSource { - override fun download(ssh: SshConnection): String { - val jiraHome = "jira-home" - ssh.execute("mkdir $jiraHome") - return jiraHome - } -} From ce3b38aa6cb6bfc0ca65e2bb3b2817b0ff684504 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 5 Apr 2019 14:27:27 +0200 Subject: [PATCH 06/28] JPERF-273: Stop jira manually, because we can --- .../api/jira/flow/start/HookedJiraStartIT.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index c5f3675f..2ab3d257 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -3,6 +3,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultJiraInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook @@ -48,7 +49,8 @@ class HookedJiraStartIT { ) val remoteReports = sshUbuntu.toSsh().newConnection().use { ssh -> val installed = jiraInstallation.install(ssh, server, track) - jiraStart.start(ssh, installed, track) + val started = jiraStart.start(ssh, installed, track) + stop(started, ssh) track.reports.flatMap { it.locate(ssh) } } @@ -68,6 +70,14 @@ class HookedJiraStartIT { ) } + private fun stop( + started: StartedJira, + ssh: SshConnection + ) { + val installed = started.installed + ssh.execute("${installed.jdk.use()}; ${installed.installation}/bin/stop-jira.sh") + } + private fun download( remotes: List, ssh: SshConnection From f0326961305de08a2d7c8a28e08538399d7d839a Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Mon, 15 Apr 2019 11:24:06 +0200 Subject: [PATCH 07/28] Rename "track" to "flow" --- .../infrastructure/api/database/MySqlDatabase.kt | 6 +++--- .../{report/ReportTrack.kt => JiraNodeFlow.kt} | 5 +++-- .../api/jira/flow/install/AsyncProfilerHook.kt | 10 +++++----- .../jira/flow/install/DefaultJiraInstallation.kt | 4 ++-- .../jira/flow/install/DefaultPostInstallHook.kt | 6 +++--- .../api/jira/flow/install/DisabledAutoBackup.kt | 4 ++-- .../jira/flow/install/HookedJiraInstallation.kt | 10 +++++----- .../api/jira/flow/install/JiraHomeProperty.kt | 4 ++-- .../api/jira/flow/install/JiraInstallation.kt | 4 ++-- .../api/jira/flow/install/JvmConfig.kt | 6 +++--- .../api/jira/flow/install/PostInstallHook.kt | 4 ++-- .../jira/flow/install/PostInstallHookSequence.kt | 6 +++--- .../api/jira/flow/install/PreInstallHook.kt | 4 ++-- .../api/jira/flow/install/SystemLog.kt | 6 +++--- .../api/jira/flow/install/UbuntuSysstat.kt | 10 +++++----- .../api/jira/flow/start/AccessLogs.kt | 6 +++--- .../api/jira/flow/start/DefaultPostStartHook.kt | 6 +++--- .../api/jira/flow/start/HookedJiraStart.kt | 10 +++++----- .../api/jira/flow/start/JiraLaunchScript.kt | 4 ++-- .../infrastructure/api/jira/flow/start/JiraLogs.kt | 10 +++++----- .../api/jira/flow/start/JiraStart.kt | 4 ++-- .../api/jira/flow/start/JstatHook.kt | 6 +++--- .../api/jira/flow/start/PostStartHook.kt | 4 ++-- .../api/jira/flow/start/PreStartHook.kt | 4 ++-- .../api/jira/flow/start/RestUpgrade.kt | 6 +++--- .../jira/flow/install/ProfilerHook.kt | 10 +++++----- .../jira/flow/install/SplunkForwarderHook.kt | 4 ++-- .../api/jira/flow/start/HookedJiraStartIT.kt | 14 +++++++------- 28 files changed, 89 insertions(+), 88 deletions(-) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{report/ReportTrack.kt => JiraNodeFlow.kt} (89%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt index c1aa31e1..ca2aa12f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt @@ -6,7 +6,7 @@ import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHookSequence -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu import com.atlassian.performance.tools.jvmtasks.api.Backoff import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction @@ -83,7 +83,7 @@ private class MysqlConnector : PostInstallHook { override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" IdempotentAction( @@ -105,7 +105,7 @@ private class MysqlJdbc( override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { Sed().replace( connection = ssh, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportTrack.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt similarity index 89% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportTrack.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index a5d9225c..fbfed18a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/ReportTrack.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -1,14 +1,15 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.report +package com.atlassian.performance.tools.infrastructure.api.jira.flow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PreStartHook import net.jcip.annotations.ThreadSafe import java.util.concurrent.CopyOnWriteArrayList @ThreadSafe -class ReportTrack { +class JiraNodeFlow { val preInstallHooks: MutableList = CopyOnWriteArrayList() val postInstallHooks: MutableList = CopyOnWriteArrayList() diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt index d62c56ef..d26a7b81 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt @@ -3,7 +3,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI @@ -12,7 +12,7 @@ class AsyncProfilerHook : PreInstallHook { override fun hook( ssh: SshConnection, server: TcpServer, - track: ReportTrack + flow: JiraNodeFlow ) { val directory = "async-profiler" val downloads = URI("https://github.com/jvm-profiling-tools/async-profiler/releases/download/") @@ -24,7 +24,7 @@ class AsyncProfilerHook : PreInstallHook { ssh.execute("sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'") val profilerPath = "./$directory/profiler.sh" val profiler = InstalledAsyncProfiler(profilerPath) - track.postStartHooks.add(profiler) + flow.postStartHooks.add(profiler) } } @@ -36,11 +36,11 @@ private class InstalledAsyncProfiler( override fun hook( ssh: SshConnection, jira: StartedJira, - track: ReportTrack + flow: JiraNodeFlow ) { ssh.execute("$profilerPath -b 20000000 start ${jira.pid}") val profiler = StartedAsyncProfiler(jira.pid, profilerPath) - track.reports.add(profiler) + flow.reports.add(profiler) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt index df932996..c10c4f42 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt @@ -4,7 +4,7 @@ import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDi import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit import com.atlassian.performance.tools.ssh.api.SshConnection @@ -17,7 +17,7 @@ class DefaultJiraInstallation( override fun install( ssh: SshConnection, server: TcpServer, - track: ReportTrack + flow: JiraNodeFlow ): InstalledJira { val installation = productDistribution.install(ssh, ".") val home = jiraHomeSource.download(ssh) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt index 0f17be94..c4c38b22 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.jira.flow.install.ProfilerHook import com.atlassian.performance.tools.infrastructure.jira.flow.install.SplunkForwarderHook import com.atlassian.performance.tools.ssh.api.SshConnection @@ -14,7 +14,7 @@ class DefaultPostInstallHook( override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { listOf( JiraHomeProperty(), @@ -23,6 +23,6 @@ class DefaultPostInstallHook( ProfilerHook(config.profiler), SplunkForwarderHook(config.splunkForwarder), UbuntuSysstat() - ).forEach { it.hook(ssh, jira, track) } + ).forEach { it.hook(ssh, jira, flow) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt index b9958c1c..abb235c5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class DisabledAutoBackup : PostInstallHook { @@ -9,7 +9,7 @@ class DisabledAutoBackup : PostInstallHook { override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { ssh.execute("echo jira.autoexport=false > ${jira.home}/jira-config.properties") } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt index 6825309e..9434e81c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraInstallation( @@ -12,11 +12,11 @@ class HookedJiraInstallation( override fun install( ssh: SshConnection, server: TcpServer, - track: ReportTrack + flow: JiraNodeFlow ): InstalledJira { - track.preInstallHooks.forEach { it.hook(ssh, server, track) } - val installed = installation.install(ssh, server, track) - track.postInstallHooks.forEach { it.hook(ssh, installed, track) } + flow.preInstallHooks.forEach { it.hook(ssh, server, flow) } + val installed = installation.install(ssh, server, flow) + flow.postInstallHooks.forEach { it.hook(ssh, installed, flow) } return installed } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt index 997dc02c..9d768c15 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class JiraHomeProperty : PostInstallHook { @@ -9,7 +9,7 @@ class JiraHomeProperty : PostInstallHook { override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { val properties = "${jira.installation}/atlassian-jira/WEB-INF/classes/jira-application.properties" ssh.execute("echo jira.home=`realpath ${jira.home}` > $properties") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt index aa9826b9..40f31e6c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection interface JiraInstallation { @@ -10,6 +10,6 @@ interface JiraInstallation { fun install( ssh: SshConnection, server: TcpServer, - track: ReportTrack + flow: JiraNodeFlow ): InstalledJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt index c98954b5..3949e116 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt @@ -5,7 +5,7 @@ import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class JvmConfig( @@ -15,7 +15,7 @@ class JvmConfig( override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { val gcLog = JiraGcLog(jira.installation) SetenvSh(jira.installation).setup( @@ -25,6 +25,6 @@ class JvmConfig( jiraIp = jira.server.ip ) val report = FileListing(gcLog.path("*")) - track.reports.add(report) + flow.reports.add(report) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt index 55a05df4..60ab3d39 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt @@ -1,13 +1,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection interface PostInstallHook { fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt index 90a013e6..fc1fa4ce 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class PostInstallHookSequence( @@ -11,8 +11,8 @@ class PostInstallHookSequence( override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { - hooks.forEach { it.hook(ssh, jira, track) } + hooks.forEach { it.hook(ssh, jira, flow) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt index 04b71b35..13419de4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt @@ -1,13 +1,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection interface PreInstallHook { fun hook( ssh: SshConnection, server: TcpServer, - track: ReportTrack + flow: JiraNodeFlow ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt index bbeaed7c..7a2c74a7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt @@ -1,12 +1,12 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection class SystemLog : PreInstallHook { - override fun hook(ssh: SshConnection, server: TcpServer, track: ReportTrack) { - track.reports.add(StaticReport("/var/log/syslog")) + override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + flow.reports.add(StaticReport("/var/log/syslog")) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt index 3014c076..9dfb8908 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu @@ -14,12 +14,12 @@ class UbuntuSysstat : PostInstallHook { override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { val postStartHooks = Ubuntu() .metrics(ssh) .map { InstalledOsMetric(it) } - track.postStartHooks.addAll(postStartHooks) + flow.postStartHooks.addAll(postStartHooks) } } @@ -30,9 +30,9 @@ private class InstalledOsMetric( override fun hook( ssh: SshConnection, jira: StartedJira, - track: ReportTrack + flow: JiraNodeFlow ) { val process = metric.start(ssh) - track.reports.add(RemoteMonitoringProcessReport(process)) + flow.reports.add(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt index ec78542d..ee740f8a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt @@ -2,12 +2,12 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class AccessLogs : PostStartHook { - override fun hook(ssh: SshConnection, jira: StartedJira, track: ReportTrack) { - track.reports.add(FileListing("${jira.installed.installation}/logs/*access*")) + override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { + flow.reports.add(FileListing("${jira.installed.installation}/logs/*access*")) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt index bb8c68e3..262b3547 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultPostStartHook : PostStartHook { @@ -9,12 +9,12 @@ class DefaultPostStartHook : PostStartHook { override fun hook( ssh: SshConnection, jira: StartedJira, - track: ReportTrack + flow: JiraNodeFlow ) { listOf( JiraLogs(), JstatHook() //,RestUpgrade(config.launchTimeouts, "admin", "admin") TODO requires database to work - ).forEach { it.hook(ssh, jira, track) } + ).forEach { it.hook(ssh, jira, flow) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt index 0e40caf8..b7050651 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraStart( @@ -12,11 +12,11 @@ class HookedJiraStart( override fun start( ssh: SshConnection, installed: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ): StartedJira { - track.preStartHooks.forEach { it.hook(ssh, installed, track) } - val started = start.start(ssh, installed, track) - track.postStartHooks.forEach { it.hook(ssh, started, track) } + flow.preStartHooks.forEach { it.hook(ssh, installed, flow) } + val started = start.start(ssh, installed, flow) + flow.postStartHooks.forEach { it.hook(ssh, started, flow) } return started } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt index 47466229..1c3472de 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection import java.time.Duration @@ -11,7 +11,7 @@ class JiraLaunchScript : JiraStart { override fun start( ssh: SshConnection, installed: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ): StartedJira { ssh.execute( "${installed.jdk.use()}; ${installed.installation}/bin/start-jira.sh", diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt index 2127e3d7..6cff53cb 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt @@ -2,20 +2,20 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection class JiraLogs : PreStartHook, PostStartHook { - override fun hook(ssh: SshConnection, jira: InstalledJira, track: ReportTrack) { + override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { listOf( StaticReport("${jira.home}/log/atlassian-jira.log"), StaticReport("${jira.installation}/logs/catalina.out") - ).forEach { track.reports.add(it) } + ).forEach { flow.reports.add(it) } } - override fun hook(ssh: SshConnection, jira: StartedJira, track: ReportTrack) { - hook(ssh, jira.installed, track) + override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { + hook(ssh, jira.installed, flow) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt index b97cfcce..eacd518f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection interface JiraStart { @@ -10,6 +10,6 @@ interface JiraStart { fun start( ssh: SshConnection, installed: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ): StartedJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt index 65b39160..389189d5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection @@ -10,9 +10,9 @@ class JstatHook : PostStartHook { override fun hook( ssh: SshConnection, jira: StartedJira, - track: ReportTrack + flow: JiraNodeFlow ) { val process = jira.installed.jdk.jstatMonitoring.start(ssh, jira.pid) - track.reports.add(RemoteMonitoringProcessReport(process)) + flow.reports.add(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt index 5a57bd49..76b51df5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt @@ -1,13 +1,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection interface PostStartHook { fun hook( ssh: SshConnection, jira: StartedJira, - track: ReportTrack + flow: JiraNodeFlow ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt index 314b2532..af358eaa 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt @@ -1,13 +1,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection interface PreStartHook { fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt index b3d07a7c..6a847711 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump import com.atlassian.performance.tools.ssh.api.SshConnection @@ -16,11 +16,11 @@ class RestUpgrade( private val adminPassword: String ) : PostStartHook { - override fun hook(ssh: SshConnection, jira: StartedJira, track: ReportTrack) { + override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) val privatePort = jira.installed.server.privatePort val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:$privatePort/rest/api/2/upgrade") - track.reports.add(StaticReport("thread-dumps")) + flow.reports.add(StaticReport("thread-dumps")) waitForStatusToChange( statusQuo = "000", timeout = timeouts.offlineTimeout, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt index 5dd08d54..c6921480 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt @@ -3,7 +3,7 @@ package com.atlassian.performance.tools.infrastructure.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport @@ -16,9 +16,9 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class ProfilerHook( private val profiler: Profiler ) : PostInstallHook { - override fun hook(ssh: SshConnection, jira: InstalledJira, track: ReportTrack) { + override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { profiler.install(ssh) - track.postStartHooks.add(InstalledProfiler(profiler)) + flow.postStartHooks.add(InstalledProfiler(profiler)) } } @@ -29,11 +29,11 @@ private class InstalledProfiler( override fun hook( ssh: SshConnection, jira: StartedJira, - track: ReportTrack + flow: JiraNodeFlow ) { val process = profiler.start(ssh, jira.pid) if (process != null) { - track.reports.add(RemoteMonitoringProcessReport(process)) + flow.reports.add(RemoteMonitoringProcessReport(process)) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt index c9aa8761..4c75a9a9 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.splunk.SplunkForwarder import com.atlassian.performance.tools.ssh.api.SshConnection @@ -13,7 +13,7 @@ internal class SplunkForwarderHook( override fun hook( ssh: SshConnection, jira: InstalledJira, - track: ReportTrack + flow: JiraNodeFlow ) { splunk.jsonifyLog4j(ssh, "${jira.installation}/atlassian-jira/WEB-INF/classes/log4j.properties") splunk.run(ssh, jira.server.name, "/home/ubuntu/jirahome/log") diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index 2ab3d257..e7864792 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -8,7 +8,7 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultJiraInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.HookedJiraInstallation -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.ReportTrack +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jvm.OracleJDK import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.ssh.api.SshConnection @@ -25,9 +25,9 @@ class HookedJiraStartIT { fun shouldStartJiraWithDefaultHooks() { // given val config = JiraNodeConfig.Builder().build() - val track = ReportTrack() - track.postStartHooks.add(DefaultPostStartHook()) - track.postInstallHooks.add(DefaultPostInstallHook(config)) + val flow = JiraNodeFlow() + flow.postStartHooks.add(DefaultPostStartHook()) + flow.postInstallHooks.add(DefaultPostInstallHook(config)) val jiraInstallation = HookedJiraInstallation(DefaultJiraInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), @@ -48,10 +48,10 @@ class HookedJiraStartIT { "my-jira" ) val remoteReports = sshUbuntu.toSsh().newConnection().use { ssh -> - val installed = jiraInstallation.install(ssh, server, track) - val started = jiraStart.start(ssh, installed, track) + val installed = jiraInstallation.install(ssh, server, flow) + val started = jiraStart.start(ssh, installed, flow) stop(started, ssh) - track.reports.flatMap { it.locate(ssh) } + flow.reports.flatMap { it.locate(ssh) } } // then From 06bee9af30071a4002ee42faf82155095622214b Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Mon, 15 Apr 2019 11:25:58 +0200 Subject: [PATCH 08/28] Resolve DB TODO It's already possible to hook in DB installation from `InstallableDatabase`. --- .../api/jira/flow/install/DefaultJiraInstallation.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt index c10c4f42..b7152cdd 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt @@ -3,13 +3,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultJiraInstallation( - private val jiraHomeSource: JiraHomeSource, // TODO add database too, but how to handle databaseIp? Perhaps as a wrapper, which could be applied by the "DB installing" code? + private val jiraHomeSource: JiraHomeSource, private val productDistribution: ProductDistribution, private val jdk: JavaDevelopmentKit ) : JiraInstallation { From 336c27814aa349fe219a23d0ce73a8801199d4da Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Mon, 15 Apr 2019 13:17:38 +0200 Subject: [PATCH 09/28] Add DC hook --- .../api/jira/DataCenterNodeFormula.kt | 36 ------------------- .../infrastructure/api/jira/flow/TcpServer.kt | 13 ++++++- .../api/jira/flow/install/DataCenterHook.kt | 25 +++++++++++++ .../api/jira/flow/install/SystemLog.kt | 12 ------- .../api/jira/flow/report/SystemLog.kt | 10 ++++++ 5 files changed, 47 insertions(+), 49 deletions(-) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/SystemLog.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt deleted file mode 100644 index 07421c07..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/DataCenterNodeFormula.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira - -//internal class DataCenterNodeFormula( -// private val nodeIndex: Int, -// private val sharedHome: Future, -// private val base: NodeFormula -//) : NodeFormula by base { -// -// override fun provision(): StoppedNode { -// -// val provisionedNode = base.provision() -// val localSharedHome = sharedHome.get().localSharedHome -// -// provisionedNode.ssh.newConnection().use { -// sharedHome.get().mount(it) -// val jiraHome = provisionedNode.jiraHome -// -// it.execute("echo ehcache.object.port = 40011 >> $jiraHome/cluster.properties") -// it.execute("echo jira.node.id = node$nodeIndex >> $jiraHome/cluster.properties") -// it.execute("echo jira.shared.home = `realpath $localSharedHome` >> $jiraHome/cluster.properties") -// } -// -// return object : StoppedNode by provisionedNode { -// override fun start(): StartedNode { -// return provisionedNode.start().copy( -// name = name, -// analyticLogs = localSharedHome -// ) -// } -// -// override fun toString() = "node #$nodeIndex" -// } -// } -// -// override fun toString() = "node formula #$nodeIndex" -//} \ No newline at end of file diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt index 6bdc69b1..d541199e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt @@ -5,4 +5,15 @@ class TcpServer( val publicPort: Int, val privatePort: Int, val name: String -) +) { + constructor( + ip: String, + port: Int, + name: String + ) : this( + ip, + port, + port, + name + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt new file mode 100644 index 00000000..5bf86cb8 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt @@ -0,0 +1,25 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome +import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.ssh.api.SshConnection + +class DataCenterHook( + private val nodeId: String, + private val sharedHome: SharedHome +) : PostInstallHook { + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + flow: JiraNodeFlow + ) { + val localSharedHome = sharedHome.localSharedHome + sharedHome.mount(ssh) + val jiraHome = jira.home // TODO what's the difference between localSharedHome and jiraHome? should both be hookable? + ssh.execute("echo ehcache.object.port = 40011 >> $jiraHome/cluster.properties") + ssh.execute("echo jira.node.id = $nodeId >> $jiraHome/cluster.properties") + ssh.execute("echo jira.shared.home = `realpath $localSharedHome` >> $jiraHome/cluster.properties") + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt deleted file mode 100644 index 7a2c74a7..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SystemLog.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport -import com.atlassian.performance.tools.ssh.api.SshConnection - -class SystemLog : PreInstallHook { - override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { - flow.reports.add(StaticReport("/var/log/syslog")) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/SystemLog.kt new file mode 100644 index 00000000..56db9839 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/SystemLog.kt @@ -0,0 +1,10 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.report + +import com.atlassian.performance.tools.ssh.api.SshConnection + +class SystemLog : Report { + + override fun locate(ssh: SshConnection): List { + return StaticReport("/var/log/syslog").locate(ssh) + } +} From eec3e10723a06b23cb2c958b8f5594d0decc64c2 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Mon, 15 Apr 2019 18:02:28 +0200 Subject: [PATCH 10/28] Let hooks be hooked in at any later stage --- .../api/database/InstallableDatabase.kt | 4 +- .../api/database/MySqlDatabase.kt | 14 ++-- .../api/jira/flow/JiraNodeFlow.kt | 47 ++++++++++--- .../api/jira/flow/install/DataCenterHook.kt | 3 +- .../flow/install/DefaultJiraInstallation.kt | 1 - .../flow/install/DefaultPostInstallHook.kt | 4 +- .../jira/flow/install/DisabledAutoBackup.kt | 3 +- .../flow/install/HookedJiraInstallation.kt | 7 +- .../jira/flow/{ => install}/InstalledJira.kt | 3 +- ...ostInstallHook.kt => InstalledJiraHook.kt} | 13 +++- ...quence.kt => InstalledJiraHookSequence.kt} | 7 +- .../api/jira/flow/install/JiraHomeProperty.kt | 3 +- .../api/jira/flow/install/JiraInstallation.kt | 1 - .../jira/flow/{start => install}/JiraLogs.kt | 10 +-- .../api/jira/flow/install/JvmConfig.kt | 3 +- .../api/jira/flow/install/PreInstallHook.kt | 13 ---- .../{install => server}/AsyncProfilerHook.kt | 16 ++--- .../api/jira/flow/{ => server}/StartedJira.kt | 4 +- .../jira/flow/{report => server}/SystemLog.kt | 4 +- .../api/jira/flow/server/TcpServerHook.kt | 23 +++++++ .../flow/{install => server}/UbuntuSysstat.kt | 27 ++++---- .../api/jira/flow/start/AccessLogs.kt | 4 +- ...StartHook.kt => DefaultStartedJiraHook.kt} | 5 +- .../api/jira/flow/start/HookedJiraStart.kt | 8 +-- .../api/jira/flow/start/JiraLaunchScript.kt | 4 +- .../api/jira/flow/start/JiraStart.kt | 4 +- .../api/jira/flow/start/JstatHook.kt | 4 +- .../api/jira/flow/start/PreStartHook.kt | 13 ---- .../api/jira/flow/start/RestUpgrade.kt | 4 +- .../{PostStartHook.kt => StartedJiraHook.kt} | 4 +- .../jira/flow/install/ProfilerHook.kt | 18 ++--- .../jira/flow/install/SplunkForwarderHook.kt | 6 +- .../api/jira/flow/start/HookedJiraStartIT.kt | 68 ++++++++++++++++--- 33 files changed, 214 insertions(+), 138 deletions(-) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{ => install}/InstalledJira.kt (75%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/{PostInstallHook.kt => InstalledJiraHook.kt} (54%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/{PostInstallHookSequence.kt => InstalledJiraHookSequence.kt} (68%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{start => install}/JiraLogs.kt (62%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{install => server}/AsyncProfilerHook.kt (89%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{ => server}/StartedJira.kt (57%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{report => server}/SystemLog.kt (60%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/{install => server}/UbuntuSysstat.kt (61%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/{DefaultPostStartHook.kt => DefaultStartedJiraHook.kt} (79%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/{PostStartHook.kt => StartedJiraHook.kt} (88%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt index 038bb75a..bb2e38c3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.database -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook interface InstallableDatabase : Database { - fun installInJira(databaseIp: String): PostInstallHook + fun installInJira(databaseIp: String): InstalledJiraHook } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt index ca2aa12f..a2ffa764 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt @@ -3,9 +3,9 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.DockerImage import com.atlassian.performance.tools.infrastructure.api.Sed import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHookSequence +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHookSequence import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu import com.atlassian.performance.tools.jvmtasks.api.Backoff @@ -70,15 +70,15 @@ class MySqlDatabase( } } - override fun installInJira(databaseIp: String): PostInstallHook { - return PostInstallHookSequence(listOf( + override fun installInJira(databaseIp: String): InstalledJiraHook { + return InstalledJiraHookSequence(listOf( MysqlJdbc(databaseIp), MysqlConnector() )) } } -private class MysqlConnector : PostInstallHook { +private class MysqlConnector : InstalledJiraHook { override fun hook( ssh: SshConnection, @@ -100,7 +100,7 @@ private class MysqlConnector : PostInstallHook { private class MysqlJdbc( private val databaseIp: String -) : PostInstallHook { +) : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index fbfed18a..d368f960 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -1,19 +1,50 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PreStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook import net.jcip.annotations.ThreadSafe import java.util.concurrent.CopyOnWriteArrayList @ThreadSafe class JiraNodeFlow { - val preInstallHooks: MutableList = CopyOnWriteArrayList() - val postInstallHooks: MutableList = CopyOnWriteArrayList() - val preStartHooks: MutableList = CopyOnWriteArrayList() - val postStartHooks: MutableList = CopyOnWriteArrayList() + private val tcpServerHooks: MutableList = CopyOnWriteArrayList() + private val installedJiraHooks: MutableList = CopyOnWriteArrayList() + private val preStartHooks: MutableList = CopyOnWriteArrayList() + private val postStartHooks: MutableList = CopyOnWriteArrayList() val reports: MutableList = CopyOnWriteArrayList() + + fun hookPreInstall( + hook: TcpServerHook + ) { + tcpServerHooks.add(hook) + } + + fun listPreInstallHooks(): Iterable = tcpServerHooks + + fun hookPostInstall( + hook: InstalledJiraHook + ) { + installedJiraHooks.add(hook) + } + + fun listPostInstallHooks(): Iterable = installedJiraHooks + + fun hookPreStart( + hook: InstalledJiraHook + ) { + preStartHooks.add(hook) + } + + fun listPreStartHooks(): Iterable = preStartHooks + + fun hookPostStart( + hook: StartedJiraHook + ) { + postStartHooks.add(hook) + } + + fun listPostStartHooks(): Iterable = postStartHooks } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt index 5bf86cb8..8256fdb5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt @@ -1,14 +1,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class DataCenterHook( private val nodeId: String, private val sharedHome: SharedHome -) : PostInstallHook { +) : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt index b7152cdd..111fd70a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt @@ -2,7 +2,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt index c4c38b22..27614423 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt @@ -1,15 +1,15 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.UbuntuSysstat import com.atlassian.performance.tools.infrastructure.jira.flow.install.ProfilerHook import com.atlassian.performance.tools.infrastructure.jira.flow.install.SplunkForwarderHook import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultPostInstallHook( private val config: JiraNodeConfig -) : PostInstallHook { +) : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt index abb235c5..4798919d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt @@ -1,10 +1,9 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection -class DisabledAutoBackup : PostInstallHook { +class DisabledAutoBackup : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt index 9434e81c..5d87c803 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt @@ -1,8 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraInstallation( @@ -14,9 +13,9 @@ class HookedJiraInstallation( server: TcpServer, flow: JiraNodeFlow ): InstalledJira { - flow.preInstallHooks.forEach { it.hook(ssh, server, flow) } + flow.listPreInstallHooks().forEach { it.hook(ssh, server, flow) } val installed = installation.install(ssh, server, flow) - flow.postInstallHooks.forEach { it.hook(ssh, installed, flow) } + flow.listPostInstallHooks().forEach { it.hook(ssh, installed, flow) } return installed } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt similarity index 75% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt index 6bd4df9d..05a3e64d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt @@ -1,5 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit class InstalledJira( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt similarity index 54% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt index 60ab3d39..7bb44785 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt @@ -1,13 +1,22 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook import com.atlassian.performance.tools.ssh.api.SshConnection -interface PostInstallHook { +interface InstalledJiraHook : StartedJiraHook { fun hook( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow ) + + override fun hook( + ssh: SshConnection, + jira: StartedJira, + flow: JiraNodeFlow + ) { + hook(ssh, jira.installed, flow) + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHookSequence.kt similarity index 68% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHookSequence.kt index fc1fa4ce..174317eb 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHookSequence.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHookSequence.kt @@ -1,12 +1,11 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection -class PostInstallHookSequence( - private val hooks: List -) : PostInstallHook { +class InstalledJiraHookSequence( + private val hooks: List +) : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt index 9d768c15..aa1d764c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt @@ -1,10 +1,9 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection -class JiraHomeProperty : PostInstallHook { +class JiraHomeProperty : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt index 40f31e6c..6a54191d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt @@ -1,6 +1,5 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt similarity index 62% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt index 6cff53cb..4266e363 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt @@ -1,12 +1,10 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection -class JiraLogs : PreStartHook, PostStartHook { +class JiraLogs : InstalledJiraHook { override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { listOf( @@ -14,8 +12,4 @@ class JiraLogs : PreStartHook, PostStartHook { StaticReport("${jira.installation}/logs/catalina.out") ).forEach { flow.reports.add(it) } } - - override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { - hook(ssh, jira.installed, flow) - } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt index 3949e116..63852750 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt @@ -3,14 +3,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class JvmConfig( private val config: JiraNodeConfig -) : PostInstallHook { +) : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt deleted file mode 100644 index 13419de4..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PreInstallHook.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.ssh.api.SshConnection - -interface PreInstallHook { - fun hook( - ssh: SshConnection, - server: TcpServer, - flow: JiraNodeFlow - ) -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt similarity index 89% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt index d26a7b81..555f4027 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt @@ -1,14 +1,14 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.flow.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI -class AsyncProfilerHook : PreInstallHook { +class AsyncProfilerHook : TcpServerHook { + override fun hook( ssh: SshConnection, server: TcpServer, @@ -24,14 +24,13 @@ class AsyncProfilerHook : PreInstallHook { ssh.execute("sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'") val profilerPath = "./$directory/profiler.sh" val profiler = InstalledAsyncProfiler(profilerPath) - flow.postStartHooks.add(profiler) + flow.hookPostStart(profiler) } - } private class InstalledAsyncProfiler( private val profilerPath: String -) : PostStartHook { +) : StartedJiraHook { override fun hook( ssh: SshConnection, @@ -48,6 +47,7 @@ private class StartedAsyncProfiler( private val pid: Int, private val profilerPath: String ) : Report { + override fun locate(ssh: SshConnection): List { val flameGraphFile = "flamegraph.svg" ssh.execute("$profilerPath stop $pid -o svg > $flameGraphFile") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartedJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/StartedJira.kt similarity index 57% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartedJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/StartedJira.kt index 582de84a..0dc47371 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/StartedJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/StartedJira.kt @@ -1,4 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.flow.server + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira class StartedJira( val installed: InstalledJira, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/SystemLog.kt similarity index 60% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/SystemLog.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/SystemLog.kt index 56db9839..7885f01f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/SystemLog.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/SystemLog.kt @@ -1,5 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.report +package com.atlassian.performance.tools.infrastructure.api.jira.flow.server +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection class SystemLog : Report { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt new file mode 100644 index 00000000..63c3588b --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt @@ -0,0 +1,23 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.server + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.ssh.api.SshConnection + +interface TcpServerHook : InstalledJiraHook { + fun hook( + ssh: SshConnection, + server: TcpServer, + flow: JiraNodeFlow + ) + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + flow: JiraNodeFlow + ) { + hook(ssh, jira.server, flow) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt similarity index 61% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt index 9dfb8908..90957535 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/UbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt @@ -1,37 +1,34 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.flow.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.Iostat import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.infrastructure.api.os.Vmstat import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection -class UbuntuSysstat : PostInstallHook { +class UbuntuSysstat : TcpServerHook { override fun hook( ssh: SshConnection, - jira: InstalledJira, + server: TcpServer, flow: JiraNodeFlow ) { - val postStartHooks = Ubuntu() - .metrics(ssh) + val ubuntu = Ubuntu() + ubuntu.install(ssh, listOf("sysstat")) + listOf(Vmstat(), Iostat()) .map { InstalledOsMetric(it) } - flow.postStartHooks.addAll(postStartHooks) + .forEach { flow.hookPostStart(it) } } } private class InstalledOsMetric( private val metric: OsMetric -) : PostStartHook { +) : TcpServerHook { - override fun hook( - ssh: SshConnection, - jira: StartedJira, - flow: JiraNodeFlow - ) { + override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { val process = metric.start(ssh) flow.reports.add(RemoteMonitoringProcessReport(process)) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt index ee740f8a..167be630 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt @@ -1,11 +1,11 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection -class AccessLogs : PostStartHook { +class AccessLogs : StartedJiraHook { override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { flow.reports.add(FileListing("${jira.installed.installation}/logs/*access*")) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt similarity index 79% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt index 262b3547..95c9c384 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt @@ -1,10 +1,11 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.JiraLogs +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection -class DefaultPostStartHook : PostStartHook { +class DefaultStartedJiraHook : StartedJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt index b7050651..61cb0820 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraStart( @@ -14,9 +14,9 @@ class HookedJiraStart( installed: InstalledJira, flow: JiraNodeFlow ): StartedJira { - flow.preStartHooks.forEach { it.hook(ssh, installed, flow) } + flow.listPreStartHooks().forEach { it.hook(ssh, installed, flow) } val started = start.start(ssh, installed, flow) - flow.postStartHooks.forEach { it.hook(ssh, started, flow) } + flow.listPostStartHooks().forEach { it.hook(ssh, started, flow) } return started } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt index 1c3472de..90e66907 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection import java.time.Duration diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt index eacd518f..829f6853 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection interface JiraStart { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt index 389189d5..3ebbc38c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt @@ -1,11 +1,11 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection -class JstatHook : PostStartHook { +class JstatHook : StartedJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt deleted file mode 100644 index af358eaa..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PreStartHook.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.ssh.api.SshConnection - -interface PreStartHook { - fun hook( - ssh: SshConnection, - jira: InstalledJira, - flow: JiraNodeFlow - ) -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt index 6a847711..484f998e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt @@ -1,9 +1,9 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI @@ -14,7 +14,7 @@ class RestUpgrade( private val timeouts: JiraLaunchTimeouts, private val adminUsername: String, private val adminPassword: String -) : PostStartHook { +) : StartedJiraHook { override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt similarity index 88% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt index 76b51df5..8e105ee1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt @@ -1,10 +1,10 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection -interface PostStartHook { +interface StartedJiraHook { fun hook( ssh: SshConnection, jira: StartedJira, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt index c6921480..01a78de4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt @@ -1,30 +1,30 @@ package com.atlassian.performance.tools.infrastructure.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection /** - * Bridges the [Profiler] SPI with the [PostInstallHook] SPI. - * In general any [Profiler] can be rewritten as an [PostInstallHook] or any other hook without this bridge. + * Bridges the [Profiler] SPI with the [InstalledJiraHook] SPI. + * In general any [Profiler] can be rewritten as an [InstalledJiraHook] or any other hookPreStart without this bridge. */ class ProfilerHook( private val profiler: Profiler -) : PostInstallHook { +) : InstalledJiraHook { override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { profiler.install(ssh) - flow.postStartHooks.add(InstalledProfiler(profiler)) + flow.hookPostStart(InstalledProfiler(profiler)) } } private class InstalledProfiler( private val profiler: Profiler -) : PostStartHook { +) : StartedJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt index 4c75a9a9..178f5aba 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt @@ -1,14 +1,14 @@ package com.atlassian.performance.tools.infrastructure.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.splunk.SplunkForwarder import com.atlassian.performance.tools.ssh.api.SshConnection internal class SplunkForwarderHook( private val splunk: SplunkForwarder -) : PostInstallHook { +) : InstalledJiraHook { override fun hook( ssh: SshConnection, diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index e7864792..c97bafa5 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -3,12 +3,12 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.flow.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultJiraInstallation -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.HookedJiraInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.* +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.UbuntuSysstat import com.atlassian.performance.tools.infrastructure.api.jvm.OracleJDK import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.ssh.api.SshConnection @@ -26,8 +26,8 @@ class HookedJiraStartIT { // given val config = JiraNodeConfig.Builder().build() val flow = JiraNodeFlow() - flow.postStartHooks.add(DefaultPostStartHook()) - flow.postInstallHooks.add(DefaultPostInstallHook(config)) + flow.hookPostStart(DefaultStartedJiraHook()) + flow.hookPostInstall(DefaultPostInstallHook(config)) val jiraInstallation = HookedJiraInstallation(DefaultJiraInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), @@ -38,8 +38,6 @@ class HookedJiraStartIT { val container = SshUbuntuContainer(Consumer { it.addExposedPort(privatePort) }) - - // when val remoteReports = container.start().use { sshUbuntu -> val server = TcpServer( "localhost", @@ -48,6 +46,7 @@ class HookedJiraStartIT { "my-jira" ) val remoteReports = sshUbuntu.toSsh().newConnection().use { ssh -> + // when val installed = jiraInstallation.install(ssh, server, flow) val started = jiraStart.start(ssh, installed, flow) stop(started, ssh) @@ -70,6 +69,47 @@ class HookedJiraStartIT { ) } + @Test + fun shouldDownloadPartialReportsInCaseOfFailure() { + // given + val flow = JiraNodeFlow() + val sysstat = UbuntuSysstat() + flow.hookPreInstall(sysstat) + flow.hookPreInstall(FailingHook()) + val jiraInstallation = HookedJiraInstallation(DefaultJiraInstallation( + jiraHomeSource = EmptyJiraHome(), + productDistribution = PublicJiraSoftwareDistribution("7.13.0"), + jdk = OracleJDK() + )) + val privatePort = 8080 + val container = SshUbuntuContainer(Consumer { + it.addExposedPort(privatePort) + }) + val remoteReports = container.start().use { sshUbuntu -> + val server = TcpServer( + "localhost", + sshUbuntu.container.getMappedPort(privatePort), + privatePort, + "my-jira" + ) + return@use sshUbuntu.toSsh().newConnection().use useSsh@{ ssh -> + // when + try { + jiraInstallation.install(ssh, server, flow) + } catch (e: Exception) { + println("Failed: ${e.message}") + } + return@useSsh flow.reports.flatMap { it.locate(ssh) } + } + } + + // then + assertThat(remoteReports).contains( + "./jpt-vmstat.log", + "./jpt-iostat.log" + ) + } + private fun stop( started: StartedJira, ssh: SshConnection @@ -90,3 +130,13 @@ class HookedJiraStartIT { } } } + +private class FailingHook : TcpServerHook, InstalledJiraHook { + override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + throw Exception("Failed") + } + + override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { + throw Exception("Failed") + } +} From 2e3a2a9710441b66d6e8077fec11d4c430fc93a5 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Tue, 2 Jul 2019 17:48:15 +0200 Subject: [PATCH 11/28] JPERF-273: Offer DB-related Jira hooks --- .../api/database/DatabaseIpConfig.kt | 25 ++++++++ .../api/database/InstallableDatabase.kt | 8 --- .../api/database/MySqlDatabase.kt | 61 +------------------ .../api/database/MysqlConnector.kt | 35 +++++++++++ .../api/jira/flow/JiraNodeFlow.kt | 12 ++-- .../jira/flow/start/DefaultStartedJiraHook.kt | 9 ++- 6 files changed, 74 insertions(+), 76 deletions(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt new file mode 100644 index 00000000..ff3a49a2 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt @@ -0,0 +1,25 @@ +package com.atlassian.performance.tools.infrastructure.api.database + +import com.atlassian.performance.tools.infrastructure.api.Sed +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.ssh.api.SshConnection + +class DatabaseIpConfig( + private val databaseIp: String +) : InstalledJiraHook { + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + flow: JiraNodeFlow + ) { + Sed().replace( + connection = ssh, + expression = "(.*(@(//)?|//))" + "([^:/]+)" + "(.*)", + output = """\1$databaseIp\5""", + file = "${jira.home}/dbconfig.xml" + ) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt deleted file mode 100644 index bb2e38c3..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/InstallableDatabase.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.database - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook - -interface InstallableDatabase : Database { - - fun installInJira(databaseIp: String): InstalledJiraHook -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt index a2ffa764..965ef55c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MySqlDatabase.kt @@ -1,15 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.DockerImage -import com.atlassian.performance.tools.infrastructure.api.Sed import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHookSequence -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu -import com.atlassian.performance.tools.jvmtasks.api.Backoff -import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger @@ -23,8 +16,7 @@ import java.time.Instant class MySqlDatabase( private val source: DatasetPackage, private val maxConnections: Int -) : InstallableDatabase { - +) : Database { private val logger: Logger = LogManager.getLogger(this::class.java) private val image: DockerImage = DockerImage( @@ -69,55 +61,4 @@ class MySqlDatabase( Thread.sleep(Duration.ofSeconds(10).toMillis()) } } - - override fun installInJira(databaseIp: String): InstalledJiraHook { - return InstalledJiraHookSequence(listOf( - MysqlJdbc(databaseIp), - MysqlConnector() - )) - } -} - -private class MysqlConnector : InstalledJiraHook { - - override fun hook( - ssh: SshConnection, - jira: InstalledJira, - flow: JiraNodeFlow - ) { - val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" - IdempotentAction( - description = "Download MySQL connector", - action = { ssh.execute("wget -q $connector") } - ).retry( - maxAttempts = 3, - backoff = StaticBackoff(Duration.ofSeconds(5)) - ) - ssh.execute("tar -xzf mysql-connector-java-5.1.40.tar.gz") - ssh.execute("cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar ${jira.installation}/lib") - } -} - -private class MysqlJdbc( - private val databaseIp: String -) : InstalledJiraHook { - - override fun hook( - ssh: SshConnection, - jira: InstalledJira, - flow: JiraNodeFlow - ) { - Sed().replace( - connection = ssh, - expression = "(.*(@(//)?|//))" + "([^:/]+)" + "(.*)", - output = """\1$databaseIp\5""", - file = "${jira.home}/dbconfig.xml" - ) - } -} - -private class StaticBackoff( - private val backOff: Duration -) : Backoff { - override fun backOff(attempt: Int): Duration = backOff } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt new file mode 100644 index 00000000..7a4844f8 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt @@ -0,0 +1,35 @@ +package com.atlassian.performance.tools.infrastructure.api.database + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.jvmtasks.api.Backoff +import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.time.Duration + +class MysqlConnector : InstalledJiraHook { + + override fun hook( + ssh: SshConnection, + jira: InstalledJira, + flow: JiraNodeFlow + ) { + val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" + IdempotentAction( + description = "Download MySQL connector", + action = { ssh.execute("wget -q $connector") } + ).retry( + maxAttempts = 3, + backoff = StaticBackoff(Duration.ofSeconds(5)) + ) + ssh.execute("tar -xzf mysql-connector-java-5.1.40.tar.gz") + ssh.execute("cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar ${jira.installation}/lib") + } +} + +private class StaticBackoff( + private val backOff: Duration +) : Backoff { + override fun backOff(attempt: Int): Duration = backOff +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index d368f960..fe62c365 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook import net.jcip.annotations.ThreadSafe import java.util.concurrent.CopyOnWriteArrayList @@ -10,11 +10,11 @@ import java.util.concurrent.CopyOnWriteArrayList @ThreadSafe class JiraNodeFlow { - private val tcpServerHooks: MutableList = CopyOnWriteArrayList() - private val installedJiraHooks: MutableList = CopyOnWriteArrayList() - private val preStartHooks: MutableList = CopyOnWriteArrayList() - private val postStartHooks: MutableList = CopyOnWriteArrayList() - val reports: MutableList = CopyOnWriteArrayList() + private val tcpServerHooks: MutableList = CopyOnWriteArrayList() + private val installedJiraHooks: MutableList = CopyOnWriteArrayList() + private val preStartHooks: MutableList = CopyOnWriteArrayList() + private val postStartHooks: MutableList = CopyOnWriteArrayList() + val reports: MutableList = CopyOnWriteArrayList() fun hookPreInstall( hook: TcpServerHook diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt index 95c9c384..15fa3f61 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.JiraLogs import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira @@ -14,8 +15,12 @@ class DefaultStartedJiraHook : StartedJiraHook { ) { listOf( JiraLogs(), - JstatHook() - //,RestUpgrade(config.launchTimeouts, "admin", "admin") TODO requires database to work + JstatHook(), + RestUpgrade( + JiraLaunchTimeouts.Builder().build(), + "admin", + "admin" + ) ).forEach { it.hook(ssh, jira, flow) } } } From d129d08fef028ad05217188ed244836a1fba4f23 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Thu, 4 Jul 2019 16:15:36 +0200 Subject: [PATCH 12/28] JPERF-273: Test `JiraNodeFlow` concurrency --- .../infrastructure/api/jira/EmptyJiraHome.kt | 0 .../api/jira/flow/JiraNodeFlow.kt | 8 +- .../api/jira/flow/install/InstalledJira.kt | 6 ++ .../flow/install/InstalledJiraHookSequence.kt | 17 ---- .../api/jira/flow/install/JiraInstallation.kt | 4 +- .../jira/flow/start/DefaultStartedJiraHook.kt | 8 +- .../api/jira/flow/start/JiraStart.kt | 4 +- .../api/jira/flow/JiraNodeFlowTest.kt | 78 +++++++++++++++++++ 8 files changed, 95 insertions(+), 30 deletions(-) rename src/{test => main}/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt (100%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHookSequence.kt create mode 100644 src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt similarity index 100% rename from src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/EmptyJiraHome.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index fe62c365..7b29ed8f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -22,7 +22,7 @@ class JiraNodeFlow { tcpServerHooks.add(hook) } - fun listPreInstallHooks(): Iterable = tcpServerHooks + internal fun listPreInstallHooks(): Iterable = tcpServerHooks fun hookPostInstall( hook: InstalledJiraHook @@ -30,7 +30,7 @@ class JiraNodeFlow { installedJiraHooks.add(hook) } - fun listPostInstallHooks(): Iterable = installedJiraHooks + internal fun listPostInstallHooks(): Iterable = installedJiraHooks fun hookPreStart( hook: InstalledJiraHook @@ -38,7 +38,7 @@ class JiraNodeFlow { preStartHooks.add(hook) } - fun listPreStartHooks(): Iterable = preStartHooks + internal fun listPreStartHooks(): Iterable = preStartHooks fun hookPostStart( hook: StartedJiraHook @@ -46,5 +46,5 @@ class JiraNodeFlow { postStartHooks.add(hook) } - fun listPostStartHooks(): Iterable = postStartHooks + internal fun listPostStartHooks(): Iterable = postStartHooks } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt index 05a3e64d..86a0c49a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt @@ -4,7 +4,13 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit class InstalledJira( + /** + * E.g. it contains `./dbconfig.xml` + */ val home: String, + /** + * E.g. it contains `./conf/server.xml` + */ val installation: String, val jdk: JavaDevelopmentKit, val server: TcpServer diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHookSequence.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHookSequence.kt deleted file mode 100644 index 174317eb..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHookSequence.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.ssh.api.SshConnection - -class InstalledJiraHookSequence( - private val hooks: List -) : InstalledJiraHook { - - override fun hook( - ssh: SshConnection, - jira: InstalledJira, - flow: JiraNodeFlow - ) { - hooks.forEach { it.hook(ssh, jira, flow) } - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt index 6a54191d..16d30a2c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt @@ -1,9 +1,11 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection +import net.jcip.annotations.ThreadSafe +@ThreadSafe interface JiraInstallation { fun install( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt index 15fa3f61..9e1d8b89 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt @@ -1,6 +1,5 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.JiraLogs import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira @@ -15,12 +14,7 @@ class DefaultStartedJiraHook : StartedJiraHook { ) { listOf( JiraLogs(), - JstatHook(), - RestUpgrade( - JiraLaunchTimeouts.Builder().build(), - "admin", - "admin" - ) + JstatHook() ).forEach { it.hook(ssh, jira, flow) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt index 829f6853..7f913ef7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt @@ -1,10 +1,12 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection +import net.jcip.annotations.ThreadSafe +@ThreadSafe interface JiraStart { fun start( diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt new file mode 100644 index 00000000..605f62e8 --- /dev/null +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt @@ -0,0 +1,78 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook +import com.atlassian.performance.tools.ssh.api.DetachedProcess +import com.atlassian.performance.tools.ssh.api.SshConnection +import org.apache.logging.log4j.Level +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import java.io.File +import java.nio.file.Path +import java.time.Duration + +class JiraNodeFlowTest { + + @Test + fun shouldHookDuringListing() { + val counter = CountingHook() + val flow = JiraNodeFlow().apply { + hookPreInstall(counter) + hookPreInstall(HookingHook(counter)) + hookPreInstall(counter) + } + val server = TcpServer("doesn't matter", 123, "fake-server") + + flow.listPreInstallHooks().forEach { + it.hook(FailingSshConnection(), server, flow) + } + + assertThat(counter.count).isEqualTo(3) + } +} + +private class CountingHook : TcpServerHook { + + var count = 0 + + override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + count++ + } +} + +private class HookingHook( + private val hook: TcpServerHook +) : TcpServerHook { + override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + flow.hookPreInstall(hook) + } +} + +private class FailingSshConnection : SshConnection { + override fun close() { + throw Exception("unexpected call") + } + + override fun download(remoteSource: String, localDestination: Path) { + throw Exception("unexpected call") + } + + override fun execute(cmd: String, timeout: Duration, stdout: Level, stderr: Level): SshConnection.SshResult { + throw Exception("unexpected call") + } + + override fun safeExecute(cmd: String, timeout: Duration, stdout: Level, stderr: Level): SshConnection.SshResult { + throw Exception("unexpected call") + } + + override fun startProcess(cmd: String): DetachedProcess { + throw Exception("unexpected call") + } + + override fun stopProcess(process: DetachedProcess) { + throw Exception("unexpected call") + } + + override fun upload(localSource: File, remoteDestination: String) { + throw Exception("unexpected call") + } +} From 58ba182fc7e073fe9e11ce6f790b7cb5cb8d9418 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Thu, 4 Jul 2019 17:00:51 +0200 Subject: [PATCH 13/28] JPERF-273: Fix `JiraNodeFlowTest.shouldHookDuringListing` --- .../api/jira/flow/JiraNodeFlow.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index 7b29ed8f..4a220cd4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -5,32 +5,33 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Repor import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook import net.jcip.annotations.ThreadSafe -import java.util.concurrent.CopyOnWriteArrayList +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue @ThreadSafe class JiraNodeFlow { - private val tcpServerHooks: MutableList = CopyOnWriteArrayList() - private val installedJiraHooks: MutableList = CopyOnWriteArrayList() - private val preStartHooks: MutableList = CopyOnWriteArrayList() - private val postStartHooks: MutableList = CopyOnWriteArrayList() - val reports: MutableList = CopyOnWriteArrayList() + private val preInstallHooks: Queue = ConcurrentLinkedQueue() + private val postInstallHooks: Queue = ConcurrentLinkedQueue() + private val preStartHooks: Queue = ConcurrentLinkedQueue() + private val postStartHooks: Queue = ConcurrentLinkedQueue() + val reports: Queue = ConcurrentLinkedQueue() fun hookPreInstall( hook: TcpServerHook ) { - tcpServerHooks.add(hook) + preInstallHooks.add(hook) } - internal fun listPreInstallHooks(): Iterable = tcpServerHooks + internal fun listPreInstallHooks(): Iterable = preInstallHooks fun hookPostInstall( hook: InstalledJiraHook ) { - installedJiraHooks.add(hook) + postInstallHooks.add(hook) } - internal fun listPostInstallHooks(): Iterable = installedJiraHooks + internal fun listPostInstallHooks(): Iterable = postInstallHooks fun hookPreStart( hook: InstalledJiraHook From 1984d8e901c305e2163cf098a8527d2073ce3db3 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Thu, 4 Jul 2019 18:33:00 +0200 Subject: [PATCH 14/28] JPERF-273: Add `ParallelInstallation` --- .../jira/flow/install/ParallelInstallation.kt | 39 +++++++++++++++++++ ...tallation.kt => SequentialInstallation.kt} | 2 +- .../api/jira/flow/start/HookedJiraStartIT.kt | 4 +- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ParallelInstallation.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/{DefaultJiraInstallation.kt => SequentialInstallation.kt} (97%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ParallelInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ParallelInstallation.kt new file mode 100644 index 00000000..7b448761 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ParallelInstallation.kt @@ -0,0 +1,39 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.concurrency.api.submitWithLogContext +import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution +import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.util.concurrent.Executors + +class ParallelInstallation( + private val jiraHomeSource: JiraHomeSource, + private val productDistribution: ProductDistribution, + private val jdk: JavaDevelopmentKit +) : JiraInstallation { + + override fun install( + ssh: SshConnection, + server: TcpServer, + flow: JiraNodeFlow + ): InstalledJira { + val pool = Executors.newCachedThreadPool { runnable -> + Thread(runnable, "jira-installation-${runnable.hashCode()}") + } + val product = pool.submitWithLogContext("product") { + productDistribution.install(ssh, ".") + } + val home = pool.submitWithLogContext("home") { + jiraHomeSource.download(ssh) + } + val java = pool.submitWithLogContext("java") { + jdk.also { it.install(ssh) } + } + val jira = InstalledJira(home.get(), product.get(), java.get(), server) + pool.shutdownNow() + return jira + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SequentialInstallation.kt similarity index 97% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SequentialInstallation.kt index 111fd70a..853dc84c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SequentialInstallation.kt @@ -7,7 +7,7 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit import com.atlassian.performance.tools.ssh.api.SshConnection -class DefaultJiraInstallation( +class SequentialInstallation( private val jiraHomeSource: JiraHomeSource, private val productDistribution: ProductDistribution, private val jdk: JavaDevelopmentKit diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index c97bafa5..cf4aa8d5 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -28,7 +28,7 @@ class HookedJiraStartIT { val flow = JiraNodeFlow() flow.hookPostStart(DefaultStartedJiraHook()) flow.hookPostInstall(DefaultPostInstallHook(config)) - val jiraInstallation = HookedJiraInstallation(DefaultJiraInstallation( + val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), jdk = OracleJDK() @@ -76,7 +76,7 @@ class HookedJiraStartIT { val sysstat = UbuntuSysstat() flow.hookPreInstall(sysstat) flow.hookPreInstall(FailingHook()) - val jiraInstallation = HookedJiraInstallation(DefaultJiraInstallation( + val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), jdk = OracleJDK() From 7192b70c4f0cfb06a11882947172f8d8cc12f751 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 5 Jul 2019 11:44:52 +0200 Subject: [PATCH 15/28] JPERF-273: Distinguish running hooks from hooking them in --- .../tools/infrastructure/api/database/DatabaseIpConfig.kt | 2 +- .../tools/infrastructure/api/database/MysqlConnector.kt | 2 +- .../infrastructure/api/jira/flow/install/DataCenterHook.kt | 2 +- .../api/jira/flow/install/DefaultPostInstallHook.kt | 4 ++-- .../api/jira/flow/install/DisabledAutoBackup.kt | 2 +- .../api/jira/flow/install/HookedJiraInstallation.kt | 4 ++-- .../api/jira/flow/install/InstalledJiraHook.kt | 7 ++++--- .../api/jira/flow/install/JiraHomeProperty.kt | 2 +- .../tools/infrastructure/api/jira/flow/install/JiraLogs.kt | 2 +- .../infrastructure/api/jira/flow/install/JvmConfig.kt | 2 +- .../api/jira/flow/server/AsyncProfilerHook.kt | 4 ++-- .../infrastructure/api/jira/flow/server/TcpServerHook.kt | 7 ++++--- .../infrastructure/api/jira/flow/server/UbuntuSysstat.kt | 4 ++-- .../tools/infrastructure/api/jira/flow/start/AccessLogs.kt | 2 +- .../api/jira/flow/start/DefaultStartedJiraHook.kt | 4 ++-- .../infrastructure/api/jira/flow/start/HookedJiraStart.kt | 4 ++-- .../tools/infrastructure/api/jira/flow/start/JstatHook.kt | 2 +- .../infrastructure/api/jira/flow/start/RestUpgrade.kt | 2 +- .../infrastructure/api/jira/flow/start/StartedJiraHook.kt | 3 ++- .../tools/infrastructure/jira/flow/install/ProfilerHook.kt | 4 ++-- .../jira/flow/install/SplunkForwarderHook.kt | 2 +- .../tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt | 6 +++--- .../api/jira/flow/start/HookedJiraStartIT.kt | 4 ++-- 23 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt index ff3a49a2..0c22a552 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt @@ -10,7 +10,7 @@ class DatabaseIpConfig( private val databaseIp: String ) : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt index 7a4844f8..265c019a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt @@ -10,7 +10,7 @@ import java.time.Duration class MysqlConnector : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt index 8256fdb5..39040f9b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt @@ -9,7 +9,7 @@ class DataCenterHook( private val sharedHome: SharedHome ) : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt index 27614423..b42a983a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt @@ -11,7 +11,7 @@ class DefaultPostInstallHook( private val config: JiraNodeConfig ) : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow @@ -23,6 +23,6 @@ class DefaultPostInstallHook( ProfilerHook(config.profiler), SplunkForwarderHook(config.splunkForwarder), UbuntuSysstat() - ).forEach { it.hook(ssh, jira, flow) } + ).forEach { it.run(ssh, jira, flow) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt index 4798919d..6f1b73b9 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt @@ -5,7 +5,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class DisabledAutoBackup : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt index 5d87c803..bb802c53 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt @@ -13,9 +13,9 @@ class HookedJiraInstallation( server: TcpServer, flow: JiraNodeFlow ): InstalledJira { - flow.listPreInstallHooks().forEach { it.hook(ssh, server, flow) } + flow.listPreInstallHooks().forEach { it.run(ssh, server, flow) } val installed = installation.install(ssh, server, flow) - flow.listPostInstallHooks().forEach { it.hook(ssh, installed, flow) } + flow.listPostInstallHooks().forEach { it.run(ssh, installed, flow) } return installed } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt index 7bb44785..d72690a4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt @@ -6,17 +6,18 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.Starte import com.atlassian.performance.tools.ssh.api.SshConnection interface InstalledJiraHook : StartedJiraHook { - fun hook( + + fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow ) - override fun hook( + override fun run( ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow ) { - hook(ssh, jira.installed, flow) + run(ssh, jira.installed, flow) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt index aa1d764c..623ceee7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt @@ -5,7 +5,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class JiraHomeProperty : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt index 4266e363..7c7013e3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt @@ -6,7 +6,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class JiraLogs : InstalledJiraHook { - override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { listOf( StaticReport("${jira.home}/log/atlassian-jira.log"), StaticReport("${jira.installation}/logs/catalina.out") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt index 63852750..48c2875b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt @@ -11,7 +11,7 @@ class JvmConfig( private val config: JiraNodeConfig ) : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt index 555f4027..f72748ee 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt @@ -9,7 +9,7 @@ import java.net.URI class AsyncProfilerHook : TcpServerHook { - override fun hook( + override fun run( ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow @@ -32,7 +32,7 @@ private class InstalledAsyncProfiler( private val profilerPath: String ) : StartedJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt index 63c3588b..05076de8 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt @@ -7,17 +7,18 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Inst import com.atlassian.performance.tools.ssh.api.SshConnection interface TcpServerHook : InstalledJiraHook { - fun hook( + + fun run( ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow ) - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow ) { - hook(ssh, jira.server, flow) + run(ssh, jira.server, flow) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt index 90957535..5941136b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt @@ -11,7 +11,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class UbuntuSysstat : TcpServerHook { - override fun hook( + override fun run( ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow @@ -28,7 +28,7 @@ private class InstalledOsMetric( private val metric: OsMetric ) : TcpServerHook { - override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { val process = metric.start(ssh) flow.reports.add(RemoteMonitoringProcessReport(process)) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt index 167be630..7e914d4b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt @@ -7,7 +7,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class AccessLogs : StartedJiraHook { - override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { flow.reports.add(FileListing("${jira.installed.installation}/logs/*access*")) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt index 9e1d8b89..8373d960 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt @@ -7,7 +7,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultStartedJiraHook : StartedJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow @@ -15,6 +15,6 @@ class DefaultStartedJiraHook : StartedJiraHook { listOf( JiraLogs(), JstatHook() - ).forEach { it.hook(ssh, jira, flow) } + ).forEach { it.run(ssh, jira, flow) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt index 61cb0820..9b00e5ac 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt @@ -14,9 +14,9 @@ class HookedJiraStart( installed: InstalledJira, flow: JiraNodeFlow ): StartedJira { - flow.listPreStartHooks().forEach { it.hook(ssh, installed, flow) } + flow.listPreStartHooks().forEach { it.run(ssh, installed, flow) } val started = start.start(ssh, installed, flow) - flow.listPostStartHooks().forEach { it.hook(ssh, started, flow) } + flow.listPostStartHooks().forEach { it.run(ssh, started, flow) } return started } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt index 3ebbc38c..114297da 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt @@ -7,7 +7,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class JstatHook : StartedJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt index 484f998e..22a5f31b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt @@ -16,7 +16,7 @@ class RestUpgrade( private val adminPassword: String ) : StartedJiraHook { - override fun hook(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) val privatePort = jira.installed.server.privatePort val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:$privatePort/rest/api/2/upgrade") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt index 8e105ee1..8bf3edfb 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt @@ -5,7 +5,8 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.Start import com.atlassian.performance.tools.ssh.api.SshConnection interface StartedJiraHook { - fun hook( + + fun run( ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt index 01a78de4..1b1de2eb 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt @@ -16,7 +16,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class ProfilerHook( private val profiler: Profiler ) : InstalledJiraHook { - override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { profiler.install(ssh) flow.hookPostStart(InstalledProfiler(profiler)) } @@ -26,7 +26,7 @@ private class InstalledProfiler( private val profiler: Profiler ) : StartedJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt index 178f5aba..474f9b8e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt @@ -10,7 +10,7 @@ internal class SplunkForwarderHook( private val splunk: SplunkForwarder ) : InstalledJiraHook { - override fun hook( + override fun run( ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt index 605f62e8..d92b0505 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt @@ -23,7 +23,7 @@ class JiraNodeFlowTest { val server = TcpServer("doesn't matter", 123, "fake-server") flow.listPreInstallHooks().forEach { - it.hook(FailingSshConnection(), server, flow) + it.run(FailingSshConnection(), server, flow) } assertThat(counter.count).isEqualTo(3) @@ -34,7 +34,7 @@ private class CountingHook : TcpServerHook { var count = 0 - override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { count++ } } @@ -42,7 +42,7 @@ private class CountingHook : TcpServerHook { private class HookingHook( private val hook: TcpServerHook ) : TcpServerHook { - override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { flow.hookPreInstall(hook) } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index cf4aa8d5..3eaa6e88 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -132,11 +132,11 @@ class HookedJiraStartIT { } private class FailingHook : TcpServerHook, InstalledJiraHook { - override fun hook(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { throw Exception("Failed") } - override fun hook(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { throw Exception("Failed") } } From fac32ba200fd5483b3ee05b4f6b7c5e4fd2886c8 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 6 Sep 2019 17:05:43 +0200 Subject: [PATCH 16/28] Bump a bunch of timeouts, because my Internet is awful Show the problem with hooking onto the tail of the hook queue during hook iteration. --- .../flow/install/DefaultPostInstallHook.kt | 4 +- .../api/jira/flow/install/JiraLogs.kt | 19 +++++- .../api/jira/flow/server/LateUbuntuSysstat.kt | 19 ++++++ .../api/jira/flow/server/UbuntuSysstat.kt | 35 ---------- .../ubuntu/EarlyUbuntuSysstat.kt | 19 ++++++ .../ubuntu/InstalledOsMetric.kt | 18 +++++ .../infrastructure/ubuntu/UbuntuSysstat.kt | 17 +++++ .../infrastructure/SshUbuntuExtensions.kt | 2 +- .../api/jira/flow/JiraNodeFlowTest.kt | 17 +++++ .../api/jira/flow/start/HookedJiraStartIT.kt | 66 +++++++++++++++---- 10 files changed, 164 insertions(+), 52 deletions(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/UbuntuSysstat.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt index b42a983a..50363f27 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt @@ -2,7 +2,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.UbuntuSysstat +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.LateUbuntuSysstat import com.atlassian.performance.tools.infrastructure.jira.flow.install.ProfilerHook import com.atlassian.performance.tools.infrastructure.jira.flow.install.SplunkForwarderHook import com.atlassian.performance.tools.ssh.api.SshConnection @@ -22,7 +22,7 @@ class DefaultPostInstallHook( JvmConfig(config), ProfilerHook(config.profiler), SplunkForwarderHook(config.splunkForwarder), - UbuntuSysstat() + LateUbuntuSysstat() ).forEach { it.run(ssh, jira, flow) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt index 7c7013e3..8e2cab01 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt @@ -3,13 +3,26 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection +import java.nio.file.Path +import java.nio.file.Paths class JiraLogs : InstalledJiraHook { override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { listOf( - StaticReport("${jira.home}/log/atlassian-jira.log"), - StaticReport("${jira.installation}/logs/catalina.out") - ).forEach { flow.reports.add(it) } + "${jira.home}/log/atlassian-jira.log", + "${jira.installation}/logs/catalina.out" + ) + .onEach { ensureFile(Paths.get(it), ssh) } + .map { StaticReport(it) } + .forEach { flow.reports.add(it) } + } + + private fun ensureFile( + path: Path, + ssh: SshConnection + ) { + ssh.execute("mkdir -p ${path.parent!!}") + ssh.execute("touch $path") } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt new file mode 100644 index 00000000..0fe5945d --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt @@ -0,0 +1,19 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.server + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.ubuntu.UbuntuSysstat +import com.atlassian.performance.tools.ssh.api.SshConnection + +class LateUbuntuSysstat : TcpServerHook { + + override fun run( + ssh: SshConnection, + server: TcpServer, + flow: JiraNodeFlow + ) { + UbuntuSysstat() + .install(ssh) + .forEach { flow.hookPostStart(it) } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt deleted file mode 100644 index 5941136b..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/UbuntuSysstat.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.server - -import com.atlassian.performance.tools.infrastructure.Iostat -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.os.OsMetric -import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu -import com.atlassian.performance.tools.infrastructure.api.os.Vmstat -import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport -import com.atlassian.performance.tools.ssh.api.SshConnection - -class UbuntuSysstat : TcpServerHook { - - override fun run( - ssh: SshConnection, - server: TcpServer, - flow: JiraNodeFlow - ) { - val ubuntu = Ubuntu() - ubuntu.install(ssh, listOf("sysstat")) - listOf(Vmstat(), Iostat()) - .map { InstalledOsMetric(it) } - .forEach { flow.hookPostStart(it) } - } -} - -private class InstalledOsMetric( - private val metric: OsMetric -) : TcpServerHook { - - override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { - val process = metric.start(ssh) - flow.reports.add(RemoteMonitoringProcessReport(process)) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt new file mode 100644 index 00000000..3a49cafc --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt @@ -0,0 +1,19 @@ +package com.atlassian.performance.tools.infrastructure.ubuntu + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook +import com.atlassian.performance.tools.ssh.api.SshConnection + +class EarlyUbuntuSysstat : TcpServerHook { + + override fun run( + ssh: SshConnection, + server: TcpServer, + flow: JiraNodeFlow + ) { + UbuntuSysstat() + .install(ssh) + .forEach { flow.hookPreInstall(it) } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt new file mode 100644 index 00000000..d10ed0cb --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt @@ -0,0 +1,18 @@ +package com.atlassian.performance.tools.infrastructure.ubuntu + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook +import com.atlassian.performance.tools.infrastructure.api.os.OsMetric +import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.ssh.api.SshConnection + +internal class InstalledOsMetric( + private val metric: OsMetric +) : TcpServerHook { + + override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + val process = metric.start(ssh) + flow.reports.add(RemoteMonitoringProcessReport(process)) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/UbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/UbuntuSysstat.kt new file mode 100644 index 00000000..8a76c645 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/UbuntuSysstat.kt @@ -0,0 +1,17 @@ +package com.atlassian.performance.tools.infrastructure.ubuntu + +import com.atlassian.performance.tools.infrastructure.Iostat +import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.infrastructure.api.os.Vmstat +import com.atlassian.performance.tools.ssh.api.SshConnection + +internal class UbuntuSysstat { + + fun install( + ssh: SshConnection + ): List { + val ubuntu = Ubuntu() + ubuntu.install(ssh, listOf("sysstat")) + return listOf(Vmstat(), Iostat()).map { InstalledOsMetric(it) } + } +} diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt index e022dcbd..03890f04 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/SshUbuntuExtensions.kt @@ -16,7 +16,7 @@ internal fun SshUbuntu.toSsh(): Ssh { ) }) ssh.newConnection().use { connection -> - connection.execute("apt-get update -qq", Duration.ofMinutes(3)) + connection.execute("apt-get update -qq", Duration.ofMinutes(7)) connection.execute("export DEBIAN_FRONTEND=noninteractive; apt-get install sudo curl screen gnupg2 -y -qq", Duration.ofMinutes(10)) } return ssh diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt index d92b0505..1f7125db 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt @@ -28,6 +28,23 @@ class JiraNodeFlowTest { assertThat(counter.count).isEqualTo(3) } + + @Test + fun shouldHookToTheTailDuringListing() { + val counter = CountingHook() + val flow = JiraNodeFlow().apply { + hookPreInstall(counter) + hookPreInstall(counter) + hookPreInstall(HookingHook(counter)) + } + val server = TcpServer("doesn't matter", 123, "fake-server") + + flow.listPreInstallHooks().forEach { + it.run(FailingSshConnection(), server, flow) + } + + assertThat(counter.count).isEqualTo(3) + } } private class CountingHook : TcpServerHook { diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index 3eaa6e88..5caf7b4c 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -8,15 +8,20 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.* import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.UbuntuSysstat -import com.atlassian.performance.tools.infrastructure.api.jvm.OracleJDK +import com.atlassian.performance.tools.infrastructure.api.jvm.Jstat +import com.atlassian.performance.tools.infrastructure.api.jvm.VersionedJavaDevelopmentKit import com.atlassian.performance.tools.infrastructure.toSsh +import com.atlassian.performance.tools.infrastructure.ubuntu.EarlyUbuntuSysstat +import com.atlassian.performance.tools.jvmtasks.api.Backoff +import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection import com.atlassian.performance.tools.sshubuntu.api.SshUbuntuContainer import org.assertj.core.api.Assertions.assertThat import org.junit.Test import java.io.File +import java.net.URI import java.nio.file.Files +import java.time.Duration import java.util.function.Consumer class HookedJiraStartIT { @@ -31,7 +36,7 @@ class HookedJiraStartIT { val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), - jdk = OracleJDK() + jdk = S3HostedJdk() )) val jiraStart = HookedJiraStart(JiraLaunchScript()) val privatePort = 8080 @@ -73,13 +78,12 @@ class HookedJiraStartIT { fun shouldDownloadPartialReportsInCaseOfFailure() { // given val flow = JiraNodeFlow() - val sysstat = UbuntuSysstat() - flow.hookPreInstall(sysstat) - flow.hookPreInstall(FailingHook()) + flow.hookPreInstall(EarlyUbuntuSysstat()) + flow.hookPostInstall(FailingHook()) val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), - jdk = OracleJDK() + jdk = S3HostedJdk() )) val privatePort = 8080 val container = SshUbuntuContainer(Consumer { @@ -132,11 +136,51 @@ class HookedJiraStartIT { } private class FailingHook : TcpServerHook, InstalledJiraHook { - override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { - throw Exception("Failed") + override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) = throw Exception("Expected failure") + override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) = throw Exception("Expected failure") +} + +/** + * Harvested from https://stash.atlassian.com/projects/JIRASERVER/repos/jira-performance-tests/pull-requests/630 + */ +class S3HostedJdk : VersionedJavaDevelopmentKit { + private val jdkVersion = "1.8.0" + private val jdkUpdate = 131 + private val jdkArchive = "jdk${jdkVersion}_$jdkUpdate-linux-x64.tar.gz" + private val jdkUrl = URI.create("https://s3.amazonaws.com/packages_java/$jdkArchive") + private val jdkBin = "~/jdk${jdkVersion}_$jdkUpdate/jre/bin/" + private val bin = "~/jdk${jdkVersion}_$jdkUpdate/bin/" + override val jstatMonitoring = Jstat(bin) + + override fun getMajorVersion() = 8 + + override fun install(connection: SshConnection) { + download(connection) + connection.execute("tar -xzf $jdkArchive") + connection.execute("echo '${use()}' >> ~/.bashrc") } - override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { - throw Exception("Failed") + private fun download(connection: SshConnection) { + IdempotentAction("download JDK") { + connection.execute( + cmd = "curl -s -L -O -k $jdkUrl", + timeout = Duration.ofMinutes(4) + ) + }.retry( + maxAttempts = 3, + backoff = StaticBackoff(Duration.ofSeconds(4)) + ) } + + override fun use(): String = "export PATH=$jdkBin:$bin:${'$'}PATH" + + override fun command(options: String) = "${jdkBin}java $options" +} + + +class StaticBackoff( + private val backoff: Duration +) : Backoff { + + override fun backOff(attempt: Int): Duration = backoff } From ebf7325b25026f952739580995475e459061c808 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 6 Sep 2019 17:29:47 +0200 Subject: [PATCH 17/28] JPERF-273: Poll hooks manually to avoid tail iteration This also means that if you run a hook, it gets unregistered --- .../infrastructure/api/jira/flow/JiraNodeFlow.kt | 13 ++++++++++++- .../api/jira/flow/install/HookedJiraInstallation.kt | 2 +- .../api/jira/flow/JiraNodeFlowTest.kt | 8 ++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index 4a220cd4..9ff38d57 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -4,6 +4,7 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Inst import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook +import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe import java.util.* import java.util.concurrent.ConcurrentLinkedQueue @@ -23,7 +24,17 @@ class JiraNodeFlow { preInstallHooks.add(hook) } - internal fun listPreInstallHooks(): Iterable = preInstallHooks + internal fun runPreInstallHooks( + ssh: SshConnection, + server: TcpServer + ) { + while (true) { + preInstallHooks + .poll() + ?.run(ssh, server, this) + ?: break + } + } fun hookPostInstall( hook: InstalledJiraHook diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt index bb802c53..7ce42588 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt @@ -13,7 +13,7 @@ class HookedJiraInstallation( server: TcpServer, flow: JiraNodeFlow ): InstalledJira { - flow.listPreInstallHooks().forEach { it.run(ssh, server, flow) } + flow.runPreInstallHooks(ssh, server) val installed = installation.install(ssh, server, flow) flow.listPostInstallHooks().forEach { it.run(ssh, installed, flow) } return installed diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt index 1f7125db..29a89e99 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt @@ -22,9 +22,7 @@ class JiraNodeFlowTest { } val server = TcpServer("doesn't matter", 123, "fake-server") - flow.listPreInstallHooks().forEach { - it.run(FailingSshConnection(), server, flow) - } + flow.runPreInstallHooks(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -39,9 +37,7 @@ class JiraNodeFlowTest { } val server = TcpServer("doesn't matter", 123, "fake-server") - flow.listPreInstallHooks().forEach { - it.run(FailingSshConnection(), server, flow) - } + flow.runPreInstallHooks(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } From d311c65b07e6d6a12b7d5f8b6bd498db91db5183 Mon Sep 17 00:00:00 2001 From: Michal Wyrzykowski Date: Wed, 16 Oct 2019 14:02:10 +0200 Subject: [PATCH 18/28] JPERF-219: Block hooking to the past --- .../api/database/DatabaseIpConfig.kt | 8 +-- .../api/database/MysqlConnector.kt | 8 +-- .../api/jira/flow/JiraNodeFlow.kt | 49 +++++++++++-------- .../api/jira/flow/PostInstallFlow.kt | 9 ++++ .../api/jira/flow/PostStartFlow.kt | 9 ++++ .../api/jira/flow/PreInstallFlow.kt | 9 ++++ .../api/jira/flow/PreStartFlow.kt | 8 +++ .../api/jira/flow/PreStartHook.kt | 14 ++++++ .../infrastructure/api/jira/flow/Reports.kt | 8 +++ .../api/jira/flow/install/DataCenterHook.kt | 6 +-- .../flow/install/DefaultPostInstallHook.kt | 7 +-- .../jira/flow/install/DisabledAutoBackup.kt | 6 +-- .../jira/flow/install/InstalledJiraHook.kt | 23 --------- .../api/jira/flow/install/JiraHomeProperty.kt | 6 +-- .../api/jira/flow/install/JiraLogs.kt | 8 +-- .../api/jira/flow/install/JvmConfig.kt | 8 +-- .../api/jira/flow/install/PostInstallHook.kt | 14 ++++++ .../api/jira/flow/server/AsyncProfilerHook.kt | 17 ++++--- .../api/jira/flow/server/LateUbuntuSysstat.kt | 37 ++++++++++---- .../api/jira/flow/server/PreInstallHook.kt | 13 +++++ .../api/jira/flow/server/TcpServerHook.kt | 24 --------- .../api/jira/flow/start/AccessLogs.kt | 8 +-- ...tedJiraHook.kt => DefaultPostStartHook.kt} | 8 ++- .../api/jira/flow/start/JstatHook.kt | 8 +-- .../{StartedJiraHook.kt => PostStartHook.kt} | 6 +-- .../api/jira/flow/start/RestUpgrade.kt | 8 +-- .../jira/flow/install/ProfilerHook.kt | 23 ++++----- .../jira/flow/install/SplunkForwarderHook.kt | 8 +-- .../ubuntu/EarlyUbuntuSysstat.kt | 10 ++-- .../ubuntu/InstalledOsMetric.kt | 10 ++-- .../api/jira/flow/JiraNodeFlowTest.kt | 26 +++++----- .../api/jira/flow/start/HookedJiraStartIT.kt | 30 +++++++----- 32 files changed, 252 insertions(+), 184 deletions(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartHook.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/PreInstallHook.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/{DefaultStartedJiraHook.kt => DefaultPostStartHook.kt} (69%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/{StartedJiraHook.kt => PostStartHook.kt} (83%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt index 0c22a552..0ef56cd7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt @@ -1,19 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.api.Sed -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection class DatabaseIpConfig( private val databaseIp: String -) : InstalledJiraHook { +) : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { Sed().replace( connection = ssh, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt index 265c019a..e29e2820 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt @@ -1,19 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.database -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.jvmtasks.api.Backoff import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection import java.time.Duration -class MysqlConnector : InstalledJiraHook { +class MysqlConnector : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" IdempotentAction( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index 9ff38d57..01c23d38 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -1,25 +1,24 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe import java.util.* import java.util.concurrent.ConcurrentLinkedQueue @ThreadSafe -class JiraNodeFlow { +class JiraNodeFlow : PreInstallFlow { + private val preInstallHooks: Queue = ConcurrentLinkedQueue() + private val postInstallHooks: Queue = ConcurrentLinkedQueue() + private val preStartHooks: Queue = ConcurrentLinkedQueue() + private val postStartHooks: Queue = ConcurrentLinkedQueue() + private val reports: Queue = ConcurrentLinkedQueue() - private val preInstallHooks: Queue = ConcurrentLinkedQueue() - private val postInstallHooks: Queue = ConcurrentLinkedQueue() - private val preStartHooks: Queue = ConcurrentLinkedQueue() - private val postStartHooks: Queue = ConcurrentLinkedQueue() - val reports: Queue = ConcurrentLinkedQueue() - - fun hookPreInstall( - hook: TcpServerHook + override fun hook( + hook: PreInstallHook ) { preInstallHooks.add(hook) } @@ -36,27 +35,35 @@ class JiraNodeFlow { } } - fun hookPostInstall( - hook: InstalledJiraHook + override fun hook( + hook: PostInstallHook ) { postInstallHooks.add(hook) } - internal fun listPostInstallHooks(): Iterable = postInstallHooks + internal fun listPostInstallHooks(): Iterable = postInstallHooks - fun hookPreStart( - hook: InstalledJiraHook + override fun hook( + hook: PreStartHook ) { preStartHooks.add(hook) } - internal fun listPreStartHooks(): Iterable = preStartHooks + internal fun listPreStartHooks(): Iterable = preStartHooks - fun hookPostStart( - hook: StartedJiraHook + override fun hook( + hook: PostStartHook ) { postStartHooks.add(hook) } - internal fun listPostStartHooks(): Iterable = postStartHooks + internal fun listPostStartHooks(): Iterable = postStartHooks + + override fun addReport(report: Report) { + reports.add(report) + } + + internal fun allReports(): Iterable { + return reports.toList() + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt new file mode 100644 index 00000000..07033d07 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt @@ -0,0 +1,9 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook + +interface PostInstallFlow : PreStartFlow { + fun hook( + hook: PostInstallHook + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt new file mode 100644 index 00000000..6885b484 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt @@ -0,0 +1,9 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook + +interface PostStartFlow : Reports { + fun hook( + hook: PostStartHook + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt new file mode 100644 index 00000000..3240a0c2 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt @@ -0,0 +1,9 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook + +interface PreInstallFlow : PostInstallFlow { + fun hook( + hook: PreInstallHook + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt new file mode 100644 index 00000000..3d207ace --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt @@ -0,0 +1,8 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + + +interface PreStartFlow : PostStartFlow { + fun hook( + hook: PreStartHook + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartHook.kt new file mode 100644 index 00000000..1629131b --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartHook.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.ssh.api.SshConnection + +interface PreStartHook { + + fun run( + ssh: SshConnection, + jira: InstalledJira, + flow: PreStartFlow + ) + +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt new file mode 100644 index 00000000..628a10d1 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt @@ -0,0 +1,8 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report + +interface Reports { + fun addReport(report: Report) + +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt index 39040f9b..a8f5acc7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt @@ -1,18 +1,18 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.ssh.api.SshConnection class DataCenterHook( private val nodeId: String, private val sharedHome: SharedHome -) : InstalledJiraHook { +) : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { val localSharedHome = sharedHome.localSharedHome sharedHome.mount(ssh) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt index 50363f27..061c649d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.LateUbuntuSysstat import com.atlassian.performance.tools.infrastructure.jira.flow.install.ProfilerHook import com.atlassian.performance.tools.infrastructure.jira.flow.install.SplunkForwarderHook @@ -9,12 +9,12 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultPostInstallHook( private val config: JiraNodeConfig -) : InstalledJiraHook { +) : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { listOf( JiraHomeProperty(), @@ -22,6 +22,7 @@ class DefaultPostInstallHook( JvmConfig(config), ProfilerHook(config.profiler), SplunkForwarderHook(config.splunkForwarder), + JiraLogs(), LateUbuntuSysstat() ).forEach { it.run(ssh, jira, flow) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt index 6f1b73b9..18050416 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt @@ -1,14 +1,14 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.ssh.api.SshConnection -class DisabledAutoBackup : InstalledJiraHook { +class DisabledAutoBackup : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { ssh.execute("echo jira.autoexport=false > ${jira.home}/jira-config.properties") } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt deleted file mode 100644 index d72690a4..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJiraHook.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook -import com.atlassian.performance.tools.ssh.api.SshConnection - -interface InstalledJiraHook : StartedJiraHook { - - fun run( - ssh: SshConnection, - jira: InstalledJira, - flow: JiraNodeFlow - ) - - override fun run( - ssh: SshConnection, - jira: StartedJira, - flow: JiraNodeFlow - ) { - run(ssh, jira.installed, flow) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt index 623ceee7..e1a08cee 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt @@ -1,14 +1,14 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.ssh.api.SshConnection -class JiraHomeProperty : InstalledJiraHook { +class JiraHomeProperty : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { val properties = "${jira.installation}/atlassian-jira/WEB-INF/classes/jira-application.properties" ssh.execute("echo jira.home=`realpath ${jira.home}` > $properties") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt index 8e2cab01..116a9c16 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt @@ -1,21 +1,21 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection import java.nio.file.Path import java.nio.file.Paths -class JiraLogs : InstalledJiraHook { +class JiraLogs : PostInstallHook { - override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, jira: InstalledJira, flow: PostInstallFlow) { listOf( "${jira.home}/log/atlassian-jira.log", "${jira.installation}/logs/catalina.out" ) .onEach { ensureFile(Paths.get(it), ssh) } .map { StaticReport(it) } - .forEach { flow.reports.add(it) } + .forEach { flow.addReport(it) } } private fun ensureFile( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt index 48c2875b..f062590d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt @@ -3,18 +3,18 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.ssh.api.SshConnection class JvmConfig( private val config: JiraNodeConfig -) : InstalledJiraHook { +) : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { val gcLog = JiraGcLog(jira.installation) SetenvSh(jira.installation).setup( @@ -24,6 +24,6 @@ class JvmConfig( jiraIp = jira.server.ip ) val report = FileListing(gcLog.path("*")) - flow.reports.add(report) + flow.addReport(report) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt new file mode 100644 index 00000000..4b8026c5 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt @@ -0,0 +1,14 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.install + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow +import com.atlassian.performance.tools.ssh.api.SshConnection + +interface PostInstallHook { + + fun run( + ssh: SshConnection, + jira: InstalledJira, + flow: PostInstallFlow + ) + +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt index f72748ee..0dac4ea1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt @@ -1,18 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI -class AsyncProfilerHook : TcpServerHook { +class AsyncProfilerHook : PreInstallHook { override fun run( ssh: SshConnection, server: TcpServer, - flow: JiraNodeFlow + flow: PreInstallFlow ) { val directory = "async-profiler" val downloads = URI("https://github.com/jvm-profiling-tools/async-profiler/releases/download/") @@ -24,22 +25,22 @@ class AsyncProfilerHook : TcpServerHook { ssh.execute("sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'") val profilerPath = "./$directory/profiler.sh" val profiler = InstalledAsyncProfiler(profilerPath) - flow.hookPostStart(profiler) + flow.hook(profiler) } } private class InstalledAsyncProfiler( private val profilerPath: String -) : StartedJiraHook { +) : PostStartHook { override fun run( ssh: SshConnection, jira: StartedJira, - flow: JiraNodeFlow + flow: PostStartFlow ) { ssh.execute("$profilerPath -b 20000000 start ${jira.pid}") val profiler = StartedAsyncProfiler(jira.pid, profilerPath) - flow.reports.add(profiler) + flow.addReport(profiler) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt index 0fe5945d..bf649e8c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt @@ -1,19 +1,36 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.ubuntu.UbuntuSysstat +import com.atlassian.performance.tools.infrastructure.Iostat +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.os.OsMetric +import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu +import com.atlassian.performance.tools.infrastructure.api.os.Vmstat +import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection -class LateUbuntuSysstat : TcpServerHook { - +class LateUbuntuSysstat : PostInstallHook { override fun run( ssh: SshConnection, - server: TcpServer, - flow: JiraNodeFlow + jira: InstalledJira, + flow: PostInstallFlow ) { - UbuntuSysstat() - .install(ssh) - .forEach { flow.hookPostStart(it) } + val ubuntu = Ubuntu() + ubuntu.install(ssh, listOf("sysstat")) + listOf(Vmstat(), Iostat()) + .map { PostStartOsMetric(it) } + .forEach { flow.hook(it) } + } +} + +internal class PostStartOsMetric( + private val metric: OsMetric +) : PostStartHook { + override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { + val process = metric.start(ssh) + flow.addReport(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/PreInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/PreInstallHook.kt new file mode 100644 index 00000000..1c426ced --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/PreInstallHook.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.flow.server + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow +import com.atlassian.performance.tools.ssh.api.SshConnection + +interface PreInstallHook { + fun run( + ssh: SshConnection, + server: TcpServer, + flow: PreInstallFlow + ) +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt deleted file mode 100644 index 05076de8..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/TcpServerHook.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.server - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook -import com.atlassian.performance.tools.ssh.api.SshConnection - -interface TcpServerHook : InstalledJiraHook { - - fun run( - ssh: SshConnection, - server: TcpServer, - flow: JiraNodeFlow - ) - - override fun run( - ssh: SshConnection, - jira: InstalledJira, - flow: JiraNodeFlow - ) { - run(ssh, jira.server, flow) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt index 7e914d4b..37b25dfd 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt @@ -1,13 +1,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection -class AccessLogs : StartedJiraHook { +class AccessLogs : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { - flow.reports.add(FileListing("${jira.installed.installation}/logs/*access*")) + override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { + flow.addReport(FileListing("${jira.installed.installation}/logs/*access*")) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt similarity index 69% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt index 8373d960..54cd6126 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultStartedJiraHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt @@ -1,19 +1,17 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.JiraLogs +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection -class DefaultStartedJiraHook : StartedJiraHook { +class DefaultPostStartHook : PostStartHook { override fun run( ssh: SshConnection, jira: StartedJira, - flow: JiraNodeFlow + flow: PostStartFlow ) { listOf( - JiraLogs(), JstatHook() ).forEach { it.run(ssh, jira, flow) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt index 114297da..4ace72c6 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt @@ -1,18 +1,18 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection -class JstatHook : StartedJiraHook { +class JstatHook : PostStartHook { override fun run( ssh: SshConnection, jira: StartedJira, - flow: JiraNodeFlow + flow: PostStartFlow ) { val process = jira.installed.jdk.jstatMonitoring.start(ssh, jira.pid) - flow.reports.add(RemoteMonitoringProcessReport(process)) + flow.addReport(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt similarity index 83% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt index 8bf3edfb..e9541666 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/StartedJiraHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt @@ -1,14 +1,14 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection -interface StartedJiraHook { +interface PostStartHook { fun run( ssh: SshConnection, jira: StartedJira, - flow: JiraNodeFlow + flow: PostStartFlow ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt index 22a5f31b..25ab900a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump @@ -14,13 +14,13 @@ class RestUpgrade( private val timeouts: JiraLaunchTimeouts, private val adminUsername: String, private val adminPassword: String -) : StartedJiraHook { +) : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) val privatePort = jira.installed.server.privatePort val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:$privatePort/rest/api/2/upgrade") - flow.reports.add(StaticReport("thread-dumps")) + flow.addReport(StaticReport("thread-dumps")) waitForStatusToChange( statusQuo = "000", timeout = timeouts.offlineTimeout, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt index 1b1de2eb..d7d3d949 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt @@ -1,39 +1,40 @@ package com.atlassian.performance.tools.infrastructure.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StartedJiraHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection /** - * Bridges the [Profiler] SPI with the [InstalledJiraHook] SPI. - * In general any [Profiler] can be rewritten as an [InstalledJiraHook] or any other hookPreStart without this bridge. + * Bridges the [Profiler] SPI with the [PostInstallHook] SPI. + * In general any [Profiler] can be rewritten as an [PostInstallHook] or any other hookPreStart without this bridge. */ class ProfilerHook( private val profiler: Profiler -) : InstalledJiraHook { - override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) { +) : PostInstallHook { + override fun run(ssh: SshConnection, jira: InstalledJira, flow: PostInstallFlow) { profiler.install(ssh) - flow.hookPostStart(InstalledProfiler(profiler)) + flow.hook(InstalledProfiler(profiler)) } } private class InstalledProfiler( private val profiler: Profiler -) : StartedJiraHook { +) : PostStartHook { override fun run( ssh: SshConnection, jira: StartedJira, - flow: JiraNodeFlow + flow: PostStartFlow ) { val process = profiler.start(ssh, jira.pid) if (process != null) { - flow.reports.add(RemoteMonitoringProcessReport(process)) + flow.addReport(RemoteMonitoringProcessReport(process)) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt index 474f9b8e..9512abd3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt @@ -1,19 +1,19 @@ package com.atlassian.performance.tools.infrastructure.jira.flow.install +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJiraHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.splunk.SplunkForwarder import com.atlassian.performance.tools.ssh.api.SshConnection internal class SplunkForwarderHook( private val splunk: SplunkForwarder -) : InstalledJiraHook { +) : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: JiraNodeFlow + flow: PostInstallFlow ) { splunk.jsonifyLog4j(ssh, "${jira.installation}/atlassian-jira/WEB-INF/classes/log4j.properties") splunk.run(ssh, jira.server.name, "/home/ubuntu/jirahome/log") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt index 3a49cafc..8b0f4ef1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt @@ -1,19 +1,19 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection -class EarlyUbuntuSysstat : TcpServerHook { +class EarlyUbuntuSysstat : PreInstallHook { override fun run( ssh: SshConnection, server: TcpServer, - flow: JiraNodeFlow + flow: PreInstallFlow ) { UbuntuSysstat() .install(ssh) - .forEach { flow.hookPreInstall(it) } + .forEach { flow.hook(it) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt index d10ed0cb..6edd02de 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt @@ -1,18 +1,18 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection internal class InstalledOsMetric( private val metric: OsMetric -) : TcpServerHook { +) : PreInstallHook { - override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, server: TcpServer, flow: PreInstallFlow) { val process = metric.start(ssh) - flow.reports.add(RemoteMonitoringProcessReport(process)) + flow.addReport(RemoteMonitoringProcessReport(process)) } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt index 29a89e99..ec433116 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt @@ -1,6 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook import com.atlassian.performance.tools.ssh.api.DetachedProcess import com.atlassian.performance.tools.ssh.api.SshConnection import org.apache.logging.log4j.Level @@ -16,9 +16,9 @@ class JiraNodeFlowTest { fun shouldHookDuringListing() { val counter = CountingHook() val flow = JiraNodeFlow().apply { - hookPreInstall(counter) - hookPreInstall(HookingHook(counter)) - hookPreInstall(counter) + hook(counter) + hook(HookingHook(counter)) + hook(counter) } val server = TcpServer("doesn't matter", 123, "fake-server") @@ -31,9 +31,9 @@ class JiraNodeFlowTest { fun shouldHookToTheTailDuringListing() { val counter = CountingHook() val flow = JiraNodeFlow().apply { - hookPreInstall(counter) - hookPreInstall(counter) - hookPreInstall(HookingHook(counter)) + hook(counter) + hook(counter) + hook(HookingHook(counter)) } val server = TcpServer("doesn't matter", 123, "fake-server") @@ -43,20 +43,20 @@ class JiraNodeFlowTest { } } -private class CountingHook : TcpServerHook { +private class CountingHook : PreInstallHook { var count = 0 - override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { + override fun run(ssh: SshConnection, server: TcpServer, flow: PreInstallFlow) { count++ } } private class HookingHook( - private val hook: TcpServerHook -) : TcpServerHook { - override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) { - flow.hookPreInstall(hook) + private val hook: PreInstallHook +) : PreInstallHook { + override fun run(ssh: SshConnection, server: TcpServer, flow: PreInstallFlow) { + flow.hook(hook) } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index 5caf7b4c..6a133ac9 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -4,10 +4,12 @@ import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJir import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.* +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.HookedJiraInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.ParallelInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.TcpServerHook import com.atlassian.performance.tools.infrastructure.api.jvm.Jstat import com.atlassian.performance.tools.infrastructure.api.jvm.VersionedJavaDevelopmentKit import com.atlassian.performance.tools.infrastructure.toSsh @@ -31,8 +33,8 @@ class HookedJiraStartIT { // given val config = JiraNodeConfig.Builder().build() val flow = JiraNodeFlow() - flow.hookPostStart(DefaultStartedJiraHook()) - flow.hookPostInstall(DefaultPostInstallHook(config)) + flow.hook(DefaultPostStartHook()) + flow.hook(DefaultPostInstallHook(config)) val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), @@ -55,7 +57,7 @@ class HookedJiraStartIT { val installed = jiraInstallation.install(ssh, server, flow) val started = jiraStart.start(ssh, installed, flow) stop(started, ssh) - flow.reports.flatMap { it.locate(ssh) } + flow.allReports().flatMap { it.locate(ssh) } } // then @@ -77,9 +79,11 @@ class HookedJiraStartIT { @Test fun shouldDownloadPartialReportsInCaseOfFailure() { // given - val flow = JiraNodeFlow() - flow.hookPreInstall(EarlyUbuntuSysstat()) - flow.hookPostInstall(FailingHook()) + val flow = JiraNodeFlow().apply { + hook(EarlyUbuntuSysstat()) + hook(FailingHook()) + } + val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), @@ -103,7 +107,7 @@ class HookedJiraStartIT { } catch (e: Exception) { println("Failed: ${e.message}") } - return@useSsh flow.reports.flatMap { it.locate(ssh) } + return@useSsh flow.allReports().flatMap { it.locate(ssh) } } } @@ -135,9 +139,11 @@ class HookedJiraStartIT { } } -private class FailingHook : TcpServerHook, InstalledJiraHook { - override fun run(ssh: SshConnection, server: TcpServer, flow: JiraNodeFlow) = throw Exception("Expected failure") - override fun run(ssh: SshConnection, jira: InstalledJira, flow: JiraNodeFlow) = throw Exception("Expected failure") +private class FailingHook : PostStartHook { + override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { + throw Exception("Expected failure") + + } } /** From c87d1980ec5acc416c76d0e3df77bee0b0b86669 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Tue, 15 Oct 2019 15:34:24 +0200 Subject: [PATCH 19/28] Fixup: 6ad30c059bcdcc8b05c4ec2f9c40cc0b3cdfb779 Use destructive polling for all JiraNodeFlow hook types. --- .../api/jira/flow/JiraNodeFlow.kt | 45 +++++++++++++++++-- .../flow/install/HookedJiraInstallation.kt | 2 +- .../api/jira/flow/start/HookedJiraStart.kt | 4 +- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index 01c23d38..06e14389 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -1,8 +1,10 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe @@ -41,7 +43,17 @@ class JiraNodeFlow : PreInstallFlow { postInstallHooks.add(hook) } - internal fun listPostInstallHooks(): Iterable = postInstallHooks + internal fun runPostInstallHooks( + ssh: SshConnection, + jira: InstalledJira + ) { + while (true) { + postInstallHooks + .poll() + ?.run(ssh, jira, this) + ?: break + } + } override fun hook( hook: PreStartHook @@ -49,7 +61,17 @@ class JiraNodeFlow : PreInstallFlow { preStartHooks.add(hook) } - internal fun listPreStartHooks(): Iterable = preStartHooks + internal fun runPreStartHooks( + ssh: SshConnection, + jira: InstalledJira + ) { + while (true) { + preStartHooks + .poll() + ?.run(ssh, jira, this) + ?: break + } + } override fun hook( hook: PostStartHook @@ -57,7 +79,17 @@ class JiraNodeFlow : PreInstallFlow { postStartHooks.add(hook) } - internal fun listPostStartHooks(): Iterable = postStartHooks + internal fun runPostStartHooks( + ssh: SshConnection, + jira: StartedJira + ) { + while (true) { + postStartHooks + .poll() + ?.run(ssh, jira, this) + ?: break + } + } override fun addReport(report: Report) { reports.add(report) @@ -66,4 +98,11 @@ class JiraNodeFlow : PreInstallFlow { internal fun allReports(): Iterable { return reports.toList() } + + fun copy(): JiraNodeFlow = JiraNodeFlow() + .also { it.preInstallHooks += this.preInstallHooks } + .also { it.postInstallHooks += this.postInstallHooks } + .also { it.preStartHooks += this.preStartHooks } + .also { it.postStartHooks += this.postStartHooks } + .also { it.reports += this.reports } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt index 7ce42588..6b3175d0 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt @@ -15,7 +15,7 @@ class HookedJiraInstallation( ): InstalledJira { flow.runPreInstallHooks(ssh, server) val installed = installation.install(ssh, server, flow) - flow.listPostInstallHooks().forEach { it.run(ssh, installed, flow) } + flow.runPostInstallHooks(ssh, installed) return installed } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt index 9b00e5ac..30d290a9 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt @@ -14,9 +14,9 @@ class HookedJiraStart( installed: InstalledJira, flow: JiraNodeFlow ): StartedJira { - flow.listPreStartHooks().forEach { it.run(ssh, installed, flow) } + flow.runPreStartHooks(ssh, installed) val started = start.start(ssh, installed, flow) - flow.listPostStartHooks().forEach { it.run(ssh, started, flow) } + flow.runPostStartHooks(ssh, started) return started } } From f03620124248dc0ff3603dbbd2f7016b1c92bf3d Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Mon, 14 Oct 2019 15:51:01 +0200 Subject: [PATCH 20/28] Extract `S3HostedJdk` --- .../api/jira/flow/start/HookedJiraStartIT.kt | 44 +------------------ .../infrastructure/api/jvm/S3HostedJdk.kt | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index 6a133ac9..f49acbd9 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -10,18 +10,15 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Defa import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.HookedJiraInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.ParallelInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jvm.Jstat -import com.atlassian.performance.tools.infrastructure.api.jvm.VersionedJavaDevelopmentKit +import com.atlassian.performance.tools.infrastructure.api.jvm.S3HostedJdk import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.infrastructure.ubuntu.EarlyUbuntuSysstat import com.atlassian.performance.tools.jvmtasks.api.Backoff -import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection import com.atlassian.performance.tools.sshubuntu.api.SshUbuntuContainer import org.assertj.core.api.Assertions.assertThat import org.junit.Test import java.io.File -import java.net.URI import java.nio.file.Files import java.time.Duration import java.util.function.Consumer @@ -142,48 +139,9 @@ class HookedJiraStartIT { private class FailingHook : PostStartHook { override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { throw Exception("Expected failure") - } } -/** - * Harvested from https://stash.atlassian.com/projects/JIRASERVER/repos/jira-performance-tests/pull-requests/630 - */ -class S3HostedJdk : VersionedJavaDevelopmentKit { - private val jdkVersion = "1.8.0" - private val jdkUpdate = 131 - private val jdkArchive = "jdk${jdkVersion}_$jdkUpdate-linux-x64.tar.gz" - private val jdkUrl = URI.create("https://s3.amazonaws.com/packages_java/$jdkArchive") - private val jdkBin = "~/jdk${jdkVersion}_$jdkUpdate/jre/bin/" - private val bin = "~/jdk${jdkVersion}_$jdkUpdate/bin/" - override val jstatMonitoring = Jstat(bin) - - override fun getMajorVersion() = 8 - - override fun install(connection: SshConnection) { - download(connection) - connection.execute("tar -xzf $jdkArchive") - connection.execute("echo '${use()}' >> ~/.bashrc") - } - - private fun download(connection: SshConnection) { - IdempotentAction("download JDK") { - connection.execute( - cmd = "curl -s -L -O -k $jdkUrl", - timeout = Duration.ofMinutes(4) - ) - }.retry( - maxAttempts = 3, - backoff = StaticBackoff(Duration.ofSeconds(4)) - ) - } - - override fun use(): String = "export PATH=$jdkBin:$bin:${'$'}PATH" - - override fun command(options: String) = "${jdkBin}java $options" -} - - class StaticBackoff( private val backoff: Duration ) : Backoff { diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt new file mode 100644 index 00000000..ec57502b --- /dev/null +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt @@ -0,0 +1,44 @@ +package com.atlassian.performance.tools.infrastructure.api.jvm + +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StaticBackoff +import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.net.URI +import java.time.Duration + +/** + * Harvested from https://stash.atlassian.com/projects/JIRASERVER/repos/jira-performance-tests/pull-requests/630 + */ +class S3HostedJdk : VersionedJavaDevelopmentKit { + private val jdkVersion = "1.8.0" + private val jdkUpdate = 131 + private val jdkArchive = "jdk${jdkVersion}_$jdkUpdate-linux-x64.tar.gz" + private val jdkUrl = URI.create("https://s3.amazonaws.com/packages_java/$jdkArchive") + private val jdkBin = "~/jdk${jdkVersion}_$jdkUpdate/jre/bin/" + private val bin = "~/jdk${jdkVersion}_$jdkUpdate/bin/" + override val jstatMonitoring = Jstat(bin) + + override fun getMajorVersion() = 8 + + override fun install(connection: SshConnection) { + download(connection) + connection.execute("tar -xzf $jdkArchive") + connection.execute("echo '${use()}' >> ~/.bashrc") + } + + private fun download(connection: SshConnection) { + IdempotentAction("download JDK") { + connection.execute( + cmd = "curl -s -L -O -k $jdkUrl", + timeout = Duration.ofMinutes(4) + ) + }.retry( + maxAttempts = 3, + backoff = StaticBackoff(Duration.ofSeconds(4)) + ) + } + + override fun use(): String = "export PATH=$jdkBin:$bin:${'$'}PATH" + + override fun command(options: String) = "${jdkBin}java $options" +} From 13a0c5c8646ba65aaa3e0e98de9e7296d5bf7673 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Wed, 16 Oct 2019 13:15:11 +0200 Subject: [PATCH 21/28] JPERF-273: Define default `JiraNodeFlow` --- .../api/jira/flow/JiraNodeFlow.kt | 33 +++++++++++++------ .../api/jira/flow/PostInstallFlow.kt | 2 +- .../api/jira/flow/PostStartFlow.kt | 2 +- .../api/jira/flow/PreInstallFlow.kt | 2 +- .../api/jira/flow/PreStartFlow.kt | 2 +- .../infrastructure/api/jira/flow/Reports.kt | 3 +- .../api/jira/flow/JiraNodeFlowTest.kt | 4 +-- .../api/jira/flow/start/HookedJiraStartIT.kt | 10 ++---- 8 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index 06e14389..756c22b0 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -1,10 +1,13 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow +import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.DefaultPostStartHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe @@ -12,7 +15,7 @@ import java.util.* import java.util.concurrent.ConcurrentLinkedQueue @ThreadSafe -class JiraNodeFlow : PreInstallFlow { +class JiraNodeFlow private constructor() : PreInstallFlow { private val preInstallHooks: Queue = ConcurrentLinkedQueue() private val postInstallHooks: Queue = ConcurrentLinkedQueue() private val preStartHooks: Queue = ConcurrentLinkedQueue() @@ -21,14 +24,14 @@ class JiraNodeFlow : PreInstallFlow { override fun hook( hook: PreInstallHook - ) { + ) = apply { preInstallHooks.add(hook) } internal fun runPreInstallHooks( ssh: SshConnection, server: TcpServer - ) { + ): JiraNodeFlow = apply { while (true) { preInstallHooks .poll() @@ -39,14 +42,14 @@ class JiraNodeFlow : PreInstallFlow { override fun hook( hook: PostInstallHook - ) { + ): PreInstallFlow = apply { postInstallHooks.add(hook) } internal fun runPostInstallHooks( ssh: SshConnection, jira: InstalledJira - ) { + ): JiraNodeFlow = apply { while (true) { postInstallHooks .poll() @@ -57,14 +60,14 @@ class JiraNodeFlow : PreInstallFlow { override fun hook( hook: PreStartHook - ) { + ): JiraNodeFlow = apply { preStartHooks.add(hook) } internal fun runPreStartHooks( ssh: SshConnection, jira: InstalledJira - ) { + ): JiraNodeFlow = apply { while (true) { preStartHooks .poll() @@ -75,14 +78,14 @@ class JiraNodeFlow : PreInstallFlow { override fun hook( hook: PostStartHook - ) { + ): JiraNodeFlow = apply { postStartHooks.add(hook) } internal fun runPostStartHooks( ssh: SshConnection, jira: StartedJira - ) { + ): JiraNodeFlow = apply { while (true) { postStartHooks .poll() @@ -91,7 +94,9 @@ class JiraNodeFlow : PreInstallFlow { } } - override fun addReport(report: Report) { + override fun addReport( + report: Report + ) = apply { reports.add(report) } @@ -105,4 +110,12 @@ class JiraNodeFlow : PreInstallFlow { .also { it.preStartHooks += this.preStartHooks } .also { it.postStartHooks += this.postStartHooks } .also { it.reports += this.reports } + + companion object { + fun default(): JiraNodeFlow = JiraNodeFlow() + .apply { hook(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } + .apply { hook(DefaultPostStartHook()) } + + fun empty(): JiraNodeFlow = JiraNodeFlow() + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt index 07033d07..1baf60dc 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt @@ -5,5 +5,5 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.Post interface PostInstallFlow : PreStartFlow { fun hook( hook: PostInstallHook - ) + ): PostInstallFlow } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt index 6885b484..175bcb20 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt @@ -5,5 +5,5 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostSt interface PostStartFlow : Reports { fun hook( hook: PostStartHook - ) + ): PostStartFlow } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt index 3240a0c2..fb054dee 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt @@ -5,5 +5,5 @@ import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreIn interface PreInstallFlow : PostInstallFlow { fun hook( hook: PreInstallHook - ) + ): PreInstallFlow } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt index 3d207ace..9f59d556 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt @@ -4,5 +4,5 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow interface PreStartFlow : PostStartFlow { fun hook( hook: PreStartHook - ) + ): PreStartFlow } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt index 628a10d1..3089ede3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt @@ -3,6 +3,5 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report interface Reports { - fun addReport(report: Report) - + fun addReport(report: Report): Reports } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt index ec433116..2e6e3006 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt @@ -15,7 +15,7 @@ class JiraNodeFlowTest { @Test fun shouldHookDuringListing() { val counter = CountingHook() - val flow = JiraNodeFlow().apply { + val flow = JiraNodeFlow.empty().apply { hook(counter) hook(HookingHook(counter)) hook(counter) @@ -30,7 +30,7 @@ class JiraNodeFlowTest { @Test fun shouldHookToTheTailDuringListing() { val counter = CountingHook() - val flow = JiraNodeFlow().apply { + val flow = JiraNodeFlow.empty().apply { hook(counter) hook(counter) hook(HookingHook(counter)) diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt index f49acbd9..3ba5589a 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt @@ -2,11 +2,9 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow.start import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome -import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.HookedJiraInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.ParallelInstallation import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira @@ -28,10 +26,7 @@ class HookedJiraStartIT { @Test fun shouldStartJiraWithDefaultHooks() { // given - val config = JiraNodeConfig.Builder().build() - val flow = JiraNodeFlow() - flow.hook(DefaultPostStartHook()) - flow.hook(DefaultPostInstallHook(config)) + val flow = JiraNodeFlow.default() val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), @@ -76,11 +71,10 @@ class HookedJiraStartIT { @Test fun shouldDownloadPartialReportsInCaseOfFailure() { // given - val flow = JiraNodeFlow().apply { + val flow = JiraNodeFlow.empty().apply { hook(EarlyUbuntuSysstat()) hook(FailingHook()) } - val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), From 1156aae652f72c6b9c5c8dcba3cf44e830301625 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Wed, 16 Oct 2019 15:44:49 +0200 Subject: [PATCH 22/28] JPERF-273: Remove fluent hook API --- .../api/jira/flow/JiraNodeFlow.kt | 107 +----------------- .../api/jira/flow/PostInstallFlow.kt | 26 ++++- .../api/jira/flow/PostStartFlow.kt | 25 +++- .../api/jira/flow/PreInstallFlow.kt | 24 +++- .../api/jira/flow/PreStartFlow.kt | 24 +++- .../infrastructure/api/jira/flow/Reports.kt | 16 ++- 6 files changed, 107 insertions(+), 115 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt index 756c22b0..e1da35be 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt @@ -2,119 +2,16 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.DefaultPostStartHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook -import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe -import java.util.* -import java.util.concurrent.ConcurrentLinkedQueue @ThreadSafe -class JiraNodeFlow private constructor() : PreInstallFlow { - private val preInstallHooks: Queue = ConcurrentLinkedQueue() - private val postInstallHooks: Queue = ConcurrentLinkedQueue() - private val preStartHooks: Queue = ConcurrentLinkedQueue() - private val postStartHooks: Queue = ConcurrentLinkedQueue() - private val reports: Queue = ConcurrentLinkedQueue() - - override fun hook( - hook: PreInstallHook - ) = apply { - preInstallHooks.add(hook) - } - - internal fun runPreInstallHooks( - ssh: SshConnection, - server: TcpServer - ): JiraNodeFlow = apply { - while (true) { - preInstallHooks - .poll() - ?.run(ssh, server, this) - ?: break - } - } - - override fun hook( - hook: PostInstallHook - ): PreInstallFlow = apply { - postInstallHooks.add(hook) - } - - internal fun runPostInstallHooks( - ssh: SshConnection, - jira: InstalledJira - ): JiraNodeFlow = apply { - while (true) { - postInstallHooks - .poll() - ?.run(ssh, jira, this) - ?: break - } - } - - override fun hook( - hook: PreStartHook - ): JiraNodeFlow = apply { - preStartHooks.add(hook) - } - - internal fun runPreStartHooks( - ssh: SshConnection, - jira: InstalledJira - ): JiraNodeFlow = apply { - while (true) { - preStartHooks - .poll() - ?.run(ssh, jira, this) - ?: break - } - } - - override fun hook( - hook: PostStartHook - ): JiraNodeFlow = apply { - postStartHooks.add(hook) - } - - internal fun runPostStartHooks( - ssh: SshConnection, - jira: StartedJira - ): JiraNodeFlow = apply { - while (true) { - postStartHooks - .poll() - ?.run(ssh, jira, this) - ?: break - } - } - - override fun addReport( - report: Report - ) = apply { - reports.add(report) - } - - internal fun allReports(): Iterable { - return reports.toList() - } - - fun copy(): JiraNodeFlow = JiraNodeFlow() - .also { it.preInstallHooks += this.preInstallHooks } - .also { it.postInstallHooks += this.postInstallHooks } - .also { it.preStartHooks += this.preStartHooks } - .also { it.postStartHooks += this.postStartHooks } - .also { it.reports += this.reports } +class JiraNodeFlow private constructor() : PreInstallFlow() { companion object { fun default(): JiraNodeFlow = JiraNodeFlow() - .apply { hook(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } .apply { hook(DefaultPostStartHook()) } + .apply { hook(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } fun empty(): JiraNodeFlow = JiraNodeFlow() } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt index 1baf60dc..a35f7b27 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt @@ -1,9 +1,31 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue + +open class PostInstallFlow protected constructor() : PreStartFlow() { + + private val postInstallHooks: Queue = ConcurrentLinkedQueue() -interface PostInstallFlow : PreStartFlow { fun hook( hook: PostInstallHook - ): PostInstallFlow + ) { + postInstallHooks.add(hook) + } + + internal fun runPostInstallHooks( + ssh: SshConnection, + jira: InstalledJira + ) { + while (true) { + postInstallHooks + .poll() + ?.run(ssh, jira, this) + ?: break + } + } + } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt index 175bcb20..b64e76be 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt @@ -1,9 +1,30 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue + +open class PostStartFlow protected constructor() : Reports() { + + private val postStartHooks: Queue = ConcurrentLinkedQueue() -interface PostStartFlow : Reports { fun hook( hook: PostStartHook - ): PostStartFlow + ) { + postStartHooks.add(hook) + } + + internal fun runPostStartHooks( + ssh: SshConnection, + jira: StartedJira + ) { + while (true) { + postStartHooks + .poll() + ?.run(ssh, jira, this) + ?: break + } + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt index fb054dee..4db6859b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt @@ -1,9 +1,29 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue + +open class PreInstallFlow protected constructor() : PostInstallFlow() { + + private val preInstallHooks: Queue = ConcurrentLinkedQueue() -interface PreInstallFlow : PostInstallFlow { fun hook( hook: PreInstallHook - ): PreInstallFlow + ) { + preInstallHooks.add(hook) + } + + internal fun runPreInstallHooks( + ssh: SshConnection, + server: TcpServer + ) { + while (true) { + preInstallHooks + .poll() + ?.run(ssh, server, this) + ?: break + } + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt index 9f59d556..55292ee8 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt @@ -1,8 +1,28 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow +import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue + +open class PreStartFlow protected constructor() : PostStartFlow() { + private val preStartHooks: Queue = ConcurrentLinkedQueue() -interface PreStartFlow : PostStartFlow { fun hook( hook: PreStartHook - ): PreStartFlow + ) { + preStartHooks.add(hook) + } + + internal fun runPreStartHooks( + ssh: SshConnection, + jira: InstalledJira + ) { + while (true) { + preStartHooks + .poll() + ?.run(ssh, jira, this) + ?: break + } + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt index 3089ede3..2024a2b5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt @@ -1,7 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.jira.flow import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue -interface Reports { - fun addReport(report: Report): Reports +open class Reports protected constructor() { + private val reports: Queue = ConcurrentLinkedQueue() + + fun addReport( + report: Report + ) { + reports.add(report) + } + + internal fun allReports(): Iterable { + return reports.toList() + } } From 23a7138c063a4a2d461bd05756d35760e244036f Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Wed, 16 Oct 2019 16:08:25 +0200 Subject: [PATCH 23/28] JPERF-273: Rename "flows" to "hooks" --- .../api/database/DatabaseIpConfig.kt | 8 ++-- .../api/database/MysqlConnector.kt | 8 ++-- .../api/jira/flow/JiraNodeFlow.kt | 18 --------- .../api/jira/flow/start/AccessLogs.kt | 13 ------ .../api/jira/flow/start/HookedJiraStart.kt | 22 ---------- .../api/jira/hook/JiraNodeHooks.kt | 18 +++++++++ .../PostInstallHooks.kt} | 8 ++-- .../PostStartHooks.kt} | 8 ++-- .../PreInstallHooks.kt} | 6 +-- .../api/jira/{flow => hook}/PreStartHook.kt | 7 ++-- .../PreStartFlow.kt => hook/PreStartHooks.kt} | 6 +-- .../api/jira/{flow => hook}/Reports.kt | 4 +- .../api/jira/{flow => hook}/TcpServer.kt | 2 +- .../{flow => hook}/install/DataCenterHook.kt | 6 +-- .../install/DefaultPostInstallHook.kt | 14 +++---- .../install/DisabledAutoBackup.kt | 6 +-- .../install/HookedJiraInstallation.kt | 14 +++---- .../{flow => hook}/install/InstalledJira.kt | 4 +- .../install/JiraHomeProperty.kt | 6 +-- .../install/JiraInstallation.kt | 8 ++-- .../jira/{flow => hook}/install/JiraLogs.kt | 10 ++--- .../jira/{flow => hook}/install/JvmConfig.kt | 10 ++--- .../install/ParallelInstallation.kt | 8 ++-- .../{flow => hook}/install/PostInstallHook.kt | 7 ++-- .../install/SequentialInstallation.kt | 8 ++-- .../jira/{flow => hook}/report/FileListing.kt | 2 +- .../api/jira/{flow => hook}/report/Report.kt | 2 +- .../{flow => hook}/report/StaticReport.kt | 2 +- .../server/AsyncProfilerHook.kt | 20 +++++----- .../server/LateUbuntuSysstat.kt | 22 +++++----- .../{flow => hook}/server/PreInstallHook.kt | 8 ++-- .../jira/{flow => hook}/server/StartedJira.kt | 4 +- .../jira/{flow => hook}/server/SystemLog.kt | 6 +-- .../api/jira/hook/start/AccessLogs.kt | 13 ++++++ .../start/DefaultPostStartHook.kt | 10 ++--- .../api/jira/hook/start/HookedJiraStart.kt | 22 ++++++++++ .../{flow => hook}/start/JiraLaunchScript.kt | 10 ++--- .../jira/{flow => hook}/start/JiraStart.kt | 10 ++--- .../jira/{flow => hook}/start/JstatHook.kt | 12 +++--- .../{flow => hook}/start/PostStartHook.kt | 8 ++-- .../jira/{flow => hook}/start/RestUpgrade.kt | 12 +++--- .../jira/flow/install/ProfilerHook.kt | 40 ------------------- .../RemoteMonitoringProcessReport.kt | 4 +- .../jira/hook/install/ProfilerHook.kt | 40 +++++++++++++++++++ .../install/SplunkForwarderHook.kt | 10 ++--- .../ubuntu/EarlyUbuntuSysstat.kt | 10 ++--- .../ubuntu/InstalledOsMetric.kt | 12 +++--- .../JiraNodeHooksTest.kt} | 20 +++++----- .../{flow => hook}/start/HookedJiraStartIT.kt | 30 +++++++------- .../infrastructure/api/jvm/S3HostedJdk.kt | 2 +- 50 files changed, 279 insertions(+), 281 deletions(-) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow/PostInstallFlow.kt => hook/PostInstallHooks.kt} (71%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow/PostStartFlow.kt => hook/PostStartHooks.kt} (71%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow/PreInstallFlow.kt => hook/PreInstallHooks.kt} (78%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/PreStartHook.kt (65%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow/PreStartFlow.kt => hook/PreStartHooks.kt} (78%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/Reports.kt (82%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/TcpServer.kt (98%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/DataCenterHook.kt (87%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/DefaultPostInstallHook.kt (64%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/DisabledAutoBackup.kt (73%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/HookedJiraInstallation.kt (50%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/InstalledJira.kt (81%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/JiraHomeProperty.kt (77%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/JiraInstallation.kt (60%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/JiraLogs.kt (65%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/JvmConfig.kt (76%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/ParallelInstallation.kt (87%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/PostInstallHook.kt (64%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/install/SequentialInstallation.kt (81%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/report/FileListing.kt (96%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/report/Report.kt (94%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/report/StaticReport.kt (95%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/server/AsyncProfilerHook.kt (74%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/server/LateUbuntuSysstat.kt (53%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/server/PreInstallHook.kt (52%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/server/StartedJira.kt (57%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/server/SystemLog.kt (60%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/start/DefaultPostStartHook.kt (54%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/start/JiraLaunchScript.kt (68%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/start/JiraStart.kt (50%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/start/JstatHook.kt (51%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/start/PostStartHook.kt (52%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/start/RestUpgrade.kt (85%) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/{flow => hook}/RemoteMonitoringProcessReport.kt (73%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/{flow => hook}/install/SplunkForwarderHook.kt (59%) rename src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow/JiraNodeFlowTest.kt => hook/JiraNodeHooksTest.kt} (79%) rename src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{flow => hook}/start/HookedJiraStartIT.kt (81%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt index 0ef56cd7..7bd6fd95 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt @@ -1,9 +1,9 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.api.Sed -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection class DatabaseIpConfig( @@ -13,7 +13,7 @@ class DatabaseIpConfig( override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { Sed().replace( connection = ssh, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt index e29e2820..198eff6f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.database -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook import com.atlassian.performance.tools.jvmtasks.api.Backoff import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection @@ -13,7 +13,7 @@ class MysqlConnector : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { val connector = "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz" IdempotentAction( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt deleted file mode 100644 index e1da35be..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlow.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow - -import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.DefaultPostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.DefaultPostStartHook -import net.jcip.annotations.ThreadSafe - -@ThreadSafe -class JiraNodeFlow private constructor() : PreInstallFlow() { - - companion object { - fun default(): JiraNodeFlow = JiraNodeFlow() - .apply { hook(DefaultPostStartHook()) } - .apply { hook(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } - - fun empty(): JiraNodeFlow = JiraNodeFlow() - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt deleted file mode 100644 index 37b25dfd..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/AccessLogs.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.ssh.api.SshConnection - -class AccessLogs : PostStartHook { - - override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { - flow.addReport(FileListing("${jira.installed.installation}/logs/*access*")) - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt deleted file mode 100644 index 30d290a9..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStart.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.ssh.api.SshConnection - -class HookedJiraStart( - private val start: JiraStart -) : JiraStart { - - override fun start( - ssh: SshConnection, - installed: InstalledJira, - flow: JiraNodeFlow - ): StartedJira { - flow.runPreStartHooks(ssh, installed) - val started = start.start(ssh, installed, flow) - flow.runPostStartHooks(ssh, started) - return started - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt new file mode 100644 index 00000000..8d292dd7 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt @@ -0,0 +1,18 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.hook + +import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.DefaultPostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.DefaultPostStartHook +import net.jcip.annotations.ThreadSafe + +@ThreadSafe +class JiraNodeHooks private constructor() : PreInstallHooks() { + + companion object { + fun default(): JiraNodeHooks = JiraNodeHooks() + .apply { hook(DefaultPostStartHook()) } + .apply { hook(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } + + fun empty(): JiraNodeHooks = JiraNodeHooks() + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostInstallHooks.kt similarity index 71% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostInstallHooks.kt index a35f7b27..c6682cc0 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostInstallFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostInstallHooks.kt @@ -1,12 +1,12 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class PostInstallFlow protected constructor() : PreStartFlow() { +open class PostInstallHooks protected constructor() : PreStartHooks() { private val postInstallHooks: Queue = ConcurrentLinkedQueue() diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostStartHooks.kt similarity index 71% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostStartHooks.kt index b64e76be..3c4fefab 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PostStartFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostStartHooks.kt @@ -1,12 +1,12 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class PostStartFlow protected constructor() : Reports() { +open class PostStartHooks protected constructor() : Reports() { private val postStartHooks: Queue = ConcurrentLinkedQueue() diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreInstallHooks.kt similarity index 78% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreInstallHooks.kt index 4db6859b..c4633f6d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreInstallFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreInstallHooks.kt @@ -1,11 +1,11 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class PreInstallFlow protected constructor() : PostInstallFlow() { +open class PreInstallHooks protected constructor() : PostInstallHooks() { private val preInstallHooks: Queue = ConcurrentLinkedQueue() diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHook.kt similarity index 65% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHook.kt index 1629131b..e4d29748 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHook.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection interface PreStartHook { @@ -8,7 +8,6 @@ interface PreStartHook { fun run( ssh: SshConnection, jira: InstalledJira, - flow: PreStartFlow + hooks: PreStartHooks ) - } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHooks.kt similarity index 78% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHooks.kt index 55292ee8..2daf7636 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/PreStartFlow.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHooks.kt @@ -1,11 +1,11 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class PreStartFlow protected constructor() : PostStartFlow() { +open class PreStartHooks protected constructor() : PostStartHooks() { private val preStartHooks: Queue = ConcurrentLinkedQueue() fun hook( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt similarity index 82% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt index 2024a2b5..fb1e5c0d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/Reports.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report import java.util.* import java.util.concurrent.ConcurrentLinkedQueue diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/TcpServer.kt similarity index 98% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/TcpServer.kt index d541199e..739e68f5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/TcpServer.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/TcpServer.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook class TcpServer( val ip: String, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt similarity index 87% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt index a8f5acc7..92aa093a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DataCenterHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection class DataCenterHook( @@ -12,7 +12,7 @@ class DataCenterHook( override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { val localSharedHome = sharedHome.localSharedHome sharedHome.mount(ssh) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt similarity index 64% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt index 061c649d..388b656a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DefaultPostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt @@ -1,10 +1,10 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.LateUbuntuSysstat -import com.atlassian.performance.tools.infrastructure.jira.flow.install.ProfilerHook -import com.atlassian.performance.tools.infrastructure.jira.flow.install.SplunkForwarderHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.LateUbuntuSysstat +import com.atlassian.performance.tools.infrastructure.jira.hook.install.ProfilerHook +import com.atlassian.performance.tools.infrastructure.jira.hook.install.SplunkForwarderHook import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultPostInstallHook( @@ -14,7 +14,7 @@ class DefaultPostInstallHook( override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { listOf( JiraHomeProperty(), @@ -24,6 +24,6 @@ class DefaultPostInstallHook( SplunkForwarderHook(config.splunkForwarder), JiraLogs(), LateUbuntuSysstat() - ).forEach { it.run(ssh, jira, flow) } + ).forEach { it.run(ssh, jira, hooks) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt similarity index 73% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt index 18050416..6152d1e9 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection class DisabledAutoBackup : PostInstallHook { @@ -8,7 +8,7 @@ class DisabledAutoBackup : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { ssh.execute("echo jira.autoexport=false > ${jira.home}/jira-config.properties") } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt similarity index 50% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt index 6b3175d0..3379bf72 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraInstallation( @@ -11,11 +11,11 @@ class HookedJiraInstallation( override fun install( ssh: SshConnection, server: TcpServer, - flow: JiraNodeFlow + hooks: JiraNodeHooks ): InstalledJira { - flow.runPreInstallHooks(ssh, server) - val installed = installation.install(ssh, server, flow) - flow.runPostInstallHooks(ssh, installed) + hooks.runPreInstallHooks(ssh, server) + val installed = installation.install(ssh, server, hooks) + hooks.runPostInstallHooks(ssh, installed) return installed } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt similarity index 81% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt index 86a0c49a..5fa9a1c7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit class InstalledJira( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt similarity index 77% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt index e1a08cee..8b4162af 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection class JiraHomeProperty : PostInstallHook { @@ -8,7 +8,7 @@ class JiraHomeProperty : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { val properties = "${jira.installation}/atlassian-jira/WEB-INF/classes/jira-application.properties" ssh.execute("echo jira.home=`realpath ${jira.home}` > $properties") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt similarity index 60% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt index 16d30a2c..6f087bc6 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe @@ -11,6 +11,6 @@ interface JiraInstallation { fun install( ssh: SshConnection, server: TcpServer, - flow: JiraNodeFlow + hooks: JiraNodeHooks ): InstalledJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt similarity index 65% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt index 116a9c16..7c3086e2 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt @@ -1,21 +1,21 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection import java.nio.file.Path import java.nio.file.Paths class JiraLogs : PostInstallHook { - override fun run(ssh: SshConnection, jira: InstalledJira, flow: PostInstallFlow) { + override fun run(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks) { listOf( "${jira.home}/log/atlassian-jira.log", "${jira.installation}/logs/catalina.out" ) .onEach { ensureFile(Paths.get(it), ssh) } .map { StaticReport(it) } - .forEach { flow.addReport(it) } + .forEach { hooks.addReport(it) } } private fun ensureFile( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt similarity index 76% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt index f062590d..47ec3a84 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt @@ -1,10 +1,10 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.FileListing +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.FileListing import com.atlassian.performance.tools.ssh.api.SshConnection class JvmConfig( @@ -14,7 +14,7 @@ class JvmConfig( override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { val gcLog = JiraGcLog(jira.installation) SetenvSh(jira.installation).setup( @@ -24,6 +24,6 @@ class JvmConfig( jiraIp = jira.server.ip ) val report = FileListing(gcLog.path("*")) - flow.addReport(report) + hooks.addReport(report) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ParallelInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt similarity index 87% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ParallelInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt index 7b448761..e4d60eeb 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/ParallelInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt @@ -1,10 +1,10 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.concurrency.api.submitWithLogContext import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.concurrent.Executors @@ -18,7 +18,7 @@ class ParallelInstallation( override fun install( ssh: SshConnection, server: TcpServer, - flow: JiraNodeFlow + hooks: JiraNodeHooks ): InstalledJira { val pool = Executors.newCachedThreadPool { runnable -> Thread(runnable, "jira-installation-${runnable.hashCode()}") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt similarity index 64% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt index 4b8026c5..e2cdfd9d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/PostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection interface PostInstallHook { @@ -8,7 +8,6 @@ interface PostInstallHook { fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) - } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SequentialInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt similarity index 81% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SequentialInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt index 853dc84c..b1684ca3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/install/SequentialInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt @@ -1,9 +1,9 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.install +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit import com.atlassian.performance.tools.ssh.api.SshConnection @@ -16,7 +16,7 @@ class SequentialInstallation( override fun install( ssh: SshConnection, server: TcpServer, - flow: JiraNodeFlow + hooks: JiraNodeHooks ): InstalledJira { val installation = productDistribution.install(ssh, ".") val home = jiraHomeSource.download(ssh) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/FileListing.kt similarity index 96% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/FileListing.kt index c63f91a2..45434e73 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/FileListing.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/FileListing.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.report +package com.atlassian.performance.tools.infrastructure.api.jira.hook.report import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt similarity index 94% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt index 44a79d79..5d6aebfc 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/Report.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.report +package com.atlassian.performance.tools.infrastructure.api.jira.hook.report import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/StaticReport.kt similarity index 95% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/StaticReport.kt index bec01d7b..a64e1a48 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/report/StaticReport.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/StaticReport.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.report +package com.atlassian.performance.tools.infrastructure.api.jira.hook.report import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/AsyncProfilerHook.kt similarity index 74% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/AsyncProfilerHook.kt index 0dac4ea1..e83a5120 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/AsyncProfilerHook.kt @@ -1,10 +1,10 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI @@ -13,7 +13,7 @@ class AsyncProfilerHook : PreInstallHook { override fun run( ssh: SshConnection, server: TcpServer, - flow: PreInstallFlow + hooks: PreInstallHooks ) { val directory = "async-profiler" val downloads = URI("https://github.com/jvm-profiling-tools/async-profiler/releases/download/") @@ -25,7 +25,7 @@ class AsyncProfilerHook : PreInstallHook { ssh.execute("sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'") val profilerPath = "./$directory/profiler.sh" val profiler = InstalledAsyncProfiler(profilerPath) - flow.hook(profiler) + hooks.hook(profiler) } } @@ -36,11 +36,11 @@ private class InstalledAsyncProfiler( override fun run( ssh: SshConnection, jira: StartedJira, - flow: PostStartFlow + hooks: PostStartHooks ) { ssh.execute("$profilerPath -b 20000000 start ${jira.pid}") val profiler = StartedAsyncProfiler(jira.pid, profilerPath) - flow.addReport(profiler) + hooks.addReport(profiler) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/LateUbuntuSysstat.kt similarity index 53% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/LateUbuntuSysstat.kt index bf649e8c..ec65cf5e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/LateUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/LateUbuntuSysstat.kt @@ -1,36 +1,36 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.server import com.atlassian.performance.tools.infrastructure.Iostat -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu import com.atlassian.performance.tools.infrastructure.api.os.Vmstat -import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection class LateUbuntuSysstat : PostInstallHook { override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { val ubuntu = Ubuntu() ubuntu.install(ssh, listOf("sysstat")) listOf(Vmstat(), Iostat()) .map { PostStartOsMetric(it) } - .forEach { flow.hook(it) } + .forEach { hooks.hook(it) } } } internal class PostStartOsMetric( private val metric: OsMetric ) : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { + override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { val process = metric.start(ssh) - flow.addReport(RemoteMonitoringProcessReport(process)) + hooks.addReport(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/PreInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/PreInstallHook.kt similarity index 52% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/PreInstallHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/PreInstallHook.kt index 1c426ced..a92e2856 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/PreInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/PreInstallHook.kt @@ -1,13 +1,13 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection interface PreInstallHook { fun run( ssh: SshConnection, server: TcpServer, - flow: PreInstallFlow + hooks: PreInstallHooks ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/StartedJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/StartedJira.kt similarity index 57% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/StartedJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/StartedJira.kt index 0dc47371..9200032b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/StartedJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/StartedJira.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira class StartedJira( val installed: InstalledJira, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/SystemLog.kt similarity index 60% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/SystemLog.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/SystemLog.kt index 7885f01f..bba920f6 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/server/SystemLog.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/SystemLog.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.server -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection class SystemLog : Report { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt new file mode 100644 index 00000000..a20c82b4 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt @@ -0,0 +1,13 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start + +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.FileListing +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.ssh.api.SshConnection + +class AccessLogs : PostStartHook { + + override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { + hooks.addReport(FileListing("${jira.installed.installation}/logs/*access*")) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt similarity index 54% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt index 54cd6126..3b40da27 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/DefaultPostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultPostStartHook : PostStartHook { @@ -9,10 +9,10 @@ class DefaultPostStartHook : PostStartHook { override fun run( ssh: SshConnection, jira: StartedJira, - flow: PostStartFlow + hooks: PostStartHooks ) { listOf( JstatHook() - ).forEach { it.run(ssh, jira, flow) } + ).forEach { it.run(ssh, jira, hooks) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt new file mode 100644 index 00000000..330fa3e9 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt @@ -0,0 +1,22 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start + +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.ssh.api.SshConnection + +class HookedJiraStart( + private val start: JiraStart +) : JiraStart { + + override fun start( + ssh: SshConnection, + installed: InstalledJira, + hooks: JiraNodeHooks + ): StartedJira { + hooks.runPreStartHooks(ssh, installed) + val started = start.start(ssh, installed, hooks) + hooks.runPostStartHooks(ssh, started) + return started + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt similarity index 68% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt index 90e66907..9ddc5f2e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraLaunchScript.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt @@ -1,8 +1,8 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection import java.time.Duration @@ -11,7 +11,7 @@ class JiraLaunchScript : JiraStart { override fun start( ssh: SshConnection, installed: InstalledJira, - flow: JiraNodeFlow + hooks: JiraNodeHooks ): StartedJira { ssh.execute( "${installed.jdk.use()}; ${installed.installation}/bin/start-jira.sh", diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt similarity index 50% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt index 7f913ef7..b272933c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt @@ -1,8 +1,8 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe @@ -12,6 +12,6 @@ interface JiraStart { fun start( ssh: SshConnection, installed: InstalledJira, - flow: JiraNodeFlow + hooks: JiraNodeHooks ): StartedJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt similarity index 51% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt index 4ace72c6..12248c15 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt @@ -1,8 +1,8 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection class JstatHook : PostStartHook { @@ -10,9 +10,9 @@ class JstatHook : PostStartHook { override fun run( ssh: SshConnection, jira: StartedJira, - flow: PostStartFlow + hooks: PostStartHooks ) { val process = jira.installed.jdk.jstatMonitoring.start(ssh, jira.pid) - flow.addReport(RemoteMonitoringProcessReport(process)) + hooks.addReport(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt similarity index 52% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt index e9541666..39f1795b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/PostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection interface PostStartHook { @@ -9,6 +9,6 @@ interface PostStartHook { fun run( ssh: SshConnection, jira: StartedJira, - flow: PostStartFlow + hooks: PostStartHooks ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt similarity index 85% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt index 25ab900a..5d19a86c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt @@ -1,9 +1,9 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.StaticReport -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI @@ -16,11 +16,11 @@ class RestUpgrade( private val adminPassword: String ) : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { + override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) val privatePort = jira.installed.server.privatePort val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:$privatePort/rest/api/2/upgrade") - flow.addReport(StaticReport("thread-dumps")) + hooks.addReport(StaticReport("thread-dumps")) waitForStatusToChange( statusQuo = "000", timeout = timeouts.offlineTimeout, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt deleted file mode 100644 index d7d3d949..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/ProfilerHook.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.jira.flow.install - -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.PostStartHook -import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler -import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport -import com.atlassian.performance.tools.ssh.api.SshConnection - -/** - * Bridges the [Profiler] SPI with the [PostInstallHook] SPI. - * In general any [Profiler] can be rewritten as an [PostInstallHook] or any other hookPreStart without this bridge. - */ -class ProfilerHook( - private val profiler: Profiler -) : PostInstallHook { - override fun run(ssh: SshConnection, jira: InstalledJira, flow: PostInstallFlow) { - profiler.install(ssh) - flow.hook(InstalledProfiler(profiler)) - } -} - -private class InstalledProfiler( - private val profiler: Profiler -) : PostStartHook { - - override fun run( - ssh: SshConnection, - jira: StartedJira, - flow: PostStartFlow - ) { - val process = profiler.start(ssh, jira.pid) - if (process != null) { - flow.addReport(RemoteMonitoringProcessReport(process)) - } - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/RemoteMonitoringProcessReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/RemoteMonitoringProcessReport.kt similarity index 73% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/RemoteMonitoringProcessReport.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/RemoteMonitoringProcessReport.kt index cf1100b9..2764836f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/RemoteMonitoringProcessReport.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/RemoteMonitoringProcessReport.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.jira.flow +package com.atlassian.performance.tools.infrastructure.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report import com.atlassian.performance.tools.infrastructure.api.process.RemoteMonitoringProcess import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt new file mode 100644 index 00000000..100bb7dc --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt @@ -0,0 +1,40 @@ +package com.atlassian.performance.tools.infrastructure.jira.hook.install + +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler +import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.ssh.api.SshConnection + +/** + * Bridges the [Profiler] SPI with the [PostInstallHook] SPI. + * In general any [Profiler] can be rewritten as an [PostInstallHook] or any other hookPreStart without this bridge. + */ +class ProfilerHook( + private val profiler: Profiler +) : PostInstallHook { + override fun run(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks) { + profiler.install(ssh) + hooks.hook(InstalledProfiler(profiler)) + } +} + +private class InstalledProfiler( + private val profiler: Profiler +) : PostStartHook { + + override fun run( + ssh: SshConnection, + jira: StartedJira, + hooks: PostStartHooks + ) { + val process = profiler.start(ssh, jira.pid) + if (process != null) { + hooks.addReport(RemoteMonitoringProcessReport(process)) + } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt similarity index 59% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt index 9512abd3..c6a22a29 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/flow/install/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt @@ -1,8 +1,8 @@ -package com.atlassian.performance.tools.infrastructure.jira.flow.install +package com.atlassian.performance.tools.infrastructure.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.splunk.SplunkForwarder import com.atlassian.performance.tools.ssh.api.SshConnection @@ -13,7 +13,7 @@ internal class SplunkForwarderHook( override fun run( ssh: SshConnection, jira: InstalledJira, - flow: PostInstallFlow + hooks: PostInstallHooks ) { splunk.jsonifyLog4j(ssh, "${jira.installation}/atlassian-jira/WEB-INF/classes/log4j.properties") splunk.run(ssh, jira.server.name, "/home/ubuntu/jirahome/log") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt index 8b0f4ef1..e7a946e0 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection class EarlyUbuntuSysstat : PreInstallHook { @@ -10,10 +10,10 @@ class EarlyUbuntuSysstat : PreInstallHook { override fun run( ssh: SshConnection, server: TcpServer, - flow: PreInstallFlow + hooks: PreInstallHooks ) { UbuntuSysstat() .install(ssh) - .forEach { flow.hook(it) } + .forEach { hooks.hook(it) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt index 6edd02de..fdce147b 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt @@ -1,18 +1,18 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PreInstallFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric -import com.atlassian.performance.tools.infrastructure.jira.flow.RemoteMonitoringProcessReport +import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection internal class InstalledOsMetric( private val metric: OsMetric ) : PreInstallHook { - override fun run(ssh: SshConnection, server: TcpServer, flow: PreInstallFlow) { + override fun run(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { val process = metric.start(ssh) - flow.addReport(RemoteMonitoringProcessReport(process)) + hooks.addReport(RemoteMonitoringProcessReport(process)) } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt similarity index 79% rename from src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt rename to src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt index 2e6e3006..428bed19 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/JiraNodeFlowTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow +package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook import com.atlassian.performance.tools.ssh.api.DetachedProcess import com.atlassian.performance.tools.ssh.api.SshConnection import org.apache.logging.log4j.Level @@ -10,19 +10,19 @@ import java.io.File import java.nio.file.Path import java.time.Duration -class JiraNodeFlowTest { +class JiraNodeHooksTest { @Test fun shouldHookDuringListing() { val counter = CountingHook() - val flow = JiraNodeFlow.empty().apply { + val hooks = JiraNodeHooks.empty().apply { hook(counter) hook(HookingHook(counter)) hook(counter) } val server = TcpServer("doesn't matter", 123, "fake-server") - flow.runPreInstallHooks(FailingSshConnection(), server) + hooks.runPreInstallHooks(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -30,14 +30,14 @@ class JiraNodeFlowTest { @Test fun shouldHookToTheTailDuringListing() { val counter = CountingHook() - val flow = JiraNodeFlow.empty().apply { + val hooks = JiraNodeHooks.empty().apply { hook(counter) hook(counter) hook(HookingHook(counter)) } val server = TcpServer("doesn't matter", 123, "fake-server") - flow.runPreInstallHooks(FailingSshConnection(), server) + hooks.runPreInstallHooks(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -47,7 +47,7 @@ private class CountingHook : PreInstallHook { var count = 0 - override fun run(ssh: SshConnection, server: TcpServer, flow: PreInstallFlow) { + override fun run(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { count++ } } @@ -55,8 +55,8 @@ private class CountingHook : PreInstallHook { private class HookingHook( private val hook: PreInstallHook ) : PreInstallHook { - override fun run(ssh: SshConnection, server: TcpServer, flow: PreInstallFlow) { - flow.hook(hook) + override fun run(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { + hooks.hook(hook) } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt similarity index 81% rename from src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt rename to src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt index 3ba5589a..de592753 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/flow/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt @@ -1,13 +1,13 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.flow.start +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome -import com.atlassian.performance.tools.infrastructure.api.jira.flow.JiraNodeFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.PostStartFlow -import com.atlassian.performance.tools.infrastructure.api.jira.flow.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.HookedJiraInstallation -import com.atlassian.performance.tools.infrastructure.api.jira.flow.install.ParallelInstallation -import com.atlassian.performance.tools.infrastructure.api.jira.flow.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.HookedJiraInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.ParallelInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.S3HostedJdk import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.infrastructure.ubuntu.EarlyUbuntuSysstat @@ -26,7 +26,7 @@ class HookedJiraStartIT { @Test fun shouldStartJiraWithDefaultHooks() { // given - val flow = JiraNodeFlow.default() + val hooks = JiraNodeHooks.default() val jiraInstallation = HookedJiraInstallation(ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), @@ -46,10 +46,10 @@ class HookedJiraStartIT { ) val remoteReports = sshUbuntu.toSsh().newConnection().use { ssh -> // when - val installed = jiraInstallation.install(ssh, server, flow) - val started = jiraStart.start(ssh, installed, flow) + val installed = jiraInstallation.install(ssh, server, hooks) + val started = jiraStart.start(ssh, installed, hooks) stop(started, ssh) - flow.allReports().flatMap { it.locate(ssh) } + hooks.allReports().flatMap { it.locate(ssh) } } // then @@ -71,7 +71,7 @@ class HookedJiraStartIT { @Test fun shouldDownloadPartialReportsInCaseOfFailure() { // given - val flow = JiraNodeFlow.empty().apply { + val hooks = JiraNodeHooks.empty().apply { hook(EarlyUbuntuSysstat()) hook(FailingHook()) } @@ -94,11 +94,11 @@ class HookedJiraStartIT { return@use sshUbuntu.toSsh().newConnection().use useSsh@{ ssh -> // when try { - jiraInstallation.install(ssh, server, flow) + jiraInstallation.install(ssh, server, hooks) } catch (e: Exception) { println("Failed: ${e.message}") } - return@useSsh flow.allReports().flatMap { it.locate(ssh) } + return@useSsh hooks.allReports().flatMap { it.locate(ssh) } } } @@ -131,7 +131,7 @@ class HookedJiraStartIT { } private class FailingHook : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, flow: PostStartFlow) { + override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { throw Exception("Expected failure") } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt index ec57502b..c4d67ae6 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt @@ -1,6 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jvm -import com.atlassian.performance.tools.infrastructure.api.jira.flow.start.StaticBackoff +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.StaticBackoff import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI From c18a5b0870589f44dc04925fe363fbff4bc52ef9 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Wed, 16 Oct 2019 16:44:22 +0200 Subject: [PATCH 24/28] Expose `Reports.listReports` --- .../performance/tools/infrastructure/api/jira/hook/Reports.kt | 2 +- .../infrastructure/api/jira/hook/start/HookedJiraStartIT.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt index fb1e5c0d..25b109ed 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt @@ -13,7 +13,7 @@ open class Reports protected constructor() { reports.add(report) } - internal fun allReports(): Iterable { + fun listReports(): Iterable { return reports.toList() } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt index de592753..b90f3e2e 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt @@ -49,7 +49,7 @@ class HookedJiraStartIT { val installed = jiraInstallation.install(ssh, server, hooks) val started = jiraStart.start(ssh, installed, hooks) stop(started, ssh) - hooks.allReports().flatMap { it.locate(ssh) } + hooks.listReports().flatMap { it.locate(ssh) } } // then @@ -98,7 +98,7 @@ class HookedJiraStartIT { } catch (e: Exception) { println("Failed: ${e.message}") } - return@useSsh hooks.allReports().flatMap { it.locate(ssh) } + return@useSsh hooks.listReports().flatMap { it.locate(ssh) } } } From 26bdabbc719864d22bb2962694fb5216fb69d7ca Mon Sep 17 00:00:00 2001 From: Marcin Masiorski Date: Fri, 18 Oct 2019 10:40:03 +0200 Subject: [PATCH 25/28] JPERF-273 Postgres 9.6.15 --- .../api/database/PostgresDatabase.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/PostgresDatabase.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/PostgresDatabase.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/PostgresDatabase.kt new file mode 100644 index 00000000..602889df --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/PostgresDatabase.kt @@ -0,0 +1,51 @@ +package com.atlassian.performance.tools.infrastructure.api.database + +import com.atlassian.performance.tools.infrastructure.DockerImage +import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage +import com.atlassian.performance.tools.ssh.api.SshConnection +import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.Logger +import java.net.URI +import java.time.Duration + +class PostgresDatabase( + private val source: DatasetPackage, + private val maxConnections: Int +) : Database { + private val logger: Logger = LogManager.getLogger(this::class.java) + + private val image: DockerImage = DockerImage( + name = "postgres:9.6.15", + pullTimeout = Duration.ofMinutes(5) + ) + + constructor( + source: DatasetPackage + ) : this( + source = source, + maxConnections = 200 + ) + + override fun setup(ssh: SshConnection): String { + val data = source.download(ssh) + val containerName = image.run( + ssh = ssh, +// TODO Dataset for Postgres +// parameters = "-p 5432:5432 -v `realpath $data`:/", + parameters = "-p 5432:5432", + arguments = "-c 'listen_addresses='*'' -c 'max_connections=$maxConnections'" + ) + Thread.sleep(Duration.ofSeconds(15).toMillis()) + logger.debug("Postgres - creating jira user and database") + ssh.execute("sudo docker exec -u postgres $containerName psql --command \"CREATE USER jira WITH NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN PASSWORD 'jira';\"") + ssh.execute("sudo docker exec -u postgres $containerName createdb -E UNICODE -l C -T template0 -O jira jira") + return data + } + + override fun start(jira: URI, ssh: SshConnection) { + // TODO Check logs for the following entry + // LOG: database system is ready to accept connections + Thread.sleep(Duration.ofSeconds(15).toMillis()) + } + +} \ No newline at end of file From 2742b7523cdd9d3ffcc9606ff6293d6b6a98a67b Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 22 Jan 2021 16:54:41 +0100 Subject: [PATCH 26/28] Refactor hooks: composition over inheritance Add JavaDoc. Use terminology of "insert" and "call" as per [common terminology]. Repackage hooks. [common terminology]: https://en.wikipedia.org/wiki/Hooking --- .../api/database/DatabaseIpConfig.kt | 4 +- .../api/database/MysqlConnector.kt | 4 +- .../api/jira/hook/JiraNodeHooks.kt | 13 +++-- .../api/jira/hook/PreInstallHooks.kt | 29 ----------- .../{server => install}/AsyncProfilerHook.kt | 14 +++--- .../api/jira/hook/install/DataCenterHook.kt | 3 +- .../hook/install/DefaultPostInstallHook.kt | 6 +-- .../jira/hook/install/DisabledAutoBackup.kt | 3 +- .../hook/install/HookedJiraInstallation.kt | 14 +++--- .../api/jira/hook/install/InstalledJira.kt | 1 - .../api/jira/hook/install/JiraHomeProperty.kt | 3 +- .../api/jira/hook/install/JiraInstallation.kt | 5 +- .../api/jira/hook/install/JiraLogs.kt | 5 +- .../api/jira/hook/install/JvmConfig.kt | 5 +- .../{server => install}/LateUbuntuSysstat.kt | 15 +++--- .../jira/hook/install/ParallelInstallation.kt | 5 +- .../api/jira/hook/install/PostInstallHook.kt | 11 ++++- .../hook/{ => install}/PostInstallHooks.kt | 20 +++++--- .../{server => install}/PreInstallHook.kt | 15 ++++-- .../api/jira/hook/install/PreInstallHooks.kt | 32 ++++++++++++ .../hook/install/SequentialInstallation.kt | 5 +- .../hook/{server => install}/StartedJira.kt | 4 +- .../hook/{server => install}/SystemLog.kt | 2 +- .../api/jira/hook/{ => install}/TcpServer.kt | 2 +- .../api/jira/hook/report/Report.kt | 8 +++ .../api/jira/hook/{ => report}/Reports.kt | 9 ++-- .../api/jira/hook/start/AccessLogs.kt | 7 ++- .../jira/hook/start/DefaultPostStartHook.kt | 7 ++- .../api/jira/hook/start/HookedJiraStart.kt | 15 +++--- .../api/jira/hook/start/JiraLaunchScript.kt | 6 +-- .../api/jira/hook/start/JiraStart.kt | 6 +-- .../api/jira/hook/start/JstatHook.kt | 7 ++- .../api/jira/hook/start/PostStartHook.kt | 13 +++-- .../jira/hook/{ => start}/PostStartHooks.kt | 20 ++++---- .../api/jira/hook/{ => start}/PreStartHook.kt | 12 ++++- .../jira/hook/{ => start}/PreStartHooks.kt | 19 ++++--- .../api/jira/hook/start/RestUpgrade.kt | 7 ++- .../jira/hook/install/ProfilerHook.kt | 14 +++--- .../jira/hook/install/SplunkForwarderHook.kt | 4 +- .../ubuntu/EarlyUbuntuSysstat.kt | 10 ++-- .../ubuntu/InstalledOsMetric.kt | 10 ++-- .../api/jira/hook/JiraNodeHooksTest.kt | 26 +++++----- .../api/jira/hook/start/HookedJiraStartIT.kt | 49 ++++++++++--------- 43 files changed, 248 insertions(+), 221 deletions(-) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreInstallHooks.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{server => install}/AsyncProfilerHook.kt (86%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{server => install}/LateUbuntuSysstat.kt (67%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{ => install}/PostInstallHooks.kt (57%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{server => install}/PreInstallHook.kt (50%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHooks.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{server => install}/StartedJira.kt (57%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{server => install}/SystemLog.kt (97%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{ => install}/TcpServer.kt (96%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{ => report}/Reports.kt (61%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{ => start}/PostStartHooks.kt (60%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{ => start}/PreStartHook.kt (58%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/{ => start}/PreStartHooks.kt (61%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt index 7bd6fd95..08df4cd4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.api.Sed -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection @@ -10,7 +10,7 @@ class DatabaseIpConfig( private val databaseIp: String ) : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt index 198eff6f..be1ae5f4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt @@ -1,6 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.database -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook import com.atlassian.performance.tools.jvmtasks.api.Backoff @@ -10,7 +10,7 @@ import java.time.Duration class MysqlConnector : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt index 8d292dd7..c680df66 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt @@ -2,16 +2,23 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.DefaultPostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.DefaultPostStartHook import net.jcip.annotations.ThreadSafe @ThreadSafe -class JiraNodeHooks private constructor() : PreInstallHooks() { +class JiraNodeHooks { + + val preInstall = PreInstallHooks() + val postInstall = preInstall.postInstall + val preStart = postInstall.preStart + val postStart = preStart.postStart + val reports = postStart.reports companion object { fun default(): JiraNodeHooks = JiraNodeHooks() - .apply { hook(DefaultPostStartHook()) } - .apply { hook(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } + .apply { postStart.insert(DefaultPostStartHook()) } + .apply { postInstall.insert(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } fun empty(): JiraNodeHooks = JiraNodeHooks() } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreInstallHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreInstallHooks.kt deleted file mode 100644 index c4633f6d..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreInstallHooks.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook - -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook -import com.atlassian.performance.tools.ssh.api.SshConnection -import java.util.* -import java.util.concurrent.ConcurrentLinkedQueue - -open class PreInstallHooks protected constructor() : PostInstallHooks() { - - private val preInstallHooks: Queue = ConcurrentLinkedQueue() - - fun hook( - hook: PreInstallHook - ) { - preInstallHooks.add(hook) - } - - internal fun runPreInstallHooks( - ssh: SshConnection, - server: TcpServer - ) { - while (true) { - preInstallHooks - .poll() - ?.run(ssh, server, this) - ?: break - } - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/AsyncProfilerHook.kt similarity index 86% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/AsyncProfilerHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/AsyncProfilerHook.kt index e83a5120..2ac9b0ca 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/AsyncProfilerHook.kt @@ -1,8 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection @@ -10,7 +8,7 @@ import java.net.URI class AsyncProfilerHook : PreInstallHook { - override fun run( + override fun call( ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks @@ -25,7 +23,7 @@ class AsyncProfilerHook : PreInstallHook { ssh.execute("sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'") val profilerPath = "./$directory/profiler.sh" val profiler = InstalledAsyncProfiler(profilerPath) - hooks.hook(profiler) + hooks.postStart.insert(profiler) } } @@ -33,14 +31,14 @@ private class InstalledAsyncProfiler( private val profilerPath: String ) : PostStartHook { - override fun run( + override fun call( ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks ) { ssh.execute("$profilerPath -b 20000000 start ${jira.pid}") val profiler = StartedAsyncProfiler(jira.pid, profilerPath) - hooks.addReport(profiler) + hooks.reports.add(profiler) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt index 92aa093a..76072799 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt @@ -1,7 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection class DataCenterHook( @@ -9,7 +8,7 @@ class DataCenterHook( private val sharedHome: SharedHome ) : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt index 388b656a..e430f371 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt @@ -1,8 +1,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.LateUbuntuSysstat import com.atlassian.performance.tools.infrastructure.jira.hook.install.ProfilerHook import com.atlassian.performance.tools.infrastructure.jira.hook.install.SplunkForwarderHook import com.atlassian.performance.tools.ssh.api.SshConnection @@ -11,7 +9,7 @@ class DefaultPostInstallHook( private val config: JiraNodeConfig ) : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks @@ -24,6 +22,6 @@ class DefaultPostInstallHook( SplunkForwarderHook(config.splunkForwarder), JiraLogs(), LateUbuntuSysstat() - ).forEach { it.run(ssh, jira, hooks) } + ).forEach { it.call(ssh, jira, hooks) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt index 6152d1e9..cfee8e56 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt @@ -1,11 +1,10 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection class DisabledAutoBackup : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt index 3379bf72..77ed9850 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt @@ -1,21 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraInstallation( - private val installation: JiraInstallation + private val installation: JiraInstallation, + private val hooks: PreInstallHooks ) : JiraInstallation { override fun install( ssh: SshConnection, - server: TcpServer, - hooks: JiraNodeHooks + server: TcpServer ): InstalledJira { - hooks.runPreInstallHooks(ssh, server) - val installed = installation.install(ssh, server, hooks) - hooks.runPostInstallHooks(ssh, installed) + hooks.call(ssh, server) + val installed = installation.install(ssh, server) + hooks.postInstall.call(ssh, installed) return installed } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt index 5fa9a1c7..3ac3346e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt @@ -1,6 +1,5 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit class InstalledJira( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt index 8b4162af..27caf6d5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt @@ -1,11 +1,10 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection class JiraHomeProperty : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt index 6f087bc6..a627fe94 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt @@ -1,7 +1,5 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe @@ -10,7 +8,6 @@ interface JiraInstallation { fun install( ssh: SshConnection, - server: TcpServer, - hooks: JiraNodeHooks + server: TcpServer ): InstalledJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt index 7c3086e2..e26305e3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt @@ -1,6 +1,5 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection import java.nio.file.Path @@ -8,14 +7,14 @@ import java.nio.file.Paths class JiraLogs : PostInstallHook { - override fun run(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks) { + override fun call(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks) { listOf( "${jira.home}/log/atlassian-jira.log", "${jira.installation}/logs/catalina.out" ) .onEach { ensureFile(Paths.get(it), ssh) } .map { StaticReport(it) } - .forEach { hooks.addReport(it) } + .forEach { hooks.reports.add(it) } } private fun ensureFile( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt index 47ec3a84..50c5bad1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt @@ -3,7 +3,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.FileListing import com.atlassian.performance.tools.ssh.api.SshConnection @@ -11,7 +10,7 @@ class JvmConfig( private val config: JiraNodeConfig ) : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks @@ -24,6 +23,6 @@ class JvmConfig( jiraIp = jira.server.ip ) val report = FileListing(gcLog.path("*")) - hooks.addReport(report) + hooks.reports.add(report) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/LateUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/LateUbuntuSysstat.kt similarity index 67% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/LateUbuntuSysstat.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/LateUbuntuSysstat.kt index ec65cf5e..f90144aa 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/LateUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/LateUbuntuSysstat.kt @@ -1,10 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.Iostat -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu @@ -13,7 +10,7 @@ import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoring import com.atlassian.performance.tools.ssh.api.SshConnection class LateUbuntuSysstat : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks @@ -22,15 +19,15 @@ class LateUbuntuSysstat : PostInstallHook { ubuntu.install(ssh, listOf("sysstat")) listOf(Vmstat(), Iostat()) .map { PostStartOsMetric(it) } - .forEach { hooks.hook(it) } + .forEach { hooks.postStart.insert(it) } } } internal class PostStartOsMetric( private val metric: OsMetric ) : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { + override fun call(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { val process = metric.start(ssh) - hooks.addReport(RemoteMonitoringProcessReport(process)) + hooks.reports.add(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt index e4d60eeb..cbd93fb0 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt @@ -3,8 +3,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.concurrency.api.submitWithLogContext import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.concurrent.Executors @@ -17,8 +15,7 @@ class ParallelInstallation( override fun install( ssh: SshConnection, - server: TcpServer, - hooks: JiraNodeHooks + server: TcpServer ): InstalledJira { val pool = Executors.newCachedThreadPool { runnable -> Thread(runnable, "jira-installation-${runnable.hashCode()}") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt index e2cdfd9d..96534248 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt @@ -1,11 +1,18 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection +/** + * Intercepts a call after Jira is installed. + */ interface PostInstallHook { - fun run( + /** + * @param [ssh] connects to the [jira] + * @param [jira] points to the installed Jira + * @param [hooks] inserts future hooks and reports + */ + fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostInstallHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHooks.kt similarity index 57% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostInstallHooks.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHooks.kt index c6682cc0..704f3caa 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostInstallHooks.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHooks.kt @@ -1,29 +1,33 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PreStartHooks import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class PostInstallHooks protected constructor() : PreStartHooks() { +class PostInstallHooks { - private val postInstallHooks: Queue = ConcurrentLinkedQueue() + private val hooks: Queue = ConcurrentLinkedQueue() + val preStart = PreStartHooks() + val postStart = preStart.postStart + val reports = postStart.reports - fun hook( + fun insert( hook: PostInstallHook ) { - postInstallHooks.add(hook) + hooks.add(hook) } - internal fun runPostInstallHooks( + internal fun call( ssh: SshConnection, jira: InstalledJira ) { while (true) { - postInstallHooks + hooks .poll() - ?.run(ssh, jira, this) + ?.call(ssh, jira, this) ?: break } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/PreInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHook.kt similarity index 50% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/PreInstallHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHook.kt index a92e2856..f78841d0 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/PreInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHook.kt @@ -1,11 +1,18 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks import com.atlassian.performance.tools.ssh.api.SshConnection +/** + * Intercepts a call before Jira is installed. + */ interface PreInstallHook { - fun run( + + /** + * @param [ssh] connects to the [server] + * @param [server] will install Jira + * @param [hooks] inserts future hooks and reports + */ + fun call( ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHooks.kt new file mode 100644 index 00000000..fe85a978 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHooks.kt @@ -0,0 +1,32 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install + +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue + +class PreInstallHooks { + + private val hooks: Queue = ConcurrentLinkedQueue() + val postInstall = PostInstallHooks() + val preStart = postInstall.preStart + val postStart = preStart.postStart + val reports = postStart.reports + + fun insert( + hook: PreInstallHook + ) { + hooks.add(hook) + } + + internal fun call( + ssh: SshConnection, + server: TcpServer + ) { + while (true) { + hooks + .poll() + ?.call(ssh, server, this) + ?: break + } + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt index b1684ca3..e9b595bd 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt @@ -2,8 +2,6 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit import com.atlassian.performance.tools.ssh.api.SshConnection @@ -15,8 +13,7 @@ class SequentialInstallation( override fun install( ssh: SshConnection, - server: TcpServer, - hooks: JiraNodeHooks + server: TcpServer ): InstalledJira { val installation = productDistribution.install(ssh, ".") val home = jiraHomeSource.download(ssh) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/StartedJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/StartedJira.kt similarity index 57% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/StartedJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/StartedJira.kt index 9200032b..a4a02097 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/StartedJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/StartedJira.kt @@ -1,6 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.server - -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install class StartedJira( val installed: InstalledJira, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SystemLog.kt similarity index 97% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/SystemLog.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SystemLog.kt index bba920f6..4eb783eb 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/server/SystemLog.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SystemLog.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.server +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/TcpServer.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/TcpServer.kt similarity index 96% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/TcpServer.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/TcpServer.kt index 739e68f5..7f673860 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/TcpServer.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/TcpServer.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook +package com.atlassian.performance.tools.infrastructure.api.jira.hook.install class TcpServer( val ip: String, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt index 5d6aebfc..1f325073 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt @@ -2,6 +2,14 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.report import com.atlassian.performance.tools.ssh.api.SshConnection +/** + * Reports back about remote events. E.g. points to interesting logs, dumps, charts. + */ interface Report { + + /** + * @param [ssh] connects to the server, which holds interesting data + * @return list of interesting file paths to be downloaded + */ fun locate(ssh: SshConnection): List } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Reports.kt similarity index 61% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Reports.kt index 25b109ed..7f98d239 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/Reports.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Reports.kt @@ -1,19 +1,18 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook +package com.atlassian.performance.tools.infrastructure.api.jira.hook.report -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class Reports protected constructor() { +class Reports { private val reports: Queue = ConcurrentLinkedQueue() - fun addReport( + fun add( report: Report ) { reports.add(report) } - fun listReports(): Iterable { + fun list(): Iterable { return reports.toList() } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt index a20c82b4..aaa333a8 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt @@ -1,13 +1,12 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection class AccessLogs : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { - hooks.addReport(FileListing("${jira.installed.installation}/logs/*access*")) + override fun call(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { + hooks.reports.add(FileListing("${jira.installed.installation}/logs/*access*")) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt index 3b40da27..64cfb618 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt @@ -1,18 +1,17 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection class DefaultPostStartHook : PostStartHook { - override fun run( + override fun call( ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks ) { listOf( JstatHook() - ).forEach { it.run(ssh, jira, hooks) } + ).forEach { it.call(ssh, jira, hooks) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt index 330fa3e9..419679f1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt @@ -1,22 +1,21 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraStart( - private val start: JiraStart + private val start: JiraStart, + private val hooks: PreStartHooks ) : JiraStart { override fun start( ssh: SshConnection, - installed: InstalledJira, - hooks: JiraNodeHooks + installed: InstalledJira ): StartedJira { - hooks.runPreStartHooks(ssh, installed) - val started = start.start(ssh, installed, hooks) - hooks.runPostStartHooks(ssh, started) + hooks.call(ssh, installed) + val started = start.start(ssh, installed) + hooks.postStart.call(ssh, started) return started } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt index 9ddc5f2e..9076209f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt @@ -1,8 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection import java.time.Duration @@ -10,8 +9,7 @@ class JiraLaunchScript : JiraStart { override fun start( ssh: SshConnection, - installed: InstalledJira, - hooks: JiraNodeHooks + installed: InstalledJira ): StartedJira { ssh.execute( "${installed.jdk.use()}; ${installed.installation}/bin/start-jira.sh", diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt index b272933c..f83db503 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt @@ -1,8 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe @@ -11,7 +10,6 @@ interface JiraStart { fun start( ssh: SshConnection, - installed: InstalledJira, - hooks: JiraNodeHooks + installed: InstalledJira ): StartedJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt index 12248c15..216045a2 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt @@ -1,18 +1,17 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection class JstatHook : PostStartHook { - override fun run( + override fun call( ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks ) { val process = jira.installed.jdk.jstatMonitoring.start(ssh, jira.pid) - hooks.addReport(RemoteMonitoringProcessReport(process)) + hooks.reports.add(RemoteMonitoringProcessReport(process)) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt index 39f1795b..f4342ec4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt @@ -1,12 +1,19 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection +/** + * Intercepts a call after Jira is started. + */ interface PostStartHook { - fun run( + /** + * @param [ssh] connects to the [jira] + * @param [jira] points to the started Jira + * @param [hooks] inserts future reports + */ + fun call( ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostStartHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHooks.kt similarity index 60% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostStartHooks.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHooks.kt index 3c4fefab..11c8f1f4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PostStartHooks.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHooks.kt @@ -1,29 +1,31 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Reports import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class PostStartHooks protected constructor() : Reports() { +class PostStartHooks { - private val postStartHooks: Queue = ConcurrentLinkedQueue() + private val hooks: Queue = ConcurrentLinkedQueue() + val reports = Reports() - fun hook( + fun insert( hook: PostStartHook ) { - postStartHooks.add(hook) + hooks.add(hook) } - internal fun runPostStartHooks( + internal fun call( ssh: SshConnection, jira: StartedJira ) { while (true) { - postStartHooks + hooks .poll() - ?.run(ssh, jira, this) + ?.call(ssh, jira, this) ?: break } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHook.kt similarity index 58% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHook.kt index e4d29748..4954d93e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHook.kt @@ -1,11 +1,19 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection +/** + * Intercepts a call before Jira is started. + */ interface PreStartHook { - fun run( + /** + * @param [ssh] connects to the [jira] + * @param [jira] points to the installed Jira + * @param [hooks] inserts future hooks and reports + */ + fun call( ssh: SshConnection, jira: InstalledJira, hooks: PreStartHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHooks.kt similarity index 61% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHooks.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHooks.kt index 2daf7636..ba0321c3 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/PreStartHooks.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHooks.kt @@ -1,27 +1,30 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook +package com.atlassian.performance.tools.infrastructure.api.jira.hook.start import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -open class PreStartHooks protected constructor() : PostStartHooks() { - private val preStartHooks: Queue = ConcurrentLinkedQueue() +class PreStartHooks { - fun hook( + private val hooks: Queue = ConcurrentLinkedQueue() + val postStart = PostStartHooks() + val reports = postStart.reports + + fun insert( hook: PreStartHook ) { - preStartHooks.add(hook) + hooks.add(hook) } - internal fun runPreStartHooks( + internal fun call( ssh: SshConnection, jira: InstalledJira ) { while (true) { - preStartHooks + hooks .poll() - ?.run(ssh, jira, this) + ?.call(ssh, jira, this) ?: break } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt index 5d19a86c..d93bfa81 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt @@ -1,9 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI @@ -16,11 +15,11 @@ class RestUpgrade( private val adminPassword: String ) : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { + override fun call(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { val threadDump = ThreadDump(jira.pid, jira.installed.jdk) val privatePort = jira.installed.server.privatePort val upgradesEndpoint = URI("http://$adminUsername:$adminPassword@localhost:$privatePort/rest/api/2/upgrade") - hooks.addReport(StaticReport("thread-dumps")) + hooks.reports.add(StaticReport("thread-dumps")) waitForStatusToChange( statusQuo = "000", timeout = timeouts.offlineTimeout, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt index 100bb7dc..5e446f87 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt @@ -1,10 +1,10 @@ package com.atlassian.performance.tools.infrastructure.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport @@ -17,9 +17,9 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class ProfilerHook( private val profiler: Profiler ) : PostInstallHook { - override fun run(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks) { + override fun call(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks) { profiler.install(ssh) - hooks.hook(InstalledProfiler(profiler)) + hooks.preStart.postStart.insert(InstalledProfiler(profiler)) } } @@ -27,14 +27,14 @@ private class InstalledProfiler( private val profiler: Profiler ) : PostStartHook { - override fun run( + override fun call( ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks ) { val process = profiler.start(ssh, jira.pid) if (process != null) { - hooks.addReport(RemoteMonitoringProcessReport(process)) + hooks.reports.add(RemoteMonitoringProcessReport(process)) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt index c6a22a29..c88e1e83 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt @@ -1,6 +1,6 @@ package com.atlassian.performance.tools.infrastructure.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook import com.atlassian.performance.tools.infrastructure.api.splunk.SplunkForwarder @@ -10,7 +10,7 @@ internal class SplunkForwarderHook( private val splunk: SplunkForwarder ) : PostInstallHook { - override fun run( + override fun call( ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt index e7a946e0..7c071e4f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt @@ -1,19 +1,19 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection class EarlyUbuntuSysstat : PreInstallHook { - override fun run( + override fun call( ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks ) { UbuntuSysstat() .install(ssh) - .forEach { hooks.hook(it) } + .forEach { hooks.insert(it) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt index fdce147b..1f9468cd 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PreInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection @@ -11,8 +11,8 @@ internal class InstalledOsMetric( private val metric: OsMetric ) : PreInstallHook { - override fun run(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { + override fun call(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { val process = metric.start(ssh) - hooks.addReport(RemoteMonitoringProcessReport(process)) + hooks.reports.add(RemoteMonitoringProcessReport(process)) } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt index 428bed19..ad51ac7a 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt @@ -1,6 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer import com.atlassian.performance.tools.ssh.api.DetachedProcess import com.atlassian.performance.tools.ssh.api.SshConnection import org.apache.logging.log4j.Level @@ -16,13 +18,13 @@ class JiraNodeHooksTest { fun shouldHookDuringListing() { val counter = CountingHook() val hooks = JiraNodeHooks.empty().apply { - hook(counter) - hook(HookingHook(counter)) - hook(counter) + preInstall.insert(counter) + preInstall.insert(HookingHook(counter)) + preInstall.insert(counter) } val server = TcpServer("doesn't matter", 123, "fake-server") - hooks.runPreInstallHooks(FailingSshConnection(), server) + hooks.preInstall.call(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -31,13 +33,13 @@ class JiraNodeHooksTest { fun shouldHookToTheTailDuringListing() { val counter = CountingHook() val hooks = JiraNodeHooks.empty().apply { - hook(counter) - hook(counter) - hook(HookingHook(counter)) + preInstall.insert(counter) + preInstall.insert(counter) + preInstall.insert(HookingHook(counter)) } val server = TcpServer("doesn't matter", 123, "fake-server") - hooks.runPreInstallHooks(FailingSshConnection(), server) + hooks.preInstall.call(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -47,7 +49,7 @@ private class CountingHook : PreInstallHook { var count = 0 - override fun run(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { + override fun call(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { count++ } } @@ -55,8 +57,8 @@ private class CountingHook : PreInstallHook { private class HookingHook( private val hook: PreInstallHook ) : PreInstallHook { - override fun run(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { - hooks.hook(hook) + override fun call(ssh: SshConnection, server: TcpServer, hooks: PreInstallHooks) { + hooks.insert(hook) } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt index b90f3e2e..4d9811db 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt @@ -3,11 +3,10 @@ package com.atlassian.performance.tools.infrastructure.api.jira.hook.start import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.HookedJiraInstallation import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.ParallelInstallation -import com.atlassian.performance.tools.infrastructure.api.jira.hook.server.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.S3HostedJdk import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.infrastructure.ubuntu.EarlyUbuntuSysstat @@ -27,12 +26,15 @@ class HookedJiraStartIT { fun shouldStartJiraWithDefaultHooks() { // given val hooks = JiraNodeHooks.default() - val jiraInstallation = HookedJiraInstallation(ParallelInstallation( - jiraHomeSource = EmptyJiraHome(), - productDistribution = PublicJiraSoftwareDistribution("7.13.0"), - jdk = S3HostedJdk() - )) - val jiraStart = HookedJiraStart(JiraLaunchScript()) + val jiraInstallation = HookedJiraInstallation( + ParallelInstallation( + jiraHomeSource = EmptyJiraHome(), + productDistribution = PublicJiraSoftwareDistribution("7.13.0"), + jdk = S3HostedJdk() + ), + hooks.preInstall + ) + val jiraStart = HookedJiraStart(JiraLaunchScript(), hooks.preStart) val privatePort = 8080 val container = SshUbuntuContainer(Consumer { it.addExposedPort(privatePort) @@ -46,10 +48,10 @@ class HookedJiraStartIT { ) val remoteReports = sshUbuntu.toSsh().newConnection().use { ssh -> // when - val installed = jiraInstallation.install(ssh, server, hooks) - val started = jiraStart.start(ssh, installed, hooks) + val installed = jiraInstallation.install(ssh, server) + val started = jiraStart.start(ssh, installed) stop(started, ssh) - hooks.listReports().flatMap { it.locate(ssh) } + hooks.reports.list().flatMap { it.locate(ssh) } } // then @@ -72,14 +74,17 @@ class HookedJiraStartIT { fun shouldDownloadPartialReportsInCaseOfFailure() { // given val hooks = JiraNodeHooks.empty().apply { - hook(EarlyUbuntuSysstat()) - hook(FailingHook()) + preInstall.insert(EarlyUbuntuSysstat()) + preInstall.postInstall.preStart.postStart.insert(FailingHook()) } - val jiraInstallation = HookedJiraInstallation(ParallelInstallation( - jiraHomeSource = EmptyJiraHome(), - productDistribution = PublicJiraSoftwareDistribution("7.13.0"), - jdk = S3HostedJdk() - )) + val jiraInstallation = HookedJiraInstallation( + ParallelInstallation( + jiraHomeSource = EmptyJiraHome(), + productDistribution = PublicJiraSoftwareDistribution("7.13.0"), + jdk = S3HostedJdk() + ), + hooks = hooks.preInstall + ) val privatePort = 8080 val container = SshUbuntuContainer(Consumer { it.addExposedPort(privatePort) @@ -94,11 +99,11 @@ class HookedJiraStartIT { return@use sshUbuntu.toSsh().newConnection().use useSsh@{ ssh -> // when try { - jiraInstallation.install(ssh, server, hooks) + jiraInstallation.install(ssh, server) } catch (e: Exception) { println("Failed: ${e.message}") } - return@useSsh hooks.listReports().flatMap { it.locate(ssh) } + return@useSsh hooks.reports.list().flatMap { it.locate(ssh) } } } @@ -131,7 +136,7 @@ class HookedJiraStartIT { } private class FailingHook : PostStartHook { - override fun run(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { + override fun call(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { throw Exception("Expected failure") } } From a336862d23ab2a1f71a68ebbfcd849cdd4a0bcbb Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 29 Jan 2021 10:35:59 +0100 Subject: [PATCH 27/28] Repackage hooks --- .../api/database/DatabaseIpConfig.kt | 6 +-- .../api/database/MysqlConnector.kt | 6 +-- .../api/jira/hook/JiraNodeHooks.kt | 25 --------- .../hook/install/DefaultPostInstallHook.kt | 27 ---------- .../api/jira/hook/install/PostInstallHooks.kt | 35 ------------ .../jira/hook/start/DefaultPostStartHook.kt | 17 ------ .../jira/{hook => }/install/InstalledJira.kt | 2 +- .../{hook => }/install/JiraInstallation.kt | 2 +- .../install/ParallelInstallation.kt | 2 +- .../install/SequentialInstallation.kt | 2 +- .../api/jira/{hook => }/install/TcpServer.kt | 2 +- .../hook}/AsyncProfilerHook.kt | 16 +++--- .../hook}/DataCenterHook.kt | 3 +- .../hook}/DisabledAutoBackup.kt | 3 +- .../hook}/HookedJiraInstallation.kt | 5 +- .../hook}/JiraHomeProperty.kt | 3 +- .../install => install/hook}/JiraLogs.kt | 5 +- .../install => install/hook}/JvmConfig.kt | 5 +- .../hook}/LateUbuntuSysstat.kt | 10 ++-- .../hook}/PostInstallHook.kt | 3 +- .../api/jira/install/hook/PostInstallHooks.kt | 54 +++++++++++++++++++ .../hook}/PreInstallHook.kt | 3 +- .../hook}/PreInstallHooks.kt | 14 +++-- .../install => install/hook}/SystemLog.kt | 6 +-- .../api/jira/{hook => }/report/FileListing.kt | 2 +- .../api/jira/{hook => }/report/Report.kt | 2 +- .../api/jira/{hook => }/report/Reports.kt | 2 +- .../jira/{hook => }/report/StaticReport.kt | 2 +- .../jira/{hook => }/start/JiraLaunchScript.kt | 5 +- .../api/jira/{hook => }/start/JiraStart.kt | 5 +- .../{hook/install => start}/StartedJira.kt | 4 +- .../{hook/start => start/hook}/AccessLogs.kt | 6 +-- .../start => start/hook}/HookedJiraStart.kt | 7 +-- .../{hook/start => start/hook}/JstatHook.kt | 4 +- .../start => start/hook}/PostStartHook.kt | 4 +- .../start => start/hook}/PostStartHooks.kt | 17 ++++-- .../start => start/hook}/PreStartHook.kt | 4 +- .../start => start/hook}/PreStartHooks.kt | 15 ++++-- .../{hook/start => start/hook}/RestUpgrade.kt | 6 +-- .../hook/RemoteMonitoringProcessReport.kt | 2 +- .../jira/hook/install/ProfilerHook.kt | 12 ++--- .../jira/hook/install/SplunkForwarderHook.kt | 6 +-- .../ubuntu/EarlyUbuntuSysstat.kt | 6 +-- .../ubuntu/InstalledOsMetric.kt | 6 +-- .../hook/PreInstallHooksTest.kt} | 26 +++++---- .../start => start/hook}/HookedJiraStartIT.kt | 25 ++++----- 46 files changed, 205 insertions(+), 219 deletions(-) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHooks.kt delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/install/InstalledJira.kt (96%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/install/JiraInstallation.kt (95%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/install/ParallelInstallation.kt (99%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/install/SequentialInstallation.kt (98%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/install/TcpServer.kt (96%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/AsyncProfilerHook.kt (76%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/DataCenterHook.kt (90%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/DisabledAutoBackup.kt (79%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/HookedJiraInstallation.kt (66%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/JiraHomeProperty.kt (83%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/JiraLogs.kt (80%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/JvmConfig.kt (82%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/LateUbuntuSysstat.kt (74%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/PostInstallHook.kt (83%) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PostInstallHooks.kt rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/PreInstallHook.kt (83%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/PreInstallHooks.kt (64%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => install/hook}/SystemLog.kt (60%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/report/FileListing.kt (96%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/report/Report.kt (97%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/report/Reports.kt (96%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/report/StaticReport.kt (95%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/start/JiraLaunchScript.kt (77%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook => }/start/JiraStart.kt (61%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/install => start}/StartedJira.kt (59%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/AccessLogs.kt (64%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/HookedJiraStart.kt (66%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/JstatHook.kt (84%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/PostStartHook.kt (82%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/PostStartHooks.kt (60%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/PreStartHook.kt (82%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/PreStartHooks.kt (64%) rename src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/RestUpgrade.kt (93%) rename src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/JiraNodeHooksTest.kt => install/hook/PreInstallHooksTest.kt} (74%) rename src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/{hook/start => start/hook}/HookedJiraStartIT.kt (85%) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt index 08df4cd4..40c12af2 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/DatabaseIpConfig.kt @@ -1,9 +1,9 @@ package com.atlassian.performance.tools.infrastructure.api.database import com.atlassian.performance.tools.infrastructure.api.Sed -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHooks +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.ssh.api.SshConnection class DatabaseIpConfig( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt index be1ae5f4..f8ecf19c 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/database/MysqlConnector.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.database -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHooks +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.jvmtasks.api.Backoff import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt deleted file mode 100644 index c680df66..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooks.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook - -import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.DefaultPostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.DefaultPostStartHook -import net.jcip.annotations.ThreadSafe - -@ThreadSafe -class JiraNodeHooks { - - val preInstall = PreInstallHooks() - val postInstall = preInstall.postInstall - val preStart = postInstall.preStart - val postStart = preStart.postStart - val reports = postStart.reports - - companion object { - fun default(): JiraNodeHooks = JiraNodeHooks() - .apply { postStart.insert(DefaultPostStartHook()) } - .apply { postInstall.insert(DefaultPostInstallHook(JiraNodeConfig.Builder().build())) } - - fun empty(): JiraNodeHooks = JiraNodeHooks() - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt deleted file mode 100644 index e430f371..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DefaultPostInstallHook.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install - -import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig -import com.atlassian.performance.tools.infrastructure.jira.hook.install.ProfilerHook -import com.atlassian.performance.tools.infrastructure.jira.hook.install.SplunkForwarderHook -import com.atlassian.performance.tools.ssh.api.SshConnection - -class DefaultPostInstallHook( - private val config: JiraNodeConfig -) : PostInstallHook { - - override fun call( - ssh: SshConnection, - jira: InstalledJira, - hooks: PostInstallHooks - ) { - listOf( - JiraHomeProperty(), - DisabledAutoBackup(), - JvmConfig(config), - ProfilerHook(config.profiler), - SplunkForwarderHook(config.splunkForwarder), - JiraLogs(), - LateUbuntuSysstat() - ).forEach { it.call(ssh, jira, hooks) } - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHooks.kt deleted file mode 100644 index 704f3caa..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHooks.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install - -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PreStartHooks -import com.atlassian.performance.tools.ssh.api.SshConnection -import java.util.* -import java.util.concurrent.ConcurrentLinkedQueue - -class PostInstallHooks { - - private val hooks: Queue = ConcurrentLinkedQueue() - val preStart = PreStartHooks() - val postStart = preStart.postStart - val reports = postStart.reports - - fun insert( - hook: PostInstallHook - ) { - hooks.add(hook) - } - - internal fun call( - ssh: SshConnection, - jira: InstalledJira - ) { - while (true) { - hooks - .poll() - ?.call(ssh, jira, this) - ?: break - } - } - -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt deleted file mode 100644 index 64cfb618..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/DefaultPostStartHook.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start - -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira -import com.atlassian.performance.tools.ssh.api.SshConnection - -class DefaultPostStartHook : PostStartHook { - - override fun call( - ssh: SshConnection, - jira: StartedJira, - hooks: PostStartHooks - ) { - listOf( - JstatHook() - ).forEach { it.call(ssh, jira, hooks) } - } -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/InstalledJira.kt similarity index 96% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/InstalledJira.kt index 3ac3346e..a796b32a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/InstalledJira.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/JiraInstallation.kt similarity index 95% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/JiraInstallation.kt index a627fe94..d9d96b83 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/JiraInstallation.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/ParallelInstallation.kt similarity index 99% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/ParallelInstallation.kt index cbd93fb0..72fefb17 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/ParallelInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/ParallelInstallation.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install import com.atlassian.performance.tools.concurrency.api.submitWithLogContext import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/SequentialInstallation.kt similarity index 98% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/SequentialInstallation.kt index e9b595bd..dbd7367a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SequentialInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/SequentialInstallation.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install import com.atlassian.performance.tools.infrastructure.api.distribution.ProductDistribution import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/TcpServer.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/TcpServer.kt similarity index 96% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/TcpServer.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/TcpServer.kt index 7f673860..9997f8a4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/TcpServer.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/TcpServer.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install class TcpServer( val ip: String, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/AsyncProfilerHook.kt similarity index 76% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/AsyncProfilerHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/AsyncProfilerHook.kt index 2ac9b0ca..32457b84 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/AsyncProfilerHook.kt @@ -1,17 +1,19 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PostStartHooks import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI class AsyncProfilerHook : PreInstallHook { override fun call( - ssh: SshConnection, - server: TcpServer, - hooks: PreInstallHooks + ssh: SshConnection, + server: TcpServer, + hooks: PreInstallHooks ) { val directory = "async-profiler" val downloads = URI("https://github.com/jvm-profiling-tools/async-profiler/releases/download/") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/DataCenterHook.kt similarity index 90% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/DataCenterHook.kt index 76072799..802a6a18 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DataCenterHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/DataCenterHook.kt @@ -1,6 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection class DataCenterHook( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/DisabledAutoBackup.kt similarity index 79% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/DisabledAutoBackup.kt index cfee8e56..dd482d1e 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/DisabledAutoBackup.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/DisabledAutoBackup.kt @@ -1,5 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection class DisabledAutoBackup : PostInstallHook { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/HookedJiraInstallation.kt similarity index 66% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/HookedJiraInstallation.kt index 77ed9850..06d40ba2 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/HookedJiraInstallation.kt @@ -1,5 +1,8 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.JiraInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraInstallation( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraHomeProperty.kt similarity index 83% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraHomeProperty.kt index 27caf6d5..a95498cf 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraHomeProperty.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraHomeProperty.kt @@ -1,5 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection class JiraHomeProperty : PostInstallHook { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraLogs.kt similarity index 80% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraLogs.kt index e26305e3..20e94ed1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraLogs.kt @@ -1,6 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection import java.nio.file.Path import java.nio.file.Paths diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JvmConfig.kt similarity index 82% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JvmConfig.kt index 50c5bad1..e772aa13 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JvmConfig.kt @@ -1,9 +1,10 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook import com.atlassian.performance.tools.infrastructure.api.jira.JiraGcLog import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig import com.atlassian.performance.tools.infrastructure.api.jira.SetenvSh -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.FileListing +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.report.FileListing import com.atlassian.performance.tools.ssh.api.SshConnection class JvmConfig( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/LateUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/LateUbuntuSysstat.kt similarity index 74% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/LateUbuntuSysstat.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/LateUbuntuSysstat.kt index f90144aa..3a6d2222 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/LateUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/LateUbuntuSysstat.kt @@ -1,8 +1,10 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook import com.atlassian.performance.tools.infrastructure.Iostat -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PostStartHooks import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu import com.atlassian.performance.tools.infrastructure.api.os.Vmstat @@ -23,7 +25,7 @@ class LateUbuntuSysstat : PostInstallHook { } } -internal class PostStartOsMetric( +private class PostStartOsMetric( private val metric: OsMetric ) : PostStartHook { override fun call(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks) { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PostInstallHook.kt similarity index 83% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PostInstallHook.kt index 96534248..0fe19b0a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PostInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PostInstallHook.kt @@ -1,5 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection /** diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PostInstallHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PostInstallHooks.kt new file mode 100644 index 00000000..155dcc63 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PostInstallHooks.kt @@ -0,0 +1,54 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook + +import com.atlassian.performance.tools.infrastructure.api.jira.JiraNodeConfig +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PreStartHooks +import com.atlassian.performance.tools.infrastructure.jira.hook.install.ProfilerHook +import com.atlassian.performance.tools.infrastructure.jira.hook.install.SplunkForwarderHook +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.util.* +import java.util.concurrent.ConcurrentLinkedQueue + +class PostInstallHooks private constructor( + val preStart: PreStartHooks +) { + + private val hooks: Queue = ConcurrentLinkedQueue() + val postStart = preStart.postStart + val reports = postStart.reports + + fun insert( + hook: PostInstallHook + ) { + hooks.add(hook) + } + + internal fun call( + ssh: SshConnection, + jira: InstalledJira + ) { + while (true) { + hooks + .poll() + ?.call(ssh, jira, this) + ?: break + } + } + + companion object Factory { + fun default(): PostInstallHooks = PostInstallHooks(PreStartHooks.default()).apply { + val config = JiraNodeConfig.Builder().build() + listOf( + JiraHomeProperty(), + DisabledAutoBackup(), + JvmConfig(config), + ProfilerHook(config.profiler), + SplunkForwarderHook(config.splunkForwarder), + JiraLogs(), + LateUbuntuSysstat() + ).forEach { insert(it) } + } + + fun empty(): PostInstallHooks = PostInstallHooks(PreStartHooks.empty()) + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHook.kt similarity index 83% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHook.kt index f78841d0..1e58b1af 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHook.kt @@ -1,5 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection /** diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooks.kt similarity index 64% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHooks.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooks.kt index fe85a978..5506de0d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/PreInstallHooks.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooks.kt @@ -1,13 +1,15 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -class PreInstallHooks { +class PreInstallHooks private constructor( + val postInstall: PostInstallHooks +) { private val hooks: Queue = ConcurrentLinkedQueue() - val postInstall = PostInstallHooks() val preStart = postInstall.preStart val postStart = preStart.postStart val reports = postStart.reports @@ -29,4 +31,10 @@ class PreInstallHooks { ?: break } } + + companion object Factory { + fun default(): PreInstallHooks = PreInstallHooks(PostInstallHooks.default()) + + fun empty(): PreInstallHooks = PreInstallHooks(PostInstallHooks.empty()) + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SystemLog.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/SystemLog.kt similarity index 60% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SystemLog.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/SystemLog.kt index 4eb783eb..cb51739d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/SystemLog.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/SystemLog.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.report.StaticReport import com.atlassian.performance.tools.ssh.api.SshConnection class SystemLog : Report { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/FileListing.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/FileListing.kt similarity index 96% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/FileListing.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/FileListing.kt index 45434e73..e1736a7d 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/FileListing.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/FileListing.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.report +package com.atlassian.performance.tools.infrastructure.api.jira.report import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Report.kt similarity index 97% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Report.kt index 1f325073..1da33c75 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Report.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Report.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.report +package com.atlassian.performance.tools.infrastructure.api.jira.report import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Reports.kt similarity index 96% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Reports.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Reports.kt index 7f98d239..bfc8b1cd 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/Reports.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Reports.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.report +package com.atlassian.performance.tools.infrastructure.api.jira.report import java.util.* import java.util.concurrent.ConcurrentLinkedQueue diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/StaticReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/StaticReport.kt similarity index 95% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/StaticReport.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/StaticReport.kt index a64e1a48..da90e4d1 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/report/StaticReport.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/StaticReport.kt @@ -1,4 +1,4 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.report +package com.atlassian.performance.tools.infrastructure.api.jira.report import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/JiraLaunchScript.kt similarity index 77% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/JiraLaunchScript.kt index 9076209f..32673528 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraLaunchScript.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/JiraLaunchScript.kt @@ -1,7 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection import java.time.Duration diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/JiraStart.kt similarity index 61% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/JiraStart.kt index f83db503..dabddc38 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/JiraStart.kt @@ -1,7 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection import net.jcip.annotations.ThreadSafe diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/StartedJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/StartedJira.kt similarity index 59% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/StartedJira.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/StartedJira.kt index a4a02097..da6f4955 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/install/StartedJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/StartedJira.kt @@ -1,4 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.install +package com.atlassian.performance.tools.infrastructure.api.jira.start + +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira class StartedJira( val installed: InstalledJira, diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/AccessLogs.kt similarity index 64% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/AccessLogs.kt index aaa333a8..cccd0da5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/AccessLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/AccessLogs.kt @@ -1,7 +1,7 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.FileListing -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.report.FileListing +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection class AccessLogs : PostStartHook { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStart.kt similarity index 66% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStart.kt index 419679f1..20634150 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStart.kt @@ -1,7 +1,8 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.JiraStart +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection class HookedJiraStart( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/JstatHook.kt similarity index 84% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/JstatHook.kt index 216045a2..27b23757 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/JstatHook.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PostStartHook.kt similarity index 82% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PostStartHook.kt index f4342ec4..c3c47123 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PostStartHook.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.ssh.api.SshConnection /** diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PostStartHooks.kt similarity index 60% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHooks.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PostStartHooks.kt index 11c8f1f4..21b0b46a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PostStartHooks.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PostStartHooks.kt @@ -1,13 +1,12 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Reports -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook +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.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -class PostStartHooks { +class PostStartHooks private constructor() { private val hooks: Queue = ConcurrentLinkedQueue() val reports = Reports() @@ -29,4 +28,12 @@ class PostStartHooks { ?: break } } + + companion object Factory { + fun default(): PostStartHooks = empty().apply { + insert(JstatHook()) + } + + fun empty(): PostStartHooks = PostStartHooks() + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PreStartHook.kt similarity index 82% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHook.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PreStartHook.kt index 4954d93e..d0fa8326 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PreStartHook.kt @@ -1,6 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection /** diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHooks.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PreStartHooks.kt similarity index 64% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHooks.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PreStartHooks.kt index ba0321c3..6ce16b42 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/PreStartHooks.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/PreStartHooks.kt @@ -1,14 +1,15 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.ssh.api.SshConnection import java.util.* import java.util.concurrent.ConcurrentLinkedQueue -class PreStartHooks { +class PreStartHooks private constructor( + val postStart: PostStartHooks +) { private val hooks: Queue = ConcurrentLinkedQueue() - val postStart = PostStartHooks() val reports = postStart.reports fun insert( @@ -28,4 +29,10 @@ class PreStartHooks { ?: break } } + + companion object Factory { + fun default() = PreStartHooks(PostStartHooks.default()) + + fun empty() = PreStartHooks(PostStartHooks.empty()) + } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/RestUpgrade.kt similarity index 93% rename from src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt rename to src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/RestUpgrade.kt index d93bfa81..84aa39f4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/RestUpgrade.kt @@ -1,8 +1,8 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook import com.atlassian.performance.tools.infrastructure.api.jira.JiraLaunchTimeouts -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.StaticReport -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.report.StaticReport +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.ThreadDump import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/RemoteMonitoringProcessReport.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/RemoteMonitoringProcessReport.kt index 2764836f..674a03e6 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/RemoteMonitoringProcessReport.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/RemoteMonitoringProcessReport.kt @@ -1,6 +1,6 @@ package com.atlassian.performance.tools.infrastructure.jira.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.report.Report +import com.atlassian.performance.tools.infrastructure.api.jira.report.Report import com.atlassian.performance.tools.infrastructure.api.process.RemoteMonitoringProcess import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt index 5e446f87..220fdbd4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/ProfilerHook.kt @@ -1,11 +1,11 @@ package com.atlassian.performance.tools.infrastructure.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.PostStartHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PostStartHooks +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.start.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.start.hook.PostStartHook import com.atlassian.performance.tools.infrastructure.api.profiler.Profiler import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt index c88e1e83..2112e483 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/hook/install/SplunkForwarderHook.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.jira.hook.install -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.InstalledJira -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PostInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PostInstallHooks +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.splunk.SplunkForwarder import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt index 7c071e4f..9bc25df4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/EarlyUbuntuSysstat.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHook import com.atlassian.performance.tools.ssh.api.SshConnection class EarlyUbuntuSysstat : PreInstallHook { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt index 1f9468cd..515b806f 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/ubuntu/InstalledOsMetric.kt @@ -1,8 +1,8 @@ package com.atlassian.performance.tools.infrastructure.ubuntu -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHook +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHooks +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHook import com.atlassian.performance.tools.infrastructure.api.os.OsMetric import com.atlassian.performance.tools.infrastructure.jira.hook.RemoteMonitoringProcessReport import com.atlassian.performance.tools.ssh.api.SshConnection diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooksTest.kt similarity index 74% rename from src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt rename to src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooksTest.kt index ad51ac7a..0b2ecc95 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/JiraNodeHooksTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooksTest.kt @@ -1,8 +1,6 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook +package com.atlassian.performance.tools.infrastructure.api.jira.install.hook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHook -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.PreInstallHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer import com.atlassian.performance.tools.ssh.api.DetachedProcess import com.atlassian.performance.tools.ssh.api.SshConnection import org.apache.logging.log4j.Level @@ -17,14 +15,14 @@ class JiraNodeHooksTest { @Test fun shouldHookDuringListing() { val counter = CountingHook() - val hooks = JiraNodeHooks.empty().apply { - preInstall.insert(counter) - preInstall.insert(HookingHook(counter)) - preInstall.insert(counter) + val hooks = PreInstallHooks.empty().apply { + insert(counter) + insert(HookingHook(counter)) + insert(counter) } val server = TcpServer("doesn't matter", 123, "fake-server") - hooks.preInstall.call(FailingSshConnection(), server) + hooks.call(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -32,14 +30,14 @@ class JiraNodeHooksTest { @Test fun shouldHookToTheTailDuringListing() { val counter = CountingHook() - val hooks = JiraNodeHooks.empty().apply { - preInstall.insert(counter) - preInstall.insert(counter) - preInstall.insert(HookingHook(counter)) + val hooks = PreInstallHooks.empty().apply { + insert(counter) + insert(counter) + insert(HookingHook(counter)) } val server = TcpServer("doesn't matter", 123, "fake-server") - hooks.preInstall.call(FailingSshConnection(), server) + hooks.call(FailingSshConnection(), server) assertThat(counter.count).isEqualTo(3) } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStartIT.kt similarity index 85% rename from src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt rename to src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStartIT.kt index 4d9811db..d9b3196f 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/hook/start/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStartIT.kt @@ -1,12 +1,13 @@ -package com.atlassian.performance.tools.infrastructure.api.jira.hook.start +package com.atlassian.performance.tools.infrastructure.api.jira.start.hook import com.atlassian.performance.tools.infrastructure.api.distribution.PublicJiraSoftwareDistribution import com.atlassian.performance.tools.infrastructure.api.jira.EmptyJiraHome -import com.atlassian.performance.tools.infrastructure.api.jira.hook.JiraNodeHooks -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.TcpServer -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.HookedJiraInstallation -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.ParallelInstallation -import com.atlassian.performance.tools.infrastructure.api.jira.hook.install.StartedJira +import com.atlassian.performance.tools.infrastructure.api.jira.install.ParallelInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.HookedJiraInstallation +import com.atlassian.performance.tools.infrastructure.api.jira.install.hook.PreInstallHooks +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.jvm.S3HostedJdk import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.infrastructure.ubuntu.EarlyUbuntuSysstat @@ -25,14 +26,14 @@ class HookedJiraStartIT { @Test fun shouldStartJiraWithDefaultHooks() { // given - val hooks = JiraNodeHooks.default() + val hooks = PreInstallHooks.default() val jiraInstallation = HookedJiraInstallation( ParallelInstallation( jiraHomeSource = EmptyJiraHome(), productDistribution = PublicJiraSoftwareDistribution("7.13.0"), jdk = S3HostedJdk() ), - hooks.preInstall + hooks ) val jiraStart = HookedJiraStart(JiraLaunchScript(), hooks.preStart) val privatePort = 8080 @@ -73,9 +74,9 @@ class HookedJiraStartIT { @Test fun shouldDownloadPartialReportsInCaseOfFailure() { // given - val hooks = JiraNodeHooks.empty().apply { - preInstall.insert(EarlyUbuntuSysstat()) - preInstall.postInstall.preStart.postStart.insert(FailingHook()) + val hooks = PreInstallHooks.empty().apply { + insert(EarlyUbuntuSysstat()) + postStart.insert(FailingHook()) } val jiraInstallation = HookedJiraInstallation( ParallelInstallation( @@ -83,7 +84,7 @@ class HookedJiraStartIT { productDistribution = PublicJiraSoftwareDistribution("7.13.0"), jdk = S3HostedJdk() ), - hooks = hooks.preInstall + hooks = hooks ) val privatePort = 8080 val container = SshUbuntuContainer(Consumer { From 8dc645b4cafc2b235413009732d99c8abb5d1d81 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 29 Jan 2021 10:56:02 +0100 Subject: [PATCH 28/28] Reuse StaticBackoff --- .../jira/install/hook/PreInstallHooksTest.kt | 40 ++----------------- .../api/jira/start/hook/HookedJiraStartIT.kt | 9 ----- .../infrastructure/api/jvm/S3HostedJdk.kt | 2 +- 3 files changed, 4 insertions(+), 47 deletions(-) diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooksTest.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooksTest.kt index 0b2ecc95..c5fb692f 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooksTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/PreInstallHooksTest.kt @@ -1,14 +1,10 @@ package com.atlassian.performance.tools.infrastructure.api.jira.install.hook import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpServer -import com.atlassian.performance.tools.ssh.api.DetachedProcess +import com.atlassian.performance.tools.infrastructure.mock.UnimplementedSshConnection import com.atlassian.performance.tools.ssh.api.SshConnection -import org.apache.logging.log4j.Level import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import java.io.File -import java.nio.file.Path -import java.time.Duration class JiraNodeHooksTest { @@ -22,7 +18,7 @@ class JiraNodeHooksTest { } val server = TcpServer("doesn't matter", 123, "fake-server") - hooks.call(FailingSshConnection(), server) + hooks.call(UnimplementedSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -37,7 +33,7 @@ class JiraNodeHooksTest { } val server = TcpServer("doesn't matter", 123, "fake-server") - hooks.call(FailingSshConnection(), server) + hooks.call(UnimplementedSshConnection(), server) assertThat(counter.count).isEqualTo(3) } @@ -59,33 +55,3 @@ private class HookingHook( hooks.insert(hook) } } - -private class FailingSshConnection : SshConnection { - override fun close() { - throw Exception("unexpected call") - } - - override fun download(remoteSource: String, localDestination: Path) { - throw Exception("unexpected call") - } - - override fun execute(cmd: String, timeout: Duration, stdout: Level, stderr: Level): SshConnection.SshResult { - throw Exception("unexpected call") - } - - override fun safeExecute(cmd: String, timeout: Duration, stdout: Level, stderr: Level): SshConnection.SshResult { - throw Exception("unexpected call") - } - - override fun startProcess(cmd: String): DetachedProcess { - throw Exception("unexpected call") - } - - override fun stopProcess(process: DetachedProcess) { - throw Exception("unexpected call") - } - - override fun upload(localSource: File, remoteDestination: String) { - throw Exception("unexpected call") - } -} diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStartIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStartIT.kt index d9b3196f..d9088d51 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStartIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/HookedJiraStartIT.kt @@ -11,14 +11,12 @@ import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.infrastructure.api.jvm.S3HostedJdk import com.atlassian.performance.tools.infrastructure.toSsh import com.atlassian.performance.tools.infrastructure.ubuntu.EarlyUbuntuSysstat -import com.atlassian.performance.tools.jvmtasks.api.Backoff import com.atlassian.performance.tools.ssh.api.SshConnection import com.atlassian.performance.tools.sshubuntu.api.SshUbuntuContainer import org.assertj.core.api.Assertions.assertThat import org.junit.Test import java.io.File import java.nio.file.Files -import java.time.Duration import java.util.function.Consumer class HookedJiraStartIT { @@ -141,10 +139,3 @@ private class FailingHook : PostStartHook { throw Exception("Expected failure") } } - -class StaticBackoff( - private val backoff: Duration -) : Backoff { - - override fun backOff(attempt: Int): Duration = backoff -} diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt index c4d67ae6..81188113 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/S3HostedJdk.kt @@ -1,7 +1,7 @@ package com.atlassian.performance.tools.infrastructure.api.jvm -import com.atlassian.performance.tools.infrastructure.api.jira.hook.start.StaticBackoff import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction +import com.atlassian.performance.tools.jvmtasks.api.StaticBackoff import com.atlassian.performance.tools.ssh.api.SshConnection import java.net.URI import java.time.Duration