@Test public void testDeleteNetworkWithSubNetsShouldDeleteTheStackAndTheResourceGroup() { NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest(); AmazonCloudFormationRetryClient cloudFormationRetryClient = mock(AmazonCloudFormationRetryClient.class); AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class); when(awsClient.createCloudFormationRetryClient(any(AwsCredentialView.class), eq(networkDeletionRequest.getRegion()))) .thenReturn(cloudFormationRetryClient); when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()))).thenReturn(cfClient); when(cfClient.waiters()).thenReturn(cfWaiters); when(cfWaiters.stackDeleteComplete()).thenReturn(deletionWaiter); underTest.deleteNetworkWithSubnets(networkDeletionRequest); verify(cloudFormationRetryClient).deleteStack(any(DeleteStackRequest.class)); verify(awsClient).createCloudFormationRetryClient(any(AwsCredentialView.class), eq(REGION.value())); verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value())); verify(deletionWaiter, times(1)).run(any()); }
@Override public void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest) { if (!networkDeletionRequest.isExisting()) { AwsCredentialView credentialView = new AwsCredentialView(networkDeletionRequest.getCloudCredential()); AmazonCloudFormationRetryClient cloudFormationRetryClient = getCloudFormationRetryClient(credentialView, networkDeletionRequest.getRegion()); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); String stackName = networkDeletionRequest.getStackName(); deleteStackRequest.setStackName(stackName); cloudFormationRetryClient.deleteStack(deleteStackRequest); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, networkDeletionRequest.getRegion()); Waiter<DescribeStacksRequest> deletionWaiter = cfClient.waiters().stackDeleteComplete(); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' ", stackName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); run(deletionWaiter, describeStacksRequest, null, String.format("Network delete failed (cloudformation: %s)", stackName), () -> AwsCloudFormationErrorMessageProvider.getErrorReason(cloudFormationRetryClient, stackName, ResourceStatus.DELETE_FAILED)); } }
AwsNetworkConnector implements DefaultNetworkConnector { @Override public void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest) { if (!networkDeletionRequest.isExisting()) { AwsCredentialView credentialView = new AwsCredentialView(networkDeletionRequest.getCloudCredential()); AmazonCloudFormationRetryClient cloudFormationRetryClient = getCloudFormationRetryClient(credentialView, networkDeletionRequest.getRegion()); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); String stackName = networkDeletionRequest.getStackName(); deleteStackRequest.setStackName(stackName); cloudFormationRetryClient.deleteStack(deleteStackRequest); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, networkDeletionRequest.getRegion()); Waiter<DescribeStacksRequest> deletionWaiter = cfClient.waiters().stackDeleteComplete(); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' ", stackName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); run(deletionWaiter, describeStacksRequest, null, String.format("Network delete failed (cloudformation: %s)", stackName), () -> AwsCloudFormationErrorMessageProvider.getErrorReason(cloudFormationRetryClient, stackName, ResourceStatus.DELETE_FAILED)); } } }
AwsNetworkConnector implements DefaultNetworkConnector { @Override public void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest) { if (!networkDeletionRequest.isExisting()) { AwsCredentialView credentialView = new AwsCredentialView(networkDeletionRequest.getCloudCredential()); AmazonCloudFormationRetryClient cloudFormationRetryClient = getCloudFormationRetryClient(credentialView, networkDeletionRequest.getRegion()); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); String stackName = networkDeletionRequest.getStackName(); deleteStackRequest.setStackName(stackName); cloudFormationRetryClient.deleteStack(deleteStackRequest); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, networkDeletionRequest.getRegion()); Waiter<DescribeStacksRequest> deletionWaiter = cfClient.waiters().stackDeleteComplete(); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' ", stackName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); run(deletionWaiter, describeStacksRequest, null, String.format("Network delete failed (cloudformation: %s)", stackName), () -> AwsCloudFormationErrorMessageProvider.getErrorReason(cloudFormationRetryClient, stackName, ResourceStatus.DELETE_FAILED)); } }  }
AwsNetworkConnector implements DefaultNetworkConnector { @Override public void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest) { if (!networkDeletionRequest.isExisting()) { AwsCredentialView credentialView = new AwsCredentialView(networkDeletionRequest.getCloudCredential()); AmazonCloudFormationRetryClient cloudFormationRetryClient = getCloudFormationRetryClient(credentialView, networkDeletionRequest.getRegion()); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); String stackName = networkDeletionRequest.getStackName(); deleteStackRequest.setStackName(stackName); cloudFormationRetryClient.deleteStack(deleteStackRequest); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, networkDeletionRequest.getRegion()); Waiter<DescribeStacksRequest> deletionWaiter = cfClient.waiters().stackDeleteComplete(); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' ", stackName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); run(deletionWaiter, describeStacksRequest, null, String.format("Network delete failed (cloudformation: %s)", stackName), () -> AwsCloudFormationErrorMessageProvider.getErrorReason(cloudFormationRetryClient, stackName, ResourceStatus.DELETE_FAILED)); } }  @Override CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest networkRequest); @Override NetworkCidr getNetworkCidr(Network network, CloudCredential credential); @Override SubnetSelectionResult filterSubnets(Collection<CloudSubnet> subnetMetas, SubnetSelectionParameters subnetSelectionParameters); @Override int subnetCountInDifferentAzMin(); @Override int subnetCountInDifferentAzMax(); @Override void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest); @Override Platform platform(); @Override Variant variant(); }
AwsNetworkConnector implements DefaultNetworkConnector { @Override public void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest) { if (!networkDeletionRequest.isExisting()) { AwsCredentialView credentialView = new AwsCredentialView(networkDeletionRequest.getCloudCredential()); AmazonCloudFormationRetryClient cloudFormationRetryClient = getCloudFormationRetryClient(credentialView, networkDeletionRequest.getRegion()); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); String stackName = networkDeletionRequest.getStackName(); deleteStackRequest.setStackName(stackName); cloudFormationRetryClient.deleteStack(deleteStackRequest); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, networkDeletionRequest.getRegion()); Waiter<DescribeStacksRequest> deletionWaiter = cfClient.waiters().stackDeleteComplete(); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' ", stackName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); run(deletionWaiter, describeStacksRequest, null, String.format("Network delete failed (cloudformation: %s)", stackName), () -> AwsCloudFormationErrorMessageProvider.getErrorReason(cloudFormationRetryClient, stackName, ResourceStatus.DELETE_FAILED)); } }  @Override CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest networkRequest); @Override NetworkCidr getNetworkCidr(Network network, CloudCredential credential); @Override SubnetSelectionResult filterSubnets(Collection<CloudSubnet> subnetMetas, SubnetSelectionParameters subnetSelectionParameters); @Override int subnetCountInDifferentAzMin(); @Override int subnetCountInDifferentAzMax(); @Override void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest); @Override Platform platform(); @Override Variant variant();  }