Git merge upstream/master

This commit is contained in:
Carlos 2011-01-03 21:14:27 +01:00
commit cc881ae1b8
1400 changed files with 18034 additions and 7743 deletions

View File

@ -29,7 +29,7 @@ data.
our current version is 1.0-beta-8
our dev version is 1.0-SNAPSHOT
our compute api supports: ec2, gogrid, cloudservers (rackspace), rimuhosting, vcloud,
our compute api supports: ec2, gogrid, cloudservers (rackspace), vcloud,
trmk-ecloud, trmk-vcloudexpress, eucalyptus, cloudsigma,
elasticstack, bluelock-vclouddirector, slicehost,
elastichosts-lon-p (Peer 1), elastichosts-sat-p (Peer 1),
@ -45,8 +45,8 @@ our blobstore api supports: s3, cloudfiles (rackspace), azurestorage, atmosonlin
* note * the pom dependency org.jclouds/jclouds-allblobstore gives you access to
to all of these providers
we also have support for: ibmdev, mezeo, nirvanix, boxdotnet, as well a number of features
the sandbox
we also have support for: ibmdev, mezeo, nirvanix, boxdotnet, rimuhosting, as well
a number of features the sandbox
If you want access to all jclouds components, include the maven dependency org.jclouds/jclouds-all
@ -105,7 +105,7 @@ Compute Example (Clojure):
Downloads:
* distribution zip: http://jclouds.googlecode.com/files/jclouds-1.0-beta-8.zip
* maven repo: https://oss.sonatype.org/content/repositories/releases
* maven repo: http://repo2.maven.org/maven2 (maven central - the default repository)
* snapshot repo: https://oss.sonatype.org/content/repositories/snapshots
Links:

View File

@ -39,5 +39,10 @@
<artifactId>jclouds-allblobstore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>aws-simpledb</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -50,8 +50,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-filesystem</artifactId>
<groupId>org.jclouds.api</groupId>
<artifactId>filesystem</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

View File

@ -39,11 +39,6 @@
<artifactId>jclouds-rackspace</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-rimuhosting</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-vcloud</artifactId>
@ -60,13 +55,13 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-gogrid</artifactId>
<groupId>org.jclouds.provider</groupId>
<artifactId>gogrid</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-slicehost</artifactId>
<groupId>org.jclouds.provider</groupId>
<artifactId>slicehost</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -75,8 +70,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-cloudsigma</artifactId>
<groupId>org.jclouds.provider</groupId>
<artifactId>cloudsigma</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

110
apis/cloudwatch/pom.xml Normal file
View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>cloudwatch</artifactId>
<name>jcloud cloudwatch api</name>
<description>jclouds components to access an implementation of CloudWatch</description>
<properties>
<test.cloudwatch.endpoint>https://monitoring.us-east-1.amazonaws.com</test.cloudwatch.endpoint>
<test.cloudwatch.apiversion>2009-05-15</test.cloudwatch.apiversion>
<test.cloudwatch.identity>${test.aws.identity}</test.cloudwatch.identity>
<test.cloudwatch.credential>${test.aws.credential}</test.cloudwatch.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.cloudwatch.endpoint</name>
<value>${test.cloudwatch.endpoint}</value>
</property>
<property>
<name>test.cloudwatch.apiversion</name>
<value>${test.cloudwatch.apiversion}</value>
</property>
<property>
<name>test.cloudwatch.identity</name>
<value>${test.cloudwatch.identity}</value>
</property>
<property>
<name>test.cloudwatch.credential</name>
<value>${test.cloudwatch.credential}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

129
apis/ec2/pom.xml Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>ec2</artifactId>
<name>jcloud ec2 api</name>
<description>jclouds components to access an implementation of EC2</description>
<properties>
<!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.ec2.endpoint>https://ec2.us-east-1.amazonaws.com</test.ec2.endpoint>
<test.ec2.apiversion>2010-06-15</test.ec2.apiversion>
<test.ec2.identity>${test.aws.identity}</test.ec2.identity>
<test.ec2.credential>${test.aws.credential}</test.ec2.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.ec2.endpoint</name>
<value>${test.ec2.endpoint}</value>
</property>
<property>
<name>test.ec2.apiversion</name>
<value>${test.ec2.apiversion}</value>
</property>
<property>
<name>test.ec2.identity</name>
<value>${test.ec2.identity}</value>
</property>
<property>
<name>test.ec2.credential</name>
<value>${test.ec2.credential}</value>
</property>
<property>
<name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist-nodes}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

129
apis/elb/pom.xml Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>elb</artifactId>
<name>jcloud elb api</name>
<description>jclouds components to access an implementation of Elastic Load Balancer</description>
<properties>
<test.elb.endpoint>https://elasticloadbalancing.us-east-1.amazonaws.com</test.elb.endpoint>
<test.elb.apiversion>2010-07-01</test.elb.apiversion>
<test.elb.identity>${test.aws.identity}</test.elb.identity>
<test.elb.credential>${test.aws.credential}</test.elb.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-loadbalancer</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-loadbalancer</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.elb.endpoint</name>
<value>${test.elb.endpoint}</value>
</property>
<property>
<name>test.elb.apiversion</name>
<value>${test.elb.apiversion}</value>
</property>
<property>
<name>test.elb.identity</name>
<value>${test.elb.identity}</value>
</property>
<property>
<name>test.elb.credential</name>
<value>${test.elb.credential}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.elb;
package org.jclouds.elb;
import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION;
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
@ -29,20 +29,23 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
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.CreateLoadBalancerResponseHandler;
import org.jclouds.aws.elb.xml.DescribeLoadBalancersResponseHandler;
import org.jclouds.aws.elb.xml.RegisterInstancesWithLoadBalancerResponseHandler;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.elb.binders.BindAvailabilityZonesToIndexedFormParams;
import org.jclouds.elb.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.elb.binders.BindLoadBalancerNamesToIndexedFormParams;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.elb.xml.CreateLoadBalancerResponseHandler;
import org.jclouds.elb.xml.DescribeLoadBalancersResponseHandler;
import org.jclouds.elb.xml.RegisterInstancesWithLoadBalancerResponseHandler;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -56,7 +59,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@FormParams(keys = VERSION, values = ELBAsyncClient.VERSION)
@VirtualHost
public interface ELBAsyncClient {
public static final String VERSION = "2009-11-25";
public static final String VERSION = "2010-07-01";
/**
* @see ELBClient#createLoadBalancerInRegion
@ -66,12 +69,11 @@ public interface ELBAsyncClient {
@XMLResponseParser(CreateLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "CreateLoadBalancer")
ListenableFuture<String> createLoadBalancerInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name,
@FormParam("Listeners.member.1.Protocol") String protocol,
@FormParam("Listeners.member.1.LoadBalancerPort") int loadBalancerPort,
@FormParam("Listeners.member.1.InstancePort") int instancePort,
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) String... availabilityZones);
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("LoadBalancerName") String name, @FormParam("Listeners.member.1.Protocol") String protocol,
@FormParam("Listeners.member.1.LoadBalancerPort") int loadBalancerPort,
@FormParam("Listeners.member.1.InstancePort") int instancePort,
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) String... availabilityZones);
/**
* @see ELBClient#deleteLoadBalancerInRegion
@ -80,8 +82,8 @@ public interface ELBAsyncClient {
@Path("/")
@FormParams(keys = ACTION, values = "DeleteLoadBalancer")
ListenableFuture<Void> deleteLoadBalancerInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name);
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("LoadBalancerName") String name);
/**
* @see ELBClient#registerInstancesWithLoadBalancerInRegion
@ -90,10 +92,10 @@ public interface ELBAsyncClient {
@Path("/")
@XMLResponseParser(RegisterInstancesWithLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "RegisterInstancesWithLoadBalancer")
ListenableFuture<? extends Set<String>> registerInstancesWithLoadBalancerInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name,
@BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds);
ListenableFuture<Set<String>> registerInstancesWithLoadBalancerInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("LoadBalancerName") String name,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
/**
* @see ELBClient#deregisterInstancesWithLoadBalancerInRegion
@ -102,9 +104,9 @@ public interface ELBAsyncClient {
@Path("/")
@FormParams(keys = ACTION, values = "DeregisterInstancesFromLoadBalancer")
ListenableFuture<Void> deregisterInstancesWithLoadBalancerInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name,
@BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds);
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("LoadBalancerName") String name,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
/**
* @see ELBClient#describeLoadBalancersInRegion
@ -113,7 +115,9 @@ public interface ELBAsyncClient {
@Path("/")
@XMLResponseParser(DescribeLoadBalancersResponseHandler.class)
@FormParams(keys = ACTION, values = "DescribeLoadBalancers")
ListenableFuture<? extends Set<LoadBalancer>> describeLoadBalancersInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<? extends LoadBalancer>> describeLoadBalancersInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@BinderParam(BindLoadBalancerNamesToIndexedFormParams.class) String... loadbalancerNames);
}

View File

@ -17,15 +17,15 @@
* ====================================================================
*/
package org.jclouds.aws.elb;
package org.jclouds.elb;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elb.domain.LoadBalancer;
/**
* Provides access to EC2 Elastic Load Balancer via their REST API.
@ -97,8 +97,9 @@ public interface ELBClient {
/**
* Returns a set of elastic load balancers
* @param region
* @param loadbalancerNames names associated with the LoadBalancers at creation time.
* @return
*/
Set<LoadBalancer> describeLoadBalancersInRegion(@Nullable String region);
Set<? extends LoadBalancer> describeLoadBalancersInRegion(@Nullable String region, String... loadbalancerNames);
}
}

