use of com.amazonaws.services.cloudformation.model.DeleteStackRequest in project cloudbreak by hortonworks.
the class AwsDeleteVpcTest method deleteNetwork.
@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));
}
use of com.amazonaws.services.cloudformation.model.DeleteStackRequest in project cloudbreak by hortonworks.
the class AwsResourceConnector method terminate.
@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
LOGGER.info("Deleting stack: {}", ac.getCloudContext().getId());
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
if (resources != null && !resources.isEmpty()) {
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
CloudResource stackResource = getCloudFormationStackResource(resources);
if (stackResource == null) {
return Collections.emptyList();
}
String cFStackName = stackResource.getName();
LOGGER.info("Deleting CloudFormation stack for stack: {} [cf stack id: {}]", cFStackName, ac.getCloudContext().getId());
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
try {
retryService.testWith2SecDelayMax5Times(() -> {
try {
cfClient.describeStacks(describeStacksRequest);
} catch (AmazonServiceException e) {
if (!e.getErrorMessage().contains(cFStackName + " does not exist")) {
throw e;
}
throw new ActionWentFailException("Stack not exists");
}
return Boolean.TRUE;
});
} catch (ActionWentFailException ignored) {
LOGGER.info(String.format("Stack not found with name: %s", cFStackName));
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
return Collections.emptyList();
}
resumeAutoScalingPolicies(ac, stack);
DeleteStackRequest deleteStackRequest = new DeleteStackRequest().withStackName(cFStackName);
cfClient.deleteStack(deleteStackRequest);
PollTask<Boolean> task = awsPollTaskFactory.newAwsTerminateStackStatusCheckerTask(ac, cfClient, DELETE_COMPLETE, DELETE_FAILED, ERROR_STATUSES, cFStackName);
try {
Boolean statePollerResult = task.call();
if (!task.completed(statePollerResult)) {
syncPollingScheduler.schedule(task);
}
} catch (Exception e) {
throw new CloudConnectorException(e.getMessage(), e);
}
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
deleteKeyPair(ac, stack);
} else if (resources != null) {
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
LOGGER.info("No CloudFormation stack saved for stack.");
} else {
LOGGER.info("No resources to release.");
}
return check(ac, resources);
}
Aggregations