From 7e7f427bc12db7a2329f68a1712d011ba4fe113d Mon Sep 17 00:00:00 2001 From: Mikolaj Grzaslewicz Date: Mon, 3 Jun 2024 17:54:44 +0200 Subject: [PATCH] DCPERF-430 Add VersionedOracleJdk --- CHANGELOG.md | 2 + .../api/jvm/VersionedOracleJdk.kt | 60 +++++++++++++++++++ .../api/jvm/VersionedOracleJdkIT.kt | 31 ++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdk.kt create mode 100644 src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdkIT.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 4165be78..305e0325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ Dropping a requirement of a major version of a dependency is a new contract. ## [Unreleased] [Unreleased]: https://github.com/atlassian/infrastructure/compare/release-4.28.3...master +### Added +- Add `VersionedOracleJdk` to support Oracle JDK 11+ ## [4.28.3] - 2024-02-08 ### Fixed diff --git a/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdk.kt b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdk.kt new file mode 100644 index 00000000..b7d62ff9 --- /dev/null +++ b/src/main/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdk.kt @@ -0,0 +1,60 @@ +package com.atlassian.performance.tools.infrastructure.api.jvm + +import com.atlassian.performance.tools.jvmtasks.api.ExponentialBackoff +import com.atlassian.performance.tools.jvmtasks.api.IdempotentAction +import com.atlassian.performance.tools.ssh.api.SshConnection +import java.time.Duration.ofSeconds + + +/** + * Supports Oracle JDK 11 and later. + */ +class VersionedOracleJdk private constructor( + private val majorVersion: String, + private val minorVersion: String, + private val patchVersion: String +) : VersionedJavaDevelopmentKit { + private val version = "$majorVersion.$minorVersion.$patchVersion" + private val downloadUrl = + "https://download.oracle.com/java/$majorVersion/archive/jdk-${version}_linux-x64_bin.tar.gz" + private val javaHome = "~/jdk-$version" + + override fun getMajorVersion() = majorVersion.toInt() + + override fun install(connection: SshConnection) { + IdempotentAction("download JDK $version") { + connection.execute( + cmd = "curl $downloadUrl > jdk-$version.tar.gz", + timeout = ofSeconds(120) + ) + }.retry(3, ExponentialBackoff(ofSeconds(10))) + connection.execute("tar --extract --gunzip --file jdk-$version.tar.gz") + connection.execute("echo '${use()}' >> ~/.profile") + } + + override fun use(): String = "export PATH=$javaHome/bin:\$PATH; export JAVA_HOME=$javaHome" + + override fun command(options: String) = "$javaHome/bin/java $options" + + override val jstatMonitoring = Jstat("$javaHome/bin/") + + class Builder { + private var majorVersion: String = "17" + private var minorVersion: String = "0" + private var patchVersion: String = "11" + + fun version(majorVersion: String, minorVersion: String, patchVersion: String) = apply { + this.majorVersion = majorVersion + this.minorVersion = minorVersion + this.patchVersion = patchVersion + } + + fun build(): VersionedOracleJdk = VersionedOracleJdk( + majorVersion = majorVersion, + minorVersion = minorVersion, + patchVersion = patchVersion + ) + + } + +} diff --git a/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdkIT.kt b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdkIT.kt new file mode 100644 index 00000000..d057f51b --- /dev/null +++ b/src/test/kotlin/com/atlassian/performance/tools/infrastructure/api/jvm/VersionedOracleJdkIT.kt @@ -0,0 +1,31 @@ +package com.atlassian.performance.tools.infrastructure.api.jvm + +import org.junit.Test + +class VersionedOracleJdkIT { + + @Test + fun shouldSupportJstat() { + JstatSupport(VersionedOracleJdk.Builder().build()).shouldSupportJstat() + } + + @Test + fun shouldGatherThreadDump() { + ThreadDumpTest(VersionedOracleJdk.Builder().build()).shouldGatherThreadDump() + } + + @Test + fun shouldHaveJavaHomeSet() { + JdkSupport(VersionedOracleJdk.Builder().build()).shouldHaveJavaHomeSet("/jdk-17.0.11") + } + + @Test + fun shouldHaveJavaHomeSetForJdk21() { + JdkSupport( + VersionedOracleJdk.Builder() + .version("21", "0", "2") + .build() + ).shouldHaveJavaHomeSet("/jdk-21.0.2") + } + +}