use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLoadBalancerLaunchService method createLoadBalancerStatus.
private CloudResourceStatus createLoadBalancerStatus(AuthenticatedContext ac, AwsLoadBalancer loadBalancer, ListStackResourcesResult result) {
LOGGER.debug(String.format("Checking final status of AWS load balancer %s", loadBalancer.getName()));
List<StackResourceSummary> summaries = result.getStackResourceSummaries();
boolean createSuccess = isResourceStatusGood(summaries, loadBalancer.getName());
for (AwsListener listener : loadBalancer.getListeners()) {
LOGGER.debug(String.format("Checking final status of AWS listener %s", listener.getName()));
createSuccess = createSuccess && isResourceStatusGood(summaries, listener.getName());
LOGGER.debug(String.format("Checking final status of AWS target group %s", listener.getTargetGroup().getName()));
createSuccess = createSuccess && isResourceStatusGood(summaries, listener.getTargetGroup().getName());
}
CloudResource.Builder cloudResource = new CloudResource.Builder().status(createSuccess ? CommonStatus.CREATED : CommonStatus.FAILED).type(ELASTIC_LOAD_BALANCER).availabilityZone(ac.getCloudContext().getLocation().getAvailabilityZone().value()).name(loadBalancer.getName());
return new CloudResourceStatus(cloudResource.build(), createSuccess ? com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.CREATED : com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.FAILED);
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLoadBalancerLaunchService method checkForLoadBalancerAndTargetGroupResources.
@VisibleForTesting
boolean checkForLoadBalancerAndTargetGroupResources(AmazonCloudFormationClient cfClient, String cFStackName, List<AwsLoadBalancer> awsLoadBalancers) {
ListStackResourcesResult result = cfClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
boolean resourcesFound = true;
List<StackResourceSummary> summaries = result.getStackResourceSummaries();
for (AwsLoadBalancer loadBalancer : awsLoadBalancers) {
LOGGER.debug("Checking to see if load balancer resource {} already exists", loadBalancer.getName());
resourcesFound = resourcesFound && summaries.stream().anyMatch(stackResourceSummary -> loadBalancer.getName().equals(stackResourceSummary.getLogicalResourceId()));
for (AwsListener listener : loadBalancer.getListeners()) {
LOGGER.debug("Checking to see if target group resource {} already exists", listener.getTargetGroup().getName());
resourcesFound = resourcesFound && summaries.stream().anyMatch(stackResourceSummary -> listener.getTargetGroup().getName().equals(stackResourceSummary.getLogicalResourceId()));
}
}
return resourcesFound;
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMultiplePorts.
@Test
public void testCollectLoadBalancerMultiplePorts() {
int numPorts = 3;
AuthenticatedContext ac = authenticatedContext();
LoadBalancer loadBalancer = createLoadBalancer();
List<StackResourceSummary> summaries = createSummaries(numPorts, true);
ListStackResourcesResult result = new ListStackResourcesResult();
result.setStackResourceSummaries(summaries);
Map<String, Object> expectedParameters = Map.of(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN, AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, TARGET_GROUP_ARN + "0Internal", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 1, LISTENER_ARN + "1Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 1, TARGET_GROUP_ARN + "1Internal", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 2, LISTENER_ARN + "2Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 2, TARGET_GROUP_ARN + "2Internal");
when(awsClient.createCloudFormationClient(any(), any())).thenReturn(cfRetryClient);
when(cloudFormationStackUtil.getCfStackName(ac)).thenReturn("stackName");
when(awsStackRequestHelper.createListStackResourcesRequest(eq("stackName"))).thenReturn(new ListStackResourcesRequest());
when(cfRetryClient.listStackResources(any())).thenReturn(result);
Map<String, Object> parameters = underTest.getParameters(ac, loadBalancer, AwsLoadBalancerScheme.INTERNAL);
assertEquals(expectedParameters, parameters);
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLoadBalancerMetadataCollectorTest method createSummaries.
private List<StackResourceSummary> createSummaries(int numPorts, boolean includeTargetGroup) {
List<StackResourceSummary> summaries = new ArrayList<>();
for (AwsLoadBalancerScheme scheme : AwsLoadBalancerScheme.class.getEnumConstants()) {
StackResourceSummary lbSummary = new StackResourceSummary();
lbSummary.setLogicalResourceId(AwsLoadBalancer.getLoadBalancerName(scheme));
lbSummary.setPhysicalResourceId(LOAD_BALANCER_ARN + scheme.resourceName());
summaries.add(lbSummary);
for (int i = 0; i < numPorts; i++) {
if (includeTargetGroup) {
StackResourceSummary tgSummary = new StackResourceSummary();
tgSummary.setLogicalResourceId(AwsTargetGroup.getTargetGroupName(i, scheme));
tgSummary.setPhysicalResourceId(TARGET_GROUP_ARN + i + scheme.resourceName());
summaries.add(tgSummary);
}
StackResourceSummary lSummary = new StackResourceSummary();
lSummary.setLogicalResourceId(AwsListener.getListenerName(i, scheme));
lSummary.setPhysicalResourceId(LISTENER_ARN + i + scheme.resourceName());
summaries.add(lSummary);
}
}
return summaries;
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithPublicLoadBalancerNoEndpointGateway.
@Test
public void testUpdateCloudformationWithPublicLoadBalancerNoEndpointGateway() {
List<CloudResource> instances = createInstances();
AwsNetworkView awsNetworkView = createNetworkView(PUBLIC_ID_1, null);
Network network = createNetwork(PUBLIC_ID_1, null);
Set<LoadBalancerType> types = Set.of(LoadBalancerType.PUBLIC);
List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
setupMocksForUpdate(awsNetworkView, network, instances, Set.of(LoadBalancerType.PUBLIC));
when(result.getStackResourceSummaries()).thenReturn(List.of()).thenReturn(firstUpdateSummaries).thenReturn(firstUpdateSummaries).thenReturn(secondUpdateSummaries);
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(location.getAvailabilityZone()).thenReturn(availabilityZone("az1"));
underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null);
verify(cfClient, times(2)).updateStack(any());
verify(result, times(4)).getStackResourceSummaries();
}
Aggregations