@Test public void buildContainerFromInstance () { String instanceId = UUID.randomUUID().toString(); String name = UUID.randomUUID().toString(); String keyName = UUID.randomUUID().toString(); String availabilityZone = UUID.randomUUID().toString(); Placement placement = new Placement().withAvailabilityZone(availabilityZone); Instance instance; AwsEC2Container container; instance = new Instance().withInstanceId(instanceId).withTags(new Tag("Name", name)).withKeyName(keyName).withPlacement(placement); container = AwsEC2Container.builder().instanceId(instanceId).keyName(keyName).name(name).build(); assertEquals(container, awsEC2Platform.buildContainerFromInstance(instance)); instance = new Instance().withInstanceId(instanceId).withKeyName(keyName); container = AwsEC2Container.builder().instanceId(instanceId).name("no-name").keyName(keyName).build(); assertEquals(container, awsEC2Platform.buildContainerFromInstance(instance)); ReflectionTestUtils.setField(awsEC2Platform, "groupingTags", asList("asg", "bosh", "somethingelse")); instance = new Instance().withInstanceId(instanceId).withKeyName(keyName).withTags(new Tag("Name", name), new Tag("asg", "scalegroup")); container = AwsEC2Container.builder() .instanceId(instanceId) .keyName(keyName) .name(name) .groupIdentifier("scalegroup") .build(); assertEquals(container, awsEC2Platform.buildContainerFromInstance(instance)); instance = new Instance().withInstanceId(instanceId).withKeyName(keyName).withTags(new Tag("Name", name), new Tag("bosh", "boshgroup"), new Tag("asg", "scalegroup")); container = AwsEC2Container.builder() .instanceId(instanceId) .keyName(keyName) .name(name) .groupIdentifier("scalegroup") .build(); assertEquals(container, awsEC2Platform.buildContainerFromInstance(instance)); }
AwsEC2Container buildContainerFromInstance (Instance instance) { String groupIdentifier = null; Boolean nativeAwsAutoscaling = null; String name = instance.getTags() .stream() .filter(tag -> tag.getKey().equals("Name")) .findFirst() .orElse(new Tag("Name", "no-name")) .getValue(); if (groupingTags != null) { Tag groupingTag = instance.getTags() .stream() .filter(tag -> groupingTags.contains(tag.getKey())) .min(Comparator.comparingInt(tag -> groupingTags.indexOf(tag.getKey()))) .orElse(null); groupIdentifier = groupingTag == null ? null : groupingTag.getValue(); nativeAwsAutoscaling = groupingTag != null && AWS_ASG_NAME_TAG_KEY.equals(groupingTag.getKey()); } Placement placement = instance.getPlacement(); String availabilityZone = placement != null ? placement.getAvailabilityZone() : AwsConstants.NO_AZ_INFORMATION; return AwsEC2Container.builder().awsEC2Platform(this) .instanceId(instance.getInstanceId()) .keyName(Optional.ofNullable(instance.getKeyName()).orElse(NO_ASSIGNED_KEY)) .name(name) .groupIdentifier(Optional.ofNullable(groupIdentifier).orElse(NO_GROUPING_IDENTIFIER)) .nativeAwsAutoscaling(Optional.ofNullable(nativeAwsAutoscaling).orElse(false)) .availabilityZone(Optional.ofNullable(availabilityZone).orElse(AwsConstants.NO_AZ_INFORMATION)) .publicAddress(instance.getPublicIpAddress()).imageId(instance.getImageId()) .privateAddress(instance.getPrivateIpAddress()) .build(); }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { AwsEC2Container buildContainerFromInstance (Instance instance) { String groupIdentifier = null; Boolean nativeAwsAutoscaling = null; String name = instance.getTags() .stream() .filter(tag -> tag.getKey().equals("Name")) .findFirst() .orElse(new Tag("Name", "no-name")) .getValue(); if (groupingTags != null) { Tag groupingTag = instance.getTags() .stream() .filter(tag -> groupingTags.contains(tag.getKey())) .min(Comparator.comparingInt(tag -> groupingTags.indexOf(tag.getKey()))) .orElse(null); groupIdentifier = groupingTag == null ? null : groupingTag.getValue(); nativeAwsAutoscaling = groupingTag != null && AWS_ASG_NAME_TAG_KEY.equals(groupingTag.getKey()); } Placement placement = instance.getPlacement(); String availabilityZone = placement != null ? placement.getAvailabilityZone() : AwsConstants.NO_AZ_INFORMATION; return AwsEC2Container.builder().awsEC2Platform(this) .instanceId(instance.getInstanceId()) .keyName(Optional.ofNullable(instance.getKeyName()).orElse(NO_ASSIGNED_KEY)) .name(name) .groupIdentifier(Optional.ofNullable(groupIdentifier).orElse(NO_GROUPING_IDENTIFIER)) .nativeAwsAutoscaling(Optional.ofNullable(nativeAwsAutoscaling).orElse(false)) .availabilityZone(Optional.ofNullable(availabilityZone).orElse(AwsConstants.NO_AZ_INFORMATION)) .publicAddress(instance.getPublicIpAddress()).imageId(instance.getImageId()) .privateAddress(instance.getPrivateIpAddress()) .build(); } }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { AwsEC2Container buildContainerFromInstance (Instance instance) { String groupIdentifier = null; Boolean nativeAwsAutoscaling = null; String name = instance.getTags() .stream() .filter(tag -> tag.getKey().equals("Name")) .findFirst() .orElse(new Tag("Name", "no-name")) .getValue(); if (groupingTags != null) { Tag groupingTag = instance.getTags() .stream() .filter(tag -> groupingTags.contains(tag.getKey())) .min(Comparator.comparingInt(tag -> groupingTags.indexOf(tag.getKey()))) .orElse(null); groupIdentifier = groupingTag == null ? null : groupingTag.getValue(); nativeAwsAutoscaling = groupingTag != null && AWS_ASG_NAME_TAG_KEY.equals(groupingTag.getKey()); } Placement placement = instance.getPlacement(); String availabilityZone = placement != null ? placement.getAvailabilityZone() : AwsConstants.NO_AZ_INFORMATION; return AwsEC2Container.builder().awsEC2Platform(this) .instanceId(instance.getInstanceId()) .keyName(Optional.ofNullable(instance.getKeyName()).orElse(NO_ASSIGNED_KEY)) .name(name) .groupIdentifier(Optional.ofNullable(groupIdentifier).orElse(NO_GROUPING_IDENTIFIER)) .nativeAwsAutoscaling(Optional.ofNullable(nativeAwsAutoscaling).orElse(false)) .availabilityZone(Optional.ofNullable(availabilityZone).orElse(AwsConstants.NO_AZ_INFORMATION)) .publicAddress(instance.getPublicIpAddress()).imageId(instance.getImageId()) .privateAddress(instance.getPrivateIpAddress()) .build(); } @Autowired  AwsEC2Platform(AmazonEC2 amazonEC2, ContainerManager containerManager, AwsEC2SelfAwareness awsEC2SelfAwareness); private  AwsEC2Platform(); }
AwsEC2Platform extends Platform implements SshBasedExperiment<AwsEC2Container> { AwsEC2Container buildContainerFromInstance (Instance instance) { String groupIdentifier = null; Boolean nativeAwsAutoscaling = null; String name = instance.getTags() .stream() .filter(tag -> tag.getKey().equals("Name")) .findFirst() .orElse(new Tag("Name", "no-name")) .getValue(); if (groupingTags != null) { Tag groupingTag = instance.getTags() .stream() .filter(tag -> groupingTags.contains(tag.getKey())) .min(Comparator.comparingInt(tag -> groupingTags.indexOf(tag.getKey()))) .orElse(null); groupIdentifier = groupingTag == null ? null : groupingTag.getValue(); nativeAwsAutoscaling = groupingTag != null && AWS_ASG_NAME_TAG_KEY.equals(groupingTag.getKey()); } Placement placement = instance.getPlacement(); String availabilityZone = placement != null ? placement.getAvailabilityZone() : AwsConstants.NO_AZ_INFORMATION; return AwsEC2Container.builder().awsEC2Platform(this) .instanceId(instance.getInstanceId()) .keyName(Optional.ofNullable(instance.getKeyName()).orElse(NO_ASSIGNED_KEY)) .name(name) .groupIdentifier(Optional.ofNullable(groupIdentifier).orElse(NO_GROUPING_IDENTIFIER)) .nativeAwsAutoscaling(Optional.ofNullable(nativeAwsAutoscaling).orElse(false)) .availabilityZone(Optional.ofNullable(availabilityZone).orElse(AwsConstants.NO_AZ_INFORMATION)) .publicAddress(instance.getPublicIpAddress()).imageId(instance.getImageId()) .privateAddress(instance.getPrivateIpAddress()) .build(); } @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> { AwsEC2Container buildContainerFromInstance (Instance instance) { String groupIdentifier = null; Boolean nativeAwsAutoscaling = null; String name = instance.getTags() .stream() .filter(tag -> tag.getKey().equals("Name")) .findFirst() .orElse(new Tag("Name", "no-name")) .getValue(); if (groupingTags != null) { Tag groupingTag = instance.getTags() .stream() .filter(tag -> groupingTags.contains(tag.getKey())) .min(Comparator.comparingInt(tag -> groupingTags.indexOf(tag.getKey()))) .orElse(null); groupIdentifier = groupingTag == null ? null : groupingTag.getValue(); nativeAwsAutoscaling = groupingTag != null && AWS_ASG_NAME_TAG_KEY.equals(groupingTag.getKey()); } Placement placement = instance.getPlacement(); String availabilityZone = placement != null ? placement.getAvailabilityZone() : AwsConstants.NO_AZ_INFORMATION; return AwsEC2Container.builder().awsEC2Platform(this) .instanceId(instance.getInstanceId()) .keyName(Optional.ofNullable(instance.getKeyName()).orElse(NO_ASSIGNED_KEY)) .name(name) .groupIdentifier(Optional.ofNullable(groupIdentifier).orElse(NO_GROUPING_IDENTIFIER)) .nativeAwsAutoscaling(Optional.ofNullable(nativeAwsAutoscaling).orElse(false)) .availabilityZone(Optional.ofNullable(availabilityZone).orElse(AwsConstants.NO_AZ_INFORMATION)) .publicAddress(instance.getPublicIpAddress()).imageId(instance.getImageId()) .privateAddress(instance.getPrivateIpAddress()) .build(); } @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);  }