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