View File

@ -17,15 +17,16 @@
* ====================================================================
*/
package org.jclouds.aws.elb;
package org.jclouds.elb;
import java.util.List;
import java.util.Properties;
import org.jclouds.aws.elb.config.ELBRestClientModule;
import org.jclouds.elb.config.ELBRestClientModule;
import org.jclouds.elb.loadbalancer.config.ELBLoadBalancerContextModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.loadbalancer.LoadBalancerServiceContextBuilder;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Injector;
import com.google.inject.Module;
@ -43,7 +44,12 @@ import com.google.inject.Module;
* @author Adrian Cole
* @see ELBContext
*/
public class ELBContextBuilder extends RestContextBuilder<ELBClient, ELBAsyncClient> {
public class ELBContextBuilder extends LoadBalancerServiceContextBuilder<ELBClient, ELBAsyncClient> {
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new ELBLoadBalancerContextModule());
}
public ELBContextBuilder(Properties props) {
super(ELBClient.class, ELBAsyncClient.class, props);

View File

@ -17,13 +17,14 @@
* ====================================================================
*/
package org.jclouds.aws.elb;
package org.jclouds.elb;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_ZONECLIENT_ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
@ -44,18 +45,18 @@ public class ELBPropertiesBuilder extends PropertiesBuilder {
properties.setProperty(PROPERTY_AUTH_TAG, "AWS");
properties.setProperty(PROPERTY_HEADER_TAG, "amz");
properties.setProperty(PROPERTY_API_VERSION, ELBAsyncClient.VERSION);
properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_EAST_1,
Region.US_WEST_1, Region.EU_WEST_1, Region.AP_SOUTHEAST_1));
properties.setProperty(PROPERTY_ENDPOINT,
"https://elasticloadbalancing.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_REGIONS,
Joiner.on(',').join(Region.US_EAST_1, Region.US_WEST_1, Region.EU_WEST_1, Region.AP_SOUTHEAST_1));
properties.setProperty(PROPERTY_ENDPOINT, "https://elasticloadbalancing.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_EAST_1,
"https://elasticloadbalancing.us-east-1.amazonaws.com");
"https://elasticloadbalancing.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_WEST_1,
"https://elasticloadbalancing.us-west-1.amazonaws.com");
"https://elasticloadbalancing.us-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.EU_WEST_1,
"https://elasticloadbalancing.eu-west-1.amazonaws.com");
"https://elasticloadbalancing.eu-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.AP_SOUTHEAST_1,
"https://elasticloadbalancing.ap-southeast-1.amazonaws.com");
"https://elasticloadbalancing.ap-southeast-1.amazonaws.com");
properties.setProperty(PROPERTY_ZONECLIENT_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
return properties;
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.elb.binders;
package org.jclouds.elb.binders;
import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithStringFormat;
@ -33,9 +33,9 @@ import org.jclouds.rest.Binder;
*/
@Singleton
public class BindAvailabilityZonesToIndexedFormParams implements Binder {
public void bindToRequest(HttpRequest request, Object input) {
indexStringArrayToFormValuesWithStringFormat(request, "AvailabilityZones.member.%s", input);
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return indexStringArrayToFormValuesWithStringFormat(request, "AvailabilityZones.member.%s", input);
}
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.elb.binders;
package org.jclouds.elb.binders;
import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithStringFormat;
@ -32,10 +32,10 @@ import org.jclouds.rest.Binder;
* @author Adrian Cole
*/
@Singleton
public class BindELBInstanceIdsToIndexedFormParams implements Binder {
public void bindToRequest(HttpRequest request, Object input) {
indexStringArrayToFormValuesWithStringFormat(request, "Instances.member.%s.InstanceId", input);
public class BindInstanceIdsToIndexedFormParams implements Binder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return indexStringArrayToFormValuesWithStringFormat(request, "Instances.member.%s.InstanceId", input);
}
}
}

View File

@ -0,0 +1,22 @@
package org.jclouds.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 LoadBalancerNames.member.index
*
* @author Adrian Cole
*/
@Singleton
public class BindLoadBalancerNamesToIndexedFormParams implements Binder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return indexStringArrayToFormValuesWithStringFormat(request, "LoadBalancerNames.member.%s", input);
}
}

View File

