@Test public void shouldWrapRuntineExceptionWithCloudConnectorException() { when(awsClient.createCloudFormationRetryClient(Mockito.any(AwsCredentialView.class), Mockito.eq(REGION))).thenThrow(new RuntimeException()); Assertions.assertThrows(CloudConnectorException.class, () -> victim.terminate(authenticatedContext, null, false, persistenceNotifier, Collections.emptyList())); }
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force, PersistenceNotifier persistenceNotifier, List<CloudResource> resources) throws ExecutionException, TimeoutException, InterruptedException { String cFStackName = cfStackUtil.getCfStackName(ac); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); try { AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(credentialView, regionName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); cfRetryClient.describeStacks(describeStacksRequest); cfRetryClient.deleteStack(awsStackRequestHelper.createDeleteStackRequest(cFStackName)); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId()); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName); Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfClient.waiters().stackDeleteComplete(); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest) .withPollingStrategy(getBackoffCancellablePollingStrategy(stackCancellationCheck)); stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters); } catch (AmazonServiceException e) { if (!e.getErrorMessage().contains(cFStackName + " does not exist") && !force) { throw e; } LOGGER.warn("Stack " + cFStackName + " does not exist, assuming that it has already been deleted"); return List.of(); } catch (Exception e) { if (force) { LOGGER.warn("Stack deletion for '{}' failed, continuing because termination is forced", cFStackName, e); } else { if (e instanceof RuntimeException) { throw new CloudConnectorException("RDS termination failed " + e.getMessage(), e); } else { throw e; } } } CloudContext cloudContext = ac.getCloudContext(); resources.forEach(r -> persistenceNotifier.notifyDeletion(r, cloudContext)); return List.of(); }
AwsRdsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force, PersistenceNotifier persistenceNotifier, List<CloudResource> resources) throws ExecutionException, TimeoutException, InterruptedException { String cFStackName = cfStackUtil.getCfStackName(ac); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); try { AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(credentialView, regionName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); cfRetryClient.describeStacks(describeStacksRequest); cfRetryClient.deleteStack(awsStackRequestHelper.createDeleteStackRequest(cFStackName)); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId()); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName); Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfClient.waiters().stackDeleteComplete(); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest) .withPollingStrategy(getBackoffCancellablePollingStrategy(stackCancellationCheck)); stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters); } catch (AmazonServiceException e) { if (!e.getErrorMessage().contains(cFStackName + " does not exist") && !force) { throw e; } LOGGER.warn("Stack " + cFStackName + " does not exist, assuming that it has already been deleted"); return List.of(); } catch (Exception e) { if (force) { LOGGER.warn("Stack deletion for '{}' failed, continuing because termination is forced", cFStackName, e); } else { if (e instanceof RuntimeException) { throw new CloudConnectorException("RDS termination failed " + e.getMessage(), e); } else { throw e; } } } CloudContext cloudContext = ac.getCloudContext(); resources.forEach(r -> persistenceNotifier.notifyDeletion(r, cloudContext)); return List.of(); } }
AwsRdsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force, PersistenceNotifier persistenceNotifier, List<CloudResource> resources) throws ExecutionException, TimeoutException, InterruptedException { String cFStackName = cfStackUtil.getCfStackName(ac); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); try { AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(credentialView, regionName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); cfRetryClient.describeStacks(describeStacksRequest); cfRetryClient.deleteStack(awsStackRequestHelper.createDeleteStackRequest(cFStackName)); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId()); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName); Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfClient.waiters().stackDeleteComplete(); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest) .withPollingStrategy(getBackoffCancellablePollingStrategy(stackCancellationCheck)); stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters); } catch (AmazonServiceException e) { if (!e.getErrorMessage().contains(cFStackName + " does not exist") && !force) { throw e; } LOGGER.warn("Stack " + cFStackName + " does not exist, assuming that it has already been deleted"); return List.of(); } catch (Exception e) { if (force) { LOGGER.warn("Stack deletion for '{}' failed, continuing because termination is forced", cFStackName, e); } else { if (e instanceof RuntimeException) { throw new CloudConnectorException("RDS termination failed " + e.getMessage(), e); } else { throw e; } } } CloudContext cloudContext = ac.getCloudContext(); resources.forEach(r -> persistenceNotifier.notifyDeletion(r, cloudContext)); return List.of(); }  }
AwsRdsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force, PersistenceNotifier persistenceNotifier, List<CloudResource> resources) throws ExecutionException, TimeoutException, InterruptedException { String cFStackName = cfStackUtil.getCfStackName(ac); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); try { AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(credentialView, regionName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); cfRetryClient.describeStacks(describeStacksRequest); cfRetryClient.deleteStack(awsStackRequestHelper.createDeleteStackRequest(cFStackName)); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId()); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName); Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfClient.waiters().stackDeleteComplete(); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest) .withPollingStrategy(getBackoffCancellablePollingStrategy(stackCancellationCheck)); stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters); } catch (AmazonServiceException e) { if (!e.getErrorMessage().contains(cFStackName + " does not exist") && !force) { throw e; } LOGGER.warn("Stack " + cFStackName + " does not exist, assuming that it has already been deleted"); return List.of(); } catch (Exception e) { if (force) { LOGGER.warn("Stack deletion for '{}' failed, continuing because termination is forced", cFStackName, e); } else { if (e instanceof RuntimeException) { throw new CloudConnectorException("RDS termination failed " + e.getMessage(), e); } else { throw e; } } } CloudContext cloudContext = ac.getCloudContext(); resources.forEach(r -> persistenceNotifier.notifyDeletion(r, cloudContext)); return List.of(); }  List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force,
        PersistenceNotifier persistenceNotifier, List<CloudResource> resources); }
AwsRdsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force, PersistenceNotifier persistenceNotifier, List<CloudResource> resources) throws ExecutionException, TimeoutException, InterruptedException { String cFStackName = cfStackUtil.getCfStackName(ac); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); try { AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(credentialView, regionName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); cfRetryClient.describeStacks(describeStacksRequest); cfRetryClient.deleteStack(awsStackRequestHelper.createDeleteStackRequest(cFStackName)); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId()); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName); Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfClient.waiters().stackDeleteComplete(); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest) .withPollingStrategy(getBackoffCancellablePollingStrategy(stackCancellationCheck)); stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters); } catch (AmazonServiceException e) { if (!e.getErrorMessage().contains(cFStackName + " does not exist") && !force) { throw e; } LOGGER.warn("Stack " + cFStackName + " does not exist, assuming that it has already been deleted"); return List.of(); } catch (Exception e) { if (force) { LOGGER.warn("Stack deletion for '{}' failed, continuing because termination is forced", cFStackName, e); } else { if (e instanceof RuntimeException) { throw new CloudConnectorException("RDS termination failed " + e.getMessage(), e); } else { throw e; } } } CloudContext cloudContext = ac.getCloudContext(); resources.forEach(r -> persistenceNotifier.notifyDeletion(r, cloudContext)); return List.of(); }  List<CloudResourceStatus> terminate(AuthenticatedContext ac, DatabaseStack stack, boolean force,
        PersistenceNotifier persistenceNotifier, List<CloudResource> resources);  }