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 3dc3eaa4803..f28d023871d 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"); + } }