use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult in project cloudbreak by hortonworks.
the class AwsMigrationUtilTest method testAllInstancesDeletedFromCloudFormationWhenASGroupFound.
@Test
public void testAllInstancesDeletedFromCloudFormationWhenASGroupFound() {
StackResource asg1 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id1");
StackResource asg2 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id2");
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(Location.location(Region.region("region")));
when(awsClient.createCloudFormationClient(any(), any())).thenReturn(amazonCloudFormationClient);
when(amazonCloudFormationClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(List.of(asg1, asg2)));
when(awsClient.createAutoScalingClient(any(), any())).thenReturn(amazonAutoScalingClient);
when(cfStackUtil.getInstanceIds(amazonAutoScalingClient, "id1")).thenReturn(Collections.emptyList());
when(cfStackUtil.getInstanceIds(amazonAutoScalingClient, "id2")).thenReturn(Collections.emptyList());
boolean actual = underTest.allInstancesDeletedFromCloudFormation(ac, cloudResource);
Assertions.assertTrue(actual);
verify(cfStackUtil).getInstanceIds(amazonAutoScalingClient, "id1");
verify(cfStackUtil).getInstanceIds(amazonAutoScalingClient, "id2");
}
use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult in project cloudbreak by hortonworks.
the class AwsCloudFormationErrorMessageProviderTest method shouldReportAddressLimitExceededOnCreate.
@Test
void shouldReportAddressLimitExceededOnCreate() {
when(cfRetryClient.describeStacks(any())).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatusReason("The following resource(s) failed to create: [EIPmaster01, ClusterNodeSecurityGroupmaster0].")));
when(cfRetryClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(new StackResource().withLogicalResourceId("ClusterNodeSecurityGroupmaster0").withResourceStatus(ResourceStatus.CREATE_FAILED.toString()).withResourceStatusReason("Resource creation cancelled"), new StackResource().withLogicalResourceId("EIPmaster01").withResourceStatus(ResourceStatus.CREATE_FAILED.toString()).withResourceStatusReason("The maximum number of addresses has been reached. (Service: AmazonEC2; Status Code: 400; Error Code: " + "AddressLimitExceeded; Request ID: ee8b7a70-a1bf-4b67-b9da-f6f6d258bfd4; Proxy: null)"), new StackResource().withLogicalResourceId("HealthyResource").withResourceStatus(ResourceStatus.CREATE_COMPLETE.toString()).withResourceStatusReason("Created")));
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: [EIPmaster01, ClusterNodeSecurityGroupmaster0]. " + "ClusterNodeSecurityGroupmaster0: Resource creation cancelled, " + "EIPmaster01: The maximum number of addresses has been reached. (Service: AmazonEC2; Status Code: 400; Error Code: AddressLimitExceeded; " + "Request ID: ee8b7a70-a1bf-4b67-b9da-f6f6d258bfd4; Proxy: null)", result);
}
use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult in project cloudbreak by hortonworks.
the class AwsCloudFormationErrorMessageProviderTest method testWhenMessageExtractedFromStackStatusAndCfEvent.
@Test
void testWhenMessageExtractedFromStackStatusAndCfEvent() {
StackEvent event = new StackEvent().withResourceStatus(ResourceStatus.CREATE_FAILED).withResourceStatusReason("Error");
Stack stack = new Stack().withStackStatusReason("Stack error");
DescribeStackEventsResult result = new DescribeStackEventsResult().withStackEvents(event);
when(cfRetryClient.describeStacks(any())).thenReturn(new DescribeStacksResult().withStacks(stack));
when(cfRetryClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult());
when(cfRetryClient.describeStackEvents(any(DescribeStackEventsRequest.class))).thenReturn(result);
String actual = underTest.getErrorReason(credentialView, REGION, STACK_NAME, ResourceStatus.CREATE_FAILED);
assertEquals(actual, stack.getStackStatusReason() + " " + event.getResourceStatusReason());
}
use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult in project spring-cloud-aws by awspring.
the class StackConfigurationBeanDefinitionParserTest method resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithoutStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId.
// @checkstyle:off
@Test
void resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithoutStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId() 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().withLogicalResourceId("EmptyBucket").withPhysicalResourceId("integrationteststack-emptybucket-foo")));
applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-autoDetectStackName.xml", getClass()));
applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
applicationContext.refresh();
ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
// Act
String physicalResourceId = resourceIdResolver.resolveToPhysicalResourceId("EmptyBucket");
// Assert
assertThat(physicalResourceId).startsWith("integrationteststack-emptybucket-");
server.removeContext(httpContext);
}
use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult in project cs-actions by CloudSlang.
the class GetStackDetailsAction method getStackResources.
private String getStackResources(String stackName, AmazonCloudFormation stackBuilder) throws IOException {
final DescribeStackResourcesRequest stackResourceRequest = new DescribeStackResourcesRequest().withStackName(stackName);
DescribeStackResourcesResult describeStackResourcesResult = stackBuilder.describeStackResources(stackResourceRequest);
String stackResources = OutputsUtil.getStackResourcesToJson(describeStackResourcesResult);
return stackResources;
}
Aggregations