use of com.amazonaws.services.cloudformation.model.StackResource in project spring-cloud-aws by awspring.
the class StackConfigurationBeanDefinitionParserTest method stackResourceRegistry_stackConfigurationWithoutStaticName_stackResourceRegistryBeanExposedUnderGeneratedName.
// @checkstyle:off
@Test
void stackResourceRegistry_stackConfigurationWithoutStaticName_stackResourceRegistryBeanExposedUnderGeneratedName() throws Exception {
// @checkstyle:on
// Arrange
HttpServer server = MetaDataServer.setupHttpServer();
HttpContext httpContext = server.createContext("/latest/meta-data/instance-id", new MetaDataServer.HttpResponseWriterHandler("foo"));
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
when(amazonCloudFormation.describeStackResources(new DescribeStackResourcesRequest().withPhysicalResourceId("foo"))).thenReturn(new DescribeStackResourcesResult().withStackResources(new StackResource().withStackName("test")));
when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("test"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-autoDetectStackName.xml", getClass()));
applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
applicationContext.refresh();
// Act
StackResourceRegistry autoDetectingStackNameProviderBasedStackResourceRegistry = applicationContext.getBean("io.awspring.cloud.core.env.stack.config.StackResourceRegistryFactoryBean#0", StackResourceRegistry.class);
// Assert
assertThat(autoDetectingStackNameProviderBasedStackResourceRegistry).isNotNull();
server.removeContext(httpContext);
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AutoScalingGroupHandler method getAutoScalingGroups.
public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient, String stackName) {
DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest();
resourcesRequest.setStackName(stackName);
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())));
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AutoScalingGroupHandlerTest method testGetAutoScalingGroups.
@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));
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AwsCloudFormationErrorMessageProviderTest method shouldDecodeAuthorizationError.
@Test
void shouldDecodeAuthorizationError() {
when(cfRetryClient.describeStacks(any())).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatusReason("The following resource(s) failed to create: [ClusterNodeSecurityGroupmaster0].")));
String resourceStatusReason = "Resource creation cancelled";
when(cfRetryClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(new StackResource().withLogicalResourceId("ClusterNodeSecurityGroupmaster0").withResourceStatus(ResourceStatus.CREATE_FAILED.toString()).withResourceStatusReason(resourceStatusReason)));
when(awsEncodedAuthorizationFailureMessageDecoder.decodeAuthorizationFailureMessageIfNeeded(any(), eq(REGION), anyString())).thenReturn("Decoded auth error");
when(cfRetryClient.describeStackEvents(any(DescribeStackEventsRequest.class))).thenReturn(new DescribeStackEventsResult());
String result = underTest.getErrorReason(credentialView, REGION, STACK_NAME, ResourceStatus.CREATE_FAILED);
assertEquals("The following resource(s) failed to create: [ClusterNodeSecurityGroupmaster0]. " + "ClusterNodeSecurityGroupmaster0: Decoded auth error", result);
verify(awsEncodedAuthorizationFailureMessageDecoder).decodeAuthorizationFailureMessageIfNeeded(credentialView, REGION, resourceStatusReason);
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AwsCloudFormationErrorMessageProvider method getStackResourceStatusReasons.
private String getStackResourceStatusReasons(AwsCredentialView credentialView, String region, String stackName, Set<String> resourceErrorStatuses, AmazonCloudFormationClient cfClient) {
DescribeStackResourcesRequest describeStackResourcesRequest = new DescribeStackResourcesRequest().withStackName(stackName);
DescribeStackResourcesResult describeStackResourcesResult = cfClient.describeStackResources(describeStackResourcesRequest);
String stackResourceStatusReasons = describeStackResourcesResult.getStackResources().stream().filter(stackResource -> resourceErrorStatuses.contains(stackResource.getResourceStatus())).map(stackResource -> getStackResourceMessage(credentialView, region, stackResource)).collect(Collectors.joining(", "));
return stackResourceStatusReasons;
}
Aggregations