Search in sources :

Example 1 with StackResourceSummary

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

the class StackConfigurationBeanDefinitionParserTest method resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId.

// @checkstyle:off
@Test
void resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId() {
    // @checkstyle:on
    // Arrange
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
    when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("EmptyBucket").withPhysicalResourceId("integrationteststack-emptybucket-foo")));
    applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.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-");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 2 with StackResourceSummary

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

the class StackConfigurationBeanDefinitionParserTest method parseInternal_stackConfigurationWithExternallyConfiguredCloudFormationClient_returnsConfiguredStackWithExternallyConfiguredClient.

// @checkstyle:off
@Test
void parseInternal_stackConfigurationWithExternallyConfiguredCloudFormationClient_returnsConfiguredStackWithExternallyConfiguredClient() throws Exception {
    // @checkstyle:on
    // Arrange
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-withCustomCloudFormationClient.xml", getClass()));
    AmazonCloudFormation amazonCloudFormationMock = beanFactory.getBean(AmazonCloudFormation.class);
    when(amazonCloudFormationMock.listStackResources(new ListStackResourcesRequest().withStackName("test"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
    when(amazonCloudFormationMock.describeStacks(new DescribeStacksRequest().withStackName("test"))).thenReturn(new DescribeStacksResult().withStacks(new Stack()));
    // Act
    StackResourceRegistry stackResourceRegistry = beanFactory.getBean(StackResourceRegistry.class);
    // Assert
    assertThat(stackResourceRegistry).isNotNull();
    assertThat(beanFactory.containsBeanDefinition(getBeanName(AmazonCloudFormationClient.class.getName()))).isFalse();
    verify(amazonCloudFormationMock, times(1)).listStackResources(new ListStackResourcesRequest().withStackName("test"));
    beanFactory.getBean("customStackTags");
    verify(amazonCloudFormationMock, times(1)).describeStacks(new DescribeStacksRequest().withStackName("test"));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) StackResourceRegistry(io.awspring.cloud.core.env.stack.StackResourceRegistry) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) ClassPathResource(org.springframework.core.io.ClassPathResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary 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);
}
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) StackResourceRegistry(io.awspring.cloud.core.env.stack.StackResourceRegistry) 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 4 with StackResourceSummary

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

the class StackConfigurationBeanDefinitionParserTest method resourceIdResolverResolveToPhysicalResourceId_logicalResourceIdOfNonExistingResourceProvided_returnsLogicalResourceIdAsPhysicalResourceId.

// @checkstyle:off
@Test
void resourceIdResolverResolveToPhysicalResourceId_logicalResourceIdOfNonExistingResourceProvided_returnsLogicalResourceIdAsPhysicalResourceId() {
    // @checkstyle:on
    // Arrange
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
    when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
    applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
    applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
    applicationContext.refresh();
    ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
    // Act
    String physicalResourceId = resourceIdResolver.resolveToPhysicalResourceId("nonExistingLogicalResourceId");
    // Assert
    assertThat(physicalResourceId).isEqualTo("nonExistingLogicalResourceId");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 5 with StackResourceSummary

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

the class StackConfigurationBeanDefinitionParserTest method resourceIdResolver_stackConfiguration_resourceIdResolverBeanExposed.

@Test
void resourceIdResolver_stackConfiguration_resourceIdResolverBeanExposed() {
    // Arrange
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
    when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
    applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
    applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
    applicationContext.refresh();
    // Act
    ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
    // Assert
    assertThat(resourceIdResolver).isNotNull();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

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