minor improvements to elastic load balancer functionality

This commit is contained in:
Lili Nader 2010-08-20 18:20:58 -07:00
parent 2db03edb18
commit 6b832c79cf
6 changed files with 28 additions and 9 deletions

View File

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

View File

@ -94,6 +94,11 @@ public interface ELBClient {
void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name,
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) {
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);
LoadBalancer elb = elbs.iterator().next();
assertEquals(elb.getInstanceIds(), instanceIds);
for(LoadBalancer elb:elbs)
{
if(elb.getName().equals(tag))
assertEquals(elb.getInstanceIds(), instanceIds);
}
}
}

View File

@ -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<LoadBalancer> allResults = client.describeLoadBalancersInRegion(region, name);
Set<LoadBalancer> allResults = client.describeLoadBalancersInRegion(region);
assertNotNull(allResults);
assert (allResults.size() >= 1);
}

View File

@ -69,4 +69,7 @@ public interface LoadBalancerService {
@Beta
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.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");
}
@ -131,4 +136,10 @@ public class BaseLoadBalancerService implements LoadBalancerService {
logger.debug("<< destroyed load balancer(%s) success(%s)", loadBalancer, successful);
}
public Set<String> listLoadBalancers()
{
Set<String> loadBalancerSet = listLoadBalancersStrategy.execute();
return loadBalancerSet;
}
}