@Test public void checkHealthDoesNotExist () { Integer INSTANCE_ID = 0; ApplicationsV2 applicationsV2 = mock(ApplicationsV2.class); ApplicationInstancesResponse applicationInstancesResponse = ApplicationInstancesResponse.builder().build(); Mono<ApplicationInstancesResponse> applicationInstancesResponseMono = Mono.just(applicationInstancesResponse); doReturn(applicationsV2).when(cloudFoundryClient).applicationsV2(); doReturn(applicationInstancesResponseMono).when(applicationsV2).instances(any(ApplicationInstancesRequest.class)); assertEquals(ContainerHealth.DOES_NOT_EXIST, cloudFoundryContainerPlatform.checkHealth(APPLICATION_ID, INSTANCE_ID)); }
public ContainerHealth checkHealth (String applicationId, Integer instanceId) { Map<String, ApplicationInstanceInfo> applicationInstanceResponse; try { applicationInstanceResponse = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest.builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances(); } catch (ClientV2Exception e) { if (CloudFoundryIgnoredClientExceptions.isIgnorable(e)) { log.warn("Platform returned ignorable exception: {} ", e.getMessage(), e); return ContainerHealth.RUNNING_EXPERIMENT; } log.error("Cannot get application instances: {}", e.getMessage(), e); return ContainerHealth.DOES_NOT_EXIST; } String status; try { status = applicationInstanceResponse.get(instanceId.toString()).getState(); } catch (NullPointerException e) { return ContainerHealth.DOES_NOT_EXIST; } return (status.equals(CloudFoundryConstants.CLOUDFOUNDRY_RUNNING_STATE) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT); }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { public ContainerHealth checkHealth (String applicationId, Integer instanceId) { Map<String, ApplicationInstanceInfo> applicationInstanceResponse; try { applicationInstanceResponse = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest.builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances(); } catch (ClientV2Exception e) { if (CloudFoundryIgnoredClientExceptions.isIgnorable(e)) { log.warn("Platform returned ignorable exception: {} ", e.getMessage(), e); return ContainerHealth.RUNNING_EXPERIMENT; } log.error("Cannot get application instances: {}", e.getMessage(), e); return ContainerHealth.DOES_NOT_EXIST; } String status; try { status = applicationInstanceResponse.get(instanceId.toString()).getState(); } catch (NullPointerException e) { return ContainerHealth.DOES_NOT_EXIST; } return (status.equals(CloudFoundryConstants.CLOUDFOUNDRY_RUNNING_STATE) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT); } }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { public ContainerHealth checkHealth (String applicationId, Integer instanceId) { Map<String, ApplicationInstanceInfo> applicationInstanceResponse; try { applicationInstanceResponse = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest.builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances(); } catch (ClientV2Exception e) { if (CloudFoundryIgnoredClientExceptions.isIgnorable(e)) { log.warn("Platform returned ignorable exception: {} ", e.getMessage(), e); return ContainerHealth.RUNNING_EXPERIMENT; } log.error("Cannot get application instances: {}", e.getMessage(), e); return ContainerHealth.DOES_NOT_EXIST; } String status; try { status = applicationInstanceResponse.get(instanceId.toString()).getState(); } catch (NullPointerException e) { return ContainerHealth.DOES_NOT_EXIST; } return (status.equals(CloudFoundryConstants.CLOUDFOUNDRY_RUNNING_STATE) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT); } @Autowired  CloudFoundryContainerPlatform(); }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { public ContainerHealth checkHealth (String applicationId, Integer instanceId) { Map<String, ApplicationInstanceInfo> applicationInstanceResponse; try { applicationInstanceResponse = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest.builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances(); } catch (ClientV2Exception e) { if (CloudFoundryIgnoredClientExceptions.isIgnorable(e)) { log.warn("Platform returned ignorable exception: {} ", e.getMessage(), e); return ContainerHealth.RUNNING_EXPERIMENT; } log.error("Cannot get application instances: {}", e.getMessage(), e); return ContainerHealth.DOES_NOT_EXIST; } String status; try { status = applicationInstanceResponse.get(instanceId.toString()).getState(); } catch (NullPointerException e) { return ContainerHealth.DOES_NOT_EXIST; } return (status.equals(CloudFoundryConstants.CLOUDFOUNDRY_RUNNING_STATE) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT); } @Autowired  CloudFoundryContainerPlatform(); @Override boolean isContainerRecycled(Container container); ContainerHealth checkHealth(String applicationId, Integer instanceId); @Override List<Container> generateRoster(); void restartInstance(RestartApplicationInstanceRequest restartApplicationInstanceRequest); @Override String getEndpoint(CloudFoundryContainer container); @Override SSHCredentials getSshCredentials(CloudFoundryContainer container); @Override void recycleContainer(CloudFoundryContainer container); }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { public ContainerHealth checkHealth (String applicationId, Integer instanceId) { Map<String, ApplicationInstanceInfo> applicationInstanceResponse; try { applicationInstanceResponse = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest.builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances(); } catch (ClientV2Exception e) { if (CloudFoundryIgnoredClientExceptions.isIgnorable(e)) { log.warn("Platform returned ignorable exception: {} ", e.getMessage(), e); return ContainerHealth.RUNNING_EXPERIMENT; } log.error("Cannot get application instances: {}", e.getMessage(), e); return ContainerHealth.DOES_NOT_EXIST; } String status; try { status = applicationInstanceResponse.get(instanceId.toString()).getState(); } catch (NullPointerException e) { return ContainerHealth.DOES_NOT_EXIST; } return (status.equals(CloudFoundryConstants.CLOUDFOUNDRY_RUNNING_STATE) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT); } @Autowired  CloudFoundryContainerPlatform(); @Override boolean isContainerRecycled(Container container); ContainerHealth checkHealth(String applicationId, Integer instanceId); @Override List<Container> generateRoster(); void restartInstance(RestartApplicationInstanceRequest restartApplicationInstanceRequest); @Override String getEndpoint(CloudFoundryContainer container); @Override SSHCredentials getSshCredentials(CloudFoundryContainer container); @Override void recycleContainer(CloudFoundryContainer container);  }