diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java index 17670dc8bd..793283405c 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java @@ -115,7 +115,7 @@ public class EC2ImageParser implements Function getAllRunningInstancesInRegion(InstanceClient client, String region, + String id) { + return Iterables.concat(client.describeInstancesInRegion(region, id)); + } + } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/AvailabilityZone.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/AvailabilityZone.java deleted file mode 100644 index cf7245e446..0000000000 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/AvailabilityZone.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * - * 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.ec2.domain; - -import java.util.Set; - -import com.google.common.collect.ImmutableSet; - -/** - * - * Availability zones used for all ec2 instance commands. - * - * @author Adrian Cole - */ -public class AvailabilityZone { - - public static final String EU_WEST_1A = "eu-west-1a"; - public static final String EU_WEST_1B = "eu-west-1b"; - public static final String US_EAST_1A = "us-east-1a"; - public static final String US_EAST_1B = "us-east-1b"; - public static final String US_EAST_1C = "us-east-1c"; - public static final String US_EAST_1D = "us-east-1d"; - public static final String US_WEST_1A = "us-west-1a"; - public static final String US_WEST_1B = "us-west-1b"; - public static final String AP_SOUTHEAST_1A = "ap-southeast-1a"; - public static final String AP_SOUTHEAST_1B = "ap-southeast-1b"; - - public static final Set zones = ImmutableSet.of(EU_WEST_1A, EU_WEST_1B, - US_EAST_1A, US_EAST_1B, US_EAST_1C, US_EAST_1D, - US_WEST_1A, US_WEST_1B, AP_SOUTHEAST_1A, AP_SOUTHEAST_1B); - -} diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java b/apis/ec2/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java index 27aefe9ad1..cd5ff1ea9b 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java @@ -22,7 +22,6 @@ package org.jclouds.ec2.options; import java.util.Arrays; import java.util.Set; -import org.jclouds.aws.domain.Region; import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; /** @@ -61,7 +60,7 @@ public class DescribeRegionsOptions extends BaseEC2RequestOptions { public static class Builder { /** - * @see DescribeRegionsOptions#regions(Region[] ) + * @see DescribeRegionsOptions#regions(String[] ) */ public static DescribeRegionsOptions regions(String... regions) { DescribeRegionsOptions options = new DescribeRegionsOptions(); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/util/EC2Utils.java b/apis/ec2/src/main/java/org/jclouds/ec2/util/EC2Utils.java deleted file mode 100644 index 7e5c6e6117..0000000000 --- a/apis/ec2/src/main/java/org/jclouds/ec2/util/EC2Utils.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - * 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.ec2.util; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -import org.jclouds.aws.util.AWSUtils; -import org.jclouds.ec2.domain.AvailabilityZone; -import org.jclouds.ec2.domain.RunningInstance; -import org.jclouds.ec2.services.InstanceClient; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; - -/** - * - * @author Adrian Cole - */ -public class EC2Utils { - public static String[] getAvailabilityZonesForRegion(String region) { - Set availabilityZones = new HashSet(); - for (String az : AvailabilityZone.zones) { - if (az.startsWith(region)) - availabilityZones.add(az); - } - - return (String[]) availabilityZones.toArray(new String[availabilityZones.size()]); - } - - public static Iterable getAllRunningInstancesInRegion(InstanceClient client, String region, - String id) { - return Iterables.concat(client.describeInstancesInRegion(region, id)); - } - - public static String findAvailabilityZoneInArgsOrNull(GeneratedHttpRequest gRequest) { - for (Object arg : gRequest.getArgs()) { - if (arg instanceof String) { - String zone = (String) arg; - if (AvailabilityZone.zones.contains(zone)) - return zone; - } - } - return null; - } - - private static final Pattern ELB_PATTERN = Pattern.compile("([^.]+)-[^.]+\\.([^.]+)\\.elb\\.amazonaws\\.com"); - - public static Map getLoadBalancerNameAndRegionFromDnsName(String dnsName) { - Matcher matcher = ELB_PATTERN.matcher(checkNotNull(dnsName, "dnsName")); - checkArgument(matcher.find(), "dnsName syntax is " + ELB_PATTERN + " didn't match: " + dnsName); - String loadBalancerName = matcher.group(1); - String regionName = matcher.group(2); - checkArgument((AWSUtils.isRegion(regionName)), - String.format("Region (%s) parsed from (%s) is not a valid region", regionName, dnsName)); - return ImmutableMap. of(regionName, loadBalancerName); - } -} diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/CreateVolumeResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/CreateVolumeResponseHandler.java index 30594e0ad8..ab50e5e88c 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/CreateVolumeResponseHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/CreateVolumeResponseHandler.java @@ -28,16 +28,16 @@ import java.util.Set; import javax.annotation.Resource; import javax.inject.Inject; -import org.jclouds.ec2.domain.Attachment; -import org.jclouds.ec2.domain.Volume; -import org.jclouds.ec2.util.EC2Utils; import org.jclouds.aws.util.AWSUtils; import org.jclouds.date.DateService; +import org.jclouds.ec2.domain.Attachment; +import org.jclouds.ec2.domain.Volume; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.location.Region; import org.jclouds.location.Zone; import org.jclouds.logging.Logger; +import org.jclouds.rest.internal.GeneratedHttpRequest; import org.xml.sax.Attributes; import com.google.common.collect.Sets; @@ -46,8 +46,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -public class CreateVolumeResponseHandler extends - ParseSax.HandlerForGeneratedRequestWithResult { +public class CreateVolumeResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult { private StringBuilder currentText = new StringBuilder(); @Resource @@ -128,8 +127,7 @@ public class CreateVolumeResponseHandler extends attachTime = dateService.iso8601DateParse(currentText.toString().trim()); } else if (qName.equals("item")) { if (inAttachmentSet) { - attachments.add(new Attachment(region, volumeId, instanceId, device, attachmentStatus, - attachTime)); + attachments.add(new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime)); volumeId = null; instanceId = null; device = null; @@ -142,8 +140,7 @@ public class CreateVolumeResponseHandler extends } private Volume newVolume() { - Volume volume = new Volume(region, id, size, snapshotId, availabilityZone, volumeStatus, - createTime, attachments); + Volume volume = new Volume(region, id, size, snapshotId, availabilityZone, volumeStatus, createTime, attachments); id = null; size = 0; snapshotId = null; @@ -163,14 +160,26 @@ public class CreateVolumeResponseHandler extends super.setContext(request); region = AWSUtils.findRegionInArgsOrNull(getRequest()); if (region == null) { - String zone = EC2Utils.findAvailabilityZoneInArgsOrNull(getRequest()); + String zone = findAvailabilityZoneInArgsOrNull(getRequest(), availabilityZoneToRegion.keySet()); if (zone != null) { - region = checkNotNull(availabilityZoneToRegion.get(zone), String.format( - "zone %s not in %s", zone, availabilityZoneToRegion)); + region = checkNotNull(availabilityZoneToRegion.get(zone), + String.format("zone %s not in %s", zone, availabilityZoneToRegion)); } else { region = defaultRegion; } } return this; } + + public static String findAvailabilityZoneInArgsOrNull(GeneratedHttpRequest gRequest, Set zones) { + for (Object arg : gRequest.getArgs()) { + if (arg instanceof String) { + String zone = (String) arg; + if (zones.contains(zone)) + return zone; + } + } + return null; + } + } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java index 605a6660fe..568a2b4978 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Set; import org.easymock.IArgumentMatcher; -import org.jclouds.aws.domain.Region; import org.jclouds.compute.config.CustomizationResponse; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; @@ -44,7 +43,6 @@ import org.jclouds.domain.LocationScope; import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata; import org.jclouds.ec2.compute.options.EC2TemplateOptions; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.options.RunInstancesOptions; @@ -65,12 +63,12 @@ public class EC2RunNodesAndAddToSetStrategyTest { @Test public void testZoneAsALocation() { - assertRegionAndZoneForLocation(ZONE_AP_SOUTHEAST_1A, Region.AP_SOUTHEAST_1, AvailabilityZone.AP_SOUTHEAST_1A); + assertRegionAndZoneForLocation(ZONE_AP_SOUTHEAST_1A, "ap-southeast-1", "ap-southeast-1a"); } @Test public void testRegionAsALocation() { - assertRegionAndZoneForLocation(REGION_AP_SOUTHEAST_1, Region.AP_SOUTHEAST_1, null); + assertRegionAndZoneForLocation(REGION_AP_SOUTHEAST_1, "ap-southeast-1", null); } // // fixtures @@ -155,10 +153,10 @@ public class EC2RunNodesAndAddToSetStrategyTest { } private static final Location REGION_AP_SOUTHEAST_1 = new LocationBuilder().scope(LocationScope.REGION).id( - Region.AP_SOUTHEAST_1).description(Region.AP_SOUTHEAST_1).parent( - new LocationBuilder().scope(LocationScope.PROVIDER).id("ec2").description("ec2").build()).build(); + "ap-southeast-1").description("ap-southeast-1").parent( + new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build()).build(); private static final Location ZONE_AP_SOUTHEAST_1A = new LocationBuilder().scope(LocationScope.ZONE).id( - AvailabilityZone.AP_SOUTHEAST_1A).description(AvailabilityZone.AP_SOUTHEAST_1A).parent( + "ap-southeast-1a").description("ap-southeast-1a").parent( REGION_AP_SOUTHEAST_1).build(); // ///////////////////////////////////////////////////////////////////// diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java index f6f3326fb6..b09dc655d9 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java @@ -27,7 +27,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import org.jclouds.aws.domain.Region; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.options.DescribeAvailabilityZonesOptions; import org.jclouds.ec2.options.DescribeRegionsOptions; import org.jclouds.ec2.xml.DescribeAvailabilityZonesResponseHandler; @@ -48,17 +47,17 @@ import com.google.inject.TypeLiteral; // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "AvailabilityZoneAndRegionAsyncClientTest") public class AvailabilityZoneAndRegionAsyncClientTest extends - BaseEC2AsyncClientTest { + BaseEC2AsyncClientTest { public void testDescribeAvailabilityZones() throws SecurityException, NoSuchMethodException, IOException { Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeAvailabilityZonesInRegion", - String.class, Array.newInstance(DescribeAvailabilityZonesOptions.class, 0).getClass()); + String.class, Array.newInstance(DescribeAvailabilityZonesOptions.class, 0).getClass()); HttpRequest request = processor.createRequest(method, Region.US_WEST_1); assertRequestLineEquals(request, "POST https://ec2.us-west-1.amazonaws.com/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: ec2.us-west-1.amazonaws.com\n"); assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeAvailabilityZones", - "application/x-www-form-urlencoded", false); + "application/x-www-form-urlencoded", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class); @@ -69,15 +68,14 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends public void testDescribeAvailabilityZonesOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeAvailabilityZonesInRegion", - String.class, Array.newInstance(DescribeAvailabilityZonesOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, Region.US_EAST_1, availabilityZones( - AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B)); + String.class, Array.newInstance(DescribeAvailabilityZonesOptions.class, 0).getClass()); + HttpRequest request = processor.createRequest(method, "us-east-1", availabilityZones("us-east-1a", "us-east-1b")); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals(request, - "Version=2010-06-15&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b", - "application/x-www-form-urlencoded", false); + "Version=2010-06-15&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b", + "application/x-www-form-urlencoded", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class); @@ -87,14 +85,14 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends } public void testDescribeRegions() throws SecurityException, NoSuchMethodException, IOException { - Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array.newInstance( - DescribeRegionsOptions.class, 0).getClass()); + Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", + Array.newInstance(DescribeRegionsOptions.class, 0).getClass()); HttpRequest request = processor.createRequest(method); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeRegions", "application/x-www-form-urlencoded", - false); + false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class); @@ -104,15 +102,15 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends } public void testDescribeRegionsOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array.newInstance( - DescribeRegionsOptions.class, 0).getClass()); + Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", + Array.newInstance(DescribeRegionsOptions.class, 0).getClass()); HttpRequest request = processor.createRequest(method, regions(Region.US_EAST_1, Region.US_WEST_1)); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals(request, - "Version=2010-06-15&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1", - "application/x-www-form-urlencoded", false); + "Version=2010-06-15&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1", + "application/x-www-form-urlencoded", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java index 76fce4f473..d7ed36b608 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java @@ -34,7 +34,6 @@ import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2ContextBuilder; import org.jclouds.ec2.EC2PropertiesBuilder; import org.jclouds.ec2.config.EC2RestClientModule; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; @@ -85,7 +84,7 @@ public abstract class BaseEC2AsyncClientTest extends RestClientTest { static class Zones implements javax.inject.Provider> { @Override public Map get() { - return ImmutableMap. of(AvailabilityZone.US_EAST_1A, Region.US_EAST_1); + return ImmutableMap. of("us-east-1a", "us-east-1"); } } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreAsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreAsyncClientTest.java index 739ac43055..cce049ae77 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreAsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreAsyncClientTest.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Method; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.functions.ReturnVoidOnVolumeAvailable; import org.jclouds.ec2.options.CreateSnapshotOptions; import org.jclouds.ec2.options.DescribeSnapshotsOptions; @@ -59,7 +58,7 @@ public class ElasticBlockStoreAsyncClientTest extends BaseEC2AsyncClientTest allResults = Sets.newTreeSet(client.describeVolumesInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { @@ -120,10 +118,10 @@ public class ElasticBlockStoreClientLiveTest { @Test void testCreateVolumeInAvailabilityZone() { - Volume expected = client.createVolumeInAvailabilityZone(AvailabilityZone.US_EAST_1B, 1); + Volume expected = client.createVolumeInAvailabilityZone(getDefaultAvailabilityZone(), 1); assertNotNull(expected); System.out.println(expected); - assertEquals(expected.getAvailabilityZone(), AvailabilityZone.US_EAST_1B); + assertEquals(expected.getAvailabilityZone(), getDefaultAvailabilityZone()); this.volumeId = expected.getId(); @@ -148,9 +146,13 @@ public class ElasticBlockStoreClientLiveTest { this.snapshot = result; } + protected String getDefaultAvailabilityZone(){ + return "us-east-1a"; + } + @Test(dependsOnMethods = "testCreateSnapshotInRegion") void testCreateVolumeFromSnapshotInAvailabilityZone() { - Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone.US_EAST_1A, snapshot.getId()); + Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(getDefaultAvailabilityZone(), snapshot.getId()); assertNotNull(volume); Predicate availabile = new RetryablePredicate(new VolumeAvailable(client), 600, 10, @@ -160,7 +162,7 @@ public class ElasticBlockStoreClientLiveTest { Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); assertEquals(volume.getId(), result.getId()); assertEquals(volume.getSnapshotId(), snapshot.getId()); - assertEquals(volume.getAvailabilityZone(), AvailabilityZone.US_EAST_1A); + assertEquals(volume.getAvailabilityZone(), getDefaultAvailabilityZone()); assertEquals(result.getStatus(), Volume.Status.AVAILABLE); client.deleteVolumeInRegion(snapshot.getRegion(), volume.getId()); @@ -168,7 +170,7 @@ public class ElasticBlockStoreClientLiveTest { @Test(dependsOnMethods = "testCreateSnapshotInRegion") void testCreateVolumeFromSnapshotInAvailabilityZoneWithSize() { - Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone.US_EAST_1B, 2, + Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(getDefaultAvailabilityZone(), 2, snapshot.getId()); assertNotNull(volume); @@ -179,7 +181,7 @@ public class ElasticBlockStoreClientLiveTest { Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); assertEquals(volume.getId(), result.getId()); assertEquals(volume.getSnapshotId(), snapshot.getId()); - assertEquals(volume.getAvailabilityZone(), AvailabilityZone.US_EAST_1B); + assertEquals(volume.getAvailabilityZone(), getDefaultAvailabilityZone()); assertEquals(volume.getSize(), 2); assertEquals(result.getStatus(), Volume.Status.AVAILABLE); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java index 3088a7ffd7..67d3c7b4a2 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java @@ -24,8 +24,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.Map; -import org.jclouds.aws.domain.Region; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; @@ -131,7 +129,7 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest - * - * ==================================================================== - * 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.ec2.utils; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.ec2.util.EC2Utils; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit") -public class EC2UtilsTest { - - public void testGetLoadBalancerNameAndRegionFromDnsName() { - assertEquals( - ImmutableMap. of("us-east-1", "my-load-balancer"), - EC2Utils - .getLoadBalancerNameAndRegionFromDnsName("my-load-balancer-1277832914.us-east-1.elb.amazonaws.com")); - assertEquals( - ImmutableMap. of("us-east-1", "ec2lb"), - EC2Utils - .getLoadBalancerNameAndRegionFromDnsName("ec2lb-915583419.us-east-1.elb.amazonaws.com")); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testGetLoadBalancerNameAndRegionFromDnsNameFail() { - EC2Utils - .getLoadBalancerNameAndRegionFromDnsName("my-load-balancer-1277832914.us-east-1.microsoft.com"); - } - -} diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/BaseEC2HandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/BaseEC2HandlerTest.java index 18d9c95bba..2b1c7d0f7e 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/BaseEC2HandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/BaseEC2HandlerTest.java @@ -24,7 +24,6 @@ import java.util.Map; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.config.SaxParserModule; @@ -68,7 +67,7 @@ public abstract class BaseEC2HandlerTest extends BaseHandlerTest { @Provides @Zone Map provideAvailabilityZoneRegionMap() { - return ImmutableMap. of(AvailabilityZone.US_EAST_1A, Region.US_EAST_1); + return ImmutableMap. of("us-east-1a", "us-east-1"); } }); factory = injector.getInstance(ParseSax.Factory.class); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/CreateVolumeResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/CreateVolumeResponseHandlerTest.java index 633ddb1071..a27064c496 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/CreateVolumeResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/CreateVolumeResponseHandlerTest.java @@ -29,7 +29,6 @@ import java.io.InputStream; import org.jclouds.aws.domain.Region; import org.jclouds.date.DateService; import org.jclouds.ec2.domain.Attachment; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.Volume; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; @@ -52,7 +51,7 @@ public class CreateVolumeResponseHandlerTest extends BaseEC2HandlerTest { InputStream is = getClass().getResourceAsStream("/created_volume.xml"); Volume expected = new Volume(Region.US_EAST_1, "vol-2a21e543", 1, null, - AvailabilityZone.US_EAST_1A, Volume.Status.CREATING, dateService + "us-east-1a", Volume.Status.CREATING, dateService .iso8601DateParse("2009-12-28T05:42:53.000Z"), Sets . newLinkedHashSet()); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java index 40e2ce34bb..3223c0aab2 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandlerTest.java @@ -24,8 +24,6 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; -import org.jclouds.aws.domain.Region; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.AvailabilityZoneInfo; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; @@ -66,14 +64,14 @@ public class DescribeAvailabilityZonesResponseHandlerTest extends BaseHandlerTes Set expected = ImmutableSet. of( - new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1A, "available", Region.US_EAST_1, ImmutableSet. of()), - new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1B, "available", Region.US_EAST_1, ImmutableSet + new AvailabilityZoneInfo("us-east-1a", "available", "us-east-1", ImmutableSet. of()), + new AvailabilityZoneInfo("us-east-1b", "available", "us-east-1", ImmutableSet . of()), - new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1C, "available", Region.US_EAST_1, ImmutableSet + new AvailabilityZoneInfo("us-east-1c", "available", "us-east-1", ImmutableSet . of("our service is awesome")), - new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1D, "downlikeaclown", Region.US_EAST_1, ImmutableSet + new AvailabilityZoneInfo("us-east-1d", "downlikeaclown", "us-east-1", ImmutableSet . of())); Set result = factory.create( injector.getInstance(DescribeAvailabilityZonesResponseHandler.class)).parse(is); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java index cba5d6dd23..a8c15847a4 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java @@ -27,7 +27,6 @@ import java.util.Set; import org.jclouds.date.DateService; import org.jclouds.ec2.domain.Attachment; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceType; @@ -74,7 +73,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { "174.129.81.68").kernelId("aki-a71cf9ce").keyName("adriancole.ec21").launchTime( dateService.iso8601DateParse("2009-11-09T03:00:34.000Z")) // MonitoringState.DISABLED, - .availabilityZone(AvailabilityZone.US_EAST_1C).virtualizationType("paravirtual") + .availabilityZone("us-east-1c").virtualizationType("paravirtual") .privateDnsName("ip-10-243-42-70.ec2.internal").privateIpAddress("10.243.42.70").ramdiskId( "ari-a51cf9cc").rootDeviceType(RootDeviceType.INSTANCE_STORE).build()), "993194456877", null, "r-a3c508cb")); @@ -92,7 +91,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")) // MonitoringState.DISABLED, - .availabilityZone(AvailabilityZone.US_EAST_1B).virtualizationType("paravirtual") + .availabilityZone("us-east-1b").virtualizationType("paravirtual") .privateDnsName("10-251-50-132.ec2.internal")// product codes // ImmutableSet.of("774F4FF8") .ramdiskId("ari-badbad00").rootDeviceType(RootDeviceType.INSTANCE_STORE).build(), @@ -102,7 +101,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name") .launchTime(dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")) // MonitoringState.DISABLED, - .availabilityZone(AvailabilityZone.US_EAST_1B).virtualizationType("paravirtual") + .availabilityZone("us-east-1b").virtualizationType("paravirtual") .privateDnsName("10-251-50-134.ec2.internal")// product codes // ImmutableSet.of("774F4FF8") .ramdiskId("ari-badbad00").rootDeviceType(RootDeviceType.INSTANCE_STORE).build()), @@ -124,7 +123,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { .keyName("adriancole.ec2ebs1") .launchTime(dateService.iso8601DateParse("2009-12-30T04:06:23.000Z")) // MonitoringState.DISABLED - .availabilityZone(AvailabilityZone.US_EAST_1B) + .availabilityZone("us-east-1b") // "placement" .virtualizationType("hvm").privateDnsName("domU-12-31-39-09-CE-53.compute-1.internal") .privateIpAddress("10.210.209.157").ramdiskId("ari-a51cf9cc") diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeVolumesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeVolumesResponseHandlerTest.java index 9d0cfc0963..02bec1b7b4 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeVolumesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeVolumesResponseHandlerTest.java @@ -27,10 +27,9 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; -import org.jclouds.ec2.domain.Attachment; -import org.jclouds.ec2.domain.AvailabilityZone; -import org.jclouds.ec2.domain.Volume; import org.jclouds.date.DateService; +import org.jclouds.ec2.domain.Attachment; +import org.jclouds.ec2.domain.Volume; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -52,11 +51,11 @@ public class DescribeVolumesResponseHandlerTest extends BaseEC2HandlerTest { InputStream is = getClass().getResourceAsStream("/describe_volumes.xml"); Set expected = Sets.newLinkedHashSet(); - expected.add(new Volume(defaultRegion, "vol-2a21e543", 1, null, AvailabilityZone.US_EAST_1A, + expected.add(new Volume(defaultRegion, "vol-2a21e543", 1, null, "us-east-1a", Volume.Status.AVAILABLE, dateService.iso8601DateParse("2009-12-28T05:42:53.000Z"), Sets. newLinkedHashSet())); expected.add(new Volume(defaultRegion, "vol-4282672b", 800, "snap-536d1b3a", - AvailabilityZone.US_EAST_1A, Volume.Status.IN_USE, dateService + "us-east-1a", Volume.Status.IN_USE, dateService .iso8601DateParse("2008-05-07T11:51:50.000Z"), Sets . newHashSet(new Attachment(defaultRegion, "vol-4282672b", "i-6058a509", "/dev/sdh", Attachment.Status.ATTACHED, dateService diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java index a35063aaf5..3e86390ef3 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java @@ -27,7 +27,6 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import org.jclouds.date.DateService; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.Reservation; @@ -70,19 +69,19 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { .imageId("ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING).instanceType( InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, - .availabilityZone(AvailabilityZone.US_EAST_1B).build(), + .availabilityZone("us-east-1b").build(), new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("1") .imageId("ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING).instanceType( InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, - .availabilityZone(AvailabilityZone.US_EAST_1B).build(), + .availabilityZone("us-east-1b").build(), new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("2") .imageId("ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING).instanceType( InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, - .availabilityZone(AvailabilityZone.US_EAST_1B).build()) + .availabilityZone("us-east-1b").build()) , "AIDADH4IGTRXXKCD", null, "r-47a5402e"); diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java index 7a1d0b15d4..38cd214bc6 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java @@ -44,13 +44,13 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.s3.config.S3RestClientModule; import org.jclouds.s3.domain.AccessControlList; +import org.jclouds.s3.domain.AccessControlList.EmailAddressGrantee; +import org.jclouds.s3.domain.AccessControlList.Grant; +import org.jclouds.s3.domain.AccessControlList.Permission; import org.jclouds.s3.domain.BucketLogging; import org.jclouds.s3.domain.CannedAccessPolicy; import org.jclouds.s3.domain.Payer; import org.jclouds.s3.domain.S3Object; -import org.jclouds.s3.domain.AccessControlList.EmailAddressGrantee; -import org.jclouds.s3.domain.AccessControlList.Grant; -import org.jclouds.s3.domain.AccessControlList.Permission; import org.jclouds.s3.functions.ParseObjectFromHeadersAndHttpContent; import org.jclouds.s3.functions.ParseObjectMetadataFromHeaders; import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState; @@ -87,7 +87,7 @@ public abstract class S3AsyncClientTest extends BaseS3A public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array.newInstance( PutBucketOptions.class, 0).getClass()); - for (String region : Region.ALL_S3) { + for (String region : Region.DEFAULT_S3) { processor.createRequest(method, region, "bucket-name"); } } diff --git a/common/aws/src/main/java/org/jclouds/aws/domain/Region.java b/common/aws/src/main/java/org/jclouds/aws/domain/Region.java index d28b2d57f3..d0a390fd10 100644 --- a/common/aws/src/main/java/org/jclouds/aws/domain/Region.java +++ b/common/aws/src/main/java/org/jclouds/aws/domain/Region.java @@ -19,8 +19,15 @@ package org.jclouds.aws.domain; +import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + +import java.util.Properties; import java.util.Set; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSet; /** @@ -84,6 +91,36 @@ public class Region { */ public static final String AP_SOUTHEAST_1 = "ap-southeast-1"; - public static Set ALL_S3 = ImmutableSet.of(EU, US_STANDARD, US_WEST_1, AP_SOUTHEAST_1); - public static Set ALL_SQS = ImmutableSet.of(EU_WEST_1, US_STANDARD, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1); + /** + * Region in Tokyo, launched March 2, 2011. This region improves latency for Asia-based users + */ + public static final String AP_NORTHEAST_1 = "ap-northeast-1"; + + public static Set DEFAULT_S3 = ImmutableSet.of(EU, US_STANDARD, US_WEST_1, AP_SOUTHEAST_1, AP_NORTHEAST_1); + + public static Set DEFAULT_REGIONS = ImmutableSet.of(US_EAST_1, US_WEST_1, EU_WEST_1, AP_SOUTHEAST_1, + AP_NORTHEAST_1); + + public static Properties regionPropertiesS3() { + + Properties properties = regionProperties(); + properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(DEFAULT_S3)); + // note that due to US_STANDARD the codes include US instead of US-VA + properties.setProperty(PROPERTY_ISO3166_CODES, "US,US-CA,IE,SG,JP-13"); + properties.setProperty(PROPERTY_REGION + "." + US_STANDARD + "." + ISO3166_CODES, "US"); + properties.setProperty(PROPERTY_REGION + "." + EU + "." + ISO3166_CODES, "IE"); + return properties; + } + + public static Properties regionProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(DEFAULT_REGIONS)); + properties.setProperty(PROPERTY_ISO3166_CODES, "US-VA,US-CA,IE,SG,JP-13"); + properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + "." + ISO3166_CODES, "US-VA"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + "." + ISO3166_CODES, "US-CA"); + properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + "." + ISO3166_CODES, "IE"); + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + "." + ISO3166_CODES, "SG"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + "." + ISO3166_CODES, "JP-13"); + return properties; + } } \ No newline at end of file diff --git a/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java b/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java index 0ce230422e..f356bfb914 100644 --- a/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java +++ b/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java @@ -117,10 +117,9 @@ public class AWSUtils { return forms.size() == 0 ? request : ModifyRequest.putFormParams(request, forms); } + // TODO: make this more dynamic public static boolean isRegion(String regionName) { - return Region.EU_WEST_1.equals(regionName) || Region.US_WEST_1.equals(regionName) - || Region.US_EAST_1.equals(regionName) || Region.US_STANDARD.equals(regionName) - || Region.AP_SOUTHEAST_1.equals(regionName); + return Region.DEFAULT_REGIONS.contains(regionName); } public static R indexIterableToFormValuesWithPrefix(R request, String prefix, Object input) { @@ -162,7 +161,7 @@ public class AWSUtils { for (Object arg : gRequest.getArgs()) { if (arg instanceof String) { String regionName = (String) arg; - //TODO regions may not be amazon regions! + // TODO regions may not be amazon regions! // take from a configured value if (isRegion(regionName)) return regionName; diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index eeeb84c7d6..519bd5c804 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -36,7 +36,10 @@ sdn.contextbuilder=org.jclouds.nirvanix.sdn.SDNContextBuilder sdn.propertiesbuilder=org.jclouds.nirvanix.sdn.SDNPropertiesBuilder aws-simpledb.contextbuilder=org.jclouds.simpledb.SimpleDBContextBuilder -aws-simpledb.propertiesbuilder=org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder +aws-simpledb.propertiesbuilder=org.jclouds.aws.simpledb.AWSSimpleDBPropertiesBuilder + +aws-sqs.contextbuilder=org.jclouds.sqs.SQSContextBuilder +aws-sqs.propertiesbuilder=org.jclouds.aws.sqs.AWSSQSPropertiesBuilder aws-elb.contextbuilder=org.jclouds.elb.ELBContextBuilder aws-elb.propertiesbuilder=org.jclouds.aws.elb.AWSELBPropertiesBuilder diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java index 720f854437..b4eda29b12 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java @@ -20,23 +20,13 @@ package org.jclouds.aws.ec2; import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; -import static org.jclouds.aws.domain.Region.EU_WEST_1; -import static org.jclouds.aws.domain.Region.US_EAST_1; -import static org.jclouds.aws.domain.Region.US_WEST_1; import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs; import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED; import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Properties; -import java.util.Set; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; +import org.jclouds.aws.domain.Region; /** * Builds properties used in EC2 Clients @@ -44,17 +34,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilder { - public static Set DEFAULT_REGIONS = ImmutableSet.of(US_EAST_1, US_WEST_1, EU_WEST_1, AP_SOUTHEAST_1); - @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-VA,US-CA,IE,SG"); - properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + "." + ISO3166_CODES, "US-VA"); - properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + "." + ISO3166_CODES, "US-CA"); - properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + "." + ISO3166_CODES, "IE"); - properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + "." + ISO3166_CODES, "SG"); - // sometimes, like in ec2, stop takes a very long time, perhaps // due to volume management. one example spent 2 minutes moving // from stopping->stopped state on an ec2 micro @@ -65,7 +47,7 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde properties.setProperty("jclouds.ssh.retryable_messages", "Auth fail,invalid data,End of IO Stream Read,Connection reset,socket is not established,connection is closed by foreign host,socket is not established"); properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(DEFAULT_REGIONS)); + properties.putAll(Region.regionProperties()); // amazon, alestic, canonical, and rightscale properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317"); // amis that work with the cluster instances diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index a67ffedbb5..1aebbc681b 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -209,7 +209,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { @Override protected Set getIso3166Codes() { - return ImmutableSet. of("US-VA", "US-CA", "IE", "SG"); + return ImmutableSet. of("US-VA", "US-CA", "IE", "SG", "JP-13"); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/AMIClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java similarity index 96% rename from apis/ec2/src/test/java/org/jclouds/ec2/services/AMIClientLiveTest.java rename to providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java index 7e6a7208a8..c6081b6cad 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/AMIClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java @@ -17,7 +17,7 @@ * ==================================================================== */ -package org.jclouds.ec2.services; +package org.jclouds.aws.ec2.services; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.imageIds; @@ -31,14 +31,13 @@ import java.util.Properties; import java.util.Set; import org.jclouds.Constants; -import org.jclouds.aws.AWSResponseException; -import org.jclouds.aws.domain.Region; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.domain.Image; -import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.Image.ImageType; +import org.jclouds.ec2.domain.RootDeviceType; +import org.jclouds.ec2.services.AMIClient; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; @@ -49,7 +48,6 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.inject.Module; @@ -69,7 +67,7 @@ public class AMIClientLiveTest { private Set imagesToDeregister = Sets.newHashSet(); - protected String provider = "ec2"; + protected String provider = "aws-ec2"; protected String identity; protected String credential; protected String endpoint; @@ -110,14 +108,13 @@ public class AMIClientLiveTest { assertEquals(client.describeImagesInRegion(null, imageIds("ami-cdf819a3")).size(), 0); } - @Test(expectedExceptions = AWSResponseException.class) + @Test(expectedExceptions = IllegalArgumentException.class) public void testDescribeImageBadId() { client.describeImagesInRegion(null, imageIds("asdaasdsa")); } public void testDescribeImages() { - for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { + for (String region : context.getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { Set allResults = Sets.newLinkedHashSet(client.describeImagesInRegion(region)); assertNotNull(allResults); assert allResults.size() >= 2 : allResults.size(); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java index 93670a523a..7f384fddc6 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java @@ -31,13 +31,12 @@ import java.util.Properties; import java.util.Set; import org.jclouds.Constants; -import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.ec2.domain.Image; -import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.Image.ImageType; +import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.RestContext; @@ -49,7 +48,6 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.inject.Module; @@ -102,7 +100,7 @@ public class AWSAMIClientLiveTest { setupCredentials(); Properties overrides = setupProperties(); context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); + ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); client = context.getApi().getAMIServices(); } @@ -116,8 +114,7 @@ public class AWSAMIClientLiveTest { } public void testDescribeImages() { - for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { + for (String region : context.getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { Set allResults = Sets.newLinkedHashSet(client.describeImagesInRegion(region)); assertNotNull(allResults); assert allResults.size() >= 2 : allResults.size(); @@ -138,7 +135,7 @@ public class AWSAMIClientLiveTest { String imageRegisteredId = client.registerImageFromManifestInRegion(null, "jcloudstest1", DEFAULT_MANIFEST); imagesToDeregister.add(imageRegisteredId); Image imageRegisteredFromManifest = Iterables.getOnlyElement(client.describeImagesInRegion(null, - imageIds(imageRegisteredId))); + imageIds(imageRegisteredId))); assertEquals(imageRegisteredFromManifest.getName(), "jcloudstest1"); assertEquals(imageRegisteredFromManifest.getImageLocation(), DEFAULT_MANIFEST); assertEquals(imageRegisteredFromManifest.getImageType(), ImageType.MACHINE); @@ -149,10 +146,10 @@ public class AWSAMIClientLiveTest { @Test(enabled = false) public void testRegisterImageFromManifestOptions() { String imageRegisteredWithOptionsId = client.registerImageFromManifestInRegion(null, "jcloudstest2", - DEFAULT_MANIFEST, withDescription("adrian")); + DEFAULT_MANIFEST, withDescription("adrian")); imagesToDeregister.add(imageRegisteredWithOptionsId); Image imageRegisteredFromManifestWithOptions = Iterables.getOnlyElement(client.describeImagesInRegion(null, - imageIds(imageRegisteredWithOptionsId))); + imageIds(imageRegisteredWithOptionsId))); assertEquals(imageRegisteredFromManifestWithOptions.getName(), "jcloudstest2"); assertEquals(imageRegisteredFromManifestWithOptions.getImageLocation(), DEFAULT_MANIFEST); assertEquals(imageRegisteredFromManifestWithOptions.getImageType(), ImageType.MACHINE); @@ -167,7 +164,7 @@ public class AWSAMIClientLiveTest { String imageRegisteredId = client.registerUnixImageBackedByEbsInRegion(null, "jcloudstest1", DEFAULT_MANIFEST); imagesToDeregister.add(imageRegisteredId); Image imageRegistered = Iterables - .getOnlyElement(client.describeImagesInRegion(null, imageIds(imageRegisteredId))); + .getOnlyElement(client.describeImagesInRegion(null, imageIds(imageRegisteredId))); assertEquals(imageRegistered.getName(), "jcloudstest1"); assertEquals(imageRegistered.getImageType(), ImageType.MACHINE); assertEquals(imageRegistered.getRootDeviceType(), RootDeviceType.EBS); @@ -178,18 +175,19 @@ public class AWSAMIClientLiveTest { // awaiting EBS functionality to be added to jclouds public void testRegisterImageBackedByEBSOptions() { String imageRegisteredWithOptionsId = client.registerUnixImageBackedByEbsInRegion(null, "jcloudstest2", - DEFAULT_SNAPSHOT, addNewBlockDevice("/dev/sda2", "myvirtual", 1).withDescription("adrian")); + DEFAULT_SNAPSHOT, addNewBlockDevice("/dev/sda2", "myvirtual", 1).withDescription("adrian")); imagesToDeregister.add(imageRegisteredWithOptionsId); Image imageRegisteredWithOptions = Iterables.getOnlyElement(client.describeImagesInRegion(null, - imageIds(imageRegisteredWithOptionsId))); + imageIds(imageRegisteredWithOptionsId))); assertEquals(imageRegisteredWithOptions.getName(), "jcloudstest2"); assertEquals(imageRegisteredWithOptions.getImageType(), ImageType.MACHINE); assertEquals(imageRegisteredWithOptions.getRootDeviceType(), RootDeviceType.EBS); assertEquals(imageRegisteredWithOptions.getRootDeviceName(), "/dev/sda1"); assertEquals(imageRegisteredWithOptions.getDescription(), "adrian"); - assertEquals(imageRegisteredWithOptions.getEbsBlockDevices().entrySet(), ImmutableMap.of("/dev/sda1", - new Image.EbsBlockDevice("/dev/sda1", 30, true), "/dev/sda2", - new Image.EbsBlockDevice("/dev/sda2", 1, true)).entrySet()); + assertEquals( + imageRegisteredWithOptions.getEbsBlockDevices().entrySet(), + ImmutableMap.of("/dev/sda1", new Image.EbsBlockDevice("/dev/sda1", 30, true), "/dev/sda2", + new Image.EbsBlockDevice("/dev/sda2", 1, true)).entrySet()); } @Test(enabled = false) diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceAsyncClientTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceAsyncClientTest.java index 6ba5b680a7..fcc2141ded 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceAsyncClientTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceAsyncClientTest.java @@ -24,11 +24,9 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.Map; -import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.options.AWSRunInstancesOptions; import org.jclouds.aws.ec2.xml.AWSDescribeInstancesResponseHandler; import org.jclouds.aws.ec2.xml.AWSRunInstancesResponseHandler; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; @@ -132,22 +130,22 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest> allResults = client.describeInstancesInRegion(region); assertNotNull(allResults); assert allResults.size() >= 0 : allResults.size(); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java index d661123576..731c5c32f5 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java @@ -11,7 +11,6 @@ import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.config.AWSEC2RestClientModule; import org.jclouds.aws.filters.FormSigner; import org.jclouds.date.DateService; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; @@ -59,7 +58,7 @@ public abstract class BaseAWSEC2AsyncClientTest extends RestClientTest { static class Zones implements javax.inject.Provider> { @Override public Map get() { - return ImmutableMap. of(AvailabilityZone.US_EAST_1A, Region.US_EAST_1); + return ImmutableMap. of("us-east-1a", "us-east-1"); } } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index c735d8750f..077e0e2fd6 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -112,14 +112,14 @@ public class PlacementGroupClientLiveTest { public void setupClient() throws FileNotFoundException, IOException { setupCredentials(); Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new JschSshClientModule()), overrides); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides); keyPair = setupKeyPair(); client = AWSEC2Client.class.cast(context.getProviderSpecificContext().getApi()); availableTester = new RetryablePredicate(new PlacementGroupAvailable(client), 60, 1, - TimeUnit.SECONDS); + TimeUnit.SECONDS); deletedTester = new RetryablePredicate(new PlacementGroupDeleted(client), 60, 1, TimeUnit.SECONDS); } @@ -128,24 +128,25 @@ public class PlacementGroupClientLiveTest { void testDescribe() { for (String region : newArrayList(Region.US_EAST_1)) { SortedSet allResults = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region)); + .describePlacementGroupsInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { PlacementGroup group = allResults.last(); SortedSet result = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region, group.getName())); + .describePlacementGroupsInRegion(region, group.getName())); assertNotNull(result); PlacementGroup compare = result.last(); assertEquals(compare, group); } } - for (String region : newArrayList(Region.EU_WEST_1, Region.US_WEST_1, Region.AP_SOUTHEAST_1)) { - try { - client.getPlacementGroupServices().describePlacementGroupsInRegion(region); - assert false : "should be unsupported"; - } catch (UnsupportedOperationException e) { - } + for (String region : client.getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { + if (!region.equals(Region.US_EAST_1)) + try { + client.getPlacementGroupServices().describePlacementGroupsInRegion(region); + assert false : "should be unsupported"; + } catch (UnsupportedOperationException e) { + } } } @@ -161,7 +162,7 @@ public class PlacementGroupClientLiveTest { private void verifyPlacementGroup(String groupName) { assert availableTester.apply(new PlacementGroup(Region.US_EAST_1, groupName, "cluster", State.PENDING)) : group; Set oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(null, - groupName); + groupName); assertNotNull(oneResult); assertEquals(oneResult.size(), 1); group = oneResult.iterator().next(); @@ -197,7 +198,7 @@ public class PlacementGroupClientLiveTest { assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) - .runScript(buildScript(template.getImage().getOperatingSystem())); + .runScript(buildScript(template.getImage().getOperatingSystem())); String group = PREFIX + "cccluster"; context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); @@ -209,7 +210,7 @@ public class PlacementGroupClientLiveTest { NodeMetadata node = getOnlyElement(nodes); getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, - node.getProviderId()))); + node.getProviderId()))); } catch (RunNodesException e) { System.err.println(e.getNodeErrors().keySet()); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java index ff2099e669..80cf0d64ce 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java @@ -29,7 +29,6 @@ import org.jclouds.aws.ec2.domain.AWSRunningInstance; import org.jclouds.aws.ec2.domain.MonitoringState; import org.jclouds.date.DateService; import org.jclouds.ec2.domain.Attachment; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceType; @@ -77,7 +76,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest .instanceType(InstanceType.M1_SMALL).ipAddress("174.129.81.68").kernelId( "aki-a71cf9ce").keyName("adriancole.ec21").launchTime( dateService.iso8601DateParse("2009-11-09T03:00:34.000Z")).monitoringState( - MonitoringState.DISABLED).availabilityZone(AvailabilityZone.US_EAST_1C) + MonitoringState.DISABLED).availabilityZone("us-east-1c") .virtualizationType("paravirtual").privateDnsName("ip-10-243-42-70.ec2.internal") .privateIpAddress("10.243.42.70").ramdiskId("ari-a51cf9cc").rootDeviceType( RootDeviceType.INSTANCE_STORE).build()), "993194456877", null, "r-a3c508cb")); @@ -95,7 +94,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest .instanceState(InstanceState.RUNNING).instanceType(InstanceType.M1_LARGE).kernelId( "aki-ba3adfd3").keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")).monitoringState( - MonitoringState.DISABLED).availabilityZone(AvailabilityZone.US_EAST_1B) + MonitoringState.DISABLED).availabilityZone("us-east-1b") .virtualizationType("paravirtual").privateDnsName("10-251-50-132.ec2.internal").productCode( "774F4FF8").ramdiskId("ari-badbad00").rootDeviceType(RootDeviceType.INSTANCE_STORE) .build(), new AWSRunningInstance.Builder().region(defaultRegion).groupId("default") @@ -103,7 +102,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest .instanceId("i-28a64435").instanceState(InstanceState.RUNNING).instanceType( InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name") .launchTime(dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")).monitoringState( - MonitoringState.DISABLED).availabilityZone(AvailabilityZone.US_EAST_1B) + MonitoringState.DISABLED).availabilityZone("us-east-1b") .virtualizationType("paravirtual").privateDnsName("10-251-50-134.ec2.internal").productCode( "774F4FF8").ramdiskId("ari-badbad00").rootDeviceType(RootDeviceType.INSTANCE_STORE) .build()), "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", null, "r-44a5402d")); @@ -123,7 +122,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest .instanceType(InstanceType.M1_SMALL).ipAddress("75.101.203.146").kernelId( "aki-a71cf9ce").keyName("adriancole.ec2ebs1").launchTime( dateService.iso8601DateParse("2009-12-30T04:06:23.000Z")).monitoringState( - MonitoringState.DISABLED).availabilityZone(AvailabilityZone.US_EAST_1B) + MonitoringState.DISABLED).availabilityZone("us-east-1b") .placementGroup("placement").virtualizationType("hvm").privateDnsName( "domU-12-31-39-09-CE-53.compute-1.internal").privateIpAddress( "10.210.209.157").ramdiskId("ari-a51cf9cc") diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java index 77cee3c388..c2e18320de 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/RunInstancesResponseHandlerTest.java @@ -29,7 +29,6 @@ import java.io.InputStream; import org.jclouds.aws.ec2.domain.AWSRunningInstance; import org.jclouds.aws.ec2.domain.MonitoringState; import org.jclouds.date.DateService; -import org.jclouds.ec2.domain.AvailabilityZone; import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.Reservation; @@ -86,19 +85,19 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { "ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING).instanceType( InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).monitoringState( - MonitoringState.ENABLED).availabilityZone(AvailabilityZone.US_EAST_1B).build(), + MonitoringState.ENABLED).availabilityZone("us-east-1b").build(), new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("1").imageId( "ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING).instanceType( InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).monitoringState( - MonitoringState.ENABLED).availabilityZone(AvailabilityZone.US_EAST_1B).build(), + MonitoringState.ENABLED).availabilityZone("us-east-1b").build(), new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("2").imageId( "ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING).instanceType( InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).monitoringState( - MonitoringState.ENABLED).availabilityZone(AvailabilityZone.US_EAST_1B).build()) + MonitoringState.ENABLED).availabilityZone("us-east-1b").build()) , "AIDADH4IGTRXXKCD", null, "r-47a5402e"); diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3PropertiesBuilder.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3PropertiesBuilder.java index 92a6232cc8..65818f3dad 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3PropertiesBuilder.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3PropertiesBuilder.java @@ -20,49 +20,36 @@ package org.jclouds.aws.s3; import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; -import static org.jclouds.aws.domain.Region.EU_WEST_1; -import static org.jclouds.aws.domain.Region.US_EAST_1; +import static org.jclouds.aws.domain.Region.US_STANDARD; import static org.jclouds.aws.domain.Region.US_WEST_1; import static org.jclouds.location.reference.LocationConstants.ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Properties; -import java.util.Set; import org.jclouds.aws.domain.Region; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; - /** * Builds properties used in S3 Clients * * @author Adrian Cole */ public class AWSS3PropertiesBuilder extends org.jclouds.s3.S3PropertiesBuilder { - public static Set DEFAULT_REGIONS = ImmutableSet.of(EU_WEST_1, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1); @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US,US-CA,IE,SG"); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_STANDARD, Region.US_WEST_1, "EU", - Region.AP_SOUTHEAST_1)); + properties.putAll(Region.regionPropertiesS3()); properties.setProperty(PROPERTY_ENDPOINT, "https://s3.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_STANDARD + "." + ENDPOINT, "https://s3.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_STANDARD + "." + ISO3166_CODES, "US"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + "." + ENDPOINT, - "https://s3-us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + "." + ISO3166_CODES, "US-CA"); + properties.setProperty(PROPERTY_REGION + "." + US_STANDARD + "." + ENDPOINT, "https://s3.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + "." + ENDPOINT, "https://s3-us-west-1.amazonaws.com"); properties.setProperty(PROPERTY_REGION + "." + "EU" + "." + ENDPOINT, "https://s3-eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + "EU" + "." + ISO3166_CODES, "IE"); - properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + "." + ENDPOINT, - "https://s3-ap-southeast-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + "." + ISO3166_CODES, "SG"); + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + "." + ENDPOINT, + "https://s3-ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + "." + ENDPOINT, + "https://s3-ap-northeast-1.amazonaws.com"); return properties; } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java index 465a46f522..0fa100c1c9 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java @@ -33,7 +33,7 @@ import com.google.common.collect.ImmutableSet; public class AWSS3ServiceIntegrationLiveTest extends S3ServiceIntegrationLiveTest { @Override protected Set getIso3166Codes() { - return ImmutableSet. of("US", "US-CA", "IE", "SG"); + return ImmutableSet. of("US", "US-CA", "IE", "SG", "JP-13"); } } diff --git a/sandbox-apis/cloudwatch/pom.xml b/sandbox-apis/cloudwatch/pom.xml index bc3511180e..68c47d5f40 100644 --- a/sandbox-apis/cloudwatch/pom.xml +++ b/sandbox-apis/cloudwatch/pom.xml @@ -61,6 +61,12 @@ ${project.version} test + + log4j + log4j + 1.2.16 + test + diff --git a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java b/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java index d6003d2b1d..5f56f9e95a 100644 --- a/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java +++ b/sandbox-apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java @@ -18,44 +18,43 @@ */ package org.jclouds.cloudwatch; + import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Properties; import org.jclouds.PropertiesBuilder; import org.jclouds.aws.domain.Region; -import com.google.common.base.Joiner; - /** * Builds properties used in Cloud Watch Clients * * @author Adrian Cole */ public class CloudWatchPropertiesBuilder extends PropertiesBuilder { + @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); properties.setProperty(PROPERTY_HEADER_TAG, "amz"); properties.setProperty(PROPERTY_API_VERSION, CloudWatchAsyncClient.VERSION); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_EAST_1, - Region.US_WEST_1, Region.EU_WEST_1, Region.AP_SOUTHEAST_1)); - properties.setProperty(PROPERTY_ENDPOINT, - "https://monitoring.us-east-1.amazonaws.com"); + properties.putAll(Region.regionProperties()); + properties.setProperty(PROPERTY_ENDPOINT, "https://monitoring.us-east-1.amazonaws.com"); properties.setProperty(PROPERTY_REGION + "." + Region.US_EAST_1 + ".endpoint", - "https://monitoring.us-east-1.amazonaws.com"); + "https://monitoring.us-east-1.amazonaws.com"); properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + ".endpoint", - "https://monitoring.us-west-1.amazonaws.com"); + "https://monitoring.us-west-1.amazonaws.com"); properties.setProperty(PROPERTY_REGION + "." + Region.EU_WEST_1 + ".endpoint", - "https://monitoring.eu-west-1.amazonaws.com"); + "https://monitoring.eu-west-1.amazonaws.com"); properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + ".endpoint", - "https://monitoring.ap-southeast-1.amazonaws.com"); + "https://monitoring.ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + Region.AP_NORTHEAST_1 + ".endpoint", + "https://monitoring.ap-northeast-1.amazonaws.com"); return properties; } diff --git a/sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java b/sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java index fac341ae11..dabb587ef8 100644 --- a/sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java +++ b/sandbox-apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java @@ -35,7 +35,6 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.google.inject.Module; /** @@ -57,10 +56,9 @@ public class CloudWatchClientLiveTest { protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); - apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint", null); + apiversion = System.getProperty("test." + provider + ".apiversion", null); } protected Properties setupProperties() { @@ -69,8 +67,10 @@ public class CloudWatchClientLiveTest { overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); overrides.setProperty(provider + ".identity", identity); overrides.setProperty(provider + ".credential", credential); - overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".apiversion", apiversion); + if (endpoint != null) + overrides.setProperty(provider + ".endpoint", endpoint); + if (apiversion != null) + overrides.setProperty(provider + ".apiversion", apiversion); return overrides; } @@ -79,7 +79,7 @@ public class CloudWatchClientLiveTest { setupCredentials(); Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); + overrides); client = context.getApi(); } @@ -87,8 +87,7 @@ public class CloudWatchClientLiveTest { void testGetMetricStatisticsInRegion() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, -1); - for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { + for (String region : Region.DEFAULT_REGIONS) { assert client.getMetricStatisticsInRegion(region, "CPUUtilization", cal.getTime(), new Date(), 60, "Average") != null; } } diff --git a/sandbox-apis/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java b/sandbox-apis/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java index 20a2b8bdf2..56f8234a0a 100644 --- a/sandbox-apis/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java +++ b/sandbox-apis/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java @@ -68,7 +68,7 @@ public class ELBAsyncClientTest extends RestClientTest { assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n"); assertPayloadEquals( request, - "Version=2010-07-01&Action=CreateLoadBalancer&Listeners.member.1.Protocol=http&LoadBalancerName=name&Listeners.member.1.InstancePort=80&Listeners.member.1.LoadBalancerPort=80", + "Version=2010-07-01&Action=CreateLoadBalancer&Listeners.member.1.Protocol=http&LoadBalancerName=name&Listeners.member.1.LoadBalancerPort=80&Listeners.member.1.InstancePort=80", "application/x-www-form-urlencoded", false); assertResponseParserClassEquals(method, request, ParseSax.class); @@ -180,9 +180,19 @@ public class ELBAsyncClientTest extends RestClientTest { protected String provider = "elb"; + @Override + protected Properties getProperties() { + Properties overrides = new Properties(); + overrides.setProperty(provider + ".endpoint", "https://elasticloadbalancing.us-east-1.amazonaws.com"); + overrides.setProperty(provider + ".propertiesbuilder", ELBPropertiesBuilder.class.getName()); + overrides.setProperty(provider + ".contextbuilder", ELBContextBuilder.class.getName()); + return overrides; + } + @Override public RestContextSpec createContextSpec() { - return new RestContextFactory().createContextSpec(provider, "identity", "credential", new Properties()); + return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", + new Properties()); } @Override diff --git a/sandbox-apis/elb/src/test/java/org/jclouds/elb/ProvidersInPropertiesTest.java b/sandbox-apis/elb/src/test/java/org/jclouds/elb/ProvidersInPropertiesTest.java deleted file mode 100644 index ae54198ecb..0000000000 --- a/sandbox-apis/elb/src/test/java/org/jclouds/elb/ProvidersInPropertiesTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - * 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.elb; - -import org.jclouds.rest.Providers; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - -/** - * - * @author Adrian Cole - * - */ -@Test(groups = "unit") -public class ProvidersInPropertiesTest { - - @Test - public void testSupportedProviders() { - Iterable providers = Providers.getSupportedProviders(); - assert Iterables.contains(providers, "elb") : providers; - } - -} diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java b/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java index dba702da45..471060ca58 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java +++ b/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java @@ -23,15 +23,10 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Properties; import org.jclouds.PropertiesBuilder; -import org.jclouds.aws.domain.Region; - -import com.google.common.base.Joiner; /** * Builds properties used in SQS Clients @@ -45,17 +40,7 @@ public class SQSPropertiesBuilder extends PropertiesBuilder { properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); properties.setProperty(PROPERTY_HEADER_TAG, "amz"); properties.setProperty(PROPERTY_API_VERSION, SQSAsyncClient.VERSION); - properties.setProperty(PROPERTY_REGIONS, - Joiner.on(',').join(Region.US_EAST_1, Region.US_WEST_1, Region.EU_WEST_1, Region.AP_SOUTHEAST_1)); properties.setProperty(PROPERTY_ENDPOINT, "https://sqs.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_EAST_1 + ".endpoint", - "https://sqs.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + ".endpoint", - "https://sqs.us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.EU_WEST_1 + ".endpoint", - "https://sqs.eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + ".endpoint", - "https://sqs.ap-southeast-1.amazonaws.com"); return properties; } diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java b/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java index 8e2cff6049..3ff143a9de 100644 --- a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java +++ b/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java @@ -19,8 +19,6 @@ package org.jclouds.sqs; -import static com.google.common.base.Predicates.equalTo; -import static com.google.common.base.Predicates.not; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -31,7 +29,6 @@ import java.util.Properties; import javax.inject.Named; import org.jclouds.Constants; -import org.jclouds.aws.domain.Region; import org.jclouds.aws.filters.FormSigner; import org.jclouds.date.DateService; import org.jclouds.http.HttpRequest; @@ -48,7 +45,6 @@ import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.sqs.xml.RegexQueueHandler; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; import com.google.inject.Module; import com.google.inject.TypeLiteral; @@ -145,14 +141,6 @@ public class SQSAsyncClientTest extends RestClientTest { checkFilters(request); } - public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array - .newInstance(CreateQueueOptions.class, 0).getClass()); - for (String region : Iterables.filter(Region.ALL_SQS, not(equalTo("us-standard")))) { - processor.createRequest(method, region, "queueName"); - } - } - @Override protected void checkFilters(HttpRequest request) { assertEquals(request.getFilters().size(), 1); @@ -172,9 +160,19 @@ public class SQSAsyncClientTest extends RestClientTest { protected String provider = "sqs"; + @Override + protected Properties getProperties() { + Properties overrides = new Properties(); + overrides.setProperty(provider + ".endpoint", "https://sqs.us-east-1.amazonaws.com"); + overrides.setProperty(provider + ".propertiesbuilder", SQSPropertiesBuilder.class.getName()); + overrides.setProperty(provider + ".contextbuilder", SQSContextBuilder.class.getName()); + return overrides; + } + @Override public RestContextSpec createContextSpec() { - return new RestContextFactory().createContextSpec(provider, "identity", "credential", new Properties()); + return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", + new Properties()); } } diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java b/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java index ec6fd38373..b949f3d6a4 100644 --- a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java +++ b/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java @@ -31,7 +31,6 @@ import java.util.SortedSet; import org.jclouds.Constants; import org.jclouds.aws.AWSResponseException; -import org.jclouds.aws.domain.Region; import org.jclouds.crypto.CryptoStreams; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; @@ -42,7 +41,6 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.inject.Module; @@ -97,60 +95,61 @@ public class SQSClientLiveTest { } @Test - void testListQueuesInRegion() throws InterruptedException { - for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { - SortedSet allResults = Sets.newTreeSet(client.listQueuesInRegion(region)); - assertNotNull(allResults); - if (allResults.size() >= 1) { - Queue queue = allResults.last(); - assertQueueInList(region, queue); - } + protected void testListQueues() throws InterruptedException { + listQueuesInRegion(null); + } + + protected void listQueuesInRegion(String region) throws InterruptedException { + SortedSet allResults = Sets.newTreeSet(client.listQueuesInRegion(region)); + assertNotNull(allResults); + if (allResults.size() >= 1) { + Queue queue = allResults.last(); + assertQueueInList(region, queue); } } public static final String PREFIX = System.getProperty("user.name") + "-sqs"; @Test - void testCreateQueue() throws InterruptedException { - String queueName = PREFIX + "1"; + protected void testCreateQueue() throws InterruptedException { + createQueueInRegion(null, PREFIX + "1"); + } - for (final String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { - try { - SortedSet result = Sets.newTreeSet(client.listQueuesInRegion(region, queuePrefix(queueName))); - if (result.size() >= 1) { - client.deleteQueue(result.last()); - queueName += 1;// cannot recreate a queue within 60 seconds - } - } catch (Exception e) { + public String createQueueInRegion(final String region, String queueName) throws InterruptedException { + try { + SortedSet result = Sets.newTreeSet(client.listQueuesInRegion(region, queuePrefix(queueName))); + if (result.size() >= 1) { + client.deleteQueue(result.last()); + queueName += 1;// cannot recreate a queue within 60 seconds + } + } catch (Exception e) { - } - Queue queue = null; - int tries = 0; - while (queue == null && tries < 5) { - try { - tries++; - queue = client.createQueueInRegion(region, queueName); - } catch (AWSResponseException e) { - queueName += "1"; - if (e.getError().getCode().equals("AWS.SimpleQueueService.QueueDeletedRecently"))// TODO - // retry - // handler - continue; - throw e; - } - } - if (region != null) - assertEquals(queue.getRegion(), region); - assertEquals(queue.getName(), queueName); - assertQueueInList(region, queue); - queues.add(queue); } + Queue queue = null; + int tries = 0; + while (queue == null && tries < 5) { + try { + tries++; + queue = client.createQueueInRegion(region, queueName); + } catch (AWSResponseException e) { + queueName += "1"; + if (e.getError().getCode().equals("AWS.SimpleQueueService.QueueDeletedRecently"))// TODO + // retry + // handler + continue; + throw e; + } + } + if (region != null) + assertEquals(queue.getRegion(), region); + assertEquals(queue.getName(), queueName); + assertQueueInList(region, queue); + queues.add(queue); + return queueName; } @Test(dependsOnMethods = "testCreateQueue") - void testSendMessage() throws InterruptedException, IOException { + protected void testSendMessage() throws InterruptedException, IOException { String message = "hardyharhar"; byte[] md5 = CryptoStreams.md5(message.getBytes()); for (Queue queue : queues) { diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/config/SQSRestClientModuleTest.java b/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/config/SQSRestClientModuleTest.java deleted file mode 100644 index 7874a12f37..0000000000 --- a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/config/SQSRestClientModuleTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * - * 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.sqs.config; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; -import java.util.Map; - -import org.jclouds.aws.domain.Region; -import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; -import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; -import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; -import org.jclouds.http.handlers.DelegatingErrorHandler; -import org.jclouds.http.handlers.DelegatingRetryHandler; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientTest.MockModule; -import org.jclouds.rest.RestContextFactory; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Module; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit") -public class SQSRestClientModuleTest { - - Injector createInjector() { - return new RestContextFactory().createContextBuilder("sqs", "uid", "key", - ImmutableSet. of(new MockModule(), new NullLoggingModule())).buildInjector(); - } - - @Test - void testServerErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); - } - - @Test - void testRegions() { - Map regionMap = createInjector().getInstance( - new Key>(org.jclouds.location.Region.class) { - }); - assertEquals(regionMap, ImmutableMap. of(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"), Region.EU_WEST_1, URI - .create("https://sqs.eu-west-1.amazonaws.com"), Region.AP_SOUTHEAST_1, URI - .create("https://sqs.ap-southeast-1.amazonaws.com"))); - } - - @Test - void testClientErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); - } - - @Test - void testClientRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getClientErrorRetryHandler().getClass(), - AWSClientErrorRetryHandler.class); - } - - @Test - void testRedirectionRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getRedirectionRetryHandler().getClass(), - AWSRedirectionRetryHandler.class); - } - -} diff --git a/sandbox-providers/aws-elb/pom.xml b/sandbox-providers/aws-elb/pom.xml index 8c3b4d6318..38209a0ded 100644 --- a/sandbox-providers/aws-elb/pom.xml +++ b/sandbox-providers/aws-elb/pom.xml @@ -74,6 +74,12 @@ test-jar test + + org.jclouds.provider + aws-ec2 + ${project.version} + test + org.jclouds.driver jclouds-log4j diff --git a/sandbox-providers/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBPropertiesBuilder.java b/sandbox-providers/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBPropertiesBuilder.java index 8a2c2c0c88..1ce6d255fe 100644 --- a/sandbox-providers/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBPropertiesBuilder.java +++ b/sandbox-providers/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBPropertiesBuilder.java @@ -21,6 +21,7 @@ package org.jclouds.aws.elb; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; import static org.jclouds.aws.domain.Region.EU_WEST_1; import static org.jclouds.aws.domain.Region.US_EAST_1; @@ -28,41 +29,37 @@ import static org.jclouds.aws.domain.Region.US_WEST_1; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_ZONECLIENT_ENDPOINT; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Properties; -import java.util.Set; import org.jclouds.aws.domain.Region; import org.jclouds.elb.ELBAsyncClient; import org.jclouds.elb.ELBPropertiesBuilder; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; - /** * Builds properties used in ELB Clients * * @author Adrian Cole */ public class AWSELBPropertiesBuilder extends ELBPropertiesBuilder { - public static Set DEFAULT_REGIONS = ImmutableSet.of(EU_WEST_1, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1); @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(DEFAULT_REGIONS)); + properties.putAll(Region.regionProperties()); properties.setProperty(PROPERTY_API_VERSION, ELBAsyncClient.VERSION); properties.setProperty(PROPERTY_ENDPOINT, "https://elasticloadbalancing.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_EAST_1 + ".endpoint", + properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + ".endpoint", "https://elasticloadbalancing.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + ".endpoint", + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + ".endpoint", "https://elasticloadbalancing.us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.EU_WEST_1 + ".endpoint", + properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + ".endpoint", "https://elasticloadbalancing.eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + ".endpoint", + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + ".endpoint", "https://elasticloadbalancing.ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + ".endpoint", + "https://elasticloadbalancing.ap-northeast-1.amazonaws.com"); properties.setProperty(PROPERTY_ZONECLIENT_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); return properties; } diff --git a/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java b/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java index 1fd4ffebd8..183bc242a7 100644 --- a/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java +++ b/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.aws.elb; +import org.jclouds.aws.domain.Region; import org.jclouds.elb.ELBClientLiveTest; import org.testng.annotations.Test; @@ -35,21 +36,21 @@ public class AWSELBClientLiveTest extends ELBClientLiveTest { @Test public void testCreateLoadBalancer() { - for (String region : AWSELBPropertiesBuilder.DEFAULT_REGIONS) { + for (String region : Region.DEFAULT_REGIONS) { createLoadBalancerInRegionZone(region, region + "a", name); } } @Test(dependsOnMethods = "testCreateLoadBalancer") public void testDescribeLoadBalancers() { - for (String region : AWSELBPropertiesBuilder.DEFAULT_REGIONS) { + for (String region : Region.DEFAULT_REGIONS) { describeLoadBalancerInRegion(region); } } @Test public void testDeleteLoadBalancer() { - for (String region : AWSELBPropertiesBuilder.DEFAULT_REGIONS) { + for (String region : Region.DEFAULT_REGIONS) { deleteLoadBalancerInRegion(region); } } diff --git a/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java b/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java index f2732b4857..1ef7e419c0 100644 --- a/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java +++ b/sandbox-providers/aws-elb/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java @@ -19,12 +19,13 @@ package org.jclouds.aws.elb; -import static org.jclouds.aws.elb.AWSELBPropertiesBuilder.DEFAULT_REGIONS; - import java.io.IOException; import java.lang.reflect.Method; +import java.util.Properties; +import org.jclouds.aws.domain.Region; import org.jclouds.elb.ELBAsyncClient; +import org.jclouds.rest.RestContextFactory; import org.testng.annotations.Test; /** @@ -40,9 +41,14 @@ public class ELBAsyncClientTest extends org.jclouds.elb.ELBAsyncClientTest { this.provider = "aws-elb"; } + @Override + protected Properties getProperties() { + return RestContextFactory.getPropertiesFromResource("/rest.properties"); + } + public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { Method method = ELBAsyncClient.class.getMethod("describeLoadBalancersInRegion", String.class, String[].class); - for (String region : DEFAULT_REGIONS) { + for (String region : Region.DEFAULT_REGIONS) { processor.createRequest(method, region); } } diff --git a/sandbox-providers/aws-simpledb/src/main/java/org/jclouds/aws/simpledb/SimpleDBPropertiesBuilder.java b/sandbox-providers/aws-simpledb/src/main/java/org/jclouds/aws/simpledb/AWSSimpleDBPropertiesBuilder.java similarity index 66% rename from sandbox-providers/aws-simpledb/src/main/java/org/jclouds/aws/simpledb/SimpleDBPropertiesBuilder.java rename to sandbox-providers/aws-simpledb/src/main/java/org/jclouds/aws/simpledb/AWSSimpleDBPropertiesBuilder.java index d483c004b1..9cf5c8fe99 100644 --- a/sandbox-providers/aws-simpledb/src/main/java/org/jclouds/aws/simpledb/SimpleDBPropertiesBuilder.java +++ b/sandbox-providers/aws-simpledb/src/main/java/org/jclouds/aws/simpledb/AWSSimpleDBPropertiesBuilder.java @@ -20,51 +20,49 @@ package org.jclouds.aws.simpledb; import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; import static org.jclouds.aws.domain.Region.EU_WEST_1; import static org.jclouds.aws.domain.Region.US_EAST_1; import static org.jclouds.aws.domain.Region.US_WEST_1; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Properties; -import java.util.Set; import org.jclouds.aws.domain.Region; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; - /** * Builds properties used in SimpleDB Clients * * @author Adrian Cole */ -public class SimpleDBPropertiesBuilder extends org.jclouds.simpledb.SimpleDBPropertiesBuilder { - public static Set DEFAULT_REGIONS = ImmutableSet.of(EU_WEST_1, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1); +public class AWSSimpleDBPropertiesBuilder extends org.jclouds.simpledb.SimpleDBPropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(DEFAULT_REGIONS)); + properties.putAll(Region.regionProperties()); + properties.setProperty(PROPERTY_ENDPOINT, "https://sdb.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_EAST_1 + ".endpoint", "https://sdb.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + ".endpoint", + properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + ".endpoint", "https://sdb.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + ".endpoint", "https://sdb.us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.EU_WEST_1 + ".endpoint", + properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + ".endpoint", "https://sdb.eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + ".endpoint", + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + ".endpoint", "https://sdb.ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + ".endpoint", + "https://sdb.ap-northeast-1.amazonaws.com"); return properties; } - public SimpleDBPropertiesBuilder() { + public AWSSimpleDBPropertiesBuilder() { super(); } - public SimpleDBPropertiesBuilder(Properties properties) { + public AWSSimpleDBPropertiesBuilder(Properties properties) { super(properties); } diff --git a/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/SimpleDBAsyncClientTest.java b/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/AWSSimpleDBAsyncClientTest.java similarity index 70% rename from sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/SimpleDBAsyncClientTest.java rename to sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/AWSSimpleDBAsyncClientTest.java index d466a26e77..b4a511df6f 100644 --- a/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/SimpleDBAsyncClientTest.java +++ b/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/AWSSimpleDBAsyncClientTest.java @@ -19,12 +19,14 @@ package org.jclouds.aws.simpledb; -import static org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder.DEFAULT_REGIONS; - import java.io.IOException; import java.lang.reflect.Method; +import java.util.Properties; +import org.jclouds.aws.domain.Region; +import org.jclouds.rest.RestContextFactory; import org.jclouds.simpledb.SimpleDBAsyncClient; +import org.jclouds.simpledb.SimpleDBAsyncClientTest; import org.testng.annotations.Test; /** @@ -34,17 +36,20 @@ import org.testng.annotations.Test; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "aws.SimpleDBAsyncClientTest") -public class SimpleDBAsyncClientTest extends org.jclouds.simpledb.SimpleDBAsyncClientTest { +public class AWSSimpleDBAsyncClientTest extends SimpleDBAsyncClientTest { - public SimpleDBAsyncClientTest() { + public AWSSimpleDBAsyncClientTest() { this.provider = "aws-simpledb"; } - // TODO fix this test as it has the wrong arg count - @Test(enabled = false) + @Override + protected Properties getProperties() { + return RestContextFactory.getPropertiesFromResource("/rest.properties"); + } + public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SimpleDBAsyncClient.class.getMethod("putAttributes", String.class, String.class); - for (String region : DEFAULT_REGIONS) { + Method method = SimpleDBAsyncClient.class.getMethod("createDomainInRegion", String.class, String.class); + for (String region : Region.DEFAULT_REGIONS) { processor.createRequest(method, region, "domainName"); } } diff --git a/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/AWSSimpleDBClientLiveTest.java b/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/AWSSimpleDBClientLiveTest.java index 93eba468ed..333c228b9e 100644 --- a/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/AWSSimpleDBClientLiveTest.java +++ b/sandbox-providers/aws-simpledb/src/test/java/org/jclouds/aws/simpledb/AWSSimpleDBClientLiveTest.java @@ -19,8 +19,7 @@ package org.jclouds.aws.simpledb; -import static org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder.DEFAULT_REGIONS; - +import org.jclouds.aws.domain.Region; import org.jclouds.simpledb.SimpleDBClientLiveTest; import org.testng.annotations.Test; @@ -36,7 +35,7 @@ public class AWSSimpleDBClientLiveTest extends SimpleDBClientLiveTest { } @Test void testListDomainsInRegion() throws InterruptedException { - for (String region : DEFAULT_REGIONS) { + for (String region : Region.DEFAULT_REGIONS) { listDomainInRegion(region); } } @@ -44,8 +43,7 @@ public class AWSSimpleDBClientLiveTest extends SimpleDBClientLiveTest { @Test void testCreateDomainInRegions() throws InterruptedException { String domainName = PREFIX + "1"; - - for (String region : DEFAULT_REGIONS) { + for (String region : Region.DEFAULT_REGIONS) { domainName = createDomainInRegion(region, domainName); } }