diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosAsyncBlobStore.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosAsyncBlobStore.java index 346eb00133..64699dc821 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosAsyncBlobStore.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosAsyncBlobStore.java @@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.Futures.compose; import java.net.URI; +import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; @@ -53,6 +54,7 @@ import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.concurrent.ConcurrentUtils; +import org.jclouds.domain.Location; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.options.GetOptions; @@ -78,13 +80,15 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { @Inject AtmosAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + Location defaultLocation, Map locations, + AtmosStorageAsyncClient async, AtmosStorageClient sync, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, BlobStoreListOptionsToListOptions container2ContainerListOptions, DirectoryEntryListToResourceMetadataList container2ResourceList, EncryptionService encryptionService, BlobToHttpGetOptions blob2ObjectGetOptions, Provider fetchBlobMetadataProvider) { - super(context, blobUtils, service); + super(context, blobUtils, service, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.sync = checkNotNull(sync, "sync"); this.async = checkNotNull(async, "async"); @@ -119,7 +123,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { * Note location is ignored */ @Override - public ListenableFuture createContainerInLocation(String location, String container) { + public ListenableFuture createContainerInLocation(Location location, String container) { return compose(async.createDirectory(container), new Function() { public Boolean apply(URI from) { diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosBlobStore.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosBlobStore.java index e8fa4b9157..2ed7b87599 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosBlobStore.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/AtmosBlobStore.java @@ -20,6 +20,8 @@ package org.jclouds.atmosonline.saas.blobstore; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Map; + import javax.inject.Inject; import javax.inject.Provider; import javax.inject.Singleton; @@ -42,6 +44,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.domain.Location; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.options.GetOptions; @@ -61,13 +64,14 @@ public class AtmosBlobStore extends BaseBlobStore { private final Provider fetchBlobMetadataProvider; @Inject - AtmosBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, AtmosStorageClient sync, + AtmosBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, Location defaultLocation, + Map locations, AtmosStorageClient sync, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, BlobStoreListOptionsToListOptions container2ContainerListOptions, DirectoryEntryListToResourceMetadataList container2ResourceList, EncryptionService encryptionService, BlobToHttpGetOptions blob2ObjectGetOptions, Provider fetchBlobMetadataProvider) { - super(context, blobUtils); + super(context, blobUtils, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.sync = checkNotNull(sync, "sync"); this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions, @@ -107,7 +111,7 @@ public class AtmosBlobStore extends BaseBlobStore { * directory name */ @Override - public boolean createContainerInLocation(String location, String container) { + public boolean createContainerInLocation(Location location, String container) { sync.createDirectory(container); return true; } diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreContextModule.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreContextModule.java index d77a8d468f..85acabd597 100755 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreContextModule.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreContextModule.java @@ -18,6 +18,10 @@ */ package org.jclouds.atmosonline.saas.blobstore.config; +import java.util.Map; + +import javax.inject.Singleton; + import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient; import org.jclouds.atmosonline.saas.AtmosStorageClient; import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore; @@ -31,7 +35,12 @@ import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -56,4 +65,15 @@ public class AtmosBlobStoreContextModule extends AtmosStorageContextModule { bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class); } + @Provides + @Singleton + Location getLocation() { + return new LocationImpl(LocationScope.ZONE, "UNKNOWN", "TODO", null); + } + + @Provides + @Singleton + Map provideLocations(Location location) { + return ImmutableMap.of(location.getId(), location); + } } diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/DirectoryEntryListToResourceMetadataList.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/DirectoryEntryListToResourceMetadataList.java index 81b473ac0c..cef8291a51 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/DirectoryEntryListToResourceMetadataList.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/DirectoryEntryListToResourceMetadataList.java @@ -18,6 +18,7 @@ */ package org.jclouds.atmosonline.saas.blobstore.functions; +import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.atmosonline.saas.domain.BoundedSet; @@ -29,6 +30,7 @@ import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.domain.internal.BlobMetadataImpl; import org.jclouds.blobstore.domain.internal.PageSetImpl; import org.jclouds.blobstore.domain.internal.StorageMetadataImpl; +import org.jclouds.domain.Location; import com.google.common.base.Function; import com.google.common.collect.Iterables; @@ -40,6 +42,12 @@ import com.google.common.collect.Maps; @Singleton public class DirectoryEntryListToResourceMetadataList implements Function, PageSet> { + private Location defaultLocation; + + @Inject + DirectoryEntryListToResourceMetadataList(Location defaultLocation) { + this.defaultLocation = defaultLocation; + } public PageSet apply(BoundedSet from) { @@ -51,12 +59,12 @@ public class DirectoryEntryListToResourceMetadataList implements : StorageType.BLOB; if (type == StorageType.FOLDER) return new StorageMetadataImpl(type, from.getObjectID(), from - .getObjectName(), null, null, null, null, null, Maps + .getObjectName(), defaultLocation, null, null, null, null, Maps . newHashMap()); else - return new BlobMetadataImpl(from.getObjectID(), from.getObjectName(), null, - null, null, null, null, Maps. newHashMap(), null, - null); + return new BlobMetadataImpl(from.getObjectID(), from.getObjectName(), + defaultLocation, null, null, null, null, Maps + . newHashMap(), null, null); } }), from.getToken()); diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/internal/StubAtmosStorageAsyncClient.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/internal/StubAtmosStorageAsyncClient.java index 5ad7b6713b..a08f3b31c0 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/internal/StubAtmosStorageAsyncClient.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/internal/StubAtmosStorageAsyncClient.java @@ -94,7 +94,7 @@ public class StubAtmosStorageAsyncClient implements AtmosStorageAsyncClient { container = directoryName; path = null; } - return Futures.compose(blobStore.createContainerInLocation("default", container), + return Futures.compose(blobStore.createContainerInLocation(null, container), new Function() { public URI apply(Boolean from) { diff --git a/aws/core/src/main/java/org/jclouds/aws/domain/Region.java b/aws/core/src/main/java/org/jclouds/aws/domain/Region.java index 7376eb49ff..f5846b25df 100644 --- a/aws/core/src/main/java/org/jclouds/aws/domain/Region.java +++ b/aws/core/src/main/java/org/jclouds/aws/domain/Region.java @@ -33,11 +33,6 @@ import com.google.common.base.CaseFormat; */ public enum Region { - /** - * Allow the default region to be chosen based on the user-configured endpoint. - */ - DEFAULT, - /** * Region returned is unknown. */ diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index 96c8db569b..6023832cae 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -297,7 +297,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { @Provides @Singleton protected Map provideImages(final EC2Client sync, - Map regionMap, LogHolder holder, + @EC2 Map regionMap, LogHolder holder, Function indexer, @Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, ImageParser parser) throws InterruptedException, ExecutionException, TimeoutException { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateNewKeyPair.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateNewKeyPair.java index 3972beea07..38f88c0ff2 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateNewKeyPair.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateNewKeyPair.java @@ -19,6 +19,8 @@ package org.jclouds.aws.ec2.compute.functions; +import static com.google.common.base.Preconditions.checkNotNull; + import java.security.SecureRandom; import javax.annotation.Resource; @@ -58,6 +60,8 @@ public class CreateNewKeyPair implements Function { } private KeyPair createNewKeyPairInRegion(Region region, String tag) { + checkNotNull(region, "region"); + checkNotNull(tag, "tag"); logger.debug(">> creating keyPair region(%s) tag(%s)", region, tag); KeyPair keyPair = null; while (keyPair == null) { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateSecurityGroupIfNeeded.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateSecurityGroupIfNeeded.java index a74105c706..0b616b3e85 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateSecurityGroupIfNeeded.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/CreateSecurityGroupIfNeeded.java @@ -1,5 +1,7 @@ package org.jclouds.aws.ec2.compute.functions; +import static com.google.common.base.Preconditions.checkNotNull; + import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; @@ -36,6 +38,8 @@ public class CreateSecurityGroupIfNeeded implements Function> creating securityGroup region(%s) name(%s)", region, name); try { ec2Client.getSecurityGroupServices().createSecurityGroupInRegion(region, name, name); @@ -47,11 +51,13 @@ public class CreateSecurityGroupIfNeeded implements Function> authorizing securityGroup region(%s) name(%s) permission to itself", region, name); - String myOwnerId = Iterables.get(ec2Client.getSecurityGroupServices() - .describeSecurityGroupsInRegion(region),0).getOwnerId(); - ec2Client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(region, name, - new UserIdGroupPair(myOwnerId, name)); + logger.debug(">> authorizing securityGroup region(%s) name(%s) permission to itself", + region, name); + String myOwnerId = Iterables.get( + ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region), 0) + .getOwnerId(); + ec2Client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(region, name, + new UserIdGroupPair(myOwnerId, name)); logger.debug("<< authorized securityGroup(%s)", name); } catch (AWSResponseException e) { 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 bfe79d8a64..6dd03a491a 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 @@ -115,7 +115,7 @@ public class EC2RestClientModule extends AbstractModule { @Provides @Singleton @EC2 - Region provideCurrentRegion(Map regionMap, @EC2 URI currentUri) { + Region provideCurrentRegion(@EC2 Map regionMap, @EC2 URI currentUri) { ImmutableBiMap map = ImmutableBiMap.copyOf(regionMap).inverse(); Region region = map.get(currentUri); assert region != null : currentUri + " not in " + map; @@ -124,6 +124,7 @@ public class EC2RestClientModule extends AbstractModule { @Provides @Singleton + @EC2 Map provideRegions(AvailabilityZoneAndRegionClient client) { return client.describeRegions(); } @@ -131,7 +132,7 @@ public class EC2RestClientModule extends AbstractModule { @Provides @Singleton Map provideAvailabilityZoneToRegions( - AvailabilityZoneAndRegionClient client, Map regions) { + AvailabilityZoneAndRegionClient client, @EC2 Map regions) { Map map = Maps.newHashMap(); for (Region region : regions.keySet()) { for (AvailabilityZoneInfo zoneInfo : client.describeAvailabilityZonesInRegion(region)) { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/functions/AvailabilityZoneToEndpoint.java b/aws/core/src/main/java/org/jclouds/aws/ec2/functions/AvailabilityZoneToEndpoint.java index 755d4bc308..55a73eeef7 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/functions/AvailabilityZoneToEndpoint.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/functions/AvailabilityZoneToEndpoint.java @@ -25,6 +25,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.AvailabilityZone; import com.google.common.base.Function; @@ -39,7 +40,7 @@ public class AvailabilityZoneToEndpoint implements Function { private final Map regionToEndpoint; @Inject - public AvailabilityZoneToEndpoint(Map regionToEndpoint, + public AvailabilityZoneToEndpoint(@EC2 Map regionToEndpoint, Map availabilityZoneToRegion) { this.regionToEndpoint = regionToEndpoint; this.availabilityZoneToRegion = availabilityZoneToRegion; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/functions/RegionToEndpoint.java b/aws/core/src/main/java/org/jclouds/aws/ec2/functions/RegionToEndpoint.java index feb9515748..37356a49d8 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/functions/RegionToEndpoint.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/functions/RegionToEndpoint.java @@ -39,13 +39,13 @@ public class RegionToEndpoint implements Function { private final URI defaultUri; @Inject - public RegionToEndpoint(Map regionToEndpoint, @EC2 URI defaultUri) { + public RegionToEndpoint(@EC2 Map regionToEndpoint, @EC2 URI defaultUri) { this.regionToEndpoint = regionToEndpoint; this.defaultUri = defaultUri; } public URI apply(Object from) { - return from.equals(Region.DEFAULT) ? defaultUri : regionToEndpoint.get(from); + return from == null ? defaultUri : regionToEndpoint.get(from); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/options/DetachVolumeOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/options/DetachVolumeOptions.java index f7c9175da7..433ac19586 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/options/DetachVolumeOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/options/DetachVolumeOptions.java @@ -32,7 +32,7 @@ import org.jclouds.aws.ec2.options.internal.BaseEC2RequestOptions; * import static org.jclouds.aws.ec2.options.DetachVolumeOptions.Builder.* *

* EC2Client client = // get connection - * client.getElasticBlockStoreServices().detachVolumeInRegion(Region.DEFAULT, id, fromDevice("123125").force()); + * client.getElasticBlockStoreServices().detachVolumeInRegion(null, id, fromDevice("123125").force()); * * * @author Adrian Cole diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIAsyncClient.java index b566b01cc9..777cbc82d3 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIAsyncClient.java @@ -24,6 +24,7 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import java.util.Map; import java.util.Set; +import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -74,7 +75,7 @@ public interface AMIAsyncClient { @FormParams(keys = ACTION, values = "DescribeImages") @XMLResponseParser(DescribeImagesResponseHandler.class) ListenableFuture> describeImagesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, DescribeImagesOptions... options); /** @@ -85,7 +86,7 @@ public interface AMIAsyncClient { @FormParams(keys = ACTION, values = "CreateImage") @XMLResponseParser(ImageIdHandler.class) ListenableFuture createImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("Name") String name, @FormParam("InstanceId") String instanceId, CreateImageOptions... options); @@ -96,7 +97,7 @@ public interface AMIAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "DeregisterImage") ListenableFuture deregisterImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("ImageId") String imageId); /** @@ -107,7 +108,7 @@ public interface AMIAsyncClient { @FormParams(keys = ACTION, values = "RegisterImage") @XMLResponseParser(ImageIdHandler.class) ListenableFuture registerImageFromManifestInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("Name") String imageName, @FormParam("ImageLocation") String pathToManifest, RegisterImageOptions... options); @@ -120,7 +121,7 @@ public interface AMIAsyncClient { "RegisterImage", "/dev/sda1", "/dev/sda1" }) @XMLResponseParser(ImageIdHandler.class) ListenableFuture registerUnixImageBackedByEbsInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("Name") String imageName, @FormParam("BlockDeviceMapping.0.Ebs.SnapshotId") String ebsSnapshotId, RegisterImageBackedByEbsOptions... options); @@ -132,7 +133,7 @@ public interface AMIAsyncClient { @Path("/") @FormParams(keys = { ACTION, "Attribute" }, values = { "ResetImageAttribute", "launchPermission" }) ListenableFuture resetLaunchPermissionsOnImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("ImageId") String imageId); /** @@ -143,7 +144,7 @@ public interface AMIAsyncClient { @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifyImageAttribute", "add", "launchPermission" }) ListenableFuture addLaunchPermissionsToImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindUserIdsToIndexedFormParams.class) Iterable userIds, @BinderParam(BindUserGroupsToIndexedFormParams.class) Iterable userGroups, @FormParam("ImageId") String imageId); @@ -156,7 +157,7 @@ public interface AMIAsyncClient { @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifyImageAttribute", "remove", "launchPermission" }) ListenableFuture removeLaunchPermissionsFromImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindUserIdsToIndexedFormParams.class) Iterable userIds, @BinderParam(BindUserGroupsToIndexedFormParams.class) Iterable userGroups, @FormParam("ImageId") String imageId); @@ -170,7 +171,7 @@ public interface AMIAsyncClient { "launchPermission" }) @XMLResponseParser(PermissionHandler.class) ListenableFuture getLaunchPermissionForImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("ImageId") String imageId); /** @@ -181,7 +182,7 @@ public interface AMIAsyncClient { @FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeImageAttribute", "productCodes" }) @XMLResponseParser(ProductCodesHandler.class) ListenableFuture> getProductCodesForImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("ImageId") String imageId); /** @@ -193,7 +194,7 @@ public interface AMIAsyncClient { "blockDeviceMapping" }) @XMLResponseParser(BlockDeviceMappingHandler.class) ListenableFuture> getBlockDeviceMappingsForImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("ImageId") String imageId); /** @@ -204,7 +205,7 @@ public interface AMIAsyncClient { @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifyImageAttribute", "add", "productCodes" }) ListenableFuture addProductCodesToImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindProductCodesToIndexedFormParams.class) Iterable productCodes, @FormParam("ImageId") String imageId); @@ -216,7 +217,7 @@ public interface AMIAsyncClient { @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifyImageAttribute", "remove", "productCodes" }) ListenableFuture removeProductCodesFromImageInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindProductCodesToIndexedFormParams.class) Iterable productCodes, @FormParam("ImageId") String imageId); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIClient.java index ffea2bec28..66d739213f 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AMIClient.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.Permission; @@ -56,7 +58,7 @@ public interface AMIClient { * @see DescribeImagesOptions */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) - Set describeImagesInRegion(Region region, DescribeImagesOptions... options); + Set describeImagesInRegion(@Nullable Region region, DescribeImagesOptions... options); /** * Returns the Product Codes of an image. @@ -72,7 +74,7 @@ public interface AMIClient { * /> * @see DescribeImagesOptions */ - Set getProductCodesForImageInRegion(Region region, String imageId); + Set getProductCodesForImageInRegion(@Nullable Region region, String imageId); /** * Returns a map of device name to block device for the image. @@ -88,7 +90,7 @@ public interface AMIClient { * /> * @see DescribeImagesOptions */ - Map getBlockDeviceMappingsForImageInRegion(Region region, String imageId); + Map getBlockDeviceMappingsForImageInRegion(@Nullable Region region, String imageId); /** * Creates an AMI that uses an Amazon EBS root device from a "running" or "stopped" instance. @@ -112,7 +114,7 @@ public interface AMIClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateImage.html" * /> */ - String createImageInRegion(Region region, String name, String instanceId, + String createImageInRegion(@Nullable Region region, String name, String instanceId, CreateImageOptions... options); /** @@ -132,7 +134,7 @@ public interface AMIClient { * @see */ - void deregisterImageInRegion(Region region, String imageId); + void deregisterImageInRegion(@Nullable Region region, String imageId); /** * Registers an AMI with Amazon EC2. Images must be registered before they can be launched. To @@ -162,7 +164,7 @@ public interface AMIClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-RegisterImage.html" * /> */ - String registerImageFromManifestInRegion(Region region, String name, String pathToManifest, + String registerImageFromManifestInRegion(@Nullable Region region, String name, String pathToManifest, RegisterImageOptions... options); /** @@ -197,7 +199,7 @@ public interface AMIClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-RegisterImage.html" * /> */ - String registerUnixImageBackedByEbsInRegion(Region region, String name, String ebsSnapshotId, + String registerUnixImageBackedByEbsInRegion(@Nullable Region region, String name, String ebsSnapshotId, RegisterImageBackedByEbsOptions... options); /** @@ -214,7 +216,7 @@ public interface AMIClient { * /> * @see DescribeImagesOptions */ - Permission getLaunchPermissionForImageInRegion(Region region, String imageId); + Permission getLaunchPermissionForImageInRegion(@Nullable Region region, String imageId); /** * Adds {@code launchPermission}s to an AMI. @@ -234,7 +236,7 @@ public interface AMIClient { * @see */ - void addLaunchPermissionsToImageInRegion(Region region, Iterable userIds, + void addLaunchPermissionsToImageInRegion(@Nullable Region region, Iterable userIds, Iterable userGroups, String imageId); /** @@ -251,7 +253,7 @@ public interface AMIClient { * @see */ - void resetLaunchPermissionsOnImageInRegion(Region region, String imageId); + void resetLaunchPermissionsOnImageInRegion(@Nullable Region region, String imageId); /** * Removes {@code launchPermission}s from an AMI. @@ -271,7 +273,7 @@ public interface AMIClient { * @see */ - void removeLaunchPermissionsFromImageInRegion(Region region, Iterable userIds, + void removeLaunchPermissionsFromImageInRegion(@Nullable Region region, Iterable userIds, Iterable userGroups, String imageId); /** @@ -290,7 +292,7 @@ public interface AMIClient { * @see */ - void addProductCodesToImageInRegion(Region region, Iterable productCodes, String imageId); + void addProductCodesToImageInRegion(@Nullable Region region, Iterable productCodes, String imageId); /** * Removes {@code productCode}s from an AMI. @@ -308,6 +310,6 @@ public interface AMIClient { * @see */ - void removeProductCodesFromImageInRegion(Region region, Iterable productCodes, + void removeProductCodesFromImageInRegion(@Nullable Region region, Iterable productCodes, String imageId); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClient.java index dfb6ff0f04..a52956e6fa 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClient.java @@ -25,6 +25,7 @@ import java.net.URI; import java.util.Map; import java.util.Set; +import javax.annotation.Nullable; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -65,7 +66,7 @@ public interface AvailabilityZoneAndRegionAsyncClient { @FormParams(keys = ACTION, values = "DescribeAvailabilityZones") @XMLResponseParser(DescribeAvailabilityZonesResponseHandler.class) ListenableFuture> describeAvailabilityZonesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, DescribeAvailabilityZonesOptions... options); /** diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClient.java index ed2714ec99..6324116a75 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionClient.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo; import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions; @@ -47,7 +49,7 @@ public interface AvailabilityZoneAndRegionClient { * @see */ - Set describeAvailabilityZonesInRegion(Region region, + Set describeAvailabilityZonesInRegion(@Nullable Region region, DescribeAvailabilityZonesOptions... options); /** diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClient.java index 5ee34feee4..c73d116aaf 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClient.java @@ -23,6 +23,7 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import java.util.Set; +import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -111,7 +112,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = ACTION, values = "DescribeVolumes") @XMLResponseParser(DescribeVolumesResponseHandler.class) ListenableFuture> describeVolumesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindVolumeIdsToIndexedFormParams.class) String... volumeIds); /** @@ -121,7 +122,7 @@ public interface ElasticBlockStoreAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "DeleteVolume") ListenableFuture deleteVolumeInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("VolumeId") String volumeId); /** @@ -132,7 +133,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = ACTION, values = "DetachVolume") @ExceptionParser(ReturnVoidOnVolumeAvailable.class) ListenableFuture detachVolumeInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("VolumeId") String volumeId, @FormParam("Force") boolean force, DetachVolumeOptions... options); @@ -144,7 +145,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = ACTION, values = "AttachVolume") @XMLResponseParser(AttachmentHandler.class) ListenableFuture attachVolumeInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("VolumeId") String volumeId, @FormParam("InstanceId") String instanceId, @FormParam("Device") String device); @@ -156,7 +157,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = ACTION, values = "CreateSnapshot") @XMLResponseParser(SnapshotHandler.class) ListenableFuture createSnapshotInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("VolumeId") String volumeId, CreateSnapshotOptions... options); /** @@ -167,7 +168,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = ACTION, values = "DescribeSnapshots") @XMLResponseParser(DescribeSnapshotsResponseHandler.class) ListenableFuture> describeSnapshotsInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, DescribeSnapshotsOptions... options); /** @@ -177,7 +178,7 @@ public interface ElasticBlockStoreAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "DeleteSnapshot") ListenableFuture deleteSnapshotInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("SnapshotId") String snapshotId); /** @@ -188,7 +189,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifySnapshotAttribute", "add", "createVolumePermission" }) ListenableFuture addCreateVolumePermissionsToSnapshotInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindUserIdsToIndexedFormParams.class) Iterable userIds, @BinderParam(BindUserGroupsToIndexedFormParams.class) Iterable userGroups, @FormParam("SnapshotId") String snapshotId); @@ -201,7 +202,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifySnapshotAttribute", "remove", "createVolumePermission" }) ListenableFuture removeCreateVolumePermissionsFromSnapshotInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindUserIdsToIndexedFormParams.class) Iterable userIds, @BinderParam(BindUserGroupsToIndexedFormParams.class) Iterable userGroups, @FormParam("SnapshotId") String snapshotId); @@ -215,7 +216,7 @@ public interface ElasticBlockStoreAsyncClient { "createVolumePermission" }) @XMLResponseParser(PermissionHandler.class) ListenableFuture getCreateVolumePermissionForSnapshotInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("SnapshotId") String snapshotId); /** @@ -226,7 +227,7 @@ public interface ElasticBlockStoreAsyncClient { @FormParams(keys = { ACTION, "Attribute" }, values = { "ResetSnapshotAttribute", "createVolumePermission" }) ListenableFuture resetCreateVolumePermissionsOnSnapshotInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("SnapshotId") String snapshotId); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClient.java index 50594aaefd..bf205d0228 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticBlockStoreClient.java @@ -21,6 +21,8 @@ package org.jclouds.aws.ec2.services; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.AvailabilityZone; @@ -136,7 +138,7 @@ public interface ElasticBlockStoreClient { * @see */ - Set describeVolumesInRegion(Region region, String... volumeIds); + Set describeVolumesInRegion(@Nullable Region region, String... volumeIds); /** * Deletes an Amazon EBS volume that you own. For more information about Amazon EBS, go to the @@ -157,7 +159,7 @@ public interface ElasticBlockStoreClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteVolume.html" * /> */ - void deleteVolumeInRegion(Region region, String volumeId); + void deleteVolumeInRegion(@Nullable Region region, String volumeId); /** * Attaches an Amazon EBS volume to a running instance and exposes it as the specified device. @@ -197,7 +199,7 @@ public interface ElasticBlockStoreClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DetachVolume.html" * /> */ - void detachVolumeInRegion(Region region, String volumeId, boolean force, + void detachVolumeInRegion(@Nullable Region region, String volumeId, boolean force, DetachVolumeOptions... options); /** @@ -230,7 +232,7 @@ public interface ElasticBlockStoreClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AttachVolume.html" * /> */ - Attachment attachVolumeInRegion(Region region, String volumeId, String instanceId, String device); + Attachment attachVolumeInRegion(@Nullable Region region, String volumeId, String instanceId, String device); /** * Creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots @@ -267,7 +269,7 @@ public interface ElasticBlockStoreClient { * @see */ - Snapshot createSnapshotInRegion(Region region, String volumeId, CreateSnapshotOptions... options); + Snapshot createSnapshotInRegion(@Nullable Region region, String volumeId, CreateSnapshotOptions... options); /** * Returns information about Amazon EBS snapshots available to the user. Information returned @@ -328,7 +330,7 @@ public interface ElasticBlockStoreClient { * @see */ - Set describeSnapshotsInRegion(Region region, DescribeSnapshotsOptions... options); + Set describeSnapshotsInRegion(@Nullable Region region, DescribeSnapshotsOptions... options); /** * Deletes a snapshot of an Amazon EBS volume that you own. For more information, go to the @@ -345,7 +347,7 @@ public interface ElasticBlockStoreClient { * @see */ - void deleteSnapshotInRegion(Region region, String snapshotId); + void deleteSnapshotInRegion(@Nullable Region region, String snapshotId); /** * Returns the {@link Permission}s of an snapshot. @@ -361,7 +363,7 @@ public interface ElasticBlockStoreClient { * /> * @see DescribeSnapshotsOptions */ - Permission getCreateVolumePermissionForSnapshotInRegion(Region region, String snapshotId); + Permission getCreateVolumePermissionForSnapshotInRegion(@Nullable Region region, String snapshotId); /** * Adds {@code createVolumePermission}s to an EBS snapshot. @@ -382,7 +384,7 @@ public interface ElasticBlockStoreClient { * @see */ - void addCreateVolumePermissionsToSnapshotInRegion(Region region, Iterable userIds, + void addCreateVolumePermissionsToSnapshotInRegion(@Nullable Region region, Iterable userIds, Iterable userGroups, String snapshotId); /** @@ -400,7 +402,7 @@ public interface ElasticBlockStoreClient { * @see */ - void resetCreateVolumePermissionsOnSnapshotInRegion(Region region, String snapshotId); + void resetCreateVolumePermissionsOnSnapshotInRegion(@Nullable Region region, String snapshotId); /** * Removes {@code createVolumePermission}s from an EBS snapshot. @@ -421,6 +423,6 @@ public interface ElasticBlockStoreClient { * @see */ - void removeCreateVolumePermissionsFromSnapshotInRegion(Region region, Iterable userIds, + void removeCreateVolumePermissionsFromSnapshotInRegion(@Nullable Region region, Iterable userIds, Iterable userGroups, String snapshotId); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClient.java index 00eccf2dba..5c0a9e796a 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClient.java @@ -24,6 +24,7 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import java.net.InetAddress; import java.util.Set; +import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -65,7 +66,7 @@ public interface ElasticIPAddressAsyncClient { @XMLResponseParser(AllocateAddressResponseHandler.class) @FormParams(keys = ACTION, values = "AllocateAddress") ListenableFuture allocateAddressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region); + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region); /** * @see BaseEC2Client#associateAddressInRegion @@ -74,7 +75,7 @@ public interface ElasticIPAddressAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "AssociateAddress") ListenableFuture associateAddressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("PublicIp") @ParamParser(InetAddressToHostAddress.class) InetAddress publicIp, @FormParam("InstanceId") String instanceId); @@ -85,7 +86,7 @@ public interface ElasticIPAddressAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "DisassociateAddress") ListenableFuture disassociateAddressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("PublicIp") @ParamParser(InetAddressToHostAddress.class) InetAddress publicIp); /** @@ -95,7 +96,7 @@ public interface ElasticIPAddressAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "ReleaseAddress") ListenableFuture releaseAddressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("PublicIp") @ParamParser(InetAddressToHostAddress.class) InetAddress publicIp); /** @@ -106,7 +107,7 @@ public interface ElasticIPAddressAsyncClient { @FormParams(keys = ACTION, values = "DescribeAddresses") @XMLResponseParser(DescribeAddressesResponseHandler.class) ListenableFuture> describeAddressesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindInetAddressesToIndexedFormParams.class) InetAddress... publicIps); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressClient.java index 366837b7ae..06e09744db 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticIPAddressClient.java @@ -22,6 +22,8 @@ import java.net.InetAddress; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair; @@ -47,7 +49,7 @@ public interface ElasticIPAddressClient { * @see #disassociateAddress * @see */ - Set describeAddressesInRegion(Region region, + Set describeAddressesInRegion(@Nullable Region region, InetAddress... publicIps); } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceAsyncClient.java index 79b07f0e6a..1eb8e2fba0 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceAsyncClient.java @@ -77,7 +77,7 @@ public interface InstanceAsyncClient { @FormParams(keys = ACTION, values = "DescribeInstances") @XMLResponseParser(DescribeInstancesResponseHandler.class) ListenableFuture> describeInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); /** @@ -88,7 +88,7 @@ public interface InstanceAsyncClient { @FormParams(keys = ACTION, values = "RunInstances") @XMLResponseParser(RunInstancesResponseHandler.class) ListenableFuture runInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @Nullable @BinderParam(IfNotNullBindAvailabilityZoneToFormParam.class) AvailabilityZone nullableAvailabilityZone, @FormParam("ImageId") String imageId, @FormParam("MinCount") int minCount, @FormParam("MaxCount") int maxCount, RunInstancesOptions... options); @@ -100,7 +100,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "RebootInstances") ListenableFuture rebootInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); /** @@ -111,7 +111,7 @@ public interface InstanceAsyncClient { @FormParams(keys = ACTION, values = "TerminateInstances") @XMLResponseParser(InstanceStateChangeHandler.class) ListenableFuture> terminateInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); /** @@ -122,7 +122,7 @@ public interface InstanceAsyncClient { @FormParams(keys = ACTION, values = "StopInstances") @XMLResponseParser(InstanceStateChangeHandler.class) ListenableFuture> stopInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("Force") boolean force, @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); @@ -134,7 +134,7 @@ public interface InstanceAsyncClient { @FormParams(keys = ACTION, values = "StartInstances") @XMLResponseParser(InstanceStateChangeHandler.class) ListenableFuture> startInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); /** @@ -145,7 +145,7 @@ public interface InstanceAsyncClient { @FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute", "userData" }) @XMLResponseParser(UnencodeStringValueHandler.class) ListenableFuture getUserDataForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -157,7 +157,7 @@ public interface InstanceAsyncClient { "rootDeviceName" }) @XMLResponseParser(StringValueHandler.class) ListenableFuture getRootDeviceNameForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -168,7 +168,7 @@ public interface InstanceAsyncClient { @FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute", "ramdisk" }) @XMLResponseParser(StringValueHandler.class) ListenableFuture getRamdiskForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -179,7 +179,7 @@ public interface InstanceAsyncClient { @FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute", "kernel" }) @XMLResponseParser(StringValueHandler.class) ListenableFuture getKernelForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -191,7 +191,7 @@ public interface InstanceAsyncClient { "disableApiTermination" }) @XMLResponseParser(BooleanValueHandler.class) ListenableFuture isApiTerminationDisabledForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -203,7 +203,7 @@ public interface InstanceAsyncClient { "instanceType" }) @XMLResponseParser(InstanceTypeHandler.class) ListenableFuture getInstanceTypeForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -215,7 +215,7 @@ public interface InstanceAsyncClient { "instanceInitiatedShutdownBehavior" }) @XMLResponseParser(InstanceInitiatedShutdownBehaviorHandler.class) ListenableFuture getInstanceInitiatedShutdownBehaviorForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -227,7 +227,7 @@ public interface InstanceAsyncClient { "blockDeviceMapping" }) @XMLResponseParser(BlockDeviceMappingHandler.class) ListenableFuture> getBlockDeviceMappingForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -237,7 +237,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = { ACTION, "Attribute" }, values = { "ResetInstanceAttribute", "ramdisk" }) ListenableFuture resetRamdiskForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -247,7 +247,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = { ACTION, "Attribute" }, values = { "ResetInstanceAttribute", "kernel" }) ListenableFuture resetKernelForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId); /** @@ -257,7 +257,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "userData" }) ListenableFuture setUserDataForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId, @FormParam("Value") @ParamParser(ConvertUnencodedBytesToBase64EncodedString.class) byte[] unencodedData); @@ -268,7 +268,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "ramdisk" }) ListenableFuture setRamdiskForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId, @FormParam("Value") String ramdisk); /** @@ -278,7 +278,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "kernel" }) ListenableFuture setKernelForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId, @FormParam("Value") String kernel); /** @@ -289,7 +289,7 @@ public interface InstanceAsyncClient { @FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "disableApiTermination" }) ListenableFuture setApiTerminationDisabledForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId, @FormParam("Value") boolean apiTerminationDisabled); @@ -300,7 +300,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "instanceType" }) ListenableFuture setInstanceTypeForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId, @FormParam("Value") InstanceType instanceType); @@ -312,7 +312,7 @@ public interface InstanceAsyncClient { @FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "instanceInitiatedShutdownBehavior" }) ListenableFuture setInstanceInitiatedShutdownBehaviorForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId, @FormParam("Value") InstanceInitiatedShutdownBehavior instanceInitiatedShutdownBehavior); @@ -323,7 +323,7 @@ public interface InstanceAsyncClient { @Path("/") @FormParams(keys = { ACTION }, values = { "ModifyInstanceAttribute" }) ListenableFuture setBlockDeviceMappingForInstanceInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId") String instanceId, @BinderParam(BindBlockDeviceMappingToIndexedFormParams.class) BlockDeviceMapping blockDeviceMapping); diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceClient.java index 75d26e5dbe..9f5914ccd3 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/InstanceClient.java @@ -61,7 +61,7 @@ public interface InstanceClient { * @see */ - Set describeInstancesInRegion(Region region, String... instanceIds); + Set describeInstancesInRegion(@Nullable Region region, String... instanceIds); /** * Launches a specified number of instances of an AMI for which you have permissions. @@ -134,7 +134,7 @@ public interface InstanceClient { * /> * @see RunInstancesOptions */ - Reservation runInstancesInRegion(Region region, + Reservation runInstancesInRegion(@Nullable Region region, @Nullable AvailabilityZone nullableAvailabilityZone, String imageId, int minCount, int maxCount, RunInstancesOptions... options); @@ -153,7 +153,7 @@ public interface InstanceClient { * @see */ - Set terminateInstancesInRegion(Region region, String... instanceIds); + Set terminateInstancesInRegion(@Nullable Region region, String... instanceIds); /** * Stops an instance that uses an Amazon EBS volume as its root device. @@ -189,7 +189,7 @@ public interface InstanceClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-StopInstances.html" * /> */ - Set stopInstancesInRegion(Region region, boolean force, + Set stopInstancesInRegion(@Nullable Region region, boolean force, String... instanceIds); /** @@ -214,7 +214,7 @@ public interface InstanceClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-StopInstances.html" * /> */ - void rebootInstancesInRegion(Region region, String... instanceIds); + void rebootInstancesInRegion(@Nullable Region region, String... instanceIds); /** * Starts an instance that uses an Amazon EBS volume as its root device. @@ -244,7 +244,7 @@ public interface InstanceClient { * @see */ - Set startInstancesInRegion(Region region, String... instanceIds); + Set startInstancesInRegion(@Nullable Region region, String... instanceIds); /** * @@ -255,7 +255,7 @@ public interface InstanceClient { * which instance to describe the attribute of * @return unencoded user data */ - String getUserDataForInstanceInRegion(Region region, String instanceId); + String getUserDataForInstanceInRegion(@Nullable Region region, String instanceId); /** * @@ -266,7 +266,7 @@ public interface InstanceClient { * which instance to describe the attribute of * @return The root device name (e.g., /dev/sda1). */ - String getRootDeviceNameForInstanceInRegion(Region region, String instanceId); + String getRootDeviceNameForInstanceInRegion(@Nullable Region region, String instanceId); /** * @@ -277,7 +277,7 @@ public interface InstanceClient { * which instance to describe the attribute of * @return the ID of the RAM disk associated with the AMI. */ - String getRamdiskForInstanceInRegion(Region region, String instanceId); + String getRamdiskForInstanceInRegion(@Nullable Region region, String instanceId); /** * @@ -288,7 +288,7 @@ public interface InstanceClient { * which instance to describe the attribute of * @return the ID of the kernel associated with the AMI. */ - String getKernelForInstanceInRegion(Region region, String instanceId); + String getKernelForInstanceInRegion(@Nullable Region region, String instanceId); /** * @@ -300,7 +300,7 @@ public interface InstanceClient { * @return Specifies whether the instance can be terminated using the APIs. You must modify this * attribute before you can terminate any "locked" instances from the APIs. */ - boolean isApiTerminationDisabledForInstanceInRegion(Region region, String instanceId); + boolean isApiTerminationDisabledForInstanceInRegion(@Nullable Region region, String instanceId); /** * @@ -311,7 +311,7 @@ public interface InstanceClient { * which instance to describe the attribute of * @return The instance type of the instance. */ - InstanceType getInstanceTypeForInstanceInRegion(Region region, String instanceId); + InstanceType getInstanceTypeForInstanceInRegion(@Nullable Region region, String instanceId); /** * @@ -336,7 +336,7 @@ public interface InstanceClient { * @return Describes the mapping that defines native device names to use when exposing virtual * devices. */ - Map getBlockDeviceMappingForInstanceInRegion(Region region, + Map getBlockDeviceMappingForInstanceInRegion(@Nullable Region region, String instanceId); /** @@ -349,7 +349,7 @@ public interface InstanceClient { * which instance to reset the attribute of * @return the ID of the RAM disk associated with the AMI. */ - String resetRamdiskForInstanceInRegion(Region region, String instanceId); + String resetRamdiskForInstanceInRegion(@Nullable Region region, String instanceId); /** * Resets an attribute of an instance to its default value. @@ -361,7 +361,7 @@ public interface InstanceClient { * which instance to reset the attribute of * @return the ID of the kernel associated with the AMI. */ - String resetKernelForInstanceInRegion(Region region, String instanceId); + String resetKernelForInstanceInRegion(@Nullable Region region, String instanceId); /** * Sets the userData used for starting the instance. @@ -383,7 +383,7 @@ public interface InstanceClient { * @see */ - void setUserDataForInstanceInRegion(Region region, String instanceId, byte[] unencodedData); + void setUserDataForInstanceInRegion(@Nullable Region region, String instanceId, byte[] unencodedData); /** * Sets the ramdisk used for starting the instance. @@ -405,7 +405,7 @@ public interface InstanceClient { * @see */ - void setRamdiskForInstanceInRegion(Region region, String instanceId, String ramdisk); + void setRamdiskForInstanceInRegion(@Nullable Region region, String instanceId, String ramdisk); /** * Sets the kernelId used for starting the instance. @@ -427,7 +427,7 @@ public interface InstanceClient { * @see */ - void setKernelForInstanceInRegion(Region region, String instanceId, String kernel); + void setKernelForInstanceInRegion(@Nullable Region region, String instanceId, String kernel); /** * This command works while the instance is running and controls whether or not the api can be @@ -443,7 +443,7 @@ public interface InstanceClient { * @see */ - void setApiTerminationDisabledForInstanceInRegion(Region region, String instanceId, + void setApiTerminationDisabledForInstanceInRegion(@Nullable Region region, String instanceId, boolean apiTerminationDisabled); /** @@ -466,7 +466,7 @@ public interface InstanceClient { * @see */ - void setInstanceTypeForInstanceInRegion(Region region, String instanceId, + void setInstanceTypeForInstanceInRegion(@Nullable Region region, String instanceId, InstanceType instanceType); /** @@ -491,7 +491,7 @@ public interface InstanceClient { * @see */ - void setInstanceInitiatedShutdownBehaviorForInstanceInRegion(Region region, String instanceId, + void setInstanceInitiatedShutdownBehaviorForInstanceInRegion(@Nullable Region region, String instanceId, InstanceInitiatedShutdownBehavior instanceInitiatedShutdownBehavior); /** @@ -538,6 +538,6 @@ public interface InstanceClient { * @see */ - void setBlockDeviceMappingForInstanceInRegion(Region region, String instanceId, + void setBlockDeviceMappingForInstanceInRegion(@Nullable Region region, String instanceId, BlockDeviceMapping blockDeviceMapping); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairAsyncClient.java index aa6aedf884..6be667ee20 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairAsyncClient.java @@ -23,6 +23,7 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import java.util.Set; +import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -62,7 +63,7 @@ public interface KeyPairAsyncClient { @FormParams(keys = ACTION, values = "CreateKeyPair") @XMLResponseParser(KeyPairResponseHandler.class) ListenableFuture createKeyPairInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("KeyName") String keyName); // map resourcenotfoundexception to empty set @@ -74,7 +75,7 @@ public interface KeyPairAsyncClient { @FormParams(keys = ACTION, values = "DescribeKeyPairs") @XMLResponseParser(DescribeKeyPairsResponseHandler.class) ListenableFuture> describeKeyPairsInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindKeyNameToIndexedFormParams.class) String... keyPairNames); /** @@ -84,7 +85,7 @@ public interface KeyPairAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "DeleteKeyPair") ListenableFuture deleteKeyPairInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("KeyName") String keyName); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairClient.java index 375f178ace..e03d98bdde 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/KeyPairClient.java @@ -21,6 +21,8 @@ package org.jclouds.aws.ec2.services; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.concurrent.Timeout; @@ -53,7 +55,7 @@ public interface KeyPairClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateKeyPair.html" * /> */ - KeyPair createKeyPairInRegion(Region region, String keyName); + KeyPair createKeyPairInRegion(@Nullable Region region, String keyName); /** * Returns information about key pairs available to you. If you specify key pairs, information @@ -70,7 +72,7 @@ public interface KeyPairClient { * @see */ - Set describeKeyPairsInRegion(Region region, String... keyPairNames); + Set describeKeyPairsInRegion(@Nullable Region region, String... keyPairNames); /** * Deletes the specified key pair, by removing the public key from Amazon EC2. You must own the @@ -88,6 +90,6 @@ public interface KeyPairClient { * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteKeyPair.html" * /> */ - void deleteKeyPairInRegion(Region region, String keyName); + void deleteKeyPairInRegion(@Nullable Region region, String keyName); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringAsyncClient.java index 49582844f5..a42e575457 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringAsyncClient.java @@ -23,6 +23,7 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import java.util.Map; +import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -61,7 +62,7 @@ public interface MonitoringAsyncClient { @FormParams(keys = ACTION, values = "MonitorInstances") @XMLResponseParser(MonitoringStateHandler.class) ListenableFuture> monitorInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId.0") String instanceId, @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); @@ -73,7 +74,7 @@ public interface MonitoringAsyncClient { @FormParams(keys = ACTION, values = "UnmonitorInstances") @XMLResponseParser(MonitoringStateHandler.class) ListenableFuture> unmonitorInstancesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("InstanceId.0") String instanceId, @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringClient.java index cc27bc6c9b..5956153679 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/MonitoringClient.java @@ -21,6 +21,8 @@ package org.jclouds.aws.ec2.services; import java.util.Map; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.MonitoringState; import org.jclouds.concurrent.Timeout; @@ -48,7 +50,7 @@ public interface MonitoringClient { * @see */ - Map monitorInstancesInRegion(Region region, String instanceId, + Map monitorInstancesInRegion(@Nullable Region region, String instanceId, String... instanceIds); /** @@ -65,6 +67,6 @@ public interface MonitoringClient { * @see */ - Map unmonitorInstancesInRegion(Region region, String instanceId, + Map unmonitorInstancesInRegion(@Nullable Region region, String instanceId, String... instanceIds); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClient.java index d0704b9675..cadeda470e 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClient.java @@ -23,6 +23,7 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import java.util.SortedSet; +import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -65,7 +66,7 @@ public interface SecurityGroupAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "CreateSecurityGroup") ListenableFuture createSecurityGroupInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("GroupName") String name, @FormParam("GroupDescription") String description); /** @@ -76,7 +77,7 @@ public interface SecurityGroupAsyncClient { @FormParams(keys = ACTION, values = "DeleteSecurityGroup") @ExceptionParser(ReturnVoidOnGroupNotFound.class) ListenableFuture deleteSecurityGroupInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("GroupName") String name); /** @@ -87,53 +88,53 @@ public interface SecurityGroupAsyncClient { @FormParams(keys = ACTION, values = "DescribeSecurityGroups") @XMLResponseParser(DescribeSecurityGroupsResponseHandler.class) ListenableFuture> describeSecurityGroupsInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @BinderParam(BindGroupNameToIndexedFormParams.class) String... securityGroupNames); /** - * @see BaseEC2Client#authorizeSecurityGroupIngressInRegion(Region, String,UserIdGroupPair) + * @see BaseEC2Client#authorizeSecurityGroupIngressInRegion(@Nullable Region, String,UserIdGroupPair) */ @POST @Path("/") @FormParams(keys = ACTION, values = "AuthorizeSecurityGroupIngress") ListenableFuture authorizeSecurityGroupIngressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("GroupName") String groupName, @BinderParam(BindUserIdGroupPairToSourceSecurityGroupFormParams.class) UserIdGroupPair sourceSecurityGroup); /** - * @see BaseEC2Client#authorizeSecurityGroupIngressInRegion(Region, + * @see BaseEC2Client#authorizeSecurityGroupIngressInRegion(@Nullable Region, * String,IpProtocol,int,int,String) */ @POST @Path("/") @FormParams(keys = ACTION, values = "AuthorizeSecurityGroupIngress") ListenableFuture authorizeSecurityGroupIngressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("GroupName") String groupName, @FormParam("IpProtocol") IpProtocol ipProtocol, @FormParam("FromPort") int fromPort, @FormParam("ToPort") int toPort, @FormParam("CidrIp") String cidrIp); /** - * @see BaseEC2Client#revokeSecurityGroupIngressInRegion(Region, String,UserIdGroupPair) + * @see BaseEC2Client#revokeSecurityGroupIngressInRegion(@Nullable Region, String,UserIdGroupPair) */ @POST @Path("/") @FormParams(keys = ACTION, values = "RevokeSecurityGroupIngress") ListenableFuture revokeSecurityGroupIngressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("GroupName") String groupName, @BinderParam(BindUserIdGroupPairToSourceSecurityGroupFormParams.class) UserIdGroupPair sourceSecurityGroup); /** - * @see BaseEC2Client#revokeSecurityGroupIngressInRegion(Region, + * @see BaseEC2Client#revokeSecurityGroupIngressInRegion(@Nullable Region, * String,IpProtocol,int,int,String) */ @POST @Path("/") @FormParams(keys = ACTION, values = "RevokeSecurityGroupIngress") ListenableFuture revokeSecurityGroupIngressInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("GroupName") String groupName, @FormParam("IpProtocol") IpProtocol ipProtocol, @FormParam("FromPort") int fromPort, @FormParam("ToPort") int toPort, @FormParam("CidrIp") String cidrIp); diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupClient.java index 6743ab8523..b28541a3fc 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/SecurityGroupClient.java @@ -21,6 +21,8 @@ package org.jclouds.aws.ec2.services; import java.util.SortedSet; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.SecurityGroup; @@ -59,7 +61,7 @@ public interface SecurityGroupClient { * @see */ - void createSecurityGroupInRegion(Region region, String name, String description); + void createSecurityGroupInRegion(@Nullable Region region, String name, String description); /** * Deletes a security group that you own. @@ -79,7 +81,7 @@ public interface SecurityGroupClient { * @see */ - void deleteSecurityGroupInRegion(Region region, String name); + void deleteSecurityGroupInRegion(@Nullable Region region, String name); /** * Returns information about security groups that you own. @@ -99,7 +101,7 @@ public interface SecurityGroupClient { * @see */ - SortedSet describeSecurityGroupsInRegion(Region region, + SortedSet describeSecurityGroupsInRegion(@Nullable Region region, String... securityGroupNames); /** @@ -123,7 +125,7 @@ public interface SecurityGroupClient { * @see { protected Logger logger = Logger.NULL; @Inject protected DateService dateService; - + @Inject + @EC2 + Region defaultRegion; private String volumeId; private String instanceId; private String device; @@ -48,8 +52,10 @@ public class AttachmentHandler extends ParseSax.HandlerWithResult { private Date attachTime; public Attachment getResult() { - return new Attachment(EC2Utils.findRegionInArgsOrNull(request), volumeId, instanceId, device, - attachmentStatus, attachTime); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + return new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime); } public void endElement(String uri, String name, String qName) { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/BaseReservationHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/BaseReservationHandler.java index e3859fa7b8..4bff8cc011 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/BaseReservationHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/BaseReservationHandler.java @@ -26,7 +26,10 @@ import java.util.Set; import java.util.SortedSet; import javax.annotation.Resource; +import javax.inject.Inject; +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.InstanceState; @@ -43,12 +46,20 @@ import org.xml.sax.Attributes; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +/** + * + * @author Adrian Cole + */ public abstract class BaseReservationHandler extends HandlerWithResult { protected final DateService dateService; - public BaseReservationHandler(DateService dateService) { + protected final Region defaultRegion; + + @Inject + public BaseReservationHandler(DateService dateService, @EC2 Region defaultRegion) { this.dateService = dateService; + this.defaultRegion = defaultRegion; } @Resource @@ -197,11 +208,14 @@ public abstract class BaseReservationHandler extends HandlerWithResult { this.attachTime = null; this.deleteOnTermination = true; } else if (inInstances && !inProductCodes && !inBlockDeviceMapping) { - instances.add(new RunningInstance(EC2Utils.findRegionInArgsOrNull(request), - amiLaunchIndex, dnsName, imageId, instanceId, instanceState, instanceType, - ipAddress, kernelId, keyName, launchTime, monitoring, availabilityZone, platform, - privateDnsName, privateIpAddress, productCodes, ramdiskId, reason, subnetId, - vpcId, rootDeviceType, rootDeviceName, ebsBlockDevices)); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + instances.add(new RunningInstance(region, amiLaunchIndex, dnsName, imageId, instanceId, + instanceState, instanceType, ipAddress, kernelId, keyName, launchTime, + monitoring, availabilityZone, platform, privateDnsName, privateIpAddress, + productCodes, ramdiskId, reason, subnetId, vpcId, rootDeviceType, rootDeviceName, + ebsBlockDevices)); this.amiLaunchIndex = null; this.dnsName = null; this.imageId = null; @@ -247,8 +261,11 @@ public abstract class BaseReservationHandler extends HandlerWithResult { } protected Reservation newReservation() { - Reservation info = new Reservation(EC2Utils.findRegionInArgsOrNull(request), groupIds, - instances, ownerId, requesterId, reservationId); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + Reservation info = new Reservation(region, groupIds, instances, ownerId, requesterId, + reservationId); this.groupIds = Sets.newTreeSet(); this.instances = Sets.newTreeSet(); this.ownerId = null; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandler.java index 4a94b4b3ea..18d85feff9 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/CreateVolumeResponseHandler.java @@ -20,7 +20,6 @@ package org.jclouds.aws.ec2.xml; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.Date; import java.util.Map; import java.util.Set; @@ -29,6 +28,7 @@ import javax.annotation.Resource; import javax.inject.Inject; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.Volume; @@ -53,6 +53,9 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerWithResult availabilityZoneToRegion; private String id; @@ -128,8 +131,8 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerWithResult pairs = Sets.newLinkedHashSet(); private InetAddress ipAddress; private StringBuilder currentText = new StringBuilder(); - + @Inject + @EC2 + Region defaultRegion; private String instanceId; protected String currentOrNull() { @@ -57,8 +62,10 @@ public class DescribeAddressesResponseHandler extends } else if (qName.equals("instanceId")) { instanceId = currentOrNull(); } else if (qName.equals("item")) { - pairs.add(new PublicIpInstanceIdPair(EC2Utils.findRegionInArgsOrNull(request), ipAddress, - instanceId)); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + pairs.add(new PublicIpInstanceIdPair(region, ipAddress, instanceId)); ipAddress = null; instanceId = null; } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandler.java index f9588f7c46..358dd13557 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeImagesResponseHandler.java @@ -22,7 +22,10 @@ import java.util.Map; import java.util.Set; import javax.annotation.Resource; +import javax.inject.Inject; +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.Image.Architecture; @@ -49,7 +52,9 @@ import com.google.common.collect.Sets; public class DescribeImagesResponseHandler extends ParseSax.HandlerWithResult> { @Resource protected Logger logger = Logger.NULL; - + @Inject + @EC2 + Region defaultRegion; private Set contents = Sets.newLinkedHashSet(); private StringBuilder currentText = new StringBuilder(); @@ -142,7 +147,10 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerWithResult reservations = Sets.newTreeSet(); @Inject - DescribeInstancesResponseHandler(DateService dateService) { - super(dateService); + DescribeInstancesResponseHandler(DateService dateService, @EC2 Region defaultRegion) { + super(dateService, defaultRegion); } @Override diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandler.java index fea9a2d98d..a6d42e93a8 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeKeyPairsResponseHandler.java @@ -20,6 +20,10 @@ package org.jclouds.aws.ec2.xml; import java.util.Set; +import javax.inject.Inject; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.functions.ParseSax; @@ -34,6 +38,9 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerWithResult> { + @Inject + @EC2 + Region defaultRegion; private StringBuilder currentText = new StringBuilder(); private Set keyPairs = Sets.newLinkedHashSet(); @@ -49,8 +56,10 @@ public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerWithResult< if (qName.equals("keyFingerprint")) { this.keyFingerprint = currentText.toString().trim(); } else if (qName.equals("item")) { - keyPairs.add(new KeyPair(EC2Utils.findRegionInArgsOrNull(request), keyName, - keyFingerprint, null)); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + keyPairs.add(new KeyPair(region, keyName, keyFingerprint, null)); } else if (qName.equals("keyName")) { this.keyName = currentText.toString().trim(); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandler.java index 815c2512bc..8a59c54f77 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/DescribeSecurityGroupsResponseHandler.java @@ -20,6 +20,10 @@ package org.jclouds.aws.ec2.xml; import java.util.SortedSet; +import javax.inject.Inject; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.IpPermission; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.SecurityGroup; @@ -39,6 +43,9 @@ import com.google.common.collect.Sets; */ public class DescribeSecurityGroupsResponseHandler extends ParseSax.HandlerWithResult> { + @Inject + @EC2 + Region defaultRegion; private StringBuilder currentText = new StringBuilder(); private SortedSet securtyGroups = Sets.newTreeSet(); @@ -111,8 +118,11 @@ public class DescribeSecurityGroupsResponseHandler extends this.userId = null; this.userIdGroupName = null; } else if (!inIpPermissions && !inIpRanges && !inGroups) { - securtyGroups.add(new SecurityGroup(EC2Utils.findRegionInArgsOrNull(request), - groupName, ownerId, groupDescription, ipPermissions)); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + securtyGroups.add(new SecurityGroup(region, groupName, ownerId, groupDescription, + ipPermissions)); this.groupName = null; this.ownerId = null; this.groupDescription = null; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandler.java index 2b9ac4fe06..cbf3178273 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/InstanceStateChangeHandler.java @@ -20,6 +20,10 @@ package org.jclouds.aws.ec2.xml; import java.util.SortedSet; +import javax.inject.Inject; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceStateChange; import org.jclouds.aws.ec2.util.EC2Utils; @@ -45,6 +49,9 @@ import com.google.common.collect.Sets; */ public class InstanceStateChangeHandler extends HandlerWithResult> { private StringBuilder currentText = new StringBuilder(); + @Inject + @EC2 + Region defaultRegion; SortedSet instances = Sets.newTreeSet(); private InstanceState shutdownState; @@ -83,8 +90,10 @@ public class InstanceStateChangeHandler extends HandlerWithResult { - + @Inject + @EC2 + Region defaultRegion; private StringBuilder currentText = new StringBuilder(); private String keyFingerprint; private String keyMaterial; private String keyName; public KeyPair getResult() { - return new KeyPair(EC2Utils.findRegionInArgsOrNull(request), keyName, keyFingerprint, - keyMaterial); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + return new KeyPair(region, keyName, keyFingerprint, keyMaterial); } public void endElement(String uri, String name, String qName) { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandler.java index 83d5784e62..1657b3909e 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandler.java @@ -20,6 +20,8 @@ package org.jclouds.aws.ec2.xml; import javax.inject.Inject; +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.date.DateService; @@ -34,8 +36,8 @@ import org.jclouds.date.DateService; public class RunInstancesResponseHandler extends BaseReservationHandler { @Inject - RunInstancesResponseHandler(DateService dateService) { - super(dateService); + RunInstancesResponseHandler(DateService dateService, @EC2 Region defaultRegion) { + super(dateService, defaultRegion); } @Override diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/SnapshotHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/SnapshotHandler.java index dced55a966..efcd430f50 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/SnapshotHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/SnapshotHandler.java @@ -22,6 +22,8 @@ import java.util.Date; import javax.inject.Inject; +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.domain.Snapshot; import org.jclouds.aws.ec2.domain.Snapshot.Status; import org.jclouds.aws.ec2.util.EC2Utils; @@ -35,8 +37,9 @@ import org.jclouds.http.functions.ParseSax; public class SnapshotHandler extends ParseSax.HandlerWithResult { private StringBuilder currentText = new StringBuilder(); - @Inject - protected DateService dateService; + protected final DateService dateService; + protected final Region defaultRegion; + private String id; private String volumeId; private int volumeSize; @@ -47,9 +50,18 @@ public class SnapshotHandler extends ParseSax.HandlerWithResult { private String description; private String ownerAlias; + @Inject + public SnapshotHandler(DateService dateService, @EC2 Region defaultRegion) { + this.dateService = dateService; + this.defaultRegion = defaultRegion; + } + public Snapshot getResult() { - Snapshot snapshot = new Snapshot(EC2Utils.findRegionInArgsOrNull(request), id, volumeId, - volumeSize, status, startTime, progress, ownerId, description, ownerAlias); + Region region = EC2Utils.findRegionInArgsOrNull(request); + if (region == null) + region = defaultRegion; + Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime, + progress, ownerId, description, ownerAlias); this.id = null; this.volumeId = null; this.volumeSize = 0; diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/S3AsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/s3/S3AsyncClient.java index e75e20f798..1e72dd84f3 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/S3AsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/S3AsyncClient.java @@ -23,6 +23,7 @@ import static org.jclouds.blobstore.attr.BlobScopes.CONTAINER; import java.util.SortedSet; import java.util.concurrent.ExecutionException; +import javax.annotation.Nullable; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HEAD; @@ -166,7 +167,7 @@ public interface S3AsyncClient { @ExceptionParser(ReturnFalseIfBucketAlreadyOwnedByYou.class) ListenableFuture putBucketInRegion( // TODO endpoint based on region - @BinderParam(BindRegionToXmlPayload.class) Region region, + @BinderParam(BindRegionToXmlPayload.class) @Nullable Region region, @HostPrefixParam String bucketName, PutBucketOptions... options); /** diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/S3Client.java b/aws/core/src/main/java/org/jclouds/aws/s3/S3Client.java index 77ed1b0192..4ea36a2c32 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/S3Client.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/S3Client.java @@ -22,6 +22,8 @@ import java.util.SortedSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.BucketLogging; @@ -194,7 +196,7 @@ public interface S3Client { * */ @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) - boolean putBucketInRegion(Region region, String bucketName, PutBucketOptions... options); + boolean putBucketInRegion(@Nullable Region region, String bucketName, PutBucketOptions... options); /** * Deletes the bucket, if it is empty. diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java b/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java index e821df9f3e..72fdbb8659 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/S3PropertiesBuilder.java @@ -24,6 +24,9 @@ import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_ENDPOINT; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_SESSIONINTERVAL; +import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_ENDPOINT_EU_WEST_1; +import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_ENDPOINT_US_STANDARD; +import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_ENDPOINT_US_WEST_1; import static org.jclouds.blobstore.reference.BlobStoreConstants.DIRECTORY_SUFFIX_FOLDER; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; @@ -45,6 +48,9 @@ public class S3PropertiesBuilder extends PropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); properties.setProperty(PROPERTY_S3_ENDPOINT, "https://s3.amazonaws.com"); + properties.setProperty(PROPERTY_S3_ENDPOINT_US_STANDARD, "https://s3.amazonaws.com"); + properties.setProperty(PROPERTY_S3_ENDPOINT_US_WEST_1, "https://s3-us-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_S3_ENDPOINT_EU_WEST_1, "https://s3-eu-west-1.amazonaws.com"); properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-amz-meta-"); properties.setProperty(PROPERTY_S3_SESSIONINTERVAL, "60"); properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX, DIRECTORY_SUFFIX_FOLDER); diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3AsyncBlobStore.java b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3AsyncBlobStore.java index c0495cfacd..d891b23d4d 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3AsyncBlobStore.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3AsyncBlobStore.java @@ -21,6 +21,7 @@ package org.jclouds.aws.s3.blobstore; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.Futures.compose; +import java.util.Map; import java.util.SortedSet; import java.util.concurrent.ExecutorService; @@ -55,6 +56,7 @@ import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.domain.Location; import org.jclouds.http.options.GetOptions; import com.google.common.base.Function; @@ -81,14 +83,15 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore { @Inject S3AsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, S3AsyncClient async, - S3Client sync, BucketToResourceMetadata bucket2ResourceMd, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + Location defaultLocation, Map locations, + S3AsyncClient async, S3Client sync, BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, Provider fetchBlobMetadataProvider) { - super(context, blobUtils, service); + super(context, blobUtils, service, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.async = checkNotNull(async, "async"); this.sync = checkNotNull(sync, "sync"); @@ -139,8 +142,9 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore { * bucket name */ @Override - public ListenableFuture createContainerInLocation(String location, String container) { - return async.putBucketInRegion(Region.fromValue(location), container); + public ListenableFuture createContainerInLocation(Location location, String container) { + location = location != null ? location : defaultLocation; + return async.putBucketInRegion(Region.fromValue(location.getId()), container); } /** diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java index 7c8b397890..de810a00ec 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java @@ -20,6 +20,7 @@ package org.jclouds.aws.s3.blobstore; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Map; import java.util.SortedSet; import javax.inject.Inject; @@ -48,6 +49,7 @@ import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.domain.Location; import org.jclouds.http.options.GetOptions; import org.jclouds.util.Utils; @@ -72,14 +74,15 @@ public class S3BlobStore extends BaseBlobStore { private final Provider fetchBlobMetadataProvider; @Inject - S3BlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, S3Client sync, + S3BlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, Location defaultLocation, + Map locations, S3Client sync, BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, Provider fetchBlobMetadataProvider) { - super(context, blobUtils); + super(context, blobUtils, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.sync = checkNotNull(sync, "sync"); this.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd"); @@ -127,8 +130,9 @@ public class S3BlobStore extends BaseBlobStore { * bucket name */ @Override - public boolean createContainerInLocation(String location, String container) { - return sync.putBucketInRegion(Region.fromValue(location), container); + public boolean createContainerInLocation(Location location, String container) { + location = location != null ? location : defaultLocation; + return sync.putBucketInRegion(Region.fromValue(location.getId()), container); } /** diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreContextModule.java b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreContextModule.java index c97c9f5d18..4bdce1b32a 100755 --- a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreContextModule.java @@ -18,6 +18,13 @@ */ package org.jclouds.aws.s3.blobstore.config; +import java.util.Map; +import java.util.Set; + +import javax.inject.Singleton; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.s3.S3; import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore; @@ -29,7 +36,14 @@ import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.internal.BlobStoreContextImpl; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import com.google.common.base.Function; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -51,4 +65,26 @@ public class S3BlobStoreContextModule extends S3ContextModule { new TypeLiteral>() { }).in(Scopes.SINGLETON); } + + @Provides + @Singleton + Location getDefaultLocation(@S3 Region region, Map locations) { + return locations.get(region.toString()); + } + + @Provides + @Singleton + Map provideLocations(@S3 Set regions) { + Set locations = Sets.newHashSet(); + for (Region zone : regions) { + locations + .add(new LocationImpl(LocationScope.ZONE, zone.toString(), zone.toString(), null)); + } + return Maps.uniqueIndex(locations, new Function() { + @Override + public String apply(Location from) { + return from.getId(); + } + }); + } } diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java index f0e96642fa..5b3a5a23f6 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceMetadata.java @@ -18,13 +18,22 @@ */ package org.jclouds.aws.s3.blobstore.functions; +import java.util.Map; + +import javax.annotation.Resource; +import javax.inject.Inject; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.domain.BucketMetadata; +import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.domain.MutableStorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl; +import org.jclouds.domain.Location; +import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -33,10 +42,37 @@ import com.google.common.base.Function; */ @Singleton public class BucketToResourceMetadata implements Function { + private final S3Client client; + private final Map locations; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + BucketToResourceMetadata(S3Client client, Map locations) { + this.client = client; + this.locations = locations; + } + public StorageMetadata apply(BucketMetadata from) { MutableStorageMetadata to = new MutableStorageMetadataImpl(); to.setName(from.getName()); to.setType(StorageType.CONTAINER); + try { + Region region = client.getBucketLocation(from.getName()); + if (region != null) { + Location location = locations.get(region.toString()); + if (location == null) + logger.error("could not get location for region %s in %s", region, locations); + to.setLocation(location); + } else { + logger.error("could not get region for %s", from.getName()); + } + } catch (ContainerNotFoundException e) { + logger.error(e, + "could not get region for %s, as service suggests the bucket doesn't exist", from + .getName()); + } return to; } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/config/S3RestClientModule.java b/aws/core/src/main/java/org/jclouds/aws/s3/config/S3RestClientModule.java index c0bd8e280d..2d3b86b1c0 100755 --- a/aws/core/src/main/java/org/jclouds/aws/s3/config/S3RestClientModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/config/S3RestClientModule.java @@ -19,11 +19,14 @@ package org.jclouds.aws.s3.config; import java.net.URI; +import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; @@ -47,6 +50,8 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Scopes; @@ -94,6 +99,24 @@ public class S3RestClientModule extends AbstractModule { bindRetryHandlers(); } + @Provides + @Singleton + @S3 + Map provideRegions( + @Named(S3Constants.PROPERTY_S3_ENDPOINT_US_STANDARD) String usstandard, + @Named(S3Constants.PROPERTY_S3_ENDPOINT_US_WEST_1) String uswest, + @Named(S3Constants.PROPERTY_S3_ENDPOINT_EU_WEST_1) String euwest) { + return ImmutableMap. of(Region.US_STANDARD, URI.create(usstandard), + Region.US_WEST_1, URI.create(uswest), Region.EU_WEST_1, URI.create(euwest)); + } + + @Provides + @Singleton + @S3 + Set provideRegions(@S3 Map map) { + return map.keySet(); + } + @Provides @Singleton @S3 @@ -101,6 +124,13 @@ public class S3RestClientModule extends AbstractModule { return URI.create(endpoint); } + @Provides + @Singleton + @S3 + Region getDefaultRegion(@S3 URI uri, @S3 Map map) { + return ImmutableBiMap.copyOf(map).inverse().get(uri); + } + @Provides @Singleton protected S3AsyncClient provideAsyncClient(RestClientFactory factory) { diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/functions/BindRegionToXmlPayload.java b/aws/core/src/main/java/org/jclouds/aws/s3/functions/BindRegionToXmlPayload.java index a13140e902..4d5d976985 100644 --- a/aws/core/src/main/java/org/jclouds/aws/s3/functions/BindRegionToXmlPayload.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/functions/BindRegionToXmlPayload.java @@ -20,11 +20,12 @@ package org.jclouds.aws.s3.functions; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.s3.S3; import org.jclouds.http.HttpRequest; import org.jclouds.rest.binders.BindToStringPayload; @@ -39,16 +40,23 @@ import org.jclouds.rest.binders.BindToStringPayload; @Singleton public class BindRegionToXmlPayload extends BindToStringPayload { + private final Region defaultRegion; + + @Inject + BindRegionToXmlPayload(@S3 Region defaultRegion) { + this.defaultRegion = defaultRegion; + } + @Override public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(input, "input") instanceof Region, - "this binder is only valid for Region!"); + input = input == null ? defaultRegion : input; + checkArgument(input instanceof Region, "this binder is only valid for Region!"); Region constraint = (Region) input; String value = null; switch (constraint) { case US_STANDARD: case US_EAST_1: - case DEFAULT:// TODO get this from the url + // nothing to bind as this is default. return; case EU_WEST_1: value = "EU"; @@ -59,12 +67,11 @@ public class BindRegionToXmlPayload extends BindToStringPayload { default: throw new IllegalStateException("unimplemented location: " + this); } - super - .bindToRequest( - request, - String - .format( - "%s", - value)); + String payload = String + .format( + "%s", + value); + super.bindToRequest(request, payload); + } } diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java b/aws/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java index bc6b3ffc0d..efad7a986e 100755 --- a/aws/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java @@ -41,4 +41,8 @@ public interface S3Constants extends AWSConstants, S3Headers { */ public static final String PROPERTY_S3_SESSIONINTERVAL = "jclouds.s3.sessioninterval"; + public static final String PROPERTY_S3_ENDPOINT_EU_WEST_1 = "jclouds.s3.endpoint.eu_west_1"; + public static final String PROPERTY_S3_ENDPOINT_US_STANDARD = "jclouds.s3.endpoint.us_standard"; + public static final String PROPERTY_S3_ENDPOINT_US_WEST_1 = "jclouds.s3.endpoint.us_west_1"; + } 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 index b622ecaec9..b3d779e489 100644 --- a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSAsyncClient.java @@ -23,6 +23,7 @@ import static org.jclouds.aws.sqs.reference.SQSParameters.VERSION; import java.util.Set; +import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -64,7 +65,7 @@ public interface SQSAsyncClient { @FormParams(keys = ACTION, values = "ListQueues") @ResponseParser(RegexListQueuesResponseHandler.class) ListenableFuture> listQueuesInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, ListQueuesOptions... options); /** @@ -75,7 +76,7 @@ public interface SQSAsyncClient { @FormParams(keys = ACTION, values = "CreateQueue") @ResponseParser(RegexQueueHandler.class) ListenableFuture createQueueInRegion( - @EndpointParam(parser = RegionToEndpoint.class) Region region, + @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @FormParam("QueueName") String queueName, CreateQueueOptions... options); /** 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 index 7e131d183b..cadbc92ec0 100644 --- a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSClient.java @@ -21,6 +21,8 @@ package org.jclouds.aws.sqs; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; + import org.jclouds.aws.domain.Region; import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.options.CreateQueueOptions; @@ -49,7 +51,7 @@ public interface SQSClient { * @see */ - Set listQueuesInRegion(Region region, ListQueuesOptions... options); + Set listQueuesInRegion(@Nullable Region region, ListQueuesOptions... options); /** * @@ -79,7 +81,7 @@ public interface SQSClient { * @param options * like the visibility timeout (in seconds) to use for this queue. */ - Queue createQueueInRegion(Region region, String queueName, CreateQueueOptions... options); + Queue createQueueInRegion(@Nullable Region region, String queueName, CreateQueueOptions... options); /** * The DeleteQueue action deletes the queue specified by the queue URL, regardless of whether the 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 index c95edf71fa..a593985e54 100644 --- a/aws/core/src/main/java/org/jclouds/aws/sqs/SQSPropertiesBuilder.java +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/SQSPropertiesBuilder.java @@ -22,6 +22,7 @@ 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; 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; @@ -40,9 +41,12 @@ public class SQSPropertiesBuilder extends PropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_SQS_ENDPOINT, "https://queue.amazonaws.com"); 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_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; } @@ -64,7 +68,7 @@ public class SQSPropertiesBuilder extends PropertiesBuilder { } public SQSPropertiesBuilder withEndpoint(URI endpoint) { - properties.setProperty(PROPERTY_SQS_ENDPOINT_US_EAST_1, checkNotNull(endpoint, "endpoint").toString()); + properties.setProperty(PROPERTY_SQS_ENDPOINT, checkNotNull(endpoint, "endpoint").toString()); return this; } 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 index a59cb21281..9e46f3ba42 100755 --- 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 @@ -47,6 +47,7 @@ import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; +import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -89,6 +90,7 @@ public class SQSRestClientModule extends AbstractModule { @Provides @Singleton + @SQS Map provideRegions( @Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1) String useast, @Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_WEST_1) String uswest, @@ -99,15 +101,22 @@ public class SQSRestClientModule extends AbstractModule { @Provides @Singleton - RequestSigner provideRequestSigner(FormSigner in) { - return in; + @SQS + protected URI provideURI(@Named(SQSConstants.PROPERTY_SQS_ENDPOINT) String endpoint) { + return URI.create(endpoint); } @Provides @Singleton @SQS - protected URI provideURI(@Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1) String endpoint) { - return URI.create(endpoint); + Region getDefaultRegion(@SQS URI uri, @SQS Map map) { + return ImmutableBiMap.copyOf(map).inverse().get(uri); + } + + @Provides + @Singleton + RequestSigner provideRequestSigner(FormSigner in) { + return in; } protected void bindErrorHandlers() { 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 index 3be96eb9ec..64d395662a 100644 --- 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 @@ -39,13 +39,13 @@ public class RegionToEndpoint implements Function { private final URI defaultUri; @Inject - public RegionToEndpoint(Map regionToEndpoint, @SQS URI defaultUri) { + public RegionToEndpoint(@SQS 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); + return from == null ? defaultUri : regionToEndpoint.get(from); } } \ 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 index 86ab79aca8..ce8c914b98 100755 --- 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 @@ -26,6 +26,8 @@ import org.jclouds.aws.reference.AWSConstants; * @author Adrian Cole */ public interface SQSConstants extends AWSConstants { + public static final String PROPERTY_SQS_ENDPOINT = "jclouds.sqs.endpoint"; + 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/xml/QueueHandler.java b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/QueueHandler.java index de153e04cb..3bd9a654a4 100644 --- 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 @@ -26,6 +26,7 @@ import javax.inject.Provider; import javax.ws.rs.core.UriBuilder; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.http.functions.ParseSax; @@ -46,7 +47,7 @@ public class QueueHandler extends ParseSax.HandlerWithResult { private final Provider uriBuilderProvider; @Inject - QueueHandler(Provider uriBuilderProvider, Map regionMap) { + QueueHandler(Provider uriBuilderProvider, @SQS Map regionMap) { this.uriBuilderProvider = uriBuilderProvider; this.regionBiMap = ImmutableBiMap.copyOf(regionMap); } diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexListQueuesResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexListQueuesResponseHandler.java index 752aee2926..9da4ff577f 100644 --- a/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexListQueuesResponseHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexListQueuesResponseHandler.java @@ -27,6 +27,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler; import org.jclouds.http.HttpResponse; @@ -45,7 +46,7 @@ import com.google.common.base.Throwables; public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements Function> { @Inject - RegexListQueuesResponseHandler(Map regionMap) { + RegexListQueuesResponseHandler(@SQS Map regionMap) { super(regionMap); } diff --git a/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexQueueHandler.java b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexQueueHandler.java index a94caab7de..67f60c6695 100644 --- a/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexQueueHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/sqs/xml/RegexQueueHandler.java @@ -26,6 +26,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler; import org.jclouds.http.HttpResponse; @@ -45,7 +46,7 @@ import com.google.inject.internal.Iterables; public class RegexQueueHandler extends BaseRegexQueueHandler implements Function { @Inject - RegexQueueHandler(Map regionMap) { + RegexQueueHandler(@SQS Map regionMap) { super(regionMap); } 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 afb3e46096..d529eb0cdd 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,8 +35,14 @@ 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.*; +import org.jclouds.aws.ec2.domain.BlockDeviceMapping; +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.Reservation; +import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice; import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; import org.jclouds.aws.ec2.predicates.InstanceHasIpAddress; @@ -105,15 +111,15 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { securityGroupName = instancePrefix + "ingress"; try { - client.getSecurityGroupServices().deleteSecurityGroupInRegion(Region.DEFAULT, + client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName); } catch (Exception e) { } - client.getSecurityGroupServices().createSecurityGroupInRegion(Region.DEFAULT, + client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName, securityGroupName); for (int port : new int[] { 80, 443, 22 }) { - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(Region.DEFAULT, + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP, port, port, "0.0.0.0/0"); } } @@ -122,13 +128,13 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { void testCreateKeyPair() throws InterruptedException, ExecutionException, TimeoutException { String keyName = instancePrefix + "1"; try { - client.getKeyPairServices().deleteKeyPairInRegion(Region.DEFAULT, keyName); + client.getKeyPairServices().deleteKeyPairInRegion(null, keyName); } catch (Exception e) { } - client.getKeyPairServices().deleteKeyPairInRegion(Region.DEFAULT, keyName); + client.getKeyPairServices().deleteKeyPairInRegion(null, keyName); - keyPair = client.getKeyPairServices().createKeyPairInRegion(Region.DEFAULT, keyName); + keyPair = client.getKeyPairServices().createKeyPairInRegion(null, keyName); assertNotNull(keyPair); assertNotNull(keyPair.getKeyMaterial()); assertNotNull(keyPair.getKeyFingerprint()); @@ -149,7 +155,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { System.out.printf("%d: running instance%n", System.currentTimeMillis()); Reservation reservation = client.getInstanceServices().runInstancesInRegion( - Region.DEFAULT, null, // allow ec2 to chose an availability zone + null, null, // allow ec2 to chose an availability zone "ami-ccf615a5", // alestic ami allows auto-invoke of user data scripts 1, // minimum instances 1, // maximum instances @@ -180,39 +186,39 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private void verifyInstanceProperties(String script) { assertEquals(script, client.getInstanceServices().getUserDataForInstanceInRegion( - Region.DEFAULT, instanceId)); + null, instanceId)); assertEquals(null, client.getInstanceServices().getRootDeviceNameForInstanceInRegion( - Region.DEFAULT, instanceId)); + null, instanceId)); - assert client.getInstanceServices().getRamdiskForInstanceInRegion(Region.DEFAULT, instanceId) + assert client.getInstanceServices().getRamdiskForInstanceInRegion(null, instanceId) .startsWith("ari-"); assertEquals(false, client.getInstanceServices().isApiTerminationDisabledForInstanceInRegion( - Region.DEFAULT, instanceId)); + null, instanceId)); - assert client.getInstanceServices().getKernelForInstanceInRegion(Region.DEFAULT, instanceId) + assert client.getInstanceServices().getKernelForInstanceInRegion(null, instanceId) .startsWith("aki-"); assertEquals(InstanceType.M1_SMALL, client.getInstanceServices() - .getInstanceTypeForInstanceInRegion(Region.DEFAULT, instanceId)); + .getInstanceTypeForInstanceInRegion(null, instanceId)); assertEquals(InstanceInitiatedShutdownBehavior.TERMINATE, client.getInstanceServices() - .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(Region.DEFAULT, instanceId)); + .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, instanceId)); assertEquals(ImmutableMap. of(), client.getInstanceServices() - .getBlockDeviceMappingForInstanceInRegion(Region.DEFAULT, instanceId)); + .getBlockDeviceMappingForInstanceInRegion(null, instanceId)); } private void setApiTerminationDisabledForInstanceInRegion() { - client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(null, instanceId, true); assertEquals(true, client.getInstanceServices().isApiTerminationDisabledForInstanceInRegion( - Region.DEFAULT, instanceId)); - client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(Region.DEFAULT, + null, instanceId)); + client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(null, instanceId, false); assertEquals(false, client.getInstanceServices().isApiTerminationDisabledForInstanceInRegion( - Region.DEFAULT, instanceId)); + null, instanceId)); } private void tryToChangeStuff() { @@ -227,7 +233,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private void setUserDataForInstanceInRegion() { try { - client.getInstanceServices().setUserDataForInstanceInRegion(Region.DEFAULT, instanceId, + client.getInstanceServices().setUserDataForInstanceInRegion(null, instanceId, "test".getBytes()); assert false : "shouldn't be allowed, as instance needs to be stopped"; } catch (AWSResponseException e) { @@ -238,8 +244,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private void setRamdiskForInstanceInRegion() { try { String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion( - Region.DEFAULT, instanceId); - client.getInstanceServices().setRamdiskForInstanceInRegion(Region.DEFAULT, instanceId, + null, instanceId); + client.getInstanceServices().setRamdiskForInstanceInRegion(null, instanceId, ramdisk); assert false : "shouldn't be allowed, as instance needs to be stopped"; } catch (AWSResponseException e) { @@ -250,8 +256,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private void setKernelForInstanceInRegion() { try { String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion( - Region.DEFAULT, instanceId); - client.getInstanceServices().setKernelForInstanceInRegion(Region.DEFAULT, instanceId, + null, instanceId); + client.getInstanceServices().setKernelForInstanceInRegion(null, instanceId, oldKernel); assert false : "shouldn't be allowed, as instance needs to be stopped"; } catch (AWSResponseException e) { @@ -261,7 +267,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private void setInstanceTypeForInstanceInRegion() { try { - client.getInstanceServices().setInstanceTypeForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, instanceId, InstanceType.C1_MEDIUM); assert false : "shouldn't be allowed, as instance needs to be stopped"; } catch (AWSResponseException e) { @@ -272,7 +278,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private void setBlockDeviceMappingForInstanceInRegion() { BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); try { - client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null, instanceId, blockDeviceMapping); assert false : "shouldn't be allowed, as instance needs to be ebs based-ami"; } catch (AWSResponseException e) { @@ -283,7 +289,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private void setInstanceInitiatedShutdownBehaviorForInstanceInRegion() { try { client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion( - Region.DEFAULT, instanceId, InstanceInitiatedShutdownBehavior.STOP); + null, instanceId, InstanceInitiatedShutdownBehavior.STOP); assert false : "shouldn't be allowed, as instance needs to be ebs based-ami"; } catch (AWSResponseException e) { assertEquals("UnsupportedInstanceAttribute", e.getError().getCode()); @@ -294,7 +300,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { void testReboot() throws InterruptedException, ExecutionException, TimeoutException, IOException { RunningInstance instance = getInstance(instanceId); System.out.printf("%d: %s rebooting instance %n", System.currentTimeMillis(), instanceId); - client.getInstanceServices().rebootInstancesInRegion(Region.DEFAULT, instanceId); + client.getInstanceServices().rebootInstancesInRegion(null, instanceId); Thread.sleep(1000); instance = getInstance(instanceId); blockUntilWeCanSshIntoInstance(instance); @@ -313,42 +319,42 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { @Test(enabled = false, dependsOnMethods = "testReboot") void testElasticIpAddress() throws InterruptedException, ExecutionException, TimeoutException, IOException { - address = client.getElasticIPAddressServices().allocateAddressInRegion(Region.DEFAULT); + address = client.getElasticIPAddressServices().allocateAddressInRegion(null); assertNotNull(address); PublicIpInstanceIdPair compare = Iterables.getLast(client.getElasticIPAddressServices() - .describeAddressesInRegion(Region.DEFAULT, address)); + .describeAddressesInRegion(null, address)); assertEquals(compare.getPublicIp(), address); assert compare.getInstanceId() == null; - client.getElasticIPAddressServices().associateAddressInRegion(Region.DEFAULT, address, + client.getElasticIPAddressServices().associateAddressInRegion(null, address, instanceId); compare = Iterables.getLast(client.getElasticIPAddressServices().describeAddressesInRegion( - Region.DEFAULT, address)); + null, address)); assertEquals(compare.getPublicIp(), address); assertEquals(compare.getInstanceId(), instanceId); Reservation reservation = Iterables.getOnlyElement(client.getInstanceServices() - .describeInstancesInRegion(Region.DEFAULT, instanceId)); + .describeInstancesInRegion(null, instanceId)); assertNotNull(Iterables.getOnlyElement(reservation).getIpAddress()); assertFalse(Iterables.getOnlyElement(reservation).getIpAddress().equals(address)); doCheckKey(address); - client.getElasticIPAddressServices().disassociateAddressInRegion(Region.DEFAULT, address); + client.getElasticIPAddressServices().disassociateAddressInRegion(null, address); compare = Iterables.getLast(client.getElasticIPAddressServices().describeAddressesInRegion( - Region.DEFAULT, address)); + null, address)); assertEquals(compare.getPublicIp(), address); assert compare.getInstanceId() == null; reservation = Iterables.getOnlyElement(client.getInstanceServices() - .describeInstancesInRegion(Region.DEFAULT, instanceId)); + .describeInstancesInRegion(null, instanceId)); // assert reservation.getRunningInstances().last().getIpAddress() == null; TODO } @@ -385,7 +391,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { private RunningInstance getInstance(String instanceId) { // search my account for the instance I just created Set reservations = client.getInstanceServices().describeInstancesInRegion( - Region.DEFAULT, instanceId); // last parameter (ids) narrows the search + null, instanceId); // last parameter (ids) narrows the search return Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); } @@ -427,13 +433,13 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest { @AfterTest void cleanup() throws InterruptedException, ExecutionException, TimeoutException { if (address != null) - client.getElasticIPAddressServices().releaseAddressInRegion(Region.DEFAULT, address); + client.getElasticIPAddressServices().releaseAddressInRegion(null, address); if (instanceId != null) - client.getInstanceServices().terminateInstancesInRegion(Region.DEFAULT, instanceId); + client.getInstanceServices().terminateInstancesInRegion(null, instanceId); if (keyPair != null) - client.getKeyPairServices().deleteKeyPairInRegion(Region.DEFAULT, keyPair.getKeyName()); + client.getKeyPairServices().deleteKeyPairInRegion(null, keyPair.getKeyName()); if (securityGroupName != null) - client.getSecurityGroupServices().deleteSecurityGroupInRegion(Region.DEFAULT, + client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName); } 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 00a73ffae1..df66858904 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 @@ -37,8 +37,18 @@ 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.*; +import org.jclouds.aws.ec2.domain.Attachment; +import org.jclouds.aws.ec2.domain.BlockDeviceMapping; +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.Reservation; +import org.jclouds.aws.ec2.domain.RootDeviceType; +import org.jclouds.aws.ec2.domain.RunningInstance; +import org.jclouds.aws.ec2.domain.Snapshot; +import org.jclouds.aws.ec2.domain.Volume; import org.jclouds.aws.ec2.domain.Image.Architecture; import org.jclouds.aws.ec2.domain.Image.ImageType; import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; @@ -147,18 +157,18 @@ public class EBSBootEC2ClientLiveTest { securityGroupName = INSTANCE_PREFIX + "ingress"; try { - client.getSecurityGroupServices().deleteSecurityGroupInRegion(Region.DEFAULT, + client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName); } catch (Exception e) { } - client.getSecurityGroupServices().createSecurityGroupInRegion(Region.DEFAULT, + client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName, securityGroupName); - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(Region.DEFAULT, + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP, 80, 80, "0.0.0.0/0"); - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(Region.DEFAULT, + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP, 443, 443, "0.0.0.0/0"); - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(Region.DEFAULT, + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, securityGroupName, IpProtocol.TCP, 22, 22, "0.0.0.0/0"); } @@ -166,12 +176,12 @@ public class EBSBootEC2ClientLiveTest { void testCreateKeyPair() { String keyName = INSTANCE_PREFIX + "1"; try { - client.getKeyPairServices().deleteKeyPairInRegion(Region.DEFAULT, keyName); + client.getKeyPairServices().deleteKeyPairInRegion(null, keyName); } catch (Exception e) { } - keyPair = client.getKeyPairServices().createKeyPairInRegion(Region.DEFAULT, keyName); + keyPair = client.getKeyPairServices().createKeyPairInRegion(null, keyName); assertNotNull(keyPair); assertNotNull(keyPair.getKeyMaterial()); assertNotNull(keyPair.getKeyFingerprint()); @@ -190,7 +200,7 @@ public class EBSBootEC2ClientLiveTest { try { System.out.printf("%d: running instance%n", System.currentTimeMillis()); Reservation reservation = client.getInstanceServices().runInstancesInRegion( - Region.DEFAULT, null, // allow ec2 to chose an availability zone + null, null, // allow ec2 to chose an availability zone imageId, 1, // minimum instances 1, // maximum instances withKeyName(keyPair.getKeyName())// key I created above @@ -412,39 +422,39 @@ public class EBSBootEC2ClientLiveTest { } private void setUserDataForInstanceInRegion() { - client.getInstanceServices().setUserDataForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setUserDataForInstanceInRegion(null, ebsInstance.getId(), "test".getBytes()); assertEquals("test", client.getInstanceServices().getUserDataForInstanceInRegion( - Region.DEFAULT, ebsInstance.getId())); + null, ebsInstance.getId())); } private void setRamdiskForInstanceInRegion() { - String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(Region.DEFAULT, + String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(null, ebsInstance.getId()); - client.getInstanceServices().setRamdiskForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setRamdiskForInstanceInRegion(null, ebsInstance.getId(), ramdisk); assertEquals(ramdisk, client.getInstanceServices().getRamdiskForInstanceInRegion( - Region.DEFAULT, ebsInstance.getId())); + null, ebsInstance.getId())); } private void setKernelForInstanceInRegion() { - String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(Region.DEFAULT, + String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(null, ebsInstance.getId()); - client.getInstanceServices().setKernelForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setKernelForInstanceInRegion(null, ebsInstance.getId(), oldKernel); assertEquals(oldKernel, client.getInstanceServices().getKernelForInstanceInRegion( - Region.DEFAULT, ebsInstance.getId())); + null, ebsInstance.getId())); } private void setInstanceTypeForInstanceInRegion() { - client.getInstanceServices().setInstanceTypeForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), InstanceType.C1_MEDIUM); assertEquals(InstanceType.C1_MEDIUM, client.getInstanceServices() - .getInstanceTypeForInstanceInRegion(Region.DEFAULT, ebsInstance.getId())); - client.getInstanceServices().setInstanceTypeForInstanceInRegion(Region.DEFAULT, + .getInstanceTypeForInstanceInRegion(null, ebsInstance.getId())); + client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(), InstanceType.M1_SMALL); assertEquals(InstanceType.M1_SMALL, client.getInstanceServices() - .getInstanceTypeForInstanceInRegion(Region.DEFAULT, ebsInstance.getId())); + .getInstanceTypeForInstanceInRegion(null, ebsInstance.getId())); } private void setBlockDeviceMappingForInstanceInRegion() { @@ -454,11 +464,11 @@ public class EBSBootEC2ClientLiveTest { blockDeviceMapping.addEbsBlockDevice ("/dev/sda1", new RunningInstance.EbsBlockDevice(volumeId, false)); try { - client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(Region.DEFAULT, + client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId(), blockDeviceMapping); Map devices = client - .getInstanceServices().getBlockDeviceMappingForInstanceInRegion(Region.DEFAULT, + .getInstanceServices().getBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId()); assertEquals(devices.size(), 1); String deviceName = Iterables.getOnlyElement(devices.keySet()); @@ -480,16 +490,16 @@ public class EBSBootEC2ClientLiveTest { try { client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion( - Region.DEFAULT, ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP); + null, ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP); assertEquals(InstanceInitiatedShutdownBehavior.STOP, client.getInstanceServices() - .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(Region.DEFAULT, + .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, ebsInstance.getId())); client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion( - Region.DEFAULT, ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE); + null, ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE); assertEquals(InstanceInitiatedShutdownBehavior.TERMINATE, client.getInstanceServices() - .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(Region.DEFAULT, + .getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null, ebsInstance.getId())); System.out.println("OK: setInstanceInitiatedShutdownBehaviorForInstanceInRegion"); } catch (Exception e) { @@ -618,7 +628,7 @@ public class EBSBootEC2ClientLiveTest { } if (securityGroupName != null) { try { - client.getSecurityGroupServices().deleteSecurityGroupInRegion(Region.DEFAULT, + client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName); } catch (Exception e) { e.printStackTrace(); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java index d908f75e17..749eea12a9 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java @@ -26,13 +26,12 @@ 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.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.aws.ec2.domain.Image; +import org.jclouds.aws.ec2.xml.BaseEC2HandlerTest; import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler; import org.jclouds.compute.domain.OsFamily; import org.jclouds.domain.Location; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -44,7 +43,7 @@ import com.google.common.collect.Iterables; * @author Adrian Cole */ @Test(groups = "unit", testName = "compute.ImageParserTest") -public class ImageParserTest extends BaseHandlerTest { +public class ImageParserTest extends BaseEC2HandlerTest { public void testParseAlesticCanonicalImage() { InputStream is = getClass().getResourceAsStream("/ec2/alestic_canonical.xml"); @@ -158,7 +157,7 @@ public class ImageParserTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 d091358443..3b7d3913f6 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 @@ -24,8 +24,7 @@ import static org.testng.Assert.assertEquals; import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; -import org.jclouds.Constants; -import org.jclouds.aws.ec2.reference.EC2Constants; +import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; @@ -52,18 +51,8 @@ public class EC2RestClientModuleTest { new AbstractModule() { @Override protected void configure() { - bindConstant().annotatedWith( - Jsr330.named(EC2Constants.PROPERTY_AWS_ACCESSKEYID)).to("user"); - bindConstant().annotatedWith( - Jsr330.named(EC2Constants.PROPERTY_AWS_SECRETACCESSKEY)).to("key"); - bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_EC2_ENDPOINT)) - .to("http://localhost"); - bindConstant().annotatedWith( - Jsr330.named(EC2Constants.PROPERTY_AWS_EXPIREINTERVAL)).to(30); - bindConstant().annotatedWith( - Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); + Jsr330.bindProperties(this.binder(), new EC2PropertiesBuilder("user", "key") + .build()); bind(UriBuilder.class).to(UriBuilderImpl.class); } }); 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 b4cde8132d..421d7d85dd 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 @@ -18,22 +18,13 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.executableBy; -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 java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.options.CreateImageOptions; import org.jclouds.aws.ec2.options.DescribeImagesOptions; import org.jclouds.aws.ec2.options.RegisterImageBackedByEbsOptions; @@ -43,25 +34,13 @@ 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.CloseContentAndReturn; 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.BeforeTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -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; /** @@ -70,14 +49,14 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.AMIAsyncClientTest") -public class AMIAsyncClientTest extends RestClientTest { +public class AMIAsyncClientTest extends BaseEC2AsyncClientTest { public void testCreateImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("createImageInRegion", Region.class, String.class, String.class, Array.newInstance(CreateImageOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "name", "instanceId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "name", "instanceId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -96,9 +75,9 @@ public class AMIAsyncClientTest extends RestClientTest { Method method = AMIAsyncClient.class.getMethod("createImageInRegion", Region.class, String.class, String.class, Array.newInstance(CreateImageOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "name", "instanceId", new CreateImageOptions().withDescription( - "description").noReboot()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "name", "instanceId", new CreateImageOptions().withDescription("description") + .noReboot()); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -118,7 +97,7 @@ public class AMIAsyncClientTest extends RestClientTest { Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", Region.class, Array .newInstance(DescribeImagesOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT); + (Region) null); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -140,8 +119,8 @@ public class AMIAsyncClientTest extends RestClientTest { IOException { Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", Region.class, Array .newInstance(DescribeImagesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, executableBy("me").ownedBy("fred", "nancy").imageIds("1", "2")); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + executableBy("me").ownedBy("fred", "nancy").imageIds("1", "2")); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -160,8 +139,8 @@ public class AMIAsyncClientTest extends RestClientTest { public void testDeregisterImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("deregisterImageInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -180,8 +159,8 @@ public class AMIAsyncClientTest extends RestClientTest { Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", Region.class, String.class, String.class, Array.newInstance( RegisterImageOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "name", "pathToManifest"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "name", "pathToManifest"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -200,9 +179,8 @@ public class AMIAsyncClientTest extends RestClientTest { Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", Region.class, String.class, String.class, Array.newInstance( RegisterImageOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "name", "pathToManifest", new RegisterImageOptions() - .withDescription("description")); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "name", "pathToManifest", new RegisterImageOptions().withDescription("description")); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -223,8 +201,8 @@ public class AMIAsyncClientTest extends RestClientTest { Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", Region.class, String.class, String.class, Array.newInstance( RegisterImageBackedByEbsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "imageName", "snapshotId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "imageName", "snapshotId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -244,11 +222,10 @@ public class AMIAsyncClientTest extends RestClientTest { Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", Region.class, String.class, String.class, Array.newInstance( RegisterImageBackedByEbsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "imageName", "snapshotId", new RegisterImageBackedByEbsOptions() - .withDescription("description").addBlockDeviceFromSnapshot("/dev/device", - null, "snapshot").addNewBlockDevice("/dev/newdevice", "newblock", - 100)); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "imageName", "snapshotId", new RegisterImageBackedByEbsOptions().withDescription( + "description").addBlockDeviceFromSnapshot("/dev/device", null, "snapshot") + .addNewBlockDevice("/dev/newdevice", "newblock", 100)); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -268,8 +245,8 @@ public class AMIAsyncClientTest extends RestClientTest { IOException { Method method = AMIAsyncClient.class.getMethod("getProductCodesForImageInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -288,8 +265,8 @@ public class AMIAsyncClientTest extends RestClientTest { NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("getBlockDeviceMappingsForImageInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -308,8 +285,8 @@ public class AMIAsyncClientTest extends RestClientTest { IOException { Method method = AMIAsyncClient.class.getMethod("getLaunchPermissionForImageInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -328,8 +305,8 @@ public class AMIAsyncClientTest extends RestClientTest { IOException { Method method = AMIAsyncClient.class.getMethod("addLaunchPermissionsToImageInRegion", Region.class, Iterable.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -353,8 +330,8 @@ public class AMIAsyncClientTest extends RestClientTest { NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("removeLaunchPermissionsFromImageInRegion", Region.class, Iterable.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -373,8 +350,8 @@ public class AMIAsyncClientTest extends RestClientTest { IOException { Method method = AMIAsyncClient.class.getMethod("resetLaunchPermissionsOnImageInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -392,8 +369,8 @@ public class AMIAsyncClientTest extends RestClientTest { IOException { Method method = AMIAsyncClient.class.getMethod("addProductCodesToImageInRegion", Region.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, ImmutableList.of("code1", "code2"), "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + ImmutableList.of("code1", "code2"), "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -413,8 +390,8 @@ public class AMIAsyncClientTest extends RestClientTest { IOException { Method method = AMIAsyncClient.class.getMethod("removeProductCodesFromImageInRegion", Region.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, ImmutableList.of("code1", "code2"), "imageId"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + ImmutableList.of("code1", "code2"), "imageId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -430,63 +407,10 @@ public class AMIAsyncClientTest extends RestClientTest { 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>() { }; } - private FormSigner filter; - - @Override - @BeforeTest - protected void setupFactory() { - super.setupFactory(); - this.filter = injector.getInstance(FormSigner.class); - } - - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.eu-west-1.amazonaws.com"), - Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), - Region.US_WEST_1, URI.create("https://ec2.us-west-1.amazonaws.com")); - } - }; - } } 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 7669b5e980..8521831bbe 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 @@ -75,7 +75,7 @@ public class AMIClientLiveTest { } public void testDescribeImages() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { SortedSet allResults = Sets.newTreeSet(client.describeImagesInRegion(region)); assertNotNull(allResults); @@ -95,11 +95,11 @@ public class AMIClientLiveTest { @Test(enabled = false) public void testRegisterImageFromManifest() { - String imageRegisteredId = client.registerImageFromManifestInRegion(Region.DEFAULT, + String imageRegisteredId = client.registerImageFromManifestInRegion(null, "jcloudstest1", DEFAULT_MANIFEST); imagesToDeregister.add(imageRegisteredId); Image imageRegisteredFromManifest = Iterables.getOnlyElement(client.describeImagesInRegion( - Region.DEFAULT, imageIds(imageRegisteredId))); + null, imageIds(imageRegisteredId))); assertEquals(imageRegisteredFromManifest.getName(), "jcloudstest1"); assertEquals(imageRegisteredFromManifest.getImageLocation(), DEFAULT_MANIFEST); assertEquals(imageRegisteredFromManifest.getImageType(), ImageType.MACHINE); @@ -110,10 +110,10 @@ public class AMIClientLiveTest { @Test(enabled = false) public void testRegisterImageFromManifestOptions() { String imageRegisteredWithOptionsId = client.registerImageFromManifestInRegion( - Region.DEFAULT, "jcloudstest2", DEFAULT_MANIFEST, withDescription("adrian")); + null, "jcloudstest2", DEFAULT_MANIFEST, withDescription("adrian")); imagesToDeregister.add(imageRegisteredWithOptionsId); Image imageRegisteredFromManifestWithOptions = Iterables.getOnlyElement(client - .describeImagesInRegion(Region.DEFAULT, imageIds(imageRegisteredWithOptionsId))); + .describeImagesInRegion(null, imageIds(imageRegisteredWithOptionsId))); assertEquals(imageRegisteredFromManifestWithOptions.getName(), "jcloudstest2"); assertEquals(imageRegisteredFromManifestWithOptions.getImageLocation(), DEFAULT_MANIFEST); assertEquals(imageRegisteredFromManifestWithOptions.getImageType(), ImageType.MACHINE); @@ -126,11 +126,11 @@ public class AMIClientLiveTest { @Test(enabled = false) // awaiting EBS functionality to be added to jclouds public void testRegisterImageBackedByEBS() { - String imageRegisteredId = client.registerUnixImageBackedByEbsInRegion(Region.DEFAULT, + String imageRegisteredId = client.registerUnixImageBackedByEbsInRegion(null, "jcloudstest1", DEFAULT_MANIFEST); imagesToDeregister.add(imageRegisteredId); Image imageRegistered = Iterables.getOnlyElement(client.describeImagesInRegion( - Region.DEFAULT, imageIds(imageRegisteredId))); + null, imageIds(imageRegisteredId))); assertEquals(imageRegistered.getName(), "jcloudstest1"); assertEquals(imageRegistered.getImageType(), ImageType.MACHINE); assertEquals(imageRegistered.getRootDeviceType(), RootDeviceType.EBS); @@ -141,11 +141,11 @@ public class AMIClientLiveTest { // awaiting EBS functionality to be added to jclouds public void testRegisterImageBackedByEBSOptions() { String imageRegisteredWithOptionsId = client.registerUnixImageBackedByEbsInRegion( - Region.DEFAULT, "jcloudstest2", DEFAULT_SNAPSHOT, addNewBlockDevice("/dev/sda2", + null, "jcloudstest2", DEFAULT_SNAPSHOT, addNewBlockDevice("/dev/sda2", "myvirtual", 1).withDescription("adrian")); imagesToDeregister.add(imageRegisteredWithOptionsId); Image imageRegisteredWithOptions = Iterables.getOnlyElement(client.describeImagesInRegion( - Region.DEFAULT, imageIds(imageRegisteredWithOptionsId))); + null, imageIds(imageRegisteredWithOptionsId))); assertEquals(imageRegisteredWithOptions.getName(), "jcloudstest2"); assertEquals(imageRegisteredWithOptions.getImageType(), ImageType.MACHINE); assertEquals(imageRegisteredWithOptions.getRootDeviceType(), RootDeviceType.EBS); @@ -158,48 +158,48 @@ public class AMIClientLiveTest { @Test(enabled = false) public void testCreateImage() { - // TODO client.createImageInRegion(Region.DEFAULT, name, instanceId, options); + // TODO client.createImageInRegion(null, name, instanceId, options); } @Test(enabled = false) public void testAddProductCodesToImage() { - // TODO client.addProductCodesToImageInRegion(Region.DEFAULT, productCodes, imageId); + // TODO client.addProductCodesToImageInRegion(null, productCodes, imageId); } @Test(enabled = false) public void testAddLaunchPermissionsToImage() { - // TODO client.addLaunchPermissionsToImageInRegion(Region.DEFAULT, userIds, userGroups, + // TODO client.addLaunchPermissionsToImageInRegion(null, userIds, userGroups, // imageId); } @Test(enabled = false) public void testRemoveLaunchPermissionsFromImage() { - // TODO client.removeLaunchPermissionsFromImageInRegion(Region.DEFAULT, userIds, userGroups, + // TODO client.removeLaunchPermissionsFromImageInRegion(null, userIds, userGroups, // imageId); } @Test(enabled = false) public void testResetLaunchPermissionsOnImage() { - // TODO client.resetLaunchPermissionsOnImageInRegion(Region.DEFAULT, imageId); + // TODO client.resetLaunchPermissionsOnImageInRegion(null, imageId); } public void testGetLaunchPermissionForImage() { - System.out.println(client.getLaunchPermissionForImageInRegion(Region.DEFAULT, imageId)); + System.out.println(client.getLaunchPermissionForImageInRegion(null, imageId)); } public void testGetProductCodesForImage() { - System.out.println(client.getProductCodesForImageInRegion(Region.DEFAULT, imageId)); + System.out.println(client.getProductCodesForImageInRegion(null, imageId)); } @Test(enabled = false) // awaiting ebs support public void testGetBlockDeviceMappingsForImage() { - System.out.println(client.getBlockDeviceMappingsForImageInRegion(Region.DEFAULT, imageId)); + System.out.println(client.getBlockDeviceMappingsForImageInRegion(null, imageId)); } @AfterTest public void deregisterImages() { for (String imageId : imagesToDeregister) - client.deregisterImageInRegion(Region.DEFAULT, imageId); + client.deregisterImageInRegion(null, imageId); } } 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 367595abe4..c80618d6fb 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 @@ -18,44 +18,24 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions.Builder.availabilityZones; import static org.jclouds.aws.ec2.options.DescribeRegionsOptions.Builder.regions; -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 java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.domain.AvailabilityZone; 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; -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; /** @@ -65,7 +45,7 @@ import com.google.inject.TypeLiteral; */ @Test(groups = "unit", testName = "ec2.AvailabilityZoneAndRegionAsyncClientTest") public class AvailabilityZoneAndRegionAsyncClientTest extends - RestClientTest { + BaseEC2AsyncClientTest { public void testDescribeAvailabilityZones() throws SecurityException, NoSuchMethodException, IOException { @@ -149,54 +129,10 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends 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() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.eu-west-1.amazonaws.com"), - Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), - Region.US_WEST_1, URI.create("https://ec2.us-west-1.amazonaws.com")); - } - }; - } } 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 1cc1dafc20..e6fb93e85b 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 @@ -68,7 +68,7 @@ public class AvailabilityZoneAndRegionClientLiveTest { } public void testDescribeAvailabilityZones() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { SortedSet allResults = Sets.newTreeSet(client .describeAvailabilityZonesInRegion(region)); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/BaseEC2AsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/BaseEC2AsyncClientTest.java new file mode 100644 index 0000000000..e5b4dcb716 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/BaseEC2AsyncClientTest.java @@ -0,0 +1,118 @@ +/** + * + * 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.ec2.services; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import java.net.URI; +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.EC2PropertiesBuilder; +import org.jclouds.aws.ec2.domain.AvailabilityZone; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.date.TimeStamp; +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.util.Jsr330; +import org.testng.annotations.BeforeTest; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; + +/** + * + * + * @author Adrian Cole + */ +public abstract class BaseEC2AsyncClientTest extends RestClientTest { + + protected FormSigner filter; + + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); + } + + public BaseEC2AsyncClientTest() { + super(); + } + + @Override + @BeforeTest + protected void setupFactory() { + super.setupFactory(); + this.filter = injector.getInstance(FormSigner.class); + } + + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder("user", "key") + .build(), "properties")); + bind(URI.class).annotatedWith(EC2.class).toInstance( + URI.create("https://ec2.amazonaws.com")); + bind(Region.class).annotatedWith(EC2.class).toInstance(Region.US_EAST_1); + 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 + @EC2 + Map provideMap() { + return ImmutableMap. of(Region.EU_WEST_1, URI + .create("https://ec2.eu-west-1.amazonaws.com"), Region.US_EAST_1, URI + .create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, URI + .create("https://ec2.us-west-1.amazonaws.com")); + } + + @SuppressWarnings("unused") + @Singleton + @Provides + Map provideAvailabilityZoneRegionMap() { + return ImmutableMap. of(AvailabilityZone.US_EAST_1A, + Region.US_EAST_1); + } + }; + } + +} \ No newline at end of file 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 4687bd45bd..df8d8f293c 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 @@ -18,23 +18,14 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.ec2.options.DescribeSnapshotsOptions.Builder.ownedBy; import static org.jclouds.aws.ec2.options.DetachVolumeOptions.Builder.fromInstance; -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 java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.functions.ReturnVoidOnVolumeAvailable; import org.jclouds.aws.ec2.options.CreateSnapshotOptions; @@ -46,24 +37,13 @@ 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; import org.jclouds.http.functions.CloseContentAndReturn; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.rest.RestClientTest; +import org.jclouds.http.functions.ParseSax; 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.ImmutableList; -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; /** @@ -72,7 +52,8 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.ElasticBlockStoreAsyncClientTest") -public class ElasticBlockStoreAsyncClientTest extends RestClientTest { +public class ElasticBlockStoreAsyncClientTest extends + BaseEC2AsyncClientTest { public void testCreateVolume() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod( @@ -80,9 +61,9 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( method, AvailabilityZone.US_EAST_1A, 20); - assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); + assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, - "Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); + "Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20"); @@ -100,9 +81,9 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( method, AvailabilityZone.US_EAST_1A, "snapshotId"); - assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); + assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, - "Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); + "Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId"); @@ -121,9 +102,9 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( method, AvailabilityZone.US_EAST_1A, 15, "snapshotId"); - assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); + assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, - "Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); + "Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15"); @@ -138,7 +119,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "id"); + method, null, "id"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -156,7 +137,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT); + method, (Region) null); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -175,7 +156,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "1", "2"); + method, null, "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -194,7 +175,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "id", "instanceId", "/device"); + method, null, "id", "instanceId", "/device"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -214,7 +195,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "id", false); + method, null, "id", false); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -234,9 +215,8 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor - .createRequest(method, Region.DEFAULT, "id", true, fromInstance("instanceId") - .fromDevice("/device")); + GeneratedHttpRequest httpMethod = processor.createRequest( + method, null, "id", true, fromInstance("instanceId").fromDevice("/device")); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -257,7 +237,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "volumeId"); + method, null, "volumeId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -277,7 +257,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "volumeId", CreateSnapshotOptions.Builder + method, null, "volumeId", CreateSnapshotOptions.Builder .withDescription("description")); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); @@ -297,7 +277,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT); + method, (Region) null); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -316,8 +296,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, ownedBy("o1", "o2").restorableBy("r1", "r2").snapshotIds( - "s1", "s2")); + method, null, ownedBy("o1", "o2").restorableBy("r1", "r2").snapshotIds("s1", "s2")); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -338,7 +317,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "snapshotId"); + method, null, "snapshotId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -360,8 +339,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), - "snapshotId"); + method, null, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "snapshotId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -383,8 +361,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), - "snapshotId"); + method, null, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "snapshotId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -404,7 +381,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, "snapshotId"); + method, null, "snapshotId"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -419,60 +396,10 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest 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() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.amazonaws.com")); - } - - @SuppressWarnings("unused") - @Singleton - @Provides - Map provideAvailabilityZoneRegionMap() { - return ImmutableMap. of(AvailabilityZone.US_EAST_1A, - Region.DEFAULT); - } - }; - } } 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 9f18c62e34..a19deafae9 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 @@ -72,7 +72,7 @@ public class ElasticBlockStoreClientLiveTest { @Test void testDescribeVolumes() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { SortedSet allResults = Sets.newTreeSet(client.describeVolumesInRegion(region)); assertNotNull(allResults); @@ -96,7 +96,7 @@ public class ElasticBlockStoreClientLiveTest { this.volumeId = expected.getId(); - SortedSet result = Sets.newTreeSet(client.describeVolumesInRegion(Region.DEFAULT, + SortedSet result = Sets.newTreeSet(client.describeVolumesInRegion(null, expected.getId())); assertNotNull(result); assertEquals(result.size(), 1); @@ -106,7 +106,7 @@ public class ElasticBlockStoreClientLiveTest { @Test(dependsOnMethods = "testCreateVolumeInAvailabilityZone") void testCreateSnapshotInRegion() { - Snapshot snapshot = client.createSnapshotInRegion(Region.DEFAULT, volumeId); + Snapshot snapshot = client.createSnapshotInRegion(null, volumeId); Predicate snapshotted = new RetryablePredicate(new SnapshotCompleted( client), 600, 10, TimeUnit.SECONDS); assert snapshotted.apply(snapshot); @@ -171,7 +171,7 @@ public class ElasticBlockStoreClientLiveTest { @Test void testDescribeSnapshots() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { SortedSet allResults = Sets.newTreeSet(client.describeSnapshotsInRegion(region)); assertNotNull(allResults); @@ -187,21 +187,21 @@ public class ElasticBlockStoreClientLiveTest { @Test(enabled = false) public void testAddCreateVolumePermissionsToSnapshot() { - // TODO client.addCreateVolumePermissionsToSnapshotInRegion(Region.DEFAULT, userIds, + // TODO client.addCreateVolumePermissionsToSnapshotInRegion(null, userIds, // userGroups, // snapshotId); } @Test(enabled = false) public void testRemoveCreateVolumePermissionsFromSnapshot() { - // TODO client.removeCreateVolumePermissionsFromSnapshotInRegion(Region.DEFAULT, userIds, + // TODO client.removeCreateVolumePermissionsFromSnapshotInRegion(null, userIds, // userGroups, // snapshotId); } @Test(enabled = false) public void testResetCreateVolumePermissionsOnSnapshot() { - // TODO client.resetCreateVolumePermissionsOnSnapshotInRegion(Region.DEFAULT, snapshotId); + // TODO client.resetCreateVolumePermissionsOnSnapshotInRegion(null, snapshotId); } @Test(dependsOnMethods = "testCreateSnapshotInRegion") @@ -212,8 +212,8 @@ public class ElasticBlockStoreClientLiveTest { @Test(dependsOnMethods = "testCreateSnapshotInRegion") void testDeleteVolumeInRegion() { - client.deleteVolumeInRegion(Region.DEFAULT, volumeId); - SortedSet result = Sets.newTreeSet(client.describeVolumesInRegion(Region.DEFAULT, + client.deleteVolumeInRegion(null, volumeId); + SortedSet result = Sets.newTreeSet(client.describeVolumesInRegion(null, volumeId)); assertEquals(result.size(), 1); Volume volume = result.iterator().next(); 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 9d9d0f57de..4bcf840dce 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 @@ -18,41 +18,20 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.testng.Assert.assertEquals; - import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.InetAddress; -import java.net.URI; -import java.util.Map; -import java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.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; import org.jclouds.http.functions.CloseContentAndReturn; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.rest.RestClientTest; +import org.jclouds.http.functions.ParseSax; 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; /** @@ -61,14 +40,15 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.ElasticIPAddressAsyncClientTest") -public class ElasticIPAddressAsyncClientTest extends RestClientTest { +public class ElasticIPAddressAsyncClientTest extends + BaseEC2AsyncClientTest { public void testDisassociateAddress() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticIPAddressAsyncClient.class.getMethod("disassociateAddressInRegion", Region.class, InetAddress.class); GeneratedHttpRequest httpMethod = processor.createRequest( - method, Region.DEFAULT, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); + method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -87,7 +67,7 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), "me"); + method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), "me"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -106,7 +86,7 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); + method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -124,7 +104,7 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); + method, null, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -143,7 +123,7 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( - method, Region.DEFAULT); + method, (Region) null); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -157,54 +137,10 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest 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() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.eu-west-1.amazonaws.com"), - Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), - Region.US_WEST_1, URI.create("https://ec2.us-west-1.amazonaws.com")); - } - }; - } } 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 59e42586e1..a59a3e5394 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 @@ -61,7 +61,7 @@ public class ElasticIPAddressClientLiveTest { @Test void testDescribeAddresses() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { SortedSet allResults = Sets.newTreeSet(client .describeAddressesInRegion(region)); 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 4d1c0b9788..d7bfcc77f0 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 @@ -18,21 +18,11 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; -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 java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.BlockDeviceMapping; import org.jclouds.aws.ec2.domain.InstanceType; @@ -48,24 +38,12 @@ 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.CloseContentAndReturn; 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.BeforeTest; 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; /** @@ -74,12 +52,12 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.InstanceAsyncClientTest") -public class InstanceAsyncClientTest extends RestClientTest { +public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest { public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion", Region.class, Array.newInstance(String.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT); + (Region) null); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -97,8 +75,8 @@ public class InstanceAsyncClientTest extends RestClientTest IOException { Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion", Region.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "2"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -117,8 +95,8 @@ public class InstanceAsyncClientTest extends RestClientTest IOException { Method method = InstanceAsyncClient.class.getMethod("terminateInstancesInRegion", Region.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "2"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -137,8 +115,8 @@ public class InstanceAsyncClientTest extends RestClientTest Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", Region.class, AvailabilityZone.class, String.class, int.class, int.class, Array.newInstance( RunInstancesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, null, "ami-voo", 1, 1); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + null, "ami-voo", 1, 1); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -181,8 +159,8 @@ public class InstanceAsyncClientTest extends RestClientTest public void testStopInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("stopInstancesInRegion", Region.class, boolean.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, true, "1", "2"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + true, "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -200,8 +178,8 @@ public class InstanceAsyncClientTest extends RestClientTest public void testRebootInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("rebootInstancesInRegion", Region.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "2"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -219,8 +197,8 @@ public class InstanceAsyncClientTest extends RestClientTest public void testStartInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("startInstancesInRegion", Region.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "2"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -239,8 +217,8 @@ public class InstanceAsyncClientTest extends RestClientTest NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -259,8 +237,8 @@ public class InstanceAsyncClientTest extends RestClientTest NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -279,8 +257,8 @@ public class InstanceAsyncClientTest extends RestClientTest IOException { Method method = InstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -299,8 +277,8 @@ public class InstanceAsyncClientTest extends RestClientTest NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod( "isApiTerminationDisabledForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -319,8 +297,8 @@ public class InstanceAsyncClientTest extends RestClientTest IOException { Method method = InstanceAsyncClient.class.getMethod("getKernelForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -339,8 +317,8 @@ public class InstanceAsyncClientTest extends RestClientTest NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -360,8 +338,8 @@ public class InstanceAsyncClientTest extends RestClientTest Method method = InstanceAsyncClient.class.getMethod( "getInstanceInitiatedShutdownBehaviorForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -381,8 +359,8 @@ public class InstanceAsyncClientTest extends RestClientTest NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod( "getBlockDeviceMappingForInstanceInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -401,8 +379,8 @@ public class InstanceAsyncClientTest extends RestClientTest NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("setUserDataForInstanceInRegion", Region.class, String.class, Array.newInstance(byte.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "test".getBytes()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "test".getBytes()); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -426,8 +404,8 @@ public class InstanceAsyncClientTest extends RestClientTest IOException { Method method = InstanceAsyncClient.class.getMethod("setRamdiskForInstanceInRegion", Region.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "test"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "test"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -445,8 +423,8 @@ public class InstanceAsyncClientTest extends RestClientTest IOException { Method method = InstanceAsyncClient.class.getMethod("setKernelForInstanceInRegion", Region.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "test"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "test"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -465,8 +443,8 @@ public class InstanceAsyncClientTest extends RestClientTest Method method = InstanceAsyncClient.class.getMethod( "setApiTerminationDisabledForInstanceInRegion", Region.class, String.class, boolean.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", true); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", true); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -486,8 +464,8 @@ public class InstanceAsyncClientTest extends RestClientTest NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion", Region.class, String.class, InstanceType.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", InstanceType.C1_MEDIUM); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", InstanceType.C1_MEDIUM); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -508,8 +486,8 @@ public class InstanceAsyncClientTest extends RestClientTest Method method = InstanceAsyncClient.class.getMethod( "setInstanceInitiatedShutdownBehaviorForInstanceInRegion", Region.class, String.class, InstanceInitiatedShutdownBehavior.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", InstanceInitiatedShutdownBehavior.TERMINATE); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", InstanceInitiatedShutdownBehavior.TERMINATE); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -534,8 +512,8 @@ public class InstanceAsyncClientTest extends RestClientTest BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice( "vol-test1", true)); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", blockDeviceMapping); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", blockDeviceMapping); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -555,63 +533,9 @@ public class InstanceAsyncClientTest extends RestClientTest 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>() { }; } - - private FormSigner filter; - - @Override - @BeforeTest - protected void setupFactory() { - super.setupFactory(); - this.filter = injector.getInstance(FormSigner.class); - } - - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.eu-west-1.amazonaws.com"), - Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), - Region.US_WEST_1, URI.create("https://ec2.us-west-1.amazonaws.com")); - } - }; - } } 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 4b0c65098a..b74ae48e76 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 @@ -61,7 +61,7 @@ public class InstanceClientLiveTest { @Test void testDescribeInstances() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { Set allResults = client.describeInstancesInRegion(region); assertNotNull(allResults); 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 b7e942ca47..8c863d03c8 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 @@ -18,39 +18,18 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; -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 java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.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; import org.jclouds.http.functions.CloseContentAndReturn; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.rest.RestClientTest; +import org.jclouds.http.functions.ParseSax; 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; /** @@ -59,13 +38,13 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.KeyPairAsyncClientTest") -public class KeyPairAsyncClientTest extends RestClientTest { +public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest { public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException { Method method = KeyPairAsyncClient.class.getMethod("deleteKeyPairInRegion", Region.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "mykey"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "mykey"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -83,7 +62,7 @@ public class KeyPairAsyncClientTest extends RestClientTest { Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", Region.class, Array.newInstance(String.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT); + (Region) null); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -101,8 +80,8 @@ public class KeyPairAsyncClientTest extends RestClientTest { IOException { Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", Region.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "2"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -117,54 +96,10 @@ public class KeyPairAsyncClientTest extends RestClientTest { 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() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.eu-west-1.amazonaws.com"), - Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), - Region.US_WEST_1, URI.create("https://ec2.us-west-1.amazonaws.com")); - } - }; - } } 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 89d6c5b879..08355280d1 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 @@ -61,7 +61,7 @@ public class KeyPairClientLiveTest { @Test void testDescribeKeyPairs() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { SortedSet allResults = Sets.newTreeSet(client.describeKeyPairsInRegion(region)); @@ -83,20 +83,20 @@ public class KeyPairClientLiveTest { void testCreateKeyPair() { String keyName = PREFIX + "1"; try { - client.deleteKeyPairInRegion(Region.DEFAULT, keyName); + client.deleteKeyPairInRegion(null, keyName); } catch (Exception e) { } - client.deleteKeyPairInRegion(Region.DEFAULT, keyName); + client.deleteKeyPairInRegion(null, keyName); - KeyPair result = client.createKeyPairInRegion(Region.DEFAULT, keyName); + KeyPair result = client.createKeyPairInRegion(null, keyName); assertNotNull(result); assertNotNull(result.getKeyMaterial()); assertNotNull(result.getKeyFingerprint()); assertEquals(result.getKeyName(), keyName); SortedSet twoResults = Sets.newTreeSet(client.describeKeyPairsInRegion( - Region.DEFAULT, keyName)); + null, keyName)); assertNotNull(twoResults); assertEquals(twoResults.size(), 1); KeyPair listPair = twoResults.iterator().next(); 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 98a05c2e6b..eb50f8e803 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 @@ -18,38 +18,17 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; -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 java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.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; -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; /** @@ -58,14 +37,14 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.MonitoringAsyncClientTest") -public class MonitoringAsyncClientTest extends RestClientTest { +public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest { public void testUnmonitorInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = MonitoringAsyncClient.class.getMethod("unmonitorInstancesInRegion", Region.class, String.class, Array.newInstance(String.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "instance1", "instance2"); + null, "instance1", "instance2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -84,7 +63,7 @@ public class MonitoringAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT, "instance1", "instance2"); + null, "instance1", "instance2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -99,54 +78,10 @@ public class MonitoringAsyncClientTest extends RestClientTest 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() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.eu-west-1.amazonaws.com"), - Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), - Region.US_WEST_1, URI.create("https://ec2.us-west-1.amazonaws.com")); - } - }; - } } 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 33c7f8cffc..6d115da7b5 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,7 +23,6 @@ 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; @@ -59,7 +58,7 @@ public class MonitoringClientLiveTest { // TODO get instance public void testMonitorInstances() { Map monitoringState = client.monitorInstancesInRegion( - Region.DEFAULT, DEFAULT_INSTANCE); + null, DEFAULT_INSTANCE); assertEquals(monitoringState.get(DEFAULT_INSTANCE), MonitoringState.PENDING); } @@ -67,7 +66,7 @@ public class MonitoringClientLiveTest { // TODO get instance public void testUnmonitorInstances() { Map monitoringState = client.unmonitorInstancesInRegion( - Region.DEFAULT, DEFAULT_INSTANCE); + null, DEFAULT_INSTANCE); assertEquals(monitoringState.get(DEFAULT_INSTANCE), MonitoringState.PENDING); } 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 05c97fd67f..9ba0c02a53 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 @@ -18,42 +18,21 @@ */ package org.jclouds.aws.ec2.services; -import static com.google.common.base.Preconditions.checkNotNull; -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 java.util.Properties; - -import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.EC2; -import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.UserIdGroupPair; 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; import org.jclouds.http.functions.CloseContentAndReturn; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.rest.RestClientTest; +import org.jclouds.http.functions.ParseSax; 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; /** @@ -62,14 +41,14 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.SecurityGroupAsyncClientTest") -public class SecurityGroupAsyncClientTest extends RestClientTest { +public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest { public void testDeleteSecurityGroup() throws SecurityException, NoSuchMethodException, IOException { Method method = SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroupInRegion", Region.class, String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "name"); + null, "name"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -89,7 +68,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT, "name", "description"); + null, "name", "description"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -109,7 +88,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT); + (Region) null); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -128,7 +107,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT, "1", "2"); + null, "1", "2"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -149,7 +128,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); + null, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -171,7 +150,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); + null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -193,7 +172,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); + null, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -215,7 +194,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - Region.DEFAULT, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); + null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -231,54 +210,10 @@ public class SecurityGroupAsyncClientTest extends RestClientTest 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() { - Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) - .build(), "properties")); - bind(URI.class).annotatedWith(EC2.class).toInstance( - URI.create("https://ec2.amazonaws.com")); - 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://ec2.eu-west-1.amazonaws.com"), - Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), - Region.US_WEST_1, URI.create("https://ec2.us-west-1.amazonaws.com")); - } - }; - } } 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 3d79bea943..f61879e155 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 @@ -69,8 +69,7 @@ public class SecurityGroupClientLiveTest { @Test void testDescribe() { - for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, - Region.US_WEST_1)) { + for (Region region : ImmutableSet.of(Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1)) { SortedSet allResults = Sets.newTreeSet(client .describeSecurityGroupsInRegion(region)); assertNotNull(allResults); @@ -90,13 +89,13 @@ public class SecurityGroupClientLiveTest { String groupName = PREFIX + "1"; String groupDescription = PREFIX + "1 description"; try { - client.deleteSecurityGroupInRegion(Region.DEFAULT, groupName); + client.deleteSecurityGroupInRegion(null, groupName); } catch (Exception e) { } - client.deleteSecurityGroupInRegion(Region.DEFAULT, groupName); + client.deleteSecurityGroupInRegion(null, groupName); - client.createSecurityGroupInRegion(Region.DEFAULT, groupName, groupDescription); + client.createSecurityGroupInRegion(null, groupName, groupDescription); verifySecurityGroup(groupName, groupDescription); } @@ -107,25 +106,24 @@ public class SecurityGroupClientLiveTest { String groupName = PREFIX + "ingress"; try { - client.deleteSecurityGroupInRegion(Region.DEFAULT, groupName); + client.deleteSecurityGroupInRegion(null, groupName); } catch (Exception e) { } - client.createSecurityGroupInRegion(Region.DEFAULT, groupName, groupName); - client.authorizeSecurityGroupIngressInRegion(Region.DEFAULT, groupName, IpProtocol.TCP, 80, - 80, "0.0.0.0/0"); + client.createSecurityGroupInRegion(null, groupName, groupName); + client.authorizeSecurityGroupIngressInRegion(null, groupName, IpProtocol.TCP, 80, 80, + "0.0.0.0/0"); assertEventually(new GroupHasPermission(client, groupName, new IpPermission(80, 80, Sets . newTreeSet(), IpProtocol.TCP, ImmutableSortedSet.of("0.0.0.0/0")))); - client.revokeSecurityGroupIngressInRegion(Region.DEFAULT, groupName, IpProtocol.TCP, 80, 80, + client.revokeSecurityGroupIngressInRegion(null, groupName, IpProtocol.TCP, 80, 80, "0.0.0.0/0"); assertEventually(new GroupHasNoPermissions(client, groupName)); } private void verifySecurityGroup(String groupName, String description) { - SortedSet oneResult = client.describeSecurityGroupsInRegion(Region.DEFAULT, - groupName); + SortedSet oneResult = client.describeSecurityGroupsInRegion(null, groupName); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); SecurityGroup listPair = oneResult.iterator().next(); @@ -140,38 +138,37 @@ public class SecurityGroupClientLiveTest { String group2Name = PREFIX + "ingress2"; try { - client.deleteSecurityGroupInRegion(Region.DEFAULT, group1Name); + client.deleteSecurityGroupInRegion(null, group1Name); } catch (Exception e) { } try { - client.deleteSecurityGroupInRegion(Region.DEFAULT, group2Name); + client.deleteSecurityGroupInRegion(null, group2Name); } catch (Exception e) { } - client.createSecurityGroupInRegion(Region.DEFAULT, group1Name, group1Name); - client.createSecurityGroupInRegion(Region.DEFAULT, group2Name, group2Name); + client.createSecurityGroupInRegion(null, group1Name, group1Name); + client.createSecurityGroupInRegion(null, group2Name, group2Name); ensureGroupsExist(group1Name, group2Name); - client.authorizeSecurityGroupIngressInRegion(Region.DEFAULT, group1Name, IpProtocol.TCP, 80, - 80, "0.0.0.0/0"); + client.authorizeSecurityGroupIngressInRegion(null, group1Name, IpProtocol.TCP, 80, 80, + "0.0.0.0/0"); assertEventually(new GroupHasPermission(client, group2Name, new IpPermission(80, 80, Sets . newTreeSet(), IpProtocol.TCP, ImmutableSortedSet.of("0.0.0.0/0")))); - SortedSet oneResult = client.describeSecurityGroupsInRegion(Region.DEFAULT, - group1Name); + SortedSet oneResult = client.describeSecurityGroupsInRegion(null, group1Name); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); SecurityGroup group = oneResult.iterator().next(); assertEquals(group.getName(), group1Name); - client.authorizeSecurityGroupIngressInRegion(Region.DEFAULT, group2Name, new UserIdGroupPair( - group.getOwnerId(), group1Name)); + client.authorizeSecurityGroupIngressInRegion(null, group2Name, new UserIdGroupPair(group + .getOwnerId(), group1Name)); assertEventually(new GroupHasPermission(client, group2Name, new IpPermission(80, 80, Sets . newTreeSet(), IpProtocol.TCP, ImmutableSortedSet.of("0.0.0.0/0")))); - client.revokeSecurityGroupIngressInRegion(Region.DEFAULT, group2Name, new UserIdGroupPair( - group.getOwnerId(), group1Name)); + client.revokeSecurityGroupIngressInRegion(null, group2Name, new UserIdGroupPair(group + .getOwnerId(), group1Name)); assertEventually(new GroupHasNoPermissions(client, group2Name)); } @@ -188,8 +185,7 @@ public class SecurityGroupClientLiveTest { public void run() { try { - SortedSet oneResult = client.describeSecurityGroupsInRegion( - Region.DEFAULT, group); + SortedSet oneResult = client.describeSecurityGroupsInRegion(null, group); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); SecurityGroup listPair = oneResult.iterator().next(); @@ -211,8 +207,7 @@ public class SecurityGroupClientLiveTest { public void run() { try { - Set oneResult = client.describeSecurityGroupsInRegion(Region.DEFAULT, - group); + Set oneResult = client.describeSecurityGroupsInRegion(null, group); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); SecurityGroup listPair = oneResult.iterator().next(); @@ -224,8 +219,8 @@ public class SecurityGroupClientLiveTest { } private void ensureGroupsExist(String group1Name, String group2Name) { - SortedSet twoResults = client.describeSecurityGroupsInRegion(Region.DEFAULT, - group1Name, group2Name); + SortedSet twoResults = client.describeSecurityGroupsInRegion(null, group1Name, + group2Name); assertNotNull(twoResults); assertEquals(twoResults.size(), 2); Iterator iterator = twoResults.iterator(); 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 ec29a069b0..19ae4c6116 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 @@ -18,15 +18,15 @@ */ package org.jclouds.aws.ec2.xml; -import static org.easymock.classextension.EasyMock.*; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; 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.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -37,13 +37,13 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.AttachmentHandlerTest") -public class AttachmentHandlerTest extends BaseHandlerTest { +public class AttachmentHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { DateService dateService = injector.getInstance(DateService.class); InputStream is = getClass().getResourceAsStream("/ec2/attach.xml"); - Attachment expected = new Attachment(Region.DEFAULT, "vol-4d826724", "i-6058a509", - "/dev/sdh", Attachment.Status.ATTACHING, dateService + Attachment expected = new Attachment(defaultRegion, "vol-4d826724", "i-6058a509", "/dev/sdh", + Attachment.Status.ATTACHING, dateService .iso8601DateParse("2008-05-07T11:51:50.000Z")); AttachmentHandler handler = injector.getInstance(AttachmentHandler.class); @@ -55,7 +55,7 @@ public class AttachmentHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }); + expect(request.getArgs()).andReturn(new Object[] { null }); replay(request); handler.setContext(request); } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/BaseEC2HandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/BaseEC2HandlerTest.java new file mode 100644 index 0000000000..dfaf03dda2 --- /dev/null +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/BaseEC2HandlerTest.java @@ -0,0 +1,79 @@ +/** + * + * 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.ec2.xml; + +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.http.functions.BaseHandlerTest; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.config.ParserModule; +import org.testng.annotations.BeforeTest; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +public class BaseEC2HandlerTest extends BaseHandlerTest { + protected Region defaultRegion = Region.US_EAST_1; + + public BaseEC2HandlerTest() { + super(); + } + + @BeforeTest + @Override + protected void setUpInjector() { + injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + + @Override + protected void configure() { + + } + + @SuppressWarnings("unused") + @Singleton + @Provides + @EC2 + Region provideDefaultRegion() { + return defaultRegion; + } + + @SuppressWarnings("unused") + @Singleton + @Provides + Map provideAvailabilityZoneRegionMap() { + return ImmutableMap. of(AvailabilityZone.US_EAST_1A, + Region.US_EAST_1); + } + }); + factory = injector.getInstance(ParseSax.Factory.class); + assert factory != null; + } + +} \ No newline at end of file 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 c82d6edff5..4552b0a579 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 @@ -24,27 +24,18 @@ import static org.easymock.classextension.EasyMock.replay; import static org.testng.Assert.assertEquals; import java.io.InputStream; -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.Volume; import org.jclouds.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; -import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Provides; /** * Tests behavior of {@code CreateVolumeResponseHandler} @@ -52,35 +43,13 @@ import com.google.inject.Provides; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.CreateVolumeResponseHandlerTest") -public class CreateVolumeResponseHandlerTest extends BaseHandlerTest { - - @BeforeTest - @Override - protected void setUpInjector() { - injector = Guice.createInjector(new ParserModule(), new AbstractModule() { - - @Override - protected void configure() { - - } - - @SuppressWarnings("unused") - @Singleton - @Provides - Map provideAvailabilityZoneRegionMap() { - return ImmutableMap. of(AvailabilityZone.US_EAST_1A, - Region.DEFAULT); - } - }); - factory = injector.getInstance(ParseSax.Factory.class); - assert factory != null; - } +public class CreateVolumeResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { DateService dateService = injector.getInstance(DateService.class); InputStream is = getClass().getResourceAsStream("/ec2/created_volume.xml"); - Volume expected = new Volume(Region.DEFAULT, "vol-2a21e543", 1, null, + Volume expected = new Volume(Region.US_EAST_1, "vol-2a21e543", 1, null, AvailabilityZone.US_EAST_1A, Volume.Status.CREATING, dateService .iso8601DateParse("2009-12-28T05:42:53.000Z"), Sets . newLinkedHashSet()); @@ -94,7 +63,7 @@ public class CreateVolumeResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 db8c65608f..17af917147 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,9 +28,7 @@ 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.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -43,7 +41,7 @@ import com.google.common.collect.ImmutableList; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.DescribeAddressesResponseHandlerTest") -public class DescribeAddressesResponseHandlerTest extends BaseHandlerTest { +public class DescribeAddressesResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/ec2/describe_addresses.xml"); @@ -54,14 +52,14 @@ public class DescribeAddressesResponseHandlerTest extends BaseHandlerTest { Set result = factory.create(handler).parse(is); - assertEquals(result, ImmutableList.of(new PublicIpInstanceIdPair(Region.DEFAULT, InetAddress + assertEquals(result, ImmutableList.of(new PublicIpInstanceIdPair(defaultRegion, InetAddress .getByName("67.202.55.255"), "i-f15ebb98"), new PublicIpInstanceIdPair( - Region.DEFAULT, InetAddress.getByName("67.202.55.233"), null))); + defaultRegion, InetAddress.getByName("67.202.55.233"), null))); } private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 e2d91e9bb8..3142184843 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,14 +27,12 @@ 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.RootDeviceType; import org.jclouds.aws.ec2.domain.Image.Architecture; import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice; import org.jclouds.aws.ec2.domain.Image.ImageState; import org.jclouds.aws.ec2.domain.Image.ImageType; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -48,13 +46,13 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.DescribeImagesResponseHandlerTest") -public class DescribeImagesResponseHandlerTest extends BaseHandlerTest { +public class DescribeImagesResponseHandlerTest extends BaseEC2HandlerTest { public void testUNIX() { InputStream is = getClass().getResourceAsStream("/ec2/describe_images.xml"); SortedSet contents = Sets.newTreeSet(); - contents.add(new Image(Region.DEFAULT, Architecture.I386, null, null, "ami-be3adfd7", + contents.add(new Image(defaultRegion, Architecture.I386, null, null, "ami-be3adfd7", "ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml", "206029621532", ImageState.AVAILABLE, ImageType.MACHINE, false, Sets. newHashSet("9961934F"), "aki-4438dd2d", null, "ari-4538dd2c", @@ -69,7 +67,7 @@ public class DescribeImagesResponseHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/describe_images_windows.xml"); SortedSet contents = Sets.newTreeSet(); - contents.add(new Image(Region.DEFAULT, Architecture.X86_64, null, null, "ami-02eb086b", + contents.add(new Image(defaultRegion, Architecture.X86_64, null, null, "ami-02eb086b", "aws-solutions-amis/SqlSvrStd2003r2-x86_64-Win_SFWBasic5.1-v1.0.manifest.xml", "771350841976", ImageState.AVAILABLE, ImageType.MACHINE, true, Sets . newHashSet("5771E9A6"), null, "windows", null, @@ -84,7 +82,7 @@ public class DescribeImagesResponseHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/describe_images_ebs.xml"); SortedSet contents = Sets.newTreeSet(); - contents.add(new Image(Region.DEFAULT, Architecture.I386, "websrv_2009-12-10", + contents.add(new Image(defaultRegion, Architecture.I386, "websrv_2009-12-10", "Web Server AMI", "ami-246f8d4d", "706093390852/websrv_2009-12-10", "706093390852", ImageState.AVAILABLE, ImageType.MACHINE, true, Sets. newHashSet(), null, "windows", null, RootDeviceType.EBS, "/dev/sda1", ImmutableMap @@ -107,7 +105,7 @@ public class DescribeImagesResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }); + expect(request.getArgs()).andReturn(new Object[] { null }); replay(request); handler.setContext(request); } 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 3da30a4a2f..99c3c4f631 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,7 +28,6 @@ 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; @@ -38,7 +37,6 @@ import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance.EbsBlockDevice; import org.jclouds.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.BeforeTest; @@ -54,7 +52,7 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.DescribeInstancesResponseHandlerTest") -public class DescribeInstancesResponseHandlerTest extends BaseHandlerTest { +public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { private DateService dateService; @@ -71,8 +69,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/describe_instances_running.xml"); Set contents = Sets.newTreeSet(); - contents.add(new Reservation(Region.DEFAULT, ImmutableSet.of("adriancole.ec2ingress"), - ImmutableSet.of(new RunningInstance(Region.DEFAULT, "0", + contents.add(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), + ImmutableSet.of(new RunningInstance(defaultRegion, "0", "ec2-174-129-81-68.compute-1.amazonaws.com", "ami-1fd73376", "i-0799056f", InstanceState.RUNNING, InstanceType.M1_SMALL, InetAddress .getByName("174.129.81.68"), "aki-a71cf9ce", "adriancole.ec21", @@ -93,8 +91,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/describe_instances.xml"); Set contents = Sets.newTreeSet(); - contents.add(new Reservation(Region.DEFAULT, ImmutableSet.of("default"), ImmutableSet.of( - new RunningInstance(Region.DEFAULT, "23", "ec2-72-44-33-4.compute-1.amazonaws.com", + contents.add(new Reservation(defaultRegion, ImmutableSet.of("default"), ImmutableSet.of( + new RunningInstance(defaultRegion, "23", "ec2-72-44-33-4.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64341", InstanceState.RUNNING, InstanceType.M1_LARGE, (InetAddress) null, "aki-ba3adfd3", "example-key-name", dateService .iso8601DateParse("2007-08-07T11:54:42.000Z"), false, @@ -102,7 +100,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseHandlerTest { ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap . of()), new RunningInstance( - Region.DEFAULT, "23", "ec2-72-44-33-6.compute-1.amazonaws.com", + defaultRegion, "23", "ec2-72-44-33-6.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64435", InstanceState.RUNNING, InstanceType.M1_LARGE, (InetAddress) null, "aki-ba3adfd3", "example-key-name", dateService .iso8601DateParse("2007-08-07T11:54:42.000Z"), false, @@ -122,8 +120,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/describe_instances_ebs.xml"); Set contents = Sets.newTreeSet(); - contents.add(new Reservation(Region.DEFAULT, ImmutableSet.of("adriancole.ec2ebsingress"), - ImmutableSet.of(new RunningInstance(Region.DEFAULT, "0", + contents.add(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"), + ImmutableSet.of(new RunningInstance(defaultRegion, "0", "ec2-75-101-203-146.compute-1.amazonaws.com", "ami-849875ed", "i-e564438d", InstanceState.RUNNING, InstanceType.M1_SMALL, InetAddress .getByName("75.101.203.146"), "aki-a71cf9ce", @@ -153,7 +151,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 10a61878a6..b8276660e6 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,9 +26,7 @@ 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.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -41,12 +39,12 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.DescribeKeyPairsHandlerTest") -public class DescribeKeyPairsResponseHandlerTest extends BaseHandlerTest { +public class DescribeKeyPairsResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/ec2/describe_keypairs.xml"); - Set expected = ImmutableSet.of(new KeyPair(Region.DEFAULT, "gsg-keypair", + Set expected = ImmutableSet.of(new KeyPair(defaultRegion, "gsg-keypair", "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f", null)); DescribeKeyPairsResponseHandler handler = injector @@ -58,7 +56,7 @@ public class DescribeKeyPairsResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }); + expect(request.getArgs()).andReturn(new Object[] { null }); replay(request); handler.setContext(request); } 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 17c803df8c..a0a448ee78 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,12 +27,10 @@ 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.SecurityGroup; import org.jclouds.aws.ec2.domain.UserIdGroupPair; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -45,20 +43,19 @@ import com.google.common.collect.ImmutableSortedSet; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.DescribeSecurityGroupsHandlerTest") -public class DescribeSecurityGroupsResponseHandlerTest extends BaseHandlerTest { +public class DescribeSecurityGroupsResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/ec2/describe_securitygroups.xml"); - SortedSet expected = ImmutableSortedSet.of(new SecurityGroup(Region.DEFAULT, + SortedSet expected = ImmutableSortedSet.of(new SecurityGroup(defaultRegion, "WebServers", "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", "Web Servers", ImmutableSortedSet .of(new IpPermission(80, 80, ImmutableSortedSet. of(), IpProtocol.TCP, ImmutableSortedSet.of("0.0.0.0/0")))), - new SecurityGroup(Region.DEFAULT, "RangedPortsBySource", - "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", "Group A", ImmutableSortedSet - .of(new IpPermission(6000, 7000, ImmutableSortedSet - . of(), IpProtocol.TCP, - ImmutableSortedSet. of())))); + new SecurityGroup(defaultRegion, "RangedPortsBySource", "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", + "Group A", ImmutableSortedSet.of(new IpPermission(6000, 7000, + ImmutableSortedSet. of(), IpProtocol.TCP, + ImmutableSortedSet. of())))); DescribeSecurityGroupsResponseHandler handler = injector .getInstance(DescribeSecurityGroupsResponseHandler.class); @@ -70,7 +67,7 @@ public class DescribeSecurityGroupsResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 9103b2f0f5..57b88227a8 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,10 +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.Snapshot; import org.jclouds.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -42,13 +40,13 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.DescribeSnapshotsResponseHandlerTest") -public class DescribeSnapshotsResponseHandlerTest extends BaseHandlerTest { +public class DescribeSnapshotsResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { DateService dateService = injector.getInstance(DateService.class); InputStream is = getClass().getResourceAsStream("/ec2/describe_snapshots.xml"); Set expected = Sets.newLinkedHashSet(); - expected.add(new Snapshot(Region.DEFAULT, "snap-78a54011", "vol-4d826724", 10, + expected.add(new Snapshot(defaultRegion, "snap-78a54011", "vol-4d826724", 10, Snapshot.Status.PENDING, dateService.iso8601DateParse("2008-05-07T12:51:50.000Z"), 80, "218213537122", "Daily Backup", null)); @@ -62,7 +60,7 @@ public class DescribeSnapshotsResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }); + expect(request.getArgs()).andReturn(new Object[] { null }); replay(request); handler.setContext(request); } 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 f605aeaea6..8295e3b1d0 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 @@ -24,28 +24,17 @@ import static org.easymock.classextension.EasyMock.replay; import static org.testng.Assert.assertEquals; import java.io.InputStream; -import java.util.Map; 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.Volume; import org.jclouds.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; -import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Provides; /** * Tests behavior of {@code DescribeVolumesResponseHandler} @@ -53,43 +42,21 @@ import com.google.inject.Provides; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.DescribeVolumesResponseHandlerTest") -public class DescribeVolumesResponseHandlerTest extends BaseHandlerTest { - - @BeforeTest - @Override - protected void setUpInjector() { - injector = Guice.createInjector(new ParserModule(), new AbstractModule(){ +public class DescribeVolumesResponseHandlerTest extends BaseEC2HandlerTest { - @Override - protected void configure() { - - } - - @SuppressWarnings("unused") - @Singleton - @Provides - Map provideAvailabilityZoneRegionMap() { - return ImmutableMap. of(AvailabilityZone.US_EAST_1A, - Region.DEFAULT); - } - }); - factory = injector.getInstance(ParseSax.Factory.class); - assert factory != null; - } - public void testApplyInputStream() { DateService dateService = injector.getInstance(DateService.class); InputStream is = getClass().getResourceAsStream("/ec2/describe_volumes.xml"); Set expected = Sets.newLinkedHashSet(); - expected.add(new Volume(Region.DEFAULT, "vol-2a21e543", 1, null, AvailabilityZone.US_EAST_1A, + expected.add(new Volume(defaultRegion, "vol-2a21e543", 1, null, AvailabilityZone.US_EAST_1A, Volume.Status.AVAILABLE, dateService.iso8601DateParse("2009-12-28T05:42:53.000Z"), Sets. newLinkedHashSet())); - expected.add(new Volume(Region.DEFAULT, "vol-4282672b", 800, "snap-536d1b3a", + expected.add(new Volume(defaultRegion, "vol-4282672b", 800, "snap-536d1b3a", AvailabilityZone.US_EAST_1A, Volume.Status.IN_USE, dateService .iso8601DateParse("2008-05-07T11:51:50.000Z"), Sets - . newHashSet(new Attachment(Region.DEFAULT, "vol-4282672b", - "i-6058a509", "/dev/sdh", Attachment.Status.ATTACHED, dateService + . newHashSet(new Attachment(defaultRegion, "vol-4282672b", "i-6058a509", + "/dev/sdh", Attachment.Status.ATTACHED, dateService .iso8601DateParse("2008-05-07T12:51:50.000Z"))))); DescribeVolumesResponseHandler handler = injector @@ -102,7 +69,7 @@ public class DescribeVolumesResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 34bda4ecf7..5d44f8b28f 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,11 +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.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.BeforeTest; @@ -44,7 +42,7 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.InstanceStateChangeHandlerTest") -public class InstanceStateChangeHandlerTest extends BaseHandlerTest { +public class InstanceStateChangeHandlerTest extends BaseEC2HandlerTest { private DateService dateService; @@ -60,7 +58,7 @@ public class InstanceStateChangeHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/terminate_instances.xml"); - Set expected = ImmutableSet.of(new InstanceStateChange(Region.DEFAULT, + Set expected = ImmutableSet.of(new InstanceStateChange(defaultRegion, "i-3ea74257", InstanceState.SHUTTING_DOWN, InstanceState.RUNNING)); InstanceStateChangeHandler handler = injector.getInstance(InstanceStateChangeHandler.class); @@ -73,7 +71,7 @@ public class InstanceStateChangeHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/start_instances.xml"); - Set expected = ImmutableSet.of(new InstanceStateChange(Region.DEFAULT, + Set expected = ImmutableSet.of(new InstanceStateChange(defaultRegion, "i-10a64379", InstanceState.PENDING, InstanceState.STOPPED)); InstanceStateChangeHandler handler = injector.getInstance(InstanceStateChangeHandler.class); addDefaultRegionToHandler(handler); @@ -85,7 +83,7 @@ public class InstanceStateChangeHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/stop_instances.xml"); - Set expected = ImmutableSet.of(new InstanceStateChange(Region.DEFAULT, + Set expected = ImmutableSet.of(new InstanceStateChange(defaultRegion, "i-10a64379", InstanceState.STOPPING, InstanceState.RUNNING)); InstanceStateChangeHandler handler = injector.getInstance(InstanceStateChangeHandler.class); @@ -96,7 +94,7 @@ public class InstanceStateChangeHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 c315544cde..e980871453 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,9 +25,7 @@ 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.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -38,13 +36,13 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.KeyPairResponseHandlerTest") -public class KeyPairResponseHandlerTest extends BaseHandlerTest { +public class KeyPairResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/ec2/create_keypair.xml"); KeyPair expected = new KeyPair( - Region.DEFAULT, + defaultRegion, "gsg-keypair", "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f", "-----BEGIN RSA PRIVATE KEY-----\n" @@ -80,7 +78,7 @@ public class KeyPairResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 0276f28df9..a9fe32153f 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,7 +26,6 @@ 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; @@ -35,7 +34,6 @@ import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance.EbsBlockDevice; import org.jclouds.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.BeforeTest; @@ -52,7 +50,7 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.RunInstancesResponseHandlerTest") -public class RunInstancesResponseHandlerTest extends BaseHandlerTest { +public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { private DateService dateService; @@ -68,8 +66,8 @@ public class RunInstancesResponseHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/ec2/run_instances.xml"); - Reservation expected = new Reservation(Region.DEFAULT, ImmutableSortedSet.of("default"), - ImmutableSet.of(new RunningInstance(Region.DEFAULT, "0", null, "ami-60a54009", + Reservation expected = new Reservation(defaultRegion, ImmutableSortedSet.of("default"), + ImmutableSet.of(new RunningInstance(defaultRegion, "0", null, "ami-60a54009", "i-2ba64342", InstanceState.PENDING, InstanceType.M1_SMALL, (InetAddress) null, null, "example-key-name", dateService .iso8601DateParse("2007-08-07T11:51:50.000Z"), true, @@ -77,7 +75,7 @@ public class RunInstancesResponseHandlerTest extends BaseHandlerTest { . newTreeSet(), null, null, null, null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap . of()), new RunningInstance( - Region.DEFAULT, "1", null, "ami-60a54009", "i-2bc64242", + defaultRegion, "1", null, "ami-60a54009", "i-2bc64242", InstanceState.PENDING, InstanceType.M1_SMALL, (InetAddress) null, null, "example-key-name", dateService .iso8601DateParse("2007-08-07T11:51:50.000Z"), true, @@ -85,7 +83,7 @@ public class RunInstancesResponseHandlerTest extends BaseHandlerTest { . newTreeSet(), null, null, null, null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap . of()), new RunningInstance( - Region.DEFAULT, "2", null, "ami-60a54009", "i-2be64332", + defaultRegion, "2", null, "ami-60a54009", "i-2be64332", InstanceState.PENDING, InstanceType.M1_SMALL, (InetAddress) null, null, "example-key-name", dateService .iso8601DateParse("2007-08-07T11:51:50.000Z"), true, @@ -104,7 +102,7 @@ public class RunInstancesResponseHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } 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 a9c6c18d5f..14636b0ac9 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,10 +25,8 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; -import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.domain.Snapshot; import org.jclouds.date.DateService; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -39,14 +37,14 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "ec2.SnapshotHandlerTest") -public class SnapshotHandlerTest extends BaseHandlerTest { +public class SnapshotHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { DateService dateService = injector.getInstance(DateService.class); InputStream is = getClass().getResourceAsStream("/ec2/created_snapshot.xml"); - Snapshot expected = new Snapshot(Region.DEFAULT, "snap-78a54011", "vol-4d826724", 10, Snapshot.Status.PENDING, - dateService.iso8601DateParse("2008-05-07T12:51:50.000Z"), 60, "213457642086", - "Daily Backup", null); + Snapshot expected = new Snapshot(defaultRegion, "snap-78a54011", "vol-4d826724", 10, + Snapshot.Status.PENDING, dateService.iso8601DateParse("2008-05-07T12:51:50.000Z"), + 60, "213457642086", "Daily Backup", null); SnapshotHandler handler = injector.getInstance(SnapshotHandler.class); addDefaultRegionToHandler(handler); @@ -56,7 +54,7 @@ public class SnapshotHandlerTest extends BaseHandlerTest { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { Region.DEFAULT }).atLeastOnce(); + expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce(); replay(request); handler.setContext(request); } diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java index 3a9e5d43d9..b152613321 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; -import java.util.Properties; import org.jclouds.aws.domain.Region; import org.jclouds.aws.s3.blobstore.functions.BlobToObject; @@ -47,7 +46,6 @@ import org.jclouds.aws.s3.options.CopyObjectOptions; import org.jclouds.aws.s3.options.ListBucketOptions; import org.jclouds.aws.s3.options.PutBucketOptions; import org.jclouds.aws.s3.options.PutObjectOptions; -import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.xml.AccessControlListHandler; import org.jclouds.aws.s3.xml.BucketLoggingHandler; import org.jclouds.aws.s3.xml.CopyObjectHandler; @@ -385,7 +383,7 @@ public class S3AsyncClientTest extends RestClientTest { Method method = S3AsyncClient.class.getMethod("putBucketInRegion", Region.class, String.class, Array.newInstance(PutBucketOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT, "bucket"); + (Region) null, "bucket"); assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/ HTTP/1.1"); assertHeadersEqual(httpMethod, "Content-Length: 0\nHost: bucket.stub\n"); @@ -546,13 +544,10 @@ public class S3AsyncClientTest extends RestClientTest { }, new TypeLiteral() { })); install(new S3ObjectModule()); - Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder(new Properties()) - .build(), "properties")); + Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user", "key") + .build(), "properties")); bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("http://stub:8080")); - bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to( - "user"); - bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)) - .to("key"); + bind(Region.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD); bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { public Logger getLogger(String category) { return Logger.NULL; diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreModuleTest.java deleted file mode 100755 index be3aab49a1..0000000000 --- a/aws/core/src/test/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreModuleTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - * 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.s3.blobstore.config; - -import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; -import static org.testng.Assert.assertEquals; - -import org.jclouds.Constants; -import org.jclouds.aws.s3.config.S3StubClientModule; -import org.jclouds.aws.s3.reference.S3Constants; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.internal.BlobStoreContextImpl; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; -import org.jclouds.util.Jsr330; -import org.testng.annotations.Test; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.S3BlobStoreModuleTest") -public class S3BlobStoreModuleTest { - - Injector createInjector() { - return Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(), - sameThreadExecutor()), new JDKLoggingModule(), new S3StubClientModule(), - new S3BlobStoreContextModule() { - @Override - protected void configure() { - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to("user"); - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)).to("key"); - bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)) - .to("http://localhost"); - bindConstant().annotatedWith( - Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); - bindConstant().annotatedWith( - Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); - super.configure(); - } - }); - } - - @Test - void testContextImplAndSingleton() { - Injector i = createInjector(); - BlobStoreContext context = i.getInstance(BlobStoreContext.class); - assertEquals(context.getClass(), BlobStoreContextImpl.class); - assertEquals(context, i.getInstance(BlobStoreContext.class)); - assertEquals(context.getAsyncBlobStore().getContext().getAsyncBlobStore(), context.getAsyncBlobStore()); - assertEquals(context.getBlobStore().getContext().getBlobStore(), context.getBlobStore()); - } - -} \ No newline at end of file diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java index 4981a8208d..f504285acb 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.s3.config; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -25,11 +26,10 @@ import static org.testng.Assert.assertFalse; import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; -import org.jclouds.Constants; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; -import org.jclouds.aws.s3.reference.S3Constants; +import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.http.functions.config.ParserModule; @@ -55,18 +55,8 @@ public class S3RestClientModuleTest { new AbstractModule() { @Override protected void configure() { - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to("user"); - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)).to("key"); - bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)) - .to("http://localhost"); - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_S3_SESSIONINTERVAL)).to("2"); - bindConstant().annotatedWith( - Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); + Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user", + "key").build(), "properties")); bind(UriBuilder.class).to(UriBuilderImpl.class); } }); diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/config/S3StubClientModule.java b/aws/core/src/test/java/org/jclouds/aws/s3/config/S3StubClientModule.java index b8af934f9f..e927e19ab7 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/config/S3StubClientModule.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/config/S3StubClientModule.java @@ -19,9 +19,11 @@ package org.jclouds.aws.s3.config; import java.net.URI; +import java.util.Set; import javax.inject.Singleton; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.s3.S3; import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3Client; @@ -33,6 +35,8 @@ import org.jclouds.rest.ConfiguresRestClient; import com.google.inject.AbstractModule; import com.google.inject.Provides; +import com.google.inject.TypeLiteral; +import com.google.inject.internal.ImmutableSet; /** * adds a stub alternative to invoking S3 @@ -47,6 +51,10 @@ public class S3StubClientModule extends AbstractModule { install(new TransientBlobStoreModule()); bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton(); bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("https://localhost/s3stub")); + bind(Region.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD); + bind(new TypeLiteral>() { + }).annotatedWith(S3.class).toInstance( + ImmutableSet.of(Region.US_STANDARD, Region.US_WEST_1, Region.EU_WEST_1)); } @Provides diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java index 2eaa0f4bf3..43ff890671 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.s3.filters; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; @@ -28,9 +29,8 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; -import org.jclouds.Constants; +import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.aws.s3.config.S3RestClientModule; -import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.config.ParserModule; @@ -144,18 +144,8 @@ public class RequestAuthorizeSignatureTest { new AbstractModule() { protected void configure() { - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to("foo"); - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)).to("bar"); - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_S3_SESSIONINTERVAL)).to("2"); - bindConstant().annotatedWith( - Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)) - .to("https://s3.amazonaws.com"); + Jsr330.bindProperties(binder(), checkNotNull( + new S3PropertiesBuilder("foo", "bar")).build()); bind(UriBuilder.class).to(UriBuilderImpl.class); } }); diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/internal/StubS3AsyncClient.java b/aws/core/src/test/java/org/jclouds/aws/s3/internal/StubS3AsyncClient.java index 237486ac49..41787d4a2f 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/internal/StubS3AsyncClient.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/internal/StubS3AsyncClient.java @@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; +import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Named; @@ -67,6 +68,9 @@ import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.concurrent.ConcurrentUtils; import org.jclouds.date.DateService; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; import org.jclouds.http.options.GetOptions; import com.google.common.base.Function; @@ -93,17 +97,20 @@ public class StubS3AsyncClient implements S3AsyncClient { private final ResourceToBucketList resource2BucketList; private final ExecutorService executorService; private final ConcurrentMap> containerToBlobs; + private final ConcurrentMap containerToLocation; @Inject private StubS3AsyncClient(TransientAsyncBlobStore blobStore, ConcurrentMap> containerToBlobs, - DateService dateService, S3Object.Factory objectProvider, Blob.Factory blobProvider, + ConcurrentMap containerToLocation, DateService dateService, + S3Object.Factory objectProvider, Blob.Factory blobProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object, BlobToObjectMetadata blob2ObjectMetadata, BucketToContainerListOptions bucket2ContainerListOptions, ResourceToBucketList resource2BucketList, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executorService) { this.containerToBlobs = containerToBlobs; + this.containerToLocation = containerToLocation; this.blobStore = blobStore; this.objectProvider = objectProvider; this.blobProvider = blobProvider; @@ -120,7 +127,6 @@ public class StubS3AsyncClient implements S3AsyncClient { public static final String TEST_ACL_ID = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c"; public static final String TEST_ACL_EMAIL = "james@misterm.org"; - private static Map bucketToLocation = new ConcurrentHashMap(); /** * An S3 item's "ACL" may be a {@link CannedAccessPolicy} or an {@link AccessControlList}. @@ -130,13 +136,14 @@ public class StubS3AsyncClient implements S3AsyncClient { public static final String DEFAULT_OWNER_ID = "abc123"; @Override - public ListenableFuture putBucketInRegion(Region region, String name, + public ListenableFuture putBucketInRegion(@Nullable Region region, String name, PutBucketOptions... optionsList) { + region = region == null ? Region.US_STANDARD : region; final PutBucketOptions options = (optionsList.length == 0) ? new PutBucketOptions() : optionsList[0]; - bucketToLocation.put(name, region); keyToAcl.put(name, options.getAcl()); - return blobStore.createContainerInLocation(region.value(), name); + return blobStore.createContainerInLocation(new LocationImpl(LocationScope.REGION, region + .value(), region.value(), null), name); } public ListenableFuture listBucket(final String name, @@ -309,7 +316,8 @@ public class StubS3AsyncClient implements S3AsyncClient { @Override public ListenableFuture getBucketLocation(String bucketName) { - return immediateFuture(bucketToLocation.get(bucketName)); + Location location = containerToLocation.get(bucketName); + return immediateFuture(Region.fromValue(location.getId())); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java index 70ab89b05c..93b1fbd976 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/services/BucketsLiveTest.java @@ -149,8 +149,9 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { public void testPublicReadAccessPolicy() throws Exception { String bucketName = getScratchContainerName(); try { - getApi().putBucketInRegion(Region.DEFAULT, bucketName, - withBucketAcl(CannedAccessPolicy.PUBLIC_READ)); + getApi() + .putBucketInRegion(null, bucketName, + withBucketAcl(CannedAccessPolicy.PUBLIC_READ)); AccessControlList acl = getApi().getBucketACL(bucketName); assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl.toString()); // TODO: I believe that the following should work based on the above acl assertion passing. @@ -175,9 +176,12 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest { } public void testDefaultBucketLocation() throws Exception { + String bucketName = getContainerName(); try { - assertEquals(Region.US_STANDARD, getApi().getBucketLocation(bucketName)); + Region location = getApi().getBucketLocation(bucketName); + assert location.equals(Region.US_STANDARD) : "bucket: " + bucketName + " location: " + + location; } finally { returnContainer(bucketName); } diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java index d4f5f71e08..16e9e6de7b 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.s3.util; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -29,8 +30,8 @@ import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; import org.jclouds.aws.domain.AWSError; +import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.aws.s3.config.S3RestClientModule; -import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.reference.S3Headers; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpException; @@ -66,15 +67,8 @@ public class S3UtilsTest { @Override protected void configure() { bind(ExecutorService.class).toInstance(Executors.newCachedThreadPool()); - // bind(new TypeLiteral>(){}).to - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to("user"); - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)).to("key"); - bindConstant().annotatedWith( - Jsr330.named(S3Constants.PROPERTY_S3_SESSIONINTERVAL)).to("2"); - bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)) - .to("https://s3.amazonaws.com"); + Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user", "key") + .build(), "properties")); bind(UriBuilder.class).to(UriBuilderImpl.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 index 4753d219af..e0fb3fe2de 100644 --- a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java @@ -64,7 +64,7 @@ public class SQSAsyncClientTest extends RestClientTest { Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", Region.class, Array .newInstance(ListQueuesOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, - Region.DEFAULT); + (Region) null); assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -82,8 +82,8 @@ public class SQSAsyncClientTest extends RestClientTest { 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")); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + ListQueuesOptions.Builder.queuePrefix("prefix")); assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -101,8 +101,8 @@ public class SQSAsyncClientTest extends RestClientTest { 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"); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "queueName"); assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -120,9 +120,8 @@ public class SQSAsyncClientTest extends RestClientTest { 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)); + GeneratedHttpRequest httpMethod = processor.createRequest(method, null, + "queueName", CreateQueueOptions.Builder.defaultVisibilityTimeout(45)); assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertHeadersEqual(httpMethod, @@ -178,11 +177,12 @@ public class SQSAsyncClientTest extends RestClientTest { @SuppressWarnings("unused") @Singleton @Provides + @SQS 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")); + return ImmutableMap. of(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/config/SQSRestClientModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java index ed22f932f1..9d6d821162 100644 --- 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 @@ -19,6 +19,7 @@ package org.jclouds.aws.sqs.config; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; @@ -28,12 +29,12 @@ import java.util.Map; import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; -import org.jclouds.Constants; 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.aws.sqs.SQS; +import org.jclouds.aws.sqs.SQSPropertiesBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.handlers.DelegatingErrorHandler; @@ -59,25 +60,8 @@ public class SQSRestClientModuleTest { 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); - bindConstant().annotatedWith( - Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); + Jsr330.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder("user", + "key").build(), "properties")); bind(UriBuilder.class).to(UriBuilderImpl.class); } }); @@ -91,11 +75,12 @@ public class SQSRestClientModuleTest { @Test void testRegions() { - Map regionMap = createInjector().getInstance(new Key>() { + Map regionMap = createInjector().getInstance(new Key>(SQS.class) { }); 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"))); + .create("https://queue.amazonaws.com"), Region.US_WEST_1, URI + .create("https://us-west-1.queue.amazonaws.com"), Region.EU_WEST_1, URI + .create("https://eu-west-1.queue.amazonaws.com"))); } @Test diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java index 33e4677b2f..5f48809f76 100644 --- a/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/xml/ListQueuesResponseHandlerTest.java @@ -35,6 +35,7 @@ import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; import org.jclouds.PerformanceTest; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ParseSax; @@ -85,6 +86,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest { @SuppressWarnings("unused") @Provides @Singleton + @SQS Map provideRegions() { return ImmutableMap. of(Region.EU_WEST_1, URI .create("https://eu-west-1.queue.amazonaws.com")); diff --git a/aws/demos/createandlistbuckets/src/main/java/org/jclouds/aws/s3/samples/MainApp.java b/aws/demos/createandlistbuckets/src/main/java/org/jclouds/aws/s3/samples/MainApp.java index 40beedae3e..a6087664b2 100755 --- a/aws/demos/createandlistbuckets/src/main/java/org/jclouds/aws/s3/samples/MainApp.java +++ b/aws/demos/createandlistbuckets/src/main/java/org/jclouds/aws/s3/samples/MainApp.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Map; -import org.jclouds.aws.domain.Region; import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3Client; import org.jclouds.blobstore.BlobStore; @@ -64,7 +63,7 @@ public class MainApp { // Create Container BlobStore blobStore = context.getBlobStore(); - blobStore.createContainerInLocation(Region.DEFAULT.toString(), containerName); + blobStore.createContainerInLocation(null, containerName); // Add Blob Blob blob = blobStore.newBlob("test"); 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 5e68dfd940..2e04a9d1a8 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 @@ -108,7 +108,7 @@ public class MainApp { try { String id = findInstanceByKeyName(client, name).getId(); System.out.printf("%d: %s terminating instance%n", System.currentTimeMillis(), id); - client.getInstanceServices().terminateInstancesInRegion(Region.DEFAULT, + client.getInstanceServices().terminateInstancesInRegion(null, findInstanceByKeyName(client, name).getId()); } catch (NoSuchElementException e) { } catch (Exception e) { @@ -117,14 +117,14 @@ public class MainApp { try { System.out.printf("%d: %s deleting keypair%n", System.currentTimeMillis(), name); - client.getKeyPairServices().deleteKeyPairInRegion(Region.DEFAULT, name); + client.getKeyPairServices().deleteKeyPairInRegion(null, name); } catch (Exception e) { e.printStackTrace(); } try { System.out.printf("%d: %s deleting group%n", System.currentTimeMillis(), name); - client.getSecurityGroupServices().deleteSecurityGroupInRegion(Region.DEFAULT, name); + client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, name); } catch (Exception e) { e.printStackTrace(); } @@ -144,16 +144,16 @@ public class MainApp { static void createSecurityGroupAndAuthorizePorts(EC2Client client, String name) { System.out.printf("%d: creating security group: %s%n", System.currentTimeMillis(), name); - client.getSecurityGroupServices().createSecurityGroupInRegion(Region.DEFAULT, name, name); + client.getSecurityGroupServices().createSecurityGroupInRegion(null, name, name); for (int port : new int[] { 80, 8080, 443, 22 }) { - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(Region.DEFAULT, + client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, name, IpProtocol.TCP, port, port, "0.0.0.0/0"); } } static KeyPair createKeyPair(EC2Client client, String name) { System.out.printf("%d: creating keypair: %s%n", System.currentTimeMillis(), name); - return client.getKeyPairServices().createKeyPairInRegion(Region.DEFAULT, name); + return client.getKeyPairServices().createKeyPairInRegion(null, name); } static RunningInstance runInstance(EC2Client client, String securityGroupName, String keyPairName) { @@ -164,7 +164,7 @@ public class MainApp { .build(OsFamily.UNIX); System.out.printf("%d: running instance%n", System.currentTimeMillis()); - Reservation reservation = client.getInstanceServices().runInstancesInRegion(Region.DEFAULT, + Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow ec2 to chose an availability zone "ami-ccf615a5", // alestic ami allows auto-invoke of user data scripts 1, // minimum instances @@ -214,7 +214,7 @@ public class MainApp { private static RunningInstance findInstanceById(EC2Client client, String instanceId) { // search my account for the instance I just created Set reservations = client.getInstanceServices().describeInstancesInRegion( - Region.DEFAULT, instanceId); // last parameter (ids) narrows the search + null, instanceId); // last parameter (ids) narrows the search // since we refined by instanceId there should only be one instance return Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); @@ -223,7 +223,7 @@ public class MainApp { private static RunningInstance findInstanceByKeyName(EC2Client client, final String keyName) { // search my account for the instance I just created Set reservations = client.getInstanceServices().describeInstancesInRegion( - Region.DEFAULT); + null); // extract all the instances from all reservations Set allInstances = Sets.newHashSet(); diff --git a/aws/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java b/aws/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java index 420e1f9dca..717420add8 100755 --- a/aws/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java +++ b/aws/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.SortedSet; -import org.jclouds.aws.domain.Region; import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.S3ContextFactory; import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore; @@ -121,7 +120,7 @@ public class JCloudsS3Service extends S3Service { throw new UnsupportedOperationException("Bucket ACL is not yet supported"); try { - if (connection.putBucketInRegion(Region.DEFAULT, bucketName)) { + if (connection.putBucketInRegion(null, bucketName)) { // Bucket created. } } catch (Exception e) { diff --git a/azure/src/main/java/org/jclouds/azure/storage/blob/AzureBlobClient.java b/azure/src/main/java/org/jclouds/azure/storage/blob/AzureBlobClient.java index c30285a9e1..e5c4c98197 100644 --- a/azure/src/main/java/org/jclouds/azure/storage/blob/AzureBlobClient.java +++ b/azure/src/main/java/org/jclouds/azure/storage/blob/AzureBlobClient.java @@ -45,7 +45,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @author Adrian Cole */ -@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) public interface AzureBlobClient { public org.jclouds.azure.storage.blob.domain.AzureBlob newBlob(); diff --git a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureAsyncBlobStore.java b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureAsyncBlobStore.java index e7c5e523ce..eeb3839113 100644 --- a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureAsyncBlobStore.java +++ b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureAsyncBlobStore.java @@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.Futures.compose; import static org.jclouds.azure.storage.options.ListOptions.Builder.includeMetadata; +import java.util.Map; import java.util.concurrent.ExecutorService; import javax.inject.Inject; @@ -52,6 +53,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.domain.Location; import org.jclouds.http.options.GetOptions; import com.google.common.base.Function; @@ -75,12 +77,14 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore { @Inject AzureAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + Location defaultLocation, Map locations, + AzureBlobAsyncClient async, ContainerToResourceMetadata container2ResourceMd, ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions, ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob, BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions) { - super(context, blobUtils, service); + super(context, blobUtils, service, defaultLocation, locations); this.async = checkNotNull(async, "async"); this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd"); this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions, @@ -130,7 +134,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore { * container name */ @Override - public ListenableFuture createContainerInLocation(String location, String container) { + public ListenableFuture createContainerInLocation(Location location, String container) { return async.createContainer(container); } diff --git a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java index 50eeda6db9..90591875fe 100644 --- a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java +++ b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java @@ -21,6 +21,8 @@ package org.jclouds.azure.storage.blob.blobstore; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.azure.storage.options.ListOptions.Builder.includeMetadata; +import java.util.Map; + import javax.inject.Inject; import javax.inject.Singleton; @@ -44,6 +46,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.domain.Location; import org.jclouds.http.options.GetOptions; import com.google.common.base.Function; @@ -64,13 +67,14 @@ public class AzureBlobStore extends BaseBlobStore { private final BlobToHttpGetOptions blob2ObjectGetOptions; @Inject - AzureBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, AzureBlobClient sync, + AzureBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, Location defaultLocation, + Map locations, AzureBlobClient sync, ContainerToResourceMetadata container2ResourceMd, ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions, ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob, BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions) { - super(context, blobUtils); + super(context, blobUtils, defaultLocation, locations); this.sync = checkNotNull(sync, "sync"); this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd"); this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions, @@ -118,7 +122,7 @@ public class AzureBlobStore extends BaseBlobStore { * container name */ @Override - public boolean createContainerInLocation(String location, String container) { + public boolean createContainerInLocation(Location location, String container) { return sync.createContainer(container); } diff --git a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreContextModule.java b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreContextModule.java index 47971e7d0e..def0ca8288 100755 --- a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreContextModule.java +++ b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreContextModule.java @@ -18,6 +18,10 @@ */ package org.jclouds.azure.storage.blob.blobstore.config; +import java.util.Map; + +import javax.inject.Singleton; + import org.jclouds.azure.storage.blob.AzureBlobAsyncClient; import org.jclouds.azure.storage.blob.AzureBlobClient; import org.jclouds.azure.storage.blob.blobstore.AzureAsyncBlobStore; @@ -31,7 +35,12 @@ import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -55,4 +64,15 @@ public class AzureBlobStoreContextModule extends AzureBlobContextModule { bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class); } + @Provides + @Singleton + Location getLocation() { + return new LocationImpl(LocationScope.ZONE, "UNKNOWN", "TODO", null); + } + + @Provides + @Singleton + Map provideLocations(Location location) { + return ImmutableMap.of(location.getId(), location); + } } diff --git a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ContainerToResourceMetadata.java b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ContainerToResourceMetadata.java index 58af490763..f3eeb7683e 100644 --- a/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ContainerToResourceMetadata.java +++ b/azure/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ContainerToResourceMetadata.java @@ -18,6 +18,7 @@ */ package org.jclouds.azure.storage.blob.blobstore.functions; +import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.azure.storage.blob.domain.ContainerProperties; @@ -25,6 +26,7 @@ import org.jclouds.blobstore.domain.MutableStorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl; +import org.jclouds.domain.Location; import com.google.common.base.Function; @@ -33,9 +35,17 @@ import com.google.common.base.Function; */ @Singleton public class ContainerToResourceMetadata implements Function { + private Location defaultLocation; + + @Inject + ContainerToResourceMetadata(Location defaultLocation) { + this.defaultLocation = defaultLocation; + } + public StorageMetadata apply(ContainerProperties from) { MutableStorageMetadata to = new MutableStorageMetadataImpl(); to.setName(from.getName()); + to.setLocation(defaultLocation); to.setETag(from.getETag()); to.setLastModified(from.getLastModified()); to.setUri(from.getUrl()); diff --git a/azure/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobAsyncClient.java b/azure/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobAsyncClient.java index a13850e11b..627b5f017b 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobAsyncClient.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobAsyncClient.java @@ -94,7 +94,7 @@ public class StubAzureBlobAsyncClient implements AzureBlobAsyncClient { public ListenableFuture createContainer(String container, CreateContainerOptions... options) { - return blobStore.createContainerInLocation("default", container); + return blobStore.createContainerInLocation(null, container); } public ListenableFuture createRootContainer(CreateContainerOptions... options) { diff --git a/blobstore/src/main/clojure/org/jclouds/blobstore.clj b/blobstore/src/main/clojure/org/jclouds/blobstore.clj index f106fd7f30..99c5c2c94a 100644 --- a/blobstore/src/main/clojure/org/jclouds/blobstore.clj +++ b/blobstore/src/main/clojure/org/jclouds/blobstore.clj @@ -32,6 +32,7 @@ Here's a quick example of how to view blob resources in rackspace (def blobstore-name \"cloudfiles\") (with-blobstore [blobstore-name user password] + (pprint (locations)) (pprint (containers)) (pprint (blobs blobstore your_container_name))) @@ -130,14 +131,20 @@ Options can also be specified for extension modules (.list blobstore container-name list-options)) (apply list-container *blobstore* blobstore args))) +(defn locations + "Retrieve the available container locations for the blobstore context." + ([] (locations *blobstore*)) + ([#^BlobStore blobstore] + (seq-from-immutable-set (.getLocations blobstore)))) + (defn create-container "Create a container." ([container-name] - (create-container container-name "default" *blobstore*)) - ([container-name location-name] - (create-container container-name location-name *blobstore*)) - ([container-name location-name blobstore] - (.createContainerInLocation blobstore location-name container-name))) + (create-container container-name nil *blobstore*)) + ([container-name location] + (create-container container-name location *blobstore*)) + ([container-name location blobstore] + (.createContainerInLocation blobstore location container-name))) (defn clear-container "Clear a container." diff --git a/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java index 792b245aaf..3790a6a199 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java @@ -18,12 +18,17 @@ */ package org.jclouds.blobstore; +import java.util.Map; + +import javax.annotation.Nullable; + import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.ListContainerOptions; +import org.jclouds.domain.Location; import com.google.common.util.concurrent.ListenableFuture; @@ -43,6 +48,11 @@ public interface AsyncBlobStore { */ Blob newBlob(String name); + /** + * @see BlobStore#getLocations + */ + ListenableFuture> getLocations(); + /** * @see BlobStore#list */ @@ -54,9 +64,9 @@ public interface AsyncBlobStore { ListenableFuture containerExists(String container); /** - * @see BlobStore#createContainerInLocation(String, String) + * @see BlobStore#createContainerInLocation(Location, String) */ - ListenableFuture createContainerInLocation(String location, String container); + ListenableFuture createContainerInLocation(@Nullable Location location, String container); /** * @see BlobStore#list(String) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java index ab50625d71..53d55b46f5 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java @@ -18,12 +18,17 @@ */ package org.jclouds.blobstore; +import java.util.Map; + +import javax.annotation.Nullable; + import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.ListContainerOptions; +import org.jclouds.domain.Location; /** * Synchronous access to a BlobStore such as Amazon S3 @@ -44,6 +49,14 @@ public interface BlobStore { */ Blob newBlob(String name); + /** + * The get locations command returns all the valid locations for containers. A location has a scope, + * which is typically region or zone. A region is a general area, like eu-west, where a zone is + * similar to a datacenter. If a location has a parent, that implies it is within that location. + * For example a location can be a rack, whose parent is likely to be a zone. + */ + Map getLocations(); + /** * Lists all root-level resources available to the account. */ @@ -67,12 +80,12 @@ public interface BlobStore { * * @param location * some blobstores allow you to specify a location, such as US-EAST, for where this - * container will exist. + * container will exist. null will choose a default location * @param container * namespace. Typically constrained to lowercase alpha-numeric and hyphens. * @return true if the container was created, false if it already existed. */ - boolean createContainerInLocation(String location, String container); + boolean createContainerInLocation(@Nullable Location location, String container); /** * Lists all resources in a container non-recursive. diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index 10129b589e..eda0fdfb78 100755 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -67,6 +67,7 @@ import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy; import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.date.DateService; +import org.jclouds.domain.Location; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; @@ -97,6 +98,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { protected final DateService dateService; protected final EncryptionService encryptionService; protected final ConcurrentMap> containerToBlobs; + protected final ConcurrentMap containerToLocation; protected final HttpGetOptionsListToGetOptions httpGetOptionsConverter; protected final IfDirectoryReturnNameStrategy ifDirectoryReturnName; protected final Factory blobFactory; @@ -105,17 +107,21 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { protected TransientAsyncBlobStore(BlobStoreContext context, DateService dateService, EncryptionService encryptionService, ConcurrentMap> containerToBlobs, + ConcurrentMap containerToLocation, HttpGetOptionsListToGetOptions httpGetOptionsConverter, IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobStoreUtils blobUtils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) { - super(context, blobUtils, service); + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + Location defaultLocation, Map locations) { + super(context, blobUtils, service, defaultLocation, locations); this.blobFactory = blobFactory; this.dateService = dateService; this.encryptionService = encryptionService; this.containerToBlobs = containerToBlobs; + this.containerToLocation = containerToLocation; this.httpGetOptionsConverter = httpGetOptionsConverter; this.ifDirectoryReturnName = ifDirectoryReturnName; + getContainerToLocation().put("stub", defaultLocation); getContainerToBlobs().put("stub", new ConcurrentHashMap()); } @@ -333,6 +339,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { MutableStorageMetadata cmd = create(); cmd.setName(name); cmd.setType(StorageType.CONTAINER); + cmd.setLocation(getContainerToLocation().get(name)); return cmd; } }), null)); @@ -346,10 +353,11 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { * {@inheritDoc} */ @Override - public ListenableFuture createContainerInLocation(final String location, + public ListenableFuture createContainerInLocation(final Location location, final String name) { if (!getContainerToBlobs().containsKey(name)) { getContainerToBlobs().put(name, new ConcurrentHashMap()); + getContainerToLocation().put(name, location != null ? location : defaultLocation); } return immediateFuture(getContainerToBlobs().containsKey(name)); } @@ -632,4 +640,8 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { return getContainerToBlobs().containsKey(container); } + public ConcurrentMap getContainerToLocation() { + return containerToLocation; + } + } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java index de193cca01..dd45cb28f8 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java @@ -13,6 +13,9 @@ import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.internal.SyncProxy; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; import org.jclouds.lifecycle.Closer; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; @@ -38,10 +41,9 @@ public class TransientBlobStoreContextModule extends AbstractModule { install(new BlobStoreMapModule()); bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT); bind(AsyncBlobStore.class).to(TransientAsyncBlobStore.class).asEagerSingleton(); - bind(BlobStoreContext.class) - .to( - new TypeLiteral>() { - }).in(Scopes.SINGLETON); + bind(BlobStoreContext.class).to( + new TypeLiteral>() { + }).in(Scopes.SINGLETON); } @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @@ -49,6 +51,12 @@ public class TransientBlobStoreContextModule extends AbstractModule { } + @Provides + @Singleton + Location provideDefaultLocation() { + return new LocationImpl(LocationScope.ZONE, "default", "description", null); + } + @Provides @Singleton public BlobStore provideClient(AsyncBlobStore client) throws IllegalArgumentException, diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreModule.java b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreModule.java index ecab213026..70861548a7 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreModule.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreModule.java @@ -18,15 +18,21 @@ */ package org.jclouds.blobstore.config; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import javax.inject.Singleton; + import org.jclouds.Constants; import org.jclouds.blobstore.TransientAsyncBlobStore; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.domain.Location; import org.jclouds.util.Jsr330; +import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; +import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; @@ -34,13 +40,22 @@ public class TransientBlobStoreModule extends AbstractModule { // must be singleton for all threads and all objects or tests may fail; static final ConcurrentHashMap> map = new ConcurrentHashMap>(); + static final ConcurrentHashMap containerToLocation = new ConcurrentHashMap(); @Override protected void configure() { bind(new TypeLiteral>>() { }).toInstance(map); + bind(new TypeLiteral>() { + }).toInstance(containerToLocation); bind(TransientAsyncBlobStore.class).in(Scopes.SINGLETON); bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to(0); bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to(0); } + + @Provides + @Singleton + Map provideLocations(Location defaultLocation) { + return ImmutableMap. of(defaultLocation.getId(), defaultLocation); + } } \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java index 0f42e634b0..e522c7dea0 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java @@ -24,6 +24,7 @@ import static com.google.common.util.concurrent.Futures.immediateFuture; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable; +import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; @@ -40,6 +41,7 @@ import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.internal.BlobStoreUtilsImpl; +import org.jclouds.domain.Location; import org.jclouds.util.Utils; import com.google.common.base.Function; @@ -55,13 +57,18 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore { protected final BlobStoreContext context; protected final BlobStoreUtils blobUtils; protected final ExecutorService service; + protected final Location defaultLocation; + protected final Map locations; @Inject protected BaseAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + Location defaultLocation, Map locations) { this.context = checkNotNull(context, "context"); this.blobUtils = checkNotNull(blobUtils, "blobUtils"); this.service = checkNotNull(service, "service"); + this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); + this.locations = checkNotNull(locations, "locations"); } @Override @@ -263,5 +270,10 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore { } } + @Override + public ListenableFuture> getLocations() { + return immediateFuture(locations); + } + protected abstract boolean deleteAndVerifyContainerGone(String container); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java index d1b2e855bd..dcbee8955f 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java @@ -21,6 +21,8 @@ package org.jclouds.blobstore.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; +import java.util.Map; + import javax.inject.Inject; import org.jclouds.blobstore.BlobStore; @@ -32,6 +34,7 @@ import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.internal.BlobStoreUtilsImpl; +import org.jclouds.domain.Location; import org.jclouds.util.Utils; import com.google.common.base.Supplier; @@ -44,11 +47,16 @@ public abstract class BaseBlobStore implements BlobStore { protected final BlobStoreContext context; protected final BlobStoreUtils blobUtils; + protected final Location defaultLocation; + protected final Map locations; @Inject - protected BaseBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils) { + protected BaseBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, + Location defaultLocation, Map locations) { this.context = checkNotNull(context, "context"); this.blobUtils = checkNotNull(blobUtils, "blobUtils"); + this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); + this.locations = checkNotNull(locations, "locations"); } @Override @@ -204,5 +212,10 @@ public abstract class BaseBlobStore implements BlobStore { } } + @Override + public Map getLocations() { + return locations; + } + protected abstract boolean deleteAndVerifyContainerGone(String container); } diff --git a/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj b/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj index 0c56230bc3..6c85903352 100644 --- a/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj +++ b/blobstore/src/test/clojure/org/jclouds/blobstore_test.clj @@ -50,6 +50,10 @@ (is (create-container "fred")) (is (container-exists? "fred"))) +(deftest locations-test + (is (not (empty? (locations)))) + (is (create-container "fred" (first (locations))))) + (deftest containers-test (is (empty? (containers))) (is (create-container "fred")) diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java index 9a96d01424..365c801c60 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java @@ -231,7 +231,7 @@ public class BaseBlobStoreIntegrationTest { protected static void createContainerAndEnsureEmpty(BlobStoreContext context, final String containerName) throws InterruptedException { - context.getBlobStore().createContainerInLocation("default", containerName); + context.getBlobStore().createContainerInLocation(null, containerName); if (context.getConsistencyModel() == ConsistencyModel.EVENTUAL) Thread.sleep(1000); context.getBlobStore().clearContainer(containerName); diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java index 130ad6d04d..98b67467a4 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java @@ -56,19 +56,20 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest { public void testPutTwiceIsOkAndDoesntOverwrite() throws InterruptedException { String containerName = getContainerName(); try { - context.getBlobStore().createContainerInLocation("default", containerName); + context.getBlobStore().createContainerInLocation(null, containerName); Blob blob = context.getBlobStore().newBlob("hello"); blob.setPayload(TEST_STRING); context.getBlobStore().putBlob(containerName, blob); - context.getBlobStore().createContainerInLocation("default", containerName); + context.getBlobStore().createContainerInLocation(null, containerName); assertEquals(context.getBlobStore().countBlobs(containerName), 1); } finally { returnContainer(containerName); } } + @Test(groups = { "integration", "live" }) public void testWithDetails() throws InterruptedException { String key = "hello"; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseServiceIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseServiceIntegrationTest.java index 7ee309f638..2da053041c 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseServiceIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseServiceIntegrationTest.java @@ -20,10 +20,15 @@ package org.jclouds.blobstore.integration.internal; import java.util.Set; +import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl; +import org.jclouds.domain.Location; import org.testng.annotations.Test; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + /** * * @author Adrian Cole @@ -36,4 +41,31 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest { assert !list.contains(new MutableStorageMetadataImpl()); } + @Test(groups = { "integration", "live" }) + public void testAllLocations() throws InterruptedException { + for (final Location location : context.getBlobStore().getLocations().values()) { + final String containerName = getScratchContainerName(); + try { + + context.getBlobStore().createContainerInLocation(location, containerName); + assertConsistencyAware(new Runnable() { + + @Override + public void run() { + PageSet list = context.getBlobStore().list(); + assert Iterables.any(list, new Predicate() { + public boolean apply(StorageMetadata md) { + return containerName.equals(md.getName()) + && location.equals(md.getLocation()); + } + }) : String.format("container %s/%s not found in list %s", location, + containerName, list); + } + + }); + } finally { + recycleContainer(containerName); + } + } + } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java index 4a9d5eabb9..795cfe9b94 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java @@ -129,9 +129,9 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat @Override public String toString() { return "[id=" + getId() + ", tag=" + getTag() + ", name=" + getName() + ", location=" - + getLocation() + ", uri=" + getUri() + ", userMetadata=" + getUserMetadata() - + ", state=" + getState() + ", privateAddresses=" + privateAddresses - + ", publicAddresses=" + publicAddresses + "]"; + + getLocation() + ", uri=" + getUri() + ", image=" + getImage() + ", userMetadata=" + + getUserMetadata() + ", state=" + getState() + ", privateAddresses=" + + privateAddresses + ", publicAddresses=" + publicAddresses + "]"; } @Override @@ -141,6 +141,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode()); result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); result = prime * result + ((tag == null) ? 0 : tag.hashCode()); + result = prime * result + ((image == null) ? 0 : image.hashCode()); return result; } @@ -168,6 +169,11 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat return false; } else if (!tag.equals(other.tag)) return false; + if (image == null) { + if (other.image != null) + return false; + } else if (!image.equals(other.image)) + return false; return true; } diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index c3266c12be..7b2419c28c 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -64,6 +64,7 @@ import org.testng.annotations.Test; import com.google.common.base.Charsets; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -288,26 +289,26 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") public void testGet() throws Exception { - Set metadataSet = Sets.newHashSet(client.getNodesWithTag(tag) - .values()); + Set metadataSet = Sets.newHashSet(Iterables.filter(client + .getNodesWithTag(tag).values(), Predicates.not(new Predicate() { + @Override + public boolean apply(NodeMetadata input) { + return input.getState() == NodeState.TERMINATED; + } + }))); for (NodeMetadata node : nodes) { metadataSet.remove(node); NodeMetadata metadata = client.getNodeMetadata(node); assertEquals(metadata.getId(), node.getId()); assertEquals(metadata.getTag(), node.getTag()); - assertEquals(metadata.getLocation(), template.getLocation()); + assertLocationSameOrChild(metadata.getLocation(), template.getLocation()); assertEquals(metadata.getImage(), template.getImage()); assertEquals(metadata.getState(), NodeState.RUNNING); assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses()); assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses()); } - assert Iterables.all(metadataSet, new Predicate() { - @Override - public boolean apply(NodeMetadata input) { - return input.getState() == NodeState.TERMINATED; - } - }) : metadataSet; - + assert metadataSet.size() == 0 : String.format( + "nodes left in set: [%s] which didn't match set: [%s]", metadataSet, nodes); } @Test(enabled = true, dependsOnMethods = "testGet") diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 73909c1a1f..dce5855b72 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -611,9 +611,12 @@ public class RestAnnotationProcessor { .next(); int index = map.keySet().iterator().next(); Function parser = injector.getInstance(annotation.parser()); - Object arg = checkNotNull(args[index], String.format("argument at index %d on method %s", - index, method)); - return parser.apply(arg); + try { + return parser.apply(args[index]); + } catch (NullPointerException e) { + logger.error("argument at index %d on method %s", index, method); + throw e; + } } return null; } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java index e275655bf1..1b0e16ac83 100755 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java @@ -18,12 +18,10 @@ */ package org.jclouds.gogrid.compute.config; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.domain.OsFamily.CENTOS; import java.net.InetAddress; import java.net.UnknownHostException; -import java.security.SecureRandom; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -45,7 +43,6 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; -import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.domain.internal.SizeImpl; @@ -67,13 +64,11 @@ import org.jclouds.domain.internal.LocationImpl; import org.jclouds.gogrid.GoGridAsyncClient; import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata; +import org.jclouds.gogrid.compute.strategy.GoGridAddNodeWithTagStrategy; import org.jclouds.gogrid.config.GoGridContextModule; -import org.jclouds.gogrid.domain.Ip; -import org.jclouds.gogrid.domain.IpType; import org.jclouds.gogrid.domain.PowerCommand; import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.ServerImage; -import org.jclouds.gogrid.options.GetIpListOptions; import org.jclouds.gogrid.predicates.ServerLatestJobCompleted; import org.jclouds.gogrid.util.GoGridUtils; import org.jclouds.logging.Logger; @@ -84,7 +79,6 @@ import org.jclouds.ssh.SshClient; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -122,62 +116,6 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule { return "%s-%s"; } - @Singleton - public static class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy { - private final GoGridClient client; - private final Function sizeToRam; - private final Function serverToNodeMetadata; - private RetryablePredicate serverLatestJobCompleted; - private RetryablePredicate serverLatestJobCompletedShort; - - @Inject - protected GoGridAddNodeWithTagStrategy(GoGridClient client, - Function serverToNodeMetadata, Function sizeToRam) { - this.client = client; - this.serverToNodeMetadata = serverToNodeMetadata; - this.sizeToRam = sizeToRam; - this.serverLatestJobCompleted = new RetryablePredicate( - new ServerLatestJobCompleted(client.getJobServices()), 800, 20, TimeUnit.SECONDS); - this.serverLatestJobCompletedShort = new RetryablePredicate( - new ServerLatestJobCompleted(client.getJobServices()), 60, 20, TimeUnit.SECONDS); - } - - @Override - public NodeMetadata execute(String tag, String name, Template template) { - Server addedServer = null; - boolean notStarted = true; - int numOfRetries = 20; - // lock-free consumption of a shared resource: IP address pool - while (notStarted) { // TODO: replace with Predicate-based thread collision avoidance for - // simplicity - Set availableIps = client.getIpServices().getIpList( - new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC)); - if (availableIps.size() == 0) - throw new RuntimeException("No public IPs available on this account."); - int ipIndex = new SecureRandom().nextInt(availableIps.size()); - Ip availableIp = Iterables.get(availableIps, ipIndex); - try { - addedServer = client.getServerServices().addServer(name, - checkNotNull(template.getImage().getId()), - sizeToRam.apply(template.getSize()), availableIp.getIp()); - notStarted = false; - } catch (Exception e) { - if (--numOfRetries == 0) - Throwables.propagate(e); - notStarted = true; - } - } - serverLatestJobCompleted.apply(addedServer); - - client.getServerServices().power(addedServer.getName(), PowerCommand.START); - serverLatestJobCompletedShort.apply(addedServer); - - addedServer = Iterables.getOnlyElement(client.getServerServices().getServersByName( - addedServer.getName())); - return serverToNodeMetadata.apply(addedServer); - } - } - @Singleton public static class GoGridRebootNodeStrategy implements RebootNodeStrategy { private final GoGridClient client; diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java index 75550c6aea..1a8e511ea4 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java @@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.InetAddress; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.inject.Inject; import javax.inject.Singleton; @@ -36,7 +38,6 @@ import org.jclouds.domain.Location; import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.services.GridServerClient; -import com.google.common.base.CharMatcher; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -47,6 +48,8 @@ import com.google.common.collect.ImmutableSet; */ @Singleton public class ServerToNodeMetadata implements Function { + public static final Pattern ALL_BEFORE_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+"); + private final Map serverStateToNodeState; private final GridServerClient client; private final Location location; @@ -63,7 +66,8 @@ public class ServerToNodeMetadata implements Function { @Override public NodeMetadata apply(Server from) { - String tag = CharMatcher.JAVA_LETTER.retainFrom(from.getName()); + Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName()); + final String tag = matcher.find() ? matcher.group(1) : null; Set ipSet = ImmutableSet.of(from.getIp().getIp()); NodeState state = serverStateToNodeState.get(from.getState().getName()); Credentials creds = client.getServerCredentialsList().get(from.getName()); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridAddNodeWithTagStrategy.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridAddNodeWithTagStrategy.java new file mode 100644 index 0000000000..2cef5bd0ed --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridAddNodeWithTagStrategy.java @@ -0,0 +1,110 @@ +/** + * + * Copyright (C) 2010 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.gogrid.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.security.SecureRandom; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.strategy.AddNodeWithTagStrategy; +import org.jclouds.gogrid.GoGridClient; +import org.jclouds.gogrid.domain.Ip; +import org.jclouds.gogrid.domain.IpType; +import org.jclouds.gogrid.domain.PowerCommand; +import org.jclouds.gogrid.domain.Server; +import org.jclouds.gogrid.options.GetIpListOptions; +import org.jclouds.gogrid.predicates.ServerLatestJobCompleted; +import org.jclouds.predicates.RetryablePredicate; + +import com.google.common.base.Function; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * @author Oleksiy Yarmula + */ +@Singleton +public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy { + private final GoGridClient client; + private final Function sizeToRam; + private final Function serverToNodeMetadata; + private RetryablePredicate serverLatestJobCompleted; + private RetryablePredicate serverLatestJobCompletedShort; + + @Inject + protected GoGridAddNodeWithTagStrategy(GoGridClient client, + Function serverToNodeMetadata, Function sizeToRam) { + this.client = client; + this.serverToNodeMetadata = serverToNodeMetadata; + this.sizeToRam = sizeToRam; + this.serverLatestJobCompleted = new RetryablePredicate(new ServerLatestJobCompleted( + client.getJobServices()), 800, 20, TimeUnit.SECONDS); + this.serverLatestJobCompletedShort = new RetryablePredicate( + new ServerLatestJobCompleted(client.getJobServices()), 60, 20, TimeUnit.SECONDS); + } + + @Override + public NodeMetadata execute(String tag, String name, Template template) { + Server addedServer = null; + boolean notStarted = true; + int numOfRetries = 20; + // lock-free consumption of a shared resource: IP address pool + while (notStarted) { // TODO: replace with Predicate-based thread collision avoidance for + // simplicity + Set availableIps = client.getIpServices().getIpList( + new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC)); + if (availableIps.size() == 0) + throw new RuntimeException("No public IPs available on this account."); + int ipIndex = new SecureRandom().nextInt(availableIps.size()); + Ip availableIp = Iterables.get(availableIps, ipIndex); + try { + addedServer = addServer(name, template, availableIp); + notStarted = false; + } catch (Exception e) { + if (--numOfRetries == 0) + Throwables.propagate(e); + notStarted = true; + } + } + serverLatestJobCompleted.apply(addedServer); + + client.getServerServices().power(addedServer.getName(), PowerCommand.START); + serverLatestJobCompletedShort.apply(addedServer); + + addedServer = Iterables.getOnlyElement(client.getServerServices().getServersByName( + addedServer.getName())); + return serverToNodeMetadata.apply(addedServer); + } + + private Server addServer(String name, Template template, Ip availableIp) { + Server addedServer; + addedServer = client.getServerServices().addServer(name, + checkNotNull(template.getImage().getId()), + sizeToRam.apply(template.getSize()), availableIp.getIp()); + return addedServer; + } +} \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java index 2ee01da79b..e0bb384599 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java @@ -38,7 +38,7 @@ public class ServerToNodeMetadataTest { Server server = createMock(Server.class); expect(server.getId()).andReturn(1000l).atLeastOnce(); - expect(server.getName()).andReturn("tag").atLeastOnce(); + expect(server.getName()).andReturn("tag-ff").atLeastOnce(); expect(server.getState()).andReturn(new Option("RUNNING")).atLeastOnce(); expect(serverStateToNodeState.get("RUNNING")).andReturn(NodeState.RUNNING); @@ -46,7 +46,7 @@ public class ServerToNodeMetadataTest { Map credentialsMap = createMock(Map.class); expect(client.getServerCredentialsList()).andReturn(credentialsMap); - expect(credentialsMap.get("tag")).andReturn(new Credentials("user", "pass")); + expect(credentialsMap.get("tag-ff")).andReturn(new Credentials("user", "pass")); expect(server.getIp()).andReturn( new Ip(InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }))); @@ -55,11 +55,9 @@ public class ServerToNodeMetadataTest { expect(server.getImage()).andReturn(image).atLeastOnce(); expect(image.getId()).andReturn(2000l).atLeastOnce(); - org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); expect(images.get("2000")).andReturn(jcImage); - - + replay(client); replay(serverStateToNodeState); replay(server); diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java index 96e02f3c19..4e4b4add64 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java @@ -49,7 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @author Adrian Cole */ -@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) public interface CloudFilesClient { CFObject newCFObject(); @@ -113,7 +113,6 @@ public interface CloudFilesClient { boolean deleteContainerIfEmpty(String container); - @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) PageSet listObjects(String container, ListContainerOptions... options); boolean containerExists(String container); diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java index 6bcd0d7303..4fdca1c3bd 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java @@ -21,6 +21,7 @@ package org.jclouds.rackspace.cloudfiles.blobstore; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.Futures.compose; +import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -41,6 +42,7 @@ import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.domain.Location; import org.jclouds.http.options.GetOptions; import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient; import org.jclouds.rackspace.cloudfiles.CloudFilesClient; @@ -78,14 +80,16 @@ public class CloudFilesAsyncBlobStore extends BaseAsyncBlobStore { @Inject CloudFilesAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, CloudFilesClient sync, - CloudFilesAsyncClient async, ContainerToResourceMetadata container2ResourceMd, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + Location defaultLocation, Map locations, + CloudFilesClient sync, CloudFilesAsyncClient async, + ContainerToResourceMetadata container2ResourceMd, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, Provider fetchBlobMetadataProvider) { - super(context, blobUtils, service); + super(context, blobUtils, service, defaultLocation, locations); this.sync = sync; this.async = async; this.container2ResourceMd = container2ResourceMd; @@ -130,7 +134,7 @@ public class CloudFilesAsyncBlobStore extends BaseAsyncBlobStore { * Note that location is currently ignored. */ @Override - public ListenableFuture createContainerInLocation(String location, String container) { + public ListenableFuture createContainerInLocation(Location location, String container) { return async.createContainer(container); } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java index b82b544547..14ba6ffe43 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java @@ -20,6 +20,7 @@ package org.jclouds.rackspace.cloudfiles.blobstore; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -37,6 +38,7 @@ import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.domain.Location; import org.jclouds.http.options.GetOptions; import org.jclouds.rackspace.cloudfiles.CloudFilesClient; import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; @@ -67,14 +69,15 @@ public class CloudFilesBlobStore extends BaseBlobStore { private final Provider fetchBlobMetadataProvider; @Inject - CloudFilesBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, CloudFilesClient sync, - ContainerToResourceMetadata container2ResourceMd, + CloudFilesBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, + Location defaultLocation, Map locations, + CloudFilesClient sync, ContainerToResourceMetadata container2ResourceMd, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, Provider fetchBlobMetadataProvider) { - super(context, blobUtils); + super(context, blobUtils, defaultLocation, locations); this.sync = sync; this.container2ResourceMd = container2ResourceMd; this.container2ContainerListOptions = container2ContainerListOptions; @@ -121,7 +124,7 @@ public class CloudFilesBlobStore extends BaseBlobStore { * container name */ @Override - public boolean createContainerInLocation(String location, String container) { + public boolean createContainerInLocation(Location location, String container) { return sync.createContainer(container); } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceMetadata.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceMetadata.java index 8a1b5b7393..037ac0a731 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceMetadata.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceMetadata.java @@ -18,12 +18,14 @@ */ package org.jclouds.rackspace.cloudfiles.blobstore.functions; +import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.blobstore.domain.MutableStorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl; +import org.jclouds.domain.Location; import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata; import com.google.common.base.Function; @@ -33,9 +35,17 @@ import com.google.common.base.Function; */ @Singleton public class ContainerToResourceMetadata implements Function { + private Location defaultLocation; + + @Inject + ContainerToResourceMetadata(Location defaultLocation) { + this.defaultLocation = defaultLocation; + } + public StorageMetadata apply(ContainerMetadata from) { MutableStorageMetadata to = new MutableStorageMetadataImpl(); to.setName(from.getName()); + to.setLocation(defaultLocation); to.setType(StorageType.CONTAINER); return to; } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/config/CloudFilesContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/config/CloudFilesContextModule.java index 54e9e74980..679aec0121 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/config/CloudFilesContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/config/CloudFilesContextModule.java @@ -28,6 +28,7 @@ import org.jclouds.lifecycle.Closer; import org.jclouds.rackspace.CloudFiles; import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient; import org.jclouds.rackspace.cloudfiles.CloudFilesClient; +import org.jclouds.rackspace.config.RackspaceLocationsModule; import org.jclouds.rackspace.reference.RackspaceConstants; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; @@ -51,6 +52,7 @@ public class CloudFilesContextModule extends AbstractModule { }, new TypeLiteral() { })); install(new CFObjectModule()); + install(new RackspaceLocationsModule()); } @Provides diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 7d596268e9..b5edc3c78d 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -63,8 +63,6 @@ import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; -import org.jclouds.domain.internal.LocationImpl; import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient; @@ -76,6 +74,7 @@ import org.jclouds.rackspace.cloudservers.domain.RebootType; import org.jclouds.rackspace.cloudservers.domain.Server; import org.jclouds.rackspace.cloudservers.domain.ServerStatus; import org.jclouds.rackspace.cloudservers.options.ListOptions; +import org.jclouds.rackspace.config.RackspaceLocationsModule; import org.jclouds.rackspace.reference.RackspaceConstants; import org.jclouds.rest.RestContext; import org.jclouds.ssh.SshClient; @@ -102,6 +101,7 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext @Override protected void configure() { super.configure(); + install(new RackspaceLocationsModule()); bind(new TypeLiteral>() { }).to(ServerToNodeMetadata.class); bind(AddNodeWithTagStrategy.class).to(CloudServersAddNodeWithTagStrategy.class); @@ -282,18 +282,6 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext TimeUnit.SECONDS); } - @Provides - @Singleton - Location getRegion() { - return new LocationImpl(LocationScope.ZONE, "DALLAS", "Dallas, TX", null); - } - - @Provides - @Singleton - Map provideLocations(Location location) { - return ImmutableMap.of(location.getId(), location); - } - @Provides @Singleton protected Function indexer() { diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java index 99a8726944..837e04a91c 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java @@ -41,7 +41,8 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ public class ServerToNodeMetadata implements Function { - public static final Pattern TAG_PATTERN = Pattern.compile("[^-]+-([^-]+)-[0-9]+"); + public static final Pattern SECOND_FIELD_DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern + .compile("[^-]+-([^-]+)-[0-9a-f]+"); private final Location location; private final Map serverToNodeState; private final Map images; @@ -56,7 +57,8 @@ public class ServerToNodeMetadata implements Function { @Override public NodeMetadata apply(Server from) { - Matcher matcher = TAG_PATTERN.matcher(from.getName()); + Matcher matcher = SECOND_FIELD_DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from + .getName()); final String tag = matcher.find() ? matcher.group(1) : null; return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, from .getMetadata(), tag, images.get(from.getImageId().toString()), serverToNodeState diff --git a/rackspace/src/main/java/org/jclouds/rackspace/config/RackspaceLocationsModule.java b/rackspace/src/main/java/org/jclouds/rackspace/config/RackspaceLocationsModule.java new file mode 100644 index 0000000000..aeeff3ddab --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/config/RackspaceLocationsModule.java @@ -0,0 +1,57 @@ +/** + * + * 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.rackspace.config; + +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.http.RequiresHttp; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * Configures the locations used in Rackspace services + * + * @author Adrian Cole + */ +@RequiresHttp +public class RackspaceLocationsModule extends AbstractModule { + + @Override + protected void configure() { + } + + @Provides + @Singleton + Location getLocation() { + return new LocationImpl(LocationScope.ZONE, "DFW1", "Dallas, TX", null); + } + + @Provides + @Singleton + Map provideLocations(Location location) { + return ImmutableMap.of(location.getId(), location); + } +} \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesAsyncClient.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesAsyncClient.java index afebbd956f..8ca27fc4ae 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesAsyncClient.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesAsyncClient.java @@ -98,7 +98,7 @@ public class StubCloudFilesAsyncClient implements CloudFilesAsyncClient { } public ListenableFuture createContainer(String container) { - return blobStore.createContainerInLocation("default", container); + return blobStore.createContainerInLocation(null, container); } public ListenableFuture deleteContainerIfEmpty(String container) { diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java index d791c473de..d2e886ce3e 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java @@ -250,7 +250,7 @@ public class CloudServersClientLiveTest { assert client.getSharedIpGroup(12312987) == null; } - @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testCreateSharedIpGroup() throws Exception { SharedIpGroup sharedIpGroup = null; while (sharedIpGroup == null) { @@ -282,6 +282,7 @@ public class CloudServersClientLiveTest { private String adminPass2; private int imageId; + @Test(enabled = false) public void testCreateServer() throws Exception { int imageId = 14362; int flavorId = 1; @@ -333,7 +334,7 @@ public class CloudServersClientLiveTest { } } - @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testServerDetails() throws Exception { Server server = client.getServer(serverId); @@ -403,7 +404,7 @@ public class CloudServersClientLiveTest { } } - @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testRenameServer() throws Exception { Server server = client.getServer(serverId); String oldName = server.getName(); @@ -412,7 +413,7 @@ public class CloudServersClientLiveTest { assertEquals(oldName + "new", client.getServer(serverId).getName()); } - @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testChangePassword() throws Exception { client.changeAdminPass(serverId, "elmo"); blockUntilServerActive(serverId); @@ -420,7 +421,7 @@ public class CloudServersClientLiveTest { this.adminPass = "elmo"; } - @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateSharedIpGroup") + @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateSharedIpGroup") public void testCreateServerIp() throws Exception { int imageId = 14362; int flavorId = 1; @@ -460,7 +461,7 @@ public class CloudServersClientLiveTest { } } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp") public void testUnshare() throws Exception { client.unshareIp(ip, serverId2); blockUntilServerActive(serverId2); @@ -481,7 +482,7 @@ public class CloudServersClientLiveTest { } } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testUnshare") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testUnshare") public void testShareConfig() throws Exception { client.shareIp(ip, serverId2, sharedIpGroupId, true); blockUntilServerActive(serverId2); @@ -491,7 +492,7 @@ public class CloudServersClientLiveTest { testUnshare(); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareConfig") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareConfig") public void testShareNoConfig() throws Exception { client.shareIp(ip, serverId2, sharedIpGroupId, false); blockUntilServerActive(serverId2); @@ -501,7 +502,7 @@ public class CloudServersClientLiveTest { testUnshare(); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig") public void testBackup() throws Exception { assertEquals(new BackupSchedule(), client.getBackupSchedule(serverId)); BackupSchedule dailyWeekly = new BackupSchedule(); @@ -514,7 +515,7 @@ public class CloudServersClientLiveTest { assertEquals(client.getBackupSchedule(serverId).isEnabled(), false); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup") public void testCreateImage() throws Exception { Image image = client.createImageFromServer("hoofie", serverId); assertEquals("hoofie", image.getName()); @@ -523,7 +524,7 @@ public class CloudServersClientLiveTest { blockUntilImageActive(imageId); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage") public void testRebuildServer() throws Exception { client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId)); blockUntilServerActive(serverId); @@ -531,19 +532,19 @@ public class CloudServersClientLiveTest { // assertEquals(new Integer(imageId), client.getServer(serverId).getImageId()); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer") public void testRebootHard() throws Exception { client.rebootServer(serverId, RebootType.HARD); blockUntilServerActive(serverId); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard") public void testRebootSoft() throws Exception { client.rebootServer(serverId, RebootType.SOFT); blockUntilServerActive(serverId); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") public void testRevertResize() throws Exception { client.resizeServer(serverId, 2); blockUntilServerVerifyResize(serverId); @@ -552,7 +553,7 @@ public class CloudServersClientLiveTest { assertEquals(new Integer(1), client.getServer(serverId).getFlavorId()); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") public void testConfirmResize() throws Exception { client.resizeServer(serverId2, 2); blockUntilServerVerifyResize(serverId2); @@ -561,8 +562,8 @@ public class CloudServersClientLiveTest { assertEquals(new Integer(2), client.getServer(serverId2).getFlavorId()); } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", - "testConfirmResize" }) + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", + "testRevertResize", "testConfirmResize" }) void deleteServer2() { if (serverId2 > 0) { client.deleteServer(serverId2); @@ -570,7 +571,7 @@ public class CloudServersClientLiveTest { } } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2") void testDeleteImage() { if (imageId > 0) { client.deleteImage(imageId); @@ -578,7 +579,7 @@ public class CloudServersClientLiveTest { } } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage") + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage") void deleteServer1() { if (serverId > 0) { client.deleteServer(serverId); @@ -586,7 +587,7 @@ public class CloudServersClientLiveTest { } } - @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "deleteServer1" }) + @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = { "deleteServer1" }) void testDeleteSharedIpGroup() { if (sharedIpGroupId > 0) { client.deleteSharedIpGroup(sharedIpGroupId); diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java index 2e9d50ba37..d2b8c17e1e 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -53,7 +53,7 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64); assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU); - assertEquals(defaultTemplate.getLocation().getId(), "DALLAS"); + assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(defaultTemplate.getSize().getCores(), 1.0d); } diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java index fc48502c1d..8c85726351 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java @@ -38,7 +38,7 @@ public class ServerToNodeMetadataTest { Server server = createMock(Server.class); expect(server.getId()).andReturn(10000).atLeastOnce(); - expect(server.getName()).andReturn("adrian-tag-100").atLeastOnce(); + expect(server.getName()).andReturn("adriancole-cloudservers-ea3").atLeastOnce(); expect(server.getMetadata()).andReturn(ImmutableMap. of()).atLeastOnce(); expect(server.getStatus()).andReturn(ServerStatus.ACTIVE).atLeastOnce(); @@ -74,7 +74,7 @@ public class ServerToNodeMetadataTest { assertEquals(metadata.getLocation(), location); assertEquals(metadata.getImage(), jcImage); assert metadata.getUserMetadata() != null; - assertEquals(metadata.getTag(), "tag"); + assertEquals(metadata.getTag(), "cloudservers"); assertEquals(metadata.getCredentials(), null); assertEquals(metadata.getPrivateAddresses(), privateAddresses); diff --git a/tools/getpath/src/test/java/org/jclouds/blobstore/GetPathLiveTest.java b/tools/getpath/src/test/java/org/jclouds/blobstore/GetPathLiveTest.java index 07ed729102..008e7a6b5d 100755 --- a/tools/getpath/src/test/java/org/jclouds/blobstore/GetPathLiveTest.java +++ b/tools/getpath/src/test/java/org/jclouds/blobstore/GetPathLiveTest.java @@ -91,10 +91,9 @@ public class GetPathLiveTest { .getProperty(PROPERTY_AWS_ACCESSKEYID), System .getProperty(PROPERTY_AWS_SECRETACCESSKEY), "s3", container, path)); - BlobStoreContext cfContext = CloudFilesContextFactory.createContext(checkNotNull( - System.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER), System - .getProperty(PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY), - new Log4JLoggingModule()); + BlobStoreContext cfContext = CloudFilesContextFactory.createContext(checkNotNull(System + .getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER), System.getProperty( + PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY), new Log4JLoggingModule()); urisToTest.add(String.format("blobstore://%s:%s@%s/%s/%s", System .getProperty(PROPERTY_RACKSPACE_USER), System.getProperty(PROPERTY_RACKSPACE_KEY), "cloudfiles", container, path)); @@ -124,7 +123,7 @@ public class GetPathLiveTest { for (BlobStoreContext context : contexts) { System.err.printf("creating container %s at %s%n", container, context .getProviderSpecificContext().getEndPoint()); - context.getBlobStore().createContainerInLocation("default", container); + context.getBlobStore().createContainerInLocation(null, container); } if (deleted) { System.err.println("sleeping 5 seconds to allow containers to create"); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index d49f2eed64..f63d36b51c 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -40,7 +40,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; * @see * @author Adrian Cole */ -@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) public interface VCloudClient { /** * This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index 622840a5ef..3921d45c58 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java @@ -46,7 +46,7 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions; * @see * @author Adrian Cole */ -@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) public interface TerremarkVCloudClient extends VCloudClient { /** diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java index 41cbee20b0..7af0068a51 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java @@ -84,7 +84,8 @@ public class TerremarkVCloudComputeServiceLiveTest extends VCloudComputeServiceL // image.getValue().getLocationId() can be null, if it is a location-free image assertEquals(image.getValue().getType(), ComputeType.IMAGE); assert image.getValue().getDefaultCredentials().account != null : image; - assert image.getValue().getDefaultCredentials().key != null : image; + if (image.getValue().getOsFamily() != OsFamily.WINDOWS) + assert image.getValue().getDefaultCredentials().key != null : image; } }