added new aws-simpledb provider

This commit is contained in:
Adrian Cole 2011-01-02 16:39:49 +01:00
parent 49cbf7a0a4
commit 2759da648d
9 changed files with 62 additions and 160 deletions

View File

@ -39,5 +39,10 @@
<artifactId>jclouds-allblobstore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>aws-simpledb</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -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<String> 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;
}

View File

@ -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<SimpleDBAsyncClient>
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 {

View File

@ -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<SimpleDBClient, SimpleDBAsyncClient> context;
private Set<String> domains = Sets.newHashSet();
protected Set<String> 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<String> 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<String> allResults = Sets.newTreeSet(client.listDomainsInRegion(region));
assertNotNull(allResults);
if (allResults.size() >= 1) {
String domain = allResults.last();
assertDomainInList(region, domain);
}
}
public static final String PREFIX = System.getProperty("user.name") + "-simpledb";
@Test
void testCreateDomain() throws InterruptedException {
String domainName = PREFIX + "1";
for (String region : DEFAULT_REGIONS) {
try {
SortedSet<String> result = Sets.newTreeSet(client.listDomainsInRegion(region));
if (result.size() >= 1) {
client.deleteDomainInRegion(region, result.last());
domainName += 1;// cannot recreate a domain within 60 seconds
}
} catch (Exception e) {
protected String createDomainInRegion(String region, String domainName) throws InterruptedException {
try {
SortedSet<String> result = Sets.newTreeSet(client.listDomainsInRegion(region));
if (result.size() >= 1) {
client.deleteDomainInRegion(region, result.last());
domainName += 1;// cannot recreate a domain within 60 seconds
}
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);

View File

@ -1,93 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testRegions() {
Map<String, URI> regionMap = createInjector().getInstance(
new Key<Map<String, URI>>(org.jclouds.location.Region.class) {
});
assertEquals(regionMap, ImmutableMap.<String, URI> of(Region.US_EAST_1, URI
.create("https://sdb.amazonaws.com"), Region.US_WEST_1, URI
.create("https://sdb.us-west-1.amazonaws.com"), Region.EU_WEST_1, URI
.create("https://sdb.eu-west-1.amazonaws.com"), Region.AP_SOUTHEAST_1, URI
.create("https://sdb.ap-southeast-1.amazonaws.com")));
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AWSClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(),
AWSRedirectionRetryHandler.class);
}
}

View File

@ -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<Object, URI> {
private final URI defaultUri;
private final Map<String, URI> regionToEndpoint;
private final String defaultProvider;
@Inject(optional = true)
@Region
Map<String, URI> regionToEndpoint;
@Inject
public RegionToEndpointOrProviderIfNull(@Provider URI defaultUri, @Region Map<String, URI> 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);
}
}

View File

@ -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

View File

@ -66,7 +66,7 @@ public class SyncProxyTest {
String take100MillisecondsAndTimeout();
@Timeout(duration = 150, timeUnit = TimeUnit.MILLISECONDS)
@Timeout(duration = 300, timeUnit = TimeUnit.MILLISECONDS)
String take100MillisecondsAndOverride();
}

View File

@ -36,5 +36,6 @@
<module>gogrid</module>
<module>slicehost</module>
<module>cloudsigma</module>
<module>aws-simpledb</module>
</modules>
</project>