Issue 258 added missing methods and a unit test. fixed live test to test all regions

This commit is contained in:
Adrian Cole 2010-05-20 00:26:38 -07:00
parent 596ca233e3
commit 570e6366a6
13 changed files with 409 additions and 285 deletions

View File

@ -23,6 +23,7 @@ import org.jclouds.aws.ec2.services.AMIAsyncClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerAsyncClient;
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
@ -76,4 +77,9 @@ public interface EC2AsyncClient {
* Provides asynchronous access to Elastic Block Store services.
*/
ElasticBlockStoreAsyncClient getElasticBlockStoreServices();
/**
* Provides asynchronous access to Elastic Load Balancer services.
*/
ElasticLoadBalancerAsyncClient getElasticLoadBalancerServices();
}

View File

@ -23,6 +23,7 @@ import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.aws.ec2.services.KeyPairClient;
import org.jclouds.aws.ec2.services.MonitoringClient;
@ -76,4 +77,9 @@ public interface EC2Client {
* Provides synchronous access to Elastic Block Store services.
*/
ElasticBlockStoreClient getElasticBlockStoreServices();
/**
* Provides synchronous access to Elastic Load Balancer services.
*/
ElasticLoadBalancerClient getElasticLoadBalancerServices();
}

View File

@ -19,7 +19,7 @@
package org.jclouds.aws.ec2;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.aws.ec2.reference.EC2Constants.*;
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_ENDPOINT;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_EXPIREINTERVAL;
@ -40,6 +40,8 @@ public class EC2PropertiesBuilder extends PropertiesBuilder {
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_EC2_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_ELB_ENDPOINT,
"https://elasticloadbalancing.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, "60");
// alestic and canonical
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "063491364108,099720109477");

View File

