From c83c7c03c629c507e4dd6b6d8eb4488a7367a1ac Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:18:20 +0000 Subject: [PATCH] fix(cloudfoundry): Update ProcessStats model due to capi-1.84.0 changes (#6283) (#6293) (cherry picked from commit 031bf1d289769f587f446d61e2fad1c3f8d1aca6) Co-authored-by: Christos Arvanitis --- .../client/model/v3/ProcessStats.java | 1 + .../ops/CloudFoundryOperationUtils.java | 2 ++ ...loudFoundryServerGroupAtomicOperation.java | 3 ++- ...FoundryServerGroupAtomicOperationTest.java | 23 +++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/model/v3/ProcessStats.java b/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/model/v3/ProcessStats.java index bb63c23916d..ff0062ca90a 100644 --- a/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/model/v3/ProcessStats.java +++ b/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/model/v3/ProcessStats.java @@ -26,6 +26,7 @@ public enum State { RUNNING, CRASHED, STARTING, + STOPPING, DOWN } } diff --git a/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/CloudFoundryOperationUtils.java b/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/CloudFoundryOperationUtils.java index aa86462bfdc..cefc691ef47 100644 --- a/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/CloudFoundryOperationUtils.java +++ b/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/CloudFoundryOperationUtils.java @@ -25,6 +25,8 @@ static String describeProcessState(ProcessStats.State state) { return "is still starting"; case CRASHED: return "crashed"; + case STOPPING: + return "is in graceful shutdown - stopping"; case RUNNING: case DOWN: default: diff --git a/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperation.java b/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperation.java index 49b46758a7d..db723101feb 100644 --- a/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperation.java +++ b/clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperation.java @@ -51,7 +51,8 @@ public Void operate(List priorOutputs) { () -> client.getApplications().getAppState(description.getServerGroupId()), inProgressState -> inProgressState != ProcessStats.State.STARTING - && inProgressState != ProcessStats.State.RUNNING, + && inProgressState != ProcessStats.State.RUNNING + && inProgressState != ProcessStats.State.STOPPING, null, getTask(), description.getServerGroupName(), diff --git a/clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperationTest.java b/clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperationTest.java index 84f266af6bf..eea3035207c 100644 --- a/clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperationTest.java +++ b/clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperationTest.java @@ -86,4 +86,27 @@ void failedToStop() { .isEqualTo( "Cloud Foundry API returned with error(s): Failed to stop 'myapp' which instead is running"); } + + @Test + void failedToStopStopping() { + OperationPoller poller = mock(OperationPoller.class); + + //noinspection unchecked + when(poller.waitForOperation(any(Supplier.class), any(), any(), any(), any(), any())) + .thenReturn(ProcessStats.State.STOPPING); + + StopCloudFoundryServerGroupAtomicOperation op = + new StopCloudFoundryServerGroupAtomicOperation(poller, desc); + + Task task = runOperation(op); + List resultObjects = task.getResultObjects(); + assertThat(resultObjects.size()).isEqualTo(1); + Object o = resultObjects.get(0); + assertThat(o).isInstanceOf(Map.class); + Object ex = ((Map) o).get("EXCEPTION"); + assertThat(ex).isInstanceOf(CloudFoundryApiException.class); + assertThat(((CloudFoundryApiException) ex).getMessage()) + .isEqualTo( + "Cloud Foundry API returned with error(s): Failed to stop 'myapp' which instead is in graceful shutdown - stopping"); + } }