use of com.amazonaws.services.cloudformation.model.AmazonCloudFormationException in project pipeline-aws-plugin by jenkinsci.
the class CloudFormationStack method update.
public void update(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, long pollIntervallMillis, String roleArn) throws ExecutionException {
try {
UpdateStackRequest req = new UpdateStackRequest();
req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM);
if (templateBody != null && !templateBody.isEmpty()) {
req.setTemplateBody(templateBody);
} else if (templateUrl != null && !templateUrl.isEmpty()) {
req.setTemplateURL(templateUrl);
} else {
req.setUsePreviousTemplate(true);
}
req.withParameters(params).withTags(tags).withRoleARN(roleArn);
this.client.updateStack(req);
new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackUpdateComplete(), pollIntervallMillis);
this.listener.getLogger().format("Updated CloudFormation stack %s %n", this.stack);
} catch (AmazonCloudFormationException e) {
if (e.getMessage().contains("No updates are to be performed")) {
this.listener.getLogger().format("No updates were needed for CloudFormation stack %s %n", this.stack);
return;
}
this.listener.getLogger().format("Failed to update CloudFormation stack %s %n", this.stack);
throw e;
}
}
use of com.amazonaws.services.cloudformation.model.AmazonCloudFormationException in project pipeline-aws-plugin by jenkinsci.
the class CFNValidateStepTests method validateWithUrlFailure.
@Test
public void validateWithUrlFailure() throws Exception {
WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
AmazonCloudFormationException ex = new AmazonCloudFormationException("invalid template");
Mockito.when(this.cloudFormation.validateTemplate(Mockito.any(ValidateTemplateRequest.class))).thenThrow(ex);
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " cfnValidate(url: 'foo')" + "}\n", true));
this.jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0));
ArgumentCaptor<ValidateTemplateRequest> captor = ArgumentCaptor.forClass(ValidateTemplateRequest.class);
Mockito.verify(this.cloudFormation).validateTemplate(captor.capture());
Assertions.assertThat(captor.getValue()).isEqualTo(new ValidateTemplateRequest().withTemplateURL("foo"));
}
use of com.amazonaws.services.cloudformation.model.AmazonCloudFormationException in project pipeline-aws-plugin by jenkinsci.
the class EventPrinter method waitAndPrintEvents.
private void waitAndPrintEvents(String stack, long pollIntervalMillis, BasicFuture<AmazonWebServiceRequest> waitResult) throws ExecutionException {
Date startDate = new Date();
String lastEventId = null;
this.printLine();
this.printStackName(stack);
this.printLine();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
if (pollIntervalMillis > 0) {
while (!waitResult.isDone()) {
try {
DescribeStackEventsResult result = this.client.describeStackEvents(new DescribeStackEventsRequest().withStackName(stack));
List<StackEvent> stackEvents = new ArrayList<>();
for (StackEvent event : result.getStackEvents()) {
if (event.getEventId().equals(lastEventId) || event.getTimestamp().before(startDate)) {
break;
}
stackEvents.add(event);
}
if (!stackEvents.isEmpty()) {
Collections.reverse(stackEvents);
for (StackEvent event : stackEvents) {
this.printEvent(sdf, event);
this.printLine();
}
lastEventId = stackEvents.get(stackEvents.size() - 1).getEventId();
}
} catch (AmazonCloudFormationException e) {
// suppress and continue
}
try {
Thread.sleep(pollIntervalMillis);
} catch (InterruptedException e) {
// suppress and continue
}
}
}
try {
waitResult.get();
} catch (InterruptedException e) {
this.listener.getLogger().format("Failed to wait for CFN action to complete: %s", e.getMessage());
}
}
Aggregations