use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestWithSingleLoadBalancerBeforeUpdate.
@Test
public void buildTestWithSingleLoadBalancerBeforeUpdate() {
// GIVEN
AwsLoadBalancer awsLoadBalancer = setupLoadBalancer(AwsLoadBalancerScheme.INTERNAL, 443, false);
// WHEN
modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withLoadBalancers(List.of(awsLoadBalancer));
String templateString = cloudFormationTemplateBuilder.build(modelContext);
// THEN
Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("\"LoadBalancerInternal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::LoadBalancer\"").contains("\"Scheme\" : \"internal\"").contains("\"TargetGroupPort443Internal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::TargetGroup\"").doesNotContain("\"ListenerPort443Internal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::Listener\"");
assert templateString.contains("\"Targets\" : [{ \"Id\" : \"instance1-443\" },{ \"Id\" : \"instance2-443\" }]}}") || templateString.contains("\"Targets\" : [{ \"Id\" : \"instance2-443\" },{ \"Id\" : \"instance1-443\" }]}}");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method setupAwsLoadBalancers.
private List<AwsLoadBalancer> setupAwsLoadBalancers() {
AwsLoadBalancer privateLb = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNAL);
privateLb.getOrCreateListener(PORT, PORT);
AwsLoadBalancer publicLb = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNET_FACING);
publicLb.getOrCreateListener(PORT, PORT);
return List.of(privateLb, publicLb);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method setupMocksForUpdate.
private void setupMocksForUpdate(AwsNetworkView awsNetworkView, Network network, List<CloudResource> instances, Set<LoadBalancerType> types) {
List<CloudLoadBalancer> loadBalancers = new ArrayList<>();
List<AwsLoadBalancer> awsLoadBalancers = new ArrayList<>();
for (LoadBalancerType type : types) {
loadBalancers.add(createCloudLoadBalancer(type));
AwsLoadBalancerScheme scheme = AwsLoadBalancerScheme.INTERNET_FACING;
if (LoadBalancerType.PRIVATE.equals(type)) {
scheme = AwsLoadBalancerScheme.INTERNAL;
}
AwsLoadBalancer awsLoadBalancer = new AwsLoadBalancer(scheme);
awsLoadBalancer.getOrCreateListener(PORT, PORT);
awsLoadBalancers.add(awsLoadBalancer);
}
when(cfStackUtil.getCfStackName(any())).thenReturn(STACK_NAME);
when(awsClient.createCloudFormationClient(any(), anyString())).thenReturn(cfClient);
when(cfClient.updateStack(any())).thenReturn(null);
when(cfClient.listStackResources(any())).thenReturn(result);
when(cloudFormationTemplateBuilder.build(any(ModelContext.class))).thenReturn("{}");
when(awsStackRequestHelper.createUpdateStackRequest(any(), any(), anyString(), anyString())).thenReturn(null);
when(cfClient.waiters()).thenReturn(waiters);
when(waiters.stackUpdateComplete()).thenReturn(updateWaiter);
when(ac.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getId()).thenReturn(1L);
when(cloudContext.getLocation()).thenReturn(location);
when(location.getRegion()).thenReturn(region);
when(region.value()).thenReturn("region");
when(cloudStack.getLoadBalancers()).thenReturn(loadBalancers);
when(cloudStack.getNetwork()).thenReturn(network);
when(awsModelService.buildDefaultModelContext(any(), any(), any())).thenReturn(new ModelContext());
when(awsLoadBalancerCommonService.getAwsLoadBalancers(eq(loadBalancers), any(), any())).thenReturn(awsLoadBalancers);
PowerMockito.mockStatic(AwsPageCollector.class);
PowerMockito.when(AwsPageCollector.getAllRouteTables(any(), any())).thenReturn(List.of());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonService method getAwsLoadBalancers.
public List<AwsLoadBalancer> getAwsLoadBalancers(List<CloudLoadBalancer> cloudLoadBalancers, Map<String, List<String>> instanceIdsByGroupName, AwsNetworkView awsNetworkView) {
LOGGER.debug("Converting internal load balancer model to AWS cloud provider model.");
List<AwsLoadBalancer> awsLoadBalancers = new ArrayList<>();
for (CloudLoadBalancer cloudLoadBalancer : cloudLoadBalancers) {
LOGGER.debug("Found load balancer model of type {}", cloudLoadBalancer.getType());
AwsLoadBalancer loadBalancer = convertLoadBalancer(cloudLoadBalancer, instanceIdsByGroupName, awsNetworkView, awsLoadBalancers);
if (loadBalancer != null && !awsLoadBalancers.contains(loadBalancer)) {
awsLoadBalancers.add(loadBalancer);
}
}
Set<String> requestedTypes = cloudLoadBalancers.stream().map(lb -> lb.getType().name()).collect(Collectors.toSet());
Set<String> awsTypes = awsLoadBalancers.stream().map(lb -> AwsLoadBalancerScheme.INTERNAL.awsScheme().equals(lb.getAwsScheme()) ? "PRIVATE" : "PUBLIC").collect(Collectors.toSet());
if (!requestedTypes.equals(awsTypes)) {
throw new CloudConnectorException(String.format("Can not create all requested AWS load balancers. " + "Types requested: [%s]; type to be created: [%s]", requestedTypes, awsTypes));
}
return awsLoadBalancers;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonService method setupLoadBalancer.
private void setupLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsLoadBalancer awsLoadBalancer) {
LOGGER.debug("Configuring target instances for listeners.");
for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : cloudLoadBalancer.getPortToTargetGroupMapping().entrySet()) {
AwsListener listener = awsLoadBalancer.getOrCreateListener(entry.getKey().getTrafficPort(), entry.getKey().getHealthCheckPort());
Set<String> instanceIds = entry.getValue().stream().flatMap(tg -> instanceIdsByGroupName.get(tg.getName()).stream()).collect(Collectors.toSet());
LOGGER.debug(String.format("Adding instances %s to listener %s", instanceIds, listener.getName()));
listener.addInstancesToTargetGroup(instanceIds);
}
}
Aggregations