@Test @SuppressWarnings("unchecked") public void checkHealth () { List<Instance> instanceList = Collections.singletonList(instance); List<Reservation> reservationList = Collections.singletonList(reservation); when(amazonEC2.describeInstances(any(DescribeInstancesRequest.class))).thenReturn(describeInstancesResult); when(describeInstancesResult.getReservations()).thenReturn(reservationList); when(reservation.getInstances()).thenReturn(instanceList); when(instance.getState()).thenReturn(new InstanceState().withCode(16)); assertEquals(ContainerHealth.NORMAL, awsEC2Platform.checkHealth(null)); when(amazonEC2.describeInstances(any(DescribeInstancesRequest.class))).thenReturn(describeInstancesResult); when(describeInstancesResult.getReservations()).thenReturn(reservationList); when(reservation.getInstances()).thenReturn(instanceList); when(instance.getState()).thenReturn(new InstanceState().withCode(0)); assertEquals(ContainerHealth.RUNNING_EXPERIMENT, awsEC2Platform.checkHealth(null)); when(amazonEC2.describeInstances(any(DescribeInstancesRequest.class))).thenReturn(describeInstancesResult); when(describeInstancesResult.getReservations()).thenReturn(Collections.EMPTY_LIST); assertEquals(ContainerHealth.DOES_NOT_EXIST, awsEC2Platform.checkHealth(null)); }
public ContainerHealth checkHealth (String instanceId) { Instance instance; InstanceState state; DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult result = amazonEC2.describeInstances(request); try { instance = result.getReservations().get(0).getInstances().get(0); state = instance.getState(); if (state.getCode() == 48) { log.info("Instance {} is terminated", v(DataDogConstants.EC2_INSTANCE, instance)); return ContainerHealth.DOES_NOT_EXIST; } } catch (IndexOutOfBoundsException | NullPointerException e) { log.error("Instance {} doesn't seem to exist anymore", instanceId, e); return ContainerHealth.DOES_NOT_EXIST; } return state.getCode() == AwsEC2Constants.AWS_RUNNING_CODE ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { public ContainerHealth checkHealth (String instanceId) { Instance instance; InstanceState state; DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult result = amazonEC2.describeInstances(request); try { instance = result.getReservations().get(0).getInstances().get(0); state = instance.getState(); if (state.getCode() == 48) { log.info("Instance {} is terminated", v(DataDogConstants.EC2_INSTANCE, instance)); return ContainerHealth.DOES_NOT_EXIST; } } catch (IndexOutOfBoundsException | NullPointerException e) { log.error("Instance {} doesn't seem to exist anymore", instanceId, e); return ContainerHealth.DOES_NOT_EXIST; } return state.getCode() == AwsEC2Constants.AWS_RUNNING_CODE ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; } }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { public ContainerHealth checkHealth (String instanceId) { Instance instance; InstanceState state; DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult result = amazonEC2.describeInstances(request); try { instance = result.getReservations().get(0).getInstances().get(0); state = instance.getState(); if (state.getCode() == 48) { log.info("Instance {} is terminated", v(DataDogConstants.EC2_INSTANCE, instance)); return ContainerHealth.DOES_NOT_EXIST; } } catch (IndexOutOfBoundsException | NullPointerException e) { log.error("Instance {} doesn't seem to exist anymore", instanceId, e); return ContainerHealth.DOES_NOT_EXIST; } return state.getCode() == AwsEC2Constants.AWS_RUNNING_CODE ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; } @Autowired  AwsEC2Platform(AmazonEC2 amazonEC2, ContainerManager containerManager, AwsEC2SelfAwareness awsEC2SelfAwareness); private  AwsEC2Platform(); }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { public ContainerHealth checkHealth (String instanceId) { Instance instance; InstanceState state; DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult result = amazonEC2.describeInstances(request); try { instance = result.getReservations().get(0).getInstances().get(0); state = instance.getState(); if (state.getCode() == 48) { log.info("Instance {} is terminated", v(DataDogConstants.EC2_INSTANCE, instance)); return ContainerHealth.DOES_NOT_EXIST; } } catch (IndexOutOfBoundsException | NullPointerException e) { log.error("Instance {} doesn't seem to exist anymore", instanceId, e); return ContainerHealth.DOES_NOT_EXIST; } return state.getCode() == AwsEC2Constants.AWS_RUNNING_CODE ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; } @Autowired  AwsEC2Platform(AmazonEC2 amazonEC2, ContainerManager containerManager, AwsEC2SelfAwareness awsEC2SelfAwareness); private  AwsEC2Platform(); void setFilter(@NotNull Map<String, List<String>> filter); void setGroupingTags(List<String> groupingTags); void setSSHPrivateKeys(@NotNull Map<String, String> sshPrivateKeys); Map<String, String> getImageIdToUsernameMap(); void setImageIdToUsernameMap(Map<String, String> imageIdToUsernameMap); @Override ApiStatus getApiStatus(); @JsonIgnore Collection<SubnetUtils.SubnetInfo> getRoutableCidrBlocks(); void setRoutableCidrBlocks(Collection<String> routableCidrBlocks); boolean isAddressRoutable(String privateIPAddress); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override List<Container> generateRoster(); @Override boolean isContainerRecycled(Container container); ContainerHealth checkHealth(String instanceId); void stopInstance(String... instanceIds); void terminateInstance(String... instanceIds); void startInstance(String... instanceIds); void restartInstance(String... instanceIds); void setSecurityGroupIds(String networkInterfaceId, Collection<String> securityGroupIds); String getChaosSecurityGroupForInstance(String instanceId); boolean isContainerTerminated(String instanceId); boolean isAutoscalingGroupAtDesiredInstances(String autoScalingGroupName); boolean hasKey(String keyName); @Override void recycleContainer(AwsEC2Container container); void triggerAutoscalingUnhealthy(String instanceId); @Override String getEndpoint(AwsEC2Container container); @Override SSHCredentials getSshCredentials(AwsEC2Container container); boolean isStarted(AwsEC2Container awsEC2Container); Map<String, Set<String>> getNetworkInterfaceToSecurityGroupsMap(String instanceId); boolean verifySecurityGroupIdsOfNetworkInterfaceMap(String instanceId, Map<String, Set<String>> originalSecurityGroups); }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { public ContainerHealth checkHealth (String instanceId) { Instance instance; InstanceState state; DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult result = amazonEC2.describeInstances(request); try { instance = result.getReservations().get(0).getInstances().get(0); state = instance.getState(); if (state.getCode() == 48) { log.info("Instance {} is terminated", v(DataDogConstants.EC2_INSTANCE, instance)); return ContainerHealth.DOES_NOT_EXIST; } } catch (IndexOutOfBoundsException | NullPointerException e) { log.error("Instance {} doesn't seem to exist anymore", instanceId, e); return ContainerHealth.DOES_NOT_EXIST; } return state.getCode() == AwsEC2Constants.AWS_RUNNING_CODE ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; } @Autowired  AwsEC2Platform(AmazonEC2 amazonEC2, ContainerManager containerManager, AwsEC2SelfAwareness awsEC2SelfAwareness); private  AwsEC2Platform(); void setFilter(@NotNull Map<String, List<String>> filter); void setGroupingTags(List<String> groupingTags); void setSSHPrivateKeys(@NotNull Map<String, String> sshPrivateKeys); Map<String, String> getImageIdToUsernameMap(); void setImageIdToUsernameMap(Map<String, String> imageIdToUsernameMap); @Override ApiStatus getApiStatus(); @JsonIgnore Collection<SubnetUtils.SubnetInfo> getRoutableCidrBlocks(); void setRoutableCidrBlocks(Collection<String> routableCidrBlocks); boolean isAddressRoutable(String privateIPAddress); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override List<Container> generateRoster(); @Override boolean isContainerRecycled(Container container); ContainerHealth checkHealth(String instanceId); void stopInstance(String... instanceIds); void terminateInstance(String... instanceIds); void startInstance(String... instanceIds); void restartInstance(String... instanceIds); void setSecurityGroupIds(String networkInterfaceId, Collection<String> securityGroupIds); String getChaosSecurityGroupForInstance(String instanceId); boolean isContainerTerminated(String instanceId); boolean isAutoscalingGroupAtDesiredInstances(String autoScalingGroupName); boolean hasKey(String keyName); @Override void recycleContainer(AwsEC2Container container); void triggerAutoscalingUnhealthy(String instanceId); @Override String getEndpoint(AwsEC2Container container); @Override SSHCredentials getSshCredentials(AwsEC2Container container); boolean isStarted(AwsEC2Container awsEC2Container); Map<String, Set<String>> getNetworkInterfaceToSecurityGroupsMap(String instanceId); boolean verifySecurityGroupIdsOfNetworkInterfaceMap(String instanceId, Map<String, Set<String>> originalSecurityGroups);  }