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 + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.aws.elb.binders; + +import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithStringFormat; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +/** + * Binds the String [] to form parameters named with InstanceId.index + * + * @author Adrian Cole + */ +@Singleton +public class BindAvailabilityZonesToIndexedFormParams implements Binder { + + public void bindToRequest(HttpRequest request, Object input) { + indexStringArrayToFormValuesWithStringFormat(request, "AvailabilityZones.member.%s", input); + } + +} \ No newline at end of file