Example usage for com.amazonaws.services.cloudformation.model StackStatus toString

List of usage examples for com.amazonaws.services.cloudformation.model StackStatus toString

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudformation.model StackStatus toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

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. j ava  2 s .co  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");
}