use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonService method convertLoadBalancer.
@VisibleForTesting
AwsLoadBalancer convertLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsNetworkView awsNetworkView, List<AwsLoadBalancer> awsLoadBalancers) {
// Check and see if we already have a load balancer whose scheme matches this one.
AwsLoadBalancer currentLoadBalancer = null;
LoadBalancerType cloudLbType = cloudLoadBalancer.getType();
Set<String> subnetIds = selectLoadBalancerSubnetIds(cloudLbType, awsNetworkView, cloudLoadBalancer);
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(cloudLbType);
currentLoadBalancer = awsLoadBalancers.stream().filter(lb -> lb.getScheme() == scheme).findFirst().orElse(new AwsLoadBalancer(scheme));
currentLoadBalancer.addSubnets(subnetIds);
setupLoadBalancer(cloudLoadBalancer, instanceIdsByGroupName, currentLoadBalancer);
return currentLoadBalancer;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme 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;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme in project cloudbreak by hortonworks.
the class AwsDownscaleService method getTargetGroupArns.
private List<String> getTargetGroupArns(List<CloudLoadBalancer> loadBalancers, AuthenticatedContext auth) {
List<String> targetGroupArns = new ArrayList<>();
for (CloudLoadBalancer loadBalancer : loadBalancers) {
for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : loadBalancer.getPortToTargetGroupMapping().entrySet()) {
String region = auth.getCloudContext().getLocation().getRegion().value();
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
String targetGroupArn = cfStackUtil.getResourceArnByLogicalId(auth, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
targetGroupArns.add(targetGroupArn);
}
}
return targetGroupArns;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method addLoadBalancerTargets.
public void addLoadBalancerTargets(AuthenticatedContext ac, CloudLoadBalancer loadBalancer, List<CloudResource> resourcesToAdd) {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : loadBalancer.getPortToTargetGroupMapping().entrySet()) {
// Get a list of the new instances in the target groups
Set<String> updatedInstanceIds = getInstanceIdsForGroups(resourcesToAdd, entry.getValue());
// Find target group ARN
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
String targetGroupArn = getResourceArnByLogicalId(ac, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
// Use ARN to fetch a list of current targets
DescribeTargetHealthResult targetHealthResult = amazonElbClient.describeTargetHealth(new DescribeTargetHealthRequest().withTargetGroupArn(targetGroupArn));
List<TargetDescription> targetDescriptions = targetHealthResult.getTargetHealthDescriptions().stream().map(TargetHealthDescription::getTarget).collect(Collectors.toList());
Set<String> alreadyRegisteredInstanceIds = targetDescriptions.stream().map(TargetDescription::getId).collect(Collectors.toSet());
// Remove any targets that have already been registered from the list being processed
updatedInstanceIds.removeAll(alreadyRegisteredInstanceIds);
// Register any new instances
if (!updatedInstanceIds.isEmpty()) {
List<TargetDescription> targetsToAdd = updatedInstanceIds.stream().map(instanceId -> new TargetDescription().withId(instanceId)).collect(Collectors.toList());
RegisterTargetsResult registerTargetsResult = amazonElbClient.registerTargets(new RegisterTargetsRequest().withTargetGroupArn(targetGroupArn).withTargets(targetsToAdd));
}
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme in project cloudbreak by hortonworks.
the class AwsLoadBalancerMetadataCollectorTest method createSummaries.
private List<StackResourceSummary> createSummaries(int numPorts, boolean includeTargetGroup) {
List<StackResourceSummary> summaries = new ArrayList<>();
for (AwsLoadBalancerScheme scheme : AwsLoadBalancerScheme.class.getEnumConstants()) {
StackResourceSummary lbSummary = new StackResourceSummary();
lbSummary.setLogicalResourceId(AwsLoadBalancer.getLoadBalancerName(scheme));
lbSummary.setPhysicalResourceId(LOAD_BALANCER_ARN + scheme.resourceName());
summaries.add(lbSummary);
for (int i = 0; i < numPorts; i++) {
if (includeTargetGroup) {
StackResourceSummary tgSummary = new StackResourceSummary();
tgSummary.setLogicalResourceId(AwsTargetGroup.getTargetGroupName(i, scheme));
tgSummary.setPhysicalResourceId(TARGET_GROUP_ARN + i + scheme.resourceName());
summaries.add(tgSummary);
}
StackResourceSummary lSummary = new StackResourceSummary();
lSummary.setLogicalResourceId(AwsListener.getListenerName(i, scheme));
lSummary.setPhysicalResourceId(LISTENER_ARN + i + scheme.resourceName());
summaries.add(lSummary);
}
}
return summaries;
}
Aggregations