From 70b85a57be344ec8b3f8db36d84fd9c52f7b96a0 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 25 Jun 2021 18:53:01 +0200 Subject: [PATCH] JPERF-273: Support Jiras with an HTTP path --- .../api/jira/install/HttpHost.kt | 19 +++++++++++++++++++ .../api/jira/install/InstalledJira.kt | 4 ++-- .../api/jira/install/JiraInstallation.kt | 6 +++--- .../api/jira/install/ParallelInstallation.kt | 6 +++--- .../jira/install/SequentialInstallation.kt | 6 +++--- .../jira/install/hook/AsyncProfilerHook.kt | 2 +- .../api/jira/install/hook/JiraLogs.kt | 2 +- .../api/jira/install/hook/JvmConfig.kt | 4 ++-- .../jira/install/hook/LateUbuntuSysstat.kt | 2 +- .../jira/instance/DefaultClusterProperties.kt | 2 +- .../api/jira/instance/JiraServerPlan.kt | 2 +- .../infrastructure/api/jira/report/Reports.kt | 17 ++++++++++++----- .../api/jira/start/hook/AccessLogs.kt | 2 +- .../api/jira/start/hook/JstatHook.kt | 2 +- .../api/jira/start/hook/RestUpgrade.kt | 16 +++++++--------- .../install/hook/HookedJiraInstallation.kt | 10 +++++----- .../jira/install/hook/ProfilerHook.kt | 2 +- .../jira/install/hook/SplunkForwarderHook.kt | 2 +- .../jira/start/hook/HookedJiraStart.kt | 4 ++-- .../api/jira/instance/JiraDataCenterPlanIT.kt | 4 ++-- .../api/jira/instance/JiraServerPlanIT.kt | 6 ++---- 21 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/HttpHost.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/HttpHost.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/HttpHost.kt new file mode 100644 index 00000000..f1019129 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/HttpHost.kt @@ -0,0 +1,19 @@ +package com.atlassian.performance.tools.infrastructure.api.jira.install + +import java.net.URI + +class HttpHost( + val tcp: TcpHost, + private val basePath: String, + private val supportsTls: Boolean +) { + + fun addressPublicly(): URI = address(tcp.publicIp) + fun addressPrivately(): URI = address(tcp.privateIp) + fun addressPrivately(userName: String, password: String): URI = address(tcp.privateIp, "$userName:$password@") + + private fun address(ip: String, userInfo: String = ""): URI { + val scheme = if (supportsTls) "https" else "http" + return URI("$scheme://$userInfo$ip:${tcp.port}/$basePath/") + } +} diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/InstalledJira.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/InstalledJira.kt index 95c77249..4927bc38 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/InstalledJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/InstalledJira.kt @@ -22,7 +22,7 @@ class InstalledJira( */ val jdk: JavaDevelopmentKit, /** - * Hosts Jira. Specifies sockets used by Jira to handle requests. + * Connects to Jira on HTTP level or below. */ - val host: TcpHost + val http: HttpHost ) diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/JiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/JiraInstallation.kt index deb4bfb0..299a6882 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/JiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/JiraInstallation.kt @@ -10,13 +10,13 @@ import net.jcip.annotations.ThreadSafe interface JiraInstallation { /** - * Installs Jira on [host]. + * Installs Jira on [tcp]. * - * @param [host] will host the Jira + * @param [tcp] will host the Jira * @param [reports] accumulates reports */ fun install( - host: TcpHost, + tcp: TcpHost, reports: Reports ): InstalledJira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/ParallelInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/ParallelInstallation.kt index 452f1bea..85ca1610 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/ParallelInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/ParallelInstallation.kt @@ -16,10 +16,10 @@ class ParallelInstallation( ) : JiraInstallation { override fun install( - host: TcpHost, + tcp: TcpHost, reports: Reports ): InstalledJira { - host.ssh.newConnection().use { ssh -> + tcp.ssh.newConnection().use { ssh -> val pool = Executors.newCachedThreadPool { runnable -> Thread(runnable, "jira-installation-${runnable.hashCode()}") } @@ -32,7 +32,7 @@ class ParallelInstallation( val java = pool.submitWithLogContext("java") { jdk.also { it.install(ssh) } } - val jira = InstalledJira(home.get(), product.get(), java.get(), host) + val jira = InstalledJira(home.get(), product.get(), java.get(), HttpHost(tcp, "/", false)) pool.shutdownNow() return jira } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/SequentialInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/SequentialInstallation.kt index c5d124d3..b8eab313 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/SequentialInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/SequentialInstallation.kt @@ -14,14 +14,14 @@ class SequentialInstallation( ) : JiraInstallation { override fun install( - host: TcpHost, + tcp: TcpHost, reports: Reports ): InstalledJira { - host.ssh.newConnection().use { ssh -> + tcp.ssh.newConnection().use { ssh -> val installation = productDistribution.installRemotely(ssh, ".") val home = jiraHomeSource.downloadRemotely(ssh) jdk.install(ssh) - return InstalledJira(home, installation, jdk, host) + return InstalledJira(home, installation, jdk, HttpHost(tcp, "/", false)) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/AsyncProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/AsyncProfilerHook.kt index 186453e7..c43ced02 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/AsyncProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/AsyncProfilerHook.kt @@ -43,7 +43,7 @@ private class InstalledAsyncProfiler( ) { ssh.execute("$profilerPath -b 20000000 start ${jira.pid}") val profiler = StartedAsyncProfiler(jira.pid, profilerPath) - reports.add(profiler, jira.installed.host) + reports.add(profiler, jira) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraLogs.kt index adfc0033..7d544f19 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JiraLogs.kt @@ -10,7 +10,7 @@ import java.nio.file.Paths class JiraLogs : PostInstallHook { override fun call(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks, reports: Reports) { - reports.add(report(jira), jira.host) + reports.add(report(jira), jira) } fun report(jira: InstalledJira): Report { diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JvmConfig.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JvmConfig.kt index 88ed1e91..3fe4ab97 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JvmConfig.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/JvmConfig.kt @@ -23,9 +23,9 @@ class JvmConfig( connection = ssh, config = config, gcLog = gcLog, - jiraIp = jira.host.publicIp + jiraIp = jira.http.tcp.publicIp ) val report = FileListing(gcLog.path("*")) - reports.add(report, jira.host) + reports.add(report, jira) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/LateUbuntuSysstat.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/LateUbuntuSysstat.kt index 26f327e2..2404e567 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/LateUbuntuSysstat.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/install/hook/LateUbuntuSysstat.kt @@ -32,6 +32,6 @@ private class PostStartOsMetric( ) : PostStartHook { override fun call(ssh: SshConnection, jira: StartedJira, hooks: PostStartHooks, reports: Reports) { val process = metric.start(ssh) - reports.add(RemoteMonitoringProcessReport(process), jira.installed.host) + reports.add(RemoteMonitoringProcessReport(process), jira) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt index 1e2bbbb3..ab342f07 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/DefaultClusterProperties.kt @@ -11,7 +11,7 @@ class DefaultClusterProperties : PostInstallHook { override fun call(ssh: SshConnection, jira: InstalledJira, hooks: PostInstallHooks, reports: Reports) { ClusterProperties(jira).apply { - set("jira.node.id", jira.host.name, ssh) + set("jira.node.id", jira.http.tcp.name, ssh) set("ehcache.object.port", "40011", ssh) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlan.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlan.kt index c9d7da75..d15eaa0a 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlan.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlan.kt @@ -30,7 +30,7 @@ class JiraServerPlan private constructor( private class JiraServer( node: StartedJira ) : JiraInstance { - override val address: URI = node.installed.host.run { URI("http://$publicIp:$port/") } + override val address: URI = node.installed.http.addressPublicly() override val nodes: List = listOf(node) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Reports.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Reports.kt index 84aa3ae9..76a7b1c4 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Reports.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/report/Reports.kt @@ -1,6 +1,8 @@ package com.atlassian.performance.tools.infrastructure.api.jira.report +import com.atlassian.performance.tools.infrastructure.api.jira.install.InstalledJira import com.atlassian.performance.tools.infrastructure.api.jira.install.TcpHost +import com.atlassian.performance.tools.infrastructure.api.jira.start.StartedJira import com.atlassian.performance.tools.infrastructure.api.os.RemotePath import com.atlassian.performance.tools.io.api.ensureDirectory import com.atlassian.performance.tools.io.api.resolveSafely @@ -15,11 +17,16 @@ class Reports private constructor( // TODO turn into SPI to allow AWS CLI transp ) { constructor() : this(ConcurrentLinkedQueue()) - fun add( - report: Report, - host: TcpHost - ) { - hostReports.add(HostReport(host, report)) + fun add(report: Report, started: StartedJira) { + add(report, started.installed) + } + + fun add(report: Report, installed: InstalledJira) { + add(report, installed.http.tcp) + } + + fun add(report: Report, tcp: TcpHost) { + hostReports.add(HostReport(tcp, report)) } fun downloadTo( diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/AccessLogs.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/AccessLogs.kt index f6f35c5d..c2c30a78 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/AccessLogs.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/AccessLogs.kt @@ -8,6 +8,6 @@ import com.atlassian.performance.tools.ssh.api.SshConnection class AccessLogs : PreStartHook { override fun call(ssh: SshConnection, jira: InstalledJira, hooks: PreStartHooks, reports: Reports) { - reports.add(FileListing("${jira.installation.path}/logs/*access*"), jira.host) + reports.add(FileListing("${jira.installation.path}/logs/*access*"), jira) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/JstatHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/JstatHook.kt index 547e51af..f1e15be5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/JstatHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/JstatHook.kt @@ -14,6 +14,6 @@ class JstatHook : PostStartHook { reports: Reports ) { val process = jira.installed.jdk.jstatMonitoring.start(ssh, jira.pid) - reports.add(RemoteMonitoringProcessReport(process), jira.installed.host) + reports.add(RemoteMonitoringProcessReport(process), jira) } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/RestUpgrade.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/RestUpgrade.kt index d0dcd229..e9e3b9b5 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/RestUpgrade.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/start/hook/RestUpgrade.kt @@ -35,13 +35,11 @@ class RestUpgrade( private val threadDump: ThreadDump, private val reports: Reports ) { - private val upgradesEndpoint: URI - - init { - val ip = jira.installed.host.privateIp - val port = jira.installed.host.port - upgradesEndpoint = URI("http://$adminUsername:$adminPassword@$ip:$port/rest/api/2/upgrade") - } + private val upgradesEndpoint: URI = jira + .installed + .http + .addressPrivately(adminUsername, adminPassword) + .resolve("rest/api/2/upgrade") fun waitUntilOnline() { waitForStatusToChange("000", timeouts.offlineTimeout) @@ -70,8 +68,8 @@ class RestUpgrade( break } if (deadline < Instant.now()) { - reports.add(JiraLogs().report(jira.installed), jira.installed.host) - reports.add(FileListing("thread-dumps/*"), jira.installed.host) + reports.add(JiraLogs().report(jira.installed), jira) + reports.add(FileListing("thread-dumps/*"), jira) throw Exception("$upgradesEndpoint failed to get out of $statusQuo status within $timeout") } threadDump.gather(ssh, "thread-dumps") diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/HookedJiraInstallation.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/HookedJiraInstallation.kt index 153fafe8..ba8b8cc7 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/HookedJiraInstallation.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/HookedJiraInstallation.kt @@ -12,14 +12,14 @@ class HookedJiraInstallation( ) : JiraInstallation { override fun install( - host: TcpHost, + tcp: TcpHost, reports: Reports ): InstalledJira { - host.ssh.newConnection().use { ssh -> - hooks.call(ssh, host, reports) + tcp.ssh.newConnection().use { ssh -> + hooks.call(ssh, tcp, reports) } - val installed = installation.install(host, reports) - host.ssh.newConnection().use { ssh -> + val installed = installation.install(tcp, reports) + tcp.ssh.newConnection().use { ssh -> hooks.postInstall.call(ssh, installed, reports) } return installed diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/ProfilerHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/ProfilerHook.kt index 294ab3e5..3ecd6098 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/ProfilerHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/ProfilerHook.kt @@ -37,7 +37,7 @@ private class InstalledProfiler( ) { val process = profiler.start(ssh, jira.pid) if (process != null) { - reports.add(RemoteMonitoringProcessReport(process), jira.installed.host) + reports.add(RemoteMonitoringProcessReport(process), jira) } } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/SplunkForwarderHook.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/SplunkForwarderHook.kt index 1e27f25b..0baf1797 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/SplunkForwarderHook.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/install/hook/SplunkForwarderHook.kt @@ -18,6 +18,6 @@ internal class SplunkForwarderHook( reports: Reports ) { splunk.jsonifyLog4j(ssh, "${jira.installation.path}/atlassian-jira/WEB-INF/classes/log4j.properties") - splunk.run(ssh, jira.host.name, "/home/ubuntu/jirahome/log") + splunk.run(ssh, jira.http.tcp.name, "/home/ubuntu/jirahome/log") } } diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/start/hook/HookedJiraStart.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/start/hook/HookedJiraStart.kt index e23395f9..73d02676 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/start/hook/HookedJiraStart.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/jira/start/hook/HookedJiraStart.kt @@ -15,11 +15,11 @@ class HookedJiraStart( installed: InstalledJira, reports: Reports ): StartedJira { - installed.host.ssh.newConnection().use { ssh -> + installed.http.tcp.ssh.newConnection().use { ssh -> hooks.call(ssh, installed, reports) } val started = start.start(installed, reports) - installed.host.ssh.newConnection().use { ssh -> + installed.http.tcp.ssh.newConnection().use { ssh -> hooks.postStart.call(ssh, started, reports) } return started diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt index 834b39d7..50e91343 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraDataCenterPlanIT.kt @@ -77,9 +77,9 @@ class JiraDataCenterPlanIT { .installation .resolve("conf/server.xml") .download(Files.createTempFile("downloaded-config", ".xml")) - assertThat(serverXml.readText()).contains(" + installed.http.tcp.ssh.newConnection().use { ssh -> ssh.execute("wget ${dataCenter.address}") } } diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlanIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlanIT.kt index 7de06cda..3c944099 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlanIT.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jira/instance/JiraServerPlanIT.kt @@ -67,18 +67,16 @@ class JiraServerPlanIT { jiraServerPlan.report().downloadTo(debugging) throw Exception("Jira Server plan failed to materialize, debugging info available in $debugging", e) } - - val theNode = jiraServer.nodes.single() - val host = theNode.installed.host val reports = jiraServerPlan.report().downloadTo(Files.createTempDirectory("jira-server-plan-")) // then + val theNode = jiraServer.nodes.single() val serverXml = theNode .installed .installation .resolve("conf/server.xml") .download(Files.createTempFile("downloaded-config", ".xml")) - assertThat(serverXml.readText()).contains("