From e665f02052a18e958c91ecdedc494b3fc0c0eaf3 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Thu, 4 Jul 2019 18:33:00 +0200 Subject: [PATCH] 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()