From c329221fa9893183fce11f07006d2cbc9bbd8582 Mon Sep 17 00:00:00 2001 From: David O'Sullivan Date: Tue, 22 Feb 2022 17:02:36 +0000 Subject: [PATCH] Bumps Supported API version, handles removal of Deployment 'state' in 2_11+ --- .../client/CloudFoundryClient.java | 2 +- .../org/cloudfoundry/CloudFoundryVersion.java | 2 ++ .../client/v3/DeploymentsTest.java | 35 +++++++++++++++---- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java index c046e2e5f4..860c720fd2 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java @@ -79,7 +79,7 @@ public interface CloudFoundryClient { /** * The currently supported Cloud Controller API version */ - String SUPPORTED_API_VERSION = "2.150.0"; + String SUPPORTED_API_VERSION = "2.171.0"; /** * Main entry point to the Cloud Foundry Application Usage Events Client API diff --git a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java index 9eea44a58a..d1d54fa8c1 100644 --- a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java +++ b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java @@ -52,6 +52,8 @@ public enum CloudFoundryVersion { PCF_2_11(Version.forIntegers(2, 164, 0)), + PCF_2_12(Version.forIntegers(2, 171, 0)), + UNSPECIFIED(Version.forIntegers(0)); private final Version version; diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java index b93ec69132..ce82f8e958 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java @@ -28,6 +28,7 @@ import org.cloudfoundry.client.v3.deployments.DeploymentRelationships; import org.cloudfoundry.client.v3.deployments.DeploymentResource; import org.cloudfoundry.client.v3.deployments.DeploymentState; +import org.cloudfoundry.client.v3.deployments.DeploymentStatusReason; import org.cloudfoundry.client.v3.deployments.DeploymentStatusValue; import org.cloudfoundry.client.v3.deployments.GetDeploymentRequest; import org.cloudfoundry.client.v3.deployments.ListDeploymentsRequest; @@ -60,8 +61,35 @@ public final class DeploymentsTest extends AbstractIntegrationTest { @Autowired private CloudFoundryOperations cloudFoundryOperations; + @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_11) + public void cancel_2_11() throws Exception { + String name = this.nameFactory.getApplicationName(); + Path path = new ClassPathResource("test-application.zip").getFile().toPath(); + + createApplicationId(this.cloudFoundryOperations, name, path) + .flatMap(applicationId -> Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId) + )) + .flatMap(function((applicationId, dropletId) -> Mono.zip( + Mono.just(applicationId), + createDeploymentId(this.cloudFoundryClient, applicationId, dropletId) + ))) + .flatMap(function((applicationId, deploymentId) -> this.cloudFoundryClient.deploymentsV3() + .cancel(CancelDeploymentRequest.builder() + .deploymentId(deploymentId) + .build()) + .then(Mono.just(applicationId)))) + .flatMapMany(applicationId -> requestListDeployments(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .consumeNextWith(deploymentResource -> assertThat(deploymentResource.getStatus().getReason()).isIn(DeploymentStatusReason.CANCELED, DeploymentStatusReason.CANCELING)) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + @SuppressWarnings("deprecation") @Test + @IfCloudFoundryVersion(lessThanOrEqualTo = CloudFoundryVersion.PCF_2_10) public void cancel() throws Exception { String name = this.nameFactory.getApplicationName(); Path path = new ClassPathResource("test-application.zip").getFile().toPath(); @@ -81,9 +109,8 @@ public void cancel() throws Exception { .build()) .then(Mono.just(applicationId)))) .flatMapMany(applicationId -> requestListDeployments(this.cloudFoundryClient, applicationId)) - .map(DeploymentResource::getState) .as(StepVerifier::create) - .consumeNextWith(isCancel()) + .consumeNextWith(deploymentResource -> assertThat(deploymentResource.getState()).isIn(DeploymentState.CANCELING, DeploymentState.CANCELED)) .expectComplete() .verify(Duration.ofMinutes(5)); } @@ -255,10 +282,6 @@ private static Mono getDropletId(CloudFoundryClient cloudFoundryClient, .map(GetApplicationCurrentDropletResponse::getId); } - private static Consumer isCancel() { - return state -> assertThat(state).isIn(DeploymentState.CANCELING, DeploymentState.CANCELED); - } - private static Mono requestCreateApplication(CloudFoundryOperations cloudFoundryOperations, String name, Path path) { return cloudFoundryOperations.applications() .push(PushApplicationRequest.builder()