Search in sources :

Example 31 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary 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 32 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.

the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages.

@Test
void createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages() throws Exception {
    // Arrange
    AmazonCloudFormation cloudFormationClient = mock(AmazonCloudFormation.class);
    StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = new StackResourceRegistryFactoryBean(cloudFormationClient, new StaticStackNameProvider(STACK_NAME));
    when(cloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(STACK_NAME))).thenReturn(new ListStackResourcesResult().withNextToken("2").withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("log1")));
    when(cloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(STACK_NAME).withNextToken("2"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("log2")));
    // Act
    ListableStackResourceFactory stackResourceFactory = stackResourceRegistryFactoryBean.createInstance();
    // Assert
    verify(cloudFormationClient, times(2)).listStackResources(isA(ListStackResourcesRequest.class));
    assertThat(stackResourceFactory.getAllResources().size()).isEqualTo(2);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListableStackResourceFactory(io.awspring.cloud.core.env.stack.ListableStackResourceFactory) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) Test(org.junit.jupiter.api.Test)

Example 33 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.

the class StackResourceRegistryFactoryBean method convertToStackResourceMappings.

private Map<String, StackResource> convertToStackResourceMappings(String prefix, List<StackResourceSummary> stackResourceSummaries) {
    Map<String, StackResource> stackResourceMappings = new HashMap<>();
    for (StackResourceSummary stackResourceSummary : stackResourceSummaries) {
        String logicalResourceId = toNestedResourceId(prefix, stackResourceSummary.getLogicalResourceId());
        stackResourceMappings.put(logicalResourceId, new StackResource(logicalResourceId, stackResourceSummary.getPhysicalResourceId(), stackResourceSummary.getResourceType()));
    }
    return stackResourceMappings;
}
Also used : HashMap(java.util.HashMap) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) StackResource(io.awspring.cloud.core.env.stack.StackResource)

Example 34 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.

the class StackResourceRegistryFactoryBean method getResourceMappings.

private Map<String, StackResource> getResourceMappings(String prefix, String stackName) {
    List<StackResourceSummary> stackResourceSummaries = getStackResourceSummaries(stackName);
    Map<String, StackResource> current = convertToStackResourceMappings(prefix, stackResourceSummaries);
    Map<String, StackResource> stackResourceMappings = new HashMap<>(current);
    for (Map.Entry<String, StackResource> e : current.entrySet()) {
        StackResource resource = e.getValue();
        if ("AWS::CloudFormation::Stack".equals(resource.getType())) {
            stackResourceMappings.putAll(getResourceMappings(e.getKey(), resource.getPhysicalId()));
        }
    }
    return stackResourceMappings;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) StackResource(io.awspring.cloud.core.env.stack.StackResource)

Aggregations

StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)34 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)17 ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)14 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)13 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)13 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)12 Network (com.sequenceiq.cloudbreak.cloud.model.Network)12 Test (org.junit.Test)12 Test (org.junit.jupiter.api.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)11 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)9 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)6 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)5 ArrayList (java.util.ArrayList)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 AwsListener (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)4