@ -27,7 +27,9 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.ELB;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.predicates.InstanceStateRunning;
@ -41,6 +43,8 @@ import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerAsyncClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
@ -70,6 +74,7 @@ import org.jclouds.rest.RestClientFactory;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
@ -110,6 +115,26 @@ public class EC2RestClientModule extends AbstractModule {
bindRetryHandlers();
}
@Provides
@Singleton
@ELB
protected URI provideELBURI(@Named(EC2Constants.PROPERTY_ELB_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Provides
@Singleton
@ELB
Map<String, URI> provideELBRegions() {
return ImmutableMap.<String, URI> of(Region.US_EAST_1, URI
.create("https://elasticloadbalancing.us-east-1.amazonaws.com"), Region.US_WEST_1,
URI.create("https://elasticloadbalancing.us-west-1.amazonaws.com"),
Region.EU_WEST_1,
URI.create("https://elasticloadbalancing.eu-west-1.amazonaws.com"),
Region.AP_SOUTHEAST_1, URI
.create("https://elasticloadbalancing.ap-southeast-1.amazonaws.com"));
}
@Provides
@Singleton
@EC2
@ -130,8 +155,8 @@ public class EC2RestClientModule extends AbstractModule {
@Provides
@Singleton
Map<String, String> provideAvailabilityZoneToRegions(
AvailabilityZoneAndRegionClient client, @EC2 Map<String, URI> regions) {
Map<String, String> provideAvailabilityZoneToRegions(AvailabilityZoneAndRegionClient client,
@EC2 Map<String, URI> regions) {
Map<String, String> map = Maps.newHashMap();
for (String region : regions.keySet()) {
for (AvailabilityZoneInfo zoneInfo : client.describeAvailabilityZonesInRegion(region)) {
@ -175,6 +200,13 @@ public class EC2RestClientModule extends AbstractModule {
return factory.create(ElasticIPAddressAsyncClient.class);
}
@Provides
@Singleton
protected ElasticLoadBalancerAsyncClient provideElasticLoadBalancerAsyncClient(
RestClientFactory factory) {
return factory.create(ElasticLoadBalancerAsyncClient.class);
}
@Provides
@Singleton
public ElasticIPAddressClient provideElasticIPAddressClient(ElasticIPAddressAsyncClient client)
@ -263,6 +295,14 @@ public class EC2RestClientModule extends AbstractModule {
return SyncProxy.create(ElasticBlockStoreClient.class, client);
}
@Provides
@Singleton
public ElasticLoadBalancerClient provideElasticLoadBalancerClient(
ElasticLoadBalancerAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(ElasticLoadBalancerClient.class, client);
}
@Provides
@Singleton
@EC2

View File

@ -28,6 +28,7 @@ import org.jclouds.aws.ec2.services.AMIAsyncClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerAsyncClient;
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
@ -48,6 +49,7 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
private final MonitoringAsyncClient monitoringServices;
private final AvailabilityZoneAndRegionAsyncClient availabilityZoneAndRegionServices;
private final ElasticBlockStoreAsyncClient elasticBlockStoreServices;
private final ElasticLoadBalancerAsyncClient elasticLoadBalancerAsyncClient;
@Inject
public EC2AsyncClientImpl(AMIAsyncClient AMIServices,
@ -56,7 +58,8 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
SecurityGroupAsyncClient securityGroupServices,
MonitoringAsyncClient monitoringServices,
AvailabilityZoneAndRegionAsyncClient availabilityZoneAndRegionServices,
ElasticBlockStoreAsyncClient elasticBlockStoreServices) {
ElasticBlockStoreAsyncClient elasticBlockStoreServices,
ElasticLoadBalancerAsyncClient elasticLoadBalancerAsyncClient) {
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
"elasticIPAddressServices");
@ -68,11 +71,14 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
"availabilityZoneAndRegionServices");
this.elasticBlockStoreServices = checkNotNull(elasticBlockStoreServices,
"elasticBlockStoreServices");
this.elasticLoadBalancerAsyncClient = checkNotNull(elasticLoadBalancerAsyncClient,
"elasticLoadBalancerAsyncClient");
}
/**
* {@inheritDoc}
*/
@Override
public AMIAsyncClient getAMIServices() {
return AMIServices;
}
@ -80,6 +86,7 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
/**
* {@inheritDoc}
*/
@Override
public ElasticIPAddressAsyncClient getElasticIPAddressServices() {
return elasticIPAddressServices;
}
@ -87,6 +94,7 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
/**
* {@inheritDoc}
*/
@Override
public InstanceAsyncClient getInstanceServices() {
return instanceServices;
}
@ -94,6 +102,7 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
/**
* {@inheritDoc}
*/
@Override
public KeyPairAsyncClient getKeyPairServices() {
return keyPairServices;
}
@ -101,6 +110,7 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
/**
* {@inheritDoc}
*/
@Override
public SecurityGroupAsyncClient getSecurityGroupServices() {
return securityGroupServices;
}
@ -108,6 +118,7 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
/**
* {@inheritDoc}
*/
@Override
public MonitoringAsyncClient getMonitoringServices() {
return monitoringServices;
}
@ -115,6 +126,7 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
/**
* {@inheritDoc}
*/
@Override
public AvailabilityZoneAndRegionAsyncClient getAvailabilityZoneAndRegionServices() {
return availabilityZoneAndRegionServices;
}
@ -122,8 +134,17 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
/**
* {@inheritDoc}
*/
@Override
public ElasticBlockStoreAsyncClient getElasticBlockStoreServices() {
return elasticBlockStoreServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticLoadBalancerAsyncClient getElasticLoadBalancerServices() {
return elasticLoadBalancerAsyncClient;
}
}

View File

@ -28,6 +28,7 @@ import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.aws.ec2.services.KeyPairClient;
import org.jclouds.aws.ec2.services.MonitoringClient;
@ -48,13 +49,15 @@ public class EC2ClientImpl implements EC2Client {
private final MonitoringClient monitoringServices;
private final AvailabilityZoneAndRegionClient availabilityZoneAndRegionServices;
private final ElasticBlockStoreClient elasticBlockStoreServices;
private final ElasticLoadBalancerClient elasticLoadBalancerClient;
@Inject
public EC2ClientImpl(AMIClient AMIServices, ElasticIPAddressClient elasticIPAddressServices,
InstanceClient instanceServices, KeyPairClient keyPairServices,
SecurityGroupClient securityGroupServices, MonitoringClient monitoringServices,
AvailabilityZoneAndRegionClient availabilityZoneAndRegionServices,
ElasticBlockStoreClient elasticBlockStoreServices) {
ElasticBlockStoreClient elasticBlockStoreServices,
ElasticLoadBalancerClient elasticLoadBalancerClient) {
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
"elasticIPAddressServices");
@ -66,11 +69,14 @@ public class EC2ClientImpl implements EC2Client {
"availabilityZoneAndRegionServices");
this.elasticBlockStoreServices = checkNotNull(elasticBlockStoreServices,
"elasticBlockStoreServices");
this.elasticLoadBalancerClient = checkNotNull(elasticLoadBalancerClient,
"elasticLoadBalancerClient");
}
/**
* {@inheritDoc}
*/
@Override
public AMIClient getAMIServices() {
return AMIServices;
}
@ -78,6 +84,7 @@ public class EC2ClientImpl implements EC2Client {
/**
* {@inheritDoc}
*/
@Override
public ElasticIPAddressClient getElasticIPAddressServices() {
return elasticIPAddressServices;
}
@ -85,6 +92,7 @@ public class EC2ClientImpl implements EC2Client {
/**
* {@inheritDoc}
*/
@Override
public InstanceClient getInstanceServices() {
return instanceServices;
}
@ -92,6 +100,7 @@ public class EC2ClientImpl implements EC2Client {
/**
* {@inheritDoc}
*/
@Override
public KeyPairClient getKeyPairServices() {
return keyPairServices;
}
@ -99,6 +108,7 @@ public class EC2ClientImpl implements EC2Client {
/**
* {@inheritDoc}
*/
@Override
public SecurityGroupClient getSecurityGroupServices() {
return securityGroupServices;
}
@ -106,6 +116,7 @@ public class EC2ClientImpl implements EC2Client {
/**
* {@inheritDoc}
*/
@Override
public MonitoringClient getMonitoringServices() {
return monitoringServices;
}
@ -113,6 +124,7 @@ public class EC2ClientImpl implements EC2Client {
/**
* {@inheritDoc}
*/
@Override
public AvailabilityZoneAndRegionClient getAvailabilityZoneAndRegionServices() {
return availabilityZoneAndRegionServices;
}
@ -120,8 +132,17 @@ public class EC2ClientImpl implements EC2Client {
/**
* {@inheritDoc}
*/
@Override
public ElasticBlockStoreClient getElasticBlockStoreServices() {
return elasticBlockStoreServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticLoadBalancerClient getElasticLoadBalancerServices() {
return elasticLoadBalancerClient;
}
}

View File

@ -33,5 +33,6 @@ public interface EC2Constants extends AWSConstants {
* the ami owners you wish to use in {@link ComputeService}
*/
public static final String PROPERTY_EC2_AMI_OWNERS = "jclouds.ec2.ami-owners";
public static final String PROPERTY_ELB_ENDPOINT = "jclouds.elb.endpoint";
}

View File

@ -59,12 +59,11 @@ public class EC2Utils {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof String) {
String regionName = (String) arg;
if(Region.EU_WEST_1.equals(regionName) ||
Region.US_WEST_1.equals(regionName) ||
Region.US_EAST_1.equals(regionName) ||
Region.US_STANDARD.equals(regionName) ||
Region.AP_SOUTHEAST_1.equals(regionName)
) return regionName;
if (Region.EU_WEST_1.equals(regionName) || Region.US_WEST_1.equals(regionName)
|| Region.US_EAST_1.equals(regionName)
|| Region.US_STANDARD.equals(regionName)
|| Region.AP_SOUTHEAST_1.equals(regionName))
return regionName;
}
}
return null;
@ -74,9 +73,22 @@ public class EC2Utils {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof String) {
String zone = (String) arg;
if(AvailabilityZone.zones.contains(zone)) return zone;
if (AvailabilityZone.zones.contains(zone))
return zone;
}
}
return null;
}
public static void indexStringArrayToFormValuesWithStringFormat(GeneratedHttpRequest<?> request,
String format, Object input) {
checkArgument(checkNotNull(input, "input") instanceof String[],
"this binder is only valid for String[] : " + input.getClass());
String[] values = (String[]) input;
for (int i = 0; i < values.length; i++) {
request.addFormParam(String.format(format, (i + 1)), checkNotNull(values[i], format
.toLowerCase()
+ "s[" + i + "]"));
}
}
}

View File

@ -20,222 +20,164 @@ import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
public class DescribeLoadBalancersResponseHandler extends
ParseSax.HandlerWithResult<Set<ElasticLoadBalancer>>
{
@Inject
public DescribeLoadBalancersResponseHandler(@EC2 String defaultRegion)
{
this.defaultRegion = defaultRegion;
this.listenerHandler = new LoadBalancerListenerHandler();
}
ParseSax.HandlerWithResult<Set<ElasticLoadBalancer>> {
@Inject
public DescribeLoadBalancersResponseHandler(@EC2 String defaultRegion) {
this.defaultRegion = defaultRegion;
this.listenerHandler = new LoadBalancerListenerHandler();
}
@Inject
protected DateService dateService;
@Inject
protected DateService dateService;
@Resource
protected Logger logger = Logger.NULL;
@Resource
protected Logger logger = Logger.NULL;
private Set<ElasticLoadBalancer> contents = Sets
.newLinkedHashSet();
private StringBuilder currentText = new StringBuilder();
private final String defaultRegion;
private final LoadBalancerListenerHandler listenerHandler;
private Set<ElasticLoadBalancer> contents = Sets.newLinkedHashSet();
private StringBuilder currentText = new StringBuilder();
private final String defaultRegion;
private final LoadBalancerListenerHandler listenerHandler;
private boolean inListenerDescriptions = false;
private boolean inInstances = false;
private boolean inAppCookieStickinessPolicies = false;
private boolean inLBCookieStickinessPolicies = false;
private boolean inAvailabilityZones = false;
private boolean inLoadBalancerDescriptions = false;
private boolean inListenerDescriptions = false;
private boolean inInstances = false;
private boolean inAppCookieStickinessPolicies = false;
private boolean inLBCookieStickinessPolicies = false;
private boolean inAvailabilityZones = false;
//TODO unused?
private boolean inLoadBalancerDescriptions = false;
private ElasticLoadBalancer elb;
private AppCookieStickinessPolicy appCookieStickinessPolicy;
private LBCookieStickinessPolicy lBCookieStickinessPolicy;
private ElasticLoadBalancer elb;
//TODO unused?
private AppCookieStickinessPolicy appCookieStickinessPolicy;
//TODO unused?
private LBCookieStickinessPolicy lBCookieStickinessPolicy;
public void startElement(String uri, String localName, String qName,
Attributes attributes)
{
if (qName.equals("ListenerDescriptions") || inListenerDescriptions)
{
inListenerDescriptions = true;
}
else if (qName.equals("AppCookieStickinessPolicies"))
{
inAppCookieStickinessPolicies = true;
}
else if (qName.equals("LBCookieStickinessPolicies"))
{
inLBCookieStickinessPolicies = true;
}
else if (qName.equals("LoadBalancerDescriptions"))
{
inLoadBalancerDescriptions = true;
}
else if (qName.equals("Instances"))
{
inInstances = true;
}
else if (qName.equals("AvailabilityZones"))
{
inAvailabilityZones = true;
}
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if (qName.equals("member"))
{
if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones))
{
elb = new ElasticLoadBalancer();
}
}
}
if (qName.equals("ListenerDescriptions") || inListenerDescriptions) {
inListenerDescriptions = true;
} else if (qName.equals("AppCookieStickinessPolicies")) {
inAppCookieStickinessPolicies = true;
} else if (qName.equals("LBCookieStickinessPolicies")) {
inLBCookieStickinessPolicies = true;
} else if (qName.equals("LoadBalancerDescriptions")) {
inLoadBalancerDescriptions = true;
} else if (qName.equals("Instances")) {
inInstances = true;
} else if (qName.equals("AvailabilityZones")) {
inAvailabilityZones = true;
}
public void endElement(String uri, String localName, String qName)
{
logger.info(qName);
//if end tag is one of below then set inXYZ to false
if (qName.equals("ListenerDescriptions"))
{
inListenerDescriptions = false;
}
else if (qName.equals("AppCookieStickinessPolicies"))
{
inAppCookieStickinessPolicies = false;
}
else if (qName.equals("LBCookieStickinessPolicies"))
{
inLBCookieStickinessPolicies = false;
}
else if (qName.equals("LoadBalancerDescriptions"))
{
inLoadBalancerDescriptions = false;
}
else if (qName.equals("Instances"))
{
inInstances = false;
}
else if (qName.equals("AvailabilityZones"))
{
inAvailabilityZones = false;
}
if (qName.equals("member")) {
if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones)) {
elb = new ElasticLoadBalancer();
}
}
}
if (qName.equals("DNSName"))
{
elb.setDnsName(currentText.toString().trim());
}
else if (qName.equals("LoadBalancerName"))
{
elb.setName(currentText.toString().trim());
}
else if (qName.equals("InstanceId"))
{
elb.getInstanceIds().add(currentText.toString().trim());
}
public void endElement(String uri, String localName, String qName) {
logger.info(qName);
else if (qName.equals("member"))
{
// if end tag is one of below then set inXYZ to false
if (qName.equals("ListenerDescriptions")) {
inListenerDescriptions = false;
} else if (qName.equals("AppCookieStickinessPolicies")) {
inAppCookieStickinessPolicies = false;
} else if (qName.equals("LBCookieStickinessPolicies")) {
inLBCookieStickinessPolicies = false;
} else if (qName.equals("LoadBalancerDescriptions")) {
inLoadBalancerDescriptions = false;
} else if (qName.equals("Instances")) {
inInstances = false;
} else if (qName.equals("AvailabilityZones")) {
inAvailabilityZones = false;
}
if (inAvailabilityZones)
{
elb.getAvailabilityZones().add(currentText.toString().trim());
}
else if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones))
{
try
{
String region = EC2Utils.findRegionInArgsOrNull(request);
if (region == null)
region = defaultRegion;
if (qName.equals("DNSName")) {
elb.setDnsName(currentText.toString().trim());
} else if (qName.equals("LoadBalancerName")) {
elb.setName(currentText.toString().trim());
} else if (qName.equals("InstanceId")) {
elb.getInstanceIds().add(currentText.toString().trim());
}
elb.setRegion(region);
contents.add(elb);
}
catch (NullPointerException e)
{
logger.warn(e, "malformed load balancer: %s", localName);
}
else if (qName.equals("member")) {
this.elb = null;
if (inAvailabilityZones) {
elb.getAvailabilityZones().add(currentText.toString().trim());
} else if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones)) {
try {
String region = EC2Utils.findRegionInArgsOrNull(request);
if (region == null)
region = defaultRegion;
elb.setRegion(region);
contents.add(elb);
} catch (NullPointerException e) {
logger.warn(e, "malformed load balancer: %s", localName);
}
}
this.elb = null;
currentText = new StringBuilder();
}
}
@Override
public Set<ElasticLoadBalancer> getResult()
{
return contents;
}
}
public void characters(char ch[], int start, int length)
{
currentText.append(ch, start, length);
}
@Override
public void setContext(GeneratedHttpRequest<?> request) {
listenerHandler.setContext(request);
super.setContext(request);
}
currentText = new StringBuilder();
}
public class LoadBalancerListenerHandler extends
ParseSax.HandlerWithResult<Set<LoadBalancerListener>>
{
private Set<LoadBalancerListener> listeners = Sets.newHashSet();
private StringBuilder currentText = new StringBuilder();
private LoadBalancerListener listener;
@Override
public Set<ElasticLoadBalancer> getResult() {
return contents;
}
public void startElement(String uri, String name, String qName,
Attributes attrs)
{
if (qName.equals("member"))
{
listener = new LoadBalancerListener();
}
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
public void endElement(String uri, String name, String qName)
{
if (qName.equals("Protocol"))
{
listener.setProtocol(currentText.toString().trim());
}
else if (qName.equals("LoadBalancerPort"))
{
listener.setLoadBalancerPort(Integer.parseInt(currentText
.toString().trim()));
}
else if (qName.equals("InstancePort"))
{
listener.setInstancePort(Integer.parseInt(currentText
.toString().trim()));
}
else if (qName.equals("member"))
{
listeners.add(listener);
}
currentText = new StringBuilder();
@Override
public void setContext(GeneratedHttpRequest<?> request) {
listenerHandler.setContext(request);
super.setContext(request);
}
}
public class LoadBalancerListenerHandler extends
ParseSax.HandlerWithResult<Set<LoadBalancerListener>> {
private Set<LoadBalancerListener> listeners = Sets.newHashSet();
private StringBuilder currentText = new StringBuilder();
private LoadBalancerListener listener;
@Override
public Set<LoadBalancerListener> getResult()
{
return listeners;
}
public void startElement(String uri, String name, String qName, Attributes attrs) {
if (qName.equals("member")) {
listener = new LoadBalancerListener();
}
}
public void characters(char ch[], int start, int length)
{
currentText.append(ch, start, length);
}
public void endElement(String uri, String name, String qName) {
if (qName.equals("Protocol")) {
listener.setProtocol(currentText.toString().trim());
} else if (qName.equals("LoadBalancerPort")) {
listener.setLoadBalancerPort(Integer.parseInt(currentText.toString().trim()));
} else if (qName.equals("InstancePort")) {
listener.setInstancePort(Integer.parseInt(currentText.toString().trim()));
} else if (qName.equals("member")) {
listeners.add(listener);
}
}
currentText = new StringBuilder();
}
@Override
public Set<LoadBalancerListener> getResult() {
return listeners;
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}
}

View File

@ -29,6 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.EC2PropertiesBuilder;
import org.jclouds.aws.ec2.ELB;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.TimeStamp;
@ -79,6 +80,8 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
.build(), "properties"));
bind(URI.class).annotatedWith(EC2.class).toInstance(
URI.create("https://ec2.amazonaws.com"));
bind(URI.class).annotatedWith(ELB.class).toInstance(
URI.create("https://elasticloadbalancing.us-east-1.amazonaws.com"));
bind(String.class).annotatedWith(EC2.class).toInstance(Region.US_EAST_1);
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
@ -105,12 +108,26 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
.create("https://ec2.us-west-1.amazonaws.com"));
}
@SuppressWarnings("unused")
@Provides
@Singleton
@ELB
Map<String, URI> provideELBRegions() {
return ImmutableMap.<String, URI> of(Region.US_EAST_1, URI
.create("https://elasticloadbalancing.us-east-1.amazonaws.com"),
Region.US_WEST_1, URI
.create("https://elasticloadbalancing.us-west-1.amazonaws.com"),
Region.EU_WEST_1, URI
.create("https://elasticloadbalancing.eu-west-1.amazonaws.com"),
Region.AP_SOUTHEAST_1, URI
.create("https://elasticloadbalancing.ap-southeast-1.amazonaws.com"));
}
@SuppressWarnings("unused")
@Singleton
@Provides
Map<String, String> provideAvailabilityZoneRegionMap() {
return ImmutableMap.<String, String> of(AvailabilityZone.US_EAST_1A,
Region.US_EAST_1);
return ImmutableMap.<String, String> of(AvailabilityZone.US_EAST_1A, Region.US_EAST_1);
}
};
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.ec2.services;
import java.io.IOException;
import java.lang.reflect.Method;
import org.jclouds.aws.ec2.xml.RegisterInstancesWithLoadBalancerResponseHandler;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ElasticLoadBalancerAsyncClient}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.ElasticLoadBalancerAsyncClientTest")
public class ElasticLoadBalancerAsyncClientTest extends
BaseEC2AsyncClientTest<ElasticLoadBalancerAsyncClient> {
public void testRegisterInstancesWithLoadBalancer() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ElasticLoadBalancerAsyncClient.class.getMethod(
"registerInstancesWithLoadBalancer", String.class, String.class, String[].class);
GeneratedHttpRequest<ElasticLoadBalancerAsyncClient> httpMethod = processor.createRequest(
method, null, "ReferenceAP1", "i-6055fa09");
assertRequestLineEquals(httpMethod,
"POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: elasticloadbalancing.us-east-1.amazonaws.com\n");
assertPayloadEquals(
httpMethod,
"Version=2009-11-25&Action=RegisterInstancesWithLoadBalancer&LoadBalancerName=ReferenceAP1&Instances.member.1.InstanceId=i-6055fa09");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method,
RegisterInstancesWithLoadBalancerResponseHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<ElasticLoadBalancerAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ElasticLoadBalancerAsyncClient>>() {
};
}
}

