List of usage examples for com.amazonaws.services.cloudformation AmazonCloudFormation describeStackEvents
DescribeStackEventsResult describeStackEvents(DescribeStackEventsRequest describeStackEventsRequest);
Returns all stack related events for a specified stack in reverse chronological order.
From source file:com.netflix.spinnaker.clouddriver.aws.provider.agent.AmazonCloudFormationCachingAgent.java
License:Apache License
@Override public CacheResult loadData(ProviderCache providerCache) { log.info("Describing items in {}", getAgentType()); AmazonCloudFormation cloudformation = amazonClientProvider.getAmazonCloudFormation(account, region); Collection<CacheData> stackCacheData = new ArrayList<>(); try {/* www . j av a 2 s . c o m*/ List<Stack> stacks = cloudformation.describeStacks().getStacks(); for (Stack stack : stacks) { Map<String, Object> stackAttributes = new HashMap<>(); stackAttributes.put("stackId", stack.getStackId()); stackAttributes.put("tags", stack.getTags().stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue))); stackAttributes.put("outputs", stack.getOutputs().stream() .collect(Collectors.toMap(Output::getOutputKey, Output::getOutputValue))); stackAttributes.put("stackName", stack.getStackName()); stackAttributes.put("region", region); stackAttributes.put("accountName", account.getName()); stackAttributes.put("accountId", account.getAccountId()); stackAttributes.put("stackStatus", stack.getStackStatus()); stackAttributes.put("creationTime", stack.getCreationTime()); if (stack.getStackStatus().equals("ROLLBACK_COMPLETE")) { DescribeStackEventsRequest request = new DescribeStackEventsRequest() .withStackName(stack.getStackName()); cloudformation.describeStackEvents(request).getStackEvents().stream() .filter(e -> e.getResourceStatus().equals("CREATE_FAILED")).findFirst() .map(StackEvent::getResourceStatusReason) .map(statusReason -> stackAttributes.put("stackStatusReason", statusReason)); } String stackCacheKey = Keys.getCloudFormationKey(stack.getStackId(), region, account.getName()); Map<String, Collection<String>> relationships = new HashMap<>(); relationships.put(STACKS.getNs(), Collections.singletonList(stackCacheKey)); stackCacheData.add(new DefaultCacheData(stackCacheKey, stackAttributes, relationships)); } } catch (AmazonCloudFormationException e) { log.error("Error retrieving stacks", e); } log.info("Caching {} items in {}", stackCacheData.size(), getAgentType()); HashMap<String, Collection<CacheData>> result = new HashMap<>(); result.put(STACKS.getNs(), stackCacheData); return new DefaultCacheResult(result); }
From source file:io.konig.maven.CreateCloudFormationStackAction.java
License:Apache License
private List<Output> getOutputForRequest(String stackName, AmazonCloudFormation client) throws InterruptedException, StackCreationException { int tried = 0; String maxTime = System.getProperty("stackMaxTime"); while (tried < (maxTime == null ? 1800 : Integer.parseInt(maxTime))) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.withStackName(stackName); Stack resultStack = client.describeStacks(describeStacksRequest).getStacks().get(0); StackStatus stackStatus = StackStatus.valueOf(resultStack.getStackStatus()); if (("CREATE_COMPLETE").equals(stackStatus.toString())) { return resultStack.getOutputs(); } else if (stackStatus.toString().endsWith("IN_PROGRESS")) { Thread.sleep(10000);/*from w w w.ja va2 s. c o m*/ } else { DescribeStackEventsRequest describeStackEventsRequest = new DescribeStackEventsRequest(); describeStackEventsRequest.withStackName(stackName); List<StackEvent> stackEvents = client.describeStackEvents(describeStackEventsRequest) .getStackEvents(); List<StackEvent> errorEvents = new ArrayList<StackEvent>(); for (StackEvent stackEvent : stackEvents) { if (stackEvent.getResourceStatus().equals("CREATE_FAILED")) { errorEvents.add(stackEvent); } } throw new StackCreationException(errorEvents.toString()); } tried++; } throw new RuntimeException("stack creation/deletion timed out"); }