use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsTerminateService method terminate.
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);
LOGGER.debug("Calling deleteCloudWatchAlarmsForSystemFailures from AwsTerminateService");
awsCloudWatchService.deleteAllCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView);
waitAndDeleteCloudformationStack(ac, stack, resources, amazonCloudFormationClient);
awsComputeResourceService.deleteComputeResources(ac, stack, resources);
deleteKeyPair(ac, stack, amazonEC2Client, credentialView, regionName);
deleteLaunchConfiguration(resources, ac);
LOGGER.debug("Deleting stack finished");
return awsResourceConnector.check(ac, resources);
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AutoScalingGroupHandler method getAutoScalingGroups.
public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient, String stackName) {
DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest();
resourcesRequest.setStackName(stackName);
DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest);
Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream().filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType())).collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId));
DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
request.setAutoScalingGroupNames(autoScalingGroups.keySet());
List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups();
return scalingGroups.stream().collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName())));
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testDeleteNetworkWithSubNetsShouldDeleteTheStackAndTheResourceGroup.
@Test
public void testDeleteNetworkWithSubNetsShouldDeleteTheStackAndTheResourceGroup() {
NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest();
AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(networkDeletionRequest.getRegion()))).thenReturn(cfClient);
when(cfClient.waiters()).thenReturn(cfWaiters);
when(retryService.testWith2SecDelayMax15Times(any())).thenReturn(true);
when(cfWaiters.stackDeleteComplete()).thenReturn(deletionWaiter);
underTest.deleteNetworkWithSubnets(networkDeletionRequest);
verify(cfClient).deleteStack(any(DeleteStackRequest.class));
verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
verify(deletionWaiter, times(1)).run(any());
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testCreateNetworkWithSubnetsShouldReturnTheNetworkAndSubnets.
@Test
public void testCreateNetworkWithSubnetsShouldReturnTheNetworkAndSubnets() {
String networkCidr = "0.0.0.0/16";
Set<NetworkSubnetRequest> subnets = Set.of(new NetworkSubnetRequest("1.1.1.1/8", PUBLIC), new NetworkSubnetRequest("1.1.1.2/8", PUBLIC));
AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
Map<String, String> output = createOutput();
NetworkCreationRequest networkCreationRequest = createNetworkRequest(networkCidr, subnets);
List<SubnetRequest> subnetRequestList = createSubnetRequestList();
Set<CreatedSubnet> createdSubnets = Set.of(new CreatedSubnet(), new CreatedSubnet(), new CreatedSubnet());
when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
when(awsSubnetRequestProvider.provide(ec2Client, new ArrayList<>(subnets), new ArrayList<>(subnets))).thenReturn(subnetRequestList);
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()))).thenReturn(cfClient);
when(cfClient.waiters()).thenReturn(cfWaiters);
when(cfWaiters.stackCreateComplete()).thenReturn(creationWaiter);
when(cfStackUtil.getOutputs(NETWORK_ID, cfClient)).thenReturn(output);
when(awsCreatedSubnetProvider.provide(output, subnetRequestList, true)).thenReturn(createdSubnets);
CreatedCloudNetwork actual = underTest.createNetworkWithSubnets(networkCreationRequest);
verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
verify(creationWaiter, times(1)).run(any());
verify(cfStackUtil).getOutputs(NETWORK_ID, cfClient);
verify(awsTaggingService, never()).prepareCloudformationTags(any(), any());
verify(cfClient, never()).createStack(any(CreateStackRequest.class));
assertEquals(VPC_ID, actual.getNetworkId());
assertEquals(NUMBER_OF_SUBNETS, actual.getSubnets().size());
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testDeleteNetworkWithSubNetsShouldThrowAnExceptionWhenTheStackDeletionFailed.
@Test(expected = CloudConnectorException.class)
public void testDeleteNetworkWithSubNetsShouldThrowAnExceptionWhenTheStackDeletionFailed() {
NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest();
AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(networkDeletionRequest.getRegion()))).thenReturn(cfClient);
when(cfClient.waiters()).thenReturn(cfWaiters);
when(retryService.testWith2SecDelayMax15Times(any())).thenReturn(true);
when(cfWaiters.stackDeleteComplete()).thenReturn(deletionWaiter);
doThrow(new WaiterTimedOutException("fail")).when(deletionWaiter).run(any());
underTest.deleteNetworkWithSubnets(networkDeletionRequest);
verify(cfClient).deleteStack(any(DeleteStackRequest.class));
verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
}
Aggregations