@ -17,11 +17,11 @@
* ====================================================================
*/
package org.jclouds.aws.elb.config;
package org.jclouds.elb.config;
import org.jclouds.aws.config.AWSFormSigningRestClientModule;
import org.jclouds.aws.elb.ELBAsyncClient;
import org.jclouds.aws.elb.ELBClient;
import org.jclouds.aws.config.WithZonesFormSigningRestClientModule;
import org.jclouds.elb.ELBAsyncClient;
import org.jclouds.elb.ELBClient;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
@ -32,9 +32,9 @@ import org.jclouds.rest.ConfiguresRestClient;
*/
@RequiresHttp
@ConfiguresRestClient
public class ELBRestClientModule extends AWSFormSigningRestClientModule<ELBClient, ELBAsyncClient> {
public class ELBRestClientModule extends WithZonesFormSigningRestClientModule<ELBClient, ELBAsyncClient> {
public ELBRestClientModule() {
super(ELBClient.class, ELBAsyncClient.class);
}
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.elb.domain;
package org.jclouds.elb.domain;
import java.util.HashSet;
import java.util.Set;
@ -45,9 +45,8 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
this.loadBalancerListeners = new HashSet<LoadBalancerListener>();
}
public LoadBalancer(String region, String name, Set<String> instanceIds,
Set<String> availabilityZones, String dnsName) {
super();
public LoadBalancer(String region, String name, Set<String> instanceIds, Set<String> availabilityZones,
String dnsName) {
this.region = region;
this.name = name;
this.instanceIds = instanceIds;
@ -125,19 +124,24 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
return name.compareTo(that.name);
}
@Override
public String toString() {
return "[region=" + region + ", name=" + name + ", instanceIds=" + instanceIds + ", availabilityZones="
+ availabilityZones + ", dnsName=" + dnsName + ", appCookieStickinessPolicy=" + appCookieStickinessPolicy
+ ", lBCookieStickinessPolicy=" + lBCookieStickinessPolicy + ", loadBalancerListeners="
+ loadBalancerListeners + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((appCookieStickinessPolicy == null) ? 0 : appCookieStickinessPolicy.hashCode());
result = prime * result + ((appCookieStickinessPolicy == null) ? 0 : appCookieStickinessPolicy.hashCode());
result = prime * result + ((availabilityZones == null) ? 0 : availabilityZones.hashCode());
result = prime * result + ((dnsName == null) ? 0 : dnsName.hashCode());
result = prime * result + ((instanceIds == null) ? 0 : instanceIds.hashCode());
result = prime * result
+ ((lBCookieStickinessPolicy == null) ? 0 : lBCookieStickinessPolicy.hashCode());
result = prime * result
+ ((loadBalancerListeners == null) ? 0 : loadBalancerListeners.hashCode());
result = prime * result + ((lBCookieStickinessPolicy == null) ? 0 : lBCookieStickinessPolicy.hashCode());
result = prime * result + ((loadBalancerListeners == null) ? 0 : loadBalancerListeners.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((region == null) ? 0 : region.hashCode());
return result;
@ -234,6 +238,11 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
return result;
}
@Override
public String toString() {
return "[policyName=" + policyName + ", cookieName=" + cookieName + "]";
}
@Override
public boolean equals(Object obj) {
if (this == obj)
@ -292,8 +301,7 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((cookieExpirationPeriod == null) ? 0 : cookieExpirationPeriod.hashCode());
result = prime * result + ((cookieExpirationPeriod == null) ? 0 : cookieExpirationPeriod.hashCode());
result = prime * result + ((policyName == null) ? 0 : policyName.hashCode());
return result;
}
@ -320,6 +328,11 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
return true;
}
@Override
public String toString() {
return "[policyName=" + policyName + ", cookieExpirationPeriod=" + cookieExpirationPeriod + "]";
}
}
public static class LoadBalancerListener {
@ -328,8 +341,8 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
private Integer loadBalancerPort;
private String protocol;
public LoadBalancerListener(Set<String> policyNames, Integer instancePort,
Integer loadBalancerPort, String protocol) {
public LoadBalancerListener(Set<String> policyNames, Integer instancePort, Integer loadBalancerPort,
String protocol) {
super();
this.policyNames = policyNames;
this.instancePort = instancePort;
@ -416,5 +429,11 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
return true;
}
@Override
public String toString() {
return "[policyNames=" + policyNames + ", instancePort=" + instancePort + ", loadBalancerPort="
+ loadBalancerPort + ", protocol=" + protocol + "]";
}
}
}

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2010 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.elb.loadbalancer.config;
import org.jclouds.elb.loadbalancer.strategy.ELBDestroyLoadBalancerStrategy;
import org.jclouds.elb.loadbalancer.strategy.ELBGetLoadBalancerMetadataStrategy;
import org.jclouds.elb.loadbalancer.strategy.ELBListLoadBalancersStrategy;
import org.jclouds.elb.loadbalancer.strategy.ELBLoadBalanceNodesStrategy;
import org.jclouds.loadbalancer.config.BindLoadBalancerStrategiesByClass;
import org.jclouds.loadbalancer.strategy.DestroyLoadBalancerStrategy;
import org.jclouds.loadbalancer.strategy.GetLoadBalancerMetadataStrategy;
import org.jclouds.loadbalancer.strategy.ListLoadBalancersStrategy;
import org.jclouds.loadbalancer.strategy.LoadBalanceNodesStrategy;
/**
* @author Adrian Cole
*/
public class ELBBindLoadBalancerStrategiesByClass extends BindLoadBalancerStrategiesByClass {
@Override
protected Class<? extends LoadBalanceNodesStrategy> defineLoadBalanceNodesStrategy() {
return ELBLoadBalanceNodesStrategy.class;
}
@Override
protected Class<? extends DestroyLoadBalancerStrategy> defineDestroyLoadBalancerStrategy() {
return ELBDestroyLoadBalancerStrategy.class;
}
@Override
protected Class<? extends GetLoadBalancerMetadataStrategy> defineGetLoadBalancerMetadataStrategy() {
return ELBGetLoadBalancerMetadataStrategy.class;
}
@Override
protected Class<? extends ListLoadBalancersStrategy> defineListLoadBalancersStrategy() {
return ELBListLoadBalancersStrategy.class;
}
}

View File

@ -17,35 +17,29 @@
* ====================================================================
*/
package org.jclouds.compute.suppliers;
package org.jclouds.elb.loadbalancer.config;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.loadbalancer.config.BindLoadBalancerSuppliersByClass;
import org.jclouds.location.suppliers.FirstZoneOrRegionMatchingRegionId;
import org.jclouds.location.suppliers.ZoneToRegionToProvider;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*
* By default allows you to use a static set of locations bound to Set<? extends Location>
*/
@Singleton
public class LocationSupplier implements Supplier<Set<? extends Location>> {
private final Set<? extends Location> locations;
public class ELBBindLoadBalancerSuppliersByClass extends BindLoadBalancerSuppliersByClass {
@Inject
LocationSupplier(Set<? extends Location> locations) {
this.locations = locations;
@Override
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
return FirstZoneOrRegionMatchingRegionId.class;
}
@Override
public Set<? extends Location> get() {
return locations;
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return ZoneToRegionToProvider.class;
}
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2010 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.elb.loadbalancer.config;
import org.jclouds.loadbalancer.config.BaseLoadBalancerServiceContextModule;
/**
* Configures the ELB connection.
*
* @author Adrian Cole
*/
public class ELBLoadBalancerContextModule extends BaseLoadBalancerServiceContextModule {
@Override
protected void configure() {
install(new ELBBindLoadBalancerSuppliersByClass());
install(new ELBBindLoadBalancerStrategiesByClass());
install(new ELBLoadBalancerServiceDependenciesModule());
super.configure();
}
}

View File

@ -0,0 +1,23 @@
package org.jclouds.elb.loadbalancer.config;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.elb.loadbalancer.functions.LoadBalancerToLoadBalancerMetadata;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import com.google.common.base.Function;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
public class ELBLoadBalancerServiceDependenciesModule extends AbstractModule {
@Override
protected void configure() {
bind(new TypeLiteral<Function<LoadBalancer, LoadBalancerMetadata>>() {
}).to(LoadBalancerToLoadBalancerMetadata.class);
}
}

View File

@ -0,0 +1,59 @@
/**
*
* Copyright (C) 2010 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.elb.loadbalancer.functions;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.domain.LoadBalancerType;
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
@Singleton
public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> {
protected final Supplier<Map<String, ? extends Location>> locationMap;
@Inject
public LoadBalancerToLoadBalancerMetadata(Supplier<Map<String, ? extends Location>> locationMap) {
this.locationMap = locationMap;
}
@Override
public LoadBalancerMetadata apply(LoadBalancer input) {
Location location = locationMap.get().get(input.getRegion());
// TODO Builder
return new LoadBalancerMetadataImpl(LoadBalancerType.LB, input.getName(), input.getName(), input.getRegion()
+ "/" + input.getName(), location, null, ImmutableMap.<String, String> of(), ImmutableSet.of(input
.getDnsName()));
}
}

View File

@ -17,21 +17,21 @@
* ====================================================================
*/
package org.jclouds.aws.ec2.compute.strategy;
package org.jclouds.elb.loadbalancer.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.aws.elb.ELBClient;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy;
import org.jclouds.elb.ELBClient;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.DestroyLoadBalancerStrategy;
import org.jclouds.loadbalancer.strategy.GetLoadBalancerMetadataStrategy;
import org.jclouds.logging.Logger;
/**
@ -39,25 +39,26 @@ import org.jclouds.logging.Logger;
* @author Adrian Cole
*/
@Singleton
public class EC2DestroyLoadBalancerStrategy implements DestroyLoadBalancerStrategy {
public class ELBDestroyLoadBalancerStrategy implements DestroyLoadBalancerStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
@Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
protected Logger logger = Logger.NULL;
private final ELBClient elbClient;
private final GetLoadBalancerMetadataStrategy getLoadBalancer;
@Inject
protected EC2DestroyLoadBalancerStrategy(ELBClient elbClient) {
protected ELBDestroyLoadBalancerStrategy(ELBClient elbClient, GetLoadBalancerMetadataStrategy getLoadBalancer) {
this.elbClient = checkNotNull(elbClient, "elbClient");
this.getLoadBalancer = checkNotNull(getLoadBalancer, "getLoadBalancer");
}
@Override
public boolean execute(String loadBalancer) {
Map<String, String> tuple = EC2Utils.getLoadBalancerNameAndRegionFromDnsName(loadBalancer);
// Only one load balancer per DNS name is expected
for (String key : tuple.keySet()) {
elbClient.deleteLoadBalancerInRegion(key, tuple.get(key));
}
return true;
public LoadBalancerMetadata destroyLoadBalancer(String id) {
String[] parts = parseHandle(id);
String region = parts[0];
String instanceId = parts[1];
elbClient.deleteLoadBalancerInRegion(region, instanceId);
return getLoadBalancer.getLoadBalancer(id);
}
}
}

View File

@ -0,0 +1,47 @@
package org.jclouds.elb.loadbalancer.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.elb.ELBClient;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.strategy.GetLoadBalancerMetadataStrategy;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ELBGetLoadBalancerMetadataStrategy implements GetLoadBalancerMetadataStrategy {
private final ELBClient client;
private final Function<LoadBalancer, LoadBalancerMetadata> converter;
@Inject
protected ELBGetLoadBalancerMetadataStrategy(ELBClient client, Function<LoadBalancer, LoadBalancerMetadata> converter) {
this.client = checkNotNull(client, "client");
this.converter = checkNotNull(converter, "converter");
}
@Override
public LoadBalancerMetadata getLoadBalancer(String id) {
String[] parts = parseHandle(id);
String region = parts[0];
String instanceId = parts[1];
try {
return converter.apply(getOnlyElement(client.describeLoadBalancersInRegion(region, region, instanceId)));
} catch (NoSuchElementException e) {
return null;
}
}
}

View File

@ -0,0 +1,93 @@
/**
*
* Copyright (C) 2010 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.elb.loadbalancer.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.elb.ELBAsyncClient;
import org.jclouds.elb.ELBClient;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.ListLoadBalancersStrategy;
import org.jclouds.location.Region;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
@Resource
@Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
protected Logger logger = Logger.NULL;
private final ELBClient client;
private final ELBAsyncClient aclient;
private final Function<LoadBalancer, LoadBalancerMetadata> converter;
private final ExecutorService executor;
private final Set<String> regions;
@Inject
protected ELBListLoadBalancersStrategy(ELBClient client, ELBAsyncClient aclient,
Function<LoadBalancer, LoadBalancerMetadata> converter,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Nullable @Region Set<String> regions) {
this.client = checkNotNull(client, "client");
this.aclient = checkNotNull(aclient, "aclient");
this.regions = checkNotNull(regions, "regions");
this.converter = checkNotNull(converter, "converter");
this.executor = checkNotNull(executor, "executor");
}
@Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
Iterable<? extends LoadBalancer> loadBalancers;
if (regions != null)
loadBalancers = concat(transformParallel(regions, new Function<String, Future<Set<? extends LoadBalancer>>>() {
@Override
public ListenableFuture<Set<? extends LoadBalancer>> apply(String from) {
return aclient.describeLoadBalancersInRegion(from);
}
}, executor, null, logger, "loadbalancers"));
else
loadBalancers = client.describeLoadBalancersInRegion(null);
return transform(loadBalancers, converter);
}
}

View File

@ -0,0 +1,109 @@
/**
*
* Copyright (C) 2010 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.elb.loadbalancer.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.aws.ec2.compute.util.EC2ComputeUtils.getRegionFromLocationOrNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Location;
import org.jclouds.elb.ELBClient;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.LoadBalanceNodesStrategy;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ELBLoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {
@Resource
@Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
protected Logger logger = Logger.NULL;
protected final ELBClient client;
protected final Function<LoadBalancer, LoadBalancerMetadata> converter;
@Inject
protected ELBLoadBalanceNodesStrategy(ELBClient client, Function<LoadBalancer, LoadBalancerMetadata> converter) {
this.client = checkNotNull(client, "client");
this.converter = checkNotNull(converter, "converter");
}
@Override
public LoadBalancerMetadata createLoadBalancerInLocation(Location location, String name, String protocol,
int loadBalancerPort, int instancePort, Iterable<? extends NodeMetadata> nodes) {
checkNotNull(location, "location");
String region = getRegionFromLocationOrNull(location);
List<String> availabilityZones = Lists.newArrayList(Iterables.transform(nodes,
new Function<NodeMetadata, String>() {
@Override
public String apply(NodeMetadata from) {
return from.getLocation().getId();
}
}));
client.createLoadBalancerInRegion(region, name, protocol, loadBalancerPort, instancePort,
availabilityZones.toArray(new String[] {}));
List<String> instanceIds = Lists.newArrayList(Iterables.transform(nodes, new Function<NodeMetadata, String>() {
@Override
public String apply(NodeMetadata from) {
return from.getProviderId();
}
}));
String[] instanceIdArray = instanceIds.toArray(new String[] {});
Set<String> registeredInstanceIds = client.registerInstancesWithLoadBalancerInRegion(region, name,
instanceIdArray);
// deregister instances
boolean changed = registeredInstanceIds.removeAll(instanceIds);
if (changed) {
List<String> list = new ArrayList<String>(registeredInstanceIds);
instanceIdArray = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
instanceIdArray[i] = list.get(i);
}
if (instanceIdArray.length > 0)
client.deregisterInstancesWithLoadBalancerInRegion(region, name, instanceIdArray);
}
return converter.apply(Iterables.getOnlyElement(client.describeLoadBalancersInRegion(region, name)));
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.elb.xml;
package org.jclouds.elb.xml;
import javax.annotation.Resource;
@ -52,4 +52,4 @@ public class CreateLoadBalancerResponseHandler extends HandlerWithResult<String>
public String getResult() {
return dnsName;
}
}
}

View File

@ -17,24 +17,22 @@
* ====================================================================
*/
package org.jclouds.aws.elb.xml;
package org.jclouds.elb.xml;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.aws.elb.domain.LoadBalancer.AppCookieStickinessPolicy;
import org.jclouds.aws.elb.domain.LoadBalancer.LBCookieStickinessPolicy;
import org.jclouds.aws.elb.domain.LoadBalancer.LoadBalancerListener;
import org.jclouds.date.DateService;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.elb.domain.LoadBalancer.AppCookieStickinessPolicy;
import org.jclouds.elb.domain.LoadBalancer.LBCookieStickinessPolicy;
import org.jclouds.elb.domain.LoadBalancer.LoadBalancerListener;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
@ -44,23 +42,21 @@ import com.google.common.collect.Sets;
* @author Lili Nadar
*/
public class DescribeLoadBalancersResponseHandler extends
ParseSax.HandlerForGeneratedRequestWithResult<Set<LoadBalancer>> {
@Inject
public DescribeLoadBalancersResponseHandler(@Region String defaultRegion) {
this.defaultRegion = defaultRegion;
this.listenerHandler = new LoadBalancerListenerHandler();
}
ParseSax.HandlerForGeneratedRequestWithResult<Set<LoadBalancer>> {
private final DateService dateService;
private final LoadBalancerListenerHandler listenerHandler;
@Inject
protected DateService dateService;
public DescribeLoadBalancersResponseHandler(DateService dateService, LoadBalancerListenerHandler listenerHandler) {
this.dateService = dateService;
this.listenerHandler = listenerHandler;
}
@Resource
protected Logger logger = Logger.NULL;
private Set<LoadBalancer> contents = Sets.newLinkedHashSet();
private StringBuilder currentText = new StringBuilder();
private final String defaultRegion;
private final LoadBalancerListenerHandler listenerHandler;
private boolean inListenerDescriptions = false;
private boolean inInstances = false;
@ -93,8 +89,7 @@ public class DescribeLoadBalancersResponseHandler extends
}
if (qName.equals("member")) {
if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones)) {
if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances || inLBCookieStickinessPolicies || inAvailabilityZones)) {
elb = new LoadBalancer();
}
}
@ -129,12 +124,9 @@ public class DescribeLoadBalancersResponseHandler extends
if (inAvailabilityZones) {
elb.getAvailabilityZones().add(currentText.toString().trim());
} else if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones)) {
|| inLBCookieStickinessPolicies || inAvailabilityZones)) {
try {
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
elb.setRegion(region);
contents.add(elb);
} catch (NullPointerException e) {
@ -166,8 +158,7 @@ public class DescribeLoadBalancersResponseHandler extends
return this;
}
public class LoadBalancerListenerHandler extends
ParseSax.HandlerWithResult<Set<LoadBalancerListener>> {
public static class LoadBalancerListenerHandler extends ParseSax.HandlerWithResult<Set<LoadBalancerListener>> {
private Set<LoadBalancerListener> listeners = Sets.newHashSet();
private StringBuilder currentText = new StringBuilder();
private LoadBalancerListener listener;

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.elb.xml;
package org.jclouds.elb.xml;
import java.util.Set;

View File

@ -0,0 +1,192 @@
/**
*
* Copyright (C) 2010 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.elb;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService;
import org.jclouds.elb.config.ELBRestClientModule;
import org.jclouds.elb.xml.CreateLoadBalancerResponseHandler;
import org.jclouds.elb.xml.DescribeLoadBalancersResponseHandler;
import org.jclouds.elb.xml.RegisterInstancesWithLoadBalancerResponseHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ELBAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "ELBAsyncClientTest")
public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
public void testCreateLoadBalancerInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = ELBAsyncClient.class.getMethod("createLoadBalancerInRegion", String.class, String.class,
String.class, int.class, int.class, String[].class);
HttpRequest request = processor.createRequest(method, null, "name", "http", 80, 80);
assertRequestLineEquals(request, "POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-07-01&Action=CreateLoadBalancer&Listeners.member.1.Protocol=http&LoadBalancerName=name&Listeners.member.1.InstancePort=80&Listeners.member.1.LoadBalancerPort=80",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CreateLoadBalancerResponseHandler.class);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(request);
}
public void testDescribeLoadBalancers() throws SecurityException, NoSuchMethodException, IOException {
Method method = ELBAsyncClient.class.getMethod("describeLoadBalancersInRegion", String.class, String[].class);
HttpRequest request = processor.createRequest(method, (String) null);
assertRequestLineEquals(request, "POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-07-01&Action=DescribeLoadBalancers",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeLoadBalancersResponseHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testDescribeLoadBalancersArgs() throws SecurityException, NoSuchMethodException, IOException {
Method method = ELBAsyncClient.class.getMethod("describeLoadBalancersInRegion", String.class, String[].class);
HttpRequest request = processor.createRequest(method, null, "1", "2");
assertRequestLineEquals(request, "POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-07-01&Action=DescribeLoadBalancers&LoadBalancerNames.member.1=1&LoadBalancerNames.member.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeLoadBalancersResponseHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testRegisterInstancesWithLoadBalancer() throws SecurityException, NoSuchMethodException, IOException {
Method method = ELBAsyncClient.class.getMethod("registerInstancesWithLoadBalancerInRegion", String.class,
String.class, String[].class);
HttpRequest request = processor.createRequest(method, null, "ReferenceAP1", "i-6055fa09");
assertRequestLineEquals(request, "POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-07-01&Action=RegisterInstancesWithLoadBalancer&LoadBalancerName=ReferenceAP1&Instances.member.1.InstanceId=i-6055fa09",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, RegisterInstancesWithLoadBalancerResponseHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDeregisterInstancesWithLoadBalancer() throws SecurityException, NoSuchMethodException, IOException {
Method method = ELBAsyncClient.class.getMethod("deregisterInstancesWithLoadBalancerInRegion", String.class,
String.class, String[].class);
HttpRequest request = processor.createRequest(method, null, "ReferenceAP1", "i-6055fa09");
assertRequestLineEquals(request, "POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-07-01&Action=DeregisterInstancesFromLoadBalancer&LoadBalancerName=ReferenceAP1&Instances.member.1.InstanceId=i-6055fa09",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<ELBAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ELBAsyncClient>>() {
};
}
@RequiresHttp
@ConfiguresRestClient
private static final class TestELBRestClientModule extends ELBRestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected String provideTimeStamp(final DateService dateService,
@Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) {
return "2009-11-08T15:54:08.897Z";
}
}
@Override
protected Module createModule() {
return new TestELBRestClientModule();
}
@Override
public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("elb", "identity", "credential", new Properties());
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), FormSigner.class);
}
}

View File

@ -17,22 +17,22 @@
* ====================================================================
*/
package org.jclouds.aws.elb;
package org.jclouds.elb;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertNotNull;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -47,7 +47,7 @@ import com.google.inject.Module;
*
* @author Lili Nader
*/
@Test(groups = "live", sequential = true, testName = "ec2.ELBClientLiveTest")
@Test(groups = "live", sequential = true)
public class ELBClientLiveTest {
private ELBClient client;
@ -61,10 +61,9 @@ public class ELBClientLiveTest {
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider
+ ".apiversion");
+ ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected Properties setupProperties() {
@ -72,9 +71,12 @@ public class ELBClientLiveTest {
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
overrides.setProperty(provider + ".endpoint", endpoint);
overrides.setProperty(provider + ".apiversion", apiversion);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@ -82,8 +84,8 @@ public class ELBClientLiveTest {
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new Log4JLoggingModule()),
overrides);
context = new LoadBalancerServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
client = context.getApi();
}
@ -91,10 +93,10 @@ public class ELBClientLiveTest {
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.createLoadBalancerInRegion(regionZone.getKey(), name, "http", 80, 80, regionZone
.getValue());
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.createLoadBalancerInRegion(regionZone.getKey(), name, "http", 80, 80,
regionZone.getValue());
assertNotNull(dnsName);
assert (dnsName.startsWith(name));
}
@ -103,8 +105,8 @@ public class ELBClientLiveTest {
@Test(dependsOnMethods = "testCreateLoadBalancer")
void testDescribeLoadBalancers() {
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);
Region.AP_SOUTHEAST_1)) {
Set<? extends LoadBalancer> allResults = client.describeLoadBalancersInRegion(region);
assertNotNull(allResults);
assert (allResults.size() >= 1);
}
@ -113,7 +115,7 @@ public class ELBClientLiveTest {
@Test
void testDeleteLoadBalancer() {
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1,
Region.AP_SOUTHEAST_1)) {
Region.AP_SOUTHEAST_1)) {
client.deleteLoadBalancerInRegion(region, "TestLoadBalancer");
}
}

View File

@ -0,0 +1,41 @@
/**
*
* Copyright (C) 2010 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.elb;
import org.jclouds.rest.Providers;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*
*/
@Test(groups = "unit")
public class ProvidersInPropertiesTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Providers.getSupportedProviders();
assert Iterables.contains(providers, "elb") : providers;
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.ec2.compute;
package org.jclouds.elb.loadbalancer;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@ -26,35 +26,25 @@ import java.util.HashSet;
import java.util.Set;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.elb.ELBAsyncClient;
import org.jclouds.aws.elb.ELBClient;
import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.compute.BaseLoadBalancerServiceLiveTest;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.elb.ELBAsyncClient;
import org.jclouds.elb.ELBClient;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.BaseLoadBalancerServiceLiveTest;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Lili Nadar
*/
@Test(groups = "live", sequential = true, testName = "ec2.EC2LoadBalancerServiceLiveTest")
public class EC2LoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest {
@Test(groups = "live", sequential = true)
public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest {
private RestContext<ELBClient, ELBAsyncClient> elbContext;
@BeforeClass
@Override
public void setServiceDefaults() {
provider = "ec2";
public ELBLoadBalancerServiceLiveTest() {
provider = "elb";
computeProvider = "ec2";
}
@Override
@ -62,20 +52,9 @@ public class EC2LoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT
return new JschSshClientModule();
}
@BeforeGroups(groups = { "live" })
public void setupELBClient() {
elbContext = new RestContextFactory().createContext("elb", identity, credential,
ImmutableSet.of(new Log4JLoggingModule()));
}
@AfterGroups(groups = { "live" })
public void tearDownELBClient() {
if (elbContext != null)
elbContext.close();
}
@Override
protected void validateNodesInLoadBalancer() {
RestContext<ELBClient, ELBAsyncClient> elbContext = context.getProviderSpecificContext();
// TODO create a LoadBalancer object and an appropriate list method so that this
// does not have to be EC2 specific code
ELBClient elbClient = elbContext.getApi();
@ -84,12 +63,11 @@ public class EC2LoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT
for (NodeMetadata node : nodes) {
instanceIds.add(node.getProviderId());
}
Set<LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1);
Set<? extends LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1);
assertNotNull(elbs);
for(LoadBalancer elb:elbs)
{
if(elb.getName().equals(tag))
assertEquals(elb.getInstanceIds(), instanceIds);
for (LoadBalancer elb : elbs) {
if (elb.getName().equals(tag))
assertEquals(elb.getInstanceIds(), instanceIds);
}
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.elb.xml;
package org.jclouds.elb.xml;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
@ -27,30 +27,32 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.aws.ec2.xml.BaseEC2HandlerTest;
import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code DescribeLoadBalancersResponseHandler}
* Tests behavior of {@code DescribeLoadBalancerResponseHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "elb.DescribeLoadBalancersResponseHandlerTest")
public class DescribeLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest {
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "DescribeLoadBalancerResponseHandlerTest")
public class DescribeLoadBalancerResponseHandlerTest extends BaseHandlerTest {
public void testParse() {
InputStream is = getClass().getResourceAsStream("/elb/describe_loadbalancers.xml");
InputStream is = getClass().getResourceAsStream("/describe_loadbalancers.xml");
Set<LoadBalancer> contents = Sets.newHashSet();
LoadBalancer dummy = new LoadBalancer(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");
LoadBalancer dummy = new LoadBalancer(null, "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");
contents.add(dummy);
Set<LoadBalancer> result = parseLoadBalancers(is);
@ -59,8 +61,7 @@ public class DescribeLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest
}
private Set<LoadBalancer> parseLoadBalancers(InputStream is) {
DescribeLoadBalancersResponseHandler handler = injector
.getInstance(DescribeLoadBalancersResponseHandler.class);
DescribeLoadBalancersResponseHandler handler = injector.getInstance(DescribeLoadBalancersResponseHandler.class);
addDefaultRegionToHandler(handler);
Set<LoadBalancer> result = factory.create(handler).parse(is);
return result;
@ -68,7 +69,7 @@ public class DescribeLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getArgs()).andReturn(new Object[] { null });
expect(request.getArgs()).andReturn(ImmutableList.<Object> of());
replay(request);
handler.setContext(request);
}

View File

@ -17,29 +17,29 @@
* ====================================================================
*/
package org.jclouds.aws.elb.xml;
package org.jclouds.elb.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.aws.ec2.xml.BaseEC2HandlerTest;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code DescribeLoadBalancersResponseHandler}
* Tests behavior of {@code RegisterInstancesWithLoadBalancerResponseHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.RegisterInstancesWithLoadBalancerResponseHandlerTest")
public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest {
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "RegisterInstancesWithLoadBalancerResponseHandlerTest")
public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends BaseHandlerTest {
public void testParse() {
InputStream is = getClass().getResourceAsStream(
"/ec2/register_instances_with_loadbalancer.xml");
InputStream is = getClass().getResourceAsStream("/register_instances_with_loadbalancer.xml");
Set<String> instanceIds = Sets.newHashSet();
instanceIds.add("i-6055fa09");
@ -52,7 +52,7 @@ public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends BaseEC
private Set<String> parseXML(InputStream is) {
RegisterInstancesWithLoadBalancerResponseHandler handler = injector
.getInstance(RegisterInstancesWithLoadBalancerResponseHandler.class);
.getInstance(RegisterInstancesWithLoadBalancerResponseHandler.class);
Set<String> result = factory.create(handler).parse(is);
return result;
}

View File

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="LOADBALANCERFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-loadbalancer.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-compute.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="COMPUTEFILE" />
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<appender name="ASYNCLOADBALANCER" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="LOADBALANCERFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.loadbalancer">
<priority value="DEBUG" />
<appender-ref ref="ASYNCLOADBALANCER" />
</category>
<category name="jclouds.compute">
<priority value="TRACE" />
<appender-ref ref="ASYNCCOMPUTE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -24,24 +24,24 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>jclouds-filesystem</artifactId>
<artifactId>filesystem</artifactId>
<name>jcloud filesystem core</name>
<description>jclouds components to access filesystem</description>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
@ -53,14 +53,14 @@
<version>1.4</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>

View File

@ -463,10 +463,6 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
return 0;
}
public HttpRequest getRequest() {
return new HttpRequest("GET", URI.create("http://stub"));
}
public int incrementFailureCount() {
return 0;
}
@ -475,6 +471,16 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
}
@Override
public HttpRequest getCurrentRequest() {
return new HttpRequest("GET", URI.create("http://stub"));
}
@Override
public void setCurrentRequest(HttpRequest request) {
}
}, response);
}

