use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method getLoadBalancerByLogicalId.
public LoadBalancer getLoadBalancerByLogicalId(AuthenticatedContext ac, String logicalId) {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
String loadBalancerArn = getResourceArnByLogicalId(ac, logicalId, region);
DescribeLoadBalancersResult loadBalancersResult = amazonElbClient.describeLoadBalancers(new DescribeLoadBalancersRequest().withLoadBalancerArns(Collections.singletonList(loadBalancerArn)));
return loadBalancersResult.getLoadBalancers().get(0);
}
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, 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.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerTargetGroupResourceBuilder method delete.
@Override
public CloudResource delete(AwsContext context, com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext auth, CloudResource resource) throws Exception {
LOGGER.info("Deleting load balancer's ('{}') target group with arn '{}'", resource.getReference(), resource.getInstanceId());
AmazonElasticLoadBalancingClient loadBalancingClient = context.getLoadBalancingClient();
DeleteTargetGroupRequest deleteTargetGroupRequest = new DeleteTargetGroupRequest().withTargetGroupArn(resource.getReference());
DeleteTargetGroupResult deleteResult = awsMethodExecutor.execute(() -> loadBalancingClient.deleteTargetGroup(deleteTargetGroupRequest), null);
return deleteResult != null ? resource : null;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class AwsNativeMetadataCollector method collectLoadBalancer.
@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> lbTypes, List<CloudResource> resources) {
List<CloudLoadBalancerMetadata> result = new ArrayList<>();
String region = ac.getCloudContext().getLocation().getRegion().value();
AwsCredentialView awsCredential = new AwsCredentialView(ac.getCloudCredential());
LOGGER.debug("Collect AWS load balancer metadata, for cluster {}", ac.getCloudContext().getName());
Set<CloudResource> loadBalancers = resources.stream().filter(resource -> ResourceType.ELASTIC_LOAD_BALANCER.equals(resource.getType())).collect(Collectors.toSet());
Set<String> loadBalancerArns = loadBalancers.stream().map(CloudResource::getReference).collect(Collectors.toSet());
AmazonElasticLoadBalancingClient loadBalancingClient = awsClient.createElasticLoadBalancingClient(awsCredential, region);
LOGGER.info("Collect AWS load balancer metadata, in region '{}' with ARNs: '{}'", region, String.join(", ", loadBalancerArns));
for (String loadBalancerArn : loadBalancerArns) {
Optional<CloudLoadBalancerMetadata> collectedLoadBalancer = collectLoadBalancerMetadata(loadBalancingClient, loadBalancerArn, resources);
collectedLoadBalancer.ifPresent(result::add);
}
return result;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method removeLoadBalancerTargets.
public void removeLoadBalancerTargets(AuthenticatedContext ac, CloudLoadBalancer loadBalancer, List<CloudResource> resourcesToRemove) {
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 instance ids to remove
Set<String> instancesToRemove = getInstanceIdsForGroups(resourcesToRemove, entry.getValue());
// Find target group ARN
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
String targetGroupArn = getResourceArnByLogicalId(ac, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
// Deregister any instances that no longer exist
if (!instancesToRemove.isEmpty()) {
try {
List<TargetDescription> targetsToRemove = instancesToRemove.stream().map(instanceId -> new TargetDescription().withId(instanceId)).collect(Collectors.toList());
DeregisterTargetsResult deregisterTargetsResult = amazonElbClient.deregisterTargets(new DeregisterTargetsRequest().withTargetGroupArn(targetGroupArn).withTargets(targetsToRemove));
} catch (InvalidTargetException ignored) {
// no-op - we tried to remove a target that wasn't in the target group, which is fine
}
}
}
}
Aggregations