Skip to content

Commit b129a3f

Browse files
committed
Check that a distribution has been started
Update the releasescript to ensure that a distribution has been started before starting it again. This functionality was accidentally removed during the updates for gh-21474. See gh-21474
1 parent 9d9a90c commit b129a3f

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,27 @@ private boolean isAlreadyPromoted(String buildName, String buildNumber, String t
124124
*/
125125
public void distribute(String sourceRepo, ReleaseInfo releaseInfo, Set<String> artifactDigests) {
126126
logger.debug("Attempting distribute via Artifactory");
127-
if (this.bintrayService.isDistributionComplete(releaseInfo, artifactDigests, Duration.ofMinutes(2))) {
128-
logger.info("Distribution already complete");
129-
return;
127+
if (!this.bintrayService.isDistributionStarted(releaseInfo)) {
128+
startDistribute(sourceRepo, releaseInfo);
130129
}
130+
if (!this.bintrayService.isDistributionComplete(releaseInfo, artifactDigests, Duration.ofMinutes(60))) {
131+
throw new DistributionTimeoutException("Distribution timed out.");
132+
}
133+
}
134+
135+
private void startDistribute(String sourceRepo, ReleaseInfo releaseInfo) {
131136
DistributionRequest request = new DistributionRequest(new String[] { sourceRepo });
132137
RequestEntity<DistributionRequest> requestEntity = RequestEntity
133138
.post(URI.create(DISTRIBUTION_URL + releaseInfo.getBuildName() + "/" + releaseInfo.getBuildNumber()))
134139
.contentType(MediaType.APPLICATION_JSON).body(request);
135140
try {
136141
this.restTemplate.exchange(requestEntity, Object.class);
137-
logger.debug("Distribution call completed");
142+
logger.debug("Distribute call completed");
138143
}
139144
catch (HttpClientErrorException ex) {
140145
logger.info("Failed to distribute.");
141146
throw ex;
142147
}
143-
if (!this.bintrayService.isDistributionComplete(releaseInfo, artifactDigests, Duration.ofMinutes(60))) {
144-
throw new DistributionTimeoutException("Distribution timed out.");
145-
}
146-
147148
}
148149

149150
private PromotionRequest getPromotionRequest(String targetRepo) {

ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.slf4j.LoggerFactory;
3030

3131
import org.springframework.boot.web.client.RestTemplateBuilder;
32+
import org.springframework.http.HttpStatus;
3233
import org.springframework.http.MediaType;
3334
import org.springframework.http.RequestEntity;
3435
import org.springframework.stereotype.Component;
@@ -73,14 +74,30 @@ public BintrayService(RestTemplateBuilder builder, BintrayProperties bintrayProp
7374
this.restTemplate = builder.build();
7475
}
7576

77+
public boolean isDistributionStarted(ReleaseInfo releaseInfo) {
78+
logger.debug("Checking if distribution is started");
79+
RequestEntity<Void> request = getPackageFilesRequest(releaseInfo, 1);
80+
try {
81+
logger.debug("Checking bintray");
82+
this.restTemplate.exchange(request, PackageFile[].class).getBody();
83+
return true;
84+
}
85+
catch (HttpClientErrorException ex) {
86+
if (ex.getStatusCode() != HttpStatus.NOT_FOUND) {
87+
throw ex;
88+
}
89+
return false;
90+
}
91+
}
92+
7693
public boolean isDistributionComplete(ReleaseInfo releaseInfo, Set<String> requiredDigests, Duration timeout) {
7794
return isDistributionComplete(releaseInfo, requiredDigests, timeout, Duration.ofSeconds(20));
7895
}
7996

8097
public boolean isDistributionComplete(ReleaseInfo releaseInfo, Set<String> requiredDigests, Duration timeout,
8198
Duration pollInterval) {
8299
logger.debug("Checking if distribution is complete");
83-
RequestEntity<Void> request = getRequest(releaseInfo, 0);
100+
RequestEntity<Void> request = getPackageFilesRequest(releaseInfo, 0);
84101
try {
85102
waitAtMost(timeout).with().pollDelay(Duration.ZERO).pollInterval(pollInterval).until(() -> {
86103
logger.debug("Checking bintray");
@@ -115,7 +132,7 @@ private boolean hasPublishedAll(PackageFile[] published, Set<String> requiredDig
115132
return false;
116133
}
117134

118-
private RequestEntity<Void> getRequest(ReleaseInfo releaseInfo, int includeUnpublished) {
135+
private RequestEntity<Void> getPackageFilesRequest(ReleaseInfo releaseInfo, int includeUnpublished) {
119136
return RequestEntity.get(URI.create(BINTRAY_URL + "packages/" + this.bintrayProperties.getSubject() + "/"
120137
+ this.bintrayProperties.getRepo() + "/" + releaseInfo.getGroupId() + "/versions/"
121138
+ releaseInfo.getVersion() + "/files?include_unpublished=" + includeUnpublished)).build();

ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryServiceTests.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@
6363
@EnableConfigurationProperties(ArtifactoryProperties.class)
6464
class ArtifactoryServiceTests {
6565

66-
private static final Duration SHORT_TIMEOUT = Duration.ofMinutes(2);
67-
68-
private static final Duration LONG_TIMEOUT = Duration.ofMinutes(60);
66+
private static final Duration TIMEOUT = Duration.ofMinutes(60);
6967

7068
@Autowired
7169
private ArtifactoryService service;
@@ -141,8 +139,8 @@ void promoteWhenPromotionFails() {
141139
@SuppressWarnings("unchecked")
142140
void distributeWhenSuccessful() throws Exception {
143141
ReleaseInfo releaseInfo = getReleaseInfo();
144-
given(this.bintrayService.isDistributionComplete(eq(releaseInfo), (Set<String>) any(), any())).willReturn(false,
145-
true);
142+
given(this.bintrayService.isDistributionStarted(eq(releaseInfo))).willReturn(false);
143+
given(this.bintrayService.isDistributionComplete(eq(releaseInfo), (Set<String>) any(), any())).willReturn(true);
146144
this.server.expect(requestTo("https://repo.spring.io/api/build/distribute/example-build/example-build-1"))
147145
.andExpect(method(HttpMethod.POST))
148146
.andExpect(content().json(
@@ -154,8 +152,7 @@ void distributeWhenSuccessful() throws Exception {
154152
this.service.distribute("libs-release-local", releaseInfo, artifactDigests);
155153
this.server.verify();
156154
InOrder ordered = inOrder(this.bintrayService);
157-
ordered.verify(this.bintrayService).isDistributionComplete(releaseInfo, artifactDigests, SHORT_TIMEOUT);
158-
ordered.verify(this.bintrayService).isDistributionComplete(releaseInfo, artifactDigests, LONG_TIMEOUT);
155+
ordered.verify(this.bintrayService).isDistributionComplete(releaseInfo, artifactDigests, TIMEOUT);
159156
}
160157

161158
@Test
@@ -175,7 +172,7 @@ void distributeWhenFailure() throws Exception {
175172
assertThatExceptionOfType(HttpClientErrorException.class)
176173
.isThrownBy(() -> this.service.distribute("libs-release-local", releaseInfo, artifactDigests));
177174
this.server.verify();
178-
verify(this.bintrayService, times(1)).isDistributionComplete(releaseInfo, artifactDigests, SHORT_TIMEOUT);
175+
verify(this.bintrayService, times(1)).isDistributionStarted(releaseInfo);
179176
verifyNoMoreInteractions(this.bintrayService);
180177
}
181178

@@ -199,8 +196,7 @@ void distributeWhenGettingPackagesTimesOut() throws Exception {
199196
.isThrownBy(() -> this.service.distribute("libs-release-local", releaseInfo, artifactDigests));
200197
this.server.verify();
201198
InOrder ordered = inOrder(this.bintrayService);
202-
ordered.verify(this.bintrayService).isDistributionComplete(releaseInfo, artifactDigests, SHORT_TIMEOUT);
203-
ordered.verify(this.bintrayService).isDistributionComplete(releaseInfo, artifactDigests, LONG_TIMEOUT);
199+
ordered.verify(this.bintrayService).isDistributionComplete(releaseInfo, artifactDigests, TIMEOUT);
204200
}
205201

206202
private ReleaseInfo getReleaseInfo() {

0 commit comments

Comments
 (0)