Example usage for com.amazonaws.services.cloudformation.model ExecuteChangeSetRequest ExecuteChangeSetRequest

List of usage examples for com.amazonaws.services.cloudformation.model ExecuteChangeSetRequest ExecuteChangeSetRequest

Introduction

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

Prototype

ExecuteChangeSetRequest

Source Link

Usage

From source file:com.github.kaklakariada.aws.sam.service.CloudformationService.java

License:Open Source License

public void executeChangeSet(String changeSetArn) {
    cloudFormation.executeChangeSet(new ExecuteChangeSetRequest().withChangeSetName(changeSetArn));
    logger.lifecycle("Executing change set {}", changeSetArn);
}

From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java

License:Apache License

public void executeChangeSet(String changeSetName, long pollIntervallMillis) throws ExecutionException {
    if (!this.changeSetHasChanges(changeSetName) || !this.exists()) {
        // If the change set has no changes or the stack was not prepared we should simply delete it.
        this.listener.getLogger().format("Deleting empty change set %s for stack %s %n", changeSetName,
                this.stack);
        DeleteChangeSetRequest req = new DeleteChangeSetRequest().withChangeSetName(changeSetName)
                .withStackName(this.stack);
        this.client.deleteChangeSet(req);
    } else {/*  w w  w  .ja va  2 s.c om*/
        this.listener.getLogger().format("Executing change set %s for stack %s %n", changeSetName, this.stack);

        final Waiter<DescribeStacksRequest> waiter;
        if (this.isInReview()) {
            waiter = this.client.waiters().stackCreateComplete();
        } else {
            waiter = this.client.waiters().stackUpdateComplete();
        }

        ExecuteChangeSetRequest req = new ExecuteChangeSetRequest().withChangeSetName(changeSetName)
                .withStackName(this.stack);
        this.client.executeChangeSet(req);
        new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, waiter,
                pollIntervallMillis);
        this.listener.getLogger().format("Executed change set %s for stack %s %n", changeSetName, this.stack);
    }
}

From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationExecuteChangeSetTask.java

License:Apache License

@TaskAction
public void executeChangeSet() throws InterruptedException, IOException {
    // to enable conventionMappings feature
    String stackName = getStackName();

    if (stackName == null) {
        throw new GradleException("stackName is not specified");
    }//from www .  ja  v a 2 s  .  c om

    AmazonCloudFormationPluginExtension ext = getProject().getExtensions()
            .getByType(AmazonCloudFormationPluginExtension.class);
    AmazonCloudFormation cfn = ext.getClient();

    try {
        DescribeStacksResult describeStackResult = cfn
                .describeStacks(new DescribeStacksRequest().withStackName(stackName));
        Stack stack = describeStackResult.getStacks().get(0);

        if (stableStatuses.contains(stack.getStackStatus())) {
            Optional<ChangeSetSummary> summary = getLatestChangeSetSummary(cfn);
            String changeSetName = summary
                    .orElseThrow(
                            () -> new GradleException("ChangeSet for stack " + stackName + " was not found."))
                    .getChangeSetName();
            ExecuteChangeSetRequest req = new ExecuteChangeSetRequest().withStackName(stackName)
                    .withChangeSetName(changeSetName);
            cfn.executeChangeSet(req);
            getLogger().info("ChangeSet is executed : {}, {}", stackName, changeSetName);
        } else {
            throw new GradleException("invalid status for update: " + stack.getStackStatus());
        }
    } catch (AmazonServiceException e) {
        if (e.getMessage().contains("does not exist")) {
            getLogger().warn("stack {} not found", stackName);
        } else if (e.getMessage().contains("No updates are to be performed.")) {
            getLogger().trace(e.getMessage());
        } else {
            throw e;
        }
    }

}