Search in sources :

Example 11 with Listener

use of com.amazonaws.services.elasticloadbalancingv2.model.Listener in project cloudbreak by hortonworks.

the class AwsNativeLoadBalancerLaunchService method launchLoadBalancerResources.

public List<CloudResourceStatus> launchLoadBalancerResources(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AmazonElasticLoadBalancingClient loadBalancingClient, boolean registerTargetGroups) {
    LOGGER.debug("Creating AWS load balancer and it's resources for cloud stack: '{}'", authenticatedContext.getCloudContext().getCrn());
    AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
    Map<String, List<String>> privateIdsByGroupName = stack.getGroups().stream().collect(Collectors.toMap(Group::getName, group -> group.getInstances().stream().map(in -> String.valueOf(in.getTemplate().getPrivateId())).collect(toList())));
    List<AwsLoadBalancer> loadBalancers = loadBalancerCommonService.getAwsLoadBalancers(stack.getLoadBalancers(), privateIdsByGroupName, awsNetworkView);
    AwsCloudStackView awsCloudStackView = new AwsCloudStackView(stack);
    Long stackId = authenticatedContext.getCloudContext().getId();
    String stackName = authenticatedContext.getCloudContext().getName();
    Collection<Tag> tags = awsTaggingService.prepareElasticLoadBalancingTags(awsCloudStackView.getTags());
    ResourceCreationContext creationContext = new ResourceCreationContext(stackId, stackName, tags, persistenceNotifier, loadBalancingClient, authenticatedContext.getCloudContext());
    try {
        for (AwsLoadBalancer awsLoadBalancer : loadBalancers) {
            createLoadBalancer(creationContext, awsLoadBalancer);
            if (registerTargetGroups) {
                for (AwsListener listener : awsLoadBalancer.getListeners()) {
                    AwsTargetGroup targetGroup = listener.getTargetGroup();
                    creationContext.setTargetGroupName(resourceNameService.resourceName(ResourceType.ELASTIC_LOAD_BALANCER_TARGET_GROUP, stackName, awsLoadBalancer.getScheme().resourceName(), targetGroup.getPort()));
                    createTargetGroup(creationContext, awsNetworkView, targetGroup);
                    createListener(creationContext, listener);
                    registerTarget(loadBalancingClient, stackId, targetGroup);
                }
            }
        }
    } catch (Exception ex) {
        String message = "Load balancer and it's resources could not be created. " + ex.getMessage();
        LOGGER.warn(message, ex);
        throw new CloudConnectorException(message, ex);
    }
    return creationContext.getResourceStatuses();
}
Also used : AwsResourceNameService(com.sequenceiq.cloudbreak.cloud.aws.common.service.AwsResourceNameService) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreateTargetGroupResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupResult) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) LoggerFactory(org.slf4j.LoggerFactory) DescribeListenersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) CreateListenerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult) StringUtils(org.apache.commons.lang3.StringUtils) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Collectors.toSet(java.util.stream.Collectors.toSet) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) Action(com.amazonaws.services.elasticloadbalancingv2.model.Action) Collection(java.util.Collection) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Set(java.util.Set) LoadBalancerTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerTypeEnum) Collectors(java.util.stream.Collectors) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerRequest) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) IpAddressType(com.amazonaws.services.elasticloadbalancingv2.model.IpAddressType) Tag(com.amazonaws.services.elasticloadbalancingv2.model.Tag) Group(com.sequenceiq.cloudbreak.cloud.model.Group) DescribeListenersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest) Optional(java.util.Optional) CreateListenerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerRequest) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) ArrayList(java.util.ArrayList) TargetTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.TargetTypeEnum) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) PersistenceRetriever(com.sequenceiq.cloudbreak.cloud.notification.PersistenceRetriever) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) AwsLoadBalancerCommonService(com.sequenceiq.cloudbreak.cloud.aws.common.connector.resource.AwsLoadBalancerCommonService) Service(org.springframework.stereotype.Service) CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) ActionTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.ActionTypeEnum) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CreateTargetGroupRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupRequest) ProtocolEnum(com.amazonaws.services.elasticloadbalancingv2.model.ProtocolEnum) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors.toList(java.util.stream.Collectors.toList) AwsCloudStackView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCloudStackView) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AwsTaggingService(com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) AwsCloudStackView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCloudStackView) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) Tag(com.amazonaws.services.elasticloadbalancingv2.model.Tag)

Example 12 with Listener