View File

@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertNotNull;
import java.util.Set;
import java.util.Map.Entry;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2AsyncClient;
@ -35,6 +36,7 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
@ -43,67 +45,56 @@ import com.google.common.collect.ImmutableSet;
* @author Lili Nader
*/
@Test(groups = "live", sequential = true, testName = "ec2.ElasticLoadBalancerClientLiveTest")
public class ElasticLoadBalancerClientLiveTest
{
public class ElasticLoadBalancerClientLiveTest {
private ElasticLoadBalancerClient client;
private RestContext<EC2AsyncClient, EC2Client> context;
private ElasticLoadBalancerClient client;
private RestContext<EC2AsyncClient, EC2Client> context;
@BeforeGroups(groups = { "live" })
public void setupClient()
{
String user = checkNotNull(System.getProperty("jclouds.test.user"),
"jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"),
"jclouds.test.key");
@BeforeGroups(groups = { "live" })
public void setupClient() {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
context = EC2ContextFactory.createContext(user, password,
new Log4JLoggingModule()).getProviderSpecificContext();
client = context.getApi().getElasticLoadBalancerServices();
}
context = EC2ContextFactory.createContext(user, password, new Log4JLoggingModule())
.getProviderSpecificContext();
client = context.getApi().getElasticLoadBalancerServices();
}
@Test
void testCreateLoadBalancer()
{
String name = "TestLoadBalancer";
for (String region : ImmutableSet.of(Region.US_EAST_1))
{
String dnsName = client.createLoadBalancer(region, name, "http",
80, 80, AvailabilityZone.US_EAST_1A);
assertNotNull(dnsName);
assert (dnsName.startsWith(name));
}
}
@Test
void testCreateLoadBalancer() {
String name = "TestLoadBalancer";
for (Entry<String, String> regionZone : ImmutableMap.<String, String> of(Region.US_EAST_1,
AvailabilityZone.US_EAST_1A, Region.US_WEST_1, AvailabilityZone.US_WEST_1A,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, Region.AP_SOUTHEAST_1,
AvailabilityZone.AP_SOUTHEAST_1A).entrySet()) {
String dnsName = client.createLoadBalancer(regionZone.getKey(), name, "http", 80, 80,
regionZone.getValue());
assertNotNull(dnsName);
assert (dnsName.startsWith(name));
}
}
@Test
void testDescribeLoadBalancers()
{
String name = "TestDescribeLoadBalancer";
for (String region : ImmutableSet.of(Region.US_EAST_1))
{
client.createLoadBalancer(region, name, "http",
80, 80, AvailabilityZone.US_EAST_1A);
Set<ElasticLoadBalancer> allResults = client.describeLoadBalancers(
region, name);
assertNotNull(allResults);
assert (allResults.size() >= 1);
client.deleteLoadBalancer(region, name);
}
}
@Test(dependsOnMethods = "testCreateLoadBalancer")
void testDescribeLoadBalancers() {
String name = "TestDescribeLoadBalancer";
for (String region : ImmutableSet.of(Region.US_EAST_1, Region.US_WEST_1, Region.EU_WEST_1,
Region.AP_SOUTHEAST_1)) {
Set<ElasticLoadBalancer> allResults = client.describeLoadBalancers(region, name);
assertNotNull(allResults);
assert (allResults.size() >= 1);
}
}
@Test
void testDeleteLoadBalancer()
{
for (String region : ImmutableSet.of(Region.US_EAST_1))
{
client.deleteLoadBalancer(region, "TestLoadBalancer");
}
}
@Test
void testDeleteLoadBalancer() {
for (String region : ImmutableSet.of(Region.US_EAST_1, Region.US_WEST_1, Region.EU_WEST_1,
Region.AP_SOUTHEAST_1)) {
client.deleteLoadBalancer(region, "TestLoadBalancer");
}
}
@AfterTest
public void shutdown()
{
context.close();
}
@AfterTest
public void shutdown() {
context.close();
}
}

