mirror of https://github.com/apache/jclouds.git
Issue 310: added simpledb client
This commit is contained in:
parent
5f6cc052ce
commit
19a8ce4db2
|
@ -28,7 +28,8 @@ import com.google.common.collect.ImmutableSet;
|
|||
* Regions used for all aws commands.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?LocationSelection.html"
|
||||
* @see <a
|
||||
* href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?LocationSelection.html"
|
||||
* />
|
||||
*
|
||||
*/
|
||||
|
@ -38,9 +39,8 @@ public class Region {
|
|||
* <p/>
|
||||
* <h3>S3</h3>
|
||||
* <p/>
|
||||
* In Amazon S3, the EU (Ireland) Region provides read-after-write
|
||||
* consistency for PUTS of new objects in your Amazon S3 bucket and eventual
|
||||
* consistency for overwrite PUTS and DELETES.
|
||||
* In Amazon S3, the EU (Ireland) Region provides read-after-write consistency for PUTS of new
|
||||
* objects in your Amazon S3 bucket and eventual consistency for overwrite PUTS and DELETES.
|
||||
*/
|
||||
public static final String EU = "EU";
|
||||
|
||||
|
@ -52,13 +52,11 @@ public class Region {
|
|||
* <p/>
|
||||
* <h3>S3</h3>
|
||||
* <p/>
|
||||
* This is the default Region. All requests sent to s3.amazonaws.com go to
|
||||
* this Region unless you specify a LocationConstraint on a bucket. The US
|
||||
* Standard Region automatically places your data in either Amazon's east or
|
||||
* west coast data centers depending on what will provide you with the lowest
|
||||
* latency. To use this region, do not set the LocationConstraint bucket
|
||||
* parameter. The US Standard Region provides eventual consistency for all
|
||||
* requests.
|
||||
* This is the default Region. All requests sent to s3.amazonaws.com go to this Region unless you
|
||||
* specify a LocationConstraint on a bucket. The US Standard Region automatically places your
|
||||
* data in either Amazon's east or west coast data centers depending on what will provide you
|
||||
* with the lowest latency. To use this region, do not set the LocationConstraint bucket
|
||||
* parameter. The US Standard Region provides eventual consistency for all requests.
|
||||
*/
|
||||
public static final String US_STANDARD = "us-standard";
|
||||
|
||||
|
@ -68,27 +66,25 @@ public class Region {
|
|||
public static final String US_EAST_1 = "us-east-1";
|
||||
|
||||
/**
|
||||
* US-West (Northern California) <h3>S3</h3> Uses Amazon S3 servers in
|
||||
* Northern California
|
||||
* US-West (Northern California) <h3>S3</h3> Uses Amazon S3 servers in Northern California
|
||||
* <p/>
|
||||
* Optionally, use the endpoint s3-us-west-1.amazonaws.com on all requests to
|
||||
* this bucket to reduce the latency you might experience after the first
|
||||
* hour of creating a bucket in this Region.
|
||||
* Optionally, use the endpoint s3-us-west-1.amazonaws.com on all requests to this bucket to
|
||||
* reduce the latency you might experience after the first hour of creating a bucket in this
|
||||
* Region.
|
||||
* <p/>
|
||||
* In Amazon S3, the US-West (Northern California) Region provides
|
||||
* read-after-write consistency for PUTS of new objects in your Amazon S3
|
||||
* bucket and eventual consistency for overwrite PUTS and DELETES.
|
||||
* In Amazon S3, the US-West (Northern California) Region provides read-after-write consistency
|
||||
* for PUTS of new objects in your Amazon S3 bucket and eventual consistency for overwrite PUTS
|
||||
* and DELETES.
|
||||
*/
|
||||
public static final String US_WEST_1 = "us-west-1";
|
||||
|
||||
/**
|
||||
* Region in Singapore, launched April 28, 2010. This region improves latency
|
||||
* for Asia-based users
|
||||
* Region in Singapore, launched April 28, 2010. This region improves latency for Asia-based
|
||||
* users
|
||||
*/
|
||||
public static final String AP_SOUTHEAST_1 = "ap-southeast-1";
|
||||
|
||||
public static Set<String> ALL_S3 = ImmutableSet.of(EU, US_STANDARD,
|
||||
US_WEST_1, AP_SOUTHEAST_1);
|
||||
public static Set<String> ALL_SQS = ImmutableSet.of(EU_WEST_1, US_STANDARD,
|
||||
US_EAST_1, US_WEST_1, AP_SOUTHEAST_1);
|
||||
public static Set<String> ALL_SIMPLEDB = ImmutableSet.of(EU_WEST_1, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1);
|
||||
public static Set<String> ALL_S3 = ImmutableSet.of(EU, US_STANDARD, US_WEST_1, AP_SOUTHEAST_1);
|
||||
public static Set<String> ALL_SQS = ImmutableSet.of(EU_WEST_1, US_STANDARD, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1);
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb;
|
||||
|
||||
import static org.jclouds.aws.simpledb.reference.SimpleDBParameters.ACTION;
|
||||
import static org.jclouds.aws.simpledb.reference.SimpleDBParameters.VERSION;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.ws.rs.FormParam;
|
||||
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.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 com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides access to SimpleDB via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(FormSigner.class)
|
||||
@FormParams(keys = VERSION, values = SimpleDBAsyncClient.VERSION)
|
||||
@VirtualHost
|
||||
public interface SimpleDBAsyncClient {
|
||||
public static final String VERSION = "2009-04-15";
|
||||
|
||||
/**
|
||||
* @see SimpleDBClient#listDomainsInRegion
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@FormParams(keys = ACTION, values = "ListDomains")
|
||||
@XMLResponseParser(ListDomainsResponseHandler.class)
|
||||
ListenableFuture<? extends ListDomainsResponse> listDomainsInRegion(
|
||||
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, ListDomainsOptions... options);
|
||||
|
||||
/**
|
||||
* @see SimpleDBClient#createDomainInRegion
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@FormParams(keys = ACTION, values = "CreateDomain")
|
||||
ListenableFuture<Void> createDomainInRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
|
||||
@FormParam("DomainName") String domainName);
|
||||
|
||||
/**
|
||||
* @see SimpleDBClient#deleteDomain
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@FormParams(keys = ACTION, values = "DeleteDomain")
|
||||
ListenableFuture<Void> deleteDomainInRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
|
||||
@FormParam("DomainName") String domainName);
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Provides access to SimpleDB via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface SimpleDBClient {
|
||||
|
||||
/**
|
||||
* The ListDomains operation lists all domains associated with the Access Key ID. It returns
|
||||
* domain names up to the limit set by MaxNumberOfDomains. A NextToken is returned if there are
|
||||
* more than MaxNumberOfDomains domains. Calling ListDomains successive times with the NextToken
|
||||
* returns up to MaxNumberOfDomains more domain names each time.
|
||||
*
|
||||
*
|
||||
* @param region
|
||||
* Domains are Region-specific.
|
||||
* @param options
|
||||
* specify result count or other options
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/SDB_API_ListDomains.html"
|
||||
* />
|
||||
*/
|
||||
ListDomainsResponse listDomainsInRegion(@Nullable String region, ListDomainsOptions... options);
|
||||
|
||||
/**
|
||||
* The CreateDomain operation creates a new domain.
|
||||
*
|
||||
* <p/>
|
||||
* The domain name must be unique among the domains associated with the Access Key ID provided in
|
||||
* the request. The CreateDomain operation might take 10 or more seconds to complete.
|
||||
*
|
||||
*
|
||||
* <h3>Note</h3>
|
||||
* CreateDomain is an idempotent operation; running it multiple times using the same domain name
|
||||
* will not result in an error response.
|
||||
* <p/>
|
||||
* 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/.
|
||||
*
|
||||
* @param region
|
||||
* Domains are Region-specific.
|
||||
* @param domainName
|
||||
* The name of the domain to create. The name can range between 3 and 255 characters
|
||||
* and can contain the following characters: a-z, A-Z, 0-9, '_', '-', and '.'.
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/SDB_API_ListDomains.html"
|
||||
* />
|
||||
*/
|
||||
void createDomainInRegion(@Nullable String region, String domainName);
|
||||
|
||||
/**
|
||||
* The DeleteDomain operation deletes a domain. Any items (and their attributes) in the domain
|
||||
* are deleted as well. The DeleteDomain operation might take 10 or more seconds to complete. <h3>
|
||||
* Note</h3>
|
||||
*
|
||||
* Running DeleteDomain on a domain that does not exist or running the function multiple times
|
||||
* using the same domain name will not result in an error response.
|
||||
*
|
||||
*
|
||||
* @param region
|
||||
* Domains are Region-specific.
|
||||
* @param domainName
|
||||
* The name of the domain to delete.
|
||||
*
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/SDB_API_ListDomains.html"
|
||||
* />
|
||||
*/
|
||||
void deleteDomainInRegion(String region, String domainName);
|
||||
|
||||
}
|
|
@ -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.aws.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 com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Creates {@link SimpleDBContext} or {@link Injector} instances based on the most commonly requested
|
||||
* arguments.
|
||||
* <p/>
|
||||
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
|
||||
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see SimpleDBContext
|
||||
*/
|
||||
public class SimpleDBContextBuilder extends RestContextBuilder<SimpleDBClient, SimpleDBAsyncClient> {
|
||||
|
||||
public SimpleDBContextBuilder(Properties props) {
|
||||
super(SimpleDBClient.class, SimpleDBAsyncClient.class, props);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new SimpleDBRestClientModule());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.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
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
public SimpleDBPropertiesBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SimpleDBPropertiesBuilder(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.aws.simpledb.config;
|
||||
|
||||
import org.jclouds.aws.config.AWSFormSigningRestClientModule;
|
||||
import org.jclouds.aws.simpledb.SimpleDBAsyncClient;
|
||||
import org.jclouds.aws.simpledb.SimpleDBClient;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
/**
|
||||
* Configures the SimpleDB connection.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class SimpleDBRestClientModule extends AWSFormSigningRestClientModule<SimpleDBClient, SimpleDBAsyncClient> {
|
||||
|
||||
public SimpleDBRestClientModule() {
|
||||
super(SimpleDBClient.class, SimpleDBAsyncClient.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,190 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/index.html?SDB_API_CreateDomain.html"
|
||||
* />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DomainMetadata {
|
||||
private final String region;
|
||||
private final String name;
|
||||
private final Date timestamp;
|
||||
private final long itemCount;
|
||||
private final long attributeValueCount;
|
||||
private final long attributeNameCount;
|
||||
private final long itemNamesSizeBytes;
|
||||
private final long attributeValuesSizeBytes;
|
||||
private final long attributeNamesSizeBytes;
|
||||
|
||||
public DomainMetadata(String region, String name, Date timestamp, long itemCount, long attributeValueCount,
|
||||
long attributeNameCount, long itemNamesSizeBytes, long attributeValuesSizeBytes, long attributeNamesSizeBytes) {
|
||||
this.region = region;
|
||||
this.name = name;
|
||||
this.timestamp = timestamp;
|
||||
this.itemCount = itemCount;
|
||||
this.attributeValueCount = attributeValueCount;
|
||||
this.attributeNameCount = attributeNameCount;
|
||||
this.itemNamesSizeBytes = itemNamesSizeBytes;
|
||||
this.attributeValuesSizeBytes = attributeValuesSizeBytes;
|
||||
this.attributeNamesSizeBytes = attributeNamesSizeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return region the domain belongs to
|
||||
*/
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return name of the domain
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The number of all items in the domain.
|
||||
*/
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getItemCount() {
|
||||
return itemCount;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The number of all attribute name/value pairs in the domain.
|
||||
*/
|
||||
public long getAttributeValueCount() {
|
||||
return attributeValueCount;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The number of unique attribute names in the domain.
|
||||
*/
|
||||
public long getAttributeNameCount() {
|
||||
return attributeNameCount;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The total size of all item names in the domain, in bytes.
|
||||
*/
|
||||
public long getItemNamesSizeBytes() {
|
||||
return itemNamesSizeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The total size of all attribute values, in bytes.
|
||||
*/
|
||||
public long getAttributeValuesSizeBytes() {
|
||||
return attributeValuesSizeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The total size of all unique attribute names, in bytes.
|
||||
*/
|
||||
public long getAttributeNamesSizeBytes() {
|
||||
return attributeNamesSizeBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (attributeNameCount ^ (attributeNameCount >>> 32));
|
||||
result = prime * result + (int) (attributeNamesSizeBytes ^ (attributeNamesSizeBytes >>> 32));
|
||||
result = prime * result + (int) (attributeValueCount ^ (attributeValueCount >>> 32));
|
||||
result = prime * result + (int) (attributeValuesSizeBytes ^ (attributeValuesSizeBytes >>> 32));
|
||||
result = prime * result + (int) (itemCount ^ (itemCount >>> 32));
|
||||
result = prime * result + (int) (itemNamesSizeBytes ^ (itemNamesSizeBytes >>> 32));
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((region == null) ? 0 : region.hashCode());
|
||||
result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DomainMetadata other = (DomainMetadata) obj;
|
||||
if (attributeNameCount != other.attributeNameCount)
|
||||
return false;
|
||||
if (attributeNamesSizeBytes != other.attributeNamesSizeBytes)
|
||||
return false;
|
||||
if (attributeValueCount != other.attributeValueCount)
|
||||
return false;
|
||||
if (attributeValuesSizeBytes != other.attributeValuesSizeBytes)
|
||||
return false;
|
||||
if (itemCount != other.itemCount)
|
||||
return false;
|
||||
if (itemNamesSizeBytes != other.itemNamesSizeBytes)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (region == null) {
|
||||
if (other.region != null)
|
||||
return false;
|
||||
} else if (!region.equals(other.region))
|
||||
return false;
|
||||
if (timestamp == null) {
|
||||
if (other.timestamp != null)
|
||||
return false;
|
||||
} else if (!timestamp.equals(other.timestamp))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[region=" + region + ", name=" + name + ", timestamp=" + timestamp + ", itemCount=" + itemCount
|
||||
+ ", attributeValueCount=" + attributeValueCount + ", attributeNameCount=" + attributeNameCount
|
||||
+ ", itemNamesSizeBytes=" + itemNamesSizeBytes + ", attributeValuesSizeBytes=" + attributeValuesSizeBytes
|
||||
+ ", attributeNamesSizeBytes=" + attributeNamesSizeBytes + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb.domain;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html" />
|
||||
*/
|
||||
public interface ListDomainsResponse extends Set<String> {
|
||||
|
||||
/**
|
||||
* An opaque token indicating that there are more than MaxNumberOfDomains domains still
|
||||
* available.
|
||||
*/
|
||||
String getNextToken();
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb.options;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Contains options supported in the Form API for the ListDomains operation. <h2>
|
||||
* Usage</h2> The recommended way to instantiate a ListDomainsOptions object is to statically import
|
||||
* ListDomainsOptions.Builder.* and invoke a static creation method followed by an instance mutator
|
||||
* (if needed):
|
||||
* <p/>
|
||||
* <code>
|
||||
* import static org.jclouds.aws.simpledb.options.ListDomainsOptions.Builder.*
|
||||
* <p/>
|
||||
* SimpleDBClient connection = // get connection
|
||||
* Set<String> domains = connection.listDomainsInRegion(maxNumberOfDomains(1));
|
||||
* <code>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/SDB_API_ListDomains.html"
|
||||
* />
|
||||
*/
|
||||
public class ListDomainsOptions extends BaseHttpRequestOptions {
|
||||
|
||||
/**
|
||||
* The maximum number of domain names you want returned.
|
||||
*
|
||||
* @param maxNumberOfDomains
|
||||
* Maximum 100
|
||||
*/
|
||||
public ListDomainsOptions maxNumberOfDomains(int maxNumberOfDomains) {
|
||||
checkArgument(maxNumberOfDomains > 0 && maxNumberOfDomains <= 100, "must be between 1-100");
|
||||
formParameters.put("MaxNumberOfDomains", maxNumberOfDomains + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getMaxNumberOfDomains() {
|
||||
return getFirstFormOrNull("MaxNumberOfDomains");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nextToken
|
||||
* tells Amazon SimpleDB where to start the next list of domain names.
|
||||
*/
|
||||
public ListDomainsOptions nextToken(String nextToken) {
|
||||
checkNotNull(nextToken, "nextToken");
|
||||
formParameters.put("NextToken", nextToken);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return String that tells Amazon SimpleDB where to start the next list of domain names.
|
||||
*/
|
||||
public String getNextToken() {
|
||||
return getFirstFormOrNull("NextToken");
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#nextToken
|
||||
*/
|
||||
public static ListDomainsOptions nextToken(String nextToken) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.nextToken(nextToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#maxNumberOfDomains
|
||||
*/
|
||||
public static ListDomainsOptions maxNumberOfDomains(int maxNumberOfDomains) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.maxNumberOfDomains(maxNumberOfDomains);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @see <a href="http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/index.html"/>
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
package org.jclouds.aws.simpledb;
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb.reference;
|
||||
|
||||
/**
|
||||
* Configuration properties and constants used in SimpleDB connections.
|
||||
*
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSSimpleDomainService/2009-02-01/APIReference/Query_QueryParams.html"
|
||||
* />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface SimpleDBParameters {
|
||||
|
||||
/**
|
||||
* The action to perform. For example: CreateDomain.
|
||||
*/
|
||||
public static final String ACTION = "Action";
|
||||
|
||||
/**
|
||||
* The API version to use, as specified in the WSDL. For example: 2009-02-01.
|
||||
*/
|
||||
public static final String VERSION = "Version";
|
||||
|
||||
/**
|
||||
* Your Access Key ID. For example: 0AS7253JW73RRM652K02. For more information, see Your AWS
|
||||
* Identifiers in the Amazon SimpleDB Developer Guide.
|
||||
*/
|
||||
public static final String AWS_ACCESS_KEY_ID = "AWSAccessKeyId";
|
||||
|
||||
/**
|
||||
* The date and time the request is signed, in the format YYYY-MM-DDThh:mm:ssZ, as specified in
|
||||
* the ISO 8601 standard. Query requests must include either Timestamp or Expires, but not both.
|
||||
*
|
||||
*/
|
||||
public static final String TIMESTAMP = "Timestamp";
|
||||
|
||||
/**
|
||||
* The date and time at which the signature included in the request expires, in the format
|
||||
* YYYY-MM-DDThh:mm:ssZ, as specified in the ISO 8601 standard. Query requests must include
|
||||
* either Timestamp or Expires, but not both.
|
||||
*/
|
||||
public static final String EXPIRES = "Expires";
|
||||
/**
|
||||
* A request signature (for information, see Request Authentication in the Amazon SimpleDB Developer
|
||||
* Guide). For example: Qnpl4Qk/7tINHzfXCiT7VbBatDA=.
|
||||
*/
|
||||
public static final String SIGNATURE = "Signature";
|
||||
/**
|
||||
*Required when you use signature version 2 with Query requests. For more information, see Query
|
||||
* Request Authentication in the Amazon SimpleDB Developer Guide.
|
||||
*/
|
||||
public static final String SIGNATURE_METHOD = "SignatureMethod";
|
||||
/**
|
||||
* For more information, see Query Request Authentication in the Amazon SimpleDB Developer Guide.
|
||||
*/
|
||||
public static final String SIGNATURE_VERSION = "SignatureVersion";
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* This package contains properties and reference data used in SimpleDB.
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
package org.jclouds.aws.simpledb.reference;
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb.xml;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.simpledb.domain.ListDomainsResponse;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Parses the following XML document:
|
||||
* <p/>
|
||||
* ListDomainsResponse
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/SDB_API_ListDomains.htm l"
|
||||
* />
|
||||
*/
|
||||
public class ListDomainsResponseHandler extends ParseSax.HandlerWithResult<ListDomainsResponse> {
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private Set<String> domains = Sets.newLinkedHashSet();
|
||||
private String nextToken;
|
||||
|
||||
@Override
|
||||
public ListDomainsResponse getResult() {
|
||||
return new ListDomainsResponseImpl(domains, nextToken);
|
||||
}
|
||||
|
||||
public static class ListDomainsResponseImpl extends LinkedHashSet<String> implements ListDomainsResponse {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final String nextToken;
|
||||
|
||||
public ListDomainsResponseImpl(Iterable<String> domains, String nextToken) {
|
||||
Iterables.addAll(this, domains);
|
||||
this.nextToken = nextToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNextToken() {
|
||||
return nextToken;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (qName.equals("DomainName")) {
|
||||
domains.add(currentText.toString().trim());
|
||||
} else if (qName.equals("NextToken")) {
|
||||
if (!currentText.toString().equals(""))
|
||||
this.nextToken = currentText.toString().trim();
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
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;
|
||||
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.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SimpleDBAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "simpledb.SimpleDBAsyncClientTest")
|
||||
public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient> {
|
||||
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
private static final class TestSimpleDBRestClientModule extends SimpleDBRestClientModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testListDomainsInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SimpleDBAsyncClient.class.getMethod("listDomainsInRegion", String.class,
|
||||
ListDomainsOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sdb.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sdb.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-04-15&Action=ListDomains", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ListDomainsResponseHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateDomainInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SimpleDBAsyncClient.class.getMethod("createDomainInRegion", String.class, String.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=CreateDomain&DomainName=domainName",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), FormSigner.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<SimpleDBAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<SimpleDBAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new TestSimpleDBRestClientModule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("simpledb", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.simpledb;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SimpleDBClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "simpledb.SimpleDBClientLiveTest")
|
||||
public class SimpleDBClientLiveTest {
|
||||
|
||||
private SimpleDBClient client;
|
||||
|
||||
private RestContext<SimpleDBClient, SimpleDBAsyncClient> context;
|
||||
|
||||
private Set<String> domains = Sets.newHashSet();
|
||||
protected String provider = "simpledb";
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
|
||||
+ ".credential");
|
||||
endpoint = System.getProperty("test." + provider + ".endpoint");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
}
|
||||
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
|
||||
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
|
||||
overrides.setProperty(provider + ".identity", identity);
|
||||
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;
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new Log4JLoggingModule()),
|
||||
overrides);
|
||||
this.client = context.getApi();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertDomainInList(final String region, final String domain) throws InterruptedException {
|
||||
assertEventually(new Runnable() {
|
||||
public void run() {
|
||||
ListDomainsResponse domains = client.listDomainsInRegion(region);
|
||||
assert domains.contains(domain) : domain + " not in " + domains;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final int INCONSISTENCY_WINDOW = 10000;
|
||||
|
||||
/**
|
||||
* Due to eventual consistency, container commands may not return correctly immediately. Hence,
|
||||
* we will try up to the inconsistency window to see if the assertion completes.
|
||||
*/
|
||||
protected static void assertEventually(Runnable assertion) throws InterruptedException {
|
||||
long start = System.currentTimeMillis();
|
||||
AssertionError error = null;
|
||||
for (int i = 0; i < 30; i++) {
|
||||
try {
|
||||
assertion.run();
|
||||
if (i > 0)
|
||||
System.err.printf("%d attempts and %dms asserting %s%n", i + 1, System.currentTimeMillis() - start,
|
||||
assertion.getClass().getSimpleName());
|
||||
return;
|
||||
} catch (AssertionError e) {
|
||||
error = e;
|
||||
}
|
||||
Thread.sleep(INCONSISTENCY_WINDOW / 30);
|
||||
}
|
||||
if (error != null)
|
||||
throw error;
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void shutdown() {
|
||||
context.close();
|
||||
}
|
||||
}
|
|
@ -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.aws.simpledb.config;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
|
||||
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
|
||||
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
|
||||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "simpledb.SimpleDBRestClientModuleTest")
|
||||
public class SimpleDBRestClientModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
return new RestContextFactory().createContextBuilder("simpledb", "uid", "key",
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServerErrorHandler() {
|
||||
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
|
||||
assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegions() {
|
||||
Map<String, URI> regionMap = createInjector().getInstance(
|
||||
new Key<Map<String, URI>>(org.jclouds.aws.Region.class) {
|
||||
});
|
||||
assertEquals(regionMap, ImmutableMap.<String, URI> of(Region.US_EAST_1, URI
|
||||
.create("https://sdb.amazonaws.com"), Region.US_WEST_1, URI
|
||||
.create("https://sdb.us-west-1.amazonaws.com"), Region.EU_WEST_1, URI
|
||||
.create("https://sdb.eu-west-1.amazonaws.com"), Region.AP_SOUTHEAST_1, URI
|
||||
.create("https://sdb.ap-southeast-1.amazonaws.com")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClientErrorHandler() {
|
||||
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
|
||||
assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClientRetryHandler() {
|
||||
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
|
||||
assertEquals(handler.getClientErrorRetryHandler().getClass(),
|
||||
AWSClientErrorRetryHandler.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedirectionRetryHandler() {
|
||||
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
|
||||
assertEquals(handler.getRedirectionRetryHandler().getClass(),
|
||||
AWSRedirectionRetryHandler.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.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.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.jclouds.http.options.HttpRequestOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests possible uses of ListDomainsOptions and ListDomainsOptions.Builder.*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListDomainsOptionsTest {
|
||||
|
||||
@Test
|
||||
public void testAssignability() {
|
||||
assert HttpRequestOptions.class.isAssignableFrom(ListDomainsOptions.class);
|
||||
assert !String.class.isAssignableFrom(ListDomainsOptions.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextToken() {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
options.nextToken("test");
|
||||
assertEquals(options.buildFormParameters().get("NextToken"), Collections.singletonList("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullNextToken() {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
assertEquals(options.buildFormParameters().get("NextToken"), Collections.EMPTY_LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextTokenStatic() {
|
||||
ListDomainsOptions options = nextToken("test");
|
||||
assertEquals(options.buildFormParameters().get("NextToken"), Collections.singletonList("test"));
|
||||
}
|
||||
|
||||
public void testInvalidMaxNumberOfDomainsZero() {
|
||||
maxNumberOfDomains(0);
|
||||
}
|
||||
|
||||
public void testInvalidMaxNumberOfDomainsOver100() {
|
||||
maxNumberOfDomains(101);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxNumberOfDomains() {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
options.maxNumberOfDomains(1);
|
||||
assertEquals(options.buildFormParameters().get("MaxNumberOfDomains"), Collections.singletonList("1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullMaxNumberOfDomains() {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
assertEquals(options.buildFormParameters().get("MaxNumberOfDomains"), Collections.EMPTY_LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxNumberOfDomainsStatic() {
|
||||
ListDomainsOptions options = maxNumberOfDomains(1);
|
||||
assertEquals(options.buildFormParameters().get("MaxNumberOfDomains"), Collections.singletonList("1"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
*
|
||||
* 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.aws.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.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListDomainsResponseHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "simpledb.ListDomainsResponseHandlerTest")
|
||||
public class ListDomainsResponseHandlerTest extends BaseHandlerTest {
|
||||
|
||||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/simpledb/list_domains.xml");
|
||||
|
||||
ListDomainsResponse result = factory.create(injector.getInstance(ListDomainsResponseHandler.class)).parse(is);
|
||||
|
||||
assertEquals(
|
||||
result,
|
||||
new ListDomainsResponseHandler.ListDomainsResponseImpl(ImmutableSet.of("Domain1-200706011651",
|
||||
"Domain2-200706011652"), "TWV0ZXJpbmdUZXN0RG9tYWluMS0yMDA3MDYwMTE2NTY"));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<ListDomainsResponse>
|
||||
<ListDomainsResult>
|
||||
<DomainName>Domain1-200706011651</DomainName>
|
||||
<DomainName>Domain2-200706011652</DomainName>
|
||||
<NextToken>TWV0ZXJpbmdUZXN0RG9tYWluMS0yMDA3MDYwMTE2NTY=</NextToken>
|
||||
</ListDomainsResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>eb13162f-1b95-4511-8b12-489b86acfd28</RequestId>
|
||||
<BoxUsage>0.0000219907</BoxUsage>
|
||||
</ResponseMetadata>
|
||||
</ListDomainsResponse>
|
20
aws/pom.xml
20
aws/pom.xml
|
@ -42,6 +42,10 @@
|
|||
<test.aws.credential>FIXME</test.aws.credential>
|
||||
<!-- when instances are hung, open a ticket and add here -->
|
||||
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes>
|
||||
<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>
|
||||
<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>
|
||||
|
@ -187,6 +191,22 @@
|
|||
<name>jclouds.compute.blacklist.nodes</name>
|
||||
<value>${jclouds.compute.blacklist.nodes}</value>
|
||||
</property>
|
||||
<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>
|
||||
<property>
|
||||
<name>test.sqs.endpoint</name>
|
||||
<value>${test.sqs.endpoint}</value>
|
||||
|
|
|
@ -35,6 +35,9 @@ sdn.propertiesbuilder=org.jclouds.nirvanix.sdn.SDNPropertiesBuilder
|
|||
sqs.contextbuilder=org.jclouds.aws.sqs.SQSContextBuilder
|
||||
sqs.propertiesbuilder=org.jclouds.aws.sqs.SQSPropertiesBuilder
|
||||
|
||||
simpledb.contextbuilder=org.jclouds.aws.simpledb.SimpleDBContextBuilder
|
||||
simpledb.propertiesbuilder=org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder
|
||||
|
||||
elb.contextbuilder=org.jclouds.aws.elb.ELBContextBuilder
|
||||
elb.propertiesbuilder=org.jclouds.aws.elb.ELBPropertiesBuilder
|
||||
|
||||
|
|
Loading…
Reference in New Issue