private void deleteFailedCreate(final String stackName, AmazonCloudFormation cf, int statusPollingIntervalMs) { { // delete an application in ROLLBACK_COMPLETE status ListStacksResult r = cf.listStacks(); r.getStackSummaries() // .stream() // .filter(x -> x.getStackName().equals(stackName)) // .limit(1) // .filter(x -> StackStatus.ROLLBACK_COMPLETE.toString().equals(x.getStackStatus())) // .forEach(x -> { log.info("Deleting stack with status " + x.getStackStatus()); // cf.deleteStack(new DeleteStackRequest().withStackName(stackName)); waitForCompletion(cf, stackName, statusPollingIntervalMs, log); }); } }
@Override protected void after() { this.cloudFormation.deleteStack(new DeleteStackRequest() .withStackName(this.stackName)); try { waitForCompletion(); } catch (InterruptedException e) { // Ignore the InterruptedException } finally { System.clearProperty("cloud.aws.credentials.accessKey"); System.clearProperty("cloud.aws.credentials.secretKey"); } }
@Override public void removeClusterInfrastructure() { autoScaling.deletePolicy(new DeletePolicyRequest().withAutoScalingGroupName(getAutoScalingGroup().getAutoScalingGroupName()).withPolicyName(SCALE_UP_POLICY)); autoScaling.deletePolicy(new DeletePolicyRequest().withAutoScalingGroupName(getAutoScalingGroup().getAutoScalingGroupName()).withPolicyName(SCALE_DOWN_POLICY)); cloudWatch.deleteAlarms(new DeleteAlarmsRequest().withAlarmNames(ESS_OVERLOAD_ALARM, ESS_IDLE_ALARM)); // CloudWatch metrics are stored for two weeks. Old data will be removed automatically. amazonSQS.deleteQueue(new DeleteQueueRequest().withQueueUrl(ESS_QUEUE_NAME)); cloudFormation.deleteStack(new DeleteStackRequest().withStackName(SystemUtils.getCloudFormationStackName())); }
private DescribeStackResourcesResult getStackResources(String stackName) throws InterruptedException, IOException { try { DescribeStacksResult describeStacksResult = this.amazonCloudFormationClient.describeStacks(new DescribeStacksRequest().withStackName(stackName)); for (Stack stack : describeStacksResult.getStacks()) { if (isAvailable(stack)) { return this.amazonCloudFormationClient.describeStackResources(new DescribeStackResourcesRequest().withStackName(stack.getStackName())); } if (isError(stack)) { if (this.stackCreatedByThisInstance) { throw new IllegalArgumentException("Could not create stack"); } this.amazonCloudFormationClient.deleteStack(new DeleteStackRequest().withStackName(stack.getStackName())); return getStackResources(stackName); } if (isInProgress(stack)) { //noinspection BusyWait Thread.sleep(5000L); return getStackResources(stackName); } } } catch (AmazonClientException e) { String templateBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource(TEMPLATE_PATH).getInputStream())); this.amazonCloudFormationClient.createStack(new CreateStackRequest().withTemplateBody(templateBody).withOnFailure(OnFailure.DELETE). withStackName(stackName).withTags(new Tag().withKey("tag1").withValue("value1")). withParameters(new Parameter().withParameterKey("RdsPassword").withParameterValue(this.rdsPassword))); this.stackCreatedByThisInstance = true; } return getStackResources(stackName); }
public void execute() { checkParams(); AmazonEC2Client ec2Client = getOrCreateClient(AmazonEC2Client.class); ec2Client .deleteKeyPair(new DeleteKeyPairRequest().withKeyName(keyName)); AmazonCloudFormationClient cloudFormationClient = getOrCreateClient(AmazonCloudFormationClient.class); cloudFormationClient.deleteStack(new DeleteStackRequest() .withStackName(stackName)); }
@AfterSuite @Parameters({ "regionName", "vpcStackName" }) public void deleteNetwork(String regionName, @Optional("it-vpc-stack") String vpcStackName) { AmazonCloudFormationClient client = new AmazonCloudFormationClient(); client.setRegion(RegionUtils.getRegion(regionName)); client.deleteStack(new DeleteStackRequest().withStackName(vpcStackName)); }
private void requestDeletion(List<String> deletionList) { for(String stackName : deletionList) { DeleteStackRequest request = new DeleteStackRequest(); request.setStackName(stackName); cfnClient.deleteStack(request); logger.info("Requested deletion of " + stackName); } }
public void deleteStack(String stackName) { LOG.info("Delete stack '{}'", stackName); cloudFormation.deleteStack(new DeleteStackRequest().withStackName(stackName)); }
@Override public void destroy() throws Exception { if (this.stackCreatedByThisInstance) { this.amazonCloudFormationClient.deleteStack(new DeleteStackRequest().withStackName(DEFAULT_STACK_NAME)); } }
/** */ public Stack stackDelete() throws Exception { final DeleteStackRequest request = new DeleteStackRequest(); request.withStackName(name); amazonClient.deleteStack(request); final Stack stack = waitForStackDelete(); return stack; }
/** * Deletes an existing stack by name. * * @param stackId Stack ID. */ public void deleteStack(final String stackId) { final DeleteStackRequest request = new DeleteStackRequest().withStackName(stackId); cloudFormationClient.deleteStack(request); }