View File

@ -24,16 +24,9 @@ import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Date;
import java.util.Set;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer;
import org.jclouds.aws.ec2.domain.Image;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer.AppCookieStickinessPolicy;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer.LBCookieStickinessPolicy;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer.LoadBalancerListener;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test;
@ -51,11 +44,12 @@ public class DescribeLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest
public void testParse() {
InputStream is = getClass().getResourceAsStream("/ec2/describe_loadbalancers.xml");
Set<ElasticLoadBalancer> contents = Sets.newHashSet();
ElasticLoadBalancer dummy = new ElasticLoadBalancer(defaultRegion, "my-load-balancer",
ImmutableSet.of("i-5b33e630", "i-8f26d7e4", "i-5933e632"), ImmutableSet.of("us-east-1a"),
"my-load-balancer-1400212309.us-east-1.elb.amazonaws.com");
ImmutableSet.of("i-5b33e630", "i-8f26d7e4", "i-5933e632"), ImmutableSet
.of("us-east-1a"),
"my-load-balancer-1400212309.us-east-1.elb.amazonaws.com");
contents.add(dummy);
Set<ElasticLoadBalancer> result = parseLoadBalancers(is);
@ -63,19 +57,18 @@ public class DescribeLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest
assertEquals(result, contents);
}
private Set<ElasticLoadBalancer> parseLoadBalancers(InputStream is) {
DescribeLoadBalancersResponseHandler handler = injector
.getInstance(DescribeLoadBalancersResponseHandler.class);
addDefaultRegionToHandler(handler);
Set<ElasticLoadBalancer> result = factory.create(handler).parse(is);
return result;
}
DescribeLoadBalancersResponseHandler handler = injector
.getInstance(DescribeLoadBalancersResponseHandler.class);
addDefaultRegionToHandler(handler);
Set<ElasticLoadBalancer> result = factory.create(handler).parse(is);
return result;
}
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getArgs()).andReturn(new Object[] { null });
replay(request);
handler.setContext(request);
}
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getArgs()).andReturn(new Object[] { null });
replay(request);
handler.setContext(request);
}
}