Issue 130, Issue 73: separated out provider context from abstraction. accessible via getProviderSpecificContext

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2684 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-20 00:32:04 +00:00
parent fd5147e09f
commit 9b39988ad7
133 changed files with 983 additions and 1139 deletions

View File

@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore;
import java.net.URI;
import java.util.Properties;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -43,21 +41,19 @@ import com.google.inject.Module;
* @see AtmosBlobStoreContext
*/
public class AtmosBlobStoreContextFactory {
public static BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createContext(
Properties properties, Module... modules) {
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(properties).build())
.withModules(modules).buildContext();
.withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createContext(
String uid, String key, Module... modules) {
public static BlobStoreContext createContext(String uid, String key, Module... modules) {
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(uid, key).build())
.withModules(modules).buildContext();
.withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createContext(
URI endpoint, String uid, String key, Module... modules) {
public static BlobStoreContext createContext(URI endpoint, String uid, String key,
Module... modules) {
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(uid, key)
.withEndpoint(endpoint).build()).withModules(modules).buildContext();
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
}
}

View File

@ -18,34 +18,28 @@
*/
package org.jclouds.atmosonline.saas.blobstore.config;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.AtmosStorage;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore;
import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStore;
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
import org.jclouds.atmosonline.saas.blobstore.strategy.RecursiveRemove;
import org.jclouds.atmosonline.saas.config.AtmosObjectModule;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.atmosonline.saas.config.AtmosStorageContextModule;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.InputStreamMap;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ClearContainerStrategy;
import org.jclouds.blobstore.strategy.ClearListStrategy;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -53,13 +47,12 @@ import com.google.inject.Provides;
*
* @author Adrian Cole
*/
public class AtmosBlobStoreContextModule extends AbstractModule {
public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
@Override
protected void configure() {
install(new BlobStoreObjectModule());
super.configure();
install(new BlobStoreMapModule());
install(new AtmosObjectModule());
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).asEagerSingleton();
bind(BlobStore.class).to(AtmosBlobStore.class).asEagerSingleton();
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
@ -69,13 +62,12 @@ public class AtmosBlobStoreContextModule extends AbstractModule {
@Provides
@Singleton
BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> provideContext(
BlobMap.Factory blobMapFactory, InputStreamMap.Factory inputStreamMapFactory,
Closer closer, AsyncBlobStore asynchBlobStore, BlobStore blobStore, AtmosStorageAsyncClient async,
AtmosStorageClient defaultApi, @AtmosStorage URI endPoint,
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) {
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
AsyncBlobStore asynchBlobStore, BlobStore blobStore,
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> context) {
return new BlobStoreContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>(blobMapFactory,
inputStreamMapFactory, closer, asynchBlobStore, blobStore, async, defaultApi, endPoint, account);
inputStreamMapFactory, asynchBlobStore, blobStore, context);
}
}

View File

@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.List;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
import org.jclouds.atmosonline.saas.blobstore.config.AtmosBlobStoreContextModule;
import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
@ -42,9 +41,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.testng.annotations.Test;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of modules configured in AtmosStorageContextBuilder
@ -69,23 +66,22 @@ public class AtmosBlobStoreContextBuilderTest {
}
public void testBuildContext() {
BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> context = newBuilder()
.buildContext();
BlobStoreContext context = newBuilder().buildBlobStoreContext();
assertEquals(context.getClass(), BlobStoreContextImpl.class);
assertEquals(context.getAsyncApi().getClass(), StubAtmosStorageAsyncClient.class);
assertEquals(context.getProviderSpecificContext().getAsyncApi().getClass(),
StubAtmosStorageAsyncClient.class);
assertEquals(context.getAsyncBlobStore().getClass(), AtmosAsyncBlobStore.class);
assertEquals(context.getAsyncApi().newObject().getClass(), AtmosObjectImpl.class);
assertEquals(((AtmosStorageAsyncClient)context.getProviderSpecificContext().getAsyncApi()).newObject().getClass(),
AtmosObjectImpl.class);
assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub"));
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
.create("https://localhost/azurestub"));
}
public void testBuildInjector() {
Injector i = newBuilder().buildInjector();
assert i
.getInstance(Key
.get(new TypeLiteral<BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient>>() {
})) != null;
assert i.getInstance(BlobStoreContext.class) != null;
assert i.getInstance(AtmosObject.class) != null;
assert i.getInstance(Blob.class) != null;
}

View File

