From 5fd944d99e0c7eb6a11392a4b4f9d597c055718c Mon Sep 17 00:00:00 2001 From: Matt Cochrane Date: Tue, 30 May 2023 17:34:51 +1000 Subject: [PATCH] Use two booleans instead of an EnumSet. --- .../api/jira/DataCenterFormula.kt | 25 ++++++++++++------- .../api/jira/JiraSharedStorageResource.kt | 8 ------ .../jira/DataCenterNodeFormula.kt | 25 +++++++++++-------- .../jira/home/SharedHomeFormula.kt | 15 ++++------- 4 files changed, 36 insertions(+), 37 deletions(-) delete mode 100644 src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/JiraSharedStorageResource.kt diff --git a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/DataCenterFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/DataCenterFormula.kt index ebb432f2..73728107 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/DataCenterFormula.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/DataCenterFormula.kt @@ -61,7 +61,8 @@ class DataCenterFormula private constructor( private val databaseVolume: Volume, private val accessRequester: AccessRequester, private val adminPasswordPlainText: String, - private val storeInS3: EnumSet, + private val storeAvatarsInS3: Boolean, + private val storeAttachmentsInS3: Boolean, private val waitForUpgrades: Boolean ) : JiraFormula { private val logger: Logger = LogManager.getLogger(this::class.java) @@ -146,7 +147,7 @@ class DataCenterFormula private constructor( ).provision() } - if (storeInS3.isNotEmpty()) { + if (storeAvatarsInS3 || storeAttachmentsInS3) { StackFormula( investment = investment, aws = aws, @@ -206,7 +207,8 @@ class DataCenterFormula private constructor( ssh = sharedHomeSsh, computer = computer, s3StorageBucketName = s3StorageBucketName, - storeInS3 = storeInS3 + storeAvatarsInS3 = storeAvatarsInS3, + storeAttachmentsInS3 = storeAttachmentsInS3 ).provision() logger.info("Shared home is set up") sharedHome @@ -241,7 +243,8 @@ class DataCenterFormula private constructor( sharedHome = sharedHome, privateIpAddress = instance.privateIpAddress, s3StorageBucketName = s3StorageBucketName, - storeInS3 = storeInS3, + storeAvatarsInS3 = storeAvatarsInS3, + storeAttachmentsInS3 = storeAttachmentsInS3, awsRegion = aws.region.name ) ) @@ -397,8 +400,8 @@ class DataCenterFormula private constructor( private var databaseVolume: Volume = Volume(100) private var accessRequester: AccessRequester = ForIpAccessRequester(LocalPublicIpv4Provider.Builder().build()) private var adminPasswordPlainText: String = "admin" - private var storeInS3: EnumSet = EnumSet.noneOf( - JiraSharedStorageResource::class.java) + private var storeAvatarsInS3: Boolean = false + private var storeAttachmentsInS3: Boolean = false private var waitForUpgrades: Boolean = true internal constructor( @@ -419,7 +422,8 @@ class DataCenterFormula private constructor( databaseVolume = formula.databaseVolume accessRequester = formula.accessRequester adminPasswordPlainText = formula.adminPasswordPlainText - storeInS3 = formula.storeInS3 + storeAvatarsInS3 = formula.storeAvatarsInS3 + storeAttachmentsInS3 = formula.storeAttachmentsInS3 waitForUpgrades = formula.waitForUpgrades } @@ -448,7 +452,9 @@ class DataCenterFormula private constructor( fun accessRequester(accessRequester: AccessRequester) = apply { this.accessRequester = accessRequester } - fun storeInS3(storeInS3: EnumSet) = apply { this.storeInS3 = storeInS3 } + fun storeAvatarsInS3(storeAvatarsInS3: Boolean) = apply { this.storeAvatarsInS3 = storeAvatarsInS3 } + + fun storeAttachmentsInS3(storeAttachmentsInS3: Boolean) = apply { this.storeAttachmentsInS3 = storeAttachmentsInS3 } /** * Don't change when starting up multi-node Jira DC of version lower than 9.1.0 @@ -471,7 +477,8 @@ class DataCenterFormula private constructor( databaseVolume = databaseVolume, accessRequester = accessRequester, adminPasswordPlainText = adminPasswordPlainText, - storeInS3 = storeInS3, + storeAvatarsInS3 = storeAvatarsInS3, + storeAttachmentsInS3 = storeAttachmentsInS3, waitForUpgrades = waitForUpgrades ) } diff --git a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/JiraSharedStorageResource.kt b/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/JiraSharedStorageResource.kt deleted file mode 100644 index 330b3f1e..00000000 --- a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/api/jira/JiraSharedStorageResource.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.atlassian.performance.tools.awsinfrastructure.api.jira; - -/** - * Describes a set of resources used by Jira and stored in shared storage (eg. shared home or S3). - */ -enum class JiraSharedStorageResource { - AVATARS, ATTACHMENTS -} diff --git a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/DataCenterNodeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/DataCenterNodeFormula.kt index 2d4daaae..e5984c62 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/DataCenterNodeFormula.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/DataCenterNodeFormula.kt @@ -1,10 +1,8 @@ package com.atlassian.performance.tools.awsinfrastructure.jira -import com.atlassian.performance.tools.awsinfrastructure.api.jira.JiraSharedStorageResource import com.atlassian.performance.tools.awsinfrastructure.api.jira.StartedNode import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome import com.atlassian.performance.tools.ssh.api.Ssh -import java.util.EnumSet import java.util.concurrent.Future internal class DataCenterNodeFormula( @@ -12,9 +10,8 @@ internal class DataCenterNodeFormula( private val sharedHome: Future, private val base: NodeFormula, private val privateIpAddress: String, - private val storeInS3: EnumSet = EnumSet.of( - JiraSharedStorageResource.ATTACHMENTS - ), + private val storeAvatarsInS3: Boolean = false, + private val storeAttachmentsInS3: Boolean = false, private val s3StorageBucketName: String? = null, private val awsRegion: String? = null ) : NodeFormula by base { @@ -33,11 +30,15 @@ internal class DataCenterNodeFormula( it.execute("echo jira.node.id = node$nodeIndex >> $jiraHome/cluster.properties") it.execute("echo jira.shared.home = `realpath $localSharedHome` >> $jiraHome/cluster.properties") - if (s3StorageBucketName != null && storeInS3.isNotEmpty()) { - val associations = storeInS3.map { element -> - """""" + if (s3StorageBucketName != null && (storeAvatarsInS3 || storeAttachmentsInS3)) { + val associations = mutableListOf() + if (storeAvatarsInS3) { + associations.add(createAssociation("avatars")) } - val formattedRegion = awsRegion?.let { it1 -> convertRegionFormat(it1) } + if (storeAttachmentsInS3) { + associations.add(createAssociation("attachments")) + } + val formattedRegion = awsRegion?.let { region -> convertRegionFormat(region) } it.execute( """ cat < $jiraHome/filestore-config.xml @@ -56,7 +57,7 @@ internal class DataCenterNodeFormula( EOT - """.trimIndent() + """.trimIndent() ) } } @@ -73,6 +74,10 @@ internal class DataCenterNodeFormula( } } + fun createAssociation(target: String): String { + return """""" + } + fun convertRegionFormat(region: String): String { return region.toLowerCase().replace('_', '-') } diff --git a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/home/SharedHomeFormula.kt b/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/home/SharedHomeFormula.kt index 45374277..d7dc9e13 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/home/SharedHomeFormula.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/awsinfrastructure/jira/home/SharedHomeFormula.kt @@ -3,15 +3,11 @@ package com.atlassian.performance.tools.awsinfrastructure.jira.home import com.atlassian.performance.tools.aws.api.Storage import com.atlassian.performance.tools.awsinfrastructure.api.aws.AwsCli import com.atlassian.performance.tools.awsinfrastructure.api.hardware.Computer -import com.atlassian.performance.tools.awsinfrastructure.api.jira.JiraSharedStorageResource -import com.atlassian.performance.tools.awsinfrastructure.api.jira.JiraSharedStorageResource.ATTACHMENTS -import com.atlassian.performance.tools.awsinfrastructure.api.jira.JiraSharedStorageResource.AVATARS import com.atlassian.performance.tools.infrastructure.api.jira.JiraHomeSource import com.atlassian.performance.tools.infrastructure.api.jira.SharedHome import com.atlassian.performance.tools.infrastructure.api.os.Ubuntu import com.atlassian.performance.tools.ssh.api.Ssh import java.time.Duration -import java.util.* internal class SharedHomeFormula( private val pluginsTransport: Storage, @@ -19,9 +15,8 @@ internal class SharedHomeFormula( private val ip: String, private val ssh: Ssh, private val computer: Computer, - private val storeInS3: EnumSet = EnumSet.of( - ATTACHMENTS - ), + private val storeAvatarsInS3: Boolean = false, + private val storeAttachmentsInS3: Boolean = false, private val s3StorageBucketName: String? = null ) { private val localSubnet = "10.0.0.0/24" @@ -48,9 +43,9 @@ internal class SharedHomeFormula( ubuntu.install(it, listOf("nfs-kernel-server")) it.execute("sudo echo '$localSharedHome $localSubnet(rw,sync,no_subtree_check,no_root_squash)' | sudo tee -a /etc/exports") - if (s3StorageBucketName != null && storeInS3.isNotEmpty()) { + if (s3StorageBucketName != null && (storeAvatarsInS3 || storeAttachmentsInS3)) { AwsCli(awsCliVersion).ensureAwsCli(it) - if (storeInS3.contains(ATTACHMENTS)) { + if (storeAttachmentsInS3) { // Copy the attachment data from NFS onto S3 // Use xargs to split the work across 30 concurrent jobs. This is much faster than a single job. it.safeExecute( @@ -58,7 +53,7 @@ internal class SharedHomeFormula( timeout = Duration.ofMinutes(10) ) } - if (storeInS3.contains(AVATARS)) { + if (storeAvatarsInS3) { // Copy the avatar data from NFS onto S3 // Split up into subdirs for faster s3 copy then use xargs to split the work across 30 concurrent jobs. it.safeExecute(