Skip to content

Commit 9d0d16b

Browse files
committed
JsmDevDeployment.groovy
* Cleanup and restructure * Restoring from snapshot now works better
1 parent 0f115ec commit 9d0d16b

File tree

4 files changed

+72
-33
lines changed

4 files changed

+72
-33
lines changed

.idea/jarRepositories.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
<id>eficode-github-jiraManagerRest</id>
136136
<url>https://github.com/eficode/JiraInstanceManagerRest/raw/packages/repository/</url>
137137
</repository>
138+
<repository>
139+
<id>eficode-github-remoteSpock</id>
140+
<url>https://github.com/eficode/remoteSpock/raw/packages/repository/</url>
141+
</repository>
138142
<repository>
139143
<id>eficode-github-BitbucketInstanceManagerRest</id>
140144
<url>https://github.com/eficode/BitbucketInstanceManagerRest/raw/packages/repository/</url>

src/main/groovy/com/eficode/devstack/deployment/impl/JsmDevDeployment.groovy

+25-23
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,23 @@ class JsmDevDeployment implements Deployment {
3737
JsmDevDeployment(String jiraBaseUrl, String dockerHost, String dockerCertPath, ArrayList<String> srcCodePaths) {
3838

3939
componentsPrefix = AllureContainer.extractDomainFromUrl(jiraBaseUrl)
40+
subDeployments.add(new JsmH2Deployment(jiraBaseUrl, dockerHost, dockerCertPath))
41+
4042

4143
allureContainer = new AllureContainer(dockerHost, dockerCertPath)
4244
allureContainer.containerName = componentsPrefix + "-reporter"
4345
dockerClient = allureContainer.dockerClient
4446

45-
46-
allureReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-allureReports")
47-
jiraReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-jiraReports")
48-
allureContainer.prepareCustomEnvVar(["CHECK_RESULTS_EVERY_SECONDS=3", "KEEP_HISTORY=1", "KEEP_HISTORY_LATEST=30"])
49-
allureContainer.setResultsVolume(allureReportVolume.name)
50-
51-
52-
srcCodeVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-code")
5347
srcSyncer = DirectorySyncer.getDuplicateContainer(dockerClient, "SrcSyncer")
54-
this.srcCodePaths = srcCodePaths
48+
reportSyncer = DirectorySyncer.getDuplicateContainer(dockerClient, "ReportSyncer")
5549

56-
if (srcSyncer?.created) {
57-
log.warn("Old SrcSyncer container exists, removing it before proceeding")
58-
srcSyncer.stopAndRemoveContainer()
59-
srcSyncer = null
60-
}
6150

6251

63-
subDeployments.add(new JsmH2Deployment(jiraBaseUrl, dockerHost, dockerCertPath))
64-
jsmDeployment.jsmContainer.prepareVolumeMount(srcCodeVolume.name, "/var/atlassian/application-data/jira/scripts/", false)
65-
jsmDeployment.jsmContainer.prepareVolumeMount(jiraReportVolume.name, "/var/atlassian/application-data/jira/allure-results/", false)
66-
52+
this.srcCodePaths = srcCodePaths
6753

6854
}
6955

56+
7057
JsmH2Deployment getJsmDeployment() {
7158
return subDeployments.find { it instanceof JsmH2Deployment } as JsmH2Deployment
7259
}
@@ -93,7 +80,8 @@ class JsmDevDeployment implements Deployment {
9380

9481
try {
9582
jsmSnapshotVolume = jsmContainer.getSnapshotVolume()
96-
}catch (ignored){}
83+
} catch (ignored) {
84+
}
9785

9886

9987
Boolean success = Deployment.super.stopAndRemoveDeployment()
@@ -120,21 +108,35 @@ class JsmDevDeployment implements Deployment {
120108
boolean setupDeployment() {
121109

122110

123-
srcSyncer = DirectorySyncer.createSyncToVolume(srcCodePaths, srcCodeVolume.name, "SrcSyncer", "-avh --chown=2001:2001")
111+
112+
srcCodeVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-code")
113+
allureReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-allureReports")
114+
jiraReportVolume = dockerClient.getOrCreateVolume(componentsPrefix + "-jiraReports")
124115

125116

117+
srcSyncer = DirectorySyncer.createSyncToVolume(srcCodePaths, srcCodeVolume.name, "SrcSyncer", "-avh --chown=2001:2001")
126118
reportSyncer = DirectorySyncer.syncBetweenVolumesAndUsers(jiraReportVolume.name, allureReportVolume.name, "1000:1000", "ReportSyncer")
127119

128120

121+
allureContainer.prepareCustomEnvVar(["CHECK_RESULTS_EVERY_SECONDS=3", "KEEP_HISTORY=1", "KEEP_HISTORY_LATEST=30"])
122+
allureContainer.setResultsVolume(allureReportVolume.name)
123+
124+
129125
allureContainer.created ?: allureContainer.createContainer()
130126
allureContainer.startContainer()
131127

128+
if (!jsmDeployment.jsmContainer.created) {
129+
jsmDeployment.jsmContainer.prepareVolumeMount(srcCodeVolume.name, "/var/atlassian/application-data/jira/scripts/", false)
130+
jsmDeployment.jsmContainer.prepareVolumeMount(jiraReportVolume.name, "/var/atlassian/application-data/jira/allure-results/", false)
131+
132+
}
133+
132134
jsmDeployment.setupDeployment(builder.useSnapshotIfAvailable, builder.snapshotAfterCreation)
133135
//Change owner of the mounted volume
134136
jsmContainer.runBashCommandInContainer("chown -R jira:jira /var/atlassian/application-data/jira/allure-results", 10, "root")
135137

136138
if (jsmDeployment.jiraRest.scriptRunnerIsInstalled()) {
137-
jsmDeployment.jiraRest.deploySpockEndpoint(['com.riadalabs.jira.plugins.insight' ])
139+
jsmDeployment.jiraRest.deploySpockEndpoint(['com.riadalabs.jira.plugins.insight'])
138140
}
139141

140142
}
@@ -197,12 +199,12 @@ class JsmDevDeployment implements Deployment {
197199
return this
198200
}
199201

200-
Builder useSnapshotIfAvailable( ) {
202+
Builder useSnapshotIfAvailable() {
201203
this.useSnapshotIfAvailable = true
202204
return this
203205
}
204206

205-
Builder snapshotAfterCreation( ) {
207+
Builder snapshotAfterCreation() {
206208
this.snapshotAfterCreation = true
207209
return this
208210
}

src/test/groovy/com/eficode/devstack/deployment/impl/JsmDevDeploymentSpec.groovy

+38-10
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,45 @@ class JsmDevDeploymentSpec extends DevStackSpec {
8585
JiraInstanceManagerRest jim = new JiraInstanceManagerRest(baseUrl)
8686

8787

88-
when:
88+
when: "When seting up the builder and running stopAndRemove"
8989
JsmDevDeployment jsmDevDep = new JsmDevDeployment.Builder(baseUrl, jsmLicenseFile.text, [localSrcDir.canonicalPath])
9090
.setJsmJvmDebugPort("5005")
9191
.setJsmVersion("latest")
9292
.enableJsmDood()
9393
.addAppToInstall(MarketplaceApp.getScriptRunnerVersion().downloadUrl, srLicenseFile.text)
94+
.snapshotAfterCreation()
95+
.useSnapshotIfAvailable()
9496
.build()
9597

9698

99+
jsmDevDep.stopAndRemoveDeployment()
100+
101+
then: "None of the parts should exist"
102+
!jsmDevDep.jsmContainer?.created
103+
!jsmDevDep.allureContainer?.created
104+
!jsmDevDep.reportSyncer?.created
105+
!jsmDevDep.srcSyncer?.created
106+
!jsmDevDep.allureReportVolume?.usageData?.propertySize
107+
!jsmDevDep.srcCodeVolume?.usageData?.propertySize
97108

109+
110+
when:
111+
Long initialSetupDuration = System.currentTimeMillis()
98112
jsmDevDep.setupDeployment()
113+
initialSetupDuration = System.currentTimeMillis() - initialSetupDuration
99114
ArrayList<ContainerSummary> containersAfter = getContainers()
100115

101116

102117
then:
103-
containersAfter.find {it.names.toString().contains("spockdev.localhost")}
104-
containersAfter.find {it.names.toString().contains("spockdev.localhost-reporter")}
105-
containersAfter.find {it.names.toString().contains("ReportSyncer")}
106-
containersAfter.find {it.names.toString().contains("SrcSyncer")}
118+
containersAfter.find { it.names.toString().contains("spockdev.localhost") }
119+
containersAfter.find { it.names.toString().contains("spockdev.localhost-reporter") }
120+
containersAfter.find { it.names.toString().contains("ReportSyncer") }
121+
containersAfter.find { it.names.toString().contains("SrcSyncer") }
107122

108123

109124
when: "Creating a file in the local synced dir"
110125

111-
File localTestFile = new File(localSrcDir, "com/eficode/atlassian/jira/jiraLocalScripts/JiraLocalSpockTest.groovy")
126+
File localTestFile = new File(localSrcDir, "com/eficode/atlassian/jira/jiraLocalScripts/JiraLocalSpockTest.groovy")
112127
localTestFile.createParentDirectories()
113128
localTestFile.text = getSuccessfulSpockBody()
114129
sleep(2000)
@@ -119,22 +134,35 @@ class JsmDevDeploymentSpec extends DevStackSpec {
119134
expect:
120135
jsmDevDep.jsmContainer.appAppUploadEnabled
121136
jsmDevDep.jsmContainer.enableJvmDebug() == null
122-
assert jim.isSpockEndpointDeployed(true) : "Spock endpoint was not deployed"
137+
assert jim.isSpockEndpointDeployed(true): "Spock endpoint was not deployed"
123138

124-
when:"Running spocktest"
139+
when: "Running spocktest"
125140
jim.runSpockTest("com.eficode.atlassian.jira.jiraLocalScripts.JiraLocalSpockTest", "", SpockOutputType.AllureReport, "allure-results/")
126141
sleep(2000)
127142
then:
128143
jsmDevDep.allureContainer.runBashCommandInContainer("ls -l /app/allure-results/")
129144
assert jsmDevDep.jsmContainer.runBashCommandInContainer("ls allure-results").first().split("\n").every { reportName ->
130145
jsmDevDep.allureContainer.runBashCommandInContainer("ls /app/allure-results/$reportName && echo Status: \$?").toString().contains("Status: 0")
131-
} : "All Reports in JIRA container haven't been synced to Allure container"
146+
}: "All Reports in JIRA container haven't been synced to Allure container"
132147

133148

149+
when:"When triggering another setup of the same deployment"
150+
String jsmCreatedTimestamp = jsmDevDep.jsmContainer.inspectContainer().created
151+
String reportSyncerCreatedTimestamp = jsmDevDep.reportSyncer.inspectContainer().created
152+
String srcSyncerCreatedTimestamp = jsmDevDep.srcSyncer.inspectContainer().created
153+
Long snapshotSetupDuration = System.currentTimeMillis()
154+
jsmDevDep.setupDeployment()
155+
snapshotSetupDuration = System.currentTimeMillis() - snapshotSetupDuration
156+
157+
then: "Snapshot should be restored and containers remain the same"
158+
jsmCreatedTimestamp == jsmDevDep.jsmContainer.inspectContainer().created
159+
reportSyncerCreatedTimestamp == jsmDevDep.reportSyncer.inspectContainer().created
160+
srcSyncerCreatedTimestamp == jsmDevDep.srcSyncer.inspectContainer().created
161+
(snapshotSetupDuration * 2) < initialSetupDuration
162+
134163
cleanup:
135164
jsmDevDep.stopAndRemoveDeployment()
136165

137166

138-
139167
}
140168
}

0 commit comments

Comments
 (0)