Skip to content

Commit

Permalink
Add RemotePath
Browse files Browse the repository at this point in the history
  • Loading branch information
dagguh committed Feb 5, 2021
1 parent 8043ce7 commit 4847966
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Progress on [JPERF-273]:
- Represent the information required to use an already installed Jira via `InstalledJira`.
- Represent a brand-new Jira instance via `EmptyJiraHome`.

- Point to remote files on SSH hosts via `RemotePath`.

[JPERF-273]: https://ecosystem.atlassian.net/browse/JPERF-273

## [4.17.5] - 2020-12-15
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.atlassian.performance.tools.infrastructure

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.os.RemotePath
import com.atlassian.performance.tools.ssh.api.SshConnection

fun JiraHomeSource.downloadRemotely(
ssh: SshConnection
) = RemotePath(ssh.getHost(), this.download(ssh))

fun ProductDistribution.installRemotely(
ssh: SshConnection,
destination: String
) = RemotePath(ssh.getHost(), this.install(ssh, destination))
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.atlassian.performance.tools.infrastructure.api.jira.install

import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit
import com.atlassian.performance.tools.infrastructure.api.os.RemotePath

/**
* Points to an already installed Jira.
Expand All @@ -11,11 +12,11 @@ class InstalledJira(
/**
* Contains `./dbconfig.xml` and other server-specific files.
*/
val home: String,
val home: RemotePath,
/**
* Contains `./bin/jira-start.sh` and other install-specific files.
*/
val installation: String,
val installation: RemotePath,
/**
* Can run Jira.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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.jvm.JavaDevelopmentKit
import com.atlassian.performance.tools.infrastructure.downloadRemotely
import com.atlassian.performance.tools.infrastructure.installRemotely
import com.atlassian.performance.tools.ssh.api.SshConnection
import java.util.concurrent.Executors

Expand All @@ -21,10 +23,10 @@ class ParallelInstallation(
Thread(runnable, "jira-installation-${runnable.hashCode()}")
}
val product = pool.submitWithLogContext("product") {
productDistribution.install(ssh, ".")
productDistribution.installRemotely(ssh, ".")
}
val home = pool.submitWithLogContext("home") {
jiraHomeSource.download(ssh)
jiraHomeSource.downloadRemotely(ssh)
}
val java = pool.submitWithLogContext("java") {
jdk.also { it.install(ssh) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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
import com.atlassian.performance.tools.infrastructure.api.jvm.JavaDevelopmentKit
import com.atlassian.performance.tools.infrastructure.downloadRemotely
import com.atlassian.performance.tools.infrastructure.installRemotely
import com.atlassian.performance.tools.ssh.api.SshConnection

class SequentialInstallation(
Expand All @@ -15,8 +17,8 @@ class SequentialInstallation(
ssh: SshConnection,
server: TcpServer
): InstalledJira {
val installation = productDistribution.install(ssh, ".")
val home = jiraHomeSource.download(ssh)
val installation = productDistribution.installRemotely(ssh, ".")
val home = jiraHomeSource.downloadRemotely(ssh)
jdk.install(ssh)
return InstalledJira(home, installation, jdk, server)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.atlassian.performance.tools.infrastructure.api.os

import com.atlassian.performance.tools.infrastructure.api.dataset.FileArchiver
import com.atlassian.performance.tools.ssh.api.Ssh
import com.atlassian.performance.tools.ssh.api.SshHost
import java.nio.file.Path
import java.time.Duration
import javax.json.Json
import javax.json.JsonObject

/**
* @since 4.18.0
*/
class RemotePath(
val host: SshHost,
val path: String
) {

constructor(json: JsonObject) : this(
host = SshHost(json.getJsonObject("host")),
path = json.getString("path")
)

fun toJson(): JsonObject = Json.createObjectBuilder()
.add("host", host.toJson())
.add("path", path)
.build()

fun resolve(other: String): RemotePath = RemotePath(host, "$path/$other")

fun move(destination: String, timeout: Duration): RemotePath {
if (path != destination) {
Ssh(host, connectivityPatience = 4).newConnection().use { ssh ->
ssh.execute("sudo mv $path $destination", timeout)
}
}
return RemotePath(host, destination)
}

fun archive(timeout: Duration): RemotePath {
val destination = Ssh(host, connectivityPatience = 4).newConnection().use { ssh ->
FileArchiver().zip(ssh, path, timeout)
}
return RemotePath(host, destination)
}

fun download(
localDestination: Path
) {
Ssh(host, connectivityPatience = 4).newConnection().use { ssh ->
ssh.download(path, localDestination)
}
}

override fun toString(): String {
return "RemotePath(host=$host, path='$path')"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ParallelInstallationIT {

// then
val serverXml = Files.createTempFile("downloaded-server", ".xml")
ssh.download(installed.installation + "/conf/server.xml", serverXml)
installed.installation.resolve("conf/server.xml").download(serverXml)
return@useSsh serverXml
}
}
Expand Down

0 comments on commit 4847966

Please sign in to comment.