minor improvements to elastic load balancer functionality

This commit is contained in:
Lili Nader 2010-08-01 16:14:43 -07:00
parent 9751d6a539
commit 43a0fa4879
4 changed files with 21 additions and 12 deletions

View File

@ -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;
@ -61,15 +61,8 @@ public class EC2LoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {
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<String> instanceIdlist = new ArrayList<String>(instanceIds);
String[] instanceIdArray = new String[instanceIdlist.size()];

View File

@ -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;
@ -55,6 +57,17 @@ public class EC2Utils {
}
}
public static String[] getAvailabilityZonesForRegion(String region)
{
Set<String> availabilityZones = new HashSet<String>();
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) {
checkArgument(checkNotNull(input, "input") instanceof String[],

View File

@ -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

View File

@ -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 <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/"
*/
String createLoadBalancerInRegion(@Nullable String region, String name, String protocol,
int loadBalancerPort, int instancePort, String availabilityZone);
int loadBalancerPort, int instancePort, String... availabilityZones);
/**
* Delete load balancer