mirror of https://github.com/apache/jclouds.git
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:
parent
7a83144421
commit
66c1b593b9
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue