@Test public void testTerminateWhenResourcesHasNoCfButStackNotExist() { CloudResource cf = new Builder().name("cfn-87654321").type(ResourceType.CLOUDFORMATION_STACK).build(); CloudResource lc = new Builder().name("lc-87654321").type(ResourceType.AWS_LAUNCHCONFIGURATION).build(); Group group = new Group("alma", InstanceGroupType.GATEWAY, List.of(), null, null, null, null, "", 0, Optional.empty()); DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult(); describeAutoScalingGroupsResult.setAutoScalingGroups(List.of()); when(cloudStack.getGroups()).thenReturn(List.of(group)); when(cfStackUtil.getCloudFormationStackResource(any())).thenReturn(cf); when(retryService.testWith2SecDelayMax15Times(any())).thenThrow(new Retry.ActionFailedException("Fail no more")); when(awsClient.createAutoScalingClient(any(), any())).thenReturn(amazonAutoScalingClient); List<CloudResourceStatus> result = underTest.terminate(authenticatedContext(), cloudStack, List.of( new Builder().name("ami-87654321").type(ResourceType.AWS_ENCRYPTED_AMI).build(), cf, lc )); verify(awsResourceConnector, times(1)).check(any(), any()); verify(awsComputeResourceService, times(1)).deleteComputeResources(any(), any(), any()); verify(encryptedImageCopyService, times(1)).deleteResources(any(), any(), any()); verify(cloudFormationRetryClient, never()).deleteStack(any()); verify(amazonAutoScalingRetryClient, never()).describeAutoScalingGroups(any()); Assertions.assertEquals(0, result.size(), "Resources result should be empty"); }
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) { LOGGER.debug("Deleting stack: {}", ac.getCloudContext().getId()); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(ac); String regionName = authenticatedContextView.getRegion(); AmazonEC2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client(); AmazonCloudFormationClient amazonCloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName); awsCloudWatchService.deleteCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView); waitAndDeleteCloudformationStack(ac, stack, resources, amazonCloudFormationClient); awsComputeResourceService.deleteComputeResources(ac, stack, resources); cleanupEncryptedResources(ac, resources, regionName, amazonEC2Client); deleteKeyPair(ac, stack, amazonEC2Client, credentialView, regionName); deleteLaunchConfiguration(resources, ac); LOGGER.debug("Deleting stack finished"); return awsResourceConnector.check(ac, resources); }
AwsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) { LOGGER.debug("Deleting stack: {}", ac.getCloudContext().getId()); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(ac); String regionName = authenticatedContextView.getRegion(); AmazonEC2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client(); AmazonCloudFormationClient amazonCloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName); awsCloudWatchService.deleteCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView); waitAndDeleteCloudformationStack(ac, stack, resources, amazonCloudFormationClient); awsComputeResourceService.deleteComputeResources(ac, stack, resources); cleanupEncryptedResources(ac, resources, regionName, amazonEC2Client); deleteKeyPair(ac, stack, amazonEC2Client, credentialView, regionName); deleteLaunchConfiguration(resources, ac); LOGGER.debug("Deleting stack finished"); return awsResourceConnector.check(ac, resources); } }
AwsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) { LOGGER.debug("Deleting stack: {}", ac.getCloudContext().getId()); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(ac); String regionName = authenticatedContextView.getRegion(); AmazonEC2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client(); AmazonCloudFormationClient amazonCloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName); awsCloudWatchService.deleteCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView); waitAndDeleteCloudformationStack(ac, stack, resources, amazonCloudFormationClient); awsComputeResourceService.deleteComputeResources(ac, stack, resources); cleanupEncryptedResources(ac, resources, regionName, amazonEC2Client); deleteKeyPair(ac, stack, amazonEC2Client, credentialView, regionName); deleteLaunchConfiguration(resources, ac); LOGGER.debug("Deleting stack finished"); return awsResourceConnector.check(ac, resources); }  }
AwsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) { LOGGER.debug("Deleting stack: {}", ac.getCloudContext().getId()); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(ac); String regionName = authenticatedContextView.getRegion(); AmazonEC2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client(); AmazonCloudFormationClient amazonCloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName); awsCloudWatchService.deleteCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView); waitAndDeleteCloudformationStack(ac, stack, resources, amazonCloudFormationClient); awsComputeResourceService.deleteComputeResources(ac, stack, resources); cleanupEncryptedResources(ac, resources, regionName, amazonEC2Client); deleteKeyPair(ac, stack, amazonEC2Client, credentialView, regionName); deleteLaunchConfiguration(resources, ac); LOGGER.debug("Deleting stack finished"); return awsResourceConnector.check(ac, resources); }  List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources); }
AwsTerminateService { public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) { LOGGER.debug("Deleting stack: {}", ac.getCloudContext().getId()); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(ac); String regionName = authenticatedContextView.getRegion(); AmazonEC2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client(); AmazonCloudFormationClient amazonCloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName); awsCloudWatchService.deleteCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView); waitAndDeleteCloudformationStack(ac, stack, resources, amazonCloudFormationClient); awsComputeResourceService.deleteComputeResources(ac, stack, resources); cleanupEncryptedResources(ac, resources, regionName, amazonEC2Client); deleteKeyPair(ac, stack, amazonEC2Client, credentialView, regionName); deleteLaunchConfiguration(resources, ac); LOGGER.debug("Deleting stack finished"); return awsResourceConnector.check(ac, resources); }  List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources);  }