From 43a0fa487906b6d7ad0d1909d4aa40bf1cb3f526 Mon Sep 17 00:00:00 2001 From: Lili Nader Date: Sun, 1 Aug 2010 16:14:43 -0700 Subject: [PATCH] minor improvements to elastic load balancer functionality --- .../strategy/EC2LoadBalanceNodesStrategy.java | 13 +++---------- .../java/org/jclouds/aws/ec2/util/EC2Utils.java | 13 +++++++++++++ .../java/org/jclouds/aws/elb/ELBAsyncClient.java | 3 ++- .../main/java/org/jclouds/aws/elb/ELBClient.java | 4 +++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalanceNodesStrategy.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalanceNodesStrategy.java index c990ea9c4a..40d07f7499 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalanceNodesStrategy.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalanceNodesStrategy.java @@ -28,7 +28,7 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.aws.ec2.domain.AvailabilityZone; +import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils.GetRegionFromLocation; import org.jclouds.aws.elb.ELBClient; import org.jclouds.compute.reference.ComputeServiceConstants; @@ -60,16 +60,9 @@ public class EC2LoadBalanceNodesStrategy implements LoadBalanceNodesStrategy { int instancePort, Set instanceIds) { String region = getRegionFromLocation.apply(location); String dnsName = new String(); - - // TODO: Fix temp hack - String availabilityZone = new String(); - for (String az : AvailabilityZone.zones) { - if (az.startsWith(region)) - availabilityZone = az; - } - + dnsName = elbClient.createLoadBalancerInRegion(region, name, protocol, loadBalancerPort, - instancePort, availabilityZone); + instancePort, EC2Utils.getAvailabilityZonesForRegion(region)); List instanceIdlist = new ArrayList(instanceIds); String[] instanceIdArray = new String[instanceIdlist.size()]; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java b/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java index b2811eb9f0..7340aa4cea 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java @@ -22,7 +22,9 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.http.HttpUtils.addFormParamTo; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -54,6 +56,17 @@ public class EC2Utils { return region; } } + + public static String[] getAvailabilityZonesForRegion(String region) + { + Set availabilityZones = new HashSet(); + for (String az : AvailabilityZone.zones) { + if (az.startsWith(region)) + availabilityZones.add(az); + } + + return (String[])availabilityZones.toArray(new String[availabilityZones.size()]); + } public static void indexStringArrayToFormValuesWithPrefix(HttpRequest request, String prefix, Object input) { 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 76f8a67d2c..d20251727d 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 @@ -30,6 +30,7 @@ import javax.ws.rs.Path; import org.jclouds.aws.ec2.xml.CreateLoadBalancerResponseHandler; import org.jclouds.aws.ec2.xml.RegisterInstancesWithLoadBalancerResponseHandler; +import org.jclouds.aws.elb.binders.BindAvailabilityZonesToIndexedFormParams; import org.jclouds.aws.elb.binders.BindELBInstanceIdsToIndexedFormParams; import org.jclouds.aws.elb.domain.LoadBalancer; import org.jclouds.aws.elb.xml.DescribeLoadBalancersResponseHandler; @@ -69,7 +70,7 @@ public interface ELBAsyncClient { @FormParam("Listeners.member.1.Protocol") String protocol, @FormParam("Listeners.member.1.LoadBalancerPort") int loadBalancerPort, @FormParam("Listeners.member.1.InstancePort") int instancePort, - @FormParam("AvailabilityZones.member.1") String availabilityZone); + @BinderParam(BindAvailabilityZonesToIndexedFormParams.class) String... availabilityZones); /** * @see ELBClient#deleteLoadBalancerInRegion 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 804c471de8..cf78a3f931 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 @@ -44,11 +44,13 @@ public interface ELBClient { * Port for the load balancer to listen on * @param instancePort * Port to forward the request to + * @param availabilityZones + * load balancer availability zones * @return dns the DNS name for the load balancer * @see