Search in sources :

Example 1 with AwsListener

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());
    }
}
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 2 with AwsListener

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);
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudFormationTemplateBuilder(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary)

Example 3 with AwsListener

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;
}
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 AwsListener

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());
}
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)

Example 5 with AwsListener

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());
}
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

AwsListener (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener)13 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)12 AwsTargetGroup (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)4 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.jupiter.api.Test)4 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)3 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3 Set (java.util.Set)3 Inject (javax.inject.Inject)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Service (org.springframework.stereotype.Service)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2