use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener 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.AwsListener 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.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener 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.AwsListener 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());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerNewPrivate.
@Test
public void testConvertLoadBalancerNewPrivate() {
when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PRIVATE))).thenReturn(AwsLoadBalancerScheme.INTERNAL);
AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(), LoadBalancerType.PRIVATE, PRIVATE_ID_1);
assertNotNull(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