Search in sources :

Example 1 with DescribeLoadBalancersRequest

use of com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest in project photon-model by vmware.

the class AWSLoadBalancerServiceTest method getAwsLoadBalancer.

private LoadBalancerDescription getAwsLoadBalancer(String name) {
    DescribeLoadBalancersRequest describeRequest = new DescribeLoadBalancersRequest().withLoadBalancerNames(name);
    DescribeLoadBalancersResult describeResult = null;
    try {
        describeResult = this.client.describeLoadBalancers(describeRequest);
    } catch (Exception e) {
        this.host.log("Exception describing load balancers with name '%s': %s", name, e.toString());
    }
    Collection<LoadBalancerDescription> lbs = describeResult != null ? describeResult.getLoadBalancerDescriptions() : null;
    if (lbs == null || lbs.isEmpty()) {
        return null;
    }
    if (lbs.size() > 1) {
        throw new IllegalStateException("More than one load balancers found with name '" + name + "'.");
    }
    return lbs.iterator().next();
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) CompletionException(java.util.concurrent.CompletionException)

Example 2 with DescribeLoadBalancersRequest

use of com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest in project SimianArmy by Netflix.

the class AWSClient method describeElasticLoadBalancers.

/**
     * Describe a set of specific ELBs.
     *
     * @param names the ELB names
     * @return the ELBs
     */
public List<LoadBalancerDescription> describeElasticLoadBalancers(String... names) {
    if (names == null || names.length == 0) {
        LOGGER.info(String.format("Getting all ELBs in region %s.", region));
    } else {
        LOGGER.info(String.format("Getting ELBs for %d names in region %s.", names.length, region));
    }
    AmazonElasticLoadBalancingClient elbClient = elbClient();
    DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest().withLoadBalancerNames(names);
    DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request);
    List<LoadBalancerDescription> elbs = result.getLoadBalancerDescriptions();
    LOGGER.info(String.format("Got %d ELBs in region %s.", elbs.size(), region));
    return elbs;
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) AmazonElasticLoadBalancingClient(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)

Example 3 with DescribeLoadBalancersRequest

use of com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest in project ignite by apache.

the class TcpDiscoveryElbIpFinder method getRegisteredAddresses.

/**
 * {@inheritDoc}
 */
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
    initClients();
    List<String> instanceIds = new ArrayList<>();
    DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName);
    List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions();
    for (LoadBalancerDescription desc : descs) {
        for (Instance instance : desc.getInstances()) instanceIds.add(instance.getInstanceId());
    }
    DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
    List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations();
    List<InetSocketAddress> addrs = new ArrayList<>();
    for (Reservation reservation : reservations) {
        List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances();
        for (com.amazonaws.services.ec2.model.Instance instance : instances) addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0));
    }
    return addrs;
}
Also used : Instance(com.amazonaws.services.elasticloadbalancing.model.Instance) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Reservation(com.amazonaws.services.ec2.model.Reservation) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)

Example 4 with DescribeLoadBalancersRequest

use of com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest in project photon-model by vmware.

the class AWSLoadBalancerService method getAWSLoadBalancer.

private DeferredResult<AWSLoadBalancerContext> getAWSLoadBalancer(AWSLoadBalancerContext context) {
    DescribeLoadBalancersRequest describeRequest = new DescribeLoadBalancersRequest().withLoadBalancerNames(context.loadBalancerStateExpanded.name);
    String message = "Describing AWS load balancer [" + context.loadBalancerStateExpanded.name + "].";
    AWSDeferredResultAsyncHandler<DescribeLoadBalancersRequest, DescribeLoadBalancersResult> handler = new AWSDeferredResultAsyncHandler<>(this, message);
    context.client.describeLoadBalancersAsync(describeRequest, handler);
    return handler.toDeferredResult().thenCompose(result -> {
        List<com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription> lbs = result.getLoadBalancerDescriptions();
        if (lbs != null && !lbs.isEmpty() && lbs.size() == 1) {
            context.registeredInstances = lbs.iterator().next().getInstances();
            return DeferredResult.completed(context);
        }
        return DeferredResult.failed(new IllegalStateException("Unable to describe load balancer with name '" + context.loadBalancerStateExpanded.name + "' for update"));
    });
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) LoadBalancerDescription(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)

Example 5 with DescribeLoadBalancersRequest

use of com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest in project iep by Netflix.

the class PaginationTest method elb.

@Test
public void elb() throws Exception {
    SortedSet<String> pages = newPageSet(5);
    final Iterator<String> reqIt = pages.iterator();
    final Iterator<String> resIt = pages.iterator();
    Function<DescribeLoadBalancersRequest, DescribeLoadBalancersResult> f = r -> {
        if (r.getMarker() != null) {
            Assert.assertEquals(reqIt.next(), r.getMarker());
        }
        return new DescribeLoadBalancersResult().withNextMarker(resIt.hasNext() ? resIt.next() : null);
    };
    Publisher<DescribeLoadBalancersResult> publisher = Pagination.createPublisher(new DescribeLoadBalancersRequest(), f);
    Iterable<String> iter = Flowable.fromPublisher(publisher).filter(r -> r.getNextMarker() != null).map(DescribeLoadBalancersResult::getNextMarker).blockingIterable();
    SortedSet<String> results = new TreeSet<>();
    for (String s : iter) {
        results.add(s);
    }
    Assert.assertEquals(pages, results);
    Assert.assertFalse(reqIt.hasNext());
}
Also used : ListHostedZonesResult(com.amazonaws.services.route53.model.ListHostedZonesResult) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) SortedSet(java.util.SortedSet) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ListMetricsResult(com.amazonaws.services.cloudwatch.model.ListMetricsResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Function(java.util.function.Function) TreeSet(java.util.TreeSet) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) Iterator(java.util.Iterator) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Publisher(org.reactivestreams.Publisher) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult) ListHostedZonesRequest(com.amazonaws.services.route53.model.ListHostedZonesRequest) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) PutMetricDataResult(com.amazonaws.services.cloudwatch.model.PutMetricDataResult) Assert(org.junit.Assert) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) TreeSet(java.util.TreeSet) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Test(org.junit.Test)

Aggregations

DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)5 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult)4 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)2 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 ListMetricsRequest (com.amazonaws.services.cloudwatch.model.ListMetricsRequest)1 ListMetricsResult (com.amazonaws.services.cloudwatch.model.ListMetricsResult)1 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 AmazonElasticLoadBalancingClient (com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient)1 Instance (com.amazonaws.services.elasticloadbalancing.model.Instance)1 DescribeTargetGroupsRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest)1 DescribeTargetGroupsResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult)1 ListClustersRequest (com.amazonaws.services.elasticmapreduce.model.ListClustersRequest)1