View File

Before

Width:  |  Height:  |  Size: 339 KiB

After

Width:  |  Height:  |  Size: 339 KiB

View File

Before

Width:  |  Height:  |  Size: 844 KiB

After

Width:  |  Height:  |  Size: 844 KiB

View File

Before

Width:  |  Height:  |  Size: 641 KiB

After

Width:  |  Height:  |  Size: 641 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

44
apis/pom.xml Normal file
View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>jclouds-project</artifactId>
<groupId>org.jclouds</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<packaging>pom</packaging>
<name>jclouds apis project</name>
<modules>
<module>filesystem</module>
<module>s3</module>
<module>ec2</module>
<module>elb</module>
<module>sqs</module>
<module>simpledb</module>
<module>cloudwatch</module>
</modules>
</project>

128
apis/s3/pom.xml Normal file
View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>s3</artifactId>
<name>jcloud s3 api</name>
<description>jclouds components to access an implementation of S3</description>
<properties>
<test.initializer>org.jclouds.s3.blobstore.S3TestInitializer</test.initializer>
<test.s3.endpoint>https://s3.amazonaws.com</test.s3.endpoint>
<test.s3.apiversion>2006-03-01</test.s3.apiversion>
<test.s3.identity>${test.aws.identity}</test.s3.identity>
<test.s3.credential>${test.aws.credential}</test.s3.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.s3.endpoint</name>
<value>${test.s3.endpoint}</value>
</property>
<property>
<name>test.s3.apiversion</name>
<value>${test.s3.apiversion}</value>
</property>
<property>
<name>test.s3.identity</name>
<value>${test.s3.identity}</value>
</property>
<property>
<name>test.s3.credential</name>
<value>${test.s3.credential}</value>
</property>
<property>
<name>test.initializer</name>
<value>${test.initializer}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

