From 6b832c79cf6391f44d1ba6c81667846e80b96a0c Mon Sep 17 00:00:00 2001 From: Lili Nader Date: Fri, 20 Aug 2010 18:20:58 -0700 Subject: [PATCH] minor improvements to elastic load balancer functionality --- .../main/java/org/jclouds/aws/elb/ELBAsyncClient.java | 3 +-- .../src/main/java/org/jclouds/aws/elb/ELBClient.java | 7 ++++++- .../ec2/compute/EC2LoadBalancerServiceLiveTest.java | 10 ++++++---- .../java/org/jclouds/aws/elb/ELBClientLiveTest.java | 3 +-- .../java/org/jclouds/compute/LoadBalancerService.java | 3 +++ .../compute/internal/BaseLoadBalancerService.java | 11 +++++++++++ 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/elb/ELBAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/elb/ELBAsyncClient.java index 53c76a190f..f0e1c47f49 100644 --- a/aws/core/src/main/java/org/jclouds/aws/elb/ELBAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/elb/ELBAsyncClient.java @@ -114,7 +114,6 @@ public interface ELBAsyncClient { @XMLResponseParser(DescribeLoadBalancersResponseHandler.class) @FormParams(keys = ACTION, values = "DescribeLoadBalancers") ListenableFuture> describeLoadBalancersInRegion( - @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, - @FormParam("LoadBalancerName") @Nullable String name); + @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); } diff --git a/aws/core/src/main/java/org/jclouds/aws/elb/ELBClient.java b/aws/core/src/main/java/org/jclouds/aws/elb/ELBClient.java index 86a49d6853..2013fe03a0 100644 --- a/aws/core/src/main/java/org/jclouds/aws/elb/ELBClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/elb/ELBClient.java @@ -94,6 +94,11 @@ public interface ELBClient { void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name, String... instanceIds); - Set describeLoadBalancersInRegion(@Nullable String region, @Nullable String name); + /** + * Returns a set of elastic load balancers + * @param region + * @return + */ + Set describeLoadBalancersInRegion(@Nullable String region); } \ No newline at end of file diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2LoadBalancerServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2LoadBalancerServiceLiveTest.java index d829f1720b..89c5cbe932 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2LoadBalancerServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2LoadBalancerServiceLiveTest.java @@ -84,10 +84,12 @@ public class EC2LoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT for (NodeMetadata node : nodes) { instanceIds.add(node.getProviderId()); } - Set elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1, tag); + Set elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1); assertNotNull(elbs); - LoadBalancer elb = elbs.iterator().next(); - assertEquals(elb.getInstanceIds(), instanceIds); + for(LoadBalancer elb:elbs) + { + if(elb.getName().equals(tag)) + assertEquals(elb.getInstanceIds(), instanceIds); + } } - } diff --git a/aws/core/src/test/java/org/jclouds/aws/elb/ELBClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/elb/ELBClientLiveTest.java index 238c10ee7a..00b2c8c734 100644 --- a/aws/core/src/test/java/org/jclouds/aws/elb/ELBClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/elb/ELBClientLiveTest.java @@ -78,10 +78,9 @@ public class ELBClientLiveTest { @Test(dependsOnMethods = "testCreateLoadBalancer") void testDescribeLoadBalancers() { - String name = "TestDescribeLoadBalancer"; for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, Region.AP_SOUTHEAST_1)) { - Set allResults = client.describeLoadBalancersInRegion(region, name); + Set allResults = client.describeLoadBalancersInRegion(region); assertNotNull(allResults); assert (allResults.size() >= 1); } diff --git a/compute/src/main/java/org/jclouds/compute/LoadBalancerService.java b/compute/src/main/java/org/jclouds/compute/LoadBalancerService.java index ea6e4560ea..d66c7b38f3 100644 --- a/compute/src/main/java/org/jclouds/compute/LoadBalancerService.java +++ b/compute/src/main/java/org/jclouds/compute/LoadBalancerService.java @@ -68,5 +68,8 @@ public interface LoadBalancerService { @Beta void destroyLoadBalancer(String handle); + + @Beta + Set listLoadBalancers(); } diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseLoadBalancerService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseLoadBalancerService.java index de6e5b0d22..e12028d669 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseLoadBalancerService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseLoadBalancerService.java @@ -35,6 +35,7 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy; +import org.jclouds.compute.strategy.ListLoadBalancersStrategy; import org.jclouds.compute.strategy.LoadBalanceNodesStrategy; import org.jclouds.domain.Location; import org.jclouds.http.handlers.BackoffLimitedRetryHandler; @@ -68,17 +69,21 @@ public class BaseLoadBalancerService implements LoadBalancerService { protected final ComputeServiceContext context; protected final LoadBalanceNodesStrategy loadBalancerStrategy; protected final DestroyLoadBalancerStrategy destroyLoadBalancerStrategy; + protected final ListLoadBalancersStrategy listLoadBalancersStrategy; protected final BackoffLimitedRetryHandler backoffLimitedRetryHandler; @Inject protected BaseLoadBalancerService(ComputeServiceContext context, LoadBalanceNodesStrategy loadBalancerStrategy, DestroyLoadBalancerStrategy destroyLoadBalancerStrategy, + ListLoadBalancersStrategy listLoadBalancersStrategy, BackoffLimitedRetryHandler backoffLimitedRetryHandler) { this.context = checkNotNull(context, "context"); this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy"); this.destroyLoadBalancerStrategy = checkNotNull(destroyLoadBalancerStrategy, "destroyLoadBalancerStrategy"); + this.listLoadBalancersStrategy = checkNotNull(listLoadBalancersStrategy, + "listLoadBalancersStrategy"); this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, "backoffLimitedRetryHandler"); } @@ -130,5 +135,11 @@ public class BaseLoadBalancerService implements LoadBalancerService { boolean successful = destroyLoadBalancerStrategy.execute(loadBalancer); logger.debug("<< destroyed load balancer(%s) success(%s)", loadBalancer, successful); } + + public Set listLoadBalancers() + { + Set loadBalancerSet = listLoadBalancersStrategy.execute(); + return loadBalancerSet; + } } \ No newline at end of file