@Test public void terminateASGContainer () throws Exception { doReturn(true).when(awsEC2Container).isNativeAwsAutoscaling(); doReturn(true).when(awsEC2Container).isMemberOfScaledGroup(); awsEC2Container.terminateASGContainer(experiment); verify(awsEC2Platform, times(1)).terminateInstance(INSTANCE_ID); verify(experiment, times(1)).setCheckContainerHealth(ArgumentMatchers.any()); verify(experiment, times(1)).setSelfHealingMethod(ArgumentMatchers.any()); verify(awsEC2Platform, never()).triggerAutoscalingUnhealthy(INSTANCE_ID); experiment.getSelfHealingMethod().run(); verify(awsEC2Platform, times(1)).triggerAutoscalingUnhealthy(INSTANCE_ID); experiment.getSelfHealingMethod().run(); verify(awsEC2Platform, times(1)).triggerAutoscalingUnhealthy(INSTANCE_ID); doReturn(false).when(awsEC2Platform).isContainerTerminated(INSTANCE_ID); verify(awsEC2Platform, never()).isContainerTerminated(INSTANCE_ID); assertEquals(ContainerHealth.RUNNING_EXPERIMENT, experiment.getCheckContainerHealth().call()); verify(awsEC2Platform, times(1)).isContainerTerminated(INSTANCE_ID); }
@ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) public void terminateASGContainer (Experiment experiment) { if (!isNativeAwsAutoscaling()) { log.debug("Instance {} is not part of an autoscaling group, won't terminate it.", v(DataDogConstants.EC2_INSTANCE, instanceId)); throw new ChaosException(NOT_PART_OF_ASG); } awsEC2Platform.terminateInstance(instanceId); experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(() -> ContainerHealth.RUNNING_EXPERIMENT)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(() -> {})); }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) public void terminateASGContainer (Experiment experiment) { if (!isNativeAwsAutoscaling()) { log.debug("Instance {} is not part of an autoscaling group, won't terminate it.", v(DataDogConstants.EC2_INSTANCE, instanceId)); throw new ChaosException(NOT_PART_OF_ASG); } awsEC2Platform.terminateInstance(instanceId); experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(() -> ContainerHealth.RUNNING_EXPERIMENT)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(() -> {})); } }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) public void terminateASGContainer (Experiment experiment) { if (!isNativeAwsAutoscaling()) { log.debug("Instance {} is not part of an autoscaling group, won't terminate it.", v(DataDogConstants.EC2_INSTANCE, instanceId)); throw new ChaosException(NOT_PART_OF_ASG); } awsEC2Platform.terminateInstance(instanceId); experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(() -> ContainerHealth.RUNNING_EXPERIMENT)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(() -> {})); } private  AwsEC2Container(); }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) public void terminateASGContainer (Experiment experiment) { if (!isNativeAwsAutoscaling()) { log.debug("Instance {} is not part of an autoscaling group, won't terminate it.", v(DataDogConstants.EC2_INSTANCE, instanceId)); throw new ChaosException(NOT_PART_OF_ASG); } awsEC2Platform.terminateInstance(instanceId); experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(() -> ContainerHealth.RUNNING_EXPERIMENT)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(() -> {})); } private  AwsEC2Container(); static AwsEC2ContainerBuilder builder(); String getInstanceId(); String getGroupIdentifier(); String getKeyName(); String getName(); boolean isSSHCapable(); String getImageId(); @Override Platform getPlatform(); @Override boolean eligibleForExperiments(); @Override String getSimpleName(); @Override String getAggregationIdentifier(); @Override DataDogIdentifier getDataDogIdentifier(); @Override boolean isCattle(); @Override boolean supportsShellBasedExperiments(); @ChaosExperiment(experimentType = ExperimentType.STATE) void stopContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE) void restartContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) void terminateASGContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.NETWORK) void removeSecurityGroups(Experiment experiment); String getRoutableAddress(); String getPublicAddress(); }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) public void terminateASGContainer (Experiment experiment) { if (!isNativeAwsAutoscaling()) { log.debug("Instance {} is not part of an autoscaling group, won't terminate it.", v(DataDogConstants.EC2_INSTANCE, instanceId)); throw new ChaosException(NOT_PART_OF_ASG); } awsEC2Platform.terminateInstance(instanceId); experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(() -> ContainerHealth.RUNNING_EXPERIMENT)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(() -> {})); } private  AwsEC2Container(); static AwsEC2ContainerBuilder builder(); String getInstanceId(); String getGroupIdentifier(); String getKeyName(); String getName(); boolean isSSHCapable(); String getImageId(); @Override Platform getPlatform(); @Override boolean eligibleForExperiments(); @Override String getSimpleName(); @Override String getAggregationIdentifier(); @Override DataDogIdentifier getDataDogIdentifier(); @Override boolean isCattle(); @Override boolean supportsShellBasedExperiments(); @ChaosExperiment(experimentType = ExperimentType.STATE) void stopContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE) void restartContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) void terminateASGContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.NETWORK) void removeSecurityGroups(Experiment experiment); String getRoutableAddress(); String getPublicAddress();  }