use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AwsMigrationUtil method allInstancesDeletedFromCloudFormation.
public boolean allInstancesDeletedFromCloudFormation(AuthenticatedContext ac, CloudResource cloudResource) {
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AwsCredentialView awsCredential = new AwsCredentialView(ac.getCloudCredential());
DescribeStackResourcesResult describeStackResourcesResult = awsClient.createCloudFormationClient(awsCredential, regionName).describeStackResources(new DescribeStackResourcesRequest().withStackName(cloudResource.getName()));
List<StackResource> asGroups = describeStackResourcesResult.getStackResources().stream().filter(it -> "AWS::AutoScaling::AutoScalingGroup".equals(it.getResourceType())).collect(Collectors.toList());
LOGGER.debug("AutoScalingGroup fetched: {}", asGroups);
boolean empty = true;
int i = 0;
while (empty && i < asGroups.size()) {
StackResource asGroup = asGroups.get(i);
List<String> result = cfStackUtil.getInstanceIds(awsClient.createAutoScalingClient(awsCredential, regionName), asGroup.getPhysicalResourceId());
LOGGER.debug("{} autoScalingGroup has {} instance(s): {}", asGroup.getPhysicalResourceId(), result.size(), result);
empty = result.isEmpty();
i++;
}
return empty;
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AwsMigrationUtilTest method testAllInstancesDeletedFromCloudFormationWhenASGroupFoundFirstASGHasInstance.
@Test
public void testAllInstancesDeletedFromCloudFormationWhenASGroupFoundFirstASGHasInstance() {
StackResource asg1 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id1");
StackResource asg2 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id2");
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(Location.location(Region.region("region")));
when(awsClient.createCloudFormationClient(any(), any())).thenReturn(amazonCloudFormationClient);
when(amazonCloudFormationClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(List.of(asg1, asg2)));
when(awsClient.createAutoScalingClient(any(), any())).thenReturn(amazonAutoScalingClient);
when(cfStackUtil.getInstanceIds(amazonAutoScalingClient, "id1")).thenReturn(List.of("instanceId1"));
boolean actual = underTest.allInstancesDeletedFromCloudFormation(ac, cloudResource);
Assertions.assertFalse(actual);
verify(cfStackUtil).getInstanceIds(amazonAutoScalingClient, "id1");
verify(cfStackUtil, never()).getInstanceIds(amazonAutoScalingClient, "id2");
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AwsMigrationUtilTest method testAllInstancesDeletedFromCloudFormationWhenASGroupFoundOSecondASGHasInstance.
@Test
public void testAllInstancesDeletedFromCloudFormationWhenASGroupFoundOSecondASGHasInstance() {
StackResource asg1 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id1");
StackResource asg2 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id2");
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(Location.location(Region.region("region")));
when(awsClient.createCloudFormationClient(any(), any())).thenReturn(amazonCloudFormationClient);
when(amazonCloudFormationClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(List.of(asg1, asg2)));
when(awsClient.createAutoScalingClient(any(), any())).thenReturn(amazonAutoScalingClient);
when(cfStackUtil.getInstanceIds(amazonAutoScalingClient, "id1")).thenReturn(Collections.emptyList());
when(cfStackUtil.getInstanceIds(amazonAutoScalingClient, "id2")).thenReturn(List.of("instanceId1"));
boolean actual = underTest.allInstancesDeletedFromCloudFormation(ac, cloudResource);
Assertions.assertFalse(actual);
verify(cfStackUtil).getInstanceIds(amazonAutoScalingClient, "id1");
verify(cfStackUtil).getInstanceIds(amazonAutoScalingClient, "id2");
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AwsMigrationUtilTest method testAllInstancesDeletedFromCloudFormationWhenASGroupFound.
@Test
public void testAllInstancesDeletedFromCloudFormationWhenASGroupFound() {
StackResource asg1 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id1");
StackResource asg2 = new StackResource().withResourceType("AWS::AutoScaling::AutoScalingGroup").withPhysicalResourceId("id2");
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(Location.location(Region.region("region")));
when(awsClient.createCloudFormationClient(any(), any())).thenReturn(amazonCloudFormationClient);
when(amazonCloudFormationClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(List.of(asg1, asg2)));
when(awsClient.createAutoScalingClient(any(), any())).thenReturn(amazonAutoScalingClient);
when(cfStackUtil.getInstanceIds(amazonAutoScalingClient, "id1")).thenReturn(Collections.emptyList());
when(cfStackUtil.getInstanceIds(amazonAutoScalingClient, "id2")).thenReturn(Collections.emptyList());
boolean actual = underTest.allInstancesDeletedFromCloudFormation(ac, cloudResource);
Assertions.assertTrue(actual);
verify(cfStackUtil).getInstanceIds(amazonAutoScalingClient, "id1");
verify(cfStackUtil).getInstanceIds(amazonAutoScalingClient, "id2");
}
use of com.amazonaws.services.cloudformation.model.StackResource in project cloudbreak by hortonworks.
the class AwsCloudFormationErrorMessageProviderTest method shouldReportAddressLimitExceededOnCreate.
@Test
void shouldReportAddressLimitExceededOnCreate() {
when(cfRetryClient.describeStacks(any())).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatusReason("The following resource(s) failed to create: [EIPmaster01, ClusterNodeSecurityGroupmaster0].")));
when(cfRetryClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(new StackResource().withLogicalResourceId("ClusterNodeSecurityGroupmaster0").withResourceStatus(ResourceStatus.CREATE_FAILED.toString()).withResourceStatusReason("Resource creation cancelled"), new StackResource().withLogicalResourceId("EIPmaster01").withResourceStatus(ResourceStatus.CREATE_FAILED.toString()).withResourceStatusReason("The maximum number of addresses has been reached. (Service: AmazonEC2; Status Code: 400; Error Code: " + "AddressLimitExceeded; Request ID: ee8b7a70-a1bf-4b67-b9da-f6f6d258bfd4; Proxy: null)"), new StackResource().withLogicalResourceId("HealthyResource").withResourceStatus(ResourceStatus.CREATE_COMPLETE.toString()).withResourceStatusReason("Created")));
when(cfRetryClient.describeStackEvents(any(DescribeStackEventsRequest.class))).thenReturn(new DescribeStackEventsResult());
String result = underTest.getErrorReason(credentialView, REGION, STACK_NAME, ResourceStatus.CREATE_FAILED);
assertEquals("The following resource(s) failed to create: [EIPmaster01, ClusterNodeSecurityGroupmaster0]. " + "ClusterNodeSecurityGroupmaster0: Resource creation cancelled, " + "EIPmaster01: The maximum number of addresses has been reached. (Service: AmazonEC2; Status Code: 400; Error Code: AddressLimitExceeded; " + "Request ID: ee8b7a70-a1bf-4b67-b9da-f6f6d258bfd4; Proxy: null)", result);
}
Aggregations