From 05a7f5233b7e69692939c1e9b91e51f6f8576773 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Mon, 11 Jan 2010 00:08:04 +0000 Subject: [PATCH] Issue 146: initial support for amazon SQS git-svn-id: http://jclouds.googlecode.com/svn/trunk@2627 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../jclouds/aws/{ec2 => }/domain/Region.java | 4 +- .../jclouds/aws/ec2/EC2ContextFactory.java | 6 + .../jclouds/aws/ec2/EC2PropertiesBuilder.java | 6 +- .../aws/ec2/compute/EC2ComputeService.java | 2 +- .../aws/ec2/config/EC2RestClientModule.java | 6 +- .../jclouds/aws/ec2/domain/Attachment.java | 2 + .../aws/ec2/domain/AvailabilityZoneInfo.java | 2 + .../org/jclouds/aws/ec2/domain/Image.java | 2 + .../aws/ec2/domain/InstanceStateChange.java | 2 + .../org/jclouds/aws/ec2/domain/KeyPair.java | 2 + .../ec2/domain/PublicIpInstanceIdPair.java | 2 + .../jclouds/aws/ec2/domain/Reservation.java | 2 + .../aws/ec2/domain/RunningInstance.java | 1 + .../jclouds/aws/ec2/domain/SecurityGroup.java | 2 + .../org/jclouds/aws/ec2/domain/Snapshot.java | 2 + .../org/jclouds/aws/ec2/domain/Volume.java | 2 + .../functions/AvailabilityZoneToEndpoint.java | 2 +- .../aws/ec2/functions/RegionToEndpoint.java | 2 +- .../ec2/options/DescribeRegionsOptions.java | 2 +- .../ec2/predicates/InstanceHasIpAddress.java | 2 +- .../ec2/predicates/InstanceStateRunning.java | 2 +- .../ec2/predicates/InstanceStateStopped.java | 2 +- .../predicates/InstanceStateTerminated.java | 2 +- .../aws/ec2/reference/EC2Constants.java | 4 - .../aws/ec2/services/AMIAsyncClient.java | 4 +- .../jclouds/aws/ec2/services/AMIClient.java | 2 +- .../AvailabilityZoneAndRegionAsyncClient.java | 4 +- .../AvailabilityZoneAndRegionClient.java | 2 +- .../ElasticBlockStoreAsyncClient.java | 4 +- .../ec2/services/ElasticBlockStoreClient.java | 2 +- .../services/ElasticIPAddressAsyncClient.java | 4 +- .../ec2/services/ElasticIPAddressClient.java | 2 +- .../aws/ec2/services/InstanceAsyncClient.java | 4 +- .../aws/ec2/services/InstanceClient.java | 2 +- .../aws/ec2/services/KeyPairAsyncClient.java | 10 +- .../aws/ec2/services/KeyPairClient.java | 2 +- .../ec2/services/MonitoringAsyncClient.java | 4 +- .../aws/ec2/services/MonitoringClient.java | 2 +- .../services/SecurityGroupAsyncClient.java | 4 +- .../aws/ec2/services/SecurityGroupClient.java | 2 +- .../org/jclouds/aws/ec2/util/EC2Utils.java | 2 +- .../ec2/xml/CreateVolumeResponseHandler.java | 2 +- ...cribeAvailabilityZonesResponseHandler.java | 2 +- .../xml/DescribeRegionsResponseHandler.java | 2 +- .../aws/{ec2 => }/filters/FormSigner.java | 2 +- .../jclouds/aws/reference/AWSConstants.java | 4 + .../org/jclouds/aws/s3/S3ContextFactory.java | 10 +- .../blobstore/S3BlobStoreContextFactory.java | 13 +- .../main/java/org/jclouds/aws/sqs/SQS.java | 39 ++++ .../org/jclouds/aws/sqs/SQSAsyncClient.java | 99 ++++++++++ .../java/org/jclouds/aws/sqs/SQSClient.java | 127 ++++++++++++ .../jclouds/aws/sqs/SQSContextBuilder.java | 76 +++++++ .../jclouds/aws/sqs/SQSContextFactory.java | 67 +++++++ .../jclouds/aws/sqs/SQSPropertiesBuilder.java | 75 +++++++ .../aws/sqs/config/SQSContextModule.java | 59 ++++++ .../aws/sqs/config/SQSRestClientModule.java | 128 ++++++++++++ .../org/jclouds/aws/sqs/domain/Queue.java | 104 ++++++++++ .../aws/sqs/functions/QueueLocation.java | 40 ++++ .../aws/sqs/functions/RegionToEndpoint.java | 51 +++++ .../aws/sqs/options/CreateQueueOptions.java | 73 +++++++ .../aws/sqs/options/ListQueuesOptions.java | 72 +++++++ .../org/jclouds/aws/sqs/package-info.java | 25 +++ .../aws/sqs/reference/SQSConstants.java | 32 +++ .../aws/sqs/reference/SQSParameters.java | 55 ++++++ .../aws/sqs/reference/package-info.java | 23 +++ .../sqs/xml/ListQueuesResponseHandler.java | 61 ++++++ .../org/jclouds/aws/sqs/xml/MD5Handler.java | 60 ++++++ .../org/jclouds/aws/sqs/xml/QueueHandler.java | 72 +++++++ ...icationArchitecturesEC2ClientLiveTest.java | 2 +- .../aws/ec2/EBSBootEC2ClientLiveTest.java | 2 +- .../aws/ec2/EC2ContextBuilderTest.java | 2 +- .../aws/ec2/config/EC2ContextModuleTest.java | 2 +- .../ec2/config/EC2RestClientModuleTest.java | 2 +- .../aws/ec2/services/AMIAsyncClientTest.java | 4 +- .../aws/ec2/services/AMIClientLiveTest.java | 2 +- ...ilabilityZoneAndRegionAsyncClientTest.java | 4 +- ...ailabilityZoneAndRegionClientLiveTest.java | 2 +- .../ElasticBlockStoreAsyncClientTest.java | 4 +- .../ElasticBlockStoreClientLiveTest.java | 2 +- .../ElasticIPAddressAsyncClientTest.java | 4 +- .../ElasticIPAddressClientLiveTest.java | 2 +- .../ec2/services/InstanceAsyncClientTest.java | 4 +- .../ec2/services/InstanceClientLiveTest.java | 2 +- .../ec2/services/KeyPairAsyncClientTest.java | 4 +- .../ec2/services/KeyPairClientLiveTest.java | 2 +- .../services/MonitoringAsyncClientTest.java | 4 +- .../services/MonitoringClientLiveTest.java | 2 +- .../SecurityGroupAsyncClientTest.java | 4 +- .../services/SecurityGroupClientLiveTest.java | 2 +- .../aws/ec2/xml/AttachmentHandlerTest.java | 2 +- .../xml/CreateVolumeResponseHandlerTest.java | 2 +- .../DescribeAddressesResponseHandlerTest.java | 2 +- ...eAvailabilityZonesResponseHandlerTest.java | 2 +- .../DescribeImagesResponseHandlerTest.java | 2 +- .../DescribeInstancesResponseHandlerTest.java | 2 +- .../DescribeKeyPairsResponseHandlerTest.java | 2 +- .../DescribeRegionsResponseHandlerTest.java | 2 +- ...ribeSecurityGroupsResponseHandlerTest.java | 2 +- .../DescribeSnapshotsResponseHandlerTest.java | 2 +- .../DescribeVolumesResponseHandlerTest.java | 2 +- .../xml/InstanceStateChangeHandlerTest.java | 2 +- .../ec2/xml/KeyPairResponseHandlerTest.java | 2 +- .../xml/RunInstancesResponseHandlerTest.java | 2 +- .../aws/ec2/xml/SnapshotHandlerTest.java | 2 +- .../aws/{ec2 => }/filters/FormSignerTest.java | 37 ++-- .../jclouds/aws/sqs/SQSAsyncClientTest.java | 186 ++++++++++++++++++ .../jclouds/aws/sqs/SQSClientLiveTest.java | 171 ++++++++++++++++ .../aws/sqs/SQSContextBuilderTest.java | 94 +++++++++ .../sqs/config/SQSRestClientModuleTest.java | 92 +++++++++ .../sqs/options/CreateQueueOptionsTest.java | 48 +++++ .../sqs/options/ListQueuesOptionsTest.java | 48 +++++ .../aws/ec2/demos/createlamp/MainApp.java | 2 +- aws/demos/pom.xml | 1 + aws/demos/speedtest-sqs/README.txt | 24 +++ aws/demos/speedtest-sqs/pom.xml | 83 ++++++++ .../java/org/jclouds/aws/sqs/SpeedTest.java | 167 ++++++++++++++++ aws/pom.xml | 6 + 117 files changed, 2425 insertions(+), 114 deletions(-) rename aws/core/src/main/java/org/jclouds/aws/{ec2 => }/domain/Region.java (94%) rename aws/core/src/main/java/org/jclouds/aws/{ec2 => }/filters/FormSigner.java (99%) create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/SQS.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/SQSAsyncClient.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/SQSClient.java create mode 100755 aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextBuilder.java create mode 100755 aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextFactory.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/SQSPropertiesBuilder.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSContextModule.java create mode 100755 aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSRestClientModule.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/domain/Queue.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/functions/QueueLocation.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/functions/RegionToEndpoint.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/options/CreateQueueOptions.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/options/ListQueuesOptions.java create mode 100755 aws/core/src/main/java/org/jclouds/aws/sqs/package-info.java create mode 100755 aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSConstants.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSParameters.java create mode 100755 aws/core/src/main/java/org/jclouds/aws/sqs/reference/package-info.java create mode 100755 aws/core/src/main/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandler.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/xml/MD5Handler.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/sqs/xml/QueueHandler.java rename aws/core/src/test/java/org/jclouds/aws/{ec2 => }/filters/FormSignerTest.java (68%) create mode 100644 aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java create mode 100644 aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java create mode 100644 aws/core/src/test/java/org/jclouds/aws/sqs/SQSContextBuilderTest.java create mode 100644 aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java create mode 100644 aws/core/src/test/java/org/jclouds/aws/sqs/options/CreateQueueOptionsTest.java create mode 100644 aws/core/src/test/java/org/jclouds/aws/sqs/options/ListQueuesOptionsTest.java create mode 100755 aws/demos/speedtest-sqs/README.txt create mode 100644 aws/demos/speedtest-sqs/pom.xml create mode 100755 aws/demos/speedtest-sqs/src/main/java/org/jclouds/aws/sqs/SpeedTest.java diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/Region.java b/aws/core/src/main/java/org/jclouds/aws/domain/Region.java similarity index 94% rename from aws/core/src/main/java/org/jclouds/aws/ec2/domain/Region.java rename to aws/core/src/main/java/org/jclouds/aws/domain/Region.java index 110b189899..bc1b84a679 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/Region.java +++ b/aws/core/src/main/java/org/jclouds/aws/domain/Region.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.aws.ec2.domain; +package org.jclouds.aws.domain; import static com.google.common.base.Preconditions.checkNotNull; @@ -24,7 +24,7 @@ import com.google.common.base.CaseFormat; /** * - * Regions used for all ec2 commands. + * Regions used for all aws commands. * * @author Adrian Cole */ diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2ContextFactory.java b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2ContextFactory.java index 9e536dd63f..c794a7e96f 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2ContextFactory.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2ContextFactory.java @@ -47,6 +47,12 @@ public class EC2ContextFactory { modules).buildContext(); } + public static RestContext createContext(Properties properties, + String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { + return new EC2ContextBuilder(new EC2PropertiesBuilder(properties).withCredentials( + awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext(); + } + public static RestContext createContext(String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { return new EC2ContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java index d67cd35e53..396f733271 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2PropertiesBuilder.java @@ -20,7 +20,7 @@ package org.jclouds.aws.ec2; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_ENDPOINT; -import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_EXPIREINTERVAL; +import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_AWS_EXPIREINTERVAL; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY; @@ -39,7 +39,7 @@ public class EC2PropertiesBuilder extends HttpPropertiesBuilder { protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_EC2_ENDPOINT, "https://ec2.amazonaws.com"); - properties.setProperty(PROPERTY_EC2_EXPIREINTERVAL, "60"); + properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, "60"); return properties; } @@ -65,7 +65,7 @@ public class EC2PropertiesBuilder extends HttpPropertiesBuilder { } public EC2PropertiesBuilder withRequestExpiration(long seconds) { - properties.setProperty(PROPERTY_EC2_EXPIREINTERVAL, seconds + ""); + properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, seconds + ""); return this; } } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java index 25e60d8b28..2018bea5c7 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java @@ -31,12 +31,12 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.aws.AWSResponseException; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.KeyPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.compute.ComputeService; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/config/EC2RestClientModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/config/EC2RestClientModule.java index b808a0772c..76c3d963f8 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/config/EC2RestClientModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/config/EC2RestClientModule.java @@ -26,12 +26,11 @@ import java.util.concurrent.TimeUnit; import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.RunningInstance; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.predicates.InstanceStateRunning; import org.jclouds.aws.ec2.reference.EC2Constants; import org.jclouds.aws.ec2.services.AMIAsyncClient; @@ -50,6 +49,7 @@ import org.jclouds.aws.ec2.services.MonitoringAsyncClient; import org.jclouds.aws.ec2.services.MonitoringClient; import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient; import org.jclouds.aws.ec2.services.SecurityGroupClient; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; @@ -114,7 +114,7 @@ public class EC2RestClientModule extends AbstractModule { @Provides @TimeStamp protected String provideTimeStamp(final DateService dateService, - @Named(EC2Constants.PROPERTY_EC2_EXPIREINTERVAL) final int expiration) { + @Named(EC2Constants.PROPERTY_AWS_EXPIREINTERVAL) final int expiration) { return dateService.iso8601DateFormat(new Date(System.currentTimeMillis() + (expiration * 1000))); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/Attachment.java b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/Attachment.java index 39cbe705fe..83e24b5ea0 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/Attachment.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/Attachment.java @@ -22,6 +22,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Date; +import org.jclouds.aws.domain.Region; + /** * * @see createContext(Properties properties, + String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { + return new S3ContextBuilder(new S3PropertiesBuilder(properties).withCredentials( + awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext(); + } + public static RestContext createContext(String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { return new S3ContextBuilder(new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey) .build()).withModules(modules).buildContext(); } - public static RestContext createContext(URI endpoint, String awsAccessKeyId, - String awsSecretAccessKey, Module... modules) { + public static RestContext createContext(URI endpoint, + String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { return new S3ContextBuilder(new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey) .withEndpoint(endpoint).build()).withModules(modules).buildContext(); } diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStoreContextFactory.java b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStoreContextFactory.java index 997375b1ac..c5e4226d42 100755 --- a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStoreContextFactory.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStoreContextFactory.java @@ -43,7 +43,8 @@ import com.google.inject.Module; * @see S3BlobStoreContext */ public class S3BlobStoreContextFactory { - public static BlobStoreContext createContext(Properties properties, Module... modules) { + public static BlobStoreContext createContext(Properties properties, + Module... modules) { return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(properties).build()) .withModules(modules).buildContext(); } @@ -54,8 +55,14 @@ public class S3BlobStoreContextFactory { awsSecretAccessKey).build()).withModules(modules).buildContext(); } - public static BlobStoreContext createContext(URI endpoint, String awsAccessKeyId, - String awsSecretAccessKey, Module... modules) { + public static BlobStoreContext createContext(Properties properties, + String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { + return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(properties).withCredentials( + awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext(); + } + + public static BlobStoreContext createContext(URI endpoint, + String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules) .buildContext(); diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/SQS.java b/aws/core/src/main/java/org/jclouds/aws/sqs/SQS.java new file mode 100644 index 0000000000..38b0aba313 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQS.java @@ -0,0 +1,39 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Related to a resource of type SQS + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface SQS { + +} \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSAsyncClient.java new file mode 100644 index 0000000000..614237141a --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSAsyncClient.java @@ -0,0 +1,99 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import static org.jclouds.aws.sqs.reference.SQSParameters.ACTION; +import static org.jclouds.aws.sqs.reference.SQSParameters.VERSION; + +import java.util.Set; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.aws.sqs.domain.Queue; +import org.jclouds.aws.sqs.functions.QueueLocation; +import org.jclouds.aws.sqs.functions.RegionToEndpoint; +import org.jclouds.aws.sqs.options.CreateQueueOptions; +import org.jclouds.aws.sqs.options.ListQueuesOptions; +import org.jclouds.aws.sqs.xml.ListQueuesResponseHandler; +import org.jclouds.aws.sqs.xml.MD5Handler; +import org.jclouds.aws.sqs.xml.QueueHandler; +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 SQS via their REST API. + *

+ * + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@FormParams(keys = VERSION, values = "2009-02-01") +@VirtualHost +public interface SQSAsyncClient { + + /** + * @see SQSClient#listQueuesInRegion + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ListQueues") + @XMLResponseParser(ListQueuesResponseHandler.class) + ListenableFuture> listQueuesInRegion( + @EndpointParam(parser = RegionToEndpoint.class) Region region, + ListQueuesOptions... options); + + /** + * @see SQSClient#createQueuesInRegion + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "CreateQueue") + @XMLResponseParser(QueueHandler.class) + ListenableFuture createQueueInRegion( + @EndpointParam(parser = RegionToEndpoint.class) Region region, + @FormParam("QueueName") String queueName, CreateQueueOptions... options); + + /** + * @see SQSClient#deleteQueue + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteQueue") + ListenableFuture deleteQueue(@EndpointParam(parser = QueueLocation.class) Queue queue); + + /** + * @see SQSClient#sendMessage + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessage") + @XMLResponseParser(MD5Handler.class) + ListenableFuture sendMessage(@EndpointParam(parser = QueueLocation.class) Queue queue, + @FormParam("MessageBody") String message); + +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSClient.java b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSClient.java new file mode 100644 index 0000000000..7e131d183b --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSClient.java @@ -0,0 +1,127 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.domain.Queue; +import org.jclouds.aws.sqs.options.CreateQueueOptions; +import org.jclouds.aws.sqs.options.ListQueuesOptions; +import org.jclouds.concurrent.Timeout; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface SQSClient { + + /** + * The ListQueues action returns a list of your queues. The maximum number of queues that can be + * returned is 1000. If you specify a value for the optional QueueNamePrefix parameter, only + * queues with a name beginning with the specified value are returned + * + * @param region + * Queues are Region-specific. + * @param options + * specify prefix or other options + * + * @see + */ + Set listQueuesInRegion(Region region, ListQueuesOptions... options); + + /** + * + * The CreateQueue action creates a new queue. + *

+ * When you request CreateQueue, you provide a name for the queue. To successfully create a new + * queue, you must provide a name that is unique within the scope of your own queues. If you + * provide the name of an existing queue, a new queue isn't created and an error isn't returned. + * Instead, the request succeeds and the queue URL for the existing queue is returned (for more + * information about queue URLs, see Queue and Message Identifiers in the Amazon SQS Developer + * Guide). Exception: if you provide a value for DefaultVisibilityTimeout that is different from + * the value for the existing queue, you receive an error. + *

Note

+ * + * If you delete a queue, you must wait at least 60 seconds before creating a queue with the same + * name. + *

+ * A default value for the queue's visibility timeout (30 seconds) is set when the queue is + * created. You can override this value with the DefaultVisibilityTimeout request parameter. For + * more information, see Visibility Timeout in the Amazon SQS Developer Guide. + * + * @param region + * Queues are Region-specific. + * @param queueName + * The name to use for the queue created. Constraints: Maximum 80 characters; + * alphanumeric characters, hyphens (-), and underscores (_) are allowed. + * @param options + * like the visibility timeout (in seconds) to use for this queue. + */ + Queue createQueueInRegion(Region region, String queueName, CreateQueueOptions... options); + + /** + * The DeleteQueue action deletes the queue specified by the queue URL, regardless of whether the + * queue is empty. If the specified queue does not exist, SQS returns a successful response.

+ * Caution

+ * + * Use DeleteQueue with care; once you delete your queue, any messages in the queue are no longer + * available. + *

+ * When you delete a queue, the deletion process takes up to 60 seconds. Requests you send + * involving that queue during the 60 seconds might succeed. For example, a SendMessage request + * might succeed, but after the 60 seconds, the queue and that message you sent no longer exist. + * Also, when you delete a queue, you must wait at least 60 seconds before creating a queue with + * the same name. + *

+ * We reserve the right to delete queues that have had no activity for more than 30 days. For + * more information, see About SQS Queues in the Amazon SQS Developer Guide. + * + * @param queue + * queue you want to delete + */ + void deleteQueue(Queue queue); + + /** + * The SendMessage action delivers a message to the specified queue. The maximum allowed message + * size is 8 KB. + *

+ * Important + *

+ * The following list shows the characters (in Unicode) allowed in your message, according to the + * W3C XML specification (for more information, go to http://www.w3.org/TR/REC-xml/#charsets). If + * you send any characters not included in the list, your request will be rejected. + *

+ * #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] + * + * @param queue + * queue you want to send to + * + * @param message + * The message to send. Type: String maximum 8 KB in size. For a list of allowed + * characters, see the preceding important note + * @return md5 of the content sent + */ + byte[] sendMessage(Queue queue, String message); +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextBuilder.java b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextBuilder.java new file mode 100755 index 0000000000..8ba79cdeaf --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextBuilder.java @@ -0,0 +1,76 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import java.util.List; +import java.util.Properties; +import java.util.concurrent.ExecutorService; + +import org.jclouds.aws.sqs.config.SQSContextModule; +import org.jclouds.aws.sqs.config.SQSRestClientModule; +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; +import com.google.inject.TypeLiteral; + +/** + * Creates {@link SQSContext} or {@link Injector} instances based on the most commonly requested + * arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see SQSContext + */ +public class SQSContextBuilder extends RestContextBuilder { + + public SQSContextBuilder(Properties props) { + super(new TypeLiteral() { + }, new TypeLiteral() { + }, props); + } + + @Override + protected void addContextModule(List modules) { + modules.add(new SQSContextModule()); + } + + @Override + protected void addClientModule(List modules) { + modules.add(new SQSRestClientModule()); + } + + @Override + public SQSContextBuilder withExecutorService(ExecutorService service) { + return (SQSContextBuilder) super.withExecutorService(service); + } + + @Override + public SQSContextBuilder withModules(Module... modules) { + return (SQSContextBuilder) super.withModules(modules); + } + +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextFactory.java b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextFactory.java new file mode 100755 index 0000000000..c9c3f4aec7 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSContextFactory.java @@ -0,0 +1,67 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rest.RestContext; + +import com.google.inject.Module; + +/** + * Creates {@link SQSContext} instances based on the most commonly requested arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see SQSAsyncClient + */ +public class SQSContextFactory { + + public static RestContext createContext(Properties properties, + Module... modules) { + return new SQSContextBuilder(new SQSPropertiesBuilder(properties).build()).withModules( + modules).buildContext(); + } + + public static RestContext createContext(Properties properties, String awsAccessKeyId, + String awsSecretAccessKey, Module... modules) { + return new SQSContextBuilder(new SQSPropertiesBuilder(properties).withCredentials(awsAccessKeyId, awsSecretAccessKey) + .build()).withModules(modules).buildContext(); + } + + public static RestContext createContext(String awsAccessKeyId, + String awsSecretAccessKey, Module... modules) { + return new SQSContextBuilder(new SQSPropertiesBuilder(awsAccessKeyId, awsSecretAccessKey) + .build()).withModules(modules).buildContext(); + } + + public static RestContext createContext(URI endpoint, + String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { + return new SQSContextBuilder(new SQSPropertiesBuilder(awsAccessKeyId, awsSecretAccessKey) + .withEndpoint(endpoint).build()).withModules(modules).buildContext(); + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSPropertiesBuilder.java b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSPropertiesBuilder.java new file mode 100644 index 0000000000..f38191b985 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSPropertiesBuilder.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_EXPIREINTERVAL; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY; +import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT_EU_WEST_1; +import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1; +import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT_US_WEST_1; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.http.HttpPropertiesBuilder; + +/** + * Builds properties used in SQS Clients + * + * @author Adrian Cole + */ +public class SQSPropertiesBuilder extends HttpPropertiesBuilder { + @Override + protected Properties defaultProperties() { + Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_SQS_ENDPOINT_US_EAST_1, "https://queue.amazonaws.com"); + properties.setProperty(PROPERTY_SQS_ENDPOINT_US_WEST_1, "https://us-west-1.queue.amazonaws.com"); + properties.setProperty(PROPERTY_SQS_ENDPOINT_EU_WEST_1, "https://eu-west-1.queue.amazonaws.com"); + properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, "60"); + return properties; + } + + public SQSPropertiesBuilder(Properties properties) { + super(properties); + } + + public SQSPropertiesBuilder(String id, String secret) { + super(); + withCredentials(id, secret); + } + + public SQSPropertiesBuilder withCredentials(String id, String secret) { + properties.setProperty(PROPERTY_AWS_ACCESSKEYID, checkNotNull(id, "awsAccessKeyId")); + properties.setProperty(PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(secret, + "awsSecretAccessKey")); + return this; + } + + public SQSPropertiesBuilder withEndpoint(URI endpoint) { + properties.setProperty(PROPERTY_SQS_ENDPOINT_US_EAST_1, checkNotNull(endpoint, "endpoint").toString()); + return this; + } + + public SQSPropertiesBuilder withRequestExpiration(long seconds) { + properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, seconds + ""); + return this; + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSContextModule.java b/aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSContextModule.java new file mode 100644 index 0000000000..0a5abc9f6b --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSContextModule.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.config; + +import java.net.URI; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.aws.reference.AWSConstants; +import org.jclouds.aws.sqs.SQS; +import org.jclouds.aws.sqs.SQSAsyncClient; +import org.jclouds.aws.sqs.SQSClient; +import org.jclouds.http.functions.config.ParserModule.CDateAdapter; +import org.jclouds.http.functions.config.ParserModule.DateAdapter; +import org.jclouds.lifecycle.Closer; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.RestContextImpl; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * Configures the SQS connection, including logging and http transport. + * + * @author Adrian Cole + */ +public class SQSContextModule extends AbstractModule { + @Override + protected void configure() { + bind(DateAdapter.class).to(CDateAdapter.class); + } + + @Provides + @Singleton + RestContext provideContext(Closer closer, SQSAsyncClient defaultApi, + SQSClient synchApi, @SQS URI endPoint, + @Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) { + return new RestContextImpl(closer, defaultApi, synchApi, endPoint, + account); + } + +} \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSRestClientModule.java b/aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSRestClientModule.java new file mode 100755 index 0000000000..a59cb21281 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/config/SQSRestClientModule.java @@ -0,0 +1,128 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.config; + +import java.net.URI; +import java.util.Date; +import java.util.Map; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; +import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; +import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; +import org.jclouds.aws.sqs.SQS; +import org.jclouds.aws.sqs.SQSAsyncClient; +import org.jclouds.aws.sqs.SQSClient; +import org.jclouds.aws.sqs.reference.SQSConstants; +import org.jclouds.aws.util.RequestSigner; +import org.jclouds.concurrent.internal.SyncProxy; +import org.jclouds.date.DateService; +import org.jclouds.date.TimeStamp; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpRetryHandler; +import org.jclouds.http.RequiresHttp; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.RestClientFactory; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * Configures the SQS connection. + * + * @author Adrian Cole + */ +@RequiresHttp +@ConfiguresRestClient +public class SQSRestClientModule extends AbstractModule { + + @Override + protected void configure() { + bindErrorHandlers(); + bindRetryHandlers(); + } + + @Provides + @TimeStamp + protected String provideTimeStamp(final DateService dateService, + @Named(SQSConstants.PROPERTY_AWS_EXPIREINTERVAL) final int expiration) { + return dateService.iso8601DateFormat(new Date(System.currentTimeMillis() + + (expiration * 1000))); + } + + @Provides + @Singleton + protected SQSAsyncClient provideAsyncClient(RestClientFactory factory) { + return factory.create(SQSAsyncClient.class); + } + + @Provides + @Singleton + public SQSClient provideClient(SQSAsyncClient client) throws IllegalArgumentException, + SecurityException, NoSuchMethodException { + return SyncProxy.create(SQSClient.class, client); + } + + @Provides + @Singleton + Map provideRegions( + @Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1) String useast, + @Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_WEST_1) String uswest, + @Named(SQSConstants.PROPERTY_SQS_ENDPOINT_EU_WEST_1) String euwest) { + return ImmutableMap. of(Region.US_EAST_1, URI.create(useast), Region.US_WEST_1, + URI.create(uswest), Region.EU_WEST_1, URI.create(euwest)); + } + + @Provides + @Singleton + RequestSigner provideRequestSigner(FormSigner in) { + return in; + } + + @Provides + @Singleton + @SQS + protected URI provideURI(@Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1) String endpoint) { + return URI.create(endpoint); + } + + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( + ParseAWSErrorFromXmlContent.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to( + ParseAWSErrorFromXmlContent.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to( + ParseAWSErrorFromXmlContent.class); + } + + protected void bindRetryHandlers() { + bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to( + AWSRedirectionRetryHandler.class); + bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to( + AWSClientErrorRetryHandler.class); + } +} \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/domain/Queue.java b/aws/core/src/main/java/org/jclouds/aws/sqs/domain/Queue.java new file mode 100644 index 0000000000..a7fa1a4df1 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/domain/Queue.java @@ -0,0 +1,104 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import org.jclouds.aws.domain.Region; + +/** + * + * @see + * @author Adrian Cole + */ +public class Queue implements Comparable { + private final Region region; + private final String name; + private final URI location; + + public Queue(Region region, String name, URI location) { + this.region = checkNotNull(region,"region"); + this.location = checkNotNull(location, "location"); + this.name = checkNotNull(name, "name"); + } + + @Override + public int compareTo(Queue o) { + return location.toASCIIString().compareTo(o.location.toASCIIString()); + } + + public Region getRegion() { + return region; + } + + public URI getLocation() { + return location; + } + + public String getName() { + return name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((region == null) ? 0 : region.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; + Queue other = (Queue) obj; + if (location == null) { + if (other.location != null) + return false; + } else if (!location.equals(other.location)) + 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; + return true; + } + + @Override + public String toString() { + return "Queue [location=" + location + ", name=" + name + ", region=" + region + "]"; + } + + +} \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/functions/QueueLocation.java b/aws/core/src/main/java/org/jclouds/aws/sqs/functions/QueueLocation.java new file mode 100644 index 0000000000..abf23b8eb0 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/functions/QueueLocation.java @@ -0,0 +1,40 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.functions; + +import java.net.URI; + +import javax.inject.Singleton; + +import org.jclouds.aws.sqs.domain.Queue; + +import com.google.common.base.Function; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class QueueLocation implements Function { + + public URI apply(Object from) { + return ((Queue) from).getLocation(); + } + +} \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/functions/RegionToEndpoint.java b/aws/core/src/main/java/org/jclouds/aws/sqs/functions/RegionToEndpoint.java new file mode 100644 index 0000000000..3be96eb9ec --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/functions/RegionToEndpoint.java @@ -0,0 +1,51 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.functions; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.SQS; + +import com.google.common.base.Function; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class RegionToEndpoint implements Function { + private final Map regionToEndpoint; + private final URI defaultUri; + + @Inject + public RegionToEndpoint(Map regionToEndpoint, @SQS URI defaultUri) { + this.regionToEndpoint = regionToEndpoint; + this.defaultUri = defaultUri; + } + + public URI apply(Object from) { + return from.equals(Region.DEFAULT) ? defaultUri : regionToEndpoint.get(from); + } + +} \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/options/CreateQueueOptions.java b/aws/core/src/main/java/org/jclouds/aws/sqs/options/CreateQueueOptions.java new file mode 100644 index 0000000000..67450d2ab1 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/options/CreateQueueOptions.java @@ -0,0 +1,73 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Contains options supported in the Form API for the CreateQueue operation.

+ * Usage

The recommended way to instantiate a CreateQueueOptions object is to statically import + * CreateQueueOptions.Builder.* and invoke a static creation method followed by an instance mutator + * (if needed): + *

+ * + * import static org.jclouds.aws.sqs.options.CreateQueueOptions.Builder.* + *

+ * SQSClient connection = // get connection + * Queue queue = connection.createQueueInRegion(defaultVisibilityTimeout("foo")); + * + * + * @author Adrian Cole + * @see + */ +public class CreateQueueOptions extends BaseHttpRequestOptions { + + /** + * A default value for the queue's visibility timeout (30 seconds) is set when the queue is + * created. You can override this value with the DefaultVisibilityTimeout request parameter. For + * more information, see Visibility Timeout in the Amazon SQS Developer Guide. + * + * @param seconds + * The visibility timeout (in seconds) to use for this queue. 0 to 43200 (maximum 12 + * hours); Default: 30 seconds + */ + public CreateQueueOptions defaultVisibilityTimeout(int seconds) { + //TODO validate + formParameters.put("DefaultVisibilityTimeout", seconds+""); + return this; + } + + public String getRestorableBy() { + return getFirstFormOrNull("DefaultVisibilityTimeout"); + } + + public static class Builder { + + /** + * @see CreateQueueOptions#defaultVisibilityTimeout(int ) + */ + public static CreateQueueOptions defaultVisibilityTimeout(int seconds) { + CreateQueueOptions options = new CreateQueueOptions(); + return options.defaultVisibilityTimeout(seconds); + } + + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/options/ListQueuesOptions.java b/aws/core/src/main/java/org/jclouds/aws/sqs/options/ListQueuesOptions.java new file mode 100644 index 0000000000..2f83e7a27d --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/options/ListQueuesOptions.java @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Contains options supported in the Form API for the ListQueues operation.

+ * Usage

The recommended way to instantiate a ListQueuesOptions object is to statically import + * ListQueuesOptions.Builder.* and invoke a static creation method followed by an instance mutator + * (if needed): + *

+ * + * import static org.jclouds.aws.sqs.options.ListQueuesOptions.Builder.* + *

+ * SQSClient connection = // get connection + * Set queues = connection.listQueuesInRegion(queuePrefix("foo")); + * + * + * @author Adrian Cole + * @see + */ +public class ListQueuesOptions extends BaseHttpRequestOptions { + + /** + * String to use for filtering the list results. Only those queues whose name begins with the + * specified string are returned. + * + * @param prefix + * Maximum 80 characters; alphanumeric characters, hyphens (-), and underscores (_) are + * allowed. + */ + public ListQueuesOptions queuePrefix(String prefix) { + //TODO validate + formParameters.put("QueueNamePrefix", prefix); + return this; + } + + public String getRestorableBy() { + return getFirstFormOrNull("QueueNamePrefix"); + } + + public static class Builder { + + /** + * @see ListQueuesOptions#queuePrefix(String ) + */ + public static ListQueuesOptions queuePrefix(String prefix) { + ListQueuesOptions options = new ListQueuesOptions(); + return options.queuePrefix(prefix); + } + + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/package-info.java b/aws/core/src/main/java/org/jclouds/aws/sqs/package-info.java new file mode 100755 index 0000000000..cfd5b73224 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/package-info.java @@ -0,0 +1,25 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 an Amazon SQS client implemented by {@link org.jclouds.http.HttpCommandExecutorService} commands. + * + * @see + * @author Adrian Cole + */ +package org.jclouds.aws.sqs; \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSConstants.java b/aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSConstants.java new file mode 100755 index 0000000000..86ab79aca8 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSConstants.java @@ -0,0 +1,32 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.reference; + +import org.jclouds.aws.reference.AWSConstants; + +/** + * Configuration properties and constants used in SQS connections. + * + * @author Adrian Cole + */ +public interface SQSConstants extends AWSConstants { + public static final String PROPERTY_SQS_ENDPOINT_EU_WEST_1 = "jclouds.sqs.endpoint.eu_west_1"; + public static final String PROPERTY_SQS_ENDPOINT_US_EAST_1 = "jclouds.sqs.endpoint.us_east_1"; + public static final String PROPERTY_SQS_ENDPOINT_US_WEST_1 = "jclouds.sqs.endpoint.us_west_1"; +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSParameters.java b/aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSParameters.java new file mode 100644 index 0000000000..bc04fd740e --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/reference/SQSParameters.java @@ -0,0 +1,55 @@ +package org.jclouds.aws.sqs.reference; + +/** + * Configuration properties and constants used in SQS connections. + * + * @see + * @author Adrian Cole + */ +public interface SQSParameters { + + /** + * The action to perform. For example: CreateQueue. + */ + 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 SQS 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 SQS 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 SQS Developer Guide. + */ + public static final String SIGNATURE_METHOD = "SignatureMethod"; + /** + * For more information, see Query Request Authentication in the Amazon SQS Developer Guide. + */ + public static final String SIGNATURE_VERSION = "SignatureVersion"; +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/reference/package-info.java b/aws/core/src/main/java/org/jclouds/aws/sqs/reference/package-info.java new file mode 100755 index 0000000000..6b5c9f7b09 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/reference/package-info.java @@ -0,0 +1,23 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 SQS. + * @author Adrian Cole + */ +package org.jclouds.aws.sqs.reference; \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandler.java new file mode 100755 index 0000000000..a40b951e99 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandler.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.xml; + +import java.util.Set; + +import javax.inject.Inject; + +import org.jclouds.aws.sqs.domain.Queue; +import org.jclouds.http.functions.ParseSax; + +import com.google.common.collect.Sets; + +/** + * + * @see + * @author Adrian Cole + */ +public class ListQueuesResponseHandler extends ParseSax.HandlerWithResult> { + + Set queues = Sets.newLinkedHashSet(); + + private final QueueHandler qHandler; + + @Inject + ListQueuesResponseHandler(QueueHandler qHandler) { + this.qHandler = qHandler; + } + + public Set getResult() { + return queues; + } + + public void endElement(String uri, String name, String qName) { + qHandler.endElement(uri, name, qName); + if (qName.equals("QueueUrl")) { + queues.add(qHandler.getResult()); + } + } + + public void characters(char ch[], int start, int length) { + qHandler.characters(ch, start, length); + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/xml/MD5Handler.java b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/MD5Handler.java new file mode 100644 index 0000000000..f8052b1d01 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/MD5Handler.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.xml; + +import javax.inject.Inject; + +import org.jclouds.encryption.EncryptionService; +import org.jclouds.http.functions.ParseSax; + +/** + * + * @see + * @author Adrian Cole + */ +public class MD5Handler extends ParseSax.HandlerWithResult { + + private StringBuilder currentText = new StringBuilder(); + byte[] md5; + + private final EncryptionService encryptionService; + + @Inject + MD5Handler(EncryptionService encryptionService) { + this.encryptionService = encryptionService; + + } + + public byte[] getResult() { + return md5; + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("MD5OfMessageBody")) { + String md5Hex = currentText.toString().trim(); + this.md5 = encryptionService.fromHexString(md5Hex); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/xml/QueueHandler.java b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/QueueHandler.java new file mode 100644 index 0000000000..6e3c1d5803 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/QueueHandler.java @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs.xml; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Inject; +import javax.ws.rs.core.UriBuilder; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.domain.Queue; +import org.jclouds.http.functions.ParseSax; + +import com.google.common.collect.ImmutableBiMap; + +/** + * + * @see + * @author Adrian Cole + */ +public class QueueHandler extends ParseSax.HandlerWithResult { + + private StringBuilder currentText = new StringBuilder(); + Queue queue; + + private final ImmutableBiMap regionBiMap; + + @Inject + QueueHandler(Map regionMap) { + this.regionBiMap = ImmutableBiMap.copyOf(regionMap); + + } + + public Queue getResult() { + return queue; + } + + public void endElement(String uri, String name, String qName) { + + if (qName.equals("QueueUrl")) { + String uriText = currentText.toString().trim(); + String queueName = uriText.substring(uriText.lastIndexOf('/') + 1); + URI location = URI.create(uriText); + URI regionURI = UriBuilder.fromUri(location).replacePath("").build(); + Region region = regionBiMap.inverse().get(regionURI); + this.queue = new Queue(region, queueName, location); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java index 8a2552600a..dffda1b464 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java @@ -35,12 +35,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jclouds.aws.AWSResponseException; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java index 94a1e52a5d..67bd7346ef 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/EBSBootEC2ClientLiveTest.java @@ -36,13 +36,13 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jclouds.aws.AWSResponseException; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.KeyPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RunningInstance; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ContextBuilderTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ContextBuilderTest.java index e847fd8a38..cdca18f72b 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ContextBuilderTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ContextBuilderTest.java @@ -27,8 +27,8 @@ import java.util.ArrayList; import java.util.List; import org.jclouds.aws.ec2.config.EC2RestClientModule; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.reference.EC2Constants; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; import org.testng.annotations.Test; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java index 09862faa64..56d899cd85 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java @@ -58,7 +58,7 @@ public class EC2ContextModuleTest { bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_EC2_ENDPOINT)) .to("http://localhost"); bindConstant().annotatedWith( - Jsr330.named(EC2Constants.PROPERTY_EC2_EXPIREINTERVAL)).to(30); + Jsr330.named(EC2Constants.PROPERTY_AWS_EXPIREINTERVAL)).to(30); super.configure(); } }); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java index 76f9d425e9..3502d28aca 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java @@ -53,7 +53,7 @@ public class EC2RestClientModuleTest { .to("key"); bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_EC2_ENDPOINT)).to( "http://localhost"); - bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_EC2_EXPIREINTERVAL)) + bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_AWS_EXPIREINTERVAL)) .to(30); } }); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java index ab6fa713df..1bdd4551a5 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java @@ -29,9 +29,8 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.domain.Region; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.options.CreateImageOptions; import org.jclouds.aws.ec2.options.DescribeImagesOptions; import org.jclouds.aws.ec2.options.RegisterImageBackedByEbsOptions; @@ -41,6 +40,7 @@ import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler; import org.jclouds.aws.ec2.xml.ImageIdHandler; import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.ProductCodesHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java index 088f47ede5..c007ba2e4a 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java @@ -29,11 +29,11 @@ import java.util.Iterator; import java.util.Set; import java.util.SortedSet; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.domain.Image; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.Image.ImageType; import org.jclouds.logging.log4j.config.Log4JLoggingModule; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java index cbdd137236..c1efaccabd 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java @@ -30,14 +30,14 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.AvailabilityZone; -import org.jclouds.aws.ec2.domain.Region; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions; import org.jclouds.aws.ec2.options.DescribeRegionsOptions; import org.jclouds.aws.ec2.xml.DescribeAvailabilityZonesResponseHandler; import org.jclouds.aws.ec2.xml.DescribeRegionsResponseHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java index c3e97b5eb2..1b792097e6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java @@ -30,12 +30,12 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.Map.Entry; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java index 5328a28344..0350c61426 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java @@ -30,10 +30,9 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.AvailabilityZone; -import org.jclouds.aws.ec2.domain.Region; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.functions.ReturnVoidOnVolumeAvailable; import org.jclouds.aws.ec2.options.CreateSnapshotOptions; import org.jclouds.aws.ec2.options.DescribeSnapshotsOptions; @@ -44,6 +43,7 @@ import org.jclouds.aws.ec2.xml.DescribeSnapshotsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler; import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.SnapshotHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java index f0f8e99a2f..d4859ea9b9 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClientLiveTest.java @@ -27,11 +27,11 @@ import java.util.SortedSet; import java.util.concurrent.TimeUnit; import org.jclouds.aws.AWSResponseException; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.domain.AvailabilityZone; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Snapshot; import org.jclouds.aws.ec2.domain.Volume; import org.jclouds.aws.ec2.predicates.SnapshotCompleted; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java index f792505cde..3bf597ffa7 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java @@ -29,11 +29,11 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.domain.Region; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler; import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressClientLiveTest.java index f9ed089b8d..fdcf3c2c5e 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressClientLiveTest.java @@ -24,11 +24,11 @@ import static org.testng.Assert.assertNotNull; import java.util.SortedSet; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java index 7a760db51a..5b1a83dbbb 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java @@ -28,12 +28,11 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.InstanceType; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.options.RunInstancesOptions; import org.jclouds.aws.ec2.xml.BlockDeviceMappingHandler; import org.jclouds.aws.ec2.xml.BooleanValueHandler; @@ -44,6 +43,7 @@ import org.jclouds.aws.ec2.xml.InstanceTypeHandler; import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler; import org.jclouds.aws.ec2.xml.StringValueHandler; import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceClientLiveTest.java index 68e904e4fd..7476f461b6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceClientLiveTest.java @@ -25,8 +25,8 @@ import static org.testng.Assert.assertNotNull; import java.util.Iterator; import java.util.SortedSet; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2ContextFactory; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.testng.annotations.BeforeGroups; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java index bd68df79a1..dbe654647e 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java @@ -28,10 +28,10 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.domain.Region; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairClientLiveTest.java index c87a39b39a..bc26f5a29e 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairClientLiveTest.java @@ -24,11 +24,11 @@ import static org.testng.Assert.assertNotNull; import java.util.SortedSet; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.domain.KeyPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java index df124b30a3..d0a609e109 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java @@ -28,10 +28,10 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.domain.Region; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.xml.MonitoringStateHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java index af32c24f3f..cee39e3d60 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java @@ -23,11 +23,11 @@ import static org.testng.Assert.assertEquals; import java.util.Map; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.domain.MonitoringState; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.testng.annotations.BeforeGroups; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java index 7bc1678ba6..6631ddd91f 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java @@ -28,13 +28,13 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.IpProtocol; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.UserIdGroupPair; -import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound; import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler; +import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupClientLiveTest.java index e7e376d724..54fa9f470c 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupClientLiveTest.java @@ -28,12 +28,12 @@ import java.util.SortedSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.domain.IpPermission; import org.jclouds.aws.ec2.domain.IpProtocol; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.SecurityGroup; import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.logging.log4j.config.Log4JLoggingModule; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/AttachmentHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/AttachmentHandlerTest.java index 7ae2d0ee71..ec29a069b0 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/AttachmentHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/AttachmentHandlerTest.java @@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Attachment; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandlerTest.java index 31f72b064c..c82d6edff5 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandlerTest.java @@ -28,9 +28,9 @@ import java.util.Map; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.AvailabilityZone; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Volume; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAddressesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAddressesResponseHandlerTest.java index 58bd8a4541..db8c65608f 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAddressesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAddressesResponseHandlerTest.java @@ -28,8 +28,8 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Set; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java index 6d3ec48b8a..56ce3caea6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java @@ -23,9 +23,9 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.http.functions.BaseHandlerTest; import org.testng.annotations.Test; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandlerTest.java index e80c319703..e2d91e9bb8 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandlerTest.java @@ -27,8 +27,8 @@ import java.io.InputStream; import java.util.Set; import java.util.SortedSet; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Image; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.Image.Architecture; import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeInstancesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeInstancesResponseHandlerTest.java index 5745e300dc..3da30a4a2f 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeInstancesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeInstancesResponseHandlerTest.java @@ -28,11 +28,11 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Set; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceType; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RunningInstance; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandlerTest.java index b07749dddf..10a61878a6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandlerTest.java @@ -26,8 +26,8 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.KeyPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeRegionsResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeRegionsResponseHandlerTest.java index 777ede57b6..9948c8b8b8 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeRegionsResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeRegionsResponseHandlerTest.java @@ -24,8 +24,8 @@ import java.io.InputStream; import java.net.URI; import java.util.Map; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.config.ParserModule; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandlerTest.java index bd667b02c3..17c803df8c 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandlerTest.java @@ -27,9 +27,9 @@ import java.io.InputStream; import java.util.Set; import java.util.SortedSet; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.IpPermission; import org.jclouds.aws.ec2.domain.IpProtocol; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.SecurityGroup; import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.http.functions.BaseHandlerTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSnapshotsResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSnapshotsResponseHandlerTest.java index dfb918dd0c..9103b2f0f5 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSnapshotsResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeSnapshotsResponseHandlerTest.java @@ -26,7 +26,7 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; -import org.jclouds.aws.ec2.domain.Region; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Snapshot; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeVolumesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeVolumesResponseHandlerTest.java index af6df9a3cd..f605aeaea6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeVolumesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/DescribeVolumesResponseHandlerTest.java @@ -29,9 +29,9 @@ import java.util.Set; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.AvailabilityZone; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Volume; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandlerTest.java index ad07d4c487..34bda4ecf7 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandlerTest.java @@ -26,9 +26,9 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceStateChange; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/KeyPairResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/KeyPairResponseHandlerTest.java index 96341a9ba8..c315544cde 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/KeyPairResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/KeyPairResponseHandlerTest.java @@ -25,8 +25,8 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.KeyPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java index 4e55443537..0d798152db 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java @@ -26,10 +26,10 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.InetAddress; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceType; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RunningInstance; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/SnapshotHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/SnapshotHandlerTest.java index 57a98c48e4..a9c6c18d5f 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/SnapshotHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/SnapshotHandlerTest.java @@ -25,7 +25,7 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; -import org.jclouds.aws.ec2.domain.Region; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Snapshot; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/filters/FormSignerTest.java b/aws/core/src/test/java/org/jclouds/aws/filters/FormSignerTest.java similarity index 68% rename from aws/core/src/test/java/org/jclouds/aws/ec2/filters/FormSignerTest.java rename to aws/core/src/test/java/org/jclouds/aws/filters/FormSignerTest.java index 8ed47db6e0..44ee8aee64 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/filters/FormSignerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/filters/FormSignerTest.java @@ -16,25 +16,31 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.aws.ec2.filters; +package org.jclouds.aws.filters; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import static org.testng.Assert.assertEquals; -import org.jclouds.aws.ec2.config.EC2RestClientModule; -import org.jclouds.aws.ec2.reference.EC2Constants; +import java.util.Date; + +import javax.inject.Named; + +import org.jclouds.aws.reference.AWSConstants; import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.date.DateService; +import org.jclouds.date.TimeStamp; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.util.Jsr330; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; +import com.google.common.util.concurrent.Executors; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.Provides; -@Test(groups = "unit", testName = "ec2.FormSignerTest") +@Test(groups = "unit", testName = "aws.FormSignerTest") public class FormSignerTest { private Injector injector; @@ -57,19 +63,26 @@ public class FormSignerTest { */ @BeforeClass protected void createFilter() { - injector = Guice.createInjector(new EC2RestClientModule(), new ExecutorServiceModule( - sameThreadExecutor()), new ParserModule(), new AbstractModule() { + injector = Guice.createInjector(new ParserModule(), new ExecutorServiceModule(Executors + .sameThreadExecutor()), new AbstractModule() { protected void configure() { - bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_AWS_ACCESSKEYID)).to( + bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( "foo"); - bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_AWS_SECRETACCESSKEY)) + bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY)) .to("bar"); - bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_EC2_ENDPOINT)).to( - "https://ec2.amazonaws.com"); - bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_EC2_EXPIREINTERVAL)) + bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_EXPIREINTERVAL)) .to(30); } + + @SuppressWarnings("unused") + @Provides + @TimeStamp + protected String provideTimeStamp(final DateService dateService, + @Named(AWSConstants.PROPERTY_AWS_EXPIREINTERVAL) final int expiration) { + return dateService.iso8601DateFormat(new Date(System.currentTimeMillis() + + (expiration * 1000))); + } }); filter = injector.getInstance(FormSigner.class); } diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java new file mode 100644 index 0000000000..c8eb5ec643 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java @@ -0,0 +1,186 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.aws.reference.AWSConstants; +import org.jclouds.aws.sqs.options.CreateQueueOptions; +import org.jclouds.aws.sqs.options.ListQueuesOptions; +import org.jclouds.aws.sqs.xml.ListQueuesResponseHandler; +import org.jclouds.aws.sqs.xml.QueueHandler; +import org.jclouds.date.TimeStamp; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code SQSAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "sqs.SQSAsyncClientTest") +public class SQSAsyncClientTest extends RestClientTest { + public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException, + IOException { + Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", Region.class, Array + .newInstance(ListQueuesOptions.class, 0).getClass()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + Region.DEFAULT); + + assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); + assertHeadersEqual(httpMethod, + "Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); + assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues"); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, ListQueuesResponseHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException, + IOException { + Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", Region.class, Array + .newInstance(ListQueuesOptions.class, 0).getClass()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + Region.DEFAULT, ListQueuesOptions.Builder.queuePrefix("prefix")); + + assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); + assertHeadersEqual(httpMethod, + "Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); + assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix"); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, ListQueuesResponseHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testCreateQueueInRegion() throws SecurityException, NoSuchMethodException, + IOException { + Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", Region.class, + String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + Region.DEFAULT, "queueName"); + + assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); + assertHeadersEqual(httpMethod, + "Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); + assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName"); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, QueueHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testCreateQueueInRegionOptions() throws SecurityException, NoSuchMethodException, + IOException { + Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", Region.class, + String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass()); + GeneratedHttpRequest httpMethod = processor + .createRequest(method, Region.DEFAULT, "queueName", CreateQueueOptions.Builder + .defaultVisibilityTimeout(45)); + + assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); + assertHeadersEqual(httpMethod, + "Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); + assertPayloadEquals(httpMethod, + "Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45"); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, QueueHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(SQS.class).toInstance(URI.create("https://default")); + bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( + "user"); + bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY)) + .to("key"); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } + + @SuppressWarnings("unused") + @Provides + @TimeStamp + String provide() { + return "2009-11-08T15:54:08.897Z"; + } + + @SuppressWarnings("unused") + @Singleton + @Provides + Map provideMap() { + return ImmutableMap. of(Region.DEFAULT, URI.create("https://booya"), + Region.EU_WEST_1, URI.create("https://sqs.eu-west-1.amazonaws.com"), + Region.US_EAST_1, URI.create("https://sqs.us-east-1.amazonaws.com"), + Region.US_WEST_1, URI.create("https://sqs.us-west-1.amazonaws.com")); + } + }; + } +} diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java new file mode 100644 index 0000000000..9ad4eb8483 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSClientLiveTest.java @@ -0,0 +1,171 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.sqs.options.ListQueuesOptions.Builder.queuePrefix; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.Set; +import java.util.SortedSet; + +import org.jclouds.aws.AWSResponseException; +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.domain.Queue; +import org.jclouds.encryption.EncryptionService; +import org.jclouds.encryption.internal.JCEEncryptionService; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContext; +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.Sets; + +/** + * Tests behavior of {@code SQSClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "sqs.SQSClientLiveTest") +public class SQSClientLiveTest { + + private SQSClient client; + + private RestContext context; + + private EncryptionService encryptionService = new JCEEncryptionService(); + private Set queues = Sets.newHashSet(); + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); + String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); + + context = SQSContextFactory.createContext(user, password, new Log4JLoggingModule()); + client = context.getApi(); + } + + @Test + void testListQueuesInRegion() throws InterruptedException { + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { + SortedSet allResults = Sets.newTreeSet(client.listQueuesInRegion(region)); + assertNotNull(allResults); + if (allResults.size() >= 1) { + Queue queue = allResults.last(); + assertQueueInList(region, queue); + } + } + } + + public static final String PREFIX = System.getProperty("user.name") + "-sqs"; + + @Test + void testCreateQueue() throws InterruptedException { + String queueName = PREFIX + "1"; + + for (final Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, + Region.US_WEST_1)) { + try { + SortedSet result = Sets.newTreeSet(client.listQueuesInRegion(region, + queuePrefix(queueName))); + if (result.size() >= 1) { + client.deleteQueue(result.last()); + queueName += 1;// cannot recreate a queue within 60 seconds + } + } catch (Exception e) { + + } + Queue queue = null; + int tries = 0; + while (queue == null && tries < 5) { + try { + tries++; + queue = client.createQueueInRegion(region, queueName); + } catch (AWSResponseException e) { + queueName += "1"; + if (e.getError().getCode().equals("AWS.SimpleQueueService.QueueDeletedRecently"))// TODO + // retry + // handler + continue; + throw e; + } + } + assertEquals(queue.getRegion(), region); + assertEquals(queue.getName(), queueName); + assertQueueInList(region, queue); + queues.add(queue); + } + } + + @Test(dependsOnMethods = "testCreateQueue") + void testSendMessage() throws InterruptedException { + String message = "hardyharhar"; + byte[] md5 = encryptionService.md5(message.getBytes()); + for (Queue queue : queues) { + assertEquals(client.sendMessage(queue, message), md5); + } + } + + private void assertQueueInList(final Region region, Queue queue) throws InterruptedException { + final Queue finalQ = queue; + assertEventually(new Runnable() { + public void run() { + SortedSet result = Sets.newTreeSet(client.listQueuesInRegion(region, + queuePrefix(finalQ.getName()))); + assertNotNull(result); + assert result.size() >= 1 : result; + assertEquals(result.first(), finalQ); + } + }); + } + + 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(); + } +} diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSContextBuilderTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSContextBuilderTest.java new file mode 100644 index 0000000000..d6d72e23e7 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSContextBuilderTest.java @@ -0,0 +1,94 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY; +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.aws.sqs.config.SQSRestClientModule; +import org.jclouds.aws.sqs.reference.SQSConstants; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.RestContextImpl; +import org.testng.annotations.Test; + +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of modules configured in SQSContextBuilder + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "sqs.SQSContextBuilderTest") +public class SQSContextBuilderTest { + + public void testNewBuilder() { + SQSContextBuilder builder = newBuilder(); + assertEquals(builder.getProperties() + .getProperty(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1), + "https://queue.amazonaws.com"); + assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_ACCESSKEYID), "id"); + assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_SECRETACCESSKEY), "secret"); + } + + public void testBuildContext() { + RestContext context = newBuilder().buildContext(); + assertEquals(context.getClass(), RestContextImpl.class); + assertEquals(context.getAccount(), "id"); + assertEquals(context.getEndPoint(), URI.create("https://queue.amazonaws.com")); + } + + public void testBuildInjector() { + Injector i = newBuilder().buildInjector(); + assert i.getInstance(Key.get(new TypeLiteral>() { + })) != null; // TODO: test all things taken from context + assert i.getInstance(FormSigner.class) != null; + } + + protected void testAddContextModule() { + List modules = new ArrayList(); + SQSContextBuilder builder = newBuilder(); + builder.addContextModule(modules); + assertEquals(modules.size(), 1); + assertEquals(modules.get(0).getClass(), SQSRestClientModule.class); + } + + private SQSContextBuilder newBuilder() { + SQSContextBuilder builder = new SQSContextBuilder(new SQSPropertiesBuilder("id", "secret") + .build()); + return builder; + } + + protected void addClientModule() { + List modules = new ArrayList(); + SQSContextBuilder builder = newBuilder(); + builder.addClientModule(modules); + assertEquals(modules.size(), 1); + assertEquals(modules.get(0).getClass(), SQSRestClientModule.class); + } + +} diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java new file mode 100644 index 0000000000..05b9816936 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java @@ -0,0 +1,92 @@ +package org.jclouds.aws.sqs.config; + +import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +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.aws.sqs.reference.SQSConstants; +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.http.handlers.DelegatingErrorHandler; +import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.util.Jsr330; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "sqs.SQSRestClientModuleTest") +public class SQSRestClientModuleTest { + + Injector createInjector() { + return Guice.createInjector(new SQSRestClientModule(), new ExecutorServiceModule( + sameThreadExecutor()), new ParserModule(), new AbstractModule() { + @Override + protected void configure() { + bindConstant().annotatedWith(Jsr330.named(SQSConstants.PROPERTY_AWS_ACCESSKEYID)).to( + "user"); + bindConstant().annotatedWith(Jsr330.named(SQSConstants.PROPERTY_AWS_SECRETACCESSKEY)) + .to("key"); + bindConstant() + .annotatedWith(Jsr330.named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1)).to( + "http://default"); + bindConstant() + .annotatedWith(Jsr330.named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_WEST_1)).to( + "http://uswest"); + bindConstant() + .annotatedWith(Jsr330.named(SQSConstants.PROPERTY_SQS_ENDPOINT_EU_WEST_1)).to( + "http://euwest"); + bindConstant().annotatedWith(Jsr330.named(SQSConstants.PROPERTY_AWS_EXPIREINTERVAL)) + .to(30); + } + }); + } + + @Test + void testServerErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); + } + + @Test + void testRegions() { + Map regionMap = createInjector().getInstance(new Key>() { + }); + assertEquals(regionMap, ImmutableMap. of(Region.US_EAST_1, URI + .create("http://default"), Region.US_WEST_1, URI.create("http://uswest"), + Region.EU_WEST_1, URI.create("http://euwest"))); + } + + @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); + } + +} \ No newline at end of file diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/options/CreateQueueOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/options/CreateQueueOptionsTest.java new file mode 100644 index 0000000000..461e063ecb --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/options/CreateQueueOptionsTest.java @@ -0,0 +1,48 @@ +package org.jclouds.aws.sqs.options; + +import static org.jclouds.aws.sqs.options.CreateQueueOptions.Builder.defaultVisibilityTimeout; +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 CreateQueueOptions and CreateQueueOptions.Builder.* + * + * @author Adrian Cole + */ +public class CreateQueueOptionsTest { + + @Test + public void testAssignability() { + assert HttpRequestOptions.class.isAssignableFrom(CreateQueueOptions.class); + assert !String.class.isAssignableFrom(CreateQueueOptions.class); + } + + @Test + public void testTimeout() { + CreateQueueOptions options = new CreateQueueOptions(); + options.defaultVisibilityTimeout(1); + assertEquals(options.buildFormParameters().get("DefaultVisibilityTimeout"), Collections + .singletonList("1")); + } + + @Test + public void testNullTimeout() { + CreateQueueOptions options = new CreateQueueOptions(); + assertEquals(options.buildFormParameters().get("DefaultVisibilityTimeout"), Collections.EMPTY_LIST); + } + + @Test + public void testTimeoutStatic() { + CreateQueueOptions options = defaultVisibilityTimeout(1); + assertEquals(options.buildFormParameters().get("DefaultVisibilityTimeout"), Collections + .singletonList("1")); + } + + public void testNoTimeout() { + defaultVisibilityTimeout(0); + } +} diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/options/ListQueuesOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/options/ListQueuesOptionsTest.java new file mode 100644 index 0000000000..80007feb96 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/options/ListQueuesOptionsTest.java @@ -0,0 +1,48 @@ +package org.jclouds.aws.sqs.options; + +import static org.jclouds.aws.sqs.options.ListQueuesOptions.Builder.queuePrefix; +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 ListQueuesOptions and ListQueuesOptions.Builder.* + * + * @author Adrian Cole + */ +public class ListQueuesOptionsTest { + + @Test + public void testAssignability() { + assert HttpRequestOptions.class.isAssignableFrom(ListQueuesOptions.class); + assert !String.class.isAssignableFrom(ListQueuesOptions.class); + } + + @Test + public void testPrefix() { + ListQueuesOptions options = new ListQueuesOptions(); + options.queuePrefix("test"); + assertEquals(options.buildFormParameters().get("QueueNamePrefix"), Collections + .singletonList("test")); + } + + @Test + public void testNullPrefix() { + ListQueuesOptions options = new ListQueuesOptions(); + assertEquals(options.buildFormParameters().get("QueueNamePrefix"), Collections.EMPTY_LIST); + } + + @Test + public void testPrefixStatic() { + ListQueuesOptions options = queuePrefix("test"); + assertEquals(options.buildFormParameters().get("QueueNamePrefix"), Collections + .singletonList("test")); + } + + public void testNoPrefix() { + queuePrefix(null); + } +} diff --git a/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java b/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java index 7932474744..47cbd4523a 100755 --- a/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java +++ b/aws/demos/createlamp/src/main/java/org/jclouds/aws/ec2/demos/createlamp/MainApp.java @@ -27,6 +27,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2ContextFactory; @@ -34,7 +35,6 @@ import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.KeyPair; -import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.predicates.InstanceStateRunning; diff --git a/aws/demos/pom.xml b/aws/demos/pom.xml index 4fadd9a88c..522269fc4e 100644 --- a/aws/demos/pom.xml +++ b/aws/demos/pom.xml @@ -35,6 +35,7 @@ googleappengine --> createlamp + speedtest-sqs createandlistbuckets diff --git a/aws/demos/speedtest-sqs/README.txt b/aws/demos/speedtest-sqs/README.txt new file mode 100755 index 0000000000..78c0a6da1b --- /dev/null +++ b/aws/demos/speedtest-sqs/README.txt @@ -0,0 +1,24 @@ +==== + + Copyright (C) 2009 Cloud Conscious, LLC. + + ==================================================================== + 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 is a simple example command line client that creates a queue in all regions, then tracks performance of it +# 1. execute 'mvn install' to build the sample +# 2. invoke the jar, passing your aws credentials and the bucket you wish to create +# ex. +# java -jar target/jclouds-speedtest-sqs-jar-with-dependencies.jar accesskey secretkey queueName messageCount diff --git a/aws/demos/speedtest-sqs/pom.xml b/aws/demos/speedtest-sqs/pom.xml new file mode 100644 index 0000000000..6079a4f0ca --- /dev/null +++ b/aws/demos/speedtest-sqs/pom.xml @@ -0,0 +1,83 @@ + + + + + 4.0.0 + + org.jclouds + jclouds-aws-demos-project + 1.0-SNAPSHOT + + jclouds-speedtest-sqs + tests speed of sqs across regions + creates a queue in all amazon regions and then tests performance against it + + + ${project.groupId} + jclouds-enterprise + ${project.version} + + + + + ${project.artifactId} + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.jclouds.aws.sqs.SpeedTest + + + + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + org.jclouds.aws.sqs.SpeedTest + + + + + + make-assembly + package + + single + + + + + + + + + diff --git a/aws/demos/speedtest-sqs/src/main/java/org/jclouds/aws/sqs/SpeedTest.java b/aws/demos/speedtest-sqs/src/main/java/org/jclouds/aws/sqs/SpeedTest.java new file mode 100755 index 0000000000..314e08fa3d --- /dev/null +++ b/aws/demos/speedtest-sqs/src/main/java/org/jclouds/aws/sqs/SpeedTest.java @@ -0,0 +1,167 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.sqs; + +import static org.jclouds.aws.sqs.options.ListQueuesOptions.Builder.queuePrefix; + +import java.util.Set; +import java.util.SortedSet; +import java.util.Map.Entry; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.domain.Queue; +import org.jclouds.enterprise.config.EnterpriseConfigurationModule; +import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.RestContext; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * This the Main class of an Application that tests your response time to amazon SQS. + * + * Usage is: java org.jclouds.aws.sqs.SpeedTest \"accesskeyid\" \"secretkey\" \"queueName\" + * \"messageCount\" + * + * @author Adrian Cole + */ +public class SpeedTest { + + public static int PARAMETERS = 4; + public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: \"accesskeyid\" \"secretkey\" \"queueName\" \"messageCount\" "; + + public static void main(String[] args) throws InterruptedException { + + if (args.length < PARAMETERS) + throw new IllegalArgumentException(INVALID_SYNTAX); + + // Args + String accesskeyid = args[0]; + String secretkey = args[1]; + String queueName = args[2]; + int messageCount = Integer.parseInt(args[3]); + + RestContext nullLoggingDefaultContext = SQSContextFactory + .createContext(System.getProperties(), accesskeyid, secretkey, + new NullLoggingModule()); + + RestContext nullLoggingEnterpriseContext = SQSContextFactory + .createContext(System.getProperties(), accesskeyid, secretkey, + new NullLoggingModule(), new EnterpriseConfigurationModule()); + try { + Set queues = Sets.newHashSet(); + if (purgeQueues(queueName, nullLoggingDefaultContext)) { + System.out.printf("pausing 60 seconds before recreating queues%n"); + Thread.sleep(60 * 1000); + } + createQueues(queueName, nullLoggingDefaultContext, queues); + runTests(messageCount, nullLoggingDefaultContext, nullLoggingEnterpriseContext, queues); + } finally { + purgeQueues(queueName, nullLoggingDefaultContext); + // Close connectons + nullLoggingDefaultContext.close(); + nullLoggingEnterpriseContext.close(); + System.exit(0); + } + + } + + private static void runTests(int messageCount, + RestContext nullLoggingDefaultContext, + RestContext nullLoggingEnterpriseContext, Set queues) + throws InterruptedException { + String message = "1"; + long timeOut = messageCount * 200; // minimum rate should be at least 5/second + + for (Entry> entry : ImmutableMap + .> of("standard", + nullLoggingDefaultContext, "enterprise", nullLoggingEnterpriseContext) + .entrySet()) { + for (Queue queue : queues) { + + int complete = 0; + int errors = 0; + Set> responses = Sets.newHashSet(); + + long start = System.currentTimeMillis(); + for (int i = 0; i < messageCount; i++) { + responses.add(entry.getValue().getAsyncApi().sendMessage(queue, message)); + } + do { + Set> retries = Sets.newHashSet(); + for (ListenableFuture response : responses) { + try { + response.get(100, TimeUnit.MILLISECONDS); + complete++; + } catch (ExecutionException e) { + System.err.println(e.getMessage()); + errors++; + } catch (TimeoutException e) { + retries.add(response); + } + } + responses = Sets.newHashSet(retries); + } while (responses.size() > 0 && System.currentTimeMillis() < start + timeOut); + long duration = System.currentTimeMillis() - start; + if (duration > timeOut) + System.out.printf("TIMEOUT: context: %s, region: %s, rate: %f messages/second%n", + entry.getKey(), queue.getRegion(), ((double) complete) + / (duration / 1000.0)); + else + System.out.printf("COMPLETE: context: %s, region: %s, rate: %f messages/second%n", + entry.getKey(), queue.getRegion(), ((double) complete) + / (duration / 1000.0)); + System.out.println("pausing 5 seconds before the next run"); + Thread.sleep(5000);// let the network quiet down + } + } + } + + private static void createQueues(String queueName, + RestContext nullLoggingDefaultContext, Set queues) { + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { + System.out.printf("creating queue: %s in region %s%n", queueName, region); + queues.add(nullLoggingDefaultContext.getApi().createQueueInRegion(region, queueName)); + } + } + + private static boolean purgeQueues(String queueName, + RestContext nullLoggingDefaultContext) { + boolean deleted = false; + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { + try { + SortedSet result = Sets.newTreeSet(nullLoggingDefaultContext.getApi() + .listQueuesInRegion(region, queuePrefix(queueName))); + if (result.size() >= 1) { + nullLoggingDefaultContext.getApi().deleteQueue(result.last()); + System.out.printf("deleted queue: %s in region %s%n", queueName, region); + deleted = true; + } + } catch (Exception e) { + + } + } + return deleted; + } +} diff --git a/aws/pom.xml b/aws/pom.xml index 7f169058de..e1e06c6ce5 100644 --- a/aws/pom.xml +++ b/aws/pom.xml @@ -48,6 +48,12 @@ ${project.version} test + + ${project.groupId} + jclouds-enterprise + ${project.version} + test + ${project.groupId} jclouds-jsch