use of com.amazonaws.services.cloudformation.model.UpdateStackSetResult 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.UpdateStackSetResult in project pipeline-aws-plugin by jenkinsci.
the class CloudFormationStackSet method doUpdate.
private UpdateStackSetResult doUpdate(UpdateStackSetRequest req, int attempt) throws InterruptedException {
try {
this.listener.getLogger().format("Attempting to update CloudFormation stack set %s %n", this.stackSet);
UpdateStackSetResult result = this.client.updateStackSet(req);
this.listener.getLogger().format("Updated CloudFormation stack set %s %n", this.stackSet);
return result;
} catch (OperationInProgressException | StaleRequestException e) {
if (attempt == MAX_STACK_SET_RETRY_ATTEMPT_COUNT) {
this.listener.getLogger().format("Retries exhausted and cloudformation stack set %s is still busy%n", this.stackSet);
throw e;
} else {
long sleepDuration = this.sleepStrategy.calculateSleepDuration(attempt);
this.listener.getLogger().format("StackSet %s busy. Waiting %d ms %n", this.stackSet, sleepDuration);
Thread.sleep(sleepDuration);
return doUpdate(req, attempt + 1);
}
} catch (LimitExceededException lee) {
if (lee.getMessage().startsWith("StackSet operations cannot involve more than")) {
if (attempt == MAX_STACK_SET_RETRY_ATTEMPT_COUNT) {
this.listener.getLogger().format("Retries exhausted and cloudformation stack set operations %s is still busy%n", this.stackSet);
throw lee;
} else {
long sleepDuration = this.sleepStrategy.calculateSleepDuration(attempt);
this.listener.getLogger().format("Too many concurrent operations in progress (%s). Waiting for %s update. Waiting %d ms %n", lee.getMessage(), this.stackSet, sleepDuration);
Thread.sleep(sleepDuration);
return doUpdate(req, attempt + 1);
}
} else {
throw lee;
}
}
}
use of com.amazonaws.services.cloudformation.model.UpdateStackSetResult 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.UpdateStackSetResult in project pipeline-aws-plugin by jenkinsci.
the class CFNUpdateStackSetStepTest method updateExistingStackWithCustomAdminRole.
@Test
public void updateExistingStackWithCustomAdminRole() 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', administratorRoleArn: 'bar', executionRoleName: 'baz')" + "}\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));
Mockito.verify(stackSet).update(Mockito.anyString(), Mockito.anyString(), Mockito.any(UpdateStackSetRequest.class));
}
use of com.amazonaws.services.cloudformation.model.UpdateStackSetResult 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));
}
Aggregations