Skip to content

Commit

Permalink
JPERF-273: Support Jiras with an HTTP path
Browse files Browse the repository at this point in the history
  • Loading branch information
dagguh committed Jun 25, 2021
1 parent 080f55e commit 961107c
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.atlassian.performance.tools.infrastructure.api.jira.install

import java.net.URI

class HttpHost internal constructor(
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/")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AsyncProfilerHook : PreInstallHook {

override fun call(
ssh: SshConnection,
host: TcpHost,
tcp: TcpHost,
hooks: PreInstallHooks,
reports: Reports
) {
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import com.atlassian.performance.tools.ssh.api.SshConnection
interface PreInstallHook {

/**
* @param [ssh] connects to the [host]
* @param [host] will install Jira
* @param [ssh] connects to the [tcp]
* @param [tcp] will install Jira
* @param [hooks] inserts future hooks
* @param [reports] accumulates reports
*/
fun call(
ssh: SshConnection,
host: TcpHost,
tcp: TcpHost,
hooks: PreInstallHooks,
reports: Reports
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.atlassian.performance.tools.ssh.api.SshConnection

class SystemLog : PreInstallHook {

override fun call(ssh: SshConnection, host: TcpHost, hooks: PreInstallHooks, reports: Reports) {
reports.add(FileListing("/var/log/syslog"), host)
override fun call(ssh: SshConnection, tcp: TcpHost, hooks: PreInstallHooks, reports: Reports) {
reports.add(FileListing("/var/log/syslog"), tcp)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StartedJira> = listOf(node)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ private class CountingHook : PreInstallHook {

var count = 0

override fun call(ssh: SshConnection, host: TcpHost, hooks: PreInstallHooks, reports: Reports) {
override fun call(ssh: SshConnection, tcp: TcpHost, hooks: PreInstallHooks, reports: Reports) {
count++
}
}

private class InsertingHook(
private val hook: PreInstallHook
) : PreInstallHook {
override fun call(ssh: SshConnection, host: TcpHost, hooks: PreInstallHooks, reports: Reports) {
override fun call(ssh: SshConnection, tcp: TcpHost, hooks: PreInstallHooks, reports: Reports) {
hooks.insert(hook)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class JiraDataCenterPlanIT {
.installation
.resolve("conf/server.xml")
.download(Files.createTempFile("downloaded-config", ".xml"))
assertThat(serverXml.readText()).contains("<Connector port=\"${installed.host.port}\"")
assertThat(serverXml.readText()).contains("<Connector port=\"${installed.http.tcp.port}\"")
assertThat(node.pid).isPositive()
installed.host.ssh.newConnection().use { ssh ->
installed.http.tcp.ssh.newConnection().use { ssh ->
ssh.execute("wget ${dataCenter.address}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<Connector port=\"${host.port}\"")
assertThat(serverXml.readText()).contains("<Connector port=\"${theNode.installed.http.tcp.port}\"")
assertThat(theNode.pid).isPositive()
assertThat(reports).isDirectory()
val fileTree = reports
Expand Down

0 comments on commit 961107c

Please sign in to comment.