-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow storing Avatars/Attachments in S3 #166
base: master
Are you sure you want to change the base?
Changes from all commits
8cbd89e
9a5a02b
533e6fd
0826469
4549bad
6bab5c4
5127c16
58a0208
6f4d0a8
547049d
404ebfa
5ccedb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,14 @@ import java.util.concurrent.ConcurrentHashMap | |
* | ||
* @since 2.15.0 | ||
*/ | ||
class AwsCli { | ||
class AwsCli (val cliVersion: String = "2.9.12") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed the default version to 2.9.12. The bulk copying in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's drop old AWS cli support, unnecessary complexity. Preserve one constructor without parameters |
||
private val versionRegex = Regex("""([0-9]+)\.[0-9]+\.[0-9]+""") | ||
init { | ||
require( versionRegex.matches(cliVersion)) { | ||
"$cliVersion is not a valid aws cli version string." | ||
} | ||
} | ||
|
||
private companion object { | ||
private val LOCKS = ConcurrentHashMap<String, Any>() | ||
} | ||
|
@@ -21,21 +28,50 @@ class AwsCli { | |
val lock = LOCKS.computeIfAbsent(ssh.getHost().ipAddress) { Object() } | ||
synchronized(lock) { | ||
val awsCliExecutionResult = ssh.safeExecute("aws --version", Duration.ofSeconds(30), Level.TRACE, Level.TRACE) | ||
if (!awsCliExecutionResult.isSuccessful()) { | ||
if (awsCliExecutionResult.isSuccessful()) { | ||
val combinedOutput = "${awsCliExecutionResult.output}${awsCliExecutionResult.errorOutput}" | ||
require(combinedOutput.contains("aws-cli/$cliVersion")) { | ||
"Aws Cli version $cliVersion requested but different version is already installed: '${combinedOutput}'." | ||
} | ||
} else { | ||
Ubuntu().install(ssh, listOf("zip", "python"), Duration.ofMinutes(3)) | ||
ssh.execute( | ||
cmd = "curl --silent https://s3.amazonaws.com/aws-cli/awscli-bundle-1.15.51.zip -o awscli-bundle.zip", | ||
timeout = Duration.ofSeconds(50) | ||
) | ||
ssh.execute("unzip -n -q awscli-bundle.zip") | ||
ssh.execute( | ||
cmd = "sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws", | ||
timeout = Duration.ofSeconds(60) | ||
) | ||
val majorVersion = versionRegex.find(cliVersion)?.groupValues?.get(1) | ||
when (majorVersion) { | ||
"1" -> installV1Cli(ssh) | ||
else -> installV2Cli(ssh) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun installV1Cli(ssh: SshConnection) { | ||
ssh.execute( | ||
cmd = "curl --silent https://s3.amazonaws.com/aws-cli/awscli-bundle-$cliVersion.zip -o awscli-bundle.zip", | ||
timeout = Duration.ofSeconds(50) | ||
) | ||
ssh.execute("unzip -n -q awscli-bundle.zip") | ||
ssh.execute( | ||
cmd = "sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws", | ||
timeout = Duration.ofSeconds(60) | ||
) | ||
} | ||
|
||
/** | ||
* Instructions for setting up a V2 CLI are from | ||
* [link](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-version.html) | ||
*/ | ||
private fun installV2Cli(ssh: SshConnection) { | ||
ssh.execute( | ||
cmd="curl --silent https://awscli.amazonaws.com/awscli-exe-linux-x86_64-$cliVersion.zip -o awscliv2.zip", | ||
timeout = Duration.ofSeconds(50) | ||
) | ||
ssh.execute("unzip -n -q awscliv2.zip") | ||
ssh.execute( | ||
cmd = "sudo ./aws/install -i /usr/local/aws-cli -b /usr/local/bin", | ||
timeout = Duration.ofSeconds(60) | ||
) | ||
} | ||
|
||
fun download( | ||
location: StorageLocation, | ||
ssh: SshConnection, | ||
|
@@ -98,4 +134,4 @@ class AwsCli { | |
timeout | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.atlassian.performance.tools.awsinfrastructure.api.jira | ||
|
||
/** | ||
* Configuration for how and where to store data in a Jira DC cluster. | ||
*/ | ||
class JiraSharedStorageConfig private constructor( | ||
val storeAvatarsInS3: Boolean, | ||
val storeAttachmentsInS3: Boolean | ||
){ | ||
|
||
fun isAnyResourceStoredInS3(): Boolean { | ||
return storeAvatarsInS3 || storeAttachmentsInS3 | ||
} | ||
|
||
override fun toString(): String { | ||
return "JiraSharedStorageConfig(storeAvatarsInS3=$storeAvatarsInS3, storeAttachmentsInS3=$storeAttachmentsInS3)" | ||
} | ||
|
||
class Builder() { | ||
private var storeAvatarsInS3: Boolean = false | ||
private var storeAttachmentsInS3: Boolean = false | ||
|
||
constructor( | ||
jiraSharedStorageConfig: JiraSharedStorageConfig | ||
) : this() { | ||
storeAvatarsInS3 = jiraSharedStorageConfig.storeAvatarsInS3 | ||
storeAttachmentsInS3 = jiraSharedStorageConfig.storeAttachmentsInS3 | ||
} | ||
|
||
fun storeAvatarsInS3(storeAvatarsInS3: Boolean) = apply { this.storeAvatarsInS3 = storeAvatarsInS3 } | ||
fun storeAttachmentsInS3(storeAttachmentsInS3: Boolean) = apply { this.storeAttachmentsInS3 = storeAttachmentsInS3 } | ||
|
||
fun build() = JiraSharedStorageConfig( | ||
storeAvatarsInS3 = storeAvatarsInS3, | ||
storeAttachmentsInS3 = storeAttachmentsInS3 | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When 2 CLI versions dropped, this could become an implementation detail that could be skipped in changelog