Search in sources :

Example 1 with StackInstanceSummary

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

the class CloudFormationStackSet method findStackSetInstances.

public List<StackInstanceSummary> findStackSetInstances() {
    List<StackInstanceSummary> summaries = new ArrayList<>();
    ListStackInstancesRequest request = new ListStackInstancesRequest().withStackSetName(this.stackSet);
    do {
        ListStackInstancesResult result = this.client.listStackInstances(request);
        request.setNextToken(result.getNextToken());
        summaries.addAll(result.getSummaries());
    } while (request.getNextToken() != null);
    return summaries;
}
Also used : ListStackInstancesRequest(com.amazonaws.services.cloudformation.model.ListStackInstancesRequest) StackInstanceSummary(com.amazonaws.services.cloudformation.model.StackInstanceSummary) ArrayList(java.util.ArrayList) ListStackInstancesResult(com.amazonaws.services.cloudformation.model.ListStackInstancesResult)

Example 2 with StackInstanceSummary

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

the class CFNUpdateStackSetStepTest method updateWithRegionBatches.

@Test
public void updateWithRegionBatches() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(stackSet.exists()).thenReturn(true);
    String operationId = UUID.randomUUID().toString();
    Mockito.when(stackSet.update(Mockito.anyString(), Mockito.anyString(), Mockito.any(UpdateStackSetRequest.class))).thenReturn(new UpdateStackSetResult().withOperationId(operationId));
    Mockito.when(stackSet.findStackSetInstances()).thenReturn(asList(new StackInstanceSummary().withAccount("a1").withRegion("r1"), new StackInstanceSummary().withAccount("a2").withRegion("r1"), new StackInstanceSummary().withAccount("a2").withRegion("r2"), new StackInstanceSummary().withAccount("a3").withRegion("r3")));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  cfnUpdateStackSet(stackSet: 'foo'," + "       pollInterval: 27," + "       batchingOptions: [" + "         regions: true" + "       ]" + "    )" + "}\n", true));
    jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    PowerMockito.verifyNew(CloudFormationStackSet.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class), Mockito.eq(SleepStrategy.EXPONENTIAL_BACKOFF_STRATEGY));
    ArgumentCaptor<UpdateStackSetRequest> requestCapture = ArgumentCaptor.forClass(UpdateStackSetRequest.class);
    Mockito.verify(stackSet, Mockito.times(3)).update(Mockito.anyString(), Mockito.anyString(), requestCapture.capture());
    Map<String, List<String>> capturedRegionAccounts = requestCapture.getAllValues().stream().flatMap(summary -> summary.getRegions().stream().flatMap(region -> summary.getAccounts().stream().map(accountId -> RegionAccountIdTuple.builder().accountId(accountId).region(region).build()))).collect(Collectors.groupingBy(RegionAccountIdTuple::getRegion, Collectors.mapping(RegionAccountIdTuple::getAccountId, Collectors.toList())));
    Assertions.assertThat(capturedRegionAccounts).containsAllEntriesOf(new HashMap<String, List<String>>() {

        {
            put("r1", asList("a1", "a2"));
            put("r2", singletonList("a2"));
            put("r3", singletonList("a3"));
        }
    });
    Mockito.verify(stackSet, Mockito.times(3)).waitForOperationToComplete(Mockito.any(), Mockito.any());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) UpdateStackSetResult(com.amazonaws.services.cloudformation.model.UpdateStackSetResult) Value(lombok.Value) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) Arrays.asList(java.util.Arrays.asList) AwsSyncClientBuilder(com.amazonaws.client.builder.AwsSyncClientBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Duration(java.time.Duration) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Assertions(org.assertj.core.api.Assertions) EnvVars(hudson.EnvVars) Collector(java.util.stream.Collector) StackInstanceSummary(com.amazonaws.services.cloudformation.model.StackInstanceSummary) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockito(org.powermock.api.mockito.PowerMockito) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Before(org.junit.Before) AWSClientFactory(de.taimos.pipeline.aws.AWSClientFactory) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrintWriter(java.io.PrintWriter) StackSetSummary(com.amazonaws.services.cloudformation.model.StackSetSummary) TaskListener(hudson.model.TaskListener) UpdateStackSetRequest(com.amazonaws.services.cloudformation.model.UpdateStackSetRequest) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Mockito(org.mockito.Mockito) Tag(com.amazonaws.services.cloudformation.model.Tag) List(java.util.List) Rule(org.junit.Rule) Builder(lombok.Builder) StackSetOperationPreferences(com.amazonaws.services.cloudformation.model.StackSetOperationPreferences) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Collections(java.util.Collections) UpdateStackSetRequest(com.amazonaws.services.cloudformation.model.UpdateStackSetRequest) UpdateStackSetResult(com.amazonaws.services.cloudformation.model.UpdateStackSetResult) StackInstanceSummary(com.amazonaws.services.cloudformation.model.StackInstanceSummary) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StackInstanceSummary (com.amazonaws.services.cloudformation.model.StackInstanceSummary)2 AwsSyncClientBuilder (com.amazonaws.client.builder.AwsSyncClientBuilder)1 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)1 ListStackInstancesRequest (com.amazonaws.services.cloudformation.model.ListStackInstancesRequest)1 ListStackInstancesResult (com.amazonaws.services.cloudformation.model.ListStackInstancesResult)1 Parameter (com.amazonaws.services.cloudformation.model.Parameter)1 StackSetOperationPreferences (com.amazonaws.services.cloudformation.model.StackSetOperationPreferences)1 StackSetSummary (com.amazonaws.services.cloudformation.model.StackSetSummary)1 Tag (com.amazonaws.services.cloudformation.model.Tag)1 UpdateStackSetRequest (com.amazonaws.services.cloudformation.model.UpdateStackSetRequest)1 UpdateStackSetResult (com.amazonaws.services.cloudformation.model.UpdateStackSetResult)1 AWSClientFactory (de.taimos.pipeline.aws.AWSClientFactory)1 EnvVars (hudson.EnvVars)1 TaskListener (hudson.model.TaskListener)1 PrintWriter (java.io.PrintWriter)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1