use of com.amazonaws.services.cloudformation.model.UpdateStackSetRequest in project pipeline-aws-plugin by jenkinsci.
the class CloudFormationStackSet method update.
public UpdateStackSetResult update(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags) {
this.listener.getLogger().format("Updating CloudFormation stack set %s %n", this.stackSet);
UpdateStackSetRequest req = new UpdateStackSetRequest().withStackSetName(this.stackSet).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM).withParameters(params).withTags(tags);
if (templateBody != null && !templateBody.isEmpty()) {
req.setTemplateBody(templateBody);
} else if (templateUrl != null && !templateUrl.isEmpty()) {
req.setTemplateURL(templateUrl);
} else {
req.setUsePreviousTemplate(true);
}
UpdateStackSetResult result = this.client.updateStackSet(req);
this.listener.getLogger().format("Updated CloudFormation stack set %s %n", this.stackSet);
return result;
}
use of com.amazonaws.services.cloudformation.model.UpdateStackSetRequest in project pipeline-aws-plugin by jenkinsci.
the class CFNUpdateStackSetStepTest method updateExistingStackStackSetWithOperationPreferences.
@Test
public void updateExistingStackStackSetWithOperationPreferences() 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));
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " cfnUpdateStackSet(stackSet: 'foo', operationPreferences: [failureToleranceCount: 5, regionOrder: ['us-west-2'], failureTolerancePercentage: 17, maxConcurrentCount: 18, maxConcurrentPercentage: 34])" + "}\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).update(Mockito.anyString(), Mockito.anyString(), requestCapture.capture());
Assertions.assertThat(requestCapture.getValue().getOperationPreferences()).isEqualTo(new StackSetOperationPreferences().withFailureToleranceCount(5).withRegionOrder("us-west-2").withFailureTolerancePercentage(17).withMaxConcurrentCount(18).withMaxConcurrentPercentage(34));
Mockito.verify(stackSet).waitForOperationToComplete(operationId, Duration.ofSeconds(1));
}
use of com.amazonaws.services.cloudformation.model.UpdateStackSetRequest in project pipeline-aws-plugin by jenkinsci.
the class CloudFormationStackSet method update.
public UpdateStackSetResult update(String templateBody, String templateUrl, UpdateStackSetRequest request) throws InterruptedException {
this.listener.getLogger().format("Updating CloudFormation stack set %s %n", this.stackSet);
UpdateStackSetRequest req = request.withStackSetName(this.stackSet).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM, Capability.CAPABILITY_AUTO_EXPAND);
if (templateBody != null && !templateBody.isEmpty()) {
req.setTemplateBody(templateBody);
} else if (templateUrl != null && !templateUrl.isEmpty()) {
req.setTemplateURL(templateUrl);
} else {
req.setUsePreviousTemplate(true);
}
return doUpdate(req, 1);
}
use of com.amazonaws.services.cloudformation.model.UpdateStackSetRequest in project pipeline-aws-plugin by jenkinsci.
the class CFNUpdateStackSetStepTest method updateExistantStack.
@Test
public void updateExistantStack() 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));
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " cfnUpdateStackSet(stackSet: 'foo', pollInterval: 27, params: ['foo=bar'], paramsFile: 'params.json')" + "}\n", true));
try (PrintWriter writer = new PrintWriter(jenkinsRule.jenkins.getWorkspaceFor(job).child("params.json").write())) {
writer.println("[{\"ParameterKey\": \"foo1\", \"ParameterValue\": \"25\"}]");
}
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).update(Mockito.anyString(), Mockito.anyString(), requestCapture.capture());
Assertions.assertThat(requestCapture.getValue().getParameters()).containsExactlyInAnyOrder(new Parameter().withParameterKey("foo").withParameterValue("bar"), new Parameter().withParameterKey("foo1").withParameterValue("25"));
Mockito.verify(stackSet).waitForOperationToComplete(operationId, Duration.ofMillis(27));
}
use of com.amazonaws.services.cloudformation.model.UpdateStackSetRequest 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());
}
Aggregations