diff --git a/all/pom.xml b/all/pom.xml index 51f0aab3ea..d95e9bb766 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -39,5 +39,10 @@ jclouds-allblobstore ${project.version} + + org.jclouds.provider + aws-simpledb + ${project.version} + diff --git a/apis/simpledb/src/main/java/org/jclouds/simpledb/SimpleDBPropertiesBuilder.java b/apis/simpledb/src/main/java/org/jclouds/simpledb/SimpleDBPropertiesBuilder.java index 1daf492d9f..2b3b52405e 100644 --- a/apis/simpledb/src/main/java/org/jclouds/simpledb/SimpleDBPropertiesBuilder.java +++ b/apis/simpledb/src/main/java/org/jclouds/simpledb/SimpleDBPropertiesBuilder.java @@ -21,29 +21,19 @@ package org.jclouds.simpledb; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; -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.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS; import java.util.Properties; -import java.util.Set; import org.jclouds.PropertiesBuilder; -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 PropertiesBuilder { - public static Set DEFAULT_REGIONS = ImmutableSet.of(EU_WEST_1, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1); @Override protected Properties defaultProperties() { @@ -51,12 +41,7 @@ public class SimpleDBPropertiesBuilder extends PropertiesBuilder { properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); properties.setProperty(PROPERTY_HEADER_TAG, "amz"); properties.setProperty(PROPERTY_API_VERSION, SimpleDBAsyncClient.VERSION); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(DEFAULT_REGIONS)); properties.setProperty(PROPERTY_ENDPOINT, "https://sdb.amazonaws.com"); - properties.setProperty(PROPERTY_ENDPOINT + "." + US_EAST_1, "https://sdb.amazonaws.com"); - properties.setProperty(PROPERTY_ENDPOINT + "." + US_WEST_1, "https://sdb.us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_ENDPOINT + "." + EU_WEST_1, "https://sdb.eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_ENDPOINT + "." + AP_SOUTHEAST_1, "https://sdb.ap-southeast-1.amazonaws.com"); return properties; } diff --git a/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBAsyncClientTest.java b/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBAsyncClientTest.java index 6ba7737bea..e35113614c 100644 --- a/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBAsyncClientTest.java +++ b/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBAsyncClientTest.java @@ -19,7 +19,6 @@ package org.jclouds.simpledb; -import static org.jclouds.simpledb.SimpleDBPropertiesBuilder.DEFAULT_REGIONS; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -96,15 +95,6 @@ public class SimpleDBAsyncClientTest extends RestClientTest checkFilters(request); } - // TODO fix this test as it has the wrong arg count - @Test(enabled = false) - public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SimpleDBAsyncClient.class.getMethod("putAttributes", String.class, String.class); - for (String region : DEFAULT_REGIONS) { - processor.createRequest(method, region, "domainName"); - } - } - // TODO fix this test as it has the wrong arg type @Test(enabled = false) public void testPutAttributes() throws SecurityException, NoSuchMethodException, IOException { diff --git a/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBClientLiveTest.java b/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBClientLiveTest.java index 7f4abd1490..0860fb915d 100644 --- a/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBClientLiveTest.java +++ b/apis/simpledb/src/test/java/org/jclouds/simpledb/SimpleDBClientLiveTest.java @@ -20,7 +20,6 @@ package org.jclouds.simpledb; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.simpledb.SimpleDBPropertiesBuilder.DEFAULT_REGIONS; import static org.testng.Assert.assertNotNull; import java.util.Properties; @@ -28,7 +27,6 @@ import java.util.Set; import java.util.SortedSet; import org.jclouds.Constants; -import org.jclouds.aws.domain.Region; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; @@ -38,7 +36,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; @@ -50,11 +47,11 @@ import com.google.inject.Module; @Test(groups = "live", sequential = true) public class SimpleDBClientLiveTest { - private SimpleDBClient client; + protected SimpleDBClient client; private RestContext context; - private Set domains = Sets.newHashSet(); + protected Set domains = Sets.newHashSet(); protected String provider = "simpledb"; protected String identity; protected String credential; @@ -93,47 +90,49 @@ public class SimpleDBClientLiveTest { } @Test - void testListDomainsInRegion() throws InterruptedException { - for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, Region.US_WEST_1, - Region.AP_SOUTHEAST_1)) { - SortedSet allResults = Sets.newTreeSet(client.listDomainsInRegion(region)); - assertNotNull(allResults); - if (allResults.size() >= 1) { - String domain = allResults.last(); - assertDomainInList(region, domain); - } + protected void testListDomains() throws InterruptedException { + listDomainInRegion(null); + } + + protected void listDomainInRegion(String region) throws InterruptedException { + SortedSet allResults = Sets.newTreeSet(client.listDomainsInRegion(region)); + assertNotNull(allResults); + if (allResults.size() >= 1) { + String domain = allResults.last(); + assertDomainInList(region, domain); } } public static final String PREFIX = System.getProperty("user.name") + "-simpledb"; - @Test - void testCreateDomain() throws InterruptedException { - String domainName = PREFIX + "1"; - - for (String region : DEFAULT_REGIONS) { - try { - SortedSet result = Sets.newTreeSet(client.listDomainsInRegion(region)); - if (result.size() >= 1) { - client.deleteDomainInRegion(region, result.last()); - domainName += 1;// cannot recreate a domain within 60 seconds - } - } catch (Exception e) { - + protected String createDomainInRegion(String region, String domainName) throws InterruptedException { + try { + SortedSet result = Sets.newTreeSet(client.listDomainsInRegion(region)); + if (result.size() >= 1) { + client.deleteDomainInRegion(region, result.last()); + domainName += 1;// cannot recreate a domain within 60 seconds } - client.createDomainInRegion(region, domainName); + } catch (Exception e) { - // TODO get the domain metadata and ensure the region is correct - - // if (region != null) - // assertEquals(domain.getRegion(), region); - // assertEquals(domain.getName(), domainName); - assertDomainInList(region, domainName); - domains.add(domainName); } + client.createDomainInRegion(region, domainName); + + // TODO get the domain metadata and ensure the region is correct + + // if (region != null) + // assertEquals(domain.getRegion(), region); + // assertEquals(domain.getName(), domainName); + assertDomainInList(region, domainName); + domains.add(domainName); + return domainName; } - private void assertDomainInList(final String region, final String domain) throws InterruptedException { + @Test + protected void testCreateDomain() throws InterruptedException { + createDomainInRegion(null, PREFIX + "1"); + } + + protected void assertDomainInList(final String region, final String domain) throws InterruptedException { assertEventually(new Runnable() { public void run() { ListDomainsResponse domains = client.listDomainsInRegion(region); diff --git a/apis/simpledb/src/test/java/org/jclouds/simpledb/config/SimpleDBRestClientModuleTest.java b/apis/simpledb/src/test/java/org/jclouds/simpledb/config/SimpleDBRestClientModuleTest.java deleted file mode 100644 index a760fb75ec..0000000000 --- a/apis/simpledb/src/test/java/org/jclouds/simpledb/config/SimpleDBRestClientModuleTest.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.simpledb.config; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; -import java.util.Map; - -import org.jclouds.aws.domain.Region; -import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; -import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; -import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; -import org.jclouds.http.handlers.DelegatingErrorHandler; -import org.jclouds.http.handlers.DelegatingRetryHandler; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.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 SimpleDBRestClientModuleTest { - - Injector createInjector() { - return new RestContextFactory().createContextBuilder("simpledb", "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://sdb.amazonaws.com"), Region.US_WEST_1, URI - .create("https://sdb.us-west-1.amazonaws.com"), Region.EU_WEST_1, URI - .create("https://sdb.eu-west-1.amazonaws.com"), Region.AP_SOUTHEAST_1, URI - .create("https://sdb.ap-southeast-1.amazonaws.com"))); - } - - @Test - void testClientErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); - } - - @Test - void testClientRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getClientErrorRetryHandler().getClass(), - AWSClientErrorRetryHandler.class); - } - - @Test - void testRedirectionRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getRedirectionRetryHandler().getClass(), - AWSRedirectionRetryHandler.class); - } - -} diff --git a/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java b/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java index 1a5bd6ca40..a9078cda86 100644 --- a/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java +++ b/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java @@ -19,38 +19,50 @@ package org.jclouds.location.functions; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; import java.net.URI; import java.util.Map; import javax.annotation.Nullable; -import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.location.Provider; import org.jclouds.location.Region; import com.google.common.base.Function; +import com.google.inject.Inject; /** + * If a mapping of regions to endpoints exists, return a corresponding * * @author Adrian Cole */ @Singleton public class RegionToEndpointOrProviderIfNull implements Function { private final URI defaultUri; - private final Map regionToEndpoint; + private final String defaultProvider; + + @Inject(optional = true) + @Region + Map regionToEndpoint; @Inject - public RegionToEndpointOrProviderIfNull(@Provider URI defaultUri, @Region Map regionToEndpoint) { + public RegionToEndpointOrProviderIfNull(@Provider URI defaultUri, @Provider String defaultProvider) { this.defaultUri = checkNotNull(defaultUri, "defaultUri"); - this.regionToEndpoint = checkNotNull(regionToEndpoint, "regionToEndpoint"); + this.defaultProvider = checkNotNull(defaultProvider, "defaultProvider"); } @Override public URI apply(@Nullable Object from) { - return from == null ? defaultUri : regionToEndpoint.get(from); + checkState(from == null || from.equals(defaultProvider) || regionToEndpoint != null, "requested location " + from + + ", but only the default location " + defaultProvider + " is configured"); + checkArgument(from == null || from.equals(defaultProvider) || regionToEndpoint.containsKey(from), + "requested location " + from + ", which is not in the configured locations: " + regionToEndpoint.keySet()); + + return from == null || from.equals(defaultProvider) ? defaultUri : regionToEndpoint.get(from); } } \ No newline at end of file diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index e5a2c3880c..406e5ca3a0 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -38,6 +38,9 @@ sqs.propertiesbuilder=org.jclouds.aws.sqs.SQSPropertiesBuilder simpledb.contextbuilder=org.jclouds.simpledb.SimpleDBContextBuilder simpledb.propertiesbuilder=org.jclouds.simpledb.SimpleDBPropertiesBuilder +aws-simpledb.contextbuilder=org.jclouds.simpledb.SimpleDBContextBuilder +aws-simpledb..propertiesbuilder=org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder + elb.contextbuilder=org.jclouds.aws.elb.ELBContextBuilder elb.propertiesbuilder=org.jclouds.aws.elb.ELBPropertiesBuilder diff --git a/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java b/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java index 43428828f2..30f5e96f19 100644 --- a/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java +++ b/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java @@ -66,7 +66,7 @@ public class SyncProxyTest { String take100MillisecondsAndTimeout(); - @Timeout(duration = 150, timeUnit = TimeUnit.MILLISECONDS) + @Timeout(duration = 300, timeUnit = TimeUnit.MILLISECONDS) String take100MillisecondsAndOverride(); } diff --git a/providers/pom.xml b/providers/pom.xml index af8b61dd27..6d7d52c475 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -36,5 +36,6 @@ gogrid slicehost cloudsigma + aws-simpledb