use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup in project cloudbreak by hortonworks.
the class AwsLaunchServiceLoadBalancerTest method testSetLoadBalancerMetadata.
@Test
public void testSetLoadBalancerMetadata() {
AwsLoadBalancer loadBalancer = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNAL);
loadBalancer.getOrCreateListener(PORT, PORT);
when(result.getStackResourceSummaries()).thenReturn(createFullSummaries(Set.of(LoadBalancerType.PRIVATE)));
underTest.setLoadBalancerMetadata(List.of(loadBalancer), result);
assertEquals(LOAD_BALANCER_ARN, loadBalancer.getArn());
AwsListener listener = loadBalancer.getListeners().iterator().next();
assert listener.areTargetGroupArnsSet();
AwsTargetGroup targetGroup = listener.getTargetGroup();
assertEquals(TARGET_GROUP_ARN, targetGroup.getArn());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup 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.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup 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