110
apis/simpledb/pom.xml Normal file
View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>simpledb</artifactId>
<name>jcloud simpledb api</name>
<description>jclouds components to access an implementation of Simple DB</description>
<properties>
<test.simpledb.endpoint>https://sdb.amazonaws.com</test.simpledb.endpoint>
<test.simpledb.apiversion>2009-04-15</test.simpledb.apiversion>
<test.simpledb.identity>${test.aws.identity}</test.simpledb.identity>
<test.simpledb.credential>${test.aws.credential}</test.simpledb.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.simpledb.endpoint</name>
<value>${test.simpledb.endpoint}</value>
</property>
<property>
<name>test.simpledb.apiversion</name>
<value>${test.simpledb.apiversion}</value>
</property>
<property>
<name>test.simpledb.identity</name>
<value>${test.simpledb.identity}</value>
</property>
<property>
<name>test.simpledb.credential</name>
<value>${test.simpledb.credential}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -17,10 +17,12 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb;
package org.jclouds.simpledb;
import static org.jclouds.aws.simpledb.reference.SimpleDBParameters.ACTION;
import static org.jclouds.aws.simpledb.reference.SimpleDBParameters.VERSION;
import static org.jclouds.simpledb.reference.SimpleDBParameters.ACTION;
import static org.jclouds.simpledb.reference.SimpleDBParameters.VERSION;
import java.util.Map;
import javax.annotation.Nullable;
import javax.ws.rs.FormParam;
@ -28,15 +30,19 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.aws.simpledb.domain.ListDomainsResponse;
import org.jclouds.aws.simpledb.options.ListDomainsOptions;
import org.jclouds.aws.simpledb.xml.ListDomainsResponseHandler;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.simpledb.binders.BindAttributesToIndexedFormParams;
import org.jclouds.simpledb.domain.Item;
import org.jclouds.simpledb.domain.ListDomainsResponse;
import org.jclouds.simpledb.options.ListDomainsOptions;
import org.jclouds.simpledb.xml.ItemsHandler;
import org.jclouds.simpledb.xml.ListDomainsResponseHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -45,6 +51,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* <p/>
*
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = SimpleDBAsyncClient.VERSION)
@ -60,7 +67,7 @@ public interface SimpleDBAsyncClient {
@FormParams(keys = ACTION, values = "ListDomains")
@XMLResponseParser(ListDomainsResponseHandler.class)
ListenableFuture<? extends ListDomainsResponse> listDomainsInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, ListDomainsOptions... options);
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, ListDomainsOptions... options);
/**
* @see SimpleDBClient#createDomainInRegion
@ -68,7 +75,7 @@ public interface SimpleDBAsyncClient {
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateDomain")
ListenableFuture<Void> createDomainInRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
ListenableFuture<Void> createDomainInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("DomainName") String domainName);
/**
@ -77,7 +84,31 @@ public interface SimpleDBAsyncClient {
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteDomain")
ListenableFuture<Void> deleteDomainInRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
ListenableFuture<Void> deleteDomainInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("DomainName") String domainName);
/**
* @see SimpleDBClient#putAttributes
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "PutAttributes")
ListenableFuture<Void> putAttributes(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("DomainName") String domainName,
@FormParam("ItemName") String itemName,
@BinderParam(BindAttributesToIndexedFormParams.class) Item attributes);
/**
* @see SimpleDBClient#putAttributes
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "Select")
@XMLResponseParser(ItemsHandler.class)
ListenableFuture<? extends Map<String, Item>> select(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("SelectExpression") String selectExpression);
}

View File

@ -17,21 +17,24 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb;
package org.jclouds.simpledb;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.simpledb.domain.ListDomainsResponse;
import org.jclouds.aws.simpledb.options.ListDomainsOptions;
import org.jclouds.concurrent.Timeout;
import org.jclouds.simpledb.domain.Item;
import org.jclouds.simpledb.domain.ListDomainsResponse;
import org.jclouds.simpledb.options.ListDomainsOptions;
/**
* Provides access to SimpleDB via their REST API.
* <p/>
*
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface SimpleDBClient {
@ -69,7 +72,7 @@ public interface SimpleDBClient {
* You can create up to 100 domains per account.
* <p/>
* If you require additional domains, go to
* http://aws.amazon.com/contact-us/simpledb-limit-request/.
* http://amazon.com/contact-us/simpledb-limit-request/.
*
* @param region
* Domains are Region-specific.
@ -103,5 +106,6 @@ public interface SimpleDBClient {
* />
*/
void deleteDomainInRegion(String region, String domainName);
void putAttributes(String region, String domain, String itemName, Item attributes);
Map<String, Item> select(String region, String selectionExpression);
}

