Skip to content

Commit 974a057

Browse files
Abel Salgado Romeroabelsromero
authored andcommitted
Apply fixes from 1.2.x
1 parent d579d44 commit 974a057

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import org.cloudfoundry.client.v3.deployments.CreateDeploymentResponse;
6565
import org.cloudfoundry.client.v3.deployments.DeploymentRelationships;
6666
import org.cloudfoundry.client.v3.deployments.DeploymentState;
67+
import org.cloudfoundry.client.v3.deployments.DeploymentStatusReason;
68+
import org.cloudfoundry.client.v3.deployments.DeploymentStatusValue;
6769
import org.cloudfoundry.client.v3.deployments.GetDeploymentRequest;
6870
import org.cloudfoundry.client.v3.deployments.GetDeploymentResponse;
6971
import org.cloudfoundry.client.v3.packages.CreatePackageRequest;
@@ -424,15 +426,14 @@ private String getDefaultDomainId(List<Domain> domains) {
424426
.getId();
425427
}
426428

427-
@SuppressWarnings("deprecation")
428429
private Mono<GetDeploymentResponse> waitForDeploymentDeployed(String deploymentId) {
429430
return this.client
430431
.deploymentsV3()
431432
.get(GetDeploymentRequest
432433
.builder()
433434
.deploymentId(deploymentId)
434435
.build())
435-
.filter(p -> p.getState().equals(DeploymentState.DEPLOYED))
436+
.filter(this::deploymentFinished)
436437
.repeatWhenEmpty(getExponentialBackOff())
437438
.doOnRequest(l -> LOG.debug("Waiting for deployment to complete. deploymentId={}", deploymentId))
438439
.doOnSuccess(response -> {
@@ -443,6 +444,16 @@ private Mono<GetDeploymentResponse> waitForDeploymentDeployed(String deploymentI
443444
ERROR_LOG_TEMPLATE, deploymentId, e.getMessage()), e));
444445
}
445446

447+
@SuppressWarnings("deprecation")
448+
private boolean deploymentFinished(GetDeploymentResponse p) {
449+
if (p.getState() != null) {
450+
return p.getState().equals(DeploymentState.DEPLOYED);
451+
}
452+
453+
return p.getStatus().getValue().equals(DeploymentStatusValue.FINALIZED)
454+
&& p.getStatus().getReason().equals(DeploymentStatusReason.DEPLOYED);
455+
}
456+
446457
private Mono<CreateDeploymentResponse> createDeployment(String dropletId, String applicationId) {
447458
return this.client
448459
.deploymentsV3()

spring-cloud-app-broker-deployer-cloudfoundry/src/test/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployerUpdateApplicationTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import org.cloudfoundry.client.v3.builds.GetBuildResponse;
4949
import org.cloudfoundry.client.v3.deployments.CreateDeploymentResponse;
5050
import org.cloudfoundry.client.v3.deployments.DeploymentState;
51+
import org.cloudfoundry.client.v3.deployments.DeploymentStatusReason;
52+
import org.cloudfoundry.client.v3.deployments.DeploymentStatusValue;
5153
import org.cloudfoundry.client.v3.deployments.DeploymentsV3;
5254
import org.cloudfoundry.client.v3.deployments.GetDeploymentResponse;
5355
import org.cloudfoundry.client.v3.packages.BitsData;
@@ -252,6 +254,8 @@ void setUp() {
252254
given(deploymentsV3.get(any()))
253255
.willReturn(Mono.just(GetDeploymentResponse.builder()
254256
.state(DeploymentState.DEPLOYED)
257+
.status(org.cloudfoundry.client.v3.deployments.Status.builder().value(DeploymentStatusValue.FINALIZED).reason(
258+
DeploymentStatusReason.DEPLOYED).build())
255259
.createdAt("DATETIME")
256260
.id("deployment-id")
257261
.build()));
@@ -273,6 +277,30 @@ void updateApp() {
273277
.verifyComplete();
274278
}
275279

280+
@Test
281+
void updateAppWhenDeploymentObjectHasNotState() {
282+
given(deploymentsV3.get(any()))
283+
.willReturn(Mono.just(GetDeploymentResponse.builder()
284+
.status(org.cloudfoundry.client.v3.deployments.Status.builder().value(DeploymentStatusValue.FINALIZED).reason(
285+
DeploymentStatusReason.DEPLOYED).build())
286+
.createdAt("DATETIME")
287+
.id("deployment-id")
288+
.build()));
289+
290+
given(applicationsV2.update(any()))
291+
.willReturn(Mono.just(UpdateApplicationResponse.builder()
292+
.build()));
293+
294+
UpdateApplicationRequest request = UpdateApplicationRequest.builder()
295+
.name(APP_NAME)
296+
.path(APP_PATH)
297+
.build();
298+
299+
StepVerifier.create(appDeployer.update(request))
300+
.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
301+
.verifyComplete();
302+
}
303+
276304
@Test
277305
void updateAppWithTarget() {
278306
given(applicationsV2.update(any()))

spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/util/ByteSizeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static Integer parseToMebibytes(String text) {
4949
" Expected a number with optional 'm' or 'g' suffix", text));
5050
}
5151
int size = Integer.parseInt(matcher.group("amount"));
52-
if (matcher.group("unit").equalsIgnoreCase("g")) {
52+
if ("g".equalsIgnoreCase(matcher.group("unit"))) {
5353
size *= 1024L;
5454
}
5555
return size;

spring-cloud-app-broker-integration-tests/src/test/resources/responses/cloudcontroller/get-deployment-DEPLOYED.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"guid": "@guid",
33
"state": "DEPLOYED",
4+
"status": {
5+
"value": "FINALIZED",
6+
"reason": "DEPLOYED",
7+
"details": {
8+
"last_successful_healthcheck": "2018-04-25T22:42:10Z"
9+
}
10+
},
411
"droplet": {
512
"guid": "44ccfa61-dbcf-4a0d-82fe-f668e9d2a962"
613
},
@@ -34,4 +41,4 @@
3441
"href": "https://api.example.org/v3/apps/@app-guid"
3542
}
3643
}
37-
}
44+
}

0 commit comments

Comments
 (0)