@Test public void isAutoscalingGroupAtDesiredInstances () { String groupId = randomUUID().toString(); final int DESIRED_CAPACITY = new Random().nextInt(10) + 5; List<com.amazonaws.services.autoscaling.model.Instance> instances = IntStream.range(0, DESIRED_CAPACITY) .mapToObj(i -> new com.amazonaws.services.autoscaling.model.Instance() .withHealthStatus("Healthy")) .collect(Collectors.toList()); AutoScalingGroup autoScalingGroup = new AutoScalingGroup().withInstances(instances).withDesiredCapacity(DESIRED_CAPACITY); DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(Collections .singletonList(autoScalingGroup)); doReturn(describeAutoScalingGroupsResult).when(amazonAutoScaling).describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(groupId)); assertTrue("An equal size set of healthy instances should be true", awsEC2Platform.isAutoscalingGroupAtDesiredInstances(groupId)); autoScalingGroup.getInstances().get(0).setHealthStatus("Unhealthy"); assertFalse("An unhealthy instance should not be counted", awsEC2Platform.isAutoscalingGroupAtDesiredInstances(groupId)); autoScalingGroup.getInstances().remove(0); autoScalingGroup.getInstances().forEach(instance1 -> instance1.setHealthStatus("Healthy")); assertFalse("Insufficient total instance should be false", awsEC2Platform.isAutoscalingGroupAtDesiredInstances(groupId)); }
public boolean isAutoscalingGroupAtDesiredInstances (String autoScalingGroupName) { List<AutoScalingGroup> autoScalingGroups = amazonAutoScaling.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(autoScalingGroupName)).getAutoScalingGroups(); int desiredCapacity = autoScalingGroups.stream().findFirst().map(AutoScalingGroup::getDesiredCapacity).orElse(1); int actualCapacity = (int) autoScalingGroups.stream() .map(AutoScalingGroup::getInstances) .flatMap(Collection::stream) .filter(instance -> instance.getHealthStatus().equals("Healthy")) .count(); return desiredCapacity == actualCapacity; }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { public boolean isAutoscalingGroupAtDesiredInstances (String autoScalingGroupName) { List<AutoScalingGroup> autoScalingGroups = amazonAutoScaling.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(autoScalingGroupName)).getAutoScalingGroups(); int desiredCapacity = autoScalingGroups.stream().findFirst().map(AutoScalingGroup::getDesiredCapacity).orElse(1); int actualCapacity = (int) autoScalingGroups.stream() .map(AutoScalingGroup::getInstances) .flatMap(Collection::stream) .filter(instance -> instance.getHealthStatus().equals("Healthy")) .count(); return desiredCapacity == actualCapacity; } }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { public boolean isAutoscalingGroupAtDesiredInstances (String autoScalingGroupName) { List<AutoScalingGroup> autoScalingGroups = amazonAutoScaling.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(autoScalingGroupName)).getAutoScalingGroups(); int desiredCapacity = autoScalingGroups.stream().findFirst().map(AutoScalingGroup::getDesiredCapacity).orElse(1); int actualCapacity = (int) autoScalingGroups.stream() .map(AutoScalingGroup::getInstances) .flatMap(Collection::stream) .filter(instance -> instance.getHealthStatus().equals("Healthy")) .count(); return desiredCapacity == actualCapacity; } @Autowired  AwsEC2Platform(AmazonEC2 amazonEC2, ContainerManager containerManager, AwsEC2SelfAwareness awsEC2SelfAwareness); private  AwsEC2Platform(); }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { public boolean isAutoscalingGroupAtDesiredInstances (String autoScalingGroupName) { List<AutoScalingGroup> autoScalingGroups = amazonAutoScaling.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(autoScalingGroupName)).getAutoScalingGroups(); int desiredCapacity = autoScalingGroups.stream().findFirst().map(AutoScalingGroup::getDesiredCapacity).orElse(1); int actualCapacity = (int) autoScalingGroups.stream() .map(AutoScalingGroup::getInstances) .flatMap(Collection::stream) .filter(instance -> instance.getHealthStatus().equals("Healthy")) .count(); return desiredCapacity == actualCapacity; } @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 boolean isAutoscalingGroupAtDesiredInstances (String autoScalingGroupName) { List<AutoScalingGroup> autoScalingGroups = amazonAutoScaling.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(autoScalingGroupName)).getAutoScalingGroups(); int desiredCapacity = autoScalingGroups.stream().findFirst().map(AutoScalingGroup::getDesiredCapacity).orElse(1); int actualCapacity = (int) autoScalingGroups.stream() .map(AutoScalingGroup::getInstances) .flatMap(Collection::stream) .filter(instance -> instance.getHealthStatus().equals("Healthy")) .count(); return desiredCapacity == actualCapacity; } @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);  }