use of com.amazonaws.services.elasticloadbalancingv2.model.Listener in project aws-cloudwatch-exporter by asserts.

the class TargetGroupLBMapProviderTest method mapLB.

@Test
public void mapLB() {
    Resource lbResource = Resource.builder().arn("lb-arn").build();
    LoadBalancer loadBalancer = LoadBalancer.builder().loadBalancerArn("lb-arn").build();
    Listener listener = Listener.builder().listenerArn("listener-arn").build();
    DescribeListenersRequest request = DescribeListenersRequest.builder().loadBalancerArn("lb-arn").build();
    DescribeListenersResponse response = DescribeListenersResponse.builder().listeners(listener).build();
    expect(resourceMapper.map(loadBalancer.loadBalancerArn())).andReturn(Optional.of(lbResource));
    expect(lbClient.describeListeners(request)).andReturn(response);
    metricCollector.recordLatency(eq(SCRAPE_LATENCY_METRIC), anyObject(SortedMap.class), anyLong());
    AtomicInteger sideEffect = new AtomicInteger();
    TargetGroupLBMapProvider testClass = new TargetGroupLBMapProvider(scrapeConfigProvider, awsClientProvider, resourceMapper, new RateLimiter(metricCollector)) {

        @Override
        void mapListener(ElasticLoadBalancingV2Client theClient, SortedMap<String, String> labels, Resource theResource, Listener theListener) {
            assertEquals(lbClient, theClient);
            assertEquals(lbResource, theResource);
            assertEquals(listener, theListener);
            sideEffect.incrementAndGet();
        }
    };
    replayAll();
    testClass.mapLB(lbClient, labels, loadBalancer);
    assertEquals(1, sideEffect.get());
    verifyAll();
}
Also used : Listener(software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener) DescribeListenersRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) Resource(ai.asserts.aws.resource.Resource) DescribeListenersResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersResponse) LoadBalancer(software.amazon.awssdk.services.elasticloadbalancingv2.model.LoadBalancer) ElasticLoadBalancingV2Client(software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client) RateLimiter(ai.asserts.aws.RateLimiter) Test(org.junit.jupiter.api.Test)

Example 13 with Listener

use of com.amazonaws.services.elasticloadbalancingv2.model.Listener in project aws-cloudwatch-exporter by asserts.

the class TargetGroupLBMapProviderTest method mapListener.

@Test
public void mapListener() {
    Resource lbResource = Resource.builder().arn("lb-arn").build();
    Resource tgResource = Resource.builder().arn("tg-arn").build();
    Listener listener = Listener.builder().listenerArn("listener-arn").build();
    DescribeRulesRequest request = DescribeRulesRequest.builder().listenerArn("listener-arn").build();
    DescribeRulesResponse response = DescribeRulesResponse.builder().rules(Rule.builder().actions(Action.builder().targetGroupArn("tg-arn").build()).build()).build();
    expect(lbClient.describeRules(request)).andReturn(response);
    metricCollector.recordLatency(eq(SCRAPE_LATENCY_METRIC), anyObject(SortedMap.class), anyLong());
    expect(resourceMapper.map("tg-arn")).andReturn(Optional.of(tgResource));
    TargetGroupLBMapProvider testClass = new TargetGroupLBMapProvider(scrapeConfigProvider, awsClientProvider, resourceMapper, new RateLimiter(metricCollector));
    replayAll();
    assertTrue(testClass.getTgToLB().isEmpty());
    testClass.mapListener(lbClient, new TreeMap<>(), lbResource, listener);
    assertEquals(ImmutableMap.of(tgResource, lbResource), testClass.getTgToLB());
    verifyAll();
}
Also used : DescribeRulesRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesRequest) Listener(software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) Resource(ai.asserts.aws.resource.Resource) DescribeRulesResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesResponse) RateLimiter(ai.asserts.aws.RateLimiter) Test(org.junit.jupiter.api.Test)

Example 14 with Listener

use of com.amazonaws.services.elasticloadbalancingv2.model.Listener in project cloudbreak by hortonworks.

the class AwsNativeLoadBalancerLaunchService method launchLoadBalancerResources.

public List<CloudResourceStatus> launchLoadBalancerResources(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AmazonElasticLoadBalancingClient loadBalancingClient) {
    LOGGER.debug("Creating AWS load balancer and it's resources for cloud stack: '{}'", authenticatedContext.getCloudContext().getCrn());
    AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
    Map<String, List<String>> privateIdsByGroupName = stack.getGroups().stream().collect(Collectors.toMap(Group::getName, group -> group.getInstances().stream().map(in -> String.valueOf(in.getTemplate().getPrivateId())).collect(toList())));
    List<AwsLoadBalancer> loadBalancers = loadBalancerCommonService.getAwsLoadBalancers(stack.getLoadBalancers(), privateIdsByGroupName, awsNetworkView);
    AwsCloudStackView awsCloudStackView = new AwsCloudStackView(stack);
    Long stackId = authenticatedContext.getCloudContext().getId();
    String stackName = authenticatedContext.getCloudContext().getName();
    Collection<Tag> tags = awsTaggingService.prepareElasticLoadBalancingTags(awsCloudStackView.getTags());
    ResourceCreationContext creationContext = new ResourceCreationContext(stackId, stackName, tags, persistenceNotifier, loadBalancingClient, authenticatedContext.getCloudContext());
    try {
        for (AwsLoadBalancer awsLoadBalancer : loadBalancers) {
            createLoadBalancer(creationContext, awsLoadBalancer);
            for (AwsListener listener : awsLoadBalancer.getListeners()) {
                AwsTargetGroup targetGroup = listener.getTargetGroup();
                creationContext.setTargetGroupName(resourceNameService.resourceName(ResourceType.ELASTIC_LOAD_BALANCER_TARGET_GROUP, stackName, awsLoadBalancer.getScheme().resourceName(), targetGroup.getPort()));
                createTargetGroup(creationContext, awsNetworkView, targetGroup);
                createListener(creationContext, listener);
                registerTarget(loadBalancingClient, stackId, targetGroup);
            }
        }
    } catch (Exception ex) {
        String message = "Load balancer and it's resources could not be created";
        LOGGER.warn(message, ex);
        throw new CloudConnectorException(message, ex);
    }
    return creationContext.getResourceStatuses();
}
Also used : AwsResourceNameService(com.sequenceiq.cloudbreak.cloud.aws.common.service.AwsResourceNameService) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreateTargetGroupResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupResult) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) LoggerFactory(org.slf4j.LoggerFactory) DescribeListenersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) CreateListenerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult) StringUtils(org.apache.commons.lang3.StringUtils) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Collectors.toSet(java.util.stream.Collectors.toSet) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) Action(com.amazonaws.services.elasticloadbalancingv2.model.Action) Collection(java.util.Collection) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Set(java.util.Set) LoadBalancerTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerTypeEnum) Collectors(java.util.stream.Collectors) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerRequest) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) IpAddressType(com.amazonaws.services.elasticloadbalancingv2.model.IpAddressType) Tag(com.amazonaws.services.elasticloadbalancingv2.model.Tag) Group(com.sequenceiq.cloudbreak.cloud.model.Group) DescribeListenersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest) Optional(java.util.Optional) CreateListenerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerRequest) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) ArrayList(java.util.ArrayList) TargetTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.TargetTypeEnum) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) PersistenceRetriever(com.sequenceiq.cloudbreak.cloud.notification.PersistenceRetriever) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) AwsLoadBalancerCommonService(com.sequenceiq.cloudbreak.cloud.aws.common.connector.resource.AwsLoadBalancerCommonService) Service(org.springframework.stereotype.Service) CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) ActionTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.ActionTypeEnum) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CreateTargetGroupRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupRequest) ProtocolEnum(com.amazonaws.services.elasticloadbalancingv2.model.ProtocolEnum) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors.toList(java.util.stream.Collectors.toList) AwsCloudStackView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCloudStackView) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AwsTaggingService(com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) AwsCloudStackView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCloudStackView) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) Tag(com.amazonaws.services.elasticloadbalancingv2.model.Tag)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)8 CreateListenerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult)8 AmazonElasticLoadBalancingClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient)8 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)8 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)8 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)8 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Optional (java.util.Optional)8 CreateLoadBalancerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult)7 CreateTargetGroupResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupResult)7 DescribeListenersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersResult)7 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)7 DescribeTargetGroupsResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult)7 Tag (com.amazonaws.services.elasticloadbalancingv2.model.Tag)7 AwsTaggingService (com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService)7 AwsLoadBalancerCommonService (com.sequenceiq.cloudbreak.cloud.aws.common.connector.resource.AwsLoadBalancerCommonService)7 AwsResourceNameService (com.sequenceiq.cloudbreak.cloud.aws.common.service.AwsResourceNameService)7 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7