Issue 95: factories that support alternate endpoints

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1921 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-09-25 00:38:40 +00:00
parent 7a83144421
commit 66c1b593b9
12 changed files with 211 additions and 24 deletions

View File

@ -23,6 +23,8 @@
*/ */
package org.jclouds.aws.s3; package org.jclouds.aws.s3;
import java.net.URI;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.logging.jdk.config.JDKLoggingModule;
@ -48,4 +50,9 @@ public class S3ContextFactory {
.buildContext(); .buildContext();
} }
public static S3Context createS3Context(URI endpoint, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return S3ContextBuilder.newBuilder(awsAccessKeyId, awsSecretAccessKey).withEndpoint(endpoint)
.withModules(modules).buildContext();
}
} }

View File

@ -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.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s 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();
}
}

View File

@ -55,7 +55,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Injector;
/** /**
* Tests behavior of {@code AzureBlobConnection} * Tests behavior of {@code AzureBlobConnection}
@ -73,9 +72,8 @@ public class AzureBlobStoreLiveTest {
public void setupConnection() { public void setupConnection() {
account = System.getProperty("jclouds.test.user"); account = System.getProperty("jclouds.test.user");
String key = System.getProperty("jclouds.test.key"); String key = System.getProperty("jclouds.test.key");
Injector injector = AzureBlobContextBuilder.newBuilder(account, key).withModules( connection = AzureBlobContextFactory.createAzureBlobContext(account, key,
new Log4JLoggingModule()).withSaxDebug().buildInjector(); new Log4JLoggingModule()).getApi();
connection = injector.getInstance(AzureBlobStore.class);
} }
@Test @Test

View File

@ -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.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s 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();
}
}

View File

@ -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.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s 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();
}
}

View File

@ -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.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s 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();
}
}

View File

@ -34,8 +34,8 @@ public class ContainerCDNMetadata extends org.jclouds.blobstore.domain.Container
private boolean cdn_enabled; private boolean cdn_enabled;
private String cdn_uri; private String cdn_uri;
public ContainerCDNMetadata(String name, boolean cdnEnabled, long ttl, String cdnUri) { public ContainerCDNMetadata(boolean cdnEnabled, long ttl, String cdnUri) {
super(name); super();
this.cdn_enabled = cdnEnabled; this.cdn_enabled = cdnEnabled;
this.ttl = ttl; this.ttl = ttl;
this.cdn_uri = cdnUri; this.cdn_uri = cdnUri;

View File

@ -45,7 +45,6 @@ public class ParseContainerCDNMetadataFromHeaders implements
*/ */
public ContainerCDNMetadata apply(final HttpResponse from) { public ContainerCDNMetadata apply(final HttpResponse from) {
// TODO: The container name is not returned as a header, hopefully one day it will be // 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), String cdnUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_URI),
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. // CDN is not, and has never, been enabled for this container.
return null; return null;
} else { } else {
return new ContainerCDNMetadata(containerName, Boolean.parseBoolean(cdnEnabled), Long return new ContainerCDNMetadata(Boolean.parseBoolean(cdnEnabled), Long.parseLong(cdnTTL),
.parseLong(cdnTTL), cdnUri); cdnUri);
} }
} }
} }

View File

@ -66,8 +66,8 @@ public class CloudFilesBlobStoreLiveTest {
public void setupConnection() { public void setupConnection() {
String account = System.getProperty("jclouds.test.user"); String account = System.getProperty("jclouds.test.user");
String key = System.getProperty("jclouds.test.key"); String key = System.getProperty("jclouds.test.key");
connection = CloudFilesContextBuilder.newBuilder(account, key).withModule( connection = CloudFilesContextFactory.createCloudFilesContext(account, key,
new Log4JLoggingModule()).withJsonDebug().buildContext().getApi(); new Log4JLoggingModule()).getApi();
} }
@Test @Test

View File

@ -29,6 +29,7 @@ import static org.testng.Assert.assertTrue;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.blobstore.ContainerNotFoundException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions; import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
@ -55,10 +56,10 @@ public class CloudFilesCDNConnectionLiveTest {
String account = System.getProperty("jclouds.test.user"); String account = System.getProperty("jclouds.test.user");
String key = System.getProperty("jclouds.test.key"); String key = System.getProperty("jclouds.test.key");
cdnConnection = CloudFilesCDNContextBuilder.newBuilder(account, key).withModule( cdnConnection = CloudFilesCDNContextFactory.createCloudFilesCDNContext(account, key,
new Log4JLoggingModule()).withJsonDebug().buildContext().getApi(); new Log4JLoggingModule()).getApi();
filesConnection = CloudFilesContextBuilder.newBuilder(account, key).withModule( filesConnection = CloudFilesContextFactory.createCloudFilesContext(account, key,
new Log4JLoggingModule()).withJsonDebug().buildContext().getApi(); new Log4JLoggingModule()).getApi();
} }
@Test @Test
@ -84,11 +85,17 @@ public class CloudFilesCDNConnectionLiveTest {
assertEquals(cdnMetadata.getCdnUri(), cdnUri); assertEquals(cdnMetadata.getCdnUri(), cdnUri);
final long initialTTL = cdnMetadata.getTtl(); final long initialTTL = cdnMetadata.getTtl();
// Check HEAD responses for non-existent container, and container with no CDN metadata try {
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithoutCDN); cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithoutCDN);
assertEquals(cdnMetadata, null); assert false : "should not exist";
cdnMetadata = cdnConnection.getCDNMetadata("DoesNotExist"); } catch (ContainerNotFoundException e) {
assertEquals(cdnMetadata, null); }
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 // List CDN metadata for containers, and ensure all CDN info is available for enabled
// container // container

View File

@ -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.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s 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();
}
}

View File

@ -60,6 +60,7 @@ import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
@ -78,10 +79,12 @@ public class CloudServersConnectionLiveTest {
String account = System.getProperty("jclouds.test.user"); String account = System.getProperty("jclouds.test.user");
String key = System.getProperty("jclouds.test.key"); String key = System.getProperty("jclouds.test.key");
Injector injector = CloudServersContextBuilder.newBuilder(account, key).withModules( connection = CloudServersContextFactory.createCloudServersContext(account, key,
new Log4JLoggingModule(), new JschSshConnectionModule()).withJsonDebug() new Log4JLoggingModule()).getApi();
.buildInjector();
connection = injector.getInstance(CloudServersConnection.class); Injector injector = Guice.createInjector(new Log4JLoggingModule(),
new JschSshConnectionModule());
sshFactory = injector.getInstance(SshConnection.Factory.class); sshFactory = injector.getInstance(SshConnection.Factory.class);
} }