@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") )); String result = AwsCloudFormationErrorMessageProvider.getErrorReason(cfRetryClient, STACK_NAME, ResourceStatus.CREATE_FAILED); Assert.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); }
public static String getErrorReason(AmazonCloudFormationRetryClient cfRetryClient, String stackName, ResourceStatus resourceErrorStatus) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); DescribeStacksResult describeStacksResult = cfRetryClient.describeStacks(describeStacksRequest); String stackStatusReason = describeStacksResult.getStacks().get(0).getStackStatusReason(); DescribeStackResourcesRequest describeStackResourcesRequest = new DescribeStackResourcesRequest().withStackName(stackName); DescribeStackResourcesResult describeStackResourcesResult = cfRetryClient.describeStackResources(describeStackResourcesRequest); String stackResourceStatusReasons = describeStackResourcesResult.getStackResources().stream() .filter(stackResource -> ResourceStatus.fromValue(stackResource.getResourceStatus()).equals(resourceErrorStatus)) .map(stackResource -> stackResource.getLogicalResourceId() + ": " + stackResource.getResourceStatusReason()) .collect(Collectors.joining(", ")); return stackStatusReason + " " + stackResourceStatusReasons; }
AwsCloudFormationErrorMessageProvider { public static String getErrorReason(AmazonCloudFormationRetryClient cfRetryClient, String stackName, ResourceStatus resourceErrorStatus) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); DescribeStacksResult describeStacksResult = cfRetryClient.describeStacks(describeStacksRequest); String stackStatusReason = describeStacksResult.getStacks().get(0).getStackStatusReason(); DescribeStackResourcesRequest describeStackResourcesRequest = new DescribeStackResourcesRequest().withStackName(stackName); DescribeStackResourcesResult describeStackResourcesResult = cfRetryClient.describeStackResources(describeStackResourcesRequest); String stackResourceStatusReasons = describeStackResourcesResult.getStackResources().stream() .filter(stackResource -> ResourceStatus.fromValue(stackResource.getResourceStatus()).equals(resourceErrorStatus)) .map(stackResource -> stackResource.getLogicalResourceId() + ": " + stackResource.getResourceStatusReason()) .collect(Collectors.joining(", ")); return stackStatusReason + " " + stackResourceStatusReasons; } }
AwsCloudFormationErrorMessageProvider { public static String getErrorReason(AmazonCloudFormationRetryClient cfRetryClient, String stackName, ResourceStatus resourceErrorStatus) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); DescribeStacksResult describeStacksResult = cfRetryClient.describeStacks(describeStacksRequest); String stackStatusReason = describeStacksResult.getStacks().get(0).getStackStatusReason(); DescribeStackResourcesRequest describeStackResourcesRequest = new DescribeStackResourcesRequest().withStackName(stackName); DescribeStackResourcesResult describeStackResourcesResult = cfRetryClient.describeStackResources(describeStackResourcesRequest); String stackResourceStatusReasons = describeStackResourcesResult.getStackResources().stream() .filter(stackResource -> ResourceStatus.fromValue(stackResource.getResourceStatus()).equals(resourceErrorStatus)) .map(stackResource -> stackResource.getLogicalResourceId() + ": " + stackResource.getResourceStatusReason()) .collect(Collectors.joining(", ")); return stackStatusReason + " " + stackResourceStatusReasons; } private  AwsCloudFormationErrorMessageProvider(); }
AwsCloudFormationErrorMessageProvider { public static String getErrorReason(AmazonCloudFormationRetryClient cfRetryClient, String stackName, ResourceStatus resourceErrorStatus) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); DescribeStacksResult describeStacksResult = cfRetryClient.describeStacks(describeStacksRequest); String stackStatusReason = describeStacksResult.getStacks().get(0).getStackStatusReason(); DescribeStackResourcesRequest describeStackResourcesRequest = new DescribeStackResourcesRequest().withStackName(stackName); DescribeStackResourcesResult describeStackResourcesResult = cfRetryClient.describeStackResources(describeStackResourcesRequest); String stackResourceStatusReasons = describeStackResourcesResult.getStackResources().stream() .filter(stackResource -> ResourceStatus.fromValue(stackResource.getResourceStatus()).equals(resourceErrorStatus)) .map(stackResource -> stackResource.getLogicalResourceId() + ": " + stackResource.getResourceStatusReason()) .collect(Collectors.joining(", ")); return stackStatusReason + " " + stackResourceStatusReasons; } private  AwsCloudFormationErrorMessageProvider(); static String getErrorReason(AmazonCloudFormationRetryClient cfRetryClient, String stackName, ResourceStatus resourceErrorStatus); }
AwsCloudFormationErrorMessageProvider { public static String getErrorReason(AmazonCloudFormationRetryClient cfRetryClient, String stackName, ResourceStatus resourceErrorStatus) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); DescribeStacksResult describeStacksResult = cfRetryClient.describeStacks(describeStacksRequest); String stackStatusReason = describeStacksResult.getStacks().get(0).getStackStatusReason(); DescribeStackResourcesRequest describeStackResourcesRequest = new DescribeStackResourcesRequest().withStackName(stackName); DescribeStackResourcesResult describeStackResourcesResult = cfRetryClient.describeStackResources(describeStackResourcesRequest); String stackResourceStatusReasons = describeStackResourcesResult.getStackResources().stream() .filter(stackResource -> ResourceStatus.fromValue(stackResource.getResourceStatus()).equals(resourceErrorStatus)) .map(stackResource -> stackResource.getLogicalResourceId() + ": " + stackResource.getResourceStatusReason()) .collect(Collectors.joining(", ")); return stackStatusReason + " " + stackResourceStatusReasons; } private  AwsCloudFormationErrorMessageProvider(); static String getErrorReason(AmazonCloudFormationRetryClient cfRetryClient, String stackName, ResourceStatus resourceErrorStatus);  }