use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class LoadBalancerRecreatorService method recreate.
@Override
public void recreate(CreateResourcesRequest request, AwsContext awsContext, AuthenticatedContext ac) throws Exception {
LOGGER.info("Launching elastic load balancers");
CloudCredential cloudCredential = ac.getCloudCredential();
String region = ac.getCloudContext().getLocation().getRegion().value();
AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
AmazonElasticLoadBalancingClient elasticLoadBalancingClient = commonAwsClient.createElasticLoadBalancingClient(awsCredentialView, region);
CloudStack cloudStack = request.getCloudStack();
loadBalancerLaunchService.launchLoadBalancerResources(ac, cloudStack, persistenceNotifier, elasticLoadBalancingClient, false);
List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = collectLoadBalancerMetadata(ac, ac.getCloudContext().getId());
Stack stack = stackService.getByIdWithLists(ac.getCloudContext().getId());
metadataSetupService.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetadata);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient 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.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerLaunchService method registerTarget.
private void registerTarget(AmazonElasticLoadBalancingClient loadBalancingClient, Long stackId, AwsTargetGroup targetGroup) {
LOGGER.debug("Registering targets to target group '{}'", targetGroup.getArn());
Set<TargetDescription> targetDescriptions = targetGroup.getInstanceIds().stream().map(privateId -> {
String instanceId = persistenceRetriever.notifyRetrieve(stackId, privateId, CommonStatus.CREATED, ResourceType.AWS_INSTANCE).orElseThrow(() -> {
String notFoundMsg = String.format("No AWS instance resource found with private id('%s') for stack('%s')", privateId, stackId);
return new CloudConnectorException(notFoundMsg);
}).getInstanceId();
return new TargetDescription().withPort(targetGroup.getPort()).withId(instanceId);
}).collect(toSet());
RegisterTargetsRequest registerTargetsRequest = new RegisterTargetsRequest().withTargetGroupArn(targetGroup.getArn()).withTargets(targetDescriptions);
LOGGER.info("Registering target group of load balancer('{}') to instances: '{}'", targetGroup.getArn(), String.join(",", targetGroup.getInstanceIds()));
loadBalancingClient.registerTargets(registerTargetsRequest);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerListenerResourceBuilder method delete.
@Override
public CloudResource delete(AwsContext context, com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext auth, CloudResource resource) throws Exception {
LOGGER.info("Trying to delete listener '{}', may it has already been deleted with it's related load balancer '{}'", resource.getReference(), resource.getInstanceId());
AmazonElasticLoadBalancingClient loadBalancingClient = context.getLoadBalancingClient();
DeleteListenerRequest deleteListenerRequest = new DeleteListenerRequest().withListenerArn(resource.getReference());
DeleteListenerResult deleteResult = null;
try {
deleteResult = awsMethodExecutor.execute(() -> loadBalancingClient.deleteListener(deleteListenerRequest), null);
} catch (AmazonServiceException awsException) {
if (StringUtils.isNotEmpty(awsException.getErrorCode()) && LISTENER_NOT_FOUND_ERROR_CODE.equals(awsException.getErrorCode())) {
LOGGER.info("Listener doesn't exist with id: '{}'", resource.getReference());
} else {
LOGGER.warn("Listener could not be fetched from AWS with id: '{}'", resource.getReference(), awsException);
throw awsException;
}
}
return deleteResult != null ? resource : null;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerResourceBuilder method delete.
@Override
public CloudResource delete(AwsContext context, AuthenticatedContext auth, CloudResource resource) throws Exception {
LOGGER.info("Deleting load balancer ('{}') from provider side", resource.getReference());
AmazonElasticLoadBalancingClient loadBalancingClient = context.getLoadBalancingClient();
DeleteLoadBalancerRequest deleteLoadBalancerRequest = new DeleteLoadBalancerRequest().withLoadBalancerArn(resource.getReference());
DeleteLoadBalancerResult deleteResult = awsMethodExecutor.execute(() -> loadBalancingClient.deleteLoadBalancer(deleteLoadBalancerRequest), null);
return deleteResult != null ? resource : null;
}
Aggregations