From 66c1b593b994c929fb27e4a8c5317bcbafc48835 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Fri, 25 Sep 2009 00:38:40 +0000 Subject: [PATCH] Issue 95: factories that support alternate endpoints git-svn-id: http://jclouds.googlecode.com/svn/trunk@1921 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../org/jclouds/aws/s3/S3ContextFactory.java | 7 ++++ .../storage/blob/AzureBlobContextFactory.java | 35 +++++++++++++++++++ .../storage/blob/AzureBlobStoreLiveTest.java | 6 ++-- .../queue/AzureQueueContextFactory.java | 35 +++++++++++++++++++ .../CloudFilesCDNContextFactory.java | 34 ++++++++++++++++++ .../cloudfiles/CloudFilesContextFactory.java | 35 +++++++++++++++++++ .../domain/ContainerCDNMetadata.java | 4 +-- .../ParseContainerCDNMetadataFromHeaders.java | 5 ++- .../CloudFilesBlobStoreLiveTest.java | 4 +-- .../CloudFilesCDNConnectionLiveTest.java | 25 ++++++++----- .../CloudServersContextFactory.java | 34 ++++++++++++++++++ .../CloudServersConnectionLiveTest.java | 11 +++--- 12 files changed, 211 insertions(+), 24 deletions(-) create mode 100644 azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextFactory.java create mode 100644 azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextFactory.java create mode 100644 rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNContextFactory.java create mode 100644 rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextFactory.java create mode 100644 rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextFactory.java diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextFactory.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextFactory.java index 1c6cef238e..b483a7c1ef 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextFactory.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextFactory.java @@ -23,6 +23,8 @@ */ package org.jclouds.aws.s3; +import java.net.URI; + import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; @@ -48,4 +50,9 @@ public class S3ContextFactory { .buildContext(); } + public static S3Context createS3Context(URI endpoint, String awsAccessKeyId, + String awsSecretAccessKey, Module... modules) { + return S3ContextBuilder.newBuilder(awsAccessKeyId, awsSecretAccessKey).withEndpoint(endpoint) + .withModules(modules).buildContext(); + } } diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextFactory.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextFactory.java new file mode 100644 index 0000000000..9f66d6f237 --- /dev/null +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextFactory.java @@ -0,0 +1,35 @@ +package org.jclouds.azure.storage.blob; + +import java.net.URI; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; + +import com.google.inject.Module; + +/** + * Creates {@link AzureBlobContext} instances based on the most commonly requested arguments. + *

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

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole, Andrew Newdigate + * @see AzureBlobContext + */ +public class AzureBlobContextFactory { + + public static AzureBlobContext createAzureBlobContext(String account, String encodedKey, + Module... modules) { + return AzureBlobContextBuilder.newBuilder(account, encodedKey).withModules(modules) + .buildContext(); + } + + public static AzureBlobContext createAzureBlobContext(URI endpoint, String account, + String encodedKey, Module... modules) { + return AzureBlobContextBuilder.newBuilder(account, encodedKey).withEndpoint(endpoint) + .withModules(modules).buildContext(); + } +} diff --git a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreLiveTest.java b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreLiveTest.java index 63f4b3a098..ec40edbd84 100644 --- a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreLiveTest.java +++ b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreLiveTest.java @@ -55,7 +55,6 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Iterables; -import com.google.inject.Injector; /** * Tests behavior of {@code AzureBlobConnection} @@ -73,9 +72,8 @@ public class AzureBlobStoreLiveTest { public void setupConnection() { account = System.getProperty("jclouds.test.user"); String key = System.getProperty("jclouds.test.key"); - Injector injector = AzureBlobContextBuilder.newBuilder(account, key).withModules( - new Log4JLoggingModule()).withSaxDebug().buildInjector(); - connection = injector.getInstance(AzureBlobStore.class); + connection = AzureBlobContextFactory.createAzureBlobContext(account, key, + new Log4JLoggingModule()).getApi(); } @Test diff --git a/azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextFactory.java b/azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextFactory.java new file mode 100644 index 0000000000..aa5d92f193 --- /dev/null +++ b/azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextFactory.java @@ -0,0 +1,35 @@ +package org.jclouds.azure.storage.queue; + +import java.net.URI; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; + +import com.google.inject.Module; + +/** + * Creates {@link AzureQueueContext} instances based on the most commonly requested arguments. + *

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

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole, Andrew Newdigate + * @see AzureQueueContext + */ +public class AzureQueueContextFactory { + + public static AzureQueueContext createAzureQueueContext(String account, String encodedKey, + Module... modules) { + return AzureQueueContextBuilder.newBuilder(account, encodedKey).withModules(modules) + .buildContext(); + } + + public static AzureQueueContext createAzureQueueContext(URI endpoint, String account, + String encodedKey, Module... modules) { + return AzureQueueContextBuilder.newBuilder(account, encodedKey).withEndpoint(endpoint) + .withModules(modules).buildContext(); + } +} diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNContextFactory.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNContextFactory.java new file mode 100644 index 0000000000..2390bb260f --- /dev/null +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNContextFactory.java @@ -0,0 +1,34 @@ +package org.jclouds.rackspace.cloudfiles; + +import java.net.URI; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; + +import com.google.inject.Module; + +/** + * Creates {@link CloudFilesCDNContext} instances based on the most commonly requested arguments. + *

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

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole, Andrew Newdigate + * @see CloudFilesCDNContext + */ +public class CloudFilesCDNContextFactory { + + public static CloudFilesCDNContext createCloudFilesCDNContext(String user, String key, + Module... modules) { + return CloudFilesCDNContextBuilder.newBuilder(user, key).withModules(modules).buildContext(); + } + + public static CloudFilesCDNContext createCloudFilesCDNContext(URI endpoint, String user, + String key, Module... modules) { + return CloudFilesCDNContextBuilder.newBuilder(user, key).withEndpoint(endpoint).withModules( + modules).buildContext(); + } +} diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextFactory.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextFactory.java new file mode 100644 index 0000000000..b080da338e --- /dev/null +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextFactory.java @@ -0,0 +1,35 @@ +package org.jclouds.rackspace.cloudfiles; + +import java.net.URI; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; + +import com.google.inject.Module; + +/** + * Creates {@link CloudFilesContext} instances based on the most commonly requested arguments. + *

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

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole, Andrew Newdigate + * @see CloudFilesContext + */ +public class CloudFilesContextFactory { + + public static CloudFilesContext createCloudFilesContext(String user, String key, + Module... modules) { + return CloudFilesContextBuilder.newBuilder(user, key).withModules(modules) + .buildContext(); + } + + public static CloudFilesContext createCloudFilesContext(URI endpoint, String user, + String key, Module... modules) { + return CloudFilesContextBuilder.newBuilder(user, key).withEndpoint(endpoint) + .withModules(modules).buildContext(); + } +} diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/domain/ContainerCDNMetadata.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/domain/ContainerCDNMetadata.java index 86ade7b0d6..4728ba5627 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/domain/ContainerCDNMetadata.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/domain/ContainerCDNMetadata.java @@ -34,8 +34,8 @@ public class ContainerCDNMetadata extends org.jclouds.blobstore.domain.Container private boolean cdn_enabled; private String cdn_uri; - public ContainerCDNMetadata(String name, boolean cdnEnabled, long ttl, String cdnUri) { - super(name); + public ContainerCDNMetadata(boolean cdnEnabled, long ttl, String cdnUri) { + super(); this.cdn_enabled = cdnEnabled; this.ttl = ttl; this.cdn_uri = cdnUri; diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java index 4c3a5705d9..b0345e204c 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java @@ -45,7 +45,6 @@ public class ParseContainerCDNMetadataFromHeaders implements */ public ContainerCDNMetadata apply(final HttpResponse from) { // TODO: The container name is not returned as a header, hopefully one day it will be - String containerName = null; String cdnUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_URI), CloudFilesHeaders.CDN_URI); @@ -57,8 +56,8 @@ public class ParseContainerCDNMetadataFromHeaders implements // CDN is not, and has never, been enabled for this container. return null; } else { - return new ContainerCDNMetadata(containerName, Boolean.parseBoolean(cdnEnabled), Long - .parseLong(cdnTTL), cdnUri); + return new ContainerCDNMetadata(Boolean.parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), + cdnUri); } } } \ No newline at end of file diff --git a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesBlobStoreLiveTest.java b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesBlobStoreLiveTest.java index 15d975ab1d..4f13e0e83a 100644 --- a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesBlobStoreLiveTest.java +++ b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesBlobStoreLiveTest.java @@ -66,8 +66,8 @@ public class CloudFilesBlobStoreLiveTest { public void setupConnection() { String account = System.getProperty("jclouds.test.user"); String key = System.getProperty("jclouds.test.key"); - connection = CloudFilesContextBuilder.newBuilder(account, key).withModule( - new Log4JLoggingModule()).withJsonDebug().buildContext().getApi(); + connection = CloudFilesContextFactory.createCloudFilesContext(account, key, + new Log4JLoggingModule()).getApi(); } @Test diff --git a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNConnectionLiveTest.java b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNConnectionLiveTest.java index a3c14b83fc..bc4a07091d 100644 --- a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNConnectionLiveTest.java +++ b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesCDNConnectionLiveTest.java @@ -29,6 +29,7 @@ import static org.testng.Assert.assertTrue; import java.util.List; import java.util.concurrent.TimeUnit; +import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions; @@ -55,10 +56,10 @@ public class CloudFilesCDNConnectionLiveTest { String account = System.getProperty("jclouds.test.user"); String key = System.getProperty("jclouds.test.key"); - cdnConnection = CloudFilesCDNContextBuilder.newBuilder(account, key).withModule( - new Log4JLoggingModule()).withJsonDebug().buildContext().getApi(); - filesConnection = CloudFilesContextBuilder.newBuilder(account, key).withModule( - new Log4JLoggingModule()).withJsonDebug().buildContext().getApi(); + cdnConnection = CloudFilesCDNContextFactory.createCloudFilesCDNContext(account, key, + new Log4JLoggingModule()).getApi(); + filesConnection = CloudFilesContextFactory.createCloudFilesContext(account, key, + new Log4JLoggingModule()).getApi(); } @Test @@ -84,11 +85,17 @@ public class CloudFilesCDNConnectionLiveTest { assertEquals(cdnMetadata.getCdnUri(), cdnUri); final long initialTTL = cdnMetadata.getTtl(); - // Check HEAD responses for non-existent container, and container with no CDN metadata - cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithoutCDN); - assertEquals(cdnMetadata, null); - cdnMetadata = cdnConnection.getCDNMetadata("DoesNotExist"); - assertEquals(cdnMetadata, null); + try { + cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithoutCDN); + assert false : "should not exist"; + } catch (ContainerNotFoundException e) { + } + + try { + cdnMetadata = cdnConnection.getCDNMetadata("DoesNotExist"); + assert false : "should not exist"; + } catch (ContainerNotFoundException e) { + } // List CDN metadata for containers, and ensure all CDN info is available for enabled // container diff --git a/rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextFactory.java b/rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextFactory.java new file mode 100644 index 0000000000..9877a49234 --- /dev/null +++ b/rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextFactory.java @@ -0,0 +1,34 @@ +package org.jclouds.rackspace.cloudservers; + +import java.net.URI; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; + +import com.google.inject.Module; + +/** + * Creates {@link CloudServersContext} instances based on the most commonly requested arguments. + *

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

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole, Andrew Newdigate + * @see CloudServersContext + */ +public class CloudServersContextFactory { + + public static CloudServersContext createCloudServersContext(String user, String key, + Module... modules) { + return CloudServersContextBuilder.newBuilder(user, key).withModules(modules).buildContext(); + } + + public static CloudServersContext createCloudServersContext(URI endpoint, String user, + String key, Module... modules) { + return CloudServersContextBuilder.newBuilder(user, key).withEndpoint(endpoint).withModules( + modules).buildContext(); + } +} diff --git a/rackspace/cloudservers/core/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersConnectionLiveTest.java b/rackspace/cloudservers/core/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersConnectionLiveTest.java index 48f78ee4d6..8fda93644f 100755 --- a/rackspace/cloudservers/core/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersConnectionLiveTest.java +++ b/rackspace/cloudservers/core/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersConnectionLiveTest.java @@ -60,6 +60,7 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; +import com.google.inject.Guice; import com.google.inject.Injector; /** @@ -78,10 +79,12 @@ public class CloudServersConnectionLiveTest { String account = System.getProperty("jclouds.test.user"); String key = System.getProperty("jclouds.test.key"); - Injector injector = CloudServersContextBuilder.newBuilder(account, key).withModules( - new Log4JLoggingModule(), new JschSshConnectionModule()).withJsonDebug() - .buildInjector(); - connection = injector.getInstance(CloudServersConnection.class); + connection = CloudServersContextFactory.createCloudServersContext(account, key, + new Log4JLoggingModule()).getApi(); + + Injector injector = Guice.createInjector(new Log4JLoggingModule(), + new JschSshConnectionModule()); + sshFactory = injector.getInstance(SshConnection.Factory.class); }