Search in sources :

Example 1 with DescribeTargetHealthResult

use of com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnector method getLoadBalancer.

@Override
public Single<LoadBalancer> getLoadBalancer(String loadBalancerId) {
    final DescribeTargetHealthRequest request = new DescribeTargetHealthRequest().withTargetGroupArn(loadBalancerId);
    long startTime = registry.clock().wallTime();
    Single<DescribeTargetHealthResult> asyncResult = AwsObservableExt.asyncActionSingle(factory -> getClient(loadBalancerId).describeTargetHealthAsync(request, factory.handler()));
    return asyncResult.observeOn(scheduler).map(result -> {
        connectorMetrics.success(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetHealth, startTime);
        Set<String> ips = result.getTargetHealthDescriptions().stream().map(description -> description.getTarget().getId()).collect(Collectors.toSet());
        return new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, ips);
    }).onErrorResumeNext(throwable -> {
        connectorMetrics.failure(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetHealth, throwable, startTime);
        if (throwable instanceof TargetGroupNotFoundException) {
            return Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.REMOVED, Collections.emptySet()));
        }
        return Single.error(throwable);
    });
}
Also used : DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Completable(rx.Completable) LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) DeregisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DeregisterTargetsRequest) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) ProxyType(com.netflix.titus.common.util.guice.ProxyType) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) Observable(rx.Observable) Inject(javax.inject.Inject) TargetGroupNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupNotFoundException) Single(rx.Single) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) CloudConnectorException(com.netflix.titus.api.connector.cloud.CloudConnectorException) Schedulers(rx.schedulers.Schedulers) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) Logger(org.slf4j.Logger) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult) AmazonClientProvider(com.netflix.titus.ext.aws.AmazonClientProvider) Set(java.util.Set) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) AwsObservableExt(com.netflix.titus.ext.aws.AwsObservableExt) Scheduler(rx.Scheduler) Collectors(java.util.stream.Collectors) Registry(com.netflix.spectator.api.Registry) ProxyConfiguration(com.netflix.titus.common.util.guice.annotation.ProxyConfiguration) Arn(com.amazonaws.arn.Arn) Collections(java.util.Collections) DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Set(java.util.Set) TargetGroupNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupNotFoundException) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult)

Example 2 with DescribeTargetHealthResult

use of com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult 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));
        }
    }
}
Also used : RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TargetHealthDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetHealthDescription) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Splitter(com.google.common.base.Splitter) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult) Collection(java.util.Collection) Output(com.amazonaws.services.cloudformation.model.Output) Set(java.util.Set) Retry(com.sequenceiq.cloudbreak.service.Retry) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) Objects(java.util.Objects) List(java.util.List) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) Group(com.sequenceiq.cloudbreak.cloud.model.Group) PRIVATE_ID(com.sequenceiq.cloudbreak.cloud.model.CloudResource.PRIVATE_ID) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) INSTANCE_TYPE(com.sequenceiq.cloudbreak.cloud.model.CloudResource.INSTANCE_TYPE) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) Supplier(java.util.function.Supplier) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Service(org.springframework.stereotype.Service) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) Retryable(org.springframework.retry.annotation.Retryable) DescribeStackResourceRequest(com.amazonaws.services.cloudformation.model.DescribeStackResourceRequest) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FileSystemDescription(com.amazonaws.services.elasticfilesystem.model.FileSystemDescription) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DescribeFileSystemsRequest(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsRequest) RegisterTargetsResult(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsResult) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) SdkClientException(com.amazonaws.SdkClientException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Instance(com.amazonaws.services.autoscaling.model.Instance) DescribeStackResourceResult(com.amazonaws.services.cloudformation.model.DescribeStackResourceResult) Collections(java.util.Collections) DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Set(java.util.Set) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult) RegisterTargetsResult(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsResult) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) Map(java.util.Map) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Aggregations

DescribeTargetHealthRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest)2 DescribeTargetHealthResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult)2 RegisterTargetsRequest (com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest)2 TargetDescription (com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription)2 Collections (java.util.Collections)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 SdkClientException (com.amazonaws.SdkClientException)1 Arn (com.amazonaws.arn.Arn)1 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 Instance (com.amazonaws.services.autoscaling.model.Instance)1 DescribeStackResourceRequest (com.amazonaws.services.cloudformation.model.DescribeStackResourceRequest)1 DescribeStackResourceResult (com.amazonaws.services.cloudformation.model.DescribeStackResourceResult)1 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 Output (com.amazonaws.services.cloudformation.model.Output)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1