Skip to content

Commit

Permalink
Use two booleans instead of an EnumSet.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewCochrane committed May 30, 2023
1 parent f6f4a25 commit 5fd944d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class DataCenterFormula private constructor(
private val databaseVolume: Volume,
private val accessRequester: AccessRequester,
private val adminPasswordPlainText: String,
private val storeInS3: EnumSet<JiraSharedStorageResource>,
private val storeAvatarsInS3: Boolean,
private val storeAttachmentsInS3: Boolean,
private val waitForUpgrades: Boolean
) : JiraFormula {
private val logger: Logger = LogManager.getLogger(this::class.java)
Expand Down Expand Up @@ -146,7 +147,7 @@ class DataCenterFormula private constructor(
).provision()
}

if (storeInS3.isNotEmpty()) {
if (storeAvatarsInS3 || storeAttachmentsInS3) {
StackFormula(
investment = investment,
aws = aws,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
)
Expand Down Expand Up @@ -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<JiraSharedStorageResource> = EnumSet.noneOf(
JiraSharedStorageResource::class.java)
private var storeAvatarsInS3: Boolean = false
private var storeAttachmentsInS3: Boolean = false
private var waitForUpgrades: Boolean = true

internal constructor(
Expand All @@ -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
}

Expand Down Expand Up @@ -448,7 +452,9 @@ class DataCenterFormula private constructor(

fun accessRequester(accessRequester: AccessRequester) = apply { this.accessRequester = accessRequester }

fun storeInS3(storeInS3: EnumSet<JiraSharedStorageResource>) = 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
Expand All @@ -471,7 +477,8 @@ class DataCenterFormula private constructor(
databaseVolume = databaseVolume,
accessRequester = accessRequester,
adminPasswordPlainText = adminPasswordPlainText,
storeInS3 = storeInS3,
storeAvatarsInS3 = storeAvatarsInS3,
storeAttachmentsInS3 = storeAttachmentsInS3,
waitForUpgrades = waitForUpgrades
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
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(
private val nodeIndex: Int,
private val sharedHome: Future<SharedHome>,
private val base: NodeFormula,
private val privateIpAddress: String,
private val storeInS3: EnumSet<JiraSharedStorageResource> = 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 {
Expand All @@ -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 ->
"""<association target="${element.name.toLowerCase()}" file-store="s3Bucket" />"""
if (s3StorageBucketName != null && (storeAvatarsInS3 || storeAttachmentsInS3)) {
val associations = mutableListOf<String>()
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 <<EOT > $jiraHome/filestore-config.xml
Expand All @@ -56,7 +57,7 @@ internal class DataCenterNodeFormula(
</associations>
</filestore-config>
EOT
""".trimIndent()
""".trimIndent()
)
}
}
Expand All @@ -73,6 +74,10 @@ internal class DataCenterNodeFormula(
}
}

fun createAssociation(target: String): String {
return """<association target="$target" file-store="s3Bucket" />"""
}

fun convertRegionFormat(region: String): String {
return region.toLowerCase().replace('_', '-')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ 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,
private val jiraHomeSource: JiraHomeSource,
private val ip: String,
private val ssh: Ssh,
private val computer: Computer,
private val storeInS3: EnumSet<JiraSharedStorageResource> = 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"
Expand All @@ -48,17 +43,17 @@ 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(
cmd = "export AWS_RETRY_MODE=standard; export AWS_MAX_ATTEMPTS=10; cd $localSharedHome/data && ( find attachments -mindepth 1 -maxdepth 1 -type d -print0 | xargs -n1 -0 -P30 -I {} aws s3 cp --recursive --only-show-errors {}/ s3://$s3StorageBucketName/{}/ )",
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(
Expand Down

0 comments on commit 5fd944d

Please sign in to comment.