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

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

Introduction

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

Prototype

public static StackStatus fromValue(String value) 

Source Link

Document

Use this in place of valueOf.

Usage

From source file:br.com.ingenieux.mojo.cloudformation.cmd.WaitForStackCommand.java

License:Apache License

public void execute() throws Exception {
    Set<StackEvent> events = new TreeSet<>((o1, o2) -> {
        return o1.getEventId().compareTo(o2.getEventId());
    });// w  ww.j a  v a 2 s.  c o  m

    boolean done = false;

    Date timeoutsAt = new Date(System.currentTimeMillis() + 60000L * ctx.getTimeoutMins());

    do {
        boolean timedOut = !timeoutsAt.after(new Date(System.currentTimeMillis()));

        if (timedOut)
            throw new IllegalStateException("Timed Out");

        {
            final DescribeStackEventsRequest req = new DescribeStackEventsRequest()
                    .withStackName(ctx.getStackId());
            String nextToken = null;

            do {
                req.withNextToken(nextToken);

                Optional<DescribeStackEventsResult> stackEvents = getDescribeStackEventsResult(req);

                if (!stackEvents.isPresent()) {
                    return;
                } else {
                    for (StackEvent e : stackEvents.get().getStackEvents()) {
                        if (!events.contains(e)) {
                            ctx.getNotifier().info("" + e);

                            events.add(e);
                        }
                    }
                }

            } while (null != nextToken);
        }

        {
            final DescribeStacksResult stacks = ctx.getClient()
                    .describeStacks(new DescribeStacksRequest().withStackName(ctx.getStackId()));

            Optional<Stack> foundStack = stacks.getStacks().stream().filter(
                    stack -> ctx.getStatusesToMatch().contains(StackStatus.fromValue(stack.getStackStatus())))
                    .findFirst();

            done = foundStack.isPresent();
        }

        if (!done) {
            Thread.sleep(15000);
        }

    } while (!done);
}

From source file:br.com.ingenieux.mojo.cloudformation.WaitForStackMojo.java

License:Apache License

public void setStatusesToMatch(String statusesToMatch) {
    this.statusesToMatch = new LinkedHashSet<>();

    this.statusesToMatch.addAll(Arrays.asList(statusesToMatch.split(",")).stream().map(this::extractNVPair)
            .map(x -> StackStatus.fromValue(x.getValue().toUpperCase())).collect(Collectors.toList()));
}

From source file:com.carrotgarden.maven.aws.cfn.CarrotCloudForm.java

License:BSD License

private Stack waitForStackCreate() throws Exception {

    final long timeStart = System.currentTimeMillis();

    while (true) {

        if (isTimeoutPending(timeStart)) {
            return newStackWithStatus(StackStatus.CREATE_FAILED, "stack create timeout");
        }/*from w ww .  ja va2 s  .c  om*/

        Stack stack = null;
        try {
            stack = findStack();
        } catch (final Exception e) {
            return newStackWithStatus(StackStatus.CREATE_FAILED, e.toString());
        }

        if (!isStackValid(stack)) {
            return newStackWithStatus(StackStatus.CREATE_FAILED, "stack create invalid/missing");
        }

        final StackStatus status = StackStatus.fromValue(stack.getStackStatus());

        switch (status) {
        case CREATE_IN_PROGRESS:
            final long timeCurrent = System.currentTimeMillis();
            final long timeDiff = timeCurrent - timeStart;
            logger.info("stack create in progress; time=" + timeDiff / 1000);
            sleep();
            continue;
        case CREATE_COMPLETE:
            logger.info("stack create success");
            printStackEvents();
            return stack;
        default:
            logger.error("stack create failure");
            return stack;
        }

    }

}

From source file:com.carrotgarden.maven.aws.cfn.CarrotCloudForm.java

License:BSD License

private Stack waitForStackDelete() throws Exception {

    final long timeStart = System.currentTimeMillis();

    while (true) {

        if (isTimeoutPending(timeStart)) {
            return newStackWithStatus(StackStatus.DELETE_FAILED, "stack delete timeout");
        }/*  w w w  . j ava  2s . c  om*/

        Stack stack = null;
        try {
            stack = findStack();
        } catch (final Exception e) {
            return newStackWithStatus(StackStatus.DELETE_FAILED, e.toString());
        }

        if (!isStackValid(stack)) {
            return newStackWithStatus(StackStatus.DELETE_COMPLETE, "stack delete invalid/missing");
        }

        final StackStatus status = StackStatus.fromValue(stack.getStackStatus());

        switch (status) {
        case DELETE_IN_PROGRESS:
            final long timeCurrent = System.currentTimeMillis();
            final long timeDiff = timeCurrent - timeStart;
            logger.info("stack delete in progress; time=" + timeDiff / 1000);
            sleep();
            continue;
        case DELETE_COMPLETE:
            logger.info("stack delete complete");
            printStackEvents();
            return stack;
        default:
            logger.error("stack delete failed");
            return stack;
        }

    }

}

From source file:com.carrotgarden.maven.aws.cfn.CarrotCloudForm.java

License:BSD License

