Merge branch 'master' of git@github.com:jclouds/jclouds

* 'master' of git@github.com:jclouds/jclouds:
  minor improvements to elastic load balancer functionality
This commit is contained in:
Adrian Cole 2010-08-22 14:01:39 -07:00
commit 44c294f76a
6 changed files with 28 additions and 9 deletions

View File

@ -114,7 +114,6 @@ public interface ELBAsyncClient {
@XMLResponseParser(DescribeLoadBalancersResponseHandler.class) @XMLResponseParser(DescribeLoadBalancersResponseHandler.class)
@FormParams(keys = ACTION, values = "DescribeLoadBalancers") @FormParams(keys = ACTION, values = "DescribeLoadBalancers")
ListenableFuture<? extends Set<LoadBalancer>> describeLoadBalancersInRegion( ListenableFuture<? extends Set<LoadBalancer>> describeLoadBalancersInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
@FormParam("LoadBalancerName") @Nullable String name);
} }

View File

@ -94,6 +94,11 @@ public interface ELBClient {
void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name, void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name,
String... instanceIds); String... instanceIds);
Set<LoadBalancer> describeLoadBalancersInRegion(@Nullable String region, @Nullable String name); /**
* Returns a set of elastic load balancers
* @param region
* @return
*/
Set<LoadBalancer> describeLoadBalancersInRegion(@Nullable String region);
} }

View File

@ -84,10 +84,12 @@ public class EC2LoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
instanceIds.add(node.getProviderId()); instanceIds.add(node.getProviderId());
} }
Set<LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1, tag); Set<LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1);
assertNotNull(elbs); assertNotNull(elbs);
LoadBalancer elb = elbs.iterator().next(); for(LoadBalancer elb:elbs)
assertEquals(elb.getInstanceIds(), instanceIds); {
if(elb.getName().equals(tag))
assertEquals(elb.getInstanceIds(), instanceIds);
}
} }
} }

View File

@ -78,10 +78,9 @@ public class ELBClientLiveTest {
@Test(dependsOnMethods = "testCreateLoadBalancer") @Test(dependsOnMethods = "testCreateLoadBalancer")
void testDescribeLoadBalancers() { void testDescribeLoadBalancers() {
String name = "TestDescribeLoadBalancer";
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1,
Region.US_WEST_1, Region.AP_SOUTHEAST_1)) { Region.US_WEST_1, Region.AP_SOUTHEAST_1)) {
Set<LoadBalancer> allResults = client.describeLoadBalancersInRegion(region, name); Set<LoadBalancer> allResults = client.describeLoadBalancersInRegion(region);
assertNotNull(allResults); assertNotNull(allResults);
assert (allResults.size() >= 1); assert (allResults.size() >= 1);
} }

View File

@ -68,5 +68,8 @@ public interface LoadBalancerService {
@Beta @Beta
void destroyLoadBalancer(String handle); void destroyLoadBalancer(String handle);
@Beta
Set<String> listLoadBalancers();
} }

View File

@ -35,6 +35,7 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy; import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy;
import org.jclouds.compute.strategy.ListLoadBalancersStrategy;
import org.jclouds.compute.strategy.LoadBalanceNodesStrategy; import org.jclouds.compute.strategy.LoadBalanceNodesStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
@ -68,17 +69,21 @@ public class BaseLoadBalancerService implements LoadBalancerService {
protected final ComputeServiceContext context; protected final ComputeServiceContext context;
protected final LoadBalanceNodesStrategy loadBalancerStrategy; protected final LoadBalanceNodesStrategy loadBalancerStrategy;
protected final DestroyLoadBalancerStrategy destroyLoadBalancerStrategy; protected final DestroyLoadBalancerStrategy destroyLoadBalancerStrategy;
protected final ListLoadBalancersStrategy listLoadBalancersStrategy;
protected final BackoffLimitedRetryHandler backoffLimitedRetryHandler; protected final BackoffLimitedRetryHandler backoffLimitedRetryHandler;
@Inject @Inject
protected BaseLoadBalancerService(ComputeServiceContext context, protected BaseLoadBalancerService(ComputeServiceContext context,
LoadBalanceNodesStrategy loadBalancerStrategy, LoadBalanceNodesStrategy loadBalancerStrategy,
DestroyLoadBalancerStrategy destroyLoadBalancerStrategy, DestroyLoadBalancerStrategy destroyLoadBalancerStrategy,
ListLoadBalancersStrategy listLoadBalancersStrategy,
BackoffLimitedRetryHandler backoffLimitedRetryHandler) { BackoffLimitedRetryHandler backoffLimitedRetryHandler) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy"); this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy");
this.destroyLoadBalancerStrategy = checkNotNull(destroyLoadBalancerStrategy, this.destroyLoadBalancerStrategy = checkNotNull(destroyLoadBalancerStrategy,
"destroyLoadBalancerStrategy"); "destroyLoadBalancerStrategy");
this.listLoadBalancersStrategy = checkNotNull(listLoadBalancersStrategy,
"listLoadBalancersStrategy");
this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler,
"backoffLimitedRetryHandler"); "backoffLimitedRetryHandler");
} }
@ -130,5 +135,11 @@ public class BaseLoadBalancerService implements LoadBalancerService {
boolean successful = destroyLoadBalancerStrategy.execute(loadBalancer); boolean successful = destroyLoadBalancerStrategy.execute(loadBalancer);
logger.debug("<< destroyed load balancer(%s) success(%s)", loadBalancer, successful); logger.debug("<< destroyed load balancer(%s) success(%s)", loadBalancer, successful);
} }
public Set<String> listLoadBalancers()
{
Set<String> loadBalancerSet = listLoadBalancersStrategy.execute();
return loadBalancerSet;
}
} }