@Test public void testGetAutoScalingGroups() { CloudResource cfResource = CloudResource.builder() .type(ResourceType.CLOUDFORMATION_STACK) .name("cf") .build(); DescribeStackResourcesResult resourcesResult = new DescribeStackResourcesResult(); StackResource stackResource = new StackResource() .withLogicalResourceId("logicalResourceId") .withPhysicalResourceId("physicalResourceId") .withResourceType("AWS::AutoScaling::AutoScalingGroup"); resourcesResult.getStackResources().add(stackResource); resourcesResult.getStackResources().add(new StackResource().withResourceType("other")); when(cloudFormationClient.describeStackResources(any(DescribeStackResourcesRequest.class))).thenReturn(resourcesResult); DescribeAutoScalingGroupsResult scalingGroupsResult = new DescribeAutoScalingGroupsResult(); AutoScalingGroup autoScalingGroup = new AutoScalingGroup().withAutoScalingGroupName(stackResource.getPhysicalResourceId()); scalingGroupsResult.getAutoScalingGroups().add(autoScalingGroup); when(autoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(scalingGroupsResult); Map<AutoScalingGroup, String> autoScalingGroups = underTest.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource); assertEquals(1, autoScalingGroups.size()); assertEquals(autoScalingGroup, autoScalingGroups.entrySet().stream().findFirst().get().getKey()); assertEquals(stackResource.getLogicalResourceId(), autoScalingGroups.entrySet().stream().findFirst().get().getValue()); ArgumentCaptor<DescribeStackResourcesRequest> stackResourcesRequestArgumentCaptor = ArgumentCaptor.forClass(DescribeStackResourcesRequest.class); verify(cloudFormationClient).describeStackResources(stackResourcesRequestArgumentCaptor.capture()); assertEquals(cfResource.getName(), stackResourcesRequestArgumentCaptor.getValue().getStackName()); ArgumentCaptor<DescribeAutoScalingGroupsRequest> scalingGroupsRequestArgumentCaptor = ArgumentCaptor.forClass(DescribeAutoScalingGroupsRequest.class); verify(autoScalingClient).describeAutoScalingGroups(scalingGroupsRequestArgumentCaptor.capture()); assertEquals(1, scalingGroupsRequestArgumentCaptor.getValue().getAutoScalingGroupNames().size()); assertEquals(stackResource.getPhysicalResourceId(), scalingGroupsRequestArgumentCaptor.getValue().getAutoScalingGroupNames().get(0)); }
public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient, CloudResource cfResource) { DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest(); resourcesRequest.setStackName(cfResource.getName()); DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest); Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream() .filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType())) .collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId)); DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest(); request.setAutoScalingGroupNames(autoScalingGroups.keySet()); List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups(); return scalingGroups.stream() .collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName()))); }
AutoScalingGroupHandler { public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient, CloudResource cfResource) { DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest(); resourcesRequest.setStackName(cfResource.getName()); DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest); Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream() .filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType())) .collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId)); DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest(); request.setAutoScalingGroupNames(autoScalingGroups.keySet()); List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups(); return scalingGroups.stream() .collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName()))); } }
AutoScalingGroupHandler { public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient, CloudResource cfResource) { DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest(); resourcesRequest.setStackName(cfResource.getName()); DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest); Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream() .filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType())) .collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId)); DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest(); request.setAutoScalingGroupNames(autoScalingGroups.keySet()); List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups(); return scalingGroups.stream() .collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName()))); }  }
AutoScalingGroupHandler { public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient, CloudResource cfResource) { DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest(); resourcesRequest.setStackName(cfResource.getName()); DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest); Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream() .filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType())) .collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId)); DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest(); request.setAutoScalingGroupNames(autoScalingGroups.keySet()); List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups(); return scalingGroups.stream() .collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName()))); }  void updateAutoScalingGroupWithLaunchConfiguration(AmazonAutoScalingClient autoScalingClient, String autoScalingGroupName,
            LaunchConfiguration oldLaunchConfiguration, String launchConfigurationName); Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient,
            CloudResource cfResource); }
AutoScalingGroupHandler { public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient, CloudResource cfResource) { DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest(); resourcesRequest.setStackName(cfResource.getName()); DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest); Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream() .filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType())) .collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId)); DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest(); request.setAutoScalingGroupNames(autoScalingGroups.keySet()); List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups(); return scalingGroups.stream() .collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName()))); }  void updateAutoScalingGroupWithLaunchConfiguration(AmazonAutoScalingClient autoScalingClient, String autoScalingGroupName,
            LaunchConfiguration oldLaunchConfiguration, String launchConfigurationName); Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient,
            CloudResource cfResource);  }