@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
@ -36,8 +34,6 @@ import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
@ -67,10 +63,7 @@ public class AtmosBlobStoreModuleTest {
void testContextImpl() {
Injector injector = createInjector();
BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> handler = injector
.getInstance(Key
.get(new TypeLiteral<BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient>>() {
}));
BlobStoreContext handler = injector.getInstance(BlobStoreContext.class);
assertEquals(handler.getClass(), BlobStoreContextImpl.class);
ContainsValueInListStrategy valueList = injector
.getInstance(ContainsValueInListStrategy.class);

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.atmosonline.saas.blobstore.integration;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
import org.testng.annotations.Test;
@ -27,8 +25,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageContainerIntegrationTest")
public class AtmosStorageContainerIntegrationTest extends
BaseContainerIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageContainerIntegrationTest extends BaseContainerIntegrationTest {
@Override
@Test(enabled = false)

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.atmosonline.saas.blobstore.integration;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "emcsaas.AtmosStorageContainerLiveTest")
public class AtmosStorageContainerLiveTest extends
BaseContainerLiveTest<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageContainerLiveTest extends BaseContainerLiveTest {
}

View File

@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.integration;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
import org.testng.annotations.Test;
@ -30,8 +28,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageInputStreamMapIntegrationTest")
public class AtmosStorageInputStreamMapIntegrationTest extends
BaseInputStreamMapIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
@Override
@Test(enabled = false)

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.atmosonline.saas.blobstore.integration;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -29,8 +27,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageIntegrationTest")
public class AtmosStorageIntegrationTest extends
BaseBlobIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageIntegrationTest extends BaseBlobIntegrationTest {
@DataProvider(name = "delete")
// no unicode support

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.atmosonline.saas.blobstore.integration;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.blobstore.integration.internal.BaseBlobLiveTest;
import org.testng.annotations.Test;
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "emcsaas.AtmosStorageLiveTest")
public class AtmosStorageLiveTest extends
BaseBlobLiveTest<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageLiveTest extends BaseBlobLiveTest {
}

View File

@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.integration;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
import org.testng.annotations.Test;
@ -30,8 +28,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageMapIntegrationTest")
public class AtmosStorageMapIntegrationTest extends
BaseBlobMapIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageMapIntegrationTest extends BaseBlobMapIntegrationTest {
@Override
@Test(enabled = false)

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.atmosonline.saas.blobstore.integration;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageServiceIntegrationTest")
public class AtmosStorageServiceIntegrationTest extends
BaseServiceIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageServiceIntegrationTest extends BaseServiceIntegrationTest {
}

View File

@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.integration;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStoreContextFactory;
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
import org.jclouds.blobstore.BlobStoreContext;
@ -37,21 +35,17 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class AtmosStorageTestInitializer extends
BaseTestInitializer<AtmosStorageAsyncClient, AtmosStorageClient> {
public class AtmosStorageTestInitializer extends BaseTestInitializer {
@SuppressWarnings("unchecked")
@Override
protected BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createLiveContext(
Module configurationModule, String url, String app, String account, String key)
throws IOException {
return (BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient>) new BlobStoreContextFactory()
.createContext("atmos", account, key, ImmutableSet.of(configurationModule,
new Log4JLoggingModule()), new Properties());
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
String account, String key) throws IOException {
return new BlobStoreContextFactory().createContext("atmos", account, key, ImmutableSet.of(
configurationModule, new Log4JLoggingModule()), new Properties());
}
@Override
protected BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createStubContext() {
protected BlobStoreContext createStubContext() {
return AtmosBlobStoreContextFactory.createContext("user", "pass",
new AtmosStorageStubClientModule());
}

View File

@ -75,4 +75,5 @@ public class EC2ComputeServiceContextBuilder extends
protected void addClientModule(List<Module> modules) {
modules.add(new EC2RestClientModule());
}
}

View File

@ -21,8 +21,6 @@ package org.jclouds.aws.ec2.compute;
import java.net.URI;
import java.util.Properties;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.EC2PropertiesBuilder;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -44,28 +42,28 @@ import com.google.inject.Module;
* @see EC2ComputeServiceContext
*/
public class EC2ComputeServiceContextFactory {
public static ComputeServiceContext<EC2AsyncClient, EC2Client> createContext(Properties properties,
Module... modules) {
public static ComputeServiceContext createContext(Properties properties, Module... modules) {
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(properties).build())
.withModules(modules).buildContext();
.withModules(modules).buildComputeServiceContext();
}
public static ComputeServiceContext<EC2AsyncClient, EC2Client> createContext(String awsAccessKeyId,
public static ComputeServiceContext createContext(String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildContext();
awsSecretAccessKey).build()).withModules(modules).buildComputeServiceContext();
}
public static ComputeServiceContext<EC2AsyncClient, EC2Client> createContext(Properties properties,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext();
public static ComputeServiceContext createContext(Properties properties, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(properties)
.withCredentials(awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
.buildComputeServiceContext();
}
public static ComputeServiceContext<EC2AsyncClient, EC2Client> createContext(URI endpoint,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
public static ComputeServiceContext createContext(URI endpoint, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
.buildContext();
.buildComputeServiceContext();
}
}

View File

@ -18,22 +18,17 @@
*/
package org.jclouds.aws.ec2.compute.config;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.EC2ComputeService;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.aws.ec2.config.EC2ContextModule;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -41,20 +36,19 @@ import com.google.inject.Provides;
*
* @author Adrian Cole
*/
public class EC2ComputeServiceContextModule extends AbstractModule {
public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Override
protected void configure() {
super.configure();
bind(ComputeService.class).to(EC2ComputeService.class).asEagerSingleton();
}
@Provides
@Singleton
ComputeServiceContext<EC2AsyncClient, EC2Client> provideContext(Closer closer,
ComputeService computeService, EC2AsyncClient asynchApi, EC2Client defaultApi,
@EC2 URI endPoint, @Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
return new ComputeServiceContextImpl<EC2AsyncClient, EC2Client>(closer, computeService,
asynchApi, defaultApi, endPoint, account);
ComputeServiceContext provideContext(ComputeService computeService,
RestContext<EC2AsyncClient, EC2Client> context) {
return new ComputeServiceContextImpl<EC2AsyncClient, EC2Client>(computeService, context);
}
}

View File

@ -26,9 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.EC2ComputeService;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.compute.ComputeService;
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.lifecycle.Closer;
@ -47,7 +45,6 @@ public class EC2ContextModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(CDateAdapter.class);
bind(ComputeService.class).to(EC2ComputeService.class);
}
@Provides

View File

@ -21,8 +21,6 @@ package org.jclouds.aws.s3.blobstore;
import java.net.URI;
import java.util.Properties;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.S3PropertiesBuilder;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -43,28 +41,28 @@ import com.google.inject.Module;
* @see S3BlobStoreContext
*/
public class S3BlobStoreContextFactory {
public static BlobStoreContext<S3AsyncClient, S3Client> createContext(Properties properties,
Module... modules) {
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(properties).build())
.withModules(modules).buildContext();
.withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext<S3AsyncClient, S3Client> createContext(String awsAccessKeyId,
public static BlobStoreContext createContext(String awsAccessKeyId, String awsSecretAccessKey,
Module... modules) {
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(Properties properties, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
.buildBlobStoreContext();
}
public static BlobStoreContext createContext(URI endpoint, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildContext();
}
public static BlobStoreContext<S3AsyncClient, S3Client> createContext(Properties properties,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext();
}
public static BlobStoreContext<S3AsyncClient, S3Client> createContext(URI endpoint,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
.buildContext();
.buildBlobStoreContext();
}
}

View File

@ -18,29 +18,23 @@
*/
package org.jclouds.aws.s3.blobstore.config;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore;
import org.jclouds.aws.s3.blobstore.S3BlobStore;
import org.jclouds.aws.s3.config.S3ObjectModule;
import org.jclouds.aws.s3.config.S3ContextModule;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.InputStreamMap;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -48,27 +42,24 @@ import com.google.inject.Provides;
*
* @author Adrian Cole
*/
public class S3BlobStoreContextModule extends AbstractModule {
public class S3BlobStoreContextModule extends S3ContextModule {
@Override
protected void configure() {
install(new BlobStoreObjectModule());
super.configure();
install(new BlobStoreMapModule());
install(new S3ObjectModule());
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).asEagerSingleton();
bind(BlobStore.class).to(S3BlobStore.class).asEagerSingleton();
}
@Provides
@Singleton
BlobStoreContext<S3AsyncClient, S3Client> provideContext(BlobMap.Factory blobMapFactory,
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
AsyncBlobStore asyncBlobstore, BlobStore blobStore, S3AsyncClient asynchApi,
S3Client defaultApi, @S3 URI endPoint,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
AsyncBlobStore asynchBlobStore, BlobStore blobStore,
RestContext<S3AsyncClient, S3Client> context) {
return new BlobStoreContextImpl<S3AsyncClient, S3Client>(blobMapFactory,
inputStreamMapFactory, closer, asyncBlobstore, blobStore, asynchApi, defaultApi,
endPoint, account);
inputStreamMapFactory, asynchBlobStore, blobStore, context);
}
}

View File

@ -67,7 +67,7 @@ public class EC2ComputeServiceLiveTest {
private RetryablePredicate<InetSocketAddress> socketTester;
private CreateNodeResponse node;
private ComputeServiceContext<?, ?> context;
private ComputeServiceContext context;
@BeforeGroups(groups = { "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,

View File

@ -61,14 +61,17 @@ import com.google.common.collect.Maps;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "s3.S3ClientLiveTest")
public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient, S3Client> {
public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest {
public S3Client getApi() {
return (S3Client) context.getProviderSpecificContext().getApi();
}
/**
* this method overrides containerName to ensure it isn't found
*/
@Test(groups = { "integration", "live" })
public void deleteContainerIfEmptyNotFound() throws Exception {
assert context.getApi().deleteBucketIfEmpty("dbienf");
assert getApi().deleteBucketIfEmpty("dbienf");
}
@Test(groups = { "integration", "live" })
@ -76,7 +79,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
String containerName = getContainerName();
try {
addBlobToContainer(containerName, "test");
assert !context.getApi().deleteBucketIfEmpty(containerName);
assert !getApi().deleteBucketIfEmpty(containerName);
} finally {
returnContainer(containerName);
}
@ -86,10 +89,10 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
String containerName = getContainerName();
try {
String key = "hello";
S3Object object = context.getApi().newS3Object();
S3Object object = getApi().newS3Object();
object.getMetadata().setKey(key);
object.setPayload(TEST_STRING);
context.getApi().putObject(containerName, object,
getApi().putObject(containerName, object,
withAcl(CannedAccessPolicy.PUBLIC_READ));
@ -108,7 +111,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
addBlobToContainer(containerName, sourceKey);
validateContent(containerName, sourceKey);
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
getApi().copyObject(containerName, sourceKey, destinationContainer,
destinationKey, overrideAcl(CannedAccessPolicy.PUBLIC_READ));
validateContent(destinationContainer, destinationKey);
@ -131,17 +134,17 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
final String publicReadWriteObjectKey = "public-read-write-acl";
final String containerName = getContainerName();
try {
S3Object object = context.getApi().newS3Object();
S3Object object = getApi().newS3Object();
object.getMetadata().setKey(publicReadWriteObjectKey);
object.setPayload("");
// Public Read-Write object
context.getApi().putObject(containerName, object,
getApi().putObject(containerName, object,
new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ_WRITE));
assertConsistencyAware(new Runnable() {
public void run() {
try {
AccessControlList acl = context.getApi().getObjectACL(containerName,
AccessControlList acl = getApi().getObjectACL(containerName,
publicReadWriteObjectKey);
assertEquals(acl.getGrants().size(), 3);
assertEquals(acl.getPermissions(GroupGranteeURI.ALL_USERS).size(), 2);
@ -172,7 +175,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
// Private object
addBlobToContainer(containerName, objectKey);
AccessControlList acl = context.getApi().getObjectACL(containerName, objectKey);
AccessControlList acl = getApi().getObjectACL(containerName, objectKey);
String ownerId = acl.getOwner().getId();
assertEquals(acl.getGrants().size(), 1);
@ -180,10 +183,10 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
addGrantsToACL(acl);
assertEquals(acl.getGrants().size(), 4);
assertTrue(context.getApi().putObjectACL(containerName, objectKey, acl));
assertTrue(getApi().putObjectACL(containerName, objectKey, acl));
// Confirm that the updated ACL has stuck.
acl = context.getApi().getObjectACL(containerName, objectKey);
acl = getApi().getObjectACL(containerName, objectKey);
checkGrants(acl);
/*
@ -197,10 +200,10 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
// Update the object's ACL settings
assertTrue(context.getApi().putObjectACL(containerName, objectKey, acl));
assertTrue(getApi().putObjectACL(containerName, objectKey, acl));
// Confirm that the updated ACL has stuck
acl = context.getApi().getObjectACL(containerName, objectKey);
acl = getApi().getObjectACL(containerName, objectKey);
assertEquals(acl.getGrants().size(), 1);
assertEquals(acl.getPermissions(ownerId).size(), 0);
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl.toString());
@ -217,7 +220,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
try {
// Private object
addBlobToContainer(containerName, privateObjectKey);
AccessControlList acl = context.getApi().getObjectACL(containerName, privateObjectKey);
AccessControlList acl = getApi().getObjectACL(containerName, privateObjectKey);
assertEquals(acl.getGrants().size(), 1);
assertTrue(acl.getOwner() != null);
@ -234,16 +237,16 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
final String publicReadObjectKey = "public-read-acl";
final String containerName = getContainerName();
try {
S3Object object = context.getApi().newS3Object();
S3Object object = getApi().newS3Object();
object.getMetadata().setKey(publicReadObjectKey);
object.setPayload("");
context.getApi().putObject(containerName, object,
getApi().putObject(containerName, object,
new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ));
assertConsistencyAware(new Runnable() {
public void run() {
try {
AccessControlList acl = context.getApi().getObjectACL(containerName,
AccessControlList acl = getApi().getObjectACL(containerName,
publicReadObjectKey);
assertEquals(acl.getGrants().size(), 2);
@ -265,17 +268,17 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
}
protected String addBlobToContainer(String sourceContainer, String key) {
S3Object sourceObject = context.getApi().newS3Object();
S3Object sourceObject = getApi().newS3Object();
sourceObject.getMetadata().setKey(key);
sourceObject.getMetadata().setContentType("text/xml");
sourceObject.setPayload(TEST_STRING);
return context.getApi().putObject(sourceContainer, sourceObject);
return getApi().putObject(sourceContainer, sourceObject);
}
protected S3Object validateObject(String sourceContainer, String key)
throws InterruptedException, ExecutionException, TimeoutException, IOException {
assertConsistencyAwareContainerSize(sourceContainer, 1);
S3Object newObject = context.getApi().getObject(sourceContainer, key);
S3Object newObject = getApi().getObject(sourceContainer, key);
assert newObject != null;
assertEquals(Utils.toStringAndClose(newObject.getContent()), TEST_STRING);
return newObject;
@ -284,14 +287,14 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
public void testMetadataWithCacheControlAndContentDisposition() throws Exception {
String key = "hello";
S3Object object = context.getApi().newS3Object();
S3Object object = getApi().newS3Object();
object.getMetadata().setKey(key);
object.setPayload(TEST_STRING);
object.getMetadata().setCacheControl("no-cache");
object.getMetadata().setContentDisposition("attachment; filename=hello.txt");
String containerName = getContainerName();
try {
context.getApi().putObject(containerName, object);
getApi().putObject(containerName, object);
S3Object newObject = validateObject(containerName, key);
@ -307,13 +310,13 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
public void testMetadataContentEncoding() throws Exception {
String key = "hello";
S3Object object = context.getApi().newS3Object();
S3Object object = getApi().newS3Object();
object.getMetadata().setKey(key);
object.setPayload(TEST_STRING);
object.getMetadata().setContentEncoding("x-compress");
String containerName = getContainerName();
try {
context.getApi().putObject(containerName, object);
getApi().putObject(containerName, object);
S3Object newObject = validateObject(containerName, key);
assertEquals(newObject.getMetadata().getContentEncoding(), "x-compress");
@ -329,7 +332,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
try {
addToContainerAndValidate(containerName, sourceKey);
context.getApi()
getApi()
.copyObject(containerName, sourceKey, destinationContainer, destinationKey);
validateContent(destinationContainer, destinationKey);
@ -357,12 +360,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
addToContainerAndValidate(containerName, sourceKey + "mod");
Date after = new Date(System.currentTimeMillis() + 1000);
context.getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
destinationKey, ifSourceModifiedSince(before));
validateContent(destinationContainer, destinationKey);
try {
context.getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
destinationKey, ifSourceModifiedSince(after));
} catch (HttpResponseException ex) {
assertEquals(ex.getResponse().getStatusCode(), 412);
@ -384,12 +387,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
addToContainerAndValidate(containerName, sourceKey + "un");
Date after = new Date(System.currentTimeMillis() + 1000);
context.getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
destinationKey, ifSourceUnmodifiedSince(after));
validateContent(destinationContainer, destinationKey);
try {
context.getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
destinationKey, ifSourceModifiedSince(before));
} catch (HttpResponseException ex) {
assertEquals(ex.getResponse().getStatusCode(), 412);
@ -407,12 +410,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
try {
String goodETag = addToContainerAndValidate(containerName, sourceKey);
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
getApi().copyObject(containerName, sourceKey, destinationContainer,
destinationKey, ifSourceETagMatches(goodETag));
validateContent(destinationContainer, destinationKey);
try {
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
getApi().copyObject(containerName, sourceKey, destinationContainer,
destinationKey, ifSourceETagMatches("setsds"));
} catch (HttpResponseException ex) {
assertEquals(ex.getResponse().getStatusCode(), 412);
@ -430,12 +433,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
try {
String goodETag = addToContainerAndValidate(containerName, sourceKey);
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
getApi().copyObject(containerName, sourceKey, destinationContainer,
destinationKey, ifSourceETagDoesntMatch("asfasdf"));
validateContent(destinationContainer, destinationKey);
try {
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
getApi().copyObject(containerName, sourceKey, destinationContainer,
destinationKey, ifSourceETagDoesntMatch(goodETag));
} catch (HttpResponseException ex) {
assertEquals(ex.getResponse().getStatusCode(), 412);
@ -457,12 +460,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
Map<String, String> metadata = Maps.newHashMap();
metadata.put("adrian", "cole");
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
getApi().copyObject(containerName, sourceKey, destinationContainer,
destinationKey, overrideMetadataWith(metadata));
validateContent(destinationContainer, destinationKey);
ObjectMetadata objectMeta = context.getApi().headObject(destinationContainer,
ObjectMetadata objectMeta = getApi().headObject(destinationContainer,
destinationKey);
assertEquals(objectMeta.getUserMetadata(), metadata);

View File

@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.List;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.S3PropertiesBuilder;
import org.jclouds.aws.s3.blobstore.config.S3BlobStoreContextModule;
import org.jclouds.aws.s3.config.S3RestClientModule;
@ -43,9 +42,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.testng.annotations.Test;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of modules configured in S3ContextBuilder
@ -65,23 +62,24 @@ public class S3BlobStoreContextBuilderTest {
}
public void testBuildContext() {
BlobStoreContext<S3AsyncClient, S3Client> context = new S3BlobStoreContextBuilder(
new S3PropertiesBuilder("id", "secret").build()).withModules(
new S3StubClientModule()).buildContext();
BlobStoreContext context = new S3BlobStoreContextBuilder(new S3PropertiesBuilder("id",
"secret").build()).withModules(new S3StubClientModule()).buildBlobStoreContext();
assertEquals(context.getClass(), BlobStoreContextImpl.class);
assertEquals(context.getAsyncApi().getClass(), StubS3AsyncClient.class);
assertEquals(context.getProviderSpecificContext().getAsyncApi().getClass(),
StubS3AsyncClient.class);
assertEquals(context.getAsyncBlobStore().getClass(), S3AsyncBlobStore.class);
assertEquals(context.getAsyncApi().newS3Object().getClass(), S3ObjectImpl.class);
assertEquals(((S3AsyncClient) context.getProviderSpecificContext().getAsyncApi())
.newS3Object().getClass(), S3ObjectImpl.class);
assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("https://localhost/s3stub"));
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
.create("https://localhost/s3stub"));
}
public void testBuildInjector() {
Injector i = new S3BlobStoreContextBuilder(new S3PropertiesBuilder("id", "secret").build())
.withModules(new S3StubClientModule()).buildInjector();
assert i.getInstance(Key.get(new TypeLiteral<BlobStoreContext<S3AsyncClient, S3Client>>() {
})) != null;
assert i.getInstance(BlobStoreContext.class) != null;
assert i.getInstance(S3Object.class) != null;
assert i.getInstance(Blob.class) != null;
}

View File

@ -21,8 +21,6 @@ package org.jclouds.aws.s3.blobstore.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.config.S3StubClientModule;
import org.jclouds.aws.s3.reference.S3Constants;
import org.jclouds.blobstore.BlobStoreContext;
@ -34,8 +32,6 @@ import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
@ -61,9 +57,7 @@ public class S3BlobStoreModuleTest {
@Test
void testContextImpl() {
BlobStoreContext<S3AsyncClient, S3Client> context = createInjector().getInstance(
Key.get(new TypeLiteral<BlobStoreContext<S3AsyncClient, S3Client>>() {
}));
BlobStoreContext context = createInjector().getInstance(BlobStoreContext.class);
assertEquals(context.getClass(), BlobStoreContextImpl.class);
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
import org.testng.annotations.Test;
@ -29,6 +27,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "s3.S3BlobIntegrationTest")
public class S3BlobIntegrationTest extends BaseBlobIntegrationTest<S3AsyncClient, S3Client> {
public class S3BlobIntegrationTest extends BaseBlobIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.integration.internal.BaseBlobLiveTest;
import org.testng.annotations.Test;
@ -29,6 +27,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "s3.S3BlobLiveTest")
public class S3BlobLiveTest extends BaseBlobLiveTest<S3AsyncClient, S3Client> {
public class S3BlobLiveTest extends BaseBlobLiveTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
import org.testng.annotations.Test;
@ -27,6 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "s3.S3BlobMapIntegrationTest")
public class S3BlobMapIntegrationTest extends BaseBlobMapIntegrationTest<S3AsyncClient, S3Client> {
public class S3BlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
import org.testng.annotations.Test;
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "s3.S3ContainerIntegrationTest")
public class S3ContainerIntegrationTest extends
BaseContainerIntegrationTest<S3AsyncClient, S3Client> {
public class S3ContainerIntegrationTest extends BaseContainerIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
import org.testng.annotations.Test;
@ -28,6 +26,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "s3.S3ContainerLiveTest")
public class S3ContainerLiveTest extends BaseContainerLiveTest<S3AsyncClient, S3Client> {
public class S3ContainerLiveTest extends BaseContainerLiveTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "s3.S3InputStreamMapIntegrationTest")
public class S3InputStreamMapIntegrationTest extends
BaseInputStreamMapIntegrationTest<S3AsyncClient, S3Client> {
public class S3InputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
import org.testng.annotations.Test;
@ -27,6 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "s3.S3ServiceIntegrationTest")
public class S3ServiceIntegrationTest extends BaseServiceIntegrationTest<S3AsyncClient, S3Client> {
public class S3ServiceIntegrationTest extends BaseServiceIntegrationTest {
}

View File

@ -21,8 +21,6 @@ package org.jclouds.aws.s3.blobstore.integration;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextFactory;
import org.jclouds.aws.s3.config.S3StubClientModule;
import org.jclouds.blobstore.BlobStoreContext;
@ -38,20 +36,18 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class S3TestInitializer extends BaseTestInitializer<S3AsyncClient, S3Client> {
public class S3TestInitializer extends BaseTestInitializer {
@SuppressWarnings("unchecked")
@Override
protected BlobStoreContext<S3AsyncClient, S3Client> createLiveContext(
Module configurationModule, String url, String app, String account, String key) throws IOException {
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
String account, String key) throws IOException {
BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true;
return (BlobStoreContext<S3AsyncClient, S3Client>) new BlobStoreContextFactory()
.createContext("s3", account, key, ImmutableSet.of(configurationModule,
new Log4JLoggingModule()), new Properties());
return new BlobStoreContextFactory().createContext("s3", account, key, ImmutableSet.of(
configurationModule, new Log4JLoggingModule()), new Properties());
}
@Override
protected BlobStoreContext<S3AsyncClient, S3Client> createStubContext() {
protected BlobStoreContext createStubContext() {
return S3BlobStoreContextFactory.createContext("user", "pass", new S3StubClientModule());
}

View File

@ -55,4 +55,5 @@ public class S3StubClientModule extends AbstractModule {
SecurityException, NoSuchMethodException {
return SyncProxy.create(S3Client.class, client);
}
}

View File

@ -36,7 +36,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.domain.BucketLogging;
@ -64,14 +63,17 @@ import com.google.common.collect.ImmutableSet;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "s3.S3ClientLiveTest")
public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient, S3Client> {
public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
public S3Client getApi() {
return (S3Client) context.getProviderSpecificContext().getApi();
}
/**
* this method overrides bucketName to ensure it isn't found
*/
@Test(groups = { "integration", "live" })
public void deleteBucketIfEmptyNotFound() throws Exception {
assert context.getApi().deleteBucketIfEmpty("dbienf");
assert getApi().deleteBucketIfEmpty("dbienf");
}
@Test(groups = { "integration", "live" })
@ -79,7 +81,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
String bucketName = getContainerName();
try {
addBlobToContainer(bucketName, "test");
assert !context.getApi().deleteBucketIfEmpty(bucketName);
assert !getApi().deleteBucketIfEmpty(bucketName);
} finally {
returnContainer(bucketName);
}
@ -89,7 +91,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
TimeoutException, IOException {
String bucketName = getContainerName();
try {
AccessControlList acl = context.getApi().getBucketACL(bucketName);
AccessControlList acl = getApi().getBucketACL(bucketName);
assertEquals(acl.getGrants().size(), 1);
assertTrue(acl.getOwner() != null);
String ownerId = acl.getOwner().getId();
@ -105,17 +107,17 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
String bucketName = getContainerName();
try {
// Confirm the bucket is private
AccessControlList acl = context.getApi().getBucketACL(bucketName);
AccessControlList acl = getApi().getBucketACL(bucketName);
String ownerId = acl.getOwner().getId();
assertEquals(acl.getGrants().size(), 1);
assertTrue(acl.hasPermission(ownerId, Permission.FULL_CONTROL));
addGrantsToACL(acl);
assertEquals(acl.getGrants().size(), 4);
assertTrue(context.getApi().putBucketACL(bucketName, acl));
assertTrue(getApi().putBucketACL(bucketName, acl));
// Confirm that the updated ACL has stuck.
acl = context.getApi().getBucketACL(bucketName);
acl = getApi().getBucketACL(bucketName);
checkGrants(acl);
} finally {
destroyContainer(bucketName);
@ -147,9 +149,9 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
public void testPublicReadAccessPolicy() throws Exception {
String bucketName = getScratchContainerName();
try {
context.getApi().putBucketInRegion(Region.DEFAULT, bucketName,
getApi().putBucketInRegion(Region.DEFAULT, bucketName,
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
AccessControlList acl = context.getApi().getBucketACL(bucketName);
AccessControlList acl = getApi().getBucketACL(bucketName);
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl.toString());
// TODO: I believe that the following should work based on the above acl assertion passing.
// However, it fails on 403
@ -175,7 +177,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
public void testDefaultBucketLocation() throws Exception {
String bucketName = getContainerName();
try {
assertEquals(Region.US_STANDARD, context.getApi().getBucketLocation(bucketName));
assertEquals(Region.US_STANDARD, getApi().getBucketLocation(bucketName));
} finally {
returnContainer(bucketName);
}
@ -184,23 +186,23 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
public void testBucketPayer() throws Exception {
final String bucketName = getContainerName();
try {
assertEquals(Payer.BUCKET_OWNER, context.getApi().getBucketPayer(bucketName));
context.getApi().setBucketPayer(bucketName, Payer.REQUESTER);
assertEquals(Payer.BUCKET_OWNER, getApi().getBucketPayer(bucketName));
getApi().setBucketPayer(bucketName, Payer.REQUESTER);
assertConsistencyAware(new Runnable() {
public void run() {
try {
assertEquals(Payer.REQUESTER, context.getApi().getBucketPayer(bucketName));
assertEquals(Payer.REQUESTER, getApi().getBucketPayer(bucketName));
} catch (Exception e) {
Throwables.propagateIfPossible(e);
}
}
});
context.getApi().setBucketPayer(bucketName, Payer.BUCKET_OWNER);
getApi().setBucketPayer(bucketName, Payer.BUCKET_OWNER);
assertConsistencyAware(new Runnable() {
public void run() {
try {
assertEquals(Payer.BUCKET_OWNER, context.getApi().getBucketPayer(bucketName));
assertEquals(Payer.BUCKET_OWNER, getApi().getBucketPayer(bucketName));
} catch (Exception e) {
Throwables.propagateIfPossible(e);
}
@ -215,19 +217,19 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
final String bucketName = getContainerName();
final String targetBucket = getContainerName();
try {
assertNull(context.getApi().getBucketLogging(bucketName));
assertNull(getApi().getBucketLogging(bucketName));
setupAclForBucketLoggingTarget(targetBucket);
final BucketLogging logging = new BucketLogging(targetBucket, "access_log-", ImmutableSet
.<Grant> of(new Grant(new EmailAddressGrantee(StubS3AsyncClient.TEST_ACL_EMAIL),
Permission.FULL_CONTROL)));
context.getApi().enableBucketLogging(bucketName, logging);
getApi().enableBucketLogging(bucketName, logging);
assertConsistencyAware(new Runnable() {
public void run() {
try {
BucketLogging newLogging = context.getApi().getBucketLogging(bucketName);
BucketLogging newLogging = getApi().getBucketLogging(bucketName);
AccessControlList acl = new AccessControlList();
for (Grant grant : newLogging.getTargetGrants()) { // TODO: add permission
// checking features to
@ -245,11 +247,11 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
}
}
});
context.getApi().disableBucketLogging(bucketName);
getApi().disableBucketLogging(bucketName);
assertConsistencyAware(new Runnable() {
public void run() {
try {
assertNull(context.getApi().getBucketLogging(bucketName));
assertNull(getApi().getBucketLogging(bucketName));
} catch (Exception e) {
Throwables.propagateIfPossible(e);
}
@ -263,10 +265,10 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
private void setupAclForBucketLoggingTarget(final String targetBucket) {
// http://docs.amazonwebservices.com/AmazonS3/latest/LoggingHowTo.html
AccessControlList acl = context.getApi().getBucketACL(targetBucket);
AccessControlList acl = getApi().getBucketACL(targetBucket);
acl.addPermission(GroupGranteeURI.LOG_DELIVERY, Permission.WRITE);
acl.addPermission(GroupGranteeURI.LOG_DELIVERY, Permission.READ_ACP);
assertTrue(context.getApi().putBucketACL(targetBucket, acl));
assertTrue(getApi().putBucketACL(targetBucket, acl));
}
/**
@ -275,12 +277,12 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
public void testEu() throws Exception {
final String bucketName = getScratchContainerName();
try {
context.getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "eu",
getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "eu",
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
assertConsistencyAware(new Runnable() {
public void run() {
try {
AccessControlList acl = context.getApi().getBucketACL(bucketName + "eu");
AccessControlList acl = getApi().getBucketACL(bucketName + "eu");
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl
.toString());
} catch (Exception e) {
@ -288,7 +290,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
}
}
});
assertEquals(Region.EU_WEST_1, context.getApi().getBucketLocation(bucketName + "eu"));
assertEquals(Region.EU_WEST_1, getApi().getBucketLocation(bucketName + "eu"));
// TODO: I believe that the following should work based on the above acl assertion passing.
// However, it fails on 403
// URL url = new URL(String.format("http://%s.s3.amazonaws.com", bucketName));
@ -304,12 +306,12 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
public void testNorthernCalifornia() throws Exception {
final String bucketName = getScratchContainerName();
try {
context.getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "cali",
getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "cali",
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
assertConsistencyAware(new Runnable() {
public void run() {
try {
AccessControlList acl = context.getApi().getBucketACL(bucketName + "cali");
AccessControlList acl = getApi().getBucketACL(bucketName + "cali");
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl
.toString());
} catch (Exception e) {
@ -317,7 +319,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
}
}
});
assertEquals(Region.EU_WEST_1, context.getApi().getBucketLocation(bucketName + "cali"));
assertEquals(Region.EU_WEST_1, getApi().getBucketLocation(bucketName + "cali"));
// TODO: I believe that the following should work based on the above acl assertion passing.
// However, it fails on 403
// URL url = new URL(String.format("http://%s.s3.amazonaws.com", bucketName));
@ -330,7 +332,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
void bucketExists() throws Exception {
String bucketName = getContainerName();
try {
SortedSet<BucketMetadata> list = context.getApi().listOwnedBuckets();
SortedSet<BucketMetadata> list = getApi().listOwnedBuckets();
BucketMetadata firstBucket = list.first();
BucketMetadata toMatch = new BucketMetadata(bucketName, new Date(), firstBucket.getOwner());
assert list.contains(toMatch);
@ -341,10 +343,10 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
protected void addAlphabetUnderRoot(String bucketName) {
for (char letter = 'a'; letter <= 'z'; letter++) {
S3Object blob = context.getApi().newS3Object();
S3Object blob = getApi().newS3Object();
blob.getMetadata().setKey(letter + "");
blob.setPayload(letter + "content");
context.getApi().putObject(bucketName, blob);
getApi().putObject(bucketName, blob);
}
}
@ -353,7 +355,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
String bucketName = getContainerName();
try {
addAlphabetUnderRoot(bucketName);
ListBucketResponse bucket = context.getApi().listBucket(bucketName, afterMarker("y"));
ListBucketResponse bucket = getApi().listBucket(bucketName, afterMarker("y"));
assertEquals(bucket.getMarker(), "y");
assert !bucket.isTruncated();
assertEquals(bucket.size(), 1);
@ -369,7 +371,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
String prefix = "apps";
addTenObjectsUnderPrefix(bucketName, prefix);
add15UnderRoot(bucketName);
ListBucketResponse bucket = context.getApi().listBucket(bucketName, delimiter("/"));
ListBucketResponse bucket = getApi().listBucket(bucketName, delimiter("/"));
assertEquals(bucket.getDelimiter(), "/");
assert !bucket.isTruncated();
assertEquals(bucket.size(), 15);
@ -388,7 +390,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
addTenObjectsUnderPrefix(bucketName, prefix);
add15UnderRoot(bucketName);
ListBucketResponse bucket = context.getApi().listBucket(bucketName, withPrefix("apps/"));
ListBucketResponse bucket = getApi().listBucket(bucketName, withPrefix("apps/"));
assert !bucket.isTruncated();
assertEquals(bucket.size(), 10);
assertEquals(bucket.getPrefix(), "apps/");
@ -403,7 +405,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
String bucketName = getContainerName();
try {
addAlphabetUnderRoot(bucketName);
ListBucketResponse bucket = context.getApi().listBucket(bucketName, maxResults(5));
ListBucketResponse bucket = getApi().listBucket(bucketName, maxResults(5));
assertEquals(bucket.getMaxKeys(), 5);
assert bucket.isTruncated();
assertEquals(bucket.size(), 5);
@ -414,19 +416,19 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
protected void add15UnderRoot(String bucketName) {
for (int i = 0; i < 15; i++) {
S3Object blob = context.getApi().newS3Object();
S3Object blob = getApi().newS3Object();
blob.getMetadata().setKey(i + "");
blob.setPayload(i + "content");
context.getApi().putObject(bucketName, blob);
getApi().putObject(bucketName, blob);
}
}
protected void addTenObjectsUnderPrefix(String bucketName, String prefix) {
for (int i = 0; i < 10; i++) {
S3Object blob = context.getApi().newS3Object();
S3Object blob = getApi().newS3Object();
blob.getMetadata().setKey(prefix + "/" + i);
blob.setPayload(i + "content");
context.getApi().putObject(bucketName, blob);
getApi().putObject(bucketName, blob);
}
}
}

View File

@ -18,13 +18,20 @@
*/
package org.jclouds.aws.s3.samples;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextFactory;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.rest.RestContext;
/**
* This the Main class of an Application that demonstrates the use of the blobstore.
@ -39,8 +46,7 @@ public class MainApp {
public static int PARAMETERS = 3;
public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: \"accesskeyid\" \"secretkey\" \"bucketName\" ";
@SuppressWarnings("unchecked")
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
if (args.length < PARAMETERS)
throw new IllegalArgumentException(INVALID_SYNTAX);
@ -51,7 +57,8 @@ public class MainApp {
String containerName = args[2];
// Init
BlobStoreContext context = S3BlobStoreContextFactory.createContext(accesskeyid, secretkey);
BlobStoreContext context = new BlobStoreContextFactory().createContext("s3", accesskeyid,
secretkey);
try {
@ -59,6 +66,7 @@ public class MainApp {
BlobStore blobStore = context.getBlobStore();
blobStore.createContainerInLocation(Region.DEFAULT.toString(), containerName);
// Add Blob
Blob blob = blobStore.newBlob("test");
blob.setPayload("testdata");
blobStore.putBlob(containerName, blob);
@ -67,11 +75,18 @@ public class MainApp {
for (StorageMetadata resourceMd : blobStore.list()) {
if (resourceMd.getType() == StorageType.CONTAINER
|| resourceMd.getType() == StorageType.FOLDER) {
System.out.printf(" %s: %s entries%n", resourceMd.getName(), context
.createInputStreamMap(resourceMd.getName()).size());
// Use Map API
Map<String, InputStream> containerMap = context.createInputStreamMap(resourceMd
.getName());
System.out.printf(" %s: %s entries%n", resourceMd.getName(), containerMap.size());
}
}
// Use Provider API
RestContext<S3AsyncClient, S3Client> providerContext = context
.getProviderSpecificContext();
providerContext.getApi().getBucketLogging(containerName);
} finally {
// Close connecton
context.close();

View File

@ -48,14 +48,14 @@ import com.google.common.collect.Sets;
public class GetAllContainersController extends HttpServlet {
private static final long serialVersionUID = 1L;
private Map<String, BlobStoreContext<?,?>> contexts;
private Map<String, BlobStoreContext> contexts;
private final BlobStoreContextToContainerResult blobStoreContextToContainerResult;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public GetAllContainersController(Map<String, BlobStoreContext<?,?>> contexts,
public GetAllContainersController(Map<String, BlobStoreContext> contexts,
BlobStoreContextToContainerResult blobStoreContextToContainerResult) {
this.contexts = contexts;
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;

View File

@ -50,15 +50,15 @@ import com.google.inject.servlet.ServletModule;
*/
public class GuiceServletConfig extends GuiceServletContextListener {
private Map<String, BlobStoreContext<?, ?>> contexts;
private Map<String, BlobStoreContext> contexts;
@SuppressWarnings("unchecked")
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
Properties props = loadJCloudsProperties(servletContextEvent);
ImmutableList<String> list = ImmutableList.<String> of(checkNotNull(
props.getProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS).split(","));
props.getProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS),
BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS).split(","));
contexts = Maps.newHashMap();
for (String className : list) {
try {
@ -68,7 +68,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
Constructor<BlobStoreContextBuilder<?, ?>> constructor = builderClass
.getConstructor(Properties.class);
contexts.put(name, constructor.newInstance(props).withModules(
new GoogleAppEngineConfigurationModule()).buildContext());
new GoogleAppEngineConfigurationModule()).buildBlobStoreContext());
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -95,7 +95,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
return Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
bind(new TypeLiteral<Map<String, BlobStoreContext<?, ?>>>() {
bind(new TypeLiteral<Map<String, BlobStoreContext>>() {
}).toInstance(GuiceServletConfig.this.contexts);
serve("*.blobstore").with(GetAllContainersController.class);
requestInjection(this);
@ -107,7 +107,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
for (BlobStoreContext<?, ?> context : contexts.values()) {
for (BlobStoreContext context : contexts.values()) {
context.close();
}
super.contextDestroyed(servletContextEvent);

View File

@ -40,10 +40,10 @@ import com.google.common.collect.Sets;
public class BlobStoreContextToContainerResult implements Function<String, ContainerResult> {
private final class BuildContainerResult implements Function<StorageMetadata, ContainerResult> {
private final String host;
private final BlobStoreContext<?, ?> context;
private final BlobStoreContext context;
private final String contextName;
private BuildContainerResult(String host, BlobStoreContext<?, ?> context, String contextName) {
private BuildContainerResult(String host, BlobStoreContext context, String contextName) {
this.host = host;
this.context = context;
this.contextName = contextName;
@ -68,14 +68,14 @@ public class BlobStoreContextToContainerResult implements Function<String, Conta
}
@Inject
private Map<String, BlobStoreContext<?, ?>> contexts;
private Map<String, BlobStoreContext> contexts;
@Resource
protected Logger logger = Logger.NULL;
public ContainerResult apply(final String contextName) {
final BlobStoreContext<?, ?> context = contexts.get(contextName);
final String host = context.getEndPoint().getHost();
final BlobStoreContext context = contexts.get(contextName);
final String host = context.getProviderSpecificContext().getEndPoint().getHost();
try {
StorageMetadata md = Iterables.getLast(Sets.newTreeSet(Iterables.filter(context
.getBlobStore().list(), new Predicate<StorageMetadata>() {

View File

@ -23,7 +23,7 @@ import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_KEY;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER;
@ -62,7 +62,7 @@ public class GoogleAppEngineLiveTest {
url = new URL(String.format("http://%s:%s", address, port));
Properties props = new Properties();
props.setProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS, String.format("%s,%s,%s",
props.setProperty(PROPERTY_BLOBSTORE_CONTEXTS, String.format("%s,%s,%s",
S3BlobStoreContextBuilder.class.getName(), CloudFilesBlobStoreContextBuilder.class
.getName(), AzureBlobStoreContextBuilder.class.getName()));

View File

@ -29,15 +29,15 @@ import java.util.SortedSet;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.S3ContextFactory;
import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore;
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextFactory;
import org.jclouds.aws.s3.domain.ListBucketResponse;
import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.options.CopyObjectOptions;
import org.jclouds.aws.s3.options.ListBucketOptions;
import org.jclouds.aws.s3.options.PutObjectOptions;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.RestContext;
import org.jets3t.service.S3ObjectsChunk;
import org.jets3t.service.S3Service;
import org.jets3t.service.S3ServiceException;
@ -60,7 +60,7 @@ public class JCloudsS3Service extends S3Service {
private static final long serialVersionUID = 1L;
private final BlobStoreContext<S3AsyncClient, S3Client> context;
private final RestContext<S3AsyncClient, S3Client> context;
private final S3Client connection;
/**
@ -76,8 +76,8 @@ public class JCloudsS3Service extends S3Service {
protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules)
throws S3ServiceException {
super(awsCredentials);
context = S3BlobStoreContextFactory.createContext(awsCredentials.getAccessKey(),
awsCredentials.getSecretKey(), modules);
context = S3ContextFactory.createContext(awsCredentials.getAccessKey(), awsCredentials
.getSecretKey(), modules);
connection = context.getApi();
}

View File

@ -37,7 +37,6 @@ import java.util.concurrent.TimeoutException;
import javax.ws.rs.core.MediaType;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.domain.ListBucketResponse;
import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
@ -72,10 +71,14 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "jets3t.JCloudsS3ServiceIntegrationTest")
public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient, S3Client> {
public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest {
AWSCredentials credentials;
S3Service service;
public S3Client getApi() {
return (S3Client) context.getProviderSpecificContext().getApi();
}
/**
* overridden only to get access to the amazon credentials used for jets3t initialization.
*
@ -102,7 +105,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
try {
S3Bucket bucket = service.createBucket(new S3Bucket(bucketName));
assertEquals(bucket.getName(), bucketName);
assertTrue(context.getApi().bucketExists(bucketName));
assertTrue(getApi().bucketExists(bucketName));
} finally {
returnContainer(bucketName);
}
@ -115,7 +118,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
service.deleteBucket(bucketName);
assertConsistencyAware(new Runnable() {
public void run() {
assertFalse(context.getApi().bucketExists(bucketName));
assertFalse(getApi().bucketExists(bucketName));
}
});
}
@ -200,7 +203,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
// Ensure there is at least 1 bucket in S3 account to list and compare.
S3Bucket[] jsBuckets = service.listAllBuckets();
SortedSet<org.jclouds.aws.s3.domain.BucketMetadata> jcBuckets = context.getApi()
SortedSet<org.jclouds.aws.s3.domain.BucketMetadata> jcBuckets = getApi()
.listOwnedBuckets();
assert jsBuckets.length == jcBuckets.size();
@ -352,7 +355,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
// Upload empty object
requestObject = new S3Object(objectKey);
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
jcObject = context.getApi().getObject(bucketName, objectKey);
jcObject = getApi().getObject(bucketName, objectKey);
// TODO null keys from s3object! assertEquals(jcObject.getKey(), objectKey);
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
assertEquals(jcObject.getMetadata().getContentType(), MediaType.APPLICATION_OCTET_STREAM);
@ -363,7 +366,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
// Upload unicode-named object
requestObject = new S3Object("₪n₪₪₪d₪-object");
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
jcObject = context.getApi().getObject(bucketName, requestObject.getKey());
jcObject = getApi().getObject(bucketName, requestObject.getKey());
// TODO null keys from s3object! assertEquals(jcObject.getKey(), requestObject.getKey());
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
assertEquals(jcObject.getMetadata().getContentType(), MediaType.APPLICATION_OCTET_STREAM);
@ -375,7 +378,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
String data = "This is my ₪n₪₪₪d₪ data";
requestObject = new S3Object(objectKey, data);
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
jcObject = context.getApi().getObject(bucketName, objectKey);
jcObject = getApi().getObject(bucketName, objectKey);
assertEquals(jcObject.getMetadata().getSize(), new Long(data.getBytes("UTF-8").length));
assertTrue(jcObject.getMetadata().getContentType().startsWith("text/plain"));
assertEquals(jsResultObject.getContentLength(), data.getBytes("UTF-8").length);
@ -385,7 +388,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
requestObject = new S3Object(objectKey);
requestObject.addMetadata("x-amz-meta-" + "my-metadata-1", "value-1");
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
jcObject = context.getApi().getObject(bucketName, objectKey);
jcObject = getApi().getObject(bucketName, objectKey);
assertEquals(jcObject.getMetadata().getUserMetadata().get("my-metadata-1"), "value-1");
assertEquals(jsResultObject.getMetadata("x-amz-meta-" + "my-metadata-1"), "value-1");
@ -393,8 +396,8 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
requestObject = new S3Object(objectKey);
requestObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
org.jclouds.aws.s3.domain.AccessControlList jcACL = context.getApi().getObjectACL(
bucketName, objectKey);
org.jclouds.aws.s3.domain.AccessControlList jcACL = getApi().getObjectACL(bucketName,
objectKey);
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
assertEquals(jcACL.getGrants().size(), 2);
@ -409,7 +412,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
data = "Here is some d₪t₪ for you";
requestObject.setDataInputStream(new ByteArrayInputStream(data.getBytes("UTF-8")));
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
jcObject = context.getApi().getObject(bucketName, objectKey);
jcObject = getApi().getObject(bucketName, objectKey);
assertTrue(jsResultObject.verifyData(data.getBytes("UTF-8")));
assertEquals(jsResultObject.getETag(), jcObject.getMetadata().getETag().replaceAll("\"",
""));
@ -444,15 +447,15 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
destinationObject = new S3Object(destinationObjectKey);
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
destinationObject, false);
jcDestinationObject = context.getApi().getObject(bucketName, destinationObject.getKey());
jcDestinationObject = getApi().getObject(bucketName, destinationObject.getKey());
// TODO null keys from s3object! assertEquals(jcDestinationObject.getKey(),
// destinationObjectKey);
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName),
sourceMetadataValue);
assertEquals(copyResult.get("ETag"), jcDestinationObject.getMetadata().getETag());
// Test destination ACL is unchanged (ie private)
org.jclouds.aws.s3.domain.AccessControlList jcACL = context.getApi().getObjectACL(
bucketName, destinationObject.getKey());
org.jclouds.aws.s3.domain.AccessControlList jcACL = getApi().getObjectACL(bucketName,
destinationObject.getKey());
assertEquals(jcACL.getGrants().size(), 1);
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
@ -461,11 +464,11 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
destinationObject.addMetadata("x-amz-meta-" + metadataName, destinationMetadataValue);
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
destinationObject, true);
jcDestinationObject = context.getApi().getObject(bucketName, destinationObject.getKey());
jcDestinationObject = getApi().getObject(bucketName, destinationObject.getKey());
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName),
destinationMetadataValue);
// Test destination ACL is unchanged (ie private)
jcACL = context.getApi().getObjectACL(bucketName, destinationObject.getKey());
jcACL = getApi().getObjectACL(bucketName, destinationObject.getKey());
assertEquals(jcACL.getGrants().size(), 1);
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
@ -475,7 +478,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
destinationObject, false);
// Test destination ACL is changed (ie public-read)
jcACL = context.getApi().getObjectACL(bucketName, destinationObject.getKey());
jcACL = getApi().getObjectACL(bucketName, destinationObject.getKey());
assertEquals(jcACL.getGrants().size(), 2);
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
@ -654,7 +657,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
multiService.putObjects(bucket, objects);
assertEquals(countOfUploadCompletions[0], OBJECT_COUNT);
ListBucketResponse theBucket = context.getApi().listBucket(bucketName);
ListBucketResponse theBucket = getApi().listBucket(bucketName);
assertEquals(theBucket.size(), OBJECT_COUNT);
} finally {

View File

@ -41,7 +41,7 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
// object.setContentType("application/octetstream");
// //object.setPayload("this is a test");
// object.setPayload(test);
// return context.getApi()Provider.getObject(s3Bucket,
// return getApi()Provider.getObject(s3Bucket,
// object.getKey()).get(120,TimeUnit.SECONDS) !=
// S3Object.NOT_FOUND;
@ -53,7 +53,7 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
S3Object object = newObject(key);
object.getMetadata().setContentType(contentType);
object.setPayload(data);
return context.getApi().putObject(bucket, object) != null;
return getApi().putObject(bucket, object) != null;
}
@Override
@ -62,11 +62,11 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
S3Object object = newObject(key);
object.getMetadata().setContentType(contentType);
object.setPayload(data);
return context.getApi().putObject(bucket, object) != null;
return getApi().putObject(bucket, object) != null;
}
private S3Object newObject(String key) {
S3Object object = context.getApi().newS3Object();
S3Object object = getApi().newS3Object();
object.getMetadata().setKey(key);
return object;
}
@ -78,7 +78,7 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
object.getMetadata().setContentType(contentType);
object.setPayload(data);
object.setContentLength(new Long(data.available()));
return context.getApi().putObject(bucket, object) != null;
return getApi().putObject(bucket, object) != null;
}
@Override
@ -87,6 +87,6 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
S3Object object = newObject(key);
object.getMetadata().setContentType(contentType);
object.setPayload(data);
return context.getApi().putObject(bucket, object) != null;
return getApi().putObject(bucket, object) != null;
}
}

View File

@ -44,8 +44,7 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
public abstract class BasePerformanceLiveTest extends
BaseBlobStoreIntegrationTest<S3AsyncClient, S3Client> {
public abstract class BasePerformanceLiveTest extends BaseBlobStoreIntegrationTest {
static {
containerCount = 1;
}
@ -77,6 +76,10 @@ public abstract class BasePerformanceLiveTest extends
}
}
public S3Client getApi() {
return (S3Client) context.getProviderSpecificContext().getApi();
}
/**
* using scratch containerName as we are changing location
*
@ -87,7 +90,7 @@ public abstract class BasePerformanceLiveTest extends
protected String createScratchContainerInEU() throws InterruptedException, ExecutionException,
TimeoutException {
String containerName = getScratchContainerName();
context.getApi().putBucketInRegion(Region.EU_WEST_1, containerName);
getApi().putBucketInRegion(Region.EU_WEST_1, containerName);
return containerName;
}

View File

@ -21,8 +21,6 @@ package org.jclouds.azure.storage.blob.blobstore;
import java.net.URI;
import java.util.Properties;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -43,21 +41,19 @@ import com.google.inject.Module;
* @see AzureBlobStoreContext
*/
public class AzureBlobStoreContextFactory {
public static BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createContext(
Properties properties, Module... modules) {
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(properties).build())
.withModules(modules).buildContext();
.withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createContext(String user,
String encodedKey, Module... modules) {
public static BlobStoreContext createContext(String user, String encodedKey, Module... modules) {
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
.build()).withModules(modules).buildContext();
.build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createContext(
URI endpoint, String user, String encodedKey, Module... modules) {
public static BlobStoreContext createContext(URI endpoint, String user, String encodedKey,
Module... modules) {
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
.withEndpoint(endpoint).build()).withModules(modules).buildContext();
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
}
}

View File

@ -18,31 +18,25 @@
*/
package org.jclouds.azure.storage.blob.blobstore.config;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.blobstore.AzureAsyncBlobStore;
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStore;
import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties;
import org.jclouds.azure.storage.blob.config.AzureBlobModule;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.azure.storage.blob.config.AzureBlobContextModule;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.InputStreamMap;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -50,13 +44,12 @@ import com.google.inject.Provides;
*
* @author Adrian Cole
*/
public class AzureBlobStoreContextModule extends AbstractModule {
public class AzureBlobStoreContextModule extends AzureBlobContextModule {
@Override
protected void configure() {
install(new BlobStoreObjectModule());
super.configure();
install(new BlobStoreMapModule());
install(new AzureBlobModule());
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).asEagerSingleton();
bind(BlobStore.class).to(AzureBlobStore.class).asEagerSingleton();
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
@ -64,14 +57,12 @@ public class AzureBlobStoreContextModule extends AbstractModule {
@Provides
@Singleton
BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> provideContext(
BlobMap.Factory blobMapFactory, InputStreamMap.Factory inputStreamMapFactory,
Closer closer, AsyncBlobStore asyncBlobStore, BlobStore blobStore,
AzureBlobAsyncClient asyncApi, AzureBlobClient defaultApi, @AzureBlob URI endPoint,
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
AsyncBlobStore asynchBlobStore, BlobStore blobStore,
RestContext<AzureBlobAsyncClient, AzureBlobClient> context) {
return new BlobStoreContextImpl<AzureBlobAsyncClient, AzureBlobClient>(blobMapFactory,
inputStreamMapFactory, closer, asyncBlobStore, blobStore, asyncApi, defaultApi,
endPoint, account);
inputStreamMapFactory, asynchBlobStore, blobStore, context);
}
}

View File

@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.List;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
import org.jclouds.azure.storage.blob.blobstore.config.AzureBlobStoreContextModule;
import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
@ -42,9 +41,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.testng.annotations.Test;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of modules configured in AzureBlobContextBuilder
@ -69,21 +66,22 @@ public class AzureBlobStoreContextBuilderTest {
}
public void testBuildContext() {
BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> context = newBuilder().buildContext();
BlobStoreContext context = newBuilder().buildBlobStoreContext();
assertEquals(context.getClass(), BlobStoreContextImpl.class);
assertEquals(context.getAsyncApi().getClass(), StubAzureBlobAsyncClient.class);
assertEquals(context.getProviderSpecificContext().getAsyncApi().getClass(),
StubAzureBlobAsyncClient.class);
assertEquals(context.getAsyncBlobStore().getClass(), AzureAsyncBlobStore.class);
assertEquals(context.getAsyncApi().newBlob().getClass(), AzureBlobImpl.class);
assertEquals(((AzureBlobAsyncClient) context.getProviderSpecificContext().getAsyncApi())
.newBlob().getClass(), AzureBlobImpl.class);
assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub"));
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
.create("https://localhost/azurestub"));
}
public void testBuildInjector() {
Injector i = newBuilder().buildInjector();
assert i.getInstance(Key
.get(new TypeLiteral<BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>>() {
})) != null;
assert i.getInstance(BlobStoreContext.class) != null;
assert i.getInstance(AzureBlob.class) != null;
assert i.getInstance(Blob.class) != null;
}

View File

@ -21,8 +21,6 @@ package org.jclouds.azure.storage.blob.blobstore.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties;
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
@ -37,8 +35,6 @@ import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
@ -70,14 +66,11 @@ public class AzureBlobStoreModuleTest {
void testContextImpl() {
Injector injector = createInjector();
BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> handler = injector.getInstance(Key
.get(new TypeLiteral<BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>>() {
}));
BlobStoreContext handler = injector.getInstance(BlobStoreContext.class);
assertEquals(handler.getClass(), BlobStoreContextImpl.class);
ContainsValueInListStrategy valueList = injector
.getInstance(ContainsValueInListStrategy.class);
assertEquals(valueList.getClass(), FindMD5InBlobProperties.class);
}
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.azure.storage.blob.blobstore.integration;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
import org.testng.annotations.Test;
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobContainerIntegrationTest")
public class AzureBlobContainerIntegrationTest extends
BaseContainerIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobContainerIntegrationTest extends BaseContainerIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.azure.storage.blob.blobstore.integration;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "azureblob.AzureBlobContainerLiveTest")
public class AzureBlobContainerLiveTest extends
BaseContainerLiveTest<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobContainerLiveTest extends BaseContainerLiveTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.azure.storage.blob.blobstore.integration;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobInputStreamMapIntegrationTest")
public class AzureBlobInputStreamMapIntegrationTest extends
BaseInputStreamMapIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
}

View File

@ -20,8 +20,6 @@ package org.jclouds.azure.storage.blob.blobstore.integration;
import java.io.UnsupportedEncodingException;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
import org.testng.annotations.Test;
@ -30,8 +28,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobIntegrationTest")
public class AzureBlobIntegrationTest extends
BaseBlobIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobIntegrationTest extends BaseBlobIntegrationTest {
@Override
public void testGetIfMatch() throws InterruptedException, UnsupportedEncodingException {

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.azure.storage.blob.blobstore.integration;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.blobstore.integration.internal.BaseBlobLiveTest;
import org.testng.annotations.Test;
@ -28,6 +26,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "azureblob.AzureBlobLiveTest")
public class AzureBlobLiveTest extends BaseBlobLiveTest<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobLiveTest extends BaseBlobLiveTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.azure.storage.blob.blobstore.integration;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobMapIntegrationTest")
public class AzureBlobMapIntegrationTest extends
BaseBlobMapIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.azure.storage.blob.blobstore.integration;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobServiceIntegrationTest")
public class AzureBlobServiceIntegrationTest extends
BaseServiceIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobServiceIntegrationTest extends BaseServiceIntegrationTest {
}

View File

@ -21,8 +21,6 @@ package org.jclouds.azure.storage.blob.blobstore.integration;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStoreContextFactory;
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
import org.jclouds.blobstore.BlobStoreContext;
@ -37,21 +35,18 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class AzureBlobTestInitializer extends
BaseTestInitializer<AzureBlobAsyncClient, AzureBlobClient> {
public class AzureBlobTestInitializer extends BaseTestInitializer {
@SuppressWarnings("unchecked")
@Override
protected BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createLiveContext(
Module configurationModule, String url, String app, String account, String key)
throws IOException {
return (BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>) new BlobStoreContextFactory()
.createContext("azureblob", account, key, ImmutableSet.of(configurationModule,
new Log4JLoggingModule()), new Properties());
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
String account, String key) throws IOException {
return (BlobStoreContext) new BlobStoreContextFactory().createContext("azureblob", account,
key, ImmutableSet.of(configurationModule, new Log4JLoggingModule()),
new Properties());
}
@Override
protected BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createStubContext() {
protected BlobStoreContext createStubContext() {
return AzureBlobStoreContextFactory.createContext("user", "pass",
new AzureBlobStubClientModule());
}

View File

@ -32,7 +32,7 @@ import com.google.inject.ImplementedBy;
*
*/
@ImplementedBy(BlobStoreContextImpl.class)
public interface BlobStoreContext<A, S> extends RestContext<A, S> {
public interface BlobStoreContext {
/**
* Creates a <code>Map<String,InputStream></code> view of the specified container.
@ -53,4 +53,8 @@ public interface BlobStoreContext<A, S> extends RestContext<A, S> {
BlobStore getBlobStore();
ConsistencyModels getConsistencyModel();
<A, S> RestContext<A, S> getProviderSpecificContext();
void close();
}

View File

@ -21,6 +21,7 @@ package org.jclouds.blobstore;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Key;
@ -52,11 +53,10 @@ public abstract class BlobStoreContextBuilder<A, S> extends RestContextBuilder<A
}
@SuppressWarnings("unchecked")
@Override
public BlobStoreContext<A, S> buildContext() {
return (BlobStoreContext<A, S>) this.buildInjector().getInstance(
Key.get(Types.newParameterizedType(BlobStoreContext.class,
asyncClientType.getType(), syncClientType.getType())));
public BlobStoreContext buildBlobStoreContext() {
// need the generic type information
return (BlobStoreContext) buildInjector().getInstance(
Key.get(Types.newParameterizedType(BlobStoreContextImpl.class, asyncClientType
.getType(), syncClientType.getType())));
}
}

View File

@ -31,7 +31,7 @@ import org.jclouds.rest.RestContextFactory;
* @author Adrian Cole
*/
public class BlobStoreContextFactory extends
RestContextFactory<BlobStoreContext<?, ?>, BlobStoreContextBuilder<?, ?>> {
RestContextFactory<BlobStoreContext, BlobStoreContextBuilder<?, ?>> {
/**
* Initializes with the default properties built-in to jclouds. This is typically stored in the
@ -53,4 +53,9 @@ public class BlobStoreContextFactory extends
public BlobStoreContextFactory(Properties properties) {
super(properties);
}
@Override
protected BlobStoreContext build(BlobStoreContextBuilder<?, ?> contextBuilder) {
return contextBuilder.buildBlobStoreContext();
}
}

View File

@ -20,7 +20,7 @@ package org.jclouds.blobstore.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
@ -31,33 +31,35 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.attr.ConsistencyModels;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.util.BlobStoreUtils;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.rest.RestContext;
/**
* @author Adrian Cole
*/
public class BlobStoreContextImpl<A, S> extends RestContextImpl<A, S> implements
BlobStoreContext<A, S> {
public class BlobStoreContextImpl<X, Y> implements BlobStoreContext {
private final BlobMap.Factory blobMapFactory;
private final InputStreamMap.Factory inputStreamMapFactory;
private final AsyncBlobStore ablobStore;
private final BlobStore blobStore;
private final ConsistencyModels consistencyModel;
private final RestContext<X, Y> providerSpecificContext;
@Inject
public BlobStoreContextImpl(BlobMap.Factory blobMapFactory,
InputStreamMap.Factory inputStreamMapFactory, Closer closer, AsyncBlobStore ablobStore,
BlobStore blobStore, A asyncApi, S syncApi, URI endPoint, String account) {
super(closer, asyncApi, syncApi, endPoint, account);
InputStreamMap.Factory inputStreamMapFactory, AsyncBlobStore ablobStore,
BlobStore blobStore, RestContext<X, Y> providerSpecificContext) {
this.providerSpecificContext = providerSpecificContext;
Class<?> type;
if (asyncApi.getClass().isAnnotationPresent(ConsistencyModel.class)) {
type = asyncApi.getClass();
} else if (asyncApi.getClass().getInterfaces().length > 0
&& asyncApi.getClass().getInterfaces()[0]
if (providerSpecificContext.getAsyncApi().getClass().isAnnotationPresent(
ConsistencyModel.class)) {
type = providerSpecificContext.getAsyncApi().getClass();
} else if (providerSpecificContext.getAsyncApi().getClass().getInterfaces().length > 0
&& providerSpecificContext.getAsyncApi().getClass().getInterfaces()[0]
.isAnnotationPresent(ConsistencyModel.class)) {
type = asyncApi.getClass().getInterfaces()[0];
type = providerSpecificContext.getAsyncApi().getClass().getInterfaces()[0];
} else {
throw new IllegalStateException("@ConsistencyModel needed on " + asyncApi.getClass());
throw new IllegalStateException("@ConsistencyModel needed on "
+ providerSpecificContext.getAsyncApi().getClass());
}
this.consistencyModel = type.getAnnotation(ConsistencyModel.class).value();
this.blobMapFactory = checkNotNull(blobMapFactory, "blobMapFactory");
@ -98,4 +100,15 @@ public class BlobStoreContextImpl<A, S> extends RestContextImpl<A, S> implements
public ConsistencyModels getConsistencyModel() {
return consistencyModel;
}
@SuppressWarnings("unchecked")
@Override
public <A, S> RestContext<A, S> getProviderSpecificContext() {
return (RestContext<A, S>) providerSpecificContext;
}
@Override
public void close() {
providerSpecificContext.close();
}
}

View File

@ -48,10 +48,10 @@ public interface BlobStoreConstants {
public static final String PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX = "jclouds.blobstore.directorysuffix";
/**
* comma-separated, fully qualified class names of implementations of BlobStoreContextBuilder
* comma-separated hints from {@code blobstore.properties}
*
*/
public static final String PROPERTY_BLOBSTORE_CONTEXTBUILDERS = "jclouds.blobstore.contextbuilders";
public static final String PROPERTY_BLOBSTORE_CONTEXTS = "jclouds.blobstore.contexts";
/**
* longest time a single synchronous operation can take before throwing an exception.

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.blobstore.integration;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
import org.testng.annotations.Test;
@ -29,6 +27,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration" }, testName = "blobstore.StubBlobIntegrationTest")
public class StubBlobIntegrationTest extends BaseBlobIntegrationTest<AsyncBlobStore, BlobStore> {
public class StubBlobIntegrationTest extends BaseBlobIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.blobstore.integration;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
import org.testng.annotations.Test;
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubBlobMapIntegrationTest")
public class StubBlobMapIntegrationTest extends
BaseBlobMapIntegrationTest<AsyncBlobStore, BlobStore> {
public class StubBlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
}

View File

@ -26,19 +26,17 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextBuilder;
import org.jclouds.blobstore.InputStreamMap;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.concurrent.Timeout;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
@ -91,11 +89,9 @@ public class StubBlobStoreContextBuilder extends BlobStoreContextBuilder<AsyncBl
@SuppressWarnings("unused")
@Provides
@Singleton
BlobStoreContext<AsyncBlobStore, BlobStore> provideContext(BlobMap.Factory blobMapFactory,
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
AsyncBlobStore asynch, BlobStore synch) {
return new BlobStoreContextImpl<AsyncBlobStore, BlobStore>(blobMapFactory,
inputStreamMapFactory, closer, asynch, synch, asynch, synch, URI
RestContext<AsyncBlobStore, BlobStore> provideContext(Closer closer,
final AsyncBlobStore async, final BlobStore sync) {
return new RestContextImpl<AsyncBlobStore, BlobStore>(closer, async, sync, URI
.create("http://localhost/blobstub"), "foo");
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.blobstore.integration;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
import org.testng.annotations.Test;
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubContainerIntegrationTest")
public class StubContainerIntegrationTest extends
BaseContainerIntegrationTest<AsyncBlobStore, BlobStore> {
public class StubContainerIntegrationTest extends BaseContainerIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.blobstore.integration;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubInputStreamMapIntegrationTest")
public class StubInputStreamMapIntegrationTest extends
BaseInputStreamMapIntegrationTest<AsyncBlobStore, BlobStore> {
public class StubInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.blobstore.integration;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
import org.testng.annotations.Test;
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubServiceIntegrationTest")
public class StubServiceIntegrationTest extends
BaseServiceIntegrationTest<AsyncBlobStore, BlobStore> {
public class StubServiceIntegrationTest extends BaseServiceIntegrationTest {
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.blobstore.integration;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.integration.internal.BaseTestInitializer;
@ -29,17 +27,17 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class StubTestInitializer extends BaseTestInitializer<AsyncBlobStore, BlobStore> {
public class StubTestInitializer extends BaseTestInitializer {
@Override
protected BlobStoreContext<AsyncBlobStore, BlobStore> createLiveContext(
Module configurationModule, String url, String app, String account, String key) {
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
String account, String key) {
return createStubContext();
}
@Override
protected BlobStoreContext<AsyncBlobStore, BlobStore> createStubContext() {
return new StubBlobStoreContextBuilder().buildContext();
protected BlobStoreContext createStubContext() {
return new StubBlobStoreContextBuilder().buildBlobStoreContext();
}
}

View File

@ -49,7 +49,7 @@ import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
public class BaseBlobIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
@Test(groups = { "integration", "live" })
public void testGetIfModifiedSince() throws InterruptedException {

View File

@ -39,7 +39,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "live" }, testName = "blobstore.BlobLiveTest")
public class BaseBlobLiveTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
public class BaseBlobLiveTest extends BaseBlobStoreIntegrationTest {
private static final String sysHttpStreamUrl = System
.getProperty("jclouds.blobstore.httpstream.url");

View File

@ -42,7 +42,7 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A, S, Blob> {
public class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<Blob> {
@Override
@Test(groups = { "integration", "live" })
@ -220,7 +220,6 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
map.putAll(newMap);
}
@SuppressWarnings("unchecked")
protected Map<String, Blob> createMap(BlobStoreContext context, String bucket) {
return context.createBlobMap(bucket);
}

View File

@ -54,7 +54,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Module;
public class BaseBlobStoreIntegrationTest<A, S> {
public class BaseBlobStoreIntegrationTest {
protected static final String LOCAL_ENCODING = System.getProperty("file.encoding");
protected static final String XML_STRING_FORMAT = "<apples><apple name=\"%s\"></apple> </apples>";
protected static final String TEST_STRING = String.format(XML_STRING_FORMAT, "apple");
@ -73,7 +73,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
public static long INCONSISTENCY_WINDOW = 5000;
protected static volatile AtomicInteger containerIndex = new AtomicInteger(0);
protected volatile BlobStoreContext<A, S> context;
protected volatile BlobStoreContext context;
protected static volatile int containerCount = 10;
public static final String CONTAINER_PREFIX = System.getProperty("user.name") + "-blobstore";
/**
@ -91,14 +91,14 @@ public class BaseBlobStoreIntegrationTest<A, S> {
}
@SuppressWarnings("unchecked")
private BlobStoreContext<A, S> getCloudResources(ITestContext testContext)
private BlobStoreContext getCloudResources(ITestContext testContext)
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
Exception {
String initializerClass = checkNotNull(System.getProperty("jclouds.test.initializer"),
"jclouds.test.initializer");
Class<BaseTestInitializer<A, S>> clazz = (Class<BaseTestInitializer<A, S>>) Class
Class<BaseTestInitializer> clazz = (Class<BaseTestInitializer>) Class
.forName(initializerClass);
BaseTestInitializer<A, S> initializer = clazz.newInstance();
BaseTestInitializer initializer = clazz.newInstance();
return initializer.init(createHttpModule(), testContext);
}
@ -125,7 +125,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
private static volatile boolean initialized = false;
protected void createContainersSharedByAllThreads(BlobStoreContext<A, S> context,
protected void createContainersSharedByAllThreads(BlobStoreContext context,
ITestContext testContext) throws Exception {
while (!initialized) {
synchronized (BaseBlobStoreIntegrationTest.class) {
@ -157,7 +157,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
}
}
private static void deleteContainerOrWarnIfUnable(BlobStoreContext<?, ?> context,
private static void deleteContainerOrWarnIfUnable(BlobStoreContext context,
String containerName) {
try {
deleteContainer(context, containerName);
@ -173,7 +173,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
/**
* Tries to delete all containers, runs up to two times
*/
protected static void deleteEverything(final BlobStoreContext<?, ?> context) throws Exception {
protected static void deleteEverything(final BlobStoreContext context) throws Exception {
try {
for (int i = 0; i < 2; i++) {
Iterable<? extends StorageMetadata> testContainers = Iterables.filter(context
@ -211,7 +211,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
* Due to eventual consistency, container commands may not return correctly immediately. Hence,
* we will try up to the inconsistency window to see if the assertion completes.
*/
protected static void assertConsistencyAware(BlobStoreContext<?, ?> context, Runnable assertion)
protected static void assertConsistencyAware(BlobStoreContext context, Runnable assertion)
throws InterruptedException {
if (context.getConsistencyModel() == ConsistencyModels.STRICT) {
assertion.run();
@ -237,7 +237,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
assertConsistencyAware(context, assertion);
}
protected static void createContainerAndEnsureEmpty(BlobStoreContext<?, ?> context,
protected static void createContainerAndEnsureEmpty(BlobStoreContext context,
final String containerName) throws InterruptedException {
context.getBlobStore().createContainerInLocation("default", containerName);
if (context.getConsistencyModel() == ConsistencyModels.EVENTUAL)
@ -384,7 +384,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
return new JavaUrlHttpCommandExecutorServiceModule();
}
protected static void deleteContainer(final BlobStoreContext<?, ?> context, final String name)
protected static void deleteContainer(final BlobStoreContext context, final String name)
throws InterruptedException {
if (context.getBlobStore().containerExists(name)) {
System.err.printf("*** deleting container %s...%n", name);

View File

@ -39,7 +39,7 @@ import com.google.common.base.Throwables;
/**
* @author Adrian Cole
*/
public class BaseContainerIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
@Test(groups = { "integration", "live" })
public void containerDoesntExist() {

View File

@ -22,6 +22,6 @@ package org.jclouds.blobstore.integration.internal;
*
* @author Adrian Cole
*/
public class BaseContainerLiveTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
public class BaseContainerLiveTest extends BaseBlobStoreIntegrationTest {
}

View File

@ -41,8 +41,7 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
public class BaseInputStreamMapIntegrationTest<A, S> extends
BaseMapIntegrationTest<A, S, InputStream> {
public class BaseInputStreamMapIntegrationTest extends BaseMapIntegrationTest<InputStream> {
@Override
@Test(groups = { "integration", "live" })
@ -191,7 +190,7 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
}
@Test(groups = { "integration", "live" })
public void testPutAllFiles() throws InterruptedException{
public void testPutAllFiles() throws InterruptedException {
String bucketName = getContainerName();
try {
Map<String, InputStream> map = createMap(context, bucketName);
@ -236,8 +235,7 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
}
void getOneReturnsAppleAndOldValueIsNull(Map<String, InputStream> map, InputStream old)
throws IOException, InterruptedException
{
throws IOException, InterruptedException {
assert old == null;
assertEquals(Utils.toStringAndClose(map.get("one")), String
.format(XML_STRING_FORMAT, "apple"));
@ -245,7 +243,7 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
}
void getOneReturnsBearAndOldValueIsApple(Map<String, InputStream> map, InputStream oldValue)
throws IOException, InterruptedException{
throws IOException, InterruptedException {
assertEquals(Utils.toStringAndClose(map.get("one")), String.format(XML_STRING_FORMAT, "bear"));
assertEquals(Utils.toStringAndClose(oldValue), String.format(XML_STRING_FORMAT, "apple"));
assertConsistencyAwareMapSize(map, 1);
@ -302,7 +300,7 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
((InputStreamMap) map).putString(key, value);
}
protected Map<String, InputStream> createMap(BlobStoreContext<?, ?> context, String bucket) {
protected Map<String, InputStream> createMap(BlobStoreContext context, String bucket) {
InputStreamMap map = context.createInputStreamMap(bucket);
return (Map<String, InputStream>) map;
}

View File

@ -46,7 +46,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
public abstract class BaseMapIntegrationTest<A, S, V> extends BaseBlobStoreIntegrationTest<A, S> {
public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegrationTest {
public abstract void testPutAll() throws InterruptedException, ExecutionException,
TimeoutException;
@ -94,7 +94,7 @@ public abstract class BaseMapIntegrationTest<A, S, V> extends BaseBlobStoreInteg
}
}
protected abstract Map<String, V> createMap(BlobStoreContext<?, ?> context, String bucket);
protected abstract Map<String, V> createMap(BlobStoreContext context, String bucket);
@Test(groups = { "integration", "live" })
public void testClear() throws InterruptedException, ExecutionException, TimeoutException {

View File

@ -28,7 +28,7 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
public class BaseServiceIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
@Test(groups = { "integration", "live" })
void containerDoesntExist() {

View File

@ -25,9 +25,9 @@ import org.testng.ITestContext;
import com.google.inject.Module;
public abstract class BaseTestInitializer<A, S> {
public abstract class BaseTestInitializer {
public BlobStoreContext<A, S> init(Module configurationModule, ITestContext testContext)
public BlobStoreContext init(Module configurationModule, ITestContext testContext)
throws Exception {
String endpoint = System.getProperty("jclouds.test.endpoint");
String app = System.getProperty("jclouds.test.app");
@ -48,8 +48,8 @@ public abstract class BaseTestInitializer<A, S> {
}
}
protected abstract BlobStoreContext<A, S> createStubContext();
protected abstract BlobStoreContext createStubContext();
protected abstract BlobStoreContext<A, S> createLiveContext(Module configurationModule,
String url, String app, String account, String key) throws IOException;
protected abstract BlobStoreContext createLiveContext(Module configurationModule, String url,
String app, String account, String key) throws IOException;
}

View File

@ -22,8 +22,6 @@ import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
@ -42,13 +40,13 @@ import com.google.inject.util.Types;
@Test(groups = { "unit" }, testName = "blobstore.BaseBlobMapTest")
public class BaseBlobMapTest {
BlobStoreContext<AsyncBlobStore, BlobStore> context;
BlobStoreContext context;
InputStreamMapImpl map;
@BeforeClass
void addDefaultObjectsSoThatTestsWillPass() {
context = new StubBlobStoreContextBuilder().buildContext();
context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
map = (InputStreamMapImpl) context.createInputStreamMap("test");
}

View File

@ -31,7 +31,11 @@ import com.google.inject.ImplementedBy;
*
*/
@ImplementedBy(ComputeServiceContextImpl.class)
public interface ComputeServiceContext<A, S> extends RestContext<A, S> {
public interface ComputeServiceContext {
ComputeService getComputeService();
<A, S> RestContext<A, S> getProviderSpecificContext();
void close();
}

View File

@ -21,6 +21,7 @@ package org.jclouds.compute;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Key;
@ -46,17 +47,16 @@ public abstract class ComputeServiceContextBuilder<A, S> extends RestContextBuil
this(asyncClientType, syncClientType, new Properties());
}
public ComputeServiceContextBuilder(TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType,
Properties properties) {
public ComputeServiceContextBuilder(TypeLiteral<A> asyncClientType,
TypeLiteral<S> syncClientType, Properties properties) {
super(asyncClientType, syncClientType, properties);
}
@SuppressWarnings("unchecked")
@Override
public ComputeServiceContext<A, S> buildContext() {
return (ComputeServiceContext<A, S>) this.buildInjector().getInstance(
Key.get(Types.newParameterizedType(ComputeServiceContext.class,
asyncClientType.getType(), syncClientType.getType())));
public ComputeServiceContext buildComputeServiceContext() {
// need the generic type information
return (ComputeServiceContext) buildInjector().getInstance(
Key.get(Types.newParameterizedType(ComputeServiceContextImpl.class, asyncClientType
.getType(), syncClientType.getType())));
}
}

View File

@ -31,7 +31,7 @@ import org.jclouds.rest.RestContextFactory;
* @author Adrian Cole
*/
public class ComputeServiceContextFactory extends
RestContextFactory<ComputeServiceContext<?, ?>, ComputeServiceContextBuilder<?, ?>> {
RestContextFactory<ComputeServiceContext, ComputeServiceContextBuilder<?, ?>> {
/**
* Initializes with the default properties built-in to jclouds. This is typically stored in the
@ -53,4 +53,9 @@ public class ComputeServiceContextFactory extends
public ComputeServiceContextFactory(Properties properties) {
super(properties);
}
@Override
protected ComputeServiceContext build(ComputeServiceContextBuilder<?, ?> contextBuilder) {
return contextBuilder.buildComputeServiceContext();
}
}

View File

@ -2,28 +2,38 @@ package org.jclouds.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.rest.RestContext;
/**
* @author Adrian Cole
*/
public class ComputeServiceContextImpl<A, S> extends RestContextImpl<A, S> implements
ComputeServiceContext<A, S> {
public class ComputeServiceContextImpl<X, Y> implements ComputeServiceContext {
private final ComputeService computeService;
private final RestContext<X, Y> providerSpecificContext;
public ComputeServiceContextImpl(Closer closer, ComputeService computeService, A asyncApi,
S syncApi, URI endPoint, String account) {
super(closer, asyncApi, syncApi, endPoint, account);
@Inject
public ComputeServiceContextImpl(ComputeService computeService,
RestContext<X, Y> providerSpecificContext) {
this.computeService = checkNotNull(computeService, "computeService");
this.providerSpecificContext = providerSpecificContext;
}
public ComputeService getComputeService() {
return computeService;
}
@SuppressWarnings("unchecked")
@Override
public <A, S> RestContext<A, S> getProviderSpecificContext() {
return (RestContext<A, S>) providerSpecificContext;
}
@Override
public void close() {
providerSpecificContext.close();
}
}

View File

@ -20,7 +20,10 @@ package org.jclouds.rest;
import java.net.URI;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.ImplementedBy;
/**
* Represents an authenticated context to the cloud.
@ -32,6 +35,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole
*
*/
@ImplementedBy(RestContextImpl.class)
public interface RestContext<A, S> {
/**

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.net.URI;
import java.util.Properties;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.jclouds.domain.Credentials;
@ -39,7 +40,7 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class RestContextFactory<T extends RestContext<?, ?>, B extends RestContextBuilder<?, ?>> {
public abstract class RestContextFactory<T, B extends RestContextBuilder<?, ?>> {
private final static Properties NO_PROPERTIES = new Properties();
private final Properties properties;
@ -115,23 +116,31 @@ public class RestContextFactory<T extends RestContext<?, ?>, B extends RestConte
return createContext(hint, account, key, ImmutableSet.<Module> of(), NO_PROPERTIES);
}
public T createContext(String hint, Properties overrides) {
return createContext(hint, null, null, ImmutableSet.<Module> of(), overrides);
}
public T createContext(String hint, Iterable<? extends Module> modules, Properties overrides) {
return createContext(hint, null, null, modules, overrides);
}
/**
*
* FIXME Comment this // ImmutableSet.<Module>of(new ExecutorServiceModule(myexecutor))
*
* @param hint
* @param account
* nullable, if credentials are present in the overrides
* @param key
* nullable, if credentials are present in the overrides
* @param modules
* @param overrides
* @return
*/
@SuppressWarnings("unchecked")
public T createContext(String hint, String account, String key,
public T createContext(String hint, @Nullable String account, @Nullable String key,
Iterable<? extends Module> modules, Properties overrides) {
checkNotNull(hint, "hint");
checkNotNull(account, "account");
checkNotNull(key, "key");
checkNotNull(modules, "modules");
checkNotNull(overrides, "overrides");
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
@ -147,12 +156,17 @@ public class RestContextFactory<T extends RestContext<?, ?>, B extends RestConte
.forName(propertiesBuilderClassName);
Class<B> contextBuilderClass = (Class<B>) Class.forName(contextBuilderClassName);
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(Properties.class)
.newInstance(overrides).withCredentials(account, key);
return (T) contextBuilderClass.getConstructor(Properties.class).newInstance(
builder.build()).withModules(Iterables.toArray(modules, Module.class))
.buildContext();
.newInstance(overrides);
if (key != null)
builder.withCredentials(account, key);
B contextBuilder = (B) contextBuilderClass.getConstructor(Properties.class).newInstance(
builder.build()).withModules(Iterables.toArray(modules, Module.class));
return build(contextBuilder);
} catch (Exception e) {
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
}
}
protected abstract T build(B contextBuilder);
}

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.URI;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.Logger;
@ -40,6 +41,7 @@ public class RestContextImpl<A, S> implements RestContext<A, S> {
private final URI endPoint;
private final String account;
@Inject
public RestContextImpl(Closer closer, A asyncApi, S syncApi, URI endPoint, String account) {
this.asyncApi = asyncApi;
this.syncApi = syncApi;

View File

@ -20,14 +20,14 @@ package org.jclouds.demo.tweetstore.config;
import static com.google.appengine.api.labs.taskqueue.TaskOptions.Builder.url;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS;
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@ -36,7 +36,7 @@ import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextBuilder;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses;
@ -55,9 +55,11 @@ import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import com.google.appengine.api.labs.taskqueue.Queue;
import com.google.appengine.api.labs.taskqueue.QueueFactory;
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
import com.google.appengine.repackaged.com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.io.Closeables;
import com.google.inject.Module;
/**
* Creates servlets (using resources from the {@link SpringAppConfig}) and mappings.
@ -69,46 +71,31 @@ import com.google.common.io.Closeables;
public class SpringServletConfig extends LoggingConfig implements ServletConfigAware {
private ServletConfig servletConfig;
private Map<String, BlobStoreContext<?, ?>> providerTypeToBlobStoreMap;
private Map<String, BlobStoreContext> providerTypeToBlobStoreMap;
private TwitterClient twitterClient;
private String container;
@SuppressWarnings("unchecked")
@PostConstruct
public void initialize() {
public void initialize() throws IOException {
Properties props = loadJCloudsProperties();
logger.trace("About to initialize members.");
Module googleModule = new GoogleAppEngineConfigurationModule();
Set<Module> modules = ImmutableSet.<Module> of(googleModule);
// shared across all blobstores and used to retrieve tweets
twitterClient = TwitterContextFactory.createContext(props,
new GoogleAppEngineConfigurationModule()).getApi();
twitterClient = TwitterContextFactory.createContext(props, googleModule).getApi();
// common namespace for storing tweets
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
PROPERTY_TWEETSTORE_CONTAINER);
ImmutableList<String> contextBuilderClassNames = ImmutableList.<String>of(
checkNotNull(props.getProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
PROPERTY_BLOBSTORE_CONTEXTBUILDERS)
.split(","));
BlobStoreContextFactory blobStoreContextFactory = new BlobStoreContextFactory();
// instantiate and store references to all blobstores by provider name
providerTypeToBlobStoreMap = Maps.newHashMap();
for (String className : contextBuilderClassNames) {
Class<BlobStoreContextBuilder<?, ?>> builderClass;
Constructor<BlobStoreContextBuilder<?, ?>> constructor;
String name;
BlobStoreContext<?, ?> context;
try {
builderClass = (Class<BlobStoreContextBuilder<?, ?>>) Class.forName(className);
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
constructor = builderClass.getConstructor(Properties.class);
context = constructor.newInstance(props)
.withModules(new GoogleAppEngineConfigurationModule())
.buildContext();
} catch (Exception e) {
throw new RuntimeException("error instantiating " + className, e);
}
providerTypeToBlobStoreMap.put(name, context);
for (String hint : Splitter.on(',').split(
checkNotNull(props.getProperty(PROPERTY_BLOBSTORE_CONTEXTS),
PROPERTY_BLOBSTORE_CONTEXTS))) {
providerTypeToBlobStoreMap.put(hint, blobStoreContextFactory.createContext(hint, modules,
props));
}
// get a queue for submitting store tweet requests
@ -117,15 +104,16 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
for (String name : providerTypeToBlobStoreMap.keySet()) {
queue.add(url("/store/do").header("context", name).method(Method.GET));
}
logger.trace("Members initialized. TwitterClient: '%s', container: '%s', provider types: '%s'",
logger.trace(
"Members initialized. TwitterClient: '%s', container: '%s', provider types: '%s'",
twitterClient, container, providerTypeToBlobStoreMap.keySet());
}
private Properties loadJCloudsProperties() {
logger.trace("About to read properties from '%s'", "/WEB-INF/jclouds.properties");
Properties props = new Properties();
InputStream input = servletConfig.getServletContext()
.getResourceAsStream("/WEB-INF/jclouds.properties");
InputStream input = servletConfig.getServletContext().getResourceAsStream(
"/WEB-INF/jclouds.properties");
try {
props.load(input);
} catch (IOException e) {
@ -176,8 +164,8 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
urlMap.put("/tweets/*", addTweetsController());
mapping.setUrlMap(urlMap);
/*
* "/store" and "/tweets" are part of the servlet mapping and thus stripped
* by the mapping if using default settings.
* "/store" and "/tweets" are part of the servlet mapping and thus stripped by the mapping if
* using default settings.
*/
mapping.setAlwaysUseFullPath(true);
return mapping;
@ -191,14 +179,18 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
@PreDestroy
public void destroy() throws Exception {
logger.trace("About to close contexts.");
for (BlobStoreContext<?, ?> context : providerTypeToBlobStoreMap.values()) {
for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) {
context.close();
}
logger.trace("Contexts closed.");
}
/* (non-Javadoc)
* @see org.springframework.web.context.ServletConfigAware#setServletConfig(javax.servlet.ServletConfig)
/*
* (non-Javadoc)
*
* @see
* org.springframework.web.context.ServletConfigAware#setServletConfig(javax.servlet.ServletConfig
* )
*/
@Override
public void setServletConfig(ServletConfig servletConfig) {

View File

@ -54,14 +54,14 @@ public class AddTweetsController extends HttpServlet implements
/** The serialVersionUID */
private static final long serialVersionUID = 3888348023150822683L;
private final Map<String, BlobStoreContext<?, ?>> contexts;
private final Map<String, BlobStoreContext> contexts;
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public AddTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
public AddTweetsController(Map<String, BlobStoreContext> contexts,
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
this.contexts = contexts;
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;

View File

@ -74,7 +74,7 @@ public class StoreTweetsController extends HttpServlet {
/** The serialVersionUID */
private static final long serialVersionUID = 7215420527854203714L;
private final Map<String, BlobStoreContext<?, ?>> contexts;
private final Map<String, BlobStoreContext> contexts;
private final TwitterClient client;
private final String container;
@ -83,7 +83,7 @@ public class StoreTweetsController extends HttpServlet {
@Inject
public StoreTweetsController(
Map<String, BlobStoreContext<?, ?>> contexts,
Map<String, BlobStoreContext> contexts,
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
TwitterClient client) {
this.container = container;
@ -93,7 +93,7 @@ public class StoreTweetsController extends HttpServlet {
@VisibleForTesting
void addMyTweets(String contextName, SortedSet<Status> allAboutMe) {
BlobStoreContext<?, ?> context = checkNotNull(contexts.get(contextName),
BlobStoreContext context = checkNotNull(contexts.get(contextName),
"no context for " + contextName + " in " + contexts.keySet());
BlobMap map = context.createBlobMap(container);
for (Status status : allAboutMe) {

View File

@ -39,11 +39,11 @@ import com.google.common.collect.Iterables;
@Singleton
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
private final Map<String, BlobStoreContext<?,?>> contexts;
private final Map<String, BlobStoreContext> contexts;
private final String container;
@Inject
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext<?,?>> contexts,
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext> contexts,
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
this.contexts = contexts;
this.container = container;
@ -53,8 +53,8 @@ public class ServiceToStoredTweetStatuses implements Function<String, Iterable<S
protected Logger logger = Logger.NULL;
public Iterable<StoredTweetStatus> apply(String service) {
BlobStoreContext<?, ?> context = contexts.get(service);
String host = context.getEndPoint().getHost();
BlobStoreContext context = contexts.get(service);
String host = context.getProviderSpecificContext().getEndPoint().getHost();
try {
BlobMap blobMap = context.createBlobMap(container);
Set<String> blobs = blobMap.keySet();

View File

@ -25,8 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
@ -47,12 +45,11 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit", testName = "tweetstore.AddTweetsControllerTest")
public class AddTweetsControllerTest {
Map<String, BlobStoreContext<?, ?>> createServices(String container)
throws InterruptedException, ExecutionException {
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
ExecutionException {
Map<String, BlobStoreContext> services = Maps.newHashMap();
for (String name : new String[] { "1", "2" }) {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext();
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
Blob blob = context.getAsyncBlobStore().newBlob("1");
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
@ -65,7 +62,7 @@ public class AddTweetsControllerTest {
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
String container = "container";
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
Map<String, BlobStoreContext> contexts = createServices(container);
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
AddTweetsController controller = new AddTweetsController(contexts, function);

View File

@ -54,19 +54,18 @@ public class StoreTweetsControllerTest {
return createMock(TwitterClient.class);
}
Map<String, BlobStoreContext<?, ?>> createBlobStores() throws InterruptedException,
ExecutionException {
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap
.<String, BlobStoreContext<?, ?>> of("test1", new StubBlobStoreContextBuilder()
.buildContext(), "test2", new StubBlobStoreContextBuilder().buildContext());
for (BlobStoreContext<?, ?> blobstore : contexts.values()) {
Map<String, BlobStoreContext> createBlobStores() throws InterruptedException, ExecutionException {
Map<String, BlobStoreContext> contexts = ImmutableMap.<String, BlobStoreContext> of("test1",
new StubBlobStoreContextBuilder().buildBlobStoreContext(), "test2",
new StubBlobStoreContextBuilder().buildBlobStoreContext());
for (BlobStoreContext blobstore : contexts.values()) {
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
}
return contexts;
}
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
Map<String, BlobStoreContext<?, ?>> stores = createBlobStores();
Map<String, BlobStoreContext> stores = createBlobStores();
StoreTweetsController function = new StoreTweetsController(stores, "favo",
createTwitterClient());
@ -91,7 +90,7 @@ public class StoreTweetsControllerTest {
function.addMyTweets("test1", allAboutMe);
function.addMyTweets("test2", allAboutMe);
for (Entry<String, BlobStoreContext<?, ?>> entry : stores.entrySet()) {
for (Entry<String, BlobStoreContext> entry : stores.entrySet()) {
BlobMap map = entry.getValue().createBlobMap("favo");
Blob frankBlob = map.get("1");
assertEquals(frankBlob.getMetadata().getName(), "1");

View File

@ -23,9 +23,7 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
@ -42,8 +40,7 @@ import org.testng.annotations.Test;
public class KeyToStoredTweetStatusTest {
BlobMap createMap() throws InterruptedException, ExecutionException {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext();
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
context.getBlobStore().createContainerInLocation(null, "test1");
return context.createBlobMap("test1");
}

View File

@ -24,8 +24,6 @@ import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
@ -44,12 +42,11 @@ import com.google.common.collect.Iterables;
@Test(groups = "unit", testName = "tweetstore.ServiceToStoredTweetStatuses")
public class ServiceToStoredTweetStatusesTest {
Map<String, BlobStoreContext<?, ?>> createServices(String container)
throws InterruptedException, ExecutionException {
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
ExecutionException {
Map<String, BlobStoreContext> services = Maps.newHashMap();
for (String name : new String[] { "1", "2" }) {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext();
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
Blob blob = context.getAsyncBlobStore().newBlob("1");
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
@ -62,7 +59,7 @@ public class ServiceToStoredTweetStatusesTest {
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
String container = "container";
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
Map<String, BlobStoreContext> contexts = createServices(container);
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);

View File

@ -23,7 +23,7 @@ import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS;
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_KEY;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER;
@ -39,13 +39,10 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.jclouds.aws.s3.S3PropertiesBuilder;
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder;
import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStoreContextBuilder;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder;
import org.jclouds.twitter.TwitterPropertiesBuilder;
import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass;
@ -66,7 +63,7 @@ public class TweetStoreLiveTest {
GoogleDevServer server;
private URL url;
private Iterable<BlobStoreContext<? extends Object, ? extends Object>> contexts;
private Iterable<BlobStoreContext> contexts;
private String container;
@BeforeTest
@ -77,11 +74,9 @@ public class TweetStoreLiveTest {
Properties props = new Properties();
props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, checkNotNull(System
.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER));
props.setProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS,
// WATCH THIS.. when adding a new context, you must update the string
String.format("%s,%s,%s", S3BlobStoreContextBuilder.class.getName(),
CloudFilesBlobStoreContextBuilder.class.getName(),
AzureBlobStoreContextBuilder.class.getName()));
props.setProperty(PROPERTY_BLOBSTORE_CONTEXTS, "cloudfiles,s3");
props = new TwitterPropertiesBuilder(props).withCredentials(
checkNotNull(System.getProperty(PROPERTY_TWITTER_USER), PROPERTY_TWITTER_USER),
@ -112,23 +107,25 @@ public class TweetStoreLiveTest {
TimeoutException, IOException {
container = checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER));
BlobStoreContextFactory factory = new BlobStoreContextFactory();
BlobStoreContext<?, ?> s3Context = factory.createContext("s3", checkNotNull(System
BlobStoreContext s3Context = factory.createContext("s3", checkNotNull(System
.getProperty(PROPERTY_AWS_ACCESSKEYID), PROPERTY_AWS_ACCESSKEYID), System
.getProperty(PROPERTY_AWS_SECRETACCESSKEY, PROPERTY_AWS_SECRETACCESSKEY));
BlobStoreContext<?, ?> cfContext = factory.createContext("cloudfiles", checkNotNull(System
BlobStoreContext cfContext = factory.createContext("cloudfiles", checkNotNull(System
.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER), System.getProperty(
PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY));
BlobStoreContext<?, ?> azContext = factory.createContext("azureblob", checkNotNull(System
.getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), PROPERTY_AZURESTORAGE_ACCOUNT), System
.getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY));
// BlobStoreContext azContext = factory.createContext("azureblob", checkNotNull(System
// .getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), PROPERTY_AZURESTORAGE_ACCOUNT), System
// .getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY));
this.contexts = ImmutableList.of(s3Context, cfContext, azContext);
// this.contexts = ImmutableList.of(s3Context, cfContext, azContext);
this.contexts = ImmutableList.of(s3Context, cfContext);
boolean deleted = false;
for (BlobStoreContext<?, ?> context : contexts) {
for (BlobStoreContext context : contexts) {
if (context.getBlobStore().containerExists(container)) {
System.err.printf("deleting container %s at %s%n", container, context.getEndPoint());
System.err.printf("deleting container %s at %s%n", container, context
.getProviderSpecificContext().getEndPoint());
context.getBlobStore().deleteContainer(container);
deleted = true;
}
@ -137,8 +134,9 @@ public class TweetStoreLiveTest {
System.err.println("sleeping 60 seconds to allow containers to clear");
Thread.sleep(60000);
}
for (BlobStoreContext<?, ?> context : contexts) {
System.err.printf("creating container %s at %s%n", container, context.getEndPoint());
for (BlobStoreContext context : contexts) {
System.err.printf("creating container %s at %s%n", container, context
.getProviderSpecificContext().getEndPoint());
context.getBlobStore().createContainerInLocation(null, container);
}
if (deleted) {
@ -162,8 +160,8 @@ public class TweetStoreLiveTest {
@Test(dependsOnMethods = "shouldFail")
public void testPrimeContainers() throws IOException, InterruptedException {
URL gurl = new URL(url, "/store/do");
for (String context : new String[] { "S3", "Azure", "CloudFiles" }) {
// WATCH THIS, you need to add a context each time
for (String context : new String[] { "cloudfiles", "s3" }) {
System.out.println("storing at context: " + context);
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection();
connection.addRequestProperty("X-AppEngine-QueueName", "twitter");
@ -176,8 +174,9 @@ public class TweetStoreLiveTest {
System.err.println("sleeping 20 seconds to allow for eventual consistency delay");
Thread.sleep(20000);
for (BlobStoreContext<?, ?> context : contexts) {
assert context.createInputStreamMap(container).size() > 0 : context.getEndPoint();
for (BlobStoreContext context : contexts) {
assert context.createInputStreamMap(container).size() > 0 : context
.getProviderSpecificContext().getEndPoint();
}
}

View File

@ -20,19 +20,19 @@ package org.jclouds.demo.tweetstore.config;
import static com.google.appengine.api.labs.taskqueue.TaskOptions.Builder.url;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS;
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.servlet.ServletContextEvent;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextBuilder;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
@ -42,11 +42,14 @@ import org.jclouds.twitter.TwitterContextFactory;
import com.google.appengine.api.labs.taskqueue.Queue;
import com.google.appengine.api.labs.taskqueue.QueueFactory;
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
import com.google.appengine.repackaged.com.google.common.base.Splitter;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.io.Closeables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
@ -59,44 +62,38 @@ import com.google.inject.util.Jsr330;
*/
public class GuiceServletConfig extends GuiceServletContextListener {
private Map<String, BlobStoreContext<?, ?>> providerTypeToBlobStoreMap;
private Map<String, BlobStoreContext> providerTypeToBlobStoreMap;
private TwitterClient twitterClient;
private String container;
@SuppressWarnings("unchecked")
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
BlobStoreContextFactory blobStoreContextFactory = null;
try {
blobStoreContextFactory = new BlobStoreContextFactory();
} catch (IOException e) {
Throwables.propagate(e);
}
Properties props = loadJCloudsProperties(servletContextEvent);
Module googleModule = new GoogleAppEngineConfigurationModule();
Set<Module> modules = ImmutableSet.<Module> of(googleModule);
// shared across all blobstores and used to retrieve tweets
twitterClient = TwitterContextFactory.createContext(props,
new GoogleAppEngineConfigurationModule()).getApi();
twitterClient = TwitterContextFactory.createContext(props, googleModule).getApi();
// common namespace for storing tweets.
// common namespace for storing tweets
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
PROPERTY_TWEETSTORE_CONTAINER);
ImmutableList<String> contextBuilderClassNames = ImmutableList.<String> of(checkNotNull(
props.getProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
PROPERTY_BLOBSTORE_CONTEXTBUILDERS).split(","));
// instantiate and store references to all blobstores by provider name
providerTypeToBlobStoreMap = Maps.newHashMap();
for (String className : contextBuilderClassNames) {
Class<BlobStoreContextBuilder<?, ?>> builderClass;
Constructor<BlobStoreContextBuilder<?, ?>> constructor;
String name;
BlobStoreContext<?, ?> context;
try {
builderClass = (Class<BlobStoreContextBuilder<?, ?>>) Class.forName(className);
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
constructor = builderClass.getConstructor(Properties.class);
context = constructor.newInstance(props).withModules(
new GoogleAppEngineConfigurationModule()).buildContext();
} catch (Exception e) {
throw new RuntimeException("error instantiating " + className, e);
}
providerTypeToBlobStoreMap.put(name, context);
for (String hint : Splitter.on(',').split(
checkNotNull(props.getProperty(PROPERTY_BLOBSTORE_CONTEXTS),
PROPERTY_BLOBSTORE_CONTEXTS))) {
providerTypeToBlobStoreMap.put(hint, blobStoreContextFactory.createContext(hint, modules,
props));
}
// get a queue for submitting store tweet requests
@ -128,8 +125,8 @@ public class GuiceServletConfig extends GuiceServletContextListener {
return Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
bind(new TypeLiteral<Map<String, BlobStoreContext<?, ?>>>() {})
.toInstance(providerTypeToBlobStoreMap);
bind(new TypeLiteral<Map<String, BlobStoreContext>>() {
}).toInstance(providerTypeToBlobStoreMap);
bind(TwitterClient.class).toInstance(twitterClient);
bindConstant().annotatedWith(Jsr330.named(PROPERTY_TWEETSTORE_CONTAINER)).to(container);
serve("/store/*").with(StoreTweetsController.class);
@ -140,7 +137,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
for (BlobStoreContext<?, ?> context : providerTypeToBlobStoreMap.values()) {
for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) {
context.close();
}
super.contextDestroyed(servletContextEvent);

View File

@ -54,14 +54,14 @@ public class AddTweetsController extends HttpServlet implements
/** The serialVersionUID */
private static final long serialVersionUID = 3888348023150822683L;
private final Map<String, BlobStoreContext<?, ?>> contexts;
private final Map<String, BlobStoreContext> contexts;
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
@Resource
protected Logger logger = Logger.NULL;
@Inject
AddTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
AddTweetsController(Map<String, BlobStoreContext> contexts,
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
this.contexts = contexts;
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;

View File

@ -73,7 +73,7 @@ public class StoreTweetsController extends HttpServlet {
/** The serialVersionUID */
private static final long serialVersionUID = 7215420527854203714L;
private final Map<String, BlobStoreContext<?, ?>> contexts;
private final Map<String, BlobStoreContext> contexts;
private final TwitterClient client;
private final String container;
@ -82,7 +82,7 @@ public class StoreTweetsController extends HttpServlet {
@Inject
@VisibleForTesting
StoreTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
StoreTweetsController(Map<String, BlobStoreContext> contexts,
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
TwitterClient client) {
this.container = container;
@ -92,7 +92,7 @@ public class StoreTweetsController extends HttpServlet {
@VisibleForTesting
void addMyTweets(String contextName, SortedSet<Status> allAboutMe) {
BlobStoreContext<?, ?> context = checkNotNull(contexts.get(contextName), "no context for "
BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for "
+ contextName + " in " + contexts.keySet());
BlobMap map = context.createBlobMap(container);
for (Status status : allAboutMe) {

View File

@ -39,11 +39,11 @@ import com.google.common.collect.Iterables;
@Singleton
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
private final Map<String, BlobStoreContext<?,?>> contexts;
private final Map<String, BlobStoreContext> contexts;
private final String container;
@Inject
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext<?,?>> contexts,
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext> contexts,
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
this.contexts = contexts;
this.container = container;
@ -53,8 +53,8 @@ public class ServiceToStoredTweetStatuses implements Function<String, Iterable<S
protected Logger logger = Logger.NULL;
public Iterable<StoredTweetStatus> apply(String service) {
BlobStoreContext<?, ?> context = contexts.get(service);
String host = context.getEndPoint().getHost();
BlobStoreContext context = contexts.get(service);
String host = context.getProviderSpecificContext().getEndPoint().getHost();
try {
BlobMap blobMap = context.createBlobMap(container);
Set<String> blobs = blobMap.keySet();

View File

@ -25,8 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
@ -47,12 +45,11 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit", testName = "tweetstore.AddTweetsControllerTest")
public class AddTweetsControllerTest {
Map<String, BlobStoreContext<?, ?>> createServices(String container)
throws InterruptedException, ExecutionException {
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
ExecutionException {
Map<String, BlobStoreContext> services = Maps.newHashMap();
for (String name : new String[] { "1", "2" }) {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext();
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
Blob blob = context.getAsyncBlobStore().newBlob("1");
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
@ -65,7 +62,7 @@ public class AddTweetsControllerTest {
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
String container = "container";
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
Map<String, BlobStoreContext> contexts = createServices(container);
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
AddTweetsController controller = new AddTweetsController(contexts, function);

View File

@ -54,19 +54,18 @@ public class StoreTweetsControllerTest {
return createMock(TwitterClient.class);
}
Map<String, BlobStoreContext<?, ?>> createBlobStores() throws InterruptedException,
ExecutionException {
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap
.<String, BlobStoreContext<?, ?>> of("test1", new StubBlobStoreContextBuilder()
.buildContext(), "test2", new StubBlobStoreContextBuilder().buildContext());
for (BlobStoreContext<?, ?> blobstore : contexts.values()) {
Map<String, BlobStoreContext> createBlobStores() throws InterruptedException, ExecutionException {
Map<String, BlobStoreContext> contexts = ImmutableMap.<String, BlobStoreContext> of("test1",
new StubBlobStoreContextBuilder().buildBlobStoreContext(), "test2",
new StubBlobStoreContextBuilder().buildBlobStoreContext());
for (BlobStoreContext blobstore : contexts.values()) {
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
}
return contexts;
}
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
Map<String, BlobStoreContext<?, ?>> stores = createBlobStores();
Map<String, BlobStoreContext> stores = createBlobStores();
StoreTweetsController function = new StoreTweetsController(stores, "favo",
createTwitterClient());
@ -91,7 +90,7 @@ public class StoreTweetsControllerTest {
function.addMyTweets("test1", allAboutMe);
function.addMyTweets("test2", allAboutMe);
for (Entry<String, BlobStoreContext<?, ?>> entry : stores.entrySet()) {
for (Entry<String, BlobStoreContext> entry : stores.entrySet()) {
BlobMap map = entry.getValue().createBlobMap("favo");
Blob frankBlob = map.get("1");
assertEquals(frankBlob.getMetadata().getName(), "1");

View File

@ -23,9 +23,7 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
@ -42,8 +40,7 @@ import org.testng.annotations.Test;
public class KeyToStoredTweetStatusTest {
BlobMap createMap() throws InterruptedException, ExecutionException {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext();
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
context.getBlobStore().createContainerInLocation(null, "test1");
return context.createBlobMap("test1");
}

View File

@ -24,8 +24,6 @@ import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
@ -44,12 +42,11 @@ import com.google.common.collect.Iterables;
@Test(groups = "unit", testName = "tweetstore.ServiceToStoredTweetStatuses")
public class ServiceToStoredTweetStatusesTest {
Map<String, BlobStoreContext<?, ?>> createServices(String container)
throws InterruptedException, ExecutionException {
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
ExecutionException {
Map<String, BlobStoreContext> services = Maps.newHashMap();
for (String name : new String[] { "1", "2" }) {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext();
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
Blob blob = context.getAsyncBlobStore().newBlob("1");
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
@ -62,7 +59,7 @@ public class ServiceToStoredTweetStatusesTest {
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
String container = "container";
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
Map<String, BlobStoreContext> contexts = createServices(container);
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);

Some files were not shown because too many files have changed in this diff Show More