use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonService method convertLoadBalancer.
@VisibleForTesting
AwsLoadBalancer convertLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsNetworkView awsNetworkView, List<AwsLoadBalancer> awsLoadBalancers) {
// Check and see if we already have a load balancer whose scheme matches this one.
AwsLoadBalancer currentLoadBalancer = null;
LoadBalancerType cloudLbType = cloudLoadBalancer.getType();
Set<String> subnetIds = selectLoadBalancerSubnetIds(cloudLbType, awsNetworkView, cloudLoadBalancer);
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(cloudLbType);
currentLoadBalancer = awsLoadBalancers.stream().filter(lb -> lb.getScheme() == scheme).findFirst().orElse(new AwsLoadBalancer(scheme));
currentLoadBalancer.addSubnets(subnetIds);
setupLoadBalancer(cloudLoadBalancer, instanceIdsByGroupName, currentLoadBalancer);
return currentLoadBalancer;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerLaunchService method setLoadBalancerMetadata.
@VisibleForTesting
void setLoadBalancerMetadata(List<AwsLoadBalancer> awsLoadBalancers, ListStackResourcesResult result) {
List<StackResourceSummary> summaries = result.getStackResourceSummaries();
for (AwsLoadBalancer loadBalancer : awsLoadBalancers) {
LOGGER.debug("Processing load balancer {}", loadBalancer.getName());
for (AwsListener listener : loadBalancer.getListeners()) {
LOGGER.debug("Processing listener {} and target group {}", listener.getName(), listener.getTargetGroup().getName());
Optional<StackResourceSummary> targetGroupSummary = summaries.stream().filter(stackResourceSummary -> listener.getTargetGroup().getName().equals(stackResourceSummary.getLogicalResourceId())).findFirst();
if (targetGroupSummary.isEmpty()) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: target group %s not found.", listener.getTargetGroup().getName()));
}
if (StringUtils.isEmpty(targetGroupSummary.get().getPhysicalResourceId())) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: target group %s arn not found.", listener.getTargetGroup().getName()));
}
listener.getTargetGroup().setArn(targetGroupSummary.get().getPhysicalResourceId());
LOGGER.debug("Found arn {} for target group {}", listener.getTargetGroup().getArn(), listener.getTargetGroup().getName());
}
Optional<StackResourceSummary> loadBalancerSummary = summaries.stream().filter(stackResourceSummary -> loadBalancer.getName().equals(stackResourceSummary.getLogicalResourceId())).findFirst();
if (loadBalancerSummary.isEmpty()) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: load balancer %s not found.", loadBalancer.getName()));
}
if (StringUtils.isEmpty(loadBalancerSummary.get().getPhysicalResourceId())) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: load balancer %s arn not found.", loadBalancer.getName()));
}
loadBalancer.setArn(loadBalancerSummary.get().getPhysicalResourceId());
loadBalancer.validateListenerConfigIsSet();
LOGGER.debug("Found arn {} for load balancer {}", loadBalancer.getArn(), loadBalancer.getName());
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer 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.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerLaunchServiceTest method getAwsLoadBalancer.
private AwsLoadBalancer getAwsLoadBalancer() {
AwsLoadBalancer awsLoadBalancer = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNAL);
awsLoadBalancer.getOrCreateListener(USER_FACING_PORT, HEALTH_CHECK_PORT);
return awsLoadBalancer;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerExistingPrivate.
@Test
public void testConvertLoadBalancerExistingPrivate() {
AwsLoadBalancer existingLoadBalancer = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNAL);
when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PRIVATE))).thenReturn(AwsLoadBalancerScheme.INTERNAL);
AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(existingLoadBalancer), LoadBalancerType.PRIVATE, PRIVATE_ID_1);
assertNotNull(awsLoadBalancer);
assertEquals(existingLoadBalancer, awsLoadBalancer);
assertEquals(AwsLoadBalancerScheme.INTERNAL, awsLoadBalancer.getScheme());
assertEquals(Set.of(PRIVATE_ID_1), awsLoadBalancer.getSubnetIds());
assertEquals(1, awsLoadBalancer.getListeners().size());
AwsListener listener = awsLoadBalancer.getListeners().get(0);
assertEquals(PORT, listener.getPort());
assertNotNull(listener.getTargetGroup());
AwsTargetGroup targetGroup = listener.getTargetGroup();
assertEquals(PORT, targetGroup.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
Aggregations