Search in sources :

Example 6 with StackCancellationCheck

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);
                }
            }
        }
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) StackCancellationCheck(com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck) AmazonServiceException(com.amazonaws.AmazonServiceException) ArrayList(java.util.ArrayList) List(java.util.List) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 7 with 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);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) StackCancellationCheck(com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck) AmazonRdsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient) ModifyDBInstanceRequest(com.amazonaws.services.rds.model.ModifyDBInstanceRequest) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest)

Example 8 with StackCancellationCheck

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);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) StopDBInstanceRequest(com.amazonaws.services.rds.model.StopDBInstanceRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) StackCancellationCheck(com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck) AmazonRdsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest)

Example 9 with StackCancellationCheck

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);
    }
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) StackCancellationCheck(com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck) DeleteStackRequest(com.amazonaws.services.cloudformation.model.DeleteStackRequest) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)

Aggregations

StackCancellationCheck (com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck)9 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)6 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)4 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)4 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)3 AmazonRdsClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient)3 List (java.util.List)3 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)2 CloudFormationTemplateBuilder (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder)2 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DeleteStackRequest (com.amazonaws.services.cloudformation.model.DeleteStackRequest)1 CREATE_FAILED (com.amazonaws.services.cloudformation.model.ResourceStatus.CREATE_FAILED)1 ModifyDBInstanceRequest (com.amazonaws.services.rds.model.ModifyDBInstanceRequest)1 StartDBInstanceRequest (com.amazonaws.services.rds.model.StartDBInstanceRequest)1 StopDBInstanceRequest (com.amazonaws.services.rds.model.StopDBInstanceRequest)1