@Test(expected = ChaosException.class) public void getTimeInStateChaosException () { String applicationId = UUID.randomUUID().toString(); Integer index = new Random().nextInt(100) + 1; CloudFoundryContainer container = CloudFoundryContainer.builder().applicationId(applicationId).instance(index).build(); ApplicationsV2 applicationsV2 = mock(ApplicationsV2.class); doReturn(applicationsV2).when(cloudFoundryClient).applicationsV2(); doReturn(Mono.empty()).when(applicationsV2).instances(ApplicationInstancesRequest.builder().applicationId(applicationId).build()); cloudFoundryContainerPlatform.getTimeInState(container); }
Instant getTimeInState (CloudFoundryContainer container) { log.debug("Looking for time in state of {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); String applicationId = container.getApplicationId(); String instanceIndex = container.getInstance().toString(); final ApplicationInstanceInfo applicationInstanceInfo = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest .builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances() .get(instanceIndex); log.debug("Time in state from Application Instance Info: {}", v("applicationInstanceInfo", applicationInstanceInfo)); Double since = applicationInstanceInfo.getSince(); return since == null ? null : Instant.ofEpochSecond(since.longValue()); }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { Instant getTimeInState (CloudFoundryContainer container) { log.debug("Looking for time in state of {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); String applicationId = container.getApplicationId(); String instanceIndex = container.getInstance().toString(); final ApplicationInstanceInfo applicationInstanceInfo = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest .builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances() .get(instanceIndex); log.debug("Time in state from Application Instance Info: {}", v("applicationInstanceInfo", applicationInstanceInfo)); Double since = applicationInstanceInfo.getSince(); return since == null ? null : Instant.ofEpochSecond(since.longValue()); } }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { Instant getTimeInState (CloudFoundryContainer container) { log.debug("Looking for time in state of {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); String applicationId = container.getApplicationId(); String instanceIndex = container.getInstance().toString(); final ApplicationInstanceInfo applicationInstanceInfo = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest .builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances() .get(instanceIndex); log.debug("Time in state from Application Instance Info: {}", v("applicationInstanceInfo", applicationInstanceInfo)); Double since = applicationInstanceInfo.getSince(); return since == null ? null : Instant.ofEpochSecond(since.longValue()); } @Autowired  CloudFoundryContainerPlatform(); }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { Instant getTimeInState (CloudFoundryContainer container) { log.debug("Looking for time in state of {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); String applicationId = container.getApplicationId(); String instanceIndex = container.getInstance().toString(); final ApplicationInstanceInfo applicationInstanceInfo = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest .builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances() .get(instanceIndex); log.debug("Time in state from Application Instance Info: {}", v("applicationInstanceInfo", applicationInstanceInfo)); Double since = applicationInstanceInfo.getSince(); return since == null ? null : Instant.ofEpochSecond(since.longValue()); } @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> { Instant getTimeInState (CloudFoundryContainer container) { log.debug("Looking for time in state of {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); String applicationId = container.getApplicationId(); String instanceIndex = container.getInstance().toString(); final ApplicationInstanceInfo applicationInstanceInfo = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest .builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances() .get(instanceIndex); log.debug("Time in state from Application Instance Info: {}", v("applicationInstanceInfo", applicationInstanceInfo)); Double since = applicationInstanceInfo.getSince(); return since == null ? null : Instant.ofEpochSecond(since.longValue()); } @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);  }