View File

@ -17,15 +17,15 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb;
package org.jclouds.simpledb;
import java.util.List;
import java.util.Properties;
import org.jclouds.aws.simpledb.config.SimpleDBRestClientModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.simpledb.config.SimpleDBRestClientModule;
import com.google.inject.Injector;
import com.google.inject.Module;
@ -41,6 +41,7 @@ import com.google.inject.Module;
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
* @see SimpleDBContext
*/
public class SimpleDBContextBuilder extends RestContextBuilder<SimpleDBClient, SimpleDBAsyncClient> {

View File

@ -17,20 +17,16 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb;
package org.jclouds.simpledb;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.aws.domain.Region;
import com.google.common.base.Joiner;
/**
* Builds properties used in SimpleDB Clients
@ -38,23 +34,14 @@ import com.google.common.base.Joiner;
* @author Adrian Cole
*/
public class SimpleDBPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_AUTH_TAG, "AWS");
properties.setProperty(PROPERTY_HEADER_TAG, "amz");
properties.setProperty(PROPERTY_API_VERSION, SimpleDBAsyncClient.VERSION);
properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_EAST_1,
Region.US_WEST_1, Region.EU_WEST_1, Region.AP_SOUTHEAST_1));
properties.setProperty(PROPERTY_ENDPOINT, "https://sdb.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_EAST_1,
"https://sdb.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_WEST_1,
"https://sdb.us-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.EU_WEST_1,
"https://sdb.eu-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.AP_SOUTHEAST_1,
"https://sdb.ap-southeast-1.amazonaws.com");
return properties;
}

View File

