Search in sources :

Example 1 with DescribeListenersRequest

use of software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest in project datarouter by hotpads.

the class ElbService method getTargetGroupsArn.

public List<String> getTargetGroupsArn(String loadBalancerArn) {
    var request = new DescribeListenersRequest().withLoadBalancerArn(loadBalancerArn);
    int randomSleepMs = RandomTool.getRandomIntBetweenTwoNumbers(0, 3_000);
    return RetryableTool.tryNTimesWithBackoffAndRandomInitialDelayUnchecked(() -> amazonElasticLoadBalancing.get().describeListeners(request).getListeners().stream().map(Listener::getDefaultActions).flatMap(List::stream).map(Action::getTargetGroupArn).filter(// remove action that have no tg (like redirect)
    Objects::nonNull).distinct().collect(Collectors.toList()), NUM_ATTEMPTS, randomSleepMs, true);
}
Also used : Action(com.amazonaws.services.elasticloadbalancingv2.model.Action) Listener(com.amazonaws.services.elasticloadbalancingv2.model.Listener) DescribeListenersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest)

Example 2 with DescribeListenersRequest

use of software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest in project aws-cloudwatch-exporter by asserts.

the class TargetGroupLBMapProvider method mapLB.

@VisibleForTesting
void mapLB(ElasticLoadBalancingV2Client lbClient, SortedMap<String, String> labels, LoadBalancer lb) {
    String lbArn = lb.loadBalancerArn();
    resourceMapper.map(lbArn).ifPresent(lbResource -> {
        String api = "ElasticLoadBalancingV2Client/describeListeners";
        SortedMap<String, String> telemetryLabels = new TreeMap<>(labels);
        telemetryLabels.put(SCRAPE_OPERATION_LABEL, api);
        rateLimiter.doWithRateLimit(api, telemetryLabels, () -> {
            DescribeListenersRequest listenersRequest = DescribeListenersRequest.builder().loadBalancerArn(lbArn).build();
            DescribeListenersResponse listenersResponse = lbClient.describeListeners(listenersRequest);
            if (!isEmpty(listenersResponse.listeners())) {
                listenersResponse.listeners().forEach(listener -> mapListener(lbClient, labels, lbResource, listener));
            }
            return null;
        });
    });
}
Also used : DescribeListenersRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest) DescribeListenersResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersResponse) TreeMap(java.util.TreeMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with DescribeListenersRequest

use of software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest 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)

Aggregations

DescribeListenersRequest (software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest)2 DescribeListenersResponse (software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersResponse)2 RateLimiter (ai.asserts.aws.RateLimiter)1 Resource (ai.asserts.aws.resource.Resource)1 Action (com.amazonaws.services.elasticloadbalancingv2.model.Action)1 DescribeListenersRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest)1 Listener (com.amazonaws.services.elasticloadbalancingv2.model.Listener)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.jupiter.api.Test)1 ElasticLoadBalancingV2Client (software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client)1 Listener (software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener)1 LoadBalancer (software.amazon.awssdk.services.elasticloadbalancingv2.model.LoadBalancer)1