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