use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithPrivateLoadBalancer.
@Test
public void testUpdateCloudformationWithPrivateLoadBalancer() {
List<CloudResource> instances = createInstances();
AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, null);
Network network = createNetwork(PRIVATE_ID_1, null);
Set<LoadBalancerType> types = Set.of(LoadBalancerType.PRIVATE);
List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
setupMocksForUpdate(awsNetworkView, network, instances, Set.of(LoadBalancerType.PRIVATE));
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();
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method createSummaries.
private List<StackResourceSummary> createSummaries(Set<LoadBalancerType> types, boolean createLbAndTg, boolean creatListeners) {
List<StackResourceSummary> summaries = new ArrayList<>();
for (LoadBalancerType type : types) {
AwsLoadBalancerScheme scheme = LoadBalancerType.PRIVATE.equals(type) ? AwsLoadBalancerScheme.INTERNAL : AwsLoadBalancerScheme.INTERNET_FACING;
if (createLbAndTg) {
StackResourceSummary tgSummary = new StackResourceSummary();
tgSummary.setLogicalResourceId(AwsTargetGroup.getTargetGroupName(PORT, scheme));
tgSummary.setPhysicalResourceId(TARGET_GROUP_ARN);
tgSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
summaries.add(tgSummary);
StackResourceSummary lbSummary = new StackResourceSummary();
lbSummary.setLogicalResourceId(AwsLoadBalancer.getLoadBalancerName(scheme));
lbSummary.setPhysicalResourceId(LOAD_BALANCER_ARN);
lbSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
summaries.add(lbSummary);
}
if (creatListeners) {
StackResourceSummary lSummary = new StackResourceSummary();
lSummary.setLogicalResourceId(AwsListener.getListenerName(PORT, scheme));
lSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
summaries.add(lSummary);
}
}
return summaries;
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLoadBalancerLaunchService method checkForListenerResources.
@VisibleForTesting
boolean checkForListenerResources(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) {
for (AwsListener listener : loadBalancer.getListeners()) {
LOGGER.debug("Checking to see if listener resource {} already exists", listener.getName());
resourcesFound = resourcesFound && summaries.stream().anyMatch(stackResourceSummary -> listener.getName().equals(stackResourceSummary.getLogicalResourceId()));
}
}
return resourcesFound;
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMissingTargetGroup.
@Test
public void testCollectLoadBalancerMissingTargetGroup() {
int numPorts = 1;
AuthenticatedContext ac = authenticatedContext();
LoadBalancer loadBalancer = createLoadBalancer();
List<StackResourceSummary> summaries = createSummaries(numPorts, false);
ListStackResourcesResult result = new ListStackResourcesResult();
result.setStackResourceSummaries(summaries);
Map<String, Object> expectedParameters = new HashMap<>();
expectedParameters.put(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN);
expectedParameters.put(AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal");
expectedParameters.put(AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, null);
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 testCollectInternalLoadBalancer.
@Test
public void testCollectInternalLoadBalancer() {
int numPorts = 1;
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");
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);
}
Aggregations