private Stack waitForStackUpdate() throws Exception {

    final long timeStart = System.currentTimeMillis();

    while (true) {

        if (isTimeoutPending(timeStart)) {
            return newStackWithStatus(StackStatus.UPDATE_ROLLBACK_FAILED, "stack update timeout");
        }//from  w ww  . jav a2 s.  c  om

        Stack stack = null;
        try {
            stack = findStack();
        } catch (final Exception e) {
            return newStackWithStatus(StackStatus.UPDATE_ROLLBACK_FAILED, e.toString());
        }

        if (!isStackValid(stack)) {
            return newStackWithStatus(StackStatus.UPDATE_ROLLBACK_FAILED, "stack update invalid/missing");
        }

        final StackStatus status = StackStatus.fromValue(stack.getStackStatus());

        switch (status) {
        case UPDATE_IN_PROGRESS:
            final long timeCurrent = System.currentTimeMillis();
            final long timeDiff = timeCurrent - timeStart;
            logger.info("stack update in progress; time=" + timeDiff / 1000);
            sleep();
            continue;
        case UPDATE_COMPLETE:
            logger.info("stack update complete");
            printStackEvents();
            return stack;
        default:
            logger.error("stack updtae failed");
            return stack;
        }

    }

}

From source file:com.carrotgarden.maven.aws.cfn.CloudFormCreateStack.java

License:BSD License

/**
 * {@inheritDoc}/*from  w  w w .  j  av a2 s .c om*/
 */
@Override
public void execute() throws MojoFailureException {

    try {

        getLog().info("stack create init [" + stackName() + "]");

        final Properties stackInputProps = Util.propsLoad(getLog(), stackPropertiesInputFile);

        final Map<String, String> pluginProps = mergePluginProps(stackInputProps, stackInputParams);

        final Map<String, String> stackTemplateParams = loadTemplateParameters(stackTemplateFile, pluginProps);

        final CarrotCloudForm formation = newCloudFormation(stackTemplateFile, stackTemplateParams);

        formation.logParamList();

        final Stack stack = formation.stackCreate();

        final StackStatus status = StackStatus.fromValue(stack.getStackStatus());

        switch (status) {
        case CREATE_COMPLETE:
            break;
        default:
            throw new IllegalStateException("stack create failed");
        }

        //

        getLog().info("stack create stack=\n" + stack);

        getLog().info("stack create output:");

        final List<Output> outputList = stack.getOutputs();

        final Properties outputProps = new Properties();

        for (final Output output : outputList) {

            final String key = output.getOutputKey();
            final String value = output.getOutputValue();

            outputProps.put(key, value);

            getLog().info("\t" + key + "=" + value);

        }

        if (stackIsInjectOutputProperties) {

            project().getProperties().putAll(outputProps);

            getLog().info("stack create output is injected in project.properties]");

        }

        if (stackIsPersistOutputProperties) {

            Util.propsSave(getLog(), outputProps, stackPropertiesOutputFile);

            getLog().info("stack create output is persisted to : " + stackPropertiesOutputFile);

        }

        //

        getLog().info("stack create done [" + stackName() + "]");

    } catch (final Exception e) {

        throw new MojoFailureException("bada-boom", e);

    }

}

From source file:com.carrotgarden.maven.aws.cfn.CloudFormDeleteStack.java

License:BSD License

/**
 * {@inheritDoc}// w w  w  . ja va  2s .  com
 */
@Override
public void execute() throws MojoFailureException {

    try {

        getLog().info("stack delete init [" + stackName() + "]");

        final CarrotCloudForm formation = newCloudFormation(null, null);

        final Stack stack = formation.stackDelete();

        final StackStatus status = StackStatus.fromValue(stack.getStackStatus());

        switch (status) {
        case DELETE_COMPLETE:
            break;
        default:
            throw new IllegalStateException("stack delete failed");
        }

        getLog().info("stack delete stack=\n" + stack);

        getLog().info("stack delete done [" + stackName() + "]");

    } catch (final Exception e) {

        throw new MojoFailureException("bada-boom", e);

    }

}

From source file:com.kinesisboard.amazonaws.utils.CloudFormationUtils.java

License:Open Source License

private static StackStatus stackStatus(AmazonCloudFormation client, String stackName) {
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
    describeStacksRequest.setStackName(stackName);
    // describeStacks (with stack name specified) will return list of size 1 if found
    // and throw AmazonServiceException if no stack with that name exists
    try {/*from  w  ww  .jav  a2  s .c  o m*/
        return StackStatus
                .fromValue(client.describeStacks(describeStacksRequest).getStacks().get(0).getStackStatus());
    } catch (AmazonServiceException ase) {
        return null;
    }
}

From source file:com.nike.cerberus.service.CloudFormationService.java

License:Apache License

/**
 * Returns the current status of the named stack.
 *
 * @param stackId Stack ID./*  w  ww.j a v a  2 s  .c  o m*/
 * @return Stack status data.
 */
@Nullable
public StackStatus getStackStatus(final String stackId) {
    final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId);

    try {
        final DescribeStacksResult result = cloudFormationClient.describeStacks(request);

        if (result.getStacks().size() > 0) {
            final String status = result.getStacks().get(0).getStackStatus();

            if (StringUtils.isNotBlank(status)) {
                return StackStatus.fromValue(status);
            }
        }
    } catch (final AmazonServiceException ase) {
        // Stack doesn't exist, just return with no status
        if (ase.getStatusCode() != 400) {
            throw ase;
        }
    }

    return null;
}