use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult in project cloudbreak by hortonworks.
the class AwsCloudFormationErrorMessageProviderTest method shouldDecodeAuthorizationError.
@Test
void shouldDecodeAuthorizationError() {
when(cfRetryClient.describeStacks(any())).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatusReason("The following resource(s) failed to create: [ClusterNodeSecurityGroupmaster0].")));
String resourceStatusReason = "Resource creation cancelled";
when(cfRetryClient.describeStackResources(any())).thenReturn(new DescribeStackResourcesResult().withStackResources(new StackResource().withLogicalResourceId("ClusterNodeSecurityGroupmaster0").withResourceStatus(ResourceStatus.CREATE_FAILED.toString()).withResourceStatusReason(resourceStatusReason)));
when(awsEncodedAuthorizationFailureMessageDecoder.decodeAuthorizationFailureMessageIfNeeded(any(), eq(REGION), anyString())).thenReturn("Decoded auth error");
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: [ClusterNodeSecurityGroupmaster0]. " + "ClusterNodeSecurityGroupmaster0: Decoded auth error", result);
verify(awsEncodedAuthorizationFailureMessageDecoder).decodeAuthorizationFailureMessageIfNeeded(credentialView, REGION, resourceStatusReason);
}
use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult in project cloudbreak by hortonworks.
the class AwsCloudFormationErrorMessageProvider method getStackResourceStatusReasons.
private String getStackResourceStatusReasons(AwsCredentialView credentialView, String region, String stackName, Set<String> resourceErrorStatuses, AmazonCloudFormationClient cfClient) {
DescribeStackResourcesRequest describeStackResourcesRequest = new DescribeStackResourcesRequest().withStackName(stackName);
DescribeStackResourcesResult describeStackResourcesResult = cfClient.describeStackResources(describeStackResourcesRequest);
String stackResourceStatusReasons = describeStackResourcesResult.getStackResources().stream().filter(stackResource -> resourceErrorStatuses.contains(stackResource.getResourceStatus())).map(stackResource -> getStackResourceMessage(credentialView, region, stackResource)).collect(Collectors.joining(", "));
return stackResourceStatusReasons;
}
use of com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult 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.DescribeStackResourcesResult 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.DescribeStackResourcesResult 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");
}
Aggregations