use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient 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