fix(provider/cf): set the status to DOWN when no process stats returned
MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/Applications.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/Applications.java
@@ -363,6 +363,6 @@ public class Applications {
public ProcessStats.State getProcessState(String appGuid) throws CloudFoundryApiException {
return safelyCall(() -> this.api.findProcessStatsById(appGuid))
.flatMap(pr -> pr.getResources().stream().findAny().map(ProcessStats::getState))
- .orElse(null);
+ .orElse(ProcessStats.State.DOWN);
}
}

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/ApplicationsTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/ApplicationsTest.java
@@ -28,6 +28,9 @@ import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundryServerGr
import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundrySpace;
import io.vavr.collection.HashMap;
import org.junit.jupiter.api.Test;
+import retrofit.RetrofitError;
+import retrofit.client.Response;
+import retrofit.mime.TypedInput;
import java.time.ZonedDateTime;
import java.util.Arrays;
@@ -148,4 +151,20 @@ class ApplicationsTest {
verify(applicationService).updateProcess("guid1", new UpdateProcess("command1", null));
}
+ @Test
+ void getProcessState(){
+ ProcessStats processStats = new ProcessStats().setState(ProcessStats.State.RUNNING);
+ ProcessResources processResources = new ProcessResources().setResources(Collections.singletonList(processStats));
+ when(applicationService.findProcessStatsById(anyString())).thenReturn(processResources);
+ ProcessStats.State result = apps.getProcessState("some-app-guid");
+ assertThat(result).isEqualTo(ProcessStats.State.RUNNING);
+ }
+
+ @Test
+ void getProcessStateWhenStatsNotFound(){
+ Response errorResponse = new Response("http://capi.io", 404,"Not Found", Collections.EMPTY_LIST, null);
+ when(applicationService.findProcessStatsById(anyString())).thenThrow(RetrofitError.httpError("http://capi.io", errorResponse, null, null));
+ ProcessStats.State result = apps.getProcessState("some-app-guid");
+ assertThat(result).isEqualTo(ProcessStats.State.DOWN);
+ }
}

fix(provider/cf): set the status to DOWN when no process stats returned (#3186)