@Test public void isContainerRecycled () { CloudFoundryContainer container = mock(CloudFoundryContainer.class); String applicationId = UUID.randomUUID().toString(); Integer index = new Random().nextInt(100) + 1; doReturn(applicationId).when(container).getApplicationId(); doReturn(index).when(container).getInstance(); Map<ContainerHealth, Boolean> containerHealthMap; containerHealthMap = new HashMap<>(); containerHealthMap.put(ContainerHealth.NORMAL, Boolean.TRUE); containerHealthMap.put(ContainerHealth.RUNNING_EXPERIMENT, Boolean.FALSE); containerHealthMap.put(ContainerHealth.DOES_NOT_EXIST, Boolean.FALSE); for (Map.Entry<ContainerHealth, Boolean> entry : containerHealthMap.entrySet()) { doReturn(entry.getKey()).when(cloudFoundryContainerPlatform).checkHealth(applicationId, index); doReturn(Instant.ofEpochMilli(1552569958455L)).when(cloudFoundryContainerPlatform).getTimeInState(container); doReturn(Instant.ofEpochMilli(1552569958454L), Instant.ofEpochMilli(1552569958456L)).when(container).getExperimentStartTime(); assertEquals(entry.getValue(), cloudFoundryContainerPlatform.isContainerRecycled(container)); assertFalse(cloudFoundryContainerPlatform.isContainerRecycled(container)); } }
@Override public boolean isContainerRecycled (Container container) { log.debug("Recycling container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); if (!(container instanceof CloudFoundryContainer)) { log.warn("Was passed another Platform's container"); return false; } CloudFoundryContainer cloudFoundryContainer = (CloudFoundryContainer) container; Instant timeInState = getTimeInState(cloudFoundryContainer); ContainerHealth containerHealth = checkHealth(cloudFoundryContainer.getApplicationId(), cloudFoundryContainer.getInstance()); Instant experimentStartTime = cloudFoundryContainer.getExperimentStartTime(); boolean isContainerRecycled = timeInState != null && timeInState.isAfter(experimentStartTime) && ContainerHealth.NORMAL .equals(containerHealth); log.debug("Evaluating if the container is recycled. {} {} {}", kv("Container Health", containerHealth), kv("Container Start Time", timeInState), kv("Experiment Start Time", experimentStartTime)); return isContainerRecycled; }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { @Override public boolean isContainerRecycled (Container container) { log.debug("Recycling container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); if (!(container instanceof CloudFoundryContainer)) { log.warn("Was passed another Platform's container"); return false; } CloudFoundryContainer cloudFoundryContainer = (CloudFoundryContainer) container; Instant timeInState = getTimeInState(cloudFoundryContainer); ContainerHealth containerHealth = checkHealth(cloudFoundryContainer.getApplicationId(), cloudFoundryContainer.getInstance()); Instant experimentStartTime = cloudFoundryContainer.getExperimentStartTime(); boolean isContainerRecycled = timeInState != null && timeInState.isAfter(experimentStartTime) && ContainerHealth.NORMAL .equals(containerHealth); log.debug("Evaluating if the container is recycled. {} {} {}", kv("Container Health", containerHealth), kv("Container Start Time", timeInState), kv("Experiment Start Time", experimentStartTime)); return isContainerRecycled; } }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { @Override public boolean isContainerRecycled (Container container) { log.debug("Recycling container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); if (!(container instanceof CloudFoundryContainer)) { log.warn("Was passed another Platform's container"); return false; } CloudFoundryContainer cloudFoundryContainer = (CloudFoundryContainer) container; Instant timeInState = getTimeInState(cloudFoundryContainer); ContainerHealth containerHealth = checkHealth(cloudFoundryContainer.getApplicationId(), cloudFoundryContainer.getInstance()); Instant experimentStartTime = cloudFoundryContainer.getExperimentStartTime(); boolean isContainerRecycled = timeInState != null && timeInState.isAfter(experimentStartTime) && ContainerHealth.NORMAL .equals(containerHealth); log.debug("Evaluating if the container is recycled. {} {} {}", kv("Container Health", containerHealth), kv("Container Start Time", timeInState), kv("Experiment Start Time", experimentStartTime)); return isContainerRecycled; } @Autowired  CloudFoundryContainerPlatform(); }
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { @Override public boolean isContainerRecycled (Container container) { log.debug("Recycling container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); if (!(container instanceof CloudFoundryContainer)) { log.warn("Was passed another Platform's container"); return false; } CloudFoundryContainer cloudFoundryContainer = (CloudFoundryContainer) container; Instant timeInState = getTimeInState(cloudFoundryContainer); ContainerHealth containerHealth = checkHealth(cloudFoundryContainer.getApplicationId(), cloudFoundryContainer.getInstance()); Instant experimentStartTime = cloudFoundryContainer.getExperimentStartTime(); boolean isContainerRecycled = timeInState != null && timeInState.isAfter(experimentStartTime) && ContainerHealth.NORMAL .equals(containerHealth); log.debug("Evaluating if the container is recycled. {} {} {}", kv("Container Health", containerHealth), kv("Container Start Time", timeInState), kv("Experiment Start Time", experimentStartTime)); return isContainerRecycled; } @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> { @Override public boolean isContainerRecycled (Container container) { log.debug("Recycling container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); if (!(container instanceof CloudFoundryContainer)) { log.warn("Was passed another Platform's container"); return false; } CloudFoundryContainer cloudFoundryContainer = (CloudFoundryContainer) container; Instant timeInState = getTimeInState(cloudFoundryContainer); ContainerHealth containerHealth = checkHealth(cloudFoundryContainer.getApplicationId(), cloudFoundryContainer.getInstance()); Instant experimentStartTime = cloudFoundryContainer.getExperimentStartTime(); boolean isContainerRecycled = timeInState != null && timeInState.isAfter(experimentStartTime) && ContainerHealth.NORMAL .equals(containerHealth); log.debug("Evaluating if the container is recycled. {} {} {}", kv("Container Health", containerHealth), kv("Container Start Time", timeInState), kv("Experiment Start Time", experimentStartTime)); return isContainerRecycled; } @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);  }