@ -0,0 +1,60 @@
package org.jclouds.simpledb.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
import java.util.Collection;
import java.util.Iterator;
import org.jclouds.simpledb.domain.AttributePair;
import org.jclouds.simpledb.domain.Item;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.utils.ModifyRequest;
import org.jclouds.rest.Binder;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableMultimap.Builder;
/**
*
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
public class BindAttributesToIndexedFormParams implements Binder {
private final String attributeName = "Attribute.%d.Name";
private final String attributeValue = "Attribute.%d.Value";
private final String attributeReplace = "Attribute.%d.Replace";
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof Item, "this binder is only valid for AttributeMap");
Item attributeMap = (Item) input;
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
int amazonOneBasedIndex = 1; // according to docs, counters must start with 1
for (String itemName : attributeMap.getAttributes().keySet()) {
Collection<AttributePair> c = attributeMap.getAttributes().get(itemName);
Iterator<AttributePair> it = c.iterator();
while (it.hasNext()) {
AttributePair attr = it.next();
// not null by contract
String value = attr.getValue();
if (value != null) {
builder.put(format(attributeName, amazonOneBasedIndex), attr.getKey());
builder.put(format(attributeValue, amazonOneBasedIndex), value);
builder.put(format(attributeReplace, amazonOneBasedIndex), String.valueOf(attr.isReplace()));
}
amazonOneBasedIndex++;
}
}
ImmutableMultimap<String, String> forms = builder.build();
return forms.size() == 0 ? request : ModifyRequest.putFormParams(request, forms);
}
}

View File

@ -17,22 +17,23 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.config;
package org.jclouds.simpledb.config;
import org.jclouds.aws.config.AWSFormSigningRestClientModule;
import org.jclouds.aws.simpledb.SimpleDBAsyncClient;
import org.jclouds.aws.simpledb.SimpleDBClient;
import org.jclouds.aws.config.FormSigningRestClientModule;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.simpledb.SimpleDBAsyncClient;
import org.jclouds.simpledb.SimpleDBClient;
/**
* Configures the SimpleDB connection.
*
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
@RequiresHttp
@ConfiguresRestClient
public class SimpleDBRestClientModule extends AWSFormSigningRestClientModule<SimpleDBClient, SimpleDBAsyncClient> {
public class SimpleDBRestClientModule extends FormSigningRestClientModule<SimpleDBClient, SimpleDBAsyncClient> {
public SimpleDBRestClientModule() {
super(SimpleDBClient.class, SimpleDBAsyncClient.class);

View File

@ -0,0 +1,60 @@
package org.jclouds.simpledb.domain;
/**
* AttributePair is a class to support the attributes to put in the SimpleDB
* <p/>
*
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
public class AttributePair
{
private String key;
private String value;
private boolean replace;
/**
*
* Default constructor to represent an attribute in a domain in SimpleDB
*
* <p/>
*
* @param key Name of Attribute
* @param value Value of Attribute
* @param replace Replace value if it already exists in domain
*/
public AttributePair(String key, String value, boolean replace)
{
this.key = key;
this.value = value ;
this.replace = replace;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public void setValue(String value)
{
this.value = value;
}
public boolean isReplace() {
return replace;
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.domain;
package org.jclouds.simpledb.domain;
import java.util.Date;
@ -27,6 +27,7 @@ import java.util.Date;
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/index.html?SDB_API_CreateDomain.html"
* />
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
public class DomainMetadata {
private final String region;

View File

@ -0,0 +1,45 @@
package org.jclouds.simpledb.domain;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
/**
* Defines the mapping of Items
*
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
public class Item {
private final Multimap<String, AttributePair> attributes = LinkedHashMultimap
.create();
public Item() {
}
/**
* Creates a map of Attribute Pair
*
*/
public Item(Multimap<String, AttributePair> attributes)
{
this.attributes.putAll(attributes);
}
public Item addAttributePair(@Nullable String itemName,
AttributePair attrPair)
{
this.attributes.put(itemName, attrPair);
return this;
}
public Multimap<String, AttributePair> getAttributes()
{
return ImmutableMultimap.<String, AttributePair> builder().putAll(
attributes).build();
}
}

View File

@ -17,13 +17,14 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.domain;
package org.jclouds.simpledb.domain;
import java.util.Set;
/**
*
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html" />
*/
public interface ListDomainsResponse extends Set<String> {
@ -34,4 +35,4 @@ public interface ListDomainsResponse extends Set<String> {
*/
String getNextToken();
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.options;
package org.jclouds.simpledb.options;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@ -31,13 +31,14 @@ import org.jclouds.http.options.BaseHttpRequestOptions;
* (if needed):
* <p/>
* <code>
* import static org.jclouds.aws.simpledb.options.ListDomainsOptions.Builder.*
* import static org.jclouds.simpledb.options.ListDomainsOptions.Builder.*
* <p/>
* SimpleDBClient connection = // get connection
* Set<String> domains = connection.listDomainsInRegion(maxNumberOfDomains(1));
* <code>
*
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
* @see <a href=
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/SDB_API_ListDomains.html"
* />

View File

@ -21,5 +21,6 @@
*
* @see <a href="http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/index.html"/>
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
package org.jclouds.aws.simpledb;
package org.jclouds.simpledb;

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.reference;
package org.jclouds.simpledb.reference;
/**
* Configuration properties and constants used in SimpleDB connections.
@ -25,6 +25,7 @@ package org.jclouds.aws.simpledb.reference;
* @see <a href="http://docs.amazonwebservices.com/AWSSimpleDomainService/2009-02-01/APIReference/Query_QueryParams.html"
* />
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
public interface SimpleDBParameters {

View File

@ -21,4 +21,4 @@
* This package contains properties and reference data used in SimpleDB.
* @author Adrian Cole
*/
package org.jclouds.aws.simpledb.reference;
package org.jclouds.simpledb.reference;

View File

@ -0,0 +1,110 @@
/**
*
* Copyright (C) 2010 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.simpledb.xml;
import java.util.Map;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.simpledb.domain.AttributePair;
import org.jclouds.simpledb.domain.Item;
import org.xml.sax.Attributes;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.inject.Inject;
/**
*
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*/
public class ItemsHandler extends
ParseSax.HandlerWithResult<Map<String, Item>> {
private StringBuilder currentText = new StringBuilder();
private Map<String, Item> items = Maps.newConcurrentMap();
private Multimap<String, AttributePair> attributes = LinkedHashMultimap.create();
private String attributeName;
private String attributeValue = "";
private String itemName;
private boolean inside = false;
protected final DateService dateService;
@Inject
public ItemsHandler(DateService dateService) {
this.dateService = dateService;
}
public Map<String, Item> getResult() {
return items;
}
public void startElement(String uri, String localName, String qName, Attributes attributes)
{
if (qName.equals("Attribute")) {
inside = true;
}
}
public void endElement(String uri, String name, String qName)
{
if (qName.equals("Attribute"))
{
inside = false;
System.out.println("AttributeName: " + attributeName);
System.out.println("AttributeValue: " + attributeValue);
}
else if(qName.equals("Name")) {
if (inside)
attributeName = currentText.toString().trim();
else
itemName = currentText.toString().trim();
} else if (qName.equals("Value"))
{
attributeValue = currentText.toString().trim();
attributes.put(attributeName,new AttributePair(attributeName,
attributeValue, false));
}
else if (qName.equals("Item"))
{
System.out.println("ItemName: " + itemName);
Item item = new Item(attributes);
items.put(itemName, item);
attributes = LinkedHashMultimap.create();
this.attributeName = null;
this.attributeValue = null;
this.itemName = null;
inside = false;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -17,12 +17,12 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.xml;
package org.jclouds.simpledb.xml;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jclouds.aws.simpledb.domain.ListDomainsResponse;
import org.jclouds.simpledb.domain.ListDomainsResponse;
import org.jclouds.http.functions.ParseSax;
import com.google.common.collect.Iterables;
@ -34,6 +34,7 @@ import com.google.common.collect.Sets;
* ListDomainsResponse
*
* @author Adrian Cole
* @author Luís A. Bastião Silva <bastiao@ua.pt>
* @see <a href=
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/SDB_API_ListDomains.htm l"
* />

View File

@ -0,0 +1,41 @@
/**
*
* Copyright (C) 2010 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.simpledb;
import org.jclouds.rest.Providers;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*
*/
@Test(groups = "unit")
public class ProvidersInPropertiesTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Providers.getSupportedProviders();
assert Iterables.contains(providers, "simpledb") : providers;
}
}

View File

@ -17,19 +17,16 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb;
package org.jclouds.simpledb;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Properties;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.simpledb.config.SimpleDBRestClientModule;
import org.jclouds.aws.simpledb.options.ListDomainsOptions;
import org.jclouds.aws.simpledb.xml.ListDomainsResponseHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax;
@ -39,6 +36,9 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.simpledb.config.SimpleDBRestClientModule;
import org.jclouds.simpledb.options.ListDomainsOptions;
import org.jclouds.simpledb.xml.ListDomainsResponseHandler;
import org.testng.annotations.Test;
import com.google.inject.Module;
@ -49,9 +49,12 @@ import com.google.inject.TypeLiteral;
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "simpledb.SimpleDBAsyncClientTest")
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "SimpleDBAsyncClientTest")
public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient> {
protected String provider = "simpledb";
@RequiresHttp
@ConfiguresRestClient
private static final class TestSimpleDBRestClientModule extends SimpleDBRestClientModule {
@ -94,11 +97,23 @@ public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient>
checkFilters(request);
}
public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException {
Method method = SimpleDBAsyncClient.class.getMethod("createDomainInRegion", String.class, String.class);
for (String region : Region.ALL_SIMPLEDB) {
processor.createRequest(method, region, "domainName");
}
// TODO fix this test as it has the wrong arg type
@Test(enabled = false)
public void testPutAttributes() throws SecurityException, NoSuchMethodException, IOException {
Method method = SimpleDBAsyncClient.class.getMethod("putAttributes", String.class, String.class, Map.class);
HttpRequest request = processor.createRequest(method, null, "domainName");
assertRequestLineEquals(request, "POST https://sdb.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: sdb.amazonaws.com\n");
assertPayloadEquals(request, "Version=2009-04-15&Action=PutAttributes&DomainName=domainName&ItemName=itemName"
+ "&Attribute.1.Name=name" + "&Attribute.1.Value=fuzzy" + "&Attribute.1.Replace=true",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
@Override
@ -120,7 +135,7 @@ public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient>
@Override
public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("simpledb", "identity", "credential", new Properties());
return new RestContextFactory().createContextSpec(provider, "identity", "credential", new Properties());
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb;
package org.jclouds.simpledb;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertNotNull;
@ -27,17 +27,15 @@ import java.util.Set;
import java.util.SortedSet;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.simpledb.domain.ListDomainsResponse;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.simpledb.domain.ListDomainsResponse;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.Module;
@ -46,14 +44,14 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "simpledb.SimpleDBClientLiveTest")
@Test(groups = "live", sequential = true)
public class SimpleDBClientLiveTest {
private SimpleDBClient client;
protected SimpleDBClient client;
private RestContext<SimpleDBClient, SimpleDBAsyncClient> context;
private Set<String> domains = Sets.newHashSet();
protected Set<String> domains = Sets.newHashSet();
protected String provider = "simpledb";
protected String identity;
protected String credential;
@ -92,48 +90,49 @@ public class SimpleDBClientLiveTest {
}
@Test
void testListDomainsInRegion() throws InterruptedException {
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1,
Region.AP_SOUTHEAST_1)) {
SortedSet<String> allResults = Sets.newTreeSet(client.listDomainsInRegion(region));
assertNotNull(allResults);
if (allResults.size() >= 1) {
String domain = allResults.last();
assertDomainInList(region, domain);
}
protected void testListDomains() throws InterruptedException {
listDomainInRegion(null);
}
protected void listDomainInRegion(String region) throws InterruptedException {
SortedSet<String> allResults = Sets.newTreeSet(client.listDomainsInRegion(region));
assertNotNull(allResults);
if (allResults.size() >= 1) {
String domain = allResults.last();
assertDomainInList(region, domain);
}
}
public static final String PREFIX = System.getProperty("user.name") + "-simpledb";
@Test
void testCreateDomain() throws InterruptedException {
String domainName = PREFIX + "1";
for (final String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1,
Region.AP_SOUTHEAST_1)) {
try {
SortedSet<String> result = Sets.newTreeSet(client.listDomainsInRegion(region));
if (result.size() >= 1) {
client.deleteDomainInRegion(region, result.last());
domainName += 1;// cannot recreate a domain within 60 seconds
}
} catch (Exception e) {
protected String createDomainInRegion(String region, String domainName) throws InterruptedException {
try {
SortedSet<String> result = Sets.newTreeSet(client.listDomainsInRegion(region));
if (result.size() >= 1) {
client.deleteDomainInRegion(region, result.last());
domainName += 1;// cannot recreate a domain within 60 seconds
}
client.createDomainInRegion(region, domainName);
} catch (Exception e) {
// TODO get the domain metadata and ensure the region is correct
// if (region != null)
// assertEquals(domain.getRegion(), region);
// assertEquals(domain.getName(), domainName);
assertDomainInList(region, domainName);
domains.add(domainName);
}
client.createDomainInRegion(region, domainName);
// TODO get the domain metadata and ensure the region is correct
// if (region != null)
// assertEquals(domain.getRegion(), region);
// assertEquals(domain.getName(), domainName);
assertDomainInList(region, domainName);
domains.add(domainName);
return domainName;
}
private void assertDomainInList(final String region, final String domain) throws InterruptedException {
@Test
protected void testCreateDomain() throws InterruptedException {
createDomainInRegion(null, PREFIX + "1");
}
protected void assertDomainInList(final String region, final String domain) throws InterruptedException {
assertEventually(new Runnable() {
public void run() {
ListDomainsResponse domains = client.listDomainsInRegion(region);

View File

@ -17,10 +17,10 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.options;
package org.jclouds.simpledb.options;
import static org.jclouds.aws.simpledb.options.ListDomainsOptions.Builder.maxNumberOfDomains;
import static org.jclouds.aws.simpledb.options.ListDomainsOptions.Builder.nextToken;
import static org.jclouds.simpledb.options.ListDomainsOptions.Builder.maxNumberOfDomains;
import static org.jclouds.simpledb.options.ListDomainsOptions.Builder.nextToken;
import static org.testng.Assert.assertEquals;
import java.util.Collections;

View File

@ -17,14 +17,14 @@
* ====================================================================
*/
package org.jclouds.aws.simpledb.xml;
package org.jclouds.simpledb.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.aws.simpledb.domain.ListDomainsResponse;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.simpledb.domain.ListDomainsResponse;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@ -34,11 +34,12 @@ import com.google.common.collect.ImmutableSet;
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "simpledb.ListDomainsResponseHandlerTest")
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "ListDomainsResponseHandlerTest")
public class ListDomainsResponseHandlerTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/simpledb/list_domains.xml");
InputStream is = getClass().getResourceAsStream("/list_domains.xml");
ListDomainsResponse result = factory.create(injector.getInstance(ListDomainsResponseHandler.class)).parse(is);

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

110
apis/sqs/pom.xml Normal file
View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds.api</groupId>
<artifactId>jclouds-apis-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sqs</artifactId>
<name>jcloud sqs api</name>
<description>jclouds components to access an implementation of Simple Queue Service</description>
<properties>
<test.sqs.endpoint>https://sqs.us-east-1.amazonaws.com</test.sqs.endpoint>
<test.sqs.apiversion>2009-02-01</test.sqs.apiversion>
<test.sqs.identity>${test.aws.identity}</test.sqs.identity>
<test.sqs.credential>${test.aws.credential}</test.sqs.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.sqs.endpoint</name>
<value>${test.sqs.endpoint}</value>
</property>
<property>
<name>test.sqs.apiversion</name>
<value>${test.sqs.apiversion}</value>
</property>
<property>
<name>test.sqs.identity</name>
<value>${test.sqs.identity}</value>
</property>
<property>
<name>test.sqs.credential</name>
<value>${test.sqs.credential}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -82,7 +82,6 @@ public interface AtmosStorageAsyncClient {
* @see AtmosStorageClient#listDirectories
*/
@GET
@Path("")
@ResponseParser(ParseDirectoryListFromContentAndHeaders.class)
@Consumes(MediaType.TEXT_XML)
ListenableFuture<BoundedSet<? extends DirectoryEntry>> listDirectories(ListOptions... options);

View File

@ -41,7 +41,7 @@ public class AtmosStorageResponseException extends HttpResponseException {
public AtmosStorageResponseException(HttpCommand command, HttpResponse response,
AtmosStorageError error) {
super(String.format("command %s failed with code %s, error: %s", command.getRequest()
super(String.format("command %s failed with code %s, error: %s", command.getCurrentRequest()
.getRequestLine(), response.getStatusCode(), error.toString()), command, response);
this.setError(error);
@ -49,7 +49,7 @@ public class AtmosStorageResponseException extends HttpResponseException {
public AtmosStorageResponseException(HttpCommand command, HttpResponse response,
AtmosStorageError error, Throwable cause) {
super(String.format("command %1$s failed with error: %2$s", command.getRequest()
super(String.format("command %1$s failed with error: %2$s", command.getCurrentRequest()
.getRequestLine(), error.toString()), command, response, cause);
this.setError(error);

View File

@ -20,28 +20,36 @@
package org.jclouds.atmosonline.saas.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
/**
* @author Adrian Cole
*/
@Singleton
public class BindMetadataToHeaders implements Binder {
private final BindUserMetadataToHeaders metaBinder;
@Inject
protected BindMetadataToHeaders(BindUserMetadataToHeaders metaBinder, Crypto crypto) {
protected BindMetadataToHeaders(BindUserMetadataToHeaders metaBinder) {
this.metaBinder = metaBinder;
}
public void bindToRequest(HttpRequest request, Object payload) {
AtmosObject object = (AtmosObject) payload;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof AtmosObject, "this binder is only valid for AtmosObject!");
checkNotNull(request, "request");
AtmosObject object = AtmosObject.class.cast(input);
checkNotNull(object.getPayload(), "object payload");
checkArgument(object.getPayload().getContentMetadata().getContentLength() != null,
"contentLength must be set, streaming not supported");
metaBinder.bindToRequest(request, object.getUserMetadata());
"contentLength must be set, streaming not supported");
return metaBinder.bindToRequest(request, object.getUserMetadata());
}
}

View File

@ -19,36 +19,57 @@
package org.jclouds.atmosonline.saas.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.domain.UserMetadata;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.utils.ModifyRequest;
import org.jclouds.rest.Binder;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Multimaps;
/**
* @author Adrian Cole
*/
@Singleton
public class BindUserMetadataToHeaders implements Binder {
public class BindUserMetadataToHeaders implements Binder, Function<UserMetadata, Map<String, String>> {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof UserMetadata,
"this binder is only valid for UserMetadatas!");
checkNotNull(request, "request");
public void bindToRequest(HttpRequest request, Object payload) {
UserMetadata md = (UserMetadata) checkNotNull(payload, "payload");
return ModifyRequest.putHeaders(request, Multimaps.forMap(apply(UserMetadata.class.cast(input))));
}
@Override
public Map<String, String> apply(UserMetadata md) {
Builder<String, String> headers = ImmutableMap.<String, String> builder();
if (md.getMetadata().size() > 0) {
String header = Joiner.on(',').withKeyValueSeparator("=").join(md.getMetadata());
request.getHeaders().put("x-emc-meta", header);
headers.put("x-emc-meta", header);
}
if (md.getListableMetadata().size() > 0) {
String header = Joiner.on(',').withKeyValueSeparator("=").join(md.getListableMetadata());
request.getHeaders().put("x-emc-listable-meta", header);
headers.put("x-emc-listable-meta", header);
}
if (md.getTags().size() > 0) {
String header = Joiner.on(',').join(md.getTags());
request.getHeaders().put("x-emc-tags", header);
headers.put("x-emc-tags", header);
}
if (md.getListableTags().size() > 0) {
String header = Joiner.on(',').join(md.getListableTags());
request.getHeaders().put("x-emc-listable-tags", header);
headers.put("x-emc-listable-tags", header);
}
return headers.build();
}
}

View File

@ -41,7 +41,7 @@ import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.rest.annotations.Provider;
import org.jclouds.location.Provider;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;

Some files were not shown because too many files have changed in this diff Show More