List of usage examples for com.amazonaws.services.cloudformation AmazonCloudFormationClient describeStacks
@Override
public DescribeStacksResult describeStacks(DescribeStacksRequest request)
Returns the description for the specified stack; if no stack name was specified, then it returns the description for all the stacks created.
From source file:com.cleanenergyexperts.aws.cf.CloudFormationMojo.java
License:Apache License
protected Stack getStack(AmazonCloudFormationClient cfClient, String stackName) throws MojoExecutionException { Stack stack = null;//w w w . j a va 2 s. c o m try { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.setStackName(stackName); getLog().info("Getting Cloud Formation Stack Details..."); DescribeStacksResult describeStacksResult = cfClient.describeStacks(describeStacksRequest); if (describeStacksResult == null || describeStacksResult.getStacks() == null || describeStacksResult.getStacks().isEmpty()) { throw new MojoExecutionException("[NULL] Could Not Get Cloud Formation Stack Details"); } stack = describeStacksResult.getStacks().get(0); } catch (AmazonServiceException e) { throw new MojoExecutionException("[SERVICE] Could Not Get Cloud Formation Stack Details", e); } catch (AmazonClientException e) { throw new MojoExecutionException("[CLIENT] Could Not Get Cloud Formation Stack Details", e); } return stack; }
From source file:com.mweagle.tereus.commands.DeleteCommand.java
License:Open Source License
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({ "DM_EXIT", "OBL_UNSATISFIED_OBLIGATION" }) @Override/* w w w . ja va2 s.c o m*/ public void run() { // Get the stack, delete the stack... int exitCode = 0; final Logger logger = LogManager.getLogger(); try { final AmazonCloudFormationClient awsClient = new AmazonCloudFormationClient(); awsClient.setRegion(RegionUtils.getRegion(this.region)); final DescribeStacksRequest describeRequest = new DescribeStacksRequest().withStackName(this.stackName); final DescribeStacksResult describeResult = awsClient.describeStacks(describeRequest); logger.info(describeResult); logger.info("Deleting stack: {}", this.stackName); if (this.dryRun) { logger.info("Dry run requested (-n/--noop). Stack deletion bypassed."); } else { final DeleteStackRequest deleteRequest = new DeleteStackRequest().withStackName(this.stackName); awsClient.deleteStack(deleteRequest); } } catch (Exception ex) { logger.error(ex.getMessage()); exitCode = 1; } System.exit(exitCode); }
From source file:com.tvarit.plugin.RolesFinder.java
License:Open Source License
public RolesFinder(String projectName, AmazonCloudFormationClient amazonCloudFormationClient) { final DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.withStackName(projectName + "-infra"); describeStacksResult = amazonCloudFormationClient.describeStacks(describeStacksRequest); }
From source file:com.tvarit.plugin.StackMaker.java
License:Open Source License
public Stack makeStack(CreateStackRequest createStackRequest, AmazonCloudFormationClient amazonCloudFormationClient, Log log) throws MojoFailureException { CreateStackResult createStackResult = amazonCloudFormationClient.createStack(createStackRequest); final String stackName = createStackRequest.getStackName(); DescribeStacksResult describeStacksResult = amazonCloudFormationClient .describeStacks(new DescribeStacksRequest().withStackName(stackName)); while (describeStacksResult.getStacks().get(0).getStackStatus() .equals(StackStatus.CREATE_IN_PROGRESS.toString())) { try {/*from w w w .ja v a 2 s. c o m*/ log.info("Awaiting stack create completion!"); Thread.sleep(5000); } catch (InterruptedException e) { log.error(e); throw new RuntimeException(e); } describeStacksResult = amazonCloudFormationClient .describeStacks(new DescribeStacksRequest().withStackName(stackName)); } final Stack stack = describeStacksResult.getStacks().get(0); final String stackStatus = stack.getStackStatus(); if (!stackStatus.equals(StackStatus.CREATE_COMPLETE.toString())) { throw new MojoFailureException("Could not create infrastructure. Stack Status is: " + stackStatus + ". Please review details on the AWS console and open a new github issue on https://github.com/sdole/tvarit-maven/issues/new that is needed."); } return stack; }
From source file:jetbrains.buildServer.runner.cloudformation.AWSClient.java
License:Apache License
public void waitForCompletion(AmazonCloudFormationClient stackbuilder, String stackName) throws InterruptedException { DescribeStacksRequest wait = new DescribeStacksRequest(); wait.setStackName(stackName);/*from w w w. ja va2s .c o m*/ Boolean completed = false; String action = "CREATE"; String stackStatus = "Waiting"; String stackReason = ""; String stackId = ""; List<String> events; int len, first, last; first = 0; myListener.waitForStack(stackStatus); while (!completed) { List<Stack> stacks = stackbuilder.describeStacks(wait).getStacks(); if (stacks.isEmpty()) { completed = true; stackStatus = "NO_SUCH_STACK"; 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(); if (stack.getStackStatus().equals(StackStatus.CREATE_COMPLETE.toString())) { stackReason = "Success"; } else { stackReason = "Failure"; } stackId = stack.getStackId(); } } } //sleep for 10 seconds Thread.sleep(10000); } if (completed) { events = describeStackEvents(stackbuilder, stackName, action); for (String event : events) { myListener.waitForStack(event.toString()); } events.clear(); } myListener.waitForStack(stackStatus); if (stackReason.contains("Failure")) { myListener.createStackFailed(stackName, stackStatus, stackReason); } else { myListener.createStackFinished(stackName, stackStatus); } }
From source file:jetbrains.buildServer.runner.cloudformation.AWSClient.java
License:Apache License
public void waitForDelete(AmazonCloudFormationClient stackbuilder, String stackName) throws InterruptedException { DescribeStacksRequest wait = new DescribeStacksRequest(); wait.setStackName(stackName);//w w w. j a v a2 s .co m String stackStatus; String stackReason; String action = "DELETE"; Boolean delete = false; List<String> events; while (!delete) { List<Stack> stacks = stackbuilder.describeStacks(wait).getStacks(); if (stacks.isEmpty()) { delete = true; stackStatus = "NO_SUCH_STACK"; stackReason = "Stack has been deleted"; } else { myListener.debugLog("From the wait for delete"); events = describeStackEvents(stackbuilder, stackName, action); for (String event : events) { myListener.waitForStack(event.toString()); } Thread.sleep(10000); events.clear(); } } stackStatus = "done"; stackReason = "Delete Complete"; myListener.waitForStack(stackStatus); myListener.createStackFinished(stackName, stackStatus); }