Search in sources :

Example 11 with ListStackResourcesRequest

use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest in project cloudbreak by hortonworks.

the class AwsLoadBalancerMetadataCollectorTest method testCollectInternalLoadBalancer.

@Test
public void testCollectInternalLoadBalancer() {
    int numPorts = 1;
    AuthenticatedContext ac = authenticatedContext();
    LoadBalancer loadBalancer = createLoadBalancer();
    List<StackResourceSummary> summaries = createSummaries(numPorts, true);
    ListStackResourcesResult result = new ListStackResourcesResult();
    result.setStackResourceSummaries(summaries);
    Map<String, Object> expectedParameters = Map.of(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN, AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, TARGET_GROUP_ARN + "0Internal");
    when(awsClient.createCloudFormationClient(any(), any())).thenReturn(cfRetryClient);
    when(cloudFormationStackUtil.getCfStackName(ac)).thenReturn("stackName");
    when(awsStackRequestHelper.createListStackResourcesRequest(eq("stackName"))).thenReturn(new ListStackResourcesRequest());
    when(cfRetryClient.listStackResources(any())).thenReturn(result);
    Map<String, Object> parameters = underTest.getParameters(ac, loadBalancer, AwsLoadBalancerScheme.INTERNAL);
    assertEquals(expectedParameters, parameters);
}
Also used : ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) Test(org.junit.jupiter.api.Test)

Example 12 with ListStackResourcesRequest

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

use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest 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)

Aggregations

ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)13 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)13 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)13 Test (org.junit.jupiter.api.Test)11 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)8 ClassPathResource (org.springframework.core.io.ClassPathResource)7 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)6 ResourceIdResolver (io.awspring.cloud.core.env.ResourceIdResolver)4 LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)3 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 StackResourceRegistry (io.awspring.cloud.core.env.stack.StackResourceRegistry)3 DescribeStackResourcesRequest (com.amazonaws.services.cloudformation.model.DescribeStackResourcesRequest)2 DescribeStackResourcesResult (com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult)2 StackResource (com.amazonaws.services.cloudformation.model.StackResource)2 HttpContext (com.sun.net.httpserver.HttpContext)2 HttpServer (com.sun.net.httpserver.HttpServer)2 MetaDataServer (io.awspring.cloud.context.MetaDataServer)2 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 DescribeStacksResult (com.amazonaws.services.cloudformation.model.DescribeStacksResult)1