Java Code Examples for com.amazonaws.services.cloudformation.model.DescribeStacksRequest#setStackName()

The following examples show how to use com.amazonaws.services.cloudformation.model.DescribeStacksRequest#setStackName() . 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: CloudFormationClient.java    From herd-mdl with Apache License 2.0 6 votes vote down vote up
public CFTStackInfo getStackInfo() throws Exception {
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
    describeStacksRequest.setStackName(stackName);

    List<Stack> stacks = amazonCloudFormation.describeStacks(describeStacksRequest).getStacks();
    CFTStackInfo cftStackInfo = null;
    if (!stacks.isEmpty()) {
        for (Stack stack : stacks) {
            cftStackInfo = new CFTStackInfo(stack);
        }
    }
    else {
        throw new Exception("Stack not found " + stackName);
    }
    return cftStackInfo;
}
 
Example 2
Source File: AWSProvider.java    From testgrid with Apache License 2.0 6 votes vote down vote up
private static Properties getCloudformationOutputs(AmazonCloudFormation cloudFormation, CreateStackResult stack) {
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
    describeStacksRequest.setStackName(stack.getStackId());
    final DescribeStacksResult describeStacksResult = cloudFormation
            .describeStacks(describeStacksRequest);

    Properties outputProps = new Properties();
    for (Stack st : describeStacksResult.getStacks()) {
        StringBuilder outputsStr = new StringBuilder("Infrastructure/Deployment outputs {\n");
        for (Output output : st.getOutputs()) {
            outputProps.setProperty(output.getOutputKey(), output.getOutputValue());
            outputsStr.append(output.getOutputKey()).append("=").append(output.getOutputValue()).append("\n");
        }
        //Log cfn outputs
        logger.info(outputsStr.toString() + "\n}");
    }
    return outputProps;
}
 
Example 3
Source File: CloudFormationClient.java    From herd-mdl with Apache License 2.0 5 votes vote down vote up
public boolean stackExists(String stackName){
    LOGGER.info("Check if stack exists or not :" + stackName);
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
    describeStacksRequest.setStackName(stackName);
    try {
        List<Stack> stacks = amazonCloudFormation.describeStacks(describeStacksRequest).getStacks();
    } catch (AmazonCloudFormationException e) {
        if (e.getErrorCode().equals("ValidationError")){
            return false;
        }
    }
    return true;
}
 
Example 4
Source File: CloudFormationClient.java    From herd-mdl with Apache License 2.0 5 votes vote down vote up
public Stack getStackByName(String stackName) {
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
    describeStacksRequest.setStackName(stackName);
    List<Stack> stacksList = amazonCloudFormation.describeStacks(describeStacksRequest).getStacks();
    assertNotNull("stack list cannot be null", stacksList);
    assertEquals("only 1 stack is expected, but getting " + stacksList.size(), 1,
            stacksList.size());
    return stacksList.get(0);
}
 
Example 5
Source File: CloudFormationUtils.java    From amazon-kinesis-connectors with Apache License 2.0 5 votes vote down vote up
private static boolean stackExists(AmazonCloudFormation client, String stackName) {
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
    describeStacksRequest.setStackName(stackName);
    try {
        client.describeStacks(describeStacksRequest);
        return true;
    } catch (AmazonServiceException e) {
        return false;
    }
}
 
Example 6
Source File: CloudFormationUtils.java    From amazon-kinesis-connectors with Apache License 2.0 5 votes vote down vote up
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 {
        return StackStatus.fromValue(client.describeStacks(describeStacksRequest)
                .getStacks()
                .get(0)
                .getStackStatus());
    } catch (AmazonServiceException ase) {
        return null;
    }
}
 
Example 7
Source File: CloudFormationClient.java    From herd-mdl with Apache License 2.0 4 votes vote down vote up
public CFTStackStatus waitForCompletionAndGetStackStatus(AmazonCloudFormation awsCloudFormation,
        String stackId) throws InterruptedException {

    int stackStatusPollingInterval = 60 * 1000;
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
    describeStacksRequest.setStackName(stackId);

    Boolean done = false;
    String stackStatus = "UNKNOWN";
    String stackReason = "";

    System.out.print("Waiting");

    while (!done) {
        List<Stack> stacks = awsCloudFormation.describeStacks(describeStacksRequest).getStacks();
        if (stacks.isEmpty()) {
            done = true;
            stackStatus = StackStatus.DELETE_COMPLETE.toString();
            stackReason = "Stack has been deleted";
        }
        else {
            for (Stack stack : stacks) {
                if (stack.getStackStatus().equals(StackStatus.CREATE_COMPLETE.toString())
                        || stack.getStackStatus().equals(StackStatus.CREATE_FAILED.toString())
                        || stack.getStackStatus().equals(StackStatus.ROLLBACK_FAILED.toString())
                        || stack.getStackStatus().equals(StackStatus.ROLLBACK_COMPLETE.toString())
                        || stack.getStackStatus().equals(StackStatus.DELETE_COMPLETE.toString())
                        || stack.getStackStatus().equals(StackStatus.DELETE_FAILED.toString())) {
                    done = true;
                    stackStatus = stack.getStackStatus();
                    stackReason = stack.getStackStatusReason();
                }
            }
        }
        System.out.print(".");
        if (!done) {
            Thread.sleep(stackStatusPollingInterval);
        }
    }
    LOGGER.info("done");

    CFTStackStatus cftStackStatus = new CFTStackStatus(stackStatus, stackReason);
    return cftStackStatus;
}
 
Example 8
Source File: AwsIntegrationTestStackRule.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
private void waitForCompletion() throws InterruptedException {
	DescribeStacksRequest wait = new DescribeStacksRequest();
	wait.setStackName(this.stackName);
	Boolean completed = false;
	String stackStatus = "Unknown";
	String stackReason = "";

	while (!completed) {
		List<Stack> stacks = null;
		try {
			stacks = this.cloudFormation.describeStacks(wait).getStacks();
		}
		catch (Exception e) {
			logger.error("cloudFormation.describeStacks() exception", e);
		}
		if (CollectionUtils.isEmpty(stacks)) {
			completed = true;
			stackStatus = StackStatus.DELETE_COMPLETE.toString();
			stackReason = "Stack has been deleted";
		}
		else {
			for (Stack stack : stacks) {
				if (stack.getStackStatus().equals(StackStatus.CREATE_COMPLETE.toString()) ||
						stack.getStackStatus().equals(StackStatus.CREATE_FAILED.toString()) ||
						stack.getStackStatus().equals(StackStatus.ROLLBACK_FAILED.toString()) ||
						stack.getStackStatus().equals(StackStatus.DELETE_FAILED.toString())) {
					completed = true;
					stackStatus = stack.getStackStatus();
					stackReason = stack.getStackStatusReason();
				}
			}
		}

		// Not done yet so sleep for 2 seconds.
		if (!completed) {
			Thread.sleep(2000);
		}
		else {
			if (stackStatus.equals(StackStatus.CREATE_FAILED.toString())) {
				Assume.assumeTrue("The test AWS stack [" + this.stackName + "] cannot be created. Reason: " +
								stackReason, true);
			}
		}
	}
}