Java Code Examples for com.amazonaws.services.cloudformation.AmazonCloudFormation#deleteStack()

The following examples show how to use com.amazonaws.services.cloudformation.AmazonCloudFormation#deleteStack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AWSProvider.java    From testgrid with Apache License 2.0 5 votes vote down vote up
/**
 * This method releases the provisioned AWS infrastructure.
 *
 * @param script            the script config
 * @param inputs
 * @return true or false to indicate the result of destroy operation.
 * @throws TestGridInfrastructureException when AWS error occurs in deletion process.
 * @throws InterruptedException            when there is an interruption while waiting for the result.
 */
private boolean doRelease(Script script, Properties inputs, TestPlan testPlan)
        throws TestGridInfrastructureException, InterruptedException, TestGridDAOException {
    Path configFilePath;
    String stackName = script.getName();
    String region = inputs.getProperty(AWS_REGION_PARAMETER);
    configFilePath = TestGridUtil.getConfigFilePath();
    AmazonCloudFormation stackdestroy = AmazonCloudFormationClientBuilder.standard()
            .withCredentials(new PropertiesFileCredentialsProvider(configFilePath.toString()))
            .withRegion(region)
            .build();
    DeleteStackRequest deleteStackRequest = new DeleteStackRequest();
    deleteStackRequest.setStackName(stackName);
    stackdestroy.deleteStack(deleteStackRequest);
    logger.info(StringUtil.concatStrings("Stack : ", stackName, " is handed over for deletion!"));

    //Notify AWSResourceManager about stack destruction to release acquired resources
    AWSResourceManager awsResourceManager = new AWSResourceManager();
    awsResourceManager.notifyStackDeletion(testPlan, script, region);

    boolean waitForStackDeletion = Boolean
            .parseBoolean(getProperty(ConfigurationProperties.WAIT_FOR_STACK_DELETION));
    if (waitForStackDeletion) {
        logger.info(StringUtil.concatStrings("Waiting for stack : ", stackName, " to delete.."));
        Waiter<DescribeStacksRequest> describeStacksRequestWaiter = new
                AmazonCloudFormationWaiters(stackdestroy).stackDeleteComplete();
        try {
            describeStacksRequestWaiter.run(new WaiterParameters<>(new DescribeStacksRequest()
                    .withStackName(stackName)));
        } catch (WaiterUnrecoverableException e) {

            throw new TestGridInfrastructureException("Error occurred while waiting for Stack :"
                                                      + stackName + " deletion !");
        }
    }
    return true;
}
 
Example 2
Source File: DeleteStackAction.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
/**
 * Creates AWS Cloud Formation Stack in sync mode using AWS Java SDK
 *
 * @param identity          Access key associated with your Amazon AWS or IAM account.
 *                          Example: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
 * @param credential        Secret access key ID associated with your Amazon AWS or IAM account.
 * @param proxyHost         Optional - proxy server used to connect to Amazon API. If empty no proxy will be used.
 *                          Default: ""
 * @param proxyPort         Optional - proxy server port. You must either specify values for both proxyHost and
 *                          proxyPort inputs or leave them both empty.
 *                          Default: ""
 * @param proxyUsername     Optional - proxy server user name.
 *                          Default: ""
 * @param proxyPassword     Optional - proxy server password associated with the proxyUsername input value.
 *                          Default: ""
 * @param region            AWS region name
 *                          Example: "eu-central-1"
 * @param stackName         Stack name to delete
 *                          Example: "MyStack"
 * @return                  A map with strings as keys and strings as values that contains: outcome of the action, returnCode of the
 *                          operation, or failure message and the exception if there is one
 */
@Action(name = "Delete AWS Cloud Formation Stack",
        outputs = {
                @Output(Outputs.RETURN_CODE),
                @Output(Outputs.RETURN_RESULT),
                @Output(Outputs.EXCEPTION)
        },
        responses = {
                @Response(text = Outputs.SUCCESS, field = Outputs.RETURN_CODE, value = Outputs.SUCCESS_RETURN_CODE,
                        matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED),
                @Response(text = Outputs.FAILURE, field = Outputs.RETURN_CODE, value = Outputs.FAILURE_RETURN_CODE,
                        matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR)
        }
)
public Map<String, String> execute(
        @Param(value = IDENTITY,   required = true)  String identity,
        @Param(value = CREDENTIAL, required = true, encrypted = true)  String credential,
        @Param(value = REGION,     required = true)  String region,
        @Param(value = PROXY_HOST)                   String proxyHost,
        @Param(value = PROXY_PORT)                   String proxyPort,
        @Param(value = PROXY_USERNAME)               String proxyUsername,
        @Param(value = PROXY_PASSWORD)               String proxyPassword,
        @Param(value = CONNECT_TIMEOUT)              String connectTimeoutMs,
        @Param(value = EXECUTION_TIMEOUT)            String execTimeoutMs,
        @Param(value = STACK_NAME, required = true)  String stackName) {

    proxyPort = defaultIfEmpty(proxyPort, DefaultValues.PROXY_PORT);
    connectTimeoutMs = defaultIfEmpty(connectTimeoutMs, DefaultValues.CONNECT_TIMEOUT);
    execTimeoutMs = defaultIfEmpty(execTimeoutMs, DefaultValues.EXEC_TIMEOUT);

    try {
        AmazonCloudFormation stackBuilder = CloudFormationClientBuilder.getCloudFormationClient(identity, credential, proxyHost, proxyPort, proxyUsername, proxyPassword, connectTimeoutMs, execTimeoutMs, region);

        // Delete the stack
        DeleteStackRequest deleteRequest = new DeleteStackRequest()
                .withStackName(stackName);

        DeleteStackResult result = stackBuilder.deleteStack(deleteRequest);
        return OutputUtilities.getSuccessResultsMap(result.toString());
    } catch (Exception e) {
        return OutputUtilities.getFailureResultsMap(e);
    }
}