Skip to content

Commit a75c55b

Browse files
committed
Use status field to check deployment status instead of state
State field was deprecated in CAPI and starting from CFJC 5.3 marked as nullable, since it won't be sent by CAPI versions 3.91+. App Broker should use status field instead.
1 parent 02696c4 commit a75c55b

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ onlyShowStandardStreamsOnTestFailure = false
55

66
awaitilityVersion = 4.0.2
77
blockHoundVersion = 1.0.4.RELEASE
8-
cfJavaClientVersion = 5.1.0.RELEASE
8+
cfJavaClientVersion = 5.3.0.RELEASE
99
checkstyleVersion = 8.37
1010
commonsTextVersion = 1.8
1111
immutablesVersion = 2.8.8

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;
@@ -441,15 +443,14 @@ private String getDefaultDomainId(List<Domain> domains) {
441443
.getId();
442444
}
443445

444-
@SuppressWarnings("deprecation")
445446
private Mono<GetDeploymentResponse> waitForDeploymentDeployed(String deploymentId) {
446447
return this.client
447448
.deploymentsV3()
448449
.get(GetDeploymentRequest
449450
.builder()
450451
.deploymentId(deploymentId)
451452
.build())
452-
.filter(p -> p.getState().equals(DeploymentState.DEPLOYED))
453+
.filter(this::deploymentFinished)
453454
.repeatWhenEmpty(getExponentialBackOff())
454455
.doOnRequest(l -> LOG.debug("Waiting for deployment to complete. deploymentId={}", deploymentId))
455456
.doOnSuccess(response -> {
@@ -460,6 +461,16 @@ private Mono<GetDeploymentResponse> waitForDeploymentDeployed(String deploymentI
460461
ERROR_LOG_TEMPLATE, deploymentId, e.getMessage()), e));
461462
}
462463

464+
@SuppressWarnings("deprecation")
465+
private boolean deploymentFinished(GetDeploymentResponse p) {
466+
if (p.getState() != null) {
467+
return p.getState().equals(DeploymentState.DEPLOYED);
468+
}
469+
470+
return p.getStatus().getValue().equals(DeploymentStatusValue.FINALIZED)
471+
&& p.getStatus().getReason().equals(DeploymentStatusReason.DEPLOYED);
472+
}
473+
463474
private Mono<CreateDeploymentResponse> createDeployment(String dropletId, String applicationId) {
464475
return this.client
465476
.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-integration-tests/src/test/resources/responses/cloudcontroller/get-deployment-DEPLOYED.json

Lines changed: 7 additions & 0 deletions
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
},

0 commit comments

Comments
 (0)