Search in sources :

Example 1 with AwsLoadBalancer

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;
}
Also used : Logger(org.slf4j.Logger) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) List(java.util.List) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Service(org.springframework.stereotype.Service) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with AwsLoadBalancer

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());
    }
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) AwsCloudFormationErrorMessageProvider(com.sequenceiq.cloudbreak.cloud.aws.util.AwsCloudFormationErrorMessageProvider) CloudFormationTemplateBuilder(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) AwsLoadBalancerCommonService(com.sequenceiq.cloudbreak.cloud.aws.common.connector.resource.AwsLoadBalancerCommonService) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Service(org.springframework.stereotype.Service) Collectors.mapping(java.util.stream.Collectors.mapping) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) StackCancellationCheck(com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Waiter(com.amazonaws.waiters.Waiter) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) Logger(org.slf4j.Logger) AwsStackRequestHelper(com.sequenceiq.cloudbreak.cloud.aws.AwsStackRequestHelper) AwsCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudFormationStackUtil(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceStatus(com.amazonaws.services.cloudformation.model.ResourceStatus) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors(java.util.stream.Collectors) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) AwsModelService(com.sequenceiq.cloudbreak.cloud.aws.common.connector.resource.AwsModelService) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) WaiterRunner.run(com.sequenceiq.cloudbreak.cloud.aws.scheduler.WaiterRunner.run) Optional(java.util.Optional) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ELASTIC_LOAD_BALANCER(com.sequenceiq.common.api.type.ResourceType.ELASTIC_LOAD_BALANCER) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with AwsLoadBalancer

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;
}
Also used : ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with AwsLoadBalancer

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;
}
Also used : AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)

Example 5 with 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());
}
Also used : AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Test(org.junit.jupiter.api.Test)

Aggregations

AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)23 AwsListener (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener)14 ArrayList (java.util.ArrayList)8 AwsTargetGroup (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup)7 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)7 List (java.util.List)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)6 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)6 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Test (org.junit.jupiter.api.Test)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Service (org.springframework.stereotype.Service)6 ModelContext (com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext)5 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)4