Search in sources :

Example 6 with ListStackResourcesRequest

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

the class StackConfigurationBeanDefinitionParserTest method stackResourceRegistry_stackConfigurationWithStaticName_stackResourceRegistryBeanExposedUnderStaticStackName.

// @checkstyle:off
@Test
void stackResourceRegistry_stackConfigurationWithStaticName_stackResourceRegistryBeanExposedUnderStaticStackName() throws Exception {
    // @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();
    // Act
    StackResourceRegistry staticStackNameProviderBasedStackResourceRegistry = applicationContext.getBean("IntegrationTestStack", StackResourceRegistry.class);
    // Assert
    assertThat(staticStackNameProviderBasedStackResourceRegistry).isNotNull();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) StackResourceRegistry(io.awspring.cloud.core.env.stack.StackResourceRegistry) 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 7 with ListStackResourcesRequest

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

the class StackResourceRegistryFactoryBean method getStackResourceSummaries.

private List<StackResourceSummary> getStackResourceSummaries(String stackName) {
    ListStackResourcesResult listStackResourcesResult = this.amazonCloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(stackName));
    if (!StringUtils.hasText(listStackResourcesResult.getNextToken())) {
        return listStackResourcesResult.getStackResourceSummaries();
    } else {
        List<StackResourceSummary> result = new ArrayList<>(listStackResourcesResult.getStackResourceSummaries());
        while (StringUtils.hasText(listStackResourcesResult.getNextToken())) {
            listStackResourcesResult = this.amazonCloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(stackName).withNextToken(listStackResourcesResult.getNextToken()));
            result.addAll(listStackResourcesResult.getStackResourceSummaries());
        }
        return result;
    }
}
Also used : ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ArrayList(java.util.ArrayList) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary)

Example 8 with ListStackResourcesRequest

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

the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMultiplePorts.

@Test
public void testCollectLoadBalancerMultiplePorts() {
    int numPorts = 3;
    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", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 1, LISTENER_ARN + "1Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 1, TARGET_GROUP_ARN + "1Internal", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 2, LISTENER_ARN + "2Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 2, TARGET_GROUP_ARN + "2Internal");
    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 9 with ListStackResourcesRequest

use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest in project pipeline-aws-plugin by jenkinsci.

the class LambdaVersionCleanupStepTest method deleteCloudFormationStack.

@Test
public void deleteCloudFormationStack() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v1").withLastModified(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)), new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo2")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo2")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v1").withLastModified(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)), new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    Mockito.when(this.cloudformation.listStackResources(new ListStackResourcesRequest().withStackName("baz"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withResourceType("AWS::Lambda::Function").withPhysicalResourceId("foo"), new StackResourceSummary().withResourceType("AWS::Baz::Function").withPhysicalResourceId("bar")).withNextToken("foo"));
    Mockito.when(this.cloudformation.listStackResources(new ListStackResourcesRequest().withStackName("baz").withNextToken("foo"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withResourceType("AWS::Lambda::Function").withPhysicalResourceId("foo2"), new StackResourceSummary().withResourceType("AWS::Baz::Function").withPhysicalResourceId("bar")));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  lambdaVersionCleanup(stackName: 'baz', daysAgo: 5)\n" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo"));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo2"));
    Mockito.verify(this.awsLambda, Mockito.times(2)).listVersionsByFunction(Mockito.any());
    Mockito.verify(this.awsLambda, Mockito.times(2)).listAliases(Mockito.any());
    Mockito.verifyNoMoreInteractions(this.awsLambda);
}
Also used : ListAliasesResult(com.amazonaws.services.lambda.model.ListAliasesResult) ListVersionsByFunctionResult(com.amazonaws.services.lambda.model.ListVersionsByFunctionResult) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) FunctionConfiguration(com.amazonaws.services.lambda.model.FunctionConfiguration) ListAliasesRequest(com.amazonaws.services.lambda.model.ListAliasesRequest) ListVersionsByFunctionRequest(com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DeleteFunctionRequest(com.amazonaws.services.lambda.model.DeleteFunctionRequest) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with ListStackResourcesRequest

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

the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMissingTargetGroup.

@Test
public void testCollectLoadBalancerMissingTargetGroup() {
    int numPorts = 1;
    AuthenticatedContext ac = authenticatedContext();
    LoadBalancer loadBalancer = createLoadBalancer();
    List<StackResourceSummary> summaries = createSummaries(numPorts, false);
    ListStackResourcesResult result = new ListStackResourcesResult();
    result.setStackResourceSummaries(summaries);
    Map<String, Object> expectedParameters = new HashMap<>();
    expectedParameters.put(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN);
    expectedParameters.put(AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal");
    expectedParameters.put(AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, null);
    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 : HashMap(java.util.HashMap) 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)

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