use of com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck in project cloudbreak by hortonworks.
the class AwsDownscaleService method waitForTerminateInstances.
private void waitForTerminateInstances(Long stackId, List<String> instanceIds, AmazonEc2Client amazonEC2Client) {
LOGGER.debug("Polling instance until terminated. [stack: {}, instances: {}]", stackId, instanceIds);
Waiter<DescribeInstancesRequest> instanceTerminatedWaiter = amazonEC2Client.waiters().instanceTerminated();
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(stackId);
try {
waitTermination(instanceIds, instanceTerminatedWaiter, stackCancellationCheck);
} catch (CloudConnectorException e) {
LOGGER.info("Wait termination failed, lets check if it is because instance was not found", e);
if (e.getCause() instanceof AmazonServiceException) {
if (!INSTANCE_NOT_FOUND_ERROR_CODE.equals(((AmazonServiceException) e.getCause()).getErrorCode())) {
throw e;
} else {
LOGGER.info("Instance was not found, lets wait for others");
List<String> runningInstanceIds = instanceIds.stream().filter(instanceId -> !e.getCause().getMessage().contains(instanceId)).collect(Collectors.toList());
LOGGER.info("Running instances on AWS to check: {}", runningInstanceIds);
if (!runningInstanceIds.isEmpty()) {
waitTermination(runningInstanceIds, instanceTerminatedWaiter, stackCancellationCheck);
}
}
}
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck in project cloudbreak by hortonworks.
the class AwsRdsModifyService method disableDeleteProtection.
public void disableDeleteProtection(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException {
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonRdsClient rdsClient = awsClient.createRdsClient(credentialView, regionName);
String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId();
ModifyDBInstanceRequest modifyDBInstanceRequest = new ModifyDBInstanceRequest();
modifyDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier);
modifyDBInstanceRequest.setDeletionProtection(false);
LOGGER.debug("RDS modify request to disable delete protection for DB: {}", dbInstanceIdentifier);
try {
rdsClient.modifyDBInstance(modifyDBInstanceRequest);
} catch (RuntimeException ex) {
throw new CloudConnectorException(ex.getMessage(), ex);
}
Waiter<DescribeDBInstancesRequest> rdsWaiter = customAmazonWaiterProvider.getDbInstanceModifyWaiter(rdsClient);
DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier);
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck);
LOGGER.debug("RDS delete protection is disabled for DB Instance ID: {}", dbInstanceIdentifier);
}
use of com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck in project cloudbreak by hortonworks.
the class AwsRdsStopService method stop.
public void stop(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException {
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonRdsClient rdsClient = awsClient.createRdsClient(credentialView, regionName);
String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId();
StopDBInstanceRequest stopDBInstanceRequest = new StopDBInstanceRequest();
stopDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier);
LOGGER.debug("RDS stop request");
try {
rdsClient.stopDBInstance(stopDBInstanceRequest);
} catch (RuntimeException ex) {
throw new CloudConnectorException(ex.getMessage(), ex);
}
Waiter<DescribeDBInstancesRequest> rdsWaiter = customAmazonWaiterProvider.getDbInstanceStopWaiter(rdsClient);
DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier);
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck, "RDS stop failed");
LOGGER.debug("RDS stop process finished. DB Instance ID: {}", dbInstanceIdentifier);
}
use of com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck in project cloudbreak by hortonworks.
the class AwsRdsTerminateService method initiateCFTemplateDeletion.
private void initiateCFTemplateDeletion(AuthenticatedContext ac, String cFStackName, AwsCredentialView credentialView, String regionName) {
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
boolean exists = retryService.testWith2SecDelayMax15Times(() -> cfStackUtil.isCfStackExists(cfClient, cFStackName));
if (exists) {
DeleteStackRequest deleteStackRequest = awsStackRequestHelper.createDeleteStackRequest(cFStackName);
cfClient.deleteStack(deleteStackRequest);
LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId());
Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfClient.waiters().stackDeleteComplete();
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest).withPollingStrategy(getBackoffCancellablePollingStrategy(stackCancellationCheck));
stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters);
}
}
Aggregations