List of usage examples for com.amazonaws.services.cloudformation.model AmazonCloudFormationException getMessage
@Override
public String getMessage()
From source file:com.github.kaklakariada.aws.sam.service.CloudformationService.java
License:Open Source License
public boolean stackExists(String stackName) { try {//from w w w . j a v a2 s. c o m return describeStack(stackName).stream() // .peek(s -> logger.info("Found stack {}", s)) // .filter(s -> s.getStackName().equals(stackName)) // .anyMatch(s -> !s.getStackStatus().equals("REVIEW_IN_PROGRESS")); } catch (final AmazonCloudFormationException e) { if (e.getStatusCode() == 400) { logger.trace("Got exception {}", e.getMessage(), e); return false; } throw e; } }
From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java
License:Apache License
public void update(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, long pollIntervallMillis, String roleArn) throws ExecutionException { try {/*w w w . jav a2 s .c o m*/ 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; } }
From source file:de.taimos.pipeline.aws.cloudformation.EventPrinter.java
License:Apache License
private void waitAndPrintEvents(String stack, long pollIntervalMillis, BasicFuture<AmazonWebServiceRequest> waitResult) throws ExecutionException { Date startDate = new Date(); String lastEventId = null;/* www.j a va 2 s. c om*/ 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()); } }
From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPluginExtension.java
License:Apache License
public Optional<Stack> getStack(String stackName) { if (getProject().getGradle().getStartParameter().isOffline() == false) { try {//from www .j a v a 2 s . c o m DescribeStacksResult describeStacksResult = getClient() .describeStacks(new DescribeStacksRequest().withStackName(stackName)); List<Stack> stacks = describeStacksResult.getStacks(); if (stacks.isEmpty() == false) { return stacks.stream().findAny(); } } catch (AmazonCloudFormationException e) { if ("ValidationError".equals(e.getErrorCode())) { return Optional.empty(); } else { throw new GradleException(e.getMessage(), e); } } } return Optional.empty(); }
From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPluginExtension.java
License:Apache License
public List<StackResource> getStackResources(String stackName) { if (getProject().getGradle().getStartParameter().isOffline() == false) { try {// w w w. j a v a 2 s. c o m DescribeStackResourcesResult describeStackResourcesResult = getClient() .describeStackResources(new DescribeStackResourcesRequest().withStackName(stackName)); return describeStackResourcesResult.getStackResources(); } catch (AmazonCloudFormationException e) { if ("ValidationError".equals(e.getErrorCode())) { return Collections.emptyList(); } else { throw new GradleException(e.getMessage(), e); } } } logger.info("offline mode: return empty resources"); return Collections.emptyList(); }