Search in sources :

Example 11 with DescribeStackResourcesResult

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");
}
Also used : DescribeStackResourcesResult(com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult) StackResource(com.amazonaws.services.cloudformation.model.StackResource) Test(org.junit.jupiter.api.Test)

Example 12 with DescribeStackResourcesResult

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);
}
Also used : DescribeStackEventsResult(com.amazonaws.services.cloudformation.model.DescribeStackEventsResult) DescribeStackResourcesResult(com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DescribeStackEventsRequest(com.amazonaws.services.cloudformation.model.DescribeStackEventsRequest) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) StackResource(com.amazonaws.services.cloudformation.model.StackResource) Test(org.junit.jupiter.api.Test)

Example 13 with DescribeStackResourcesResult

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());
}
Also used : DescribeStackEventsResult(com.amazonaws.services.cloudformation.model.DescribeStackEventsResult) StackEvent(com.amazonaws.services.cloudformation.model.StackEvent) DescribeStackResourcesResult(com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DescribeStackEventsRequest(com.amazonaws.services.cloudformation.model.DescribeStackEventsRequest) Stack(com.amazonaws.services.cloudformation.model.Stack) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Test(org.junit.jupiter.api.Test)

Example 14 with DescribeStackResourcesResult

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);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) HttpContext(com.sun.net.httpserver.HttpContext) DescribeStackResourcesRequest(com.amazonaws.services.cloudformation.model.DescribeStackResourcesRequest) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ClassPathResource(org.springframework.core.io.ClassPathResource) DescribeStackResourcesResult(com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) HttpServer(com.sun.net.httpserver.HttpServer) MetaDataServer(io.awspring.cloud.context.MetaDataServer) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) StackResource(com.amazonaws.services.cloudformation.model.StackResource) Test(org.junit.jupiter.api.Test)

Example 15 with DescribeStackResourcesResult

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;
}
Also used : DescribeStackResourcesResult(com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult) DescribeStackResourcesRequest(com.amazonaws.services.cloudformation.model.DescribeStackResourcesRequest)

Aggregations

DescribeStackResourcesResult (com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult)15 StackResource (com.amazonaws.services.cloudformation.model.StackResource)11 Test (org.junit.jupiter.api.Test)9 DescribeStackResourcesRequest (com.amazonaws.services.cloudformation.model.DescribeStackResourcesRequest)8 DescribeStackEventsRequest (com.amazonaws.services.cloudformation.model.DescribeStackEventsRequest)5 DescribeStackEventsResult (com.amazonaws.services.cloudformation.model.DescribeStackEventsResult)5 DescribeStacksResult (com.amazonaws.services.cloudformation.model.DescribeStacksResult)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Stack (com.amazonaws.services.cloudformation.model.Stack)3 StackEvent (com.amazonaws.services.cloudformation.model.StackEvent)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Logger (org.slf4j.Logger)3 Component (org.springframework.stereotype.Component)3 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)2 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)2 ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)2 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)2