Search in sources :

Example 1 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnectorTest method validateTargetGroupNotFoundExceptionIsTranslatedToRemovedState.

@Test
public void validateTargetGroupNotFoundExceptionIsTranslatedToRemovedState() {
    TestSubscriber testSubscriber = new TestSubscriber();
    AmazonElasticLoadBalancingAsync albClient = mock(AmazonElasticLoadBalancingAsync.class);
    when(albClient.describeTargetHealthAsync(any(), any())).thenThrow(TargetGroupNotFoundException.class);
    awsLoadBalancerConnector = getAwsLoadBalancerConnector(albClient);
    awsLoadBalancerConnector.getLoadBalancer(targetGroupWithTargets).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    LoadBalancer loadBalancer = (LoadBalancer) testSubscriber.getOnNextEvents().get(0);
    assertEquals(targetGroupWithTargets, loadBalancer.getId());
    assertEquals(LoadBalancer.State.REMOVED, loadBalancer.getState());
}
Also used : TestSubscriber(rx.observers.TestSubscriber) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) Test(org.junit.Test)

Example 2 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnector method getLoadBalancer.

@Override
public Single<LoadBalancer> getLoadBalancer(String loadBalancerId) {
    final DescribeTargetHealthRequest request = new DescribeTargetHealthRequest().withTargetGroupArn(loadBalancerId);
    long startTime = registry.clock().wallTime();
    Single<DescribeTargetHealthResult> asyncResult = AwsObservableExt.asyncActionSingle(factory -> getClient(loadBalancerId).describeTargetHealthAsync(request, factory.handler()));
    return asyncResult.observeOn(scheduler).map(result -> {
        connectorMetrics.success(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetHealth, startTime);
        Set<String> ips = result.getTargetHealthDescriptions().stream().map(description -> description.getTarget().getId()).collect(Collectors.toSet());
        return new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, ips);
    }).onErrorResumeNext(throwable -> {
        connectorMetrics.failure(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetHealth, throwable, startTime);
        if (throwable instanceof TargetGroupNotFoundException) {
            return Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.REMOVED, Collections.emptySet()));
        }
        return Single.error(throwable);
    });
}
Also used : DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Completable(rx.Completable) LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) DeregisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DeregisterTargetsRequest) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) ProxyType(com.netflix.titus.common.util.guice.ProxyType) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) Observable(rx.Observable) Inject(javax.inject.Inject) TargetGroupNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupNotFoundException) Single(rx.Single) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) CloudConnectorException(com.netflix.titus.api.connector.cloud.CloudConnectorException) Schedulers(rx.schedulers.Schedulers) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) Logger(org.slf4j.Logger) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult) AmazonClientProvider(com.netflix.titus.ext.aws.AmazonClientProvider) Set(java.util.Set) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) AwsObservableExt(com.netflix.titus.ext.aws.AwsObservableExt) Scheduler(rx.Scheduler) Collectors(java.util.stream.Collectors) Registry(com.netflix.spectator.api.Registry) ProxyConfiguration(com.netflix.titus.common.util.guice.annotation.ProxyConfiguration) Arn(com.amazonaws.arn.Arn) Collections(java.util.Collections) DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Set(java.util.Set) TargetGroupNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupNotFoundException) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult)

Example 3 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project datarouter by hotpads.

the class AwsElbConfigScanner method getAlbSchemeForEc2Instance.

private Map<String, Boolean> getAlbSchemeForEc2Instance(String serverType, String ec2InstanceId) {
    Map<String, Boolean> privatePublicAlbsMap = new HashMap<>();
    boolean unknownAlb = true;
    boolean instanceHasPublicAlb = false;
    boolean instanceHasPrivateAlb = false;
    for (LoadBalancer loadBalancer : elbService.getLoadBalancers()) {
        // exact ALB name
        if (!loadBalancer.getLoadBalancerName().equals(serverType) && !loadBalancer.getLoadBalancerName().startsWith(serverType + "-privat")) {
            continue;
        }
        for (String targetGroupArn : elbService.getTargetGroupsArn(loadBalancer.getLoadBalancerArn())) {
            for (String targetEc2InstanceId : elbService.getTargetEc2InstancesId(targetGroupArn)) {
                if (!targetEc2InstanceId.equals(ec2InstanceId)) {
                    continue;
                }
                LoadBalancerSchemeEnum loadBalancerScheme = LoadBalancerSchemeEnum.fromValue(loadBalancer.getScheme());
                if (LoadBalancerSchemeEnum.InternetFacing == loadBalancerScheme) {
                    instanceHasPublicAlb = true;
                }
                if (LoadBalancerSchemeEnum.Internal == loadBalancerScheme) {
                    instanceHasPrivateAlb = true;
                }
                unknownAlb = false;
            }
        }
    }
    privatePublicAlbsMap.put(HAS_PUBLIC_LOAD_BALANCER_KEY, instanceHasPublicAlb);
    privatePublicAlbsMap.put(HAS_PRIVATE_LOAD_BALANCER_KEY, instanceHasPrivateAlb);
    privatePublicAlbsMap.put(UNKNOWN_LOAD_BALANCER, unknownAlb);
    return privatePublicAlbsMap;
}
Also used : HashMap(java.util.HashMap) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) LoadBalancerSchemeEnum(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerSchemeEnum)

Example 4 with LoadBalancer

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

the class TargetGroupLBMapProviderTest method update.

@Test
public void update() {
    LoadBalancer loadBalancer = LoadBalancer.builder().loadBalancerArn("lb-arn").build();
    expect(awsClientProvider.getELBV2Client("region")).andReturn(lbClient);
    expect(lbClient.describeLoadBalancers()).andReturn(DescribeLoadBalancersResponse.builder().loadBalancers(loadBalancer).build());
    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 mapLB(ElasticLoadBalancingV2Client client, SortedMap<String, String> theLabels, LoadBalancer theLb) {
            assertEquals(lbClient, client);
            assertEquals(labels, theLabels);
            assertEquals(loadBalancer, theLb);
            sideEffect.incrementAndGet();
        }
    };
    lbClient.close();
    replayAll();
    testClass.update();
    assertEquals(1, sideEffect.get());
    verifyAll();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) 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 5 with LoadBalancer

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

the class AwsMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
    LOGGER.debug("Collect AWS load balancer metadata, for cluster {}", ac.getCloudContext().getName());
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = new ArrayList<>();
    for (LoadBalancerType type : loadBalancerTypes) {
        AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(type);
        String loadBalancerName = AwsLoadBalancer.getLoadBalancerName(scheme);
        LOGGER.debug("Attempting to collect metadata for load balancer {}, type {}", loadBalancerName, type);
        try {
            LoadBalancer loadBalancer = cloudFormationStackUtil.getLoadBalancerByLogicalId(ac, loadBalancerName);
            LOGGER.debug("Parsing all listener and target group information for load balancer {}", loadBalancerName);
            Map<String, Object> parameters = awsLoadBalancerMetadataCollector.getParameters(ac, loadBalancer, scheme);
            CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(type).withCloudDns(loadBalancer.getDNSName()).withHostedZoneId(loadBalancer.getCanonicalHostedZoneId()).withName(loadBalancerName).withParameters(parameters).build();
            cloudLoadBalancerMetadata.add(loadBalancerMetadata);
            LOGGER.debug("Saved metadata for load balancer {}: DNS {}, zone id {}", loadBalancerName, loadBalancer.getDNSName(), loadBalancer.getCanonicalHostedZoneId());
        } catch (RuntimeException e) {
            LOGGER.debug("Unable to find metadata for load balancer " + loadBalancerName, e);
        }
    }
    return cloudLoadBalancerMetadata;
}
Also used : ArrayList(java.util.ArrayList) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Aggregations

LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)20 Test (org.junit.jupiter.api.Test)16 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)14 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)14 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)13 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)12 AmazonServiceException (com.amazonaws.AmazonServiceException)10 AmazonElasticLoadBalancingClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient)10 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)10 ArrayList (java.util.ArrayList)10 AmazonElasticLoadBalancingException (com.amazonaws.services.elasticloadbalancingv2.model.AmazonElasticLoadBalancingException)9 RegisterTargetsResult (com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsResult)9 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 CommonStatus (com.sequenceiq.common.api.type.CommonStatus)9 ResourceType (com.sequenceiq.common.api.type.ResourceType)9 List (java.util.List)9 Map (java.util.Map)9 CreateLoadBalancerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult)8 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 CreateListenerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult)7