mirror of https://github.com/apache/jclouds.git
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:
parent
fd5147e09f
commit
9b39988ad7
|
@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
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.atmosonline.saas.AtmosStoragePropertiesBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
@ -43,21 +41,19 @@ import com.google.inject.Module;
|
||||||
* @see AtmosBlobStoreContext
|
* @see AtmosBlobStoreContext
|
||||||
*/
|
*/
|
||||||
public class AtmosBlobStoreContextFactory {
|
public class AtmosBlobStoreContextFactory {
|
||||||
public static BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createContext(
|
public static BlobStoreContext createContext(Properties properties, Module... modules) {
|
||||||
Properties properties, Module... modules) {
|
|
||||||
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(properties).build())
|
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(properties).build())
|
||||||
.withModules(modules).buildContext();
|
.withModules(modules).buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createContext(
|
public static BlobStoreContext createContext(String uid, String key, Module... modules) {
|
||||||
String uid, String key, Module... modules) {
|
|
||||||
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(uid, key).build())
|
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(uid, key).build())
|
||||||
.withModules(modules).buildContext();
|
.withModules(modules).buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createContext(
|
public static BlobStoreContext createContext(URI endpoint, String uid, String key,
|
||||||
URI endpoint, String uid, String key, Module... modules) {
|
Module... modules) {
|
||||||
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(uid, key)
|
return new AtmosBlobStoreContextBuilder(new AtmosStoragePropertiesBuilder(uid, key)
|
||||||
.withEndpoint(endpoint).build()).withModules(modules).buildContext();
|
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,34 +18,28 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.blobstore.config;
|
package org.jclouds.atmosonline.saas.blobstore.config;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorage;
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
|
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorageClient;
|
import org.jclouds.atmosonline.saas.AtmosStorageClient;
|
||||||
import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore;
|
import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore;
|
||||||
import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStore;
|
import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStore;
|
||||||
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
|
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
|
||||||
import org.jclouds.atmosonline.saas.blobstore.strategy.RecursiveRemove;
|
import org.jclouds.atmosonline.saas.blobstore.strategy.RecursiveRemove;
|
||||||
import org.jclouds.atmosonline.saas.config.AtmosObjectModule;
|
import org.jclouds.atmosonline.saas.config.AtmosStorageContextModule;
|
||||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.InputStreamMap;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.blobstore.strategy.ClearContainerStrategy;
|
import org.jclouds.blobstore.strategy.ClearContainerStrategy;
|
||||||
import org.jclouds.blobstore.strategy.ClearListStrategy;
|
import org.jclouds.blobstore.strategy.ClearListStrategy;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,13 +47,12 @@ import com.google.inject.Provides;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AtmosBlobStoreContextModule extends AbstractModule {
|
public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreObjectModule());
|
super.configure();
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
install(new AtmosObjectModule());
|
|
||||||
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).asEagerSingleton();
|
||||||
bind(BlobStore.class).to(AtmosBlobStore.class).asEagerSingleton();
|
bind(BlobStore.class).to(AtmosBlobStore.class).asEagerSingleton();
|
||||||
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
|
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
|
||||||
|
@ -69,13 +62,12 @@ public class AtmosBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> provideContext(
|
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
|
||||||
BlobMap.Factory blobMapFactory, InputStreamMap.Factory inputStreamMapFactory,
|
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
||||||
Closer closer, AsyncBlobStore asynchBlobStore, BlobStore blobStore, AtmosStorageAsyncClient async,
|
AsyncBlobStore asynchBlobStore, BlobStore blobStore,
|
||||||
AtmosStorageClient defaultApi, @AtmosStorage URI endPoint,
|
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> context) {
|
||||||
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) {
|
|
||||||
return new BlobStoreContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>(blobMapFactory,
|
return new BlobStoreContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>(blobMapFactory,
|
||||||
inputStreamMapFactory, closer, asynchBlobStore, blobStore, async, defaultApi, endPoint, account);
|
inputStreamMapFactory, asynchBlobStore, blobStore, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
|
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorageClient;
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
|
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
|
||||||
import org.jclouds.atmosonline.saas.blobstore.config.AtmosBlobStoreContextModule;
|
import org.jclouds.atmosonline.saas.blobstore.config.AtmosBlobStoreContextModule;
|
||||||
import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
|
import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
|
||||||
|
@ -42,9 +41,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of modules configured in AtmosStorageContextBuilder
|
* Tests behavior of modules configured in AtmosStorageContextBuilder
|
||||||
|
@ -69,23 +66,22 @@ public class AtmosBlobStoreContextBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBuildContext() {
|
public void testBuildContext() {
|
||||||
BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> context = newBuilder()
|
BlobStoreContext context = newBuilder().buildBlobStoreContext();
|
||||||
.buildContext();
|
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
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.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.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
|
||||||
assertEquals(context.getAccount(), "id");
|
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub"));
|
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
|
||||||
|
.create("https://localhost/azurestub"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBuildInjector() {
|
public void testBuildInjector() {
|
||||||
Injector i = newBuilder().buildInjector();
|
Injector i = newBuilder().buildInjector();
|
||||||
assert i
|
assert i.getInstance(BlobStoreContext.class) != null;
|
||||||
.getInstance(Key
|
|
||||||
.get(new TypeLiteral<BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient>>() {
|
|
||||||
})) != null;
|
|
||||||
assert i.getInstance(AtmosObject.class) != null;
|
assert i.getInstance(AtmosObject.class) != null;
|
||||||
assert i.getInstance(Blob.class) != null;
|
assert i.getInstance(Blob.class) != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.config;
|
||||||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||||
import static org.testng.Assert.assertEquals;
|
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.blobstore.strategy.FindMD5InUserMetadata;
|
||||||
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
|
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
|
||||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
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.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -67,10 +63,7 @@ public class AtmosBlobStoreModuleTest {
|
||||||
void testContextImpl() {
|
void testContextImpl() {
|
||||||
|
|
||||||
Injector injector = createInjector();
|
Injector injector = createInjector();
|
||||||
BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> handler = injector
|
BlobStoreContext handler = injector.getInstance(BlobStoreContext.class);
|
||||||
.getInstance(Key
|
|
||||||
.get(new TypeLiteral<BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient>>() {
|
|
||||||
}));
|
|
||||||
assertEquals(handler.getClass(), BlobStoreContextImpl.class);
|
assertEquals(handler.getClass(), BlobStoreContextImpl.class);
|
||||||
ContainsValueInListStrategy valueList = injector
|
ContainsValueInListStrategy valueList = injector
|
||||||
.getInstance(ContainsValueInListStrategy.class);
|
.getInstance(ContainsValueInListStrategy.class);
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,8 +25,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageContainerIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageContainerIntegrationTest")
|
||||||
public class AtmosStorageContainerIntegrationTest extends
|
public class AtmosStorageContainerIntegrationTest extends BaseContainerIntegrationTest {
|
||||||
BaseContainerIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "emcsaas.AtmosStorageContainerLiveTest")
|
@Test(groups = { "live" }, testName = "emcsaas.AtmosStorageContainerLiveTest")
|
||||||
public class AtmosStorageContainerLiveTest extends
|
public class AtmosStorageContainerLiveTest extends BaseContainerLiveTest {
|
||||||
BaseContainerLiveTest<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.integration;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
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.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -30,8 +28,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageInputStreamMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageInputStreamMapIntegrationTest")
|
||||||
public class AtmosStorageInputStreamMapIntegrationTest extends
|
public class AtmosStorageInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
|
||||||
BaseInputStreamMapIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -29,8 +27,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageIntegrationTest")
|
||||||
public class AtmosStorageIntegrationTest extends
|
public class AtmosStorageIntegrationTest extends BaseBlobIntegrationTest {
|
||||||
BaseBlobIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
@DataProvider(name = "delete")
|
@DataProvider(name = "delete")
|
||||||
// no unicode support
|
// no unicode support
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseBlobLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "emcsaas.AtmosStorageLiveTest")
|
@Test(groups = { "live" }, testName = "emcsaas.AtmosStorageLiveTest")
|
||||||
public class AtmosStorageLiveTest extends
|
public class AtmosStorageLiveTest extends BaseBlobLiveTest {
|
||||||
BaseBlobLiveTest<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.integration;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
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.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -30,8 +28,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageMapIntegrationTest")
|
||||||
public class AtmosStorageMapIntegrationTest extends
|
public class AtmosStorageMapIntegrationTest extends BaseBlobMapIntegrationTest {
|
||||||
BaseBlobMapIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageServiceIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageServiceIntegrationTest")
|
||||||
public class AtmosStorageServiceIntegrationTest extends
|
public class AtmosStorageServiceIntegrationTest extends BaseServiceIntegrationTest {
|
||||||
BaseServiceIntegrationTest<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,8 +21,6 @@ package org.jclouds.atmosonline.saas.blobstore.integration;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
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.blobstore.AtmosBlobStoreContextFactory;
|
||||||
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
|
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
@ -37,21 +35,17 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AtmosStorageTestInitializer extends
|
public class AtmosStorageTestInitializer extends BaseTestInitializer {
|
||||||
BaseTestInitializer<AtmosStorageAsyncClient, AtmosStorageClient> {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createLiveContext(
|
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
|
||||||
Module configurationModule, String url, String app, String account, String key)
|
String account, String key) throws IOException {
|
||||||
throws IOException {
|
return new BlobStoreContextFactory().createContext("atmos", account, key, ImmutableSet.of(
|
||||||
return (BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient>) new BlobStoreContextFactory()
|
configurationModule, new Log4JLoggingModule()), new Properties());
|
||||||
.createContext("atmos", account, key, ImmutableSet.of(configurationModule,
|
|
||||||
new Log4JLoggingModule()), new Properties());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<AtmosStorageAsyncClient, AtmosStorageClient> createStubContext() {
|
protected BlobStoreContext createStubContext() {
|
||||||
return AtmosBlobStoreContextFactory.createContext("user", "pass",
|
return AtmosBlobStoreContextFactory.createContext("user", "pass",
|
||||||
new AtmosStorageStubClientModule());
|
new AtmosStorageStubClientModule());
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,4 +75,5 @@ public class EC2ComputeServiceContextBuilder extends
|
||||||
protected void addClientModule(List<Module> modules) {
|
protected void addClientModule(List<Module> modules) {
|
||||||
modules.add(new EC2RestClientModule());
|
modules.add(new EC2RestClientModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.aws.ec2.compute;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
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.aws.ec2.EC2PropertiesBuilder;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
@ -44,28 +42,28 @@ import com.google.inject.Module;
|
||||||
* @see EC2ComputeServiceContext
|
* @see EC2ComputeServiceContext
|
||||||
*/
|
*/
|
||||||
public class EC2ComputeServiceContextFactory {
|
public class EC2ComputeServiceContextFactory {
|
||||||
public static ComputeServiceContext<EC2AsyncClient, EC2Client> createContext(Properties properties,
|
public static ComputeServiceContext createContext(Properties properties, Module... modules) {
|
||||||
Module... modules) {
|
|
||||||
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(properties).build())
|
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) {
|
String awsSecretAccessKey, Module... modules) {
|
||||||
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
|
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
|
||||||
awsSecretAccessKey).build()).withModules(modules).buildContext();
|
awsSecretAccessKey).build()).withModules(modules).buildComputeServiceContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComputeServiceContext<EC2AsyncClient, EC2Client> createContext(Properties properties,
|
public static ComputeServiceContext createContext(Properties properties, String awsAccessKeyId,
|
||||||
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
|
String awsSecretAccessKey, Module... modules) {
|
||||||
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(properties).withCredentials(
|
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(properties)
|
||||||
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext();
|
.withCredentials(awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
|
||||||
|
.buildComputeServiceContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComputeServiceContext<EC2AsyncClient, EC2Client> createContext(URI endpoint,
|
public static ComputeServiceContext createContext(URI endpoint, String awsAccessKeyId,
|
||||||
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
|
String awsSecretAccessKey, Module... modules) {
|
||||||
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
|
return new EC2ComputeServiceContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
|
||||||
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
|
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
|
||||||
.buildContext();
|
.buildComputeServiceContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,22 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.compute.config;
|
package org.jclouds.aws.ec2.compute.config;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.EC2;
|
|
||||||
import org.jclouds.aws.ec2.EC2AsyncClient;
|
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||||
import org.jclouds.aws.ec2.EC2Client;
|
import org.jclouds.aws.ec2.EC2Client;
|
||||||
import org.jclouds.aws.ec2.compute.EC2ComputeService;
|
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.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
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;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,20 +36,19 @@ import com.google.inject.Provides;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class EC2ComputeServiceContextModule extends AbstractModule {
|
public class EC2ComputeServiceContextModule extends EC2ContextModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
super.configure();
|
||||||
bind(ComputeService.class).to(EC2ComputeService.class).asEagerSingleton();
|
bind(ComputeService.class).to(EC2ComputeService.class).asEagerSingleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
ComputeServiceContext<EC2AsyncClient, EC2Client> provideContext(Closer closer,
|
ComputeServiceContext provideContext(ComputeService computeService,
|
||||||
ComputeService computeService, EC2AsyncClient asynchApi, EC2Client defaultApi,
|
RestContext<EC2AsyncClient, EC2Client> context) {
|
||||||
@EC2 URI endPoint, @Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
return new ComputeServiceContextImpl<EC2AsyncClient, EC2Client>(computeService, context);
|
||||||
return new ComputeServiceContextImpl<EC2AsyncClient, EC2Client>(closer, computeService,
|
|
||||||
asynchApi, defaultApi, endPoint, account);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,7 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.aws.ec2.EC2;
|
import org.jclouds.aws.ec2.EC2;
|
||||||
import org.jclouds.aws.ec2.EC2AsyncClient;
|
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||||
import org.jclouds.aws.ec2.EC2Client;
|
import org.jclouds.aws.ec2.EC2Client;
|
||||||
import org.jclouds.aws.ec2.compute.EC2ComputeService;
|
|
||||||
import org.jclouds.aws.reference.AWSConstants;
|
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.CDateAdapter;
|
||||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
@ -47,7 +45,6 @@ public class EC2ContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(DateAdapter.class).to(CDateAdapter.class);
|
bind(DateAdapter.class).to(CDateAdapter.class);
|
||||||
bind(ComputeService.class).to(EC2ComputeService.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.aws.s3.blobstore;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
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.aws.s3.S3PropertiesBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
@ -43,28 +41,28 @@ import com.google.inject.Module;
|
||||||
* @see S3BlobStoreContext
|
* @see S3BlobStoreContext
|
||||||
*/
|
*/
|
||||||
public class S3BlobStoreContextFactory {
|
public class S3BlobStoreContextFactory {
|
||||||
public static BlobStoreContext<S3AsyncClient, S3Client> createContext(Properties properties,
|
public static BlobStoreContext createContext(Properties properties, Module... modules) {
|
||||||
Module... modules) {
|
|
||||||
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(properties).build())
|
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) {
|
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,
|
return new S3BlobStoreContextBuilder(new S3PropertiesBuilder(awsAccessKeyId,
|
||||||
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
|
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
|
||||||
.buildContext();
|
.buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,29 +18,23 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.config;
|
package org.jclouds.aws.s3.blobstore.config;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
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.S3AsyncClient;
|
||||||
import org.jclouds.aws.s3.S3Client;
|
import org.jclouds.aws.s3.S3Client;
|
||||||
import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore;
|
import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore;
|
||||||
import org.jclouds.aws.s3.blobstore.S3BlobStore;
|
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.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.InputStreamMap;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,27 +42,24 @@ import com.google.inject.Provides;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class S3BlobStoreContextModule extends AbstractModule {
|
public class S3BlobStoreContextModule extends S3ContextModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreObjectModule());
|
super.configure();
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
install(new S3ObjectModule());
|
|
||||||
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).asEagerSingleton();
|
||||||
bind(BlobStore.class).to(S3BlobStore.class).asEagerSingleton();
|
bind(BlobStore.class).to(S3BlobStore.class).asEagerSingleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
BlobStoreContext<S3AsyncClient, S3Client> provideContext(BlobMap.Factory blobMapFactory,
|
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
|
||||||
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
||||||
AsyncBlobStore asyncBlobstore, BlobStore blobStore, S3AsyncClient asynchApi,
|
AsyncBlobStore asynchBlobStore, BlobStore blobStore,
|
||||||
S3Client defaultApi, @S3 URI endPoint,
|
RestContext<S3AsyncClient, S3Client> context) {
|
||||||
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
|
||||||
return new BlobStoreContextImpl<S3AsyncClient, S3Client>(blobMapFactory,
|
return new BlobStoreContextImpl<S3AsyncClient, S3Client>(blobMapFactory,
|
||||||
inputStreamMapFactory, closer, asyncBlobstore, blobStore, asynchApi, defaultApi,
|
inputStreamMapFactory, asynchBlobStore, blobStore, context);
|
||||||
endPoint, account);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class EC2ComputeServiceLiveTest {
|
||||||
|
|
||||||
private RetryablePredicate<InetSocketAddress> socketTester;
|
private RetryablePredicate<InetSocketAddress> socketTester;
|
||||||
private CreateNodeResponse node;
|
private CreateNodeResponse node;
|
||||||
private ComputeServiceContext<?, ?> context;
|
private ComputeServiceContext context;
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,
|
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,
|
||||||
|
|
|
@ -61,14 +61,17 @@ import com.google.common.collect.Maps;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "s3.S3ClientLiveTest")
|
@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
|
* this method overrides containerName to ensure it isn't found
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void deleteContainerIfEmptyNotFound() throws Exception {
|
public void deleteContainerIfEmptyNotFound() throws Exception {
|
||||||
assert context.getApi().deleteBucketIfEmpty("dbienf");
|
assert getApi().deleteBucketIfEmpty("dbienf");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
|
@ -76,7 +79,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addBlobToContainer(containerName, "test");
|
addBlobToContainer(containerName, "test");
|
||||||
assert !context.getApi().deleteBucketIfEmpty(containerName);
|
assert !getApi().deleteBucketIfEmpty(containerName);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(containerName);
|
returnContainer(containerName);
|
||||||
}
|
}
|
||||||
|
@ -86,10 +89,10 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
String key = "hello";
|
String key = "hello";
|
||||||
S3Object object = context.getApi().newS3Object();
|
S3Object object = getApi().newS3Object();
|
||||||
object.getMetadata().setKey(key);
|
object.getMetadata().setKey(key);
|
||||||
object.setPayload(TEST_STRING);
|
object.setPayload(TEST_STRING);
|
||||||
context.getApi().putObject(containerName, object,
|
getApi().putObject(containerName, object,
|
||||||
|
|
||||||
withAcl(CannedAccessPolicy.PUBLIC_READ));
|
withAcl(CannedAccessPolicy.PUBLIC_READ));
|
||||||
|
|
||||||
|
@ -108,7 +111,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
addBlobToContainer(containerName, sourceKey);
|
addBlobToContainer(containerName, sourceKey);
|
||||||
validateContent(containerName, sourceKey);
|
validateContent(containerName, sourceKey);
|
||||||
|
|
||||||
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
|
getApi().copyObject(containerName, sourceKey, destinationContainer,
|
||||||
destinationKey, overrideAcl(CannedAccessPolicy.PUBLIC_READ));
|
destinationKey, overrideAcl(CannedAccessPolicy.PUBLIC_READ));
|
||||||
|
|
||||||
validateContent(destinationContainer, destinationKey);
|
validateContent(destinationContainer, destinationKey);
|
||||||
|
@ -131,17 +134,17 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
final String publicReadWriteObjectKey = "public-read-write-acl";
|
final String publicReadWriteObjectKey = "public-read-write-acl";
|
||||||
final String containerName = getContainerName();
|
final String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
S3Object object = context.getApi().newS3Object();
|
S3Object object = getApi().newS3Object();
|
||||||
object.getMetadata().setKey(publicReadWriteObjectKey);
|
object.getMetadata().setKey(publicReadWriteObjectKey);
|
||||||
object.setPayload("");
|
object.setPayload("");
|
||||||
// Public Read-Write object
|
// Public Read-Write object
|
||||||
context.getApi().putObject(containerName, object,
|
getApi().putObject(containerName, object,
|
||||||
new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ_WRITE));
|
new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ_WRITE));
|
||||||
|
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
AccessControlList acl = context.getApi().getObjectACL(containerName,
|
AccessControlList acl = getApi().getObjectACL(containerName,
|
||||||
publicReadWriteObjectKey);
|
publicReadWriteObjectKey);
|
||||||
assertEquals(acl.getGrants().size(), 3);
|
assertEquals(acl.getGrants().size(), 3);
|
||||||
assertEquals(acl.getPermissions(GroupGranteeURI.ALL_USERS).size(), 2);
|
assertEquals(acl.getPermissions(GroupGranteeURI.ALL_USERS).size(), 2);
|
||||||
|
@ -172,7 +175,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
|
|
||||||
// Private object
|
// Private object
|
||||||
addBlobToContainer(containerName, objectKey);
|
addBlobToContainer(containerName, objectKey);
|
||||||
AccessControlList acl = context.getApi().getObjectACL(containerName, objectKey);
|
AccessControlList acl = getApi().getObjectACL(containerName, objectKey);
|
||||||
String ownerId = acl.getOwner().getId();
|
String ownerId = acl.getOwner().getId();
|
||||||
|
|
||||||
assertEquals(acl.getGrants().size(), 1);
|
assertEquals(acl.getGrants().size(), 1);
|
||||||
|
@ -180,10 +183,10 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
|
|
||||||
addGrantsToACL(acl);
|
addGrantsToACL(acl);
|
||||||
assertEquals(acl.getGrants().size(), 4);
|
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.
|
// Confirm that the updated ACL has stuck.
|
||||||
acl = context.getApi().getObjectACL(containerName, objectKey);
|
acl = getApi().getObjectACL(containerName, objectKey);
|
||||||
checkGrants(acl);
|
checkGrants(acl);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -197,10 +200,10 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
||||||
|
|
||||||
// Update the object's ACL settings
|
// 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
|
// 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.getGrants().size(), 1);
|
||||||
assertEquals(acl.getPermissions(ownerId).size(), 0);
|
assertEquals(acl.getPermissions(ownerId).size(), 0);
|
||||||
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl.toString());
|
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl.toString());
|
||||||
|
@ -217,7 +220,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
try {
|
try {
|
||||||
// Private object
|
// Private object
|
||||||
addBlobToContainer(containerName, privateObjectKey);
|
addBlobToContainer(containerName, privateObjectKey);
|
||||||
AccessControlList acl = context.getApi().getObjectACL(containerName, privateObjectKey);
|
AccessControlList acl = getApi().getObjectACL(containerName, privateObjectKey);
|
||||||
|
|
||||||
assertEquals(acl.getGrants().size(), 1);
|
assertEquals(acl.getGrants().size(), 1);
|
||||||
assertTrue(acl.getOwner() != null);
|
assertTrue(acl.getOwner() != null);
|
||||||
|
@ -234,16 +237,16 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
final String publicReadObjectKey = "public-read-acl";
|
final String publicReadObjectKey = "public-read-acl";
|
||||||
final String containerName = getContainerName();
|
final String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
S3Object object = context.getApi().newS3Object();
|
S3Object object = getApi().newS3Object();
|
||||||
object.getMetadata().setKey(publicReadObjectKey);
|
object.getMetadata().setKey(publicReadObjectKey);
|
||||||
object.setPayload("");
|
object.setPayload("");
|
||||||
context.getApi().putObject(containerName, object,
|
getApi().putObject(containerName, object,
|
||||||
new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ));
|
new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ));
|
||||||
|
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
AccessControlList acl = context.getApi().getObjectACL(containerName,
|
AccessControlList acl = getApi().getObjectACL(containerName,
|
||||||
publicReadObjectKey);
|
publicReadObjectKey);
|
||||||
|
|
||||||
assertEquals(acl.getGrants().size(), 2);
|
assertEquals(acl.getGrants().size(), 2);
|
||||||
|
@ -265,17 +268,17 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String addBlobToContainer(String sourceContainer, String key) {
|
protected String addBlobToContainer(String sourceContainer, String key) {
|
||||||
S3Object sourceObject = context.getApi().newS3Object();
|
S3Object sourceObject = getApi().newS3Object();
|
||||||
sourceObject.getMetadata().setKey(key);
|
sourceObject.getMetadata().setKey(key);
|
||||||
sourceObject.getMetadata().setContentType("text/xml");
|
sourceObject.getMetadata().setContentType("text/xml");
|
||||||
sourceObject.setPayload(TEST_STRING);
|
sourceObject.setPayload(TEST_STRING);
|
||||||
return context.getApi().putObject(sourceContainer, sourceObject);
|
return getApi().putObject(sourceContainer, sourceObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected S3Object validateObject(String sourceContainer, String key)
|
protected S3Object validateObject(String sourceContainer, String key)
|
||||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
assertConsistencyAwareContainerSize(sourceContainer, 1);
|
assertConsistencyAwareContainerSize(sourceContainer, 1);
|
||||||
S3Object newObject = context.getApi().getObject(sourceContainer, key);
|
S3Object newObject = getApi().getObject(sourceContainer, key);
|
||||||
assert newObject != null;
|
assert newObject != null;
|
||||||
assertEquals(Utils.toStringAndClose(newObject.getContent()), TEST_STRING);
|
assertEquals(Utils.toStringAndClose(newObject.getContent()), TEST_STRING);
|
||||||
return newObject;
|
return newObject;
|
||||||
|
@ -284,14 +287,14 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
public void testMetadataWithCacheControlAndContentDisposition() throws Exception {
|
public void testMetadataWithCacheControlAndContentDisposition() throws Exception {
|
||||||
String key = "hello";
|
String key = "hello";
|
||||||
|
|
||||||
S3Object object = context.getApi().newS3Object();
|
S3Object object = getApi().newS3Object();
|
||||||
object.getMetadata().setKey(key);
|
object.getMetadata().setKey(key);
|
||||||
object.setPayload(TEST_STRING);
|
object.setPayload(TEST_STRING);
|
||||||
object.getMetadata().setCacheControl("no-cache");
|
object.getMetadata().setCacheControl("no-cache");
|
||||||
object.getMetadata().setContentDisposition("attachment; filename=hello.txt");
|
object.getMetadata().setContentDisposition("attachment; filename=hello.txt");
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
context.getApi().putObject(containerName, object);
|
getApi().putObject(containerName, object);
|
||||||
|
|
||||||
S3Object newObject = validateObject(containerName, key);
|
S3Object newObject = validateObject(containerName, key);
|
||||||
|
|
||||||
|
@ -307,13 +310,13 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
public void testMetadataContentEncoding() throws Exception {
|
public void testMetadataContentEncoding() throws Exception {
|
||||||
String key = "hello";
|
String key = "hello";
|
||||||
|
|
||||||
S3Object object = context.getApi().newS3Object();
|
S3Object object = getApi().newS3Object();
|
||||||
object.getMetadata().setKey(key);
|
object.getMetadata().setKey(key);
|
||||||
object.setPayload(TEST_STRING);
|
object.setPayload(TEST_STRING);
|
||||||
object.getMetadata().setContentEncoding("x-compress");
|
object.getMetadata().setContentEncoding("x-compress");
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
context.getApi().putObject(containerName, object);
|
getApi().putObject(containerName, object);
|
||||||
S3Object newObject = validateObject(containerName, key);
|
S3Object newObject = validateObject(containerName, key);
|
||||||
|
|
||||||
assertEquals(newObject.getMetadata().getContentEncoding(), "x-compress");
|
assertEquals(newObject.getMetadata().getContentEncoding(), "x-compress");
|
||||||
|
@ -329,7 +332,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
try {
|
try {
|
||||||
addToContainerAndValidate(containerName, sourceKey);
|
addToContainerAndValidate(containerName, sourceKey);
|
||||||
|
|
||||||
context.getApi()
|
getApi()
|
||||||
.copyObject(containerName, sourceKey, destinationContainer, destinationKey);
|
.copyObject(containerName, sourceKey, destinationContainer, destinationKey);
|
||||||
|
|
||||||
validateContent(destinationContainer, destinationKey);
|
validateContent(destinationContainer, destinationKey);
|
||||||
|
@ -357,12 +360,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
addToContainerAndValidate(containerName, sourceKey + "mod");
|
addToContainerAndValidate(containerName, sourceKey + "mod");
|
||||||
Date after = new Date(System.currentTimeMillis() + 1000);
|
Date after = new Date(System.currentTimeMillis() + 1000);
|
||||||
|
|
||||||
context.getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
|
getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
|
||||||
destinationKey, ifSourceModifiedSince(before));
|
destinationKey, ifSourceModifiedSince(before));
|
||||||
validateContent(destinationContainer, destinationKey);
|
validateContent(destinationContainer, destinationKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
|
getApi().copyObject(containerName, sourceKey + "mod", destinationContainer,
|
||||||
destinationKey, ifSourceModifiedSince(after));
|
destinationKey, ifSourceModifiedSince(after));
|
||||||
} catch (HttpResponseException ex) {
|
} catch (HttpResponseException ex) {
|
||||||
assertEquals(ex.getResponse().getStatusCode(), 412);
|
assertEquals(ex.getResponse().getStatusCode(), 412);
|
||||||
|
@ -384,12 +387,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
addToContainerAndValidate(containerName, sourceKey + "un");
|
addToContainerAndValidate(containerName, sourceKey + "un");
|
||||||
Date after = new Date(System.currentTimeMillis() + 1000);
|
Date after = new Date(System.currentTimeMillis() + 1000);
|
||||||
|
|
||||||
context.getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
|
getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
|
||||||
destinationKey, ifSourceUnmodifiedSince(after));
|
destinationKey, ifSourceUnmodifiedSince(after));
|
||||||
validateContent(destinationContainer, destinationKey);
|
validateContent(destinationContainer, destinationKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
|
getApi().copyObject(containerName, sourceKey + "un", destinationContainer,
|
||||||
destinationKey, ifSourceModifiedSince(before));
|
destinationKey, ifSourceModifiedSince(before));
|
||||||
} catch (HttpResponseException ex) {
|
} catch (HttpResponseException ex) {
|
||||||
assertEquals(ex.getResponse().getStatusCode(), 412);
|
assertEquals(ex.getResponse().getStatusCode(), 412);
|
||||||
|
@ -407,12 +410,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
try {
|
try {
|
||||||
String goodETag = addToContainerAndValidate(containerName, sourceKey);
|
String goodETag = addToContainerAndValidate(containerName, sourceKey);
|
||||||
|
|
||||||
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
|
getApi().copyObject(containerName, sourceKey, destinationContainer,
|
||||||
destinationKey, ifSourceETagMatches(goodETag));
|
destinationKey, ifSourceETagMatches(goodETag));
|
||||||
validateContent(destinationContainer, destinationKey);
|
validateContent(destinationContainer, destinationKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
|
getApi().copyObject(containerName, sourceKey, destinationContainer,
|
||||||
destinationKey, ifSourceETagMatches("setsds"));
|
destinationKey, ifSourceETagMatches("setsds"));
|
||||||
} catch (HttpResponseException ex) {
|
} catch (HttpResponseException ex) {
|
||||||
assertEquals(ex.getResponse().getStatusCode(), 412);
|
assertEquals(ex.getResponse().getStatusCode(), 412);
|
||||||
|
@ -430,12 +433,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
try {
|
try {
|
||||||
String goodETag = addToContainerAndValidate(containerName, sourceKey);
|
String goodETag = addToContainerAndValidate(containerName, sourceKey);
|
||||||
|
|
||||||
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
|
getApi().copyObject(containerName, sourceKey, destinationContainer,
|
||||||
destinationKey, ifSourceETagDoesntMatch("asfasdf"));
|
destinationKey, ifSourceETagDoesntMatch("asfasdf"));
|
||||||
validateContent(destinationContainer, destinationKey);
|
validateContent(destinationContainer, destinationKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
|
getApi().copyObject(containerName, sourceKey, destinationContainer,
|
||||||
destinationKey, ifSourceETagDoesntMatch(goodETag));
|
destinationKey, ifSourceETagDoesntMatch(goodETag));
|
||||||
} catch (HttpResponseException ex) {
|
} catch (HttpResponseException ex) {
|
||||||
assertEquals(ex.getResponse().getStatusCode(), 412);
|
assertEquals(ex.getResponse().getStatusCode(), 412);
|
||||||
|
@ -457,12 +460,12 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient
|
||||||
Map<String, String> metadata = Maps.newHashMap();
|
Map<String, String> metadata = Maps.newHashMap();
|
||||||
metadata.put("adrian", "cole");
|
metadata.put("adrian", "cole");
|
||||||
|
|
||||||
context.getApi().copyObject(containerName, sourceKey, destinationContainer,
|
getApi().copyObject(containerName, sourceKey, destinationContainer,
|
||||||
destinationKey, overrideMetadataWith(metadata));
|
destinationKey, overrideMetadataWith(metadata));
|
||||||
|
|
||||||
validateContent(destinationContainer, destinationKey);
|
validateContent(destinationContainer, destinationKey);
|
||||||
|
|
||||||
ObjectMetadata objectMeta = context.getApi().headObject(destinationContainer,
|
ObjectMetadata objectMeta = getApi().headObject(destinationContainer,
|
||||||
destinationKey);
|
destinationKey);
|
||||||
|
|
||||||
assertEquals(objectMeta.getUserMetadata(), metadata);
|
assertEquals(objectMeta.getUserMetadata(), metadata);
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.aws.s3.S3AsyncClient;
|
import org.jclouds.aws.s3.S3AsyncClient;
|
||||||
import org.jclouds.aws.s3.S3Client;
|
|
||||||
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
||||||
import org.jclouds.aws.s3.blobstore.config.S3BlobStoreContextModule;
|
import org.jclouds.aws.s3.blobstore.config.S3BlobStoreContextModule;
|
||||||
import org.jclouds.aws.s3.config.S3RestClientModule;
|
import org.jclouds.aws.s3.config.S3RestClientModule;
|
||||||
|
@ -43,9 +42,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of modules configured in S3ContextBuilder
|
* Tests behavior of modules configured in S3ContextBuilder
|
||||||
|
@ -65,23 +62,24 @@ public class S3BlobStoreContextBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBuildContext() {
|
public void testBuildContext() {
|
||||||
BlobStoreContext<S3AsyncClient, S3Client> context = new S3BlobStoreContextBuilder(
|
BlobStoreContext context = new S3BlobStoreContextBuilder(new S3PropertiesBuilder("id",
|
||||||
new S3PropertiesBuilder("id", "secret").build()).withModules(
|
"secret").build()).withModules(new S3StubClientModule()).buildBlobStoreContext();
|
||||||
new S3StubClientModule()).buildContext();
|
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
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.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.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
|
||||||
assertEquals(context.getAccount(), "id");
|
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://localhost/s3stub"));
|
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
|
||||||
|
.create("https://localhost/s3stub"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBuildInjector() {
|
public void testBuildInjector() {
|
||||||
Injector i = new S3BlobStoreContextBuilder(new S3PropertiesBuilder("id", "secret").build())
|
Injector i = new S3BlobStoreContextBuilder(new S3PropertiesBuilder("id", "secret").build())
|
||||||
.withModules(new S3StubClientModule()).buildInjector();
|
.withModules(new S3StubClientModule()).buildInjector();
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<BlobStoreContext<S3AsyncClient, S3Client>>() {
|
assert i.getInstance(BlobStoreContext.class) != null;
|
||||||
})) != null;
|
|
||||||
assert i.getInstance(S3Object.class) != null;
|
assert i.getInstance(S3Object.class) != null;
|
||||||
assert i.getInstance(Blob.class) != null;
|
assert i.getInstance(Blob.class) != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.aws.s3.blobstore.config;
|
||||||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||||
import static org.testng.Assert.assertEquals;
|
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.config.S3StubClientModule;
|
||||||
import org.jclouds.aws.s3.reference.S3Constants;
|
import org.jclouds.aws.s3.reference.S3Constants;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
@ -34,8 +32,6 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -61,9 +57,7 @@ public class S3BlobStoreModuleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testContextImpl() {
|
void testContextImpl() {
|
||||||
BlobStoreContext<S3AsyncClient, S3Client> context = createInjector().getInstance(
|
BlobStoreContext context = createInjector().getInstance(BlobStoreContext.class);
|
||||||
Key.get(new TypeLiteral<BlobStoreContext<S3AsyncClient, S3Client>>() {
|
|
||||||
}));
|
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -29,6 +27,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "s3.S3BlobIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "s3.S3BlobIntegrationTest")
|
||||||
public class S3BlobIntegrationTest extends BaseBlobIntegrationTest<S3AsyncClient, S3Client> {
|
public class S3BlobIntegrationTest extends BaseBlobIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseBlobLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -29,6 +27,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "s3.S3BlobLiveTest")
|
@Test(groups = { "live" }, testName = "s3.S3BlobLiveTest")
|
||||||
public class S3BlobLiveTest extends BaseBlobLiveTest<S3AsyncClient, S3Client> {
|
public class S3BlobLiveTest extends BaseBlobLiveTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,6 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "s3.S3BlobMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "s3.S3BlobMapIntegrationTest")
|
||||||
public class S3BlobMapIntegrationTest extends BaseBlobMapIntegrationTest<S3AsyncClient, S3Client> {
|
public class S3BlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "s3.S3ContainerIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "s3.S3ContainerIntegrationTest")
|
||||||
public class S3ContainerIntegrationTest extends
|
public class S3ContainerIntegrationTest extends BaseContainerIntegrationTest {
|
||||||
BaseContainerIntegrationTest<S3AsyncClient, S3Client> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -28,6 +26,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "s3.S3ContainerLiveTest")
|
@Test(groups = { "live" }, testName = "s3.S3ContainerLiveTest")
|
||||||
public class S3ContainerLiveTest extends BaseContainerLiveTest<S3AsyncClient, S3Client> {
|
public class S3ContainerLiveTest extends BaseContainerLiveTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "s3.S3InputStreamMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "s3.S3InputStreamMapIntegrationTest")
|
||||||
public class S3InputStreamMapIntegrationTest extends
|
public class S3InputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
|
||||||
BaseInputStreamMapIntegrationTest<S3AsyncClient, S3Client> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,6 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "s3.S3ServiceIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "s3.S3ServiceIntegrationTest")
|
||||||
public class S3ServiceIntegrationTest extends BaseServiceIntegrationTest<S3AsyncClient, S3Client> {
|
public class S3ServiceIntegrationTest extends BaseServiceIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,8 +21,6 @@ package org.jclouds.aws.s3.blobstore.integration;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
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.blobstore.S3BlobStoreContextFactory;
|
||||||
import org.jclouds.aws.s3.config.S3StubClientModule;
|
import org.jclouds.aws.s3.config.S3StubClientModule;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
@ -38,20 +36,18 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class S3TestInitializer extends BaseTestInitializer<S3AsyncClient, S3Client> {
|
public class S3TestInitializer extends BaseTestInitializer {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<S3AsyncClient, S3Client> createLiveContext(
|
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
|
||||||
Module configurationModule, String url, String app, String account, String key) throws IOException {
|
String account, String key) throws IOException {
|
||||||
BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true;
|
BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true;
|
||||||
return (BlobStoreContext<S3AsyncClient, S3Client>) new BlobStoreContextFactory()
|
return new BlobStoreContextFactory().createContext("s3", account, key, ImmutableSet.of(
|
||||||
.createContext("s3", account, key, ImmutableSet.of(configurationModule,
|
configurationModule, new Log4JLoggingModule()), new Properties());
|
||||||
new Log4JLoggingModule()), new Properties());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<S3AsyncClient, S3Client> createStubContext() {
|
protected BlobStoreContext createStubContext() {
|
||||||
return S3BlobStoreContextFactory.createContext("user", "pass", new S3StubClientModule());
|
return S3BlobStoreContextFactory.createContext("user", "pass", new S3StubClientModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,4 +55,5 @@ public class S3StubClientModule extends AbstractModule {
|
||||||
SecurityException, NoSuchMethodException {
|
SecurityException, NoSuchMethodException {
|
||||||
return SyncProxy.create(S3Client.class, client);
|
return SyncProxy.create(S3Client.class, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.Region;
|
import org.jclouds.aws.domain.Region;
|
||||||
import org.jclouds.aws.s3.S3AsyncClient;
|
|
||||||
import org.jclouds.aws.s3.S3Client;
|
import org.jclouds.aws.s3.S3Client;
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList;
|
import org.jclouds.aws.s3.domain.AccessControlList;
|
||||||
import org.jclouds.aws.s3.domain.BucketLogging;
|
import org.jclouds.aws.s3.domain.BucketLogging;
|
||||||
|
@ -64,14 +63,17 @@ import com.google.common.collect.ImmutableSet;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "s3.S3ClientLiveTest")
|
@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
|
* this method overrides bucketName to ensure it isn't found
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void deleteBucketIfEmptyNotFound() throws Exception {
|
public void deleteBucketIfEmptyNotFound() throws Exception {
|
||||||
assert context.getApi().deleteBucketIfEmpty("dbienf");
|
assert getApi().deleteBucketIfEmpty("dbienf");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
|
@ -79,7 +81,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addBlobToContainer(bucketName, "test");
|
addBlobToContainer(bucketName, "test");
|
||||||
assert !context.getApi().deleteBucketIfEmpty(bucketName);
|
assert !getApi().deleteBucketIfEmpty(bucketName);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(bucketName);
|
returnContainer(bucketName);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +91,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
TimeoutException, IOException {
|
TimeoutException, IOException {
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
AccessControlList acl = context.getApi().getBucketACL(bucketName);
|
AccessControlList acl = getApi().getBucketACL(bucketName);
|
||||||
assertEquals(acl.getGrants().size(), 1);
|
assertEquals(acl.getGrants().size(), 1);
|
||||||
assertTrue(acl.getOwner() != null);
|
assertTrue(acl.getOwner() != null);
|
||||||
String ownerId = acl.getOwner().getId();
|
String ownerId = acl.getOwner().getId();
|
||||||
|
@ -105,17 +107,17 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
// Confirm the bucket is private
|
// Confirm the bucket is private
|
||||||
AccessControlList acl = context.getApi().getBucketACL(bucketName);
|
AccessControlList acl = getApi().getBucketACL(bucketName);
|
||||||
String ownerId = acl.getOwner().getId();
|
String ownerId = acl.getOwner().getId();
|
||||||
assertEquals(acl.getGrants().size(), 1);
|
assertEquals(acl.getGrants().size(), 1);
|
||||||
assertTrue(acl.hasPermission(ownerId, Permission.FULL_CONTROL));
|
assertTrue(acl.hasPermission(ownerId, Permission.FULL_CONTROL));
|
||||||
|
|
||||||
addGrantsToACL(acl);
|
addGrantsToACL(acl);
|
||||||
assertEquals(acl.getGrants().size(), 4);
|
assertEquals(acl.getGrants().size(), 4);
|
||||||
assertTrue(context.getApi().putBucketACL(bucketName, acl));
|
assertTrue(getApi().putBucketACL(bucketName, acl));
|
||||||
|
|
||||||
// Confirm that the updated ACL has stuck.
|
// Confirm that the updated ACL has stuck.
|
||||||
acl = context.getApi().getBucketACL(bucketName);
|
acl = getApi().getBucketACL(bucketName);
|
||||||
checkGrants(acl);
|
checkGrants(acl);
|
||||||
} finally {
|
} finally {
|
||||||
destroyContainer(bucketName);
|
destroyContainer(bucketName);
|
||||||
|
@ -147,9 +149,9 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
public void testPublicReadAccessPolicy() throws Exception {
|
public void testPublicReadAccessPolicy() throws Exception {
|
||||||
String bucketName = getScratchContainerName();
|
String bucketName = getScratchContainerName();
|
||||||
try {
|
try {
|
||||||
context.getApi().putBucketInRegion(Region.DEFAULT, bucketName,
|
getApi().putBucketInRegion(Region.DEFAULT, bucketName,
|
||||||
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
|
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());
|
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.
|
// TODO: I believe that the following should work based on the above acl assertion passing.
|
||||||
// However, it fails on 403
|
// However, it fails on 403
|
||||||
|
@ -175,7 +177,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
public void testDefaultBucketLocation() throws Exception {
|
public void testDefaultBucketLocation() throws Exception {
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
assertEquals(Region.US_STANDARD, context.getApi().getBucketLocation(bucketName));
|
assertEquals(Region.US_STANDARD, getApi().getBucketLocation(bucketName));
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(bucketName);
|
returnContainer(bucketName);
|
||||||
}
|
}
|
||||||
|
@ -184,23 +186,23 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
public void testBucketPayer() throws Exception {
|
public void testBucketPayer() throws Exception {
|
||||||
final String bucketName = getContainerName();
|
final String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
assertEquals(Payer.BUCKET_OWNER, context.getApi().getBucketPayer(bucketName));
|
assertEquals(Payer.BUCKET_OWNER, getApi().getBucketPayer(bucketName));
|
||||||
context.getApi().setBucketPayer(bucketName, Payer.REQUESTER);
|
getApi().setBucketPayer(bucketName, Payer.REQUESTER);
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
assertEquals(Payer.REQUESTER, context.getApi().getBucketPayer(bucketName));
|
assertEquals(Payer.REQUESTER, getApi().getBucketPayer(bucketName));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Throwables.propagateIfPossible(e);
|
Throwables.propagateIfPossible(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context.getApi().setBucketPayer(bucketName, Payer.BUCKET_OWNER);
|
getApi().setBucketPayer(bucketName, Payer.BUCKET_OWNER);
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
assertEquals(Payer.BUCKET_OWNER, context.getApi().getBucketPayer(bucketName));
|
assertEquals(Payer.BUCKET_OWNER, getApi().getBucketPayer(bucketName));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Throwables.propagateIfPossible(e);
|
Throwables.propagateIfPossible(e);
|
||||||
}
|
}
|
||||||
|
@ -215,19 +217,19 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
final String bucketName = getContainerName();
|
final String bucketName = getContainerName();
|
||||||
final String targetBucket = getContainerName();
|
final String targetBucket = getContainerName();
|
||||||
try {
|
try {
|
||||||
assertNull(context.getApi().getBucketLogging(bucketName));
|
assertNull(getApi().getBucketLogging(bucketName));
|
||||||
|
|
||||||
setupAclForBucketLoggingTarget(targetBucket);
|
setupAclForBucketLoggingTarget(targetBucket);
|
||||||
final BucketLogging logging = new BucketLogging(targetBucket, "access_log-", ImmutableSet
|
final BucketLogging logging = new BucketLogging(targetBucket, "access_log-", ImmutableSet
|
||||||
.<Grant> of(new Grant(new EmailAddressGrantee(StubS3AsyncClient.TEST_ACL_EMAIL),
|
.<Grant> of(new Grant(new EmailAddressGrantee(StubS3AsyncClient.TEST_ACL_EMAIL),
|
||||||
Permission.FULL_CONTROL)));
|
Permission.FULL_CONTROL)));
|
||||||
|
|
||||||
context.getApi().enableBucketLogging(bucketName, logging);
|
getApi().enableBucketLogging(bucketName, logging);
|
||||||
|
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
BucketLogging newLogging = context.getApi().getBucketLogging(bucketName);
|
BucketLogging newLogging = getApi().getBucketLogging(bucketName);
|
||||||
AccessControlList acl = new AccessControlList();
|
AccessControlList acl = new AccessControlList();
|
||||||
for (Grant grant : newLogging.getTargetGrants()) { // TODO: add permission
|
for (Grant grant : newLogging.getTargetGrants()) { // TODO: add permission
|
||||||
// checking features to
|
// checking features to
|
||||||
|
@ -245,11 +247,11 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context.getApi().disableBucketLogging(bucketName);
|
getApi().disableBucketLogging(bucketName);
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
assertNull(context.getApi().getBucketLogging(bucketName));
|
assertNull(getApi().getBucketLogging(bucketName));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Throwables.propagateIfPossible(e);
|
Throwables.propagateIfPossible(e);
|
||||||
}
|
}
|
||||||
|
@ -263,10 +265,10 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
|
|
||||||
private void setupAclForBucketLoggingTarget(final String targetBucket) {
|
private void setupAclForBucketLoggingTarget(final String targetBucket) {
|
||||||
// http://docs.amazonwebservices.com/AmazonS3/latest/LoggingHowTo.html
|
// 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.WRITE);
|
||||||
acl.addPermission(GroupGranteeURI.LOG_DELIVERY, Permission.READ_ACP);
|
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 {
|
public void testEu() throws Exception {
|
||||||
final String bucketName = getScratchContainerName();
|
final String bucketName = getScratchContainerName();
|
||||||
try {
|
try {
|
||||||
context.getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "eu",
|
getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "eu",
|
||||||
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
|
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
AccessControlList acl = context.getApi().getBucketACL(bucketName + "eu");
|
AccessControlList acl = getApi().getBucketACL(bucketName + "eu");
|
||||||
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl
|
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl
|
||||||
.toString());
|
.toString());
|
||||||
} catch (Exception e) {
|
} 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.
|
// TODO: I believe that the following should work based on the above acl assertion passing.
|
||||||
// However, it fails on 403
|
// However, it fails on 403
|
||||||
// URL url = new URL(String.format("http://%s.s3.amazonaws.com", bucketName));
|
// 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 {
|
public void testNorthernCalifornia() throws Exception {
|
||||||
final String bucketName = getScratchContainerName();
|
final String bucketName = getScratchContainerName();
|
||||||
try {
|
try {
|
||||||
context.getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "cali",
|
getApi().putBucketInRegion(Region.EU_WEST_1, bucketName + "cali",
|
||||||
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
|
withBucketAcl(CannedAccessPolicy.PUBLIC_READ));
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
AccessControlList acl = context.getApi().getBucketACL(bucketName + "cali");
|
AccessControlList acl = getApi().getBucketACL(bucketName + "cali");
|
||||||
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl
|
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl
|
||||||
.toString());
|
.toString());
|
||||||
} catch (Exception e) {
|
} 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.
|
// TODO: I believe that the following should work based on the above acl assertion passing.
|
||||||
// However, it fails on 403
|
// However, it fails on 403
|
||||||
// URL url = new URL(String.format("http://%s.s3.amazonaws.com", bucketName));
|
// 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 {
|
void bucketExists() throws Exception {
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
SortedSet<BucketMetadata> list = context.getApi().listOwnedBuckets();
|
SortedSet<BucketMetadata> list = getApi().listOwnedBuckets();
|
||||||
BucketMetadata firstBucket = list.first();
|
BucketMetadata firstBucket = list.first();
|
||||||
BucketMetadata toMatch = new BucketMetadata(bucketName, new Date(), firstBucket.getOwner());
|
BucketMetadata toMatch = new BucketMetadata(bucketName, new Date(), firstBucket.getOwner());
|
||||||
assert list.contains(toMatch);
|
assert list.contains(toMatch);
|
||||||
|
@ -341,10 +343,10 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
|
|
||||||
protected void addAlphabetUnderRoot(String bucketName) {
|
protected void addAlphabetUnderRoot(String bucketName) {
|
||||||
for (char letter = 'a'; letter <= 'z'; letter++) {
|
for (char letter = 'a'; letter <= 'z'; letter++) {
|
||||||
S3Object blob = context.getApi().newS3Object();
|
S3Object blob = getApi().newS3Object();
|
||||||
blob.getMetadata().setKey(letter + "");
|
blob.getMetadata().setKey(letter + "");
|
||||||
blob.setPayload(letter + "content");
|
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();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addAlphabetUnderRoot(bucketName);
|
addAlphabetUnderRoot(bucketName);
|
||||||
ListBucketResponse bucket = context.getApi().listBucket(bucketName, afterMarker("y"));
|
ListBucketResponse bucket = getApi().listBucket(bucketName, afterMarker("y"));
|
||||||
assertEquals(bucket.getMarker(), "y");
|
assertEquals(bucket.getMarker(), "y");
|
||||||
assert !bucket.isTruncated();
|
assert !bucket.isTruncated();
|
||||||
assertEquals(bucket.size(), 1);
|
assertEquals(bucket.size(), 1);
|
||||||
|
@ -369,7 +371,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
String prefix = "apps";
|
String prefix = "apps";
|
||||||
addTenObjectsUnderPrefix(bucketName, prefix);
|
addTenObjectsUnderPrefix(bucketName, prefix);
|
||||||
add15UnderRoot(bucketName);
|
add15UnderRoot(bucketName);
|
||||||
ListBucketResponse bucket = context.getApi().listBucket(bucketName, delimiter("/"));
|
ListBucketResponse bucket = getApi().listBucket(bucketName, delimiter("/"));
|
||||||
assertEquals(bucket.getDelimiter(), "/");
|
assertEquals(bucket.getDelimiter(), "/");
|
||||||
assert !bucket.isTruncated();
|
assert !bucket.isTruncated();
|
||||||
assertEquals(bucket.size(), 15);
|
assertEquals(bucket.size(), 15);
|
||||||
|
@ -388,7 +390,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
addTenObjectsUnderPrefix(bucketName, prefix);
|
addTenObjectsUnderPrefix(bucketName, prefix);
|
||||||
add15UnderRoot(bucketName);
|
add15UnderRoot(bucketName);
|
||||||
|
|
||||||
ListBucketResponse bucket = context.getApi().listBucket(bucketName, withPrefix("apps/"));
|
ListBucketResponse bucket = getApi().listBucket(bucketName, withPrefix("apps/"));
|
||||||
assert !bucket.isTruncated();
|
assert !bucket.isTruncated();
|
||||||
assertEquals(bucket.size(), 10);
|
assertEquals(bucket.size(), 10);
|
||||||
assertEquals(bucket.getPrefix(), "apps/");
|
assertEquals(bucket.getPrefix(), "apps/");
|
||||||
|
@ -403,7 +405,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addAlphabetUnderRoot(bucketName);
|
addAlphabetUnderRoot(bucketName);
|
||||||
ListBucketResponse bucket = context.getApi().listBucket(bucketName, maxResults(5));
|
ListBucketResponse bucket = getApi().listBucket(bucketName, maxResults(5));
|
||||||
assertEquals(bucket.getMaxKeys(), 5);
|
assertEquals(bucket.getMaxKeys(), 5);
|
||||||
assert bucket.isTruncated();
|
assert bucket.isTruncated();
|
||||||
assertEquals(bucket.size(), 5);
|
assertEquals(bucket.size(), 5);
|
||||||
|
@ -414,19 +416,19 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient,
|
||||||
|
|
||||||
protected void add15UnderRoot(String bucketName) {
|
protected void add15UnderRoot(String bucketName) {
|
||||||
for (int i = 0; i < 15; i++) {
|
for (int i = 0; i < 15; i++) {
|
||||||
S3Object blob = context.getApi().newS3Object();
|
S3Object blob = getApi().newS3Object();
|
||||||
blob.getMetadata().setKey(i + "");
|
blob.getMetadata().setKey(i + "");
|
||||||
blob.setPayload(i + "content");
|
blob.setPayload(i + "content");
|
||||||
context.getApi().putObject(bucketName, blob);
|
getApi().putObject(bucketName, blob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addTenObjectsUnderPrefix(String bucketName, String prefix) {
|
protected void addTenObjectsUnderPrefix(String bucketName, String prefix) {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
S3Object blob = context.getApi().newS3Object();
|
S3Object blob = getApi().newS3Object();
|
||||||
blob.getMetadata().setKey(prefix + "/" + i);
|
blob.getMetadata().setKey(prefix + "/" + i);
|
||||||
blob.setPayload(i + "content");
|
blob.setPayload(i + "content");
|
||||||
context.getApi().putObject(bucketName, blob);
|
getApi().putObject(bucketName, blob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,13 +18,20 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.samples;
|
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.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.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContextFactory;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
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.
|
* 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 int PARAMETERS = 3;
|
||||||
public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: \"accesskeyid\" \"secretkey\" \"bucketName\" ";
|
public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: \"accesskeyid\" \"secretkey\" \"bucketName\" ";
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
if (args.length < PARAMETERS)
|
if (args.length < PARAMETERS)
|
||||||
throw new IllegalArgumentException(INVALID_SYNTAX);
|
throw new IllegalArgumentException(INVALID_SYNTAX);
|
||||||
|
@ -51,7 +57,8 @@ public class MainApp {
|
||||||
String containerName = args[2];
|
String containerName = args[2];
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
BlobStoreContext context = S3BlobStoreContextFactory.createContext(accesskeyid, secretkey);
|
BlobStoreContext context = new BlobStoreContextFactory().createContext("s3", accesskeyid,
|
||||||
|
secretkey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -59,6 +66,7 @@ public class MainApp {
|
||||||
BlobStore blobStore = context.getBlobStore();
|
BlobStore blobStore = context.getBlobStore();
|
||||||
blobStore.createContainerInLocation(Region.DEFAULT.toString(), containerName);
|
blobStore.createContainerInLocation(Region.DEFAULT.toString(), containerName);
|
||||||
|
|
||||||
|
// Add Blob
|
||||||
Blob blob = blobStore.newBlob("test");
|
Blob blob = blobStore.newBlob("test");
|
||||||
blob.setPayload("testdata");
|
blob.setPayload("testdata");
|
||||||
blobStore.putBlob(containerName, blob);
|
blobStore.putBlob(containerName, blob);
|
||||||
|
@ -67,11 +75,18 @@ public class MainApp {
|
||||||
for (StorageMetadata resourceMd : blobStore.list()) {
|
for (StorageMetadata resourceMd : blobStore.list()) {
|
||||||
if (resourceMd.getType() == StorageType.CONTAINER
|
if (resourceMd.getType() == StorageType.CONTAINER
|
||||||
|| resourceMd.getType() == StorageType.FOLDER) {
|
|| resourceMd.getType() == StorageType.FOLDER) {
|
||||||
System.out.printf(" %s: %s entries%n", resourceMd.getName(), context
|
// Use Map API
|
||||||
.createInputStreamMap(resourceMd.getName()).size());
|
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 {
|
} finally {
|
||||||
// Close connecton
|
// Close connecton
|
||||||
context.close();
|
context.close();
|
||||||
|
|
|
@ -48,14 +48,14 @@ import com.google.common.collect.Sets;
|
||||||
public class GetAllContainersController extends HttpServlet {
|
public class GetAllContainersController extends HttpServlet {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Map<String, BlobStoreContext<?,?>> contexts;
|
private Map<String, BlobStoreContext> contexts;
|
||||||
private final BlobStoreContextToContainerResult blobStoreContextToContainerResult;
|
private final BlobStoreContextToContainerResult blobStoreContextToContainerResult;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GetAllContainersController(Map<String, BlobStoreContext<?,?>> contexts,
|
public GetAllContainersController(Map<String, BlobStoreContext> contexts,
|
||||||
BlobStoreContextToContainerResult blobStoreContextToContainerResult) {
|
BlobStoreContextToContainerResult blobStoreContextToContainerResult) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
||||||
|
|
|
@ -50,15 +50,15 @@ import com.google.inject.servlet.ServletModule;
|
||||||
*/
|
*/
|
||||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
private Map<String, BlobStoreContext<?, ?>> contexts;
|
private Map<String, BlobStoreContext> contexts;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
Properties props = loadJCloudsProperties(servletContextEvent);
|
Properties props = loadJCloudsProperties(servletContextEvent);
|
||||||
ImmutableList<String> list = ImmutableList.<String> of(checkNotNull(
|
ImmutableList<String> list = ImmutableList.<String> of(checkNotNull(
|
||||||
props.getProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
|
props.getProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS),
|
||||||
BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS).split(","));
|
BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTS).split(","));
|
||||||
contexts = Maps.newHashMap();
|
contexts = Maps.newHashMap();
|
||||||
for (String className : list) {
|
for (String className : list) {
|
||||||
try {
|
try {
|
||||||
|
@ -68,7 +68,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
Constructor<BlobStoreContextBuilder<?, ?>> constructor = builderClass
|
Constructor<BlobStoreContextBuilder<?, ?>> constructor = builderClass
|
||||||
.getConstructor(Properties.class);
|
.getConstructor(Properties.class);
|
||||||
contexts.put(name, constructor.newInstance(props).withModules(
|
contexts.put(name, constructor.newInstance(props).withModules(
|
||||||
new GoogleAppEngineConfigurationModule()).buildContext());
|
new GoogleAppEngineConfigurationModule()).buildBlobStoreContext());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
return Guice.createInjector(new ServletModule() {
|
return Guice.createInjector(new ServletModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
protected void configureServlets() {
|
||||||
bind(new TypeLiteral<Map<String, BlobStoreContext<?, ?>>>() {
|
bind(new TypeLiteral<Map<String, BlobStoreContext>>() {
|
||||||
}).toInstance(GuiceServletConfig.this.contexts);
|
}).toInstance(GuiceServletConfig.this.contexts);
|
||||||
serve("*.blobstore").with(GetAllContainersController.class);
|
serve("*.blobstore").with(GetAllContainersController.class);
|
||||||
requestInjection(this);
|
requestInjection(this);
|
||||||
|
@ -107,7 +107,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
||||||
for (BlobStoreContext<?, ?> context : contexts.values()) {
|
for (BlobStoreContext context : contexts.values()) {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
super.contextDestroyed(servletContextEvent);
|
super.contextDestroyed(servletContextEvent);
|
||||||
|
|
|
@ -40,10 +40,10 @@ import com.google.common.collect.Sets;
|
||||||
public class BlobStoreContextToContainerResult implements Function<String, ContainerResult> {
|
public class BlobStoreContextToContainerResult implements Function<String, ContainerResult> {
|
||||||
private final class BuildContainerResult implements Function<StorageMetadata, ContainerResult> {
|
private final class BuildContainerResult implements Function<StorageMetadata, ContainerResult> {
|
||||||
private final String host;
|
private final String host;
|
||||||
private final BlobStoreContext<?, ?> context;
|
private final BlobStoreContext context;
|
||||||
private final String contextName;
|
private final String contextName;
|
||||||
|
|
||||||
private BuildContainerResult(String host, BlobStoreContext<?, ?> context, String contextName) {
|
private BuildContainerResult(String host, BlobStoreContext context, String contextName) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.contextName = contextName;
|
this.contextName = contextName;
|
||||||
|
@ -68,14 +68,14 @@ public class BlobStoreContextToContainerResult implements Function<String, Conta
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Map<String, BlobStoreContext<?, ?>> contexts;
|
private Map<String, BlobStoreContext> contexts;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
public ContainerResult apply(final String contextName) {
|
public ContainerResult apply(final String contextName) {
|
||||||
final BlobStoreContext<?, ?> context = contexts.get(contextName);
|
final BlobStoreContext context = contexts.get(contextName);
|
||||||
final String host = context.getEndPoint().getHost();
|
final String host = context.getProviderSpecificContext().getEndPoint().getHost();
|
||||||
try {
|
try {
|
||||||
StorageMetadata md = Iterables.getLast(Sets.newTreeSet(Iterables.filter(context
|
StorageMetadata md = Iterables.getLast(Sets.newTreeSet(Iterables.filter(context
|
||||||
.getBlobStore().list(), new Predicate<StorageMetadata>() {
|
.getBlobStore().list(), new Predicate<StorageMetadata>() {
|
||||||
|
|
|
@ -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.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_ACCOUNT;
|
||||||
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY;
|
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_KEY;
|
||||||
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER;
|
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));
|
url = new URL(String.format("http://%s:%s", address, port));
|
||||||
Properties props = new Properties();
|
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
|
S3BlobStoreContextBuilder.class.getName(), CloudFilesBlobStoreContextBuilder.class
|
||||||
.getName(), AzureBlobStoreContextBuilder.class.getName()));
|
.getName(), AzureBlobStoreContextBuilder.class.getName()));
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,15 @@ import java.util.SortedSet;
|
||||||
import org.jclouds.aws.domain.Region;
|
import org.jclouds.aws.domain.Region;
|
||||||
import org.jclouds.aws.s3.S3AsyncClient;
|
import org.jclouds.aws.s3.S3AsyncClient;
|
||||||
import org.jclouds.aws.s3.S3Client;
|
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.S3AsyncBlobStore;
|
||||||
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextFactory;
|
|
||||||
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
||||||
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
||||||
import org.jclouds.aws.s3.options.CopyObjectOptions;
|
import org.jclouds.aws.s3.options.CopyObjectOptions;
|
||||||
import org.jclouds.aws.s3.options.ListBucketOptions;
|
import org.jclouds.aws.s3.options.ListBucketOptions;
|
||||||
import org.jclouds.aws.s3.options.PutObjectOptions;
|
import org.jclouds.aws.s3.options.PutObjectOptions;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jets3t.service.S3ObjectsChunk;
|
import org.jets3t.service.S3ObjectsChunk;
|
||||||
import org.jets3t.service.S3Service;
|
import org.jets3t.service.S3Service;
|
||||||
import org.jets3t.service.S3ServiceException;
|
import org.jets3t.service.S3ServiceException;
|
||||||
|
@ -60,7 +60,7 @@ public class JCloudsS3Service extends S3Service {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final BlobStoreContext<S3AsyncClient, S3Client> context;
|
private final RestContext<S3AsyncClient, S3Client> context;
|
||||||
private final S3Client connection;
|
private final S3Client connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,8 +76,8 @@ public class JCloudsS3Service extends S3Service {
|
||||||
protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules)
|
protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules)
|
||||||
throws S3ServiceException {
|
throws S3ServiceException {
|
||||||
super(awsCredentials);
|
super(awsCredentials);
|
||||||
context = S3BlobStoreContextFactory.createContext(awsCredentials.getAccessKey(),
|
context = S3ContextFactory.createContext(awsCredentials.getAccessKey(), awsCredentials
|
||||||
awsCredentials.getSecretKey(), modules);
|
.getSecretKey(), modules);
|
||||||
connection = context.getApi();
|
connection = context.getApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.aws.s3.S3AsyncClient;
|
|
||||||
import org.jclouds.aws.s3.S3Client;
|
import org.jclouds.aws.s3.S3Client;
|
||||||
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
|
import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
|
||||||
|
@ -72,10 +71,14 @@ import com.google.common.collect.Iterables;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "jets3t.JCloudsS3ServiceIntegrationTest")
|
@Test(groups = { "live" }, testName = "jets3t.JCloudsS3ServiceIntegrationTest")
|
||||||
public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3AsyncClient, S3Client> {
|
public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
AWSCredentials credentials;
|
AWSCredentials credentials;
|
||||||
S3Service service;
|
S3Service service;
|
||||||
|
|
||||||
|
public S3Client getApi() {
|
||||||
|
return (S3Client) context.getProviderSpecificContext().getApi();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* overridden only to get access to the amazon credentials used for jets3t initialization.
|
* overridden only to get access to the amazon credentials used for jets3t initialization.
|
||||||
*
|
*
|
||||||
|
@ -102,7 +105,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
try {
|
try {
|
||||||
S3Bucket bucket = service.createBucket(new S3Bucket(bucketName));
|
S3Bucket bucket = service.createBucket(new S3Bucket(bucketName));
|
||||||
assertEquals(bucket.getName(), bucketName);
|
assertEquals(bucket.getName(), bucketName);
|
||||||
assertTrue(context.getApi().bucketExists(bucketName));
|
assertTrue(getApi().bucketExists(bucketName));
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(bucketName);
|
returnContainer(bucketName);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +118,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
service.deleteBucket(bucketName);
|
service.deleteBucket(bucketName);
|
||||||
assertConsistencyAware(new Runnable() {
|
assertConsistencyAware(new Runnable() {
|
||||||
public void run() {
|
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.
|
// Ensure there is at least 1 bucket in S3 account to list and compare.
|
||||||
S3Bucket[] jsBuckets = service.listAllBuckets();
|
S3Bucket[] jsBuckets = service.listAllBuckets();
|
||||||
|
|
||||||
SortedSet<org.jclouds.aws.s3.domain.BucketMetadata> jcBuckets = context.getApi()
|
SortedSet<org.jclouds.aws.s3.domain.BucketMetadata> jcBuckets = getApi()
|
||||||
.listOwnedBuckets();
|
.listOwnedBuckets();
|
||||||
|
|
||||||
assert jsBuckets.length == jcBuckets.size();
|
assert jsBuckets.length == jcBuckets.size();
|
||||||
|
@ -352,7 +355,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
// Upload empty object
|
// Upload empty object
|
||||||
requestObject = new S3Object(objectKey);
|
requestObject = new S3Object(objectKey);
|
||||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
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);
|
// TODO null keys from s3object! assertEquals(jcObject.getKey(), objectKey);
|
||||||
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
|
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
|
||||||
assertEquals(jcObject.getMetadata().getContentType(), MediaType.APPLICATION_OCTET_STREAM);
|
assertEquals(jcObject.getMetadata().getContentType(), MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
@ -363,7 +366,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
// Upload unicode-named object
|
// Upload unicode-named object
|
||||||
requestObject = new S3Object("₪n₪₪₪d₪-object");
|
requestObject = new S3Object("₪n₪₪₪d₪-object");
|
||||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
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());
|
// TODO null keys from s3object! assertEquals(jcObject.getKey(), requestObject.getKey());
|
||||||
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
|
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
|
||||||
assertEquals(jcObject.getMetadata().getContentType(), MediaType.APPLICATION_OCTET_STREAM);
|
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";
|
String data = "This is my ₪n₪₪₪d₪ data";
|
||||||
requestObject = new S3Object(objectKey, data);
|
requestObject = new S3Object(objectKey, data);
|
||||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
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));
|
assertEquals(jcObject.getMetadata().getSize(), new Long(data.getBytes("UTF-8").length));
|
||||||
assertTrue(jcObject.getMetadata().getContentType().startsWith("text/plain"));
|
assertTrue(jcObject.getMetadata().getContentType().startsWith("text/plain"));
|
||||||
assertEquals(jsResultObject.getContentLength(), data.getBytes("UTF-8").length);
|
assertEquals(jsResultObject.getContentLength(), data.getBytes("UTF-8").length);
|
||||||
|
@ -385,7 +388,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
requestObject = new S3Object(objectKey);
|
requestObject = new S3Object(objectKey);
|
||||||
requestObject.addMetadata("x-amz-meta-" + "my-metadata-1", "value-1");
|
requestObject.addMetadata("x-amz-meta-" + "my-metadata-1", "value-1");
|
||||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
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(jcObject.getMetadata().getUserMetadata().get("my-metadata-1"), "value-1");
|
||||||
assertEquals(jsResultObject.getMetadata("x-amz-meta-" + "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 = new S3Object(objectKey);
|
||||||
requestObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
|
requestObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
|
||||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
||||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = context.getApi().getObjectACL(
|
org.jclouds.aws.s3.domain.AccessControlList jcACL = getApi().getObjectACL(bucketName,
|
||||||
bucketName, objectKey);
|
objectKey);
|
||||||
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
||||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
||||||
assertEquals(jcACL.getGrants().size(), 2);
|
assertEquals(jcACL.getGrants().size(), 2);
|
||||||
|
@ -409,7 +412,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
data = "Here is some d₪t₪ for you";
|
data = "Here is some d₪t₪ for you";
|
||||||
requestObject.setDataInputStream(new ByteArrayInputStream(data.getBytes("UTF-8")));
|
requestObject.setDataInputStream(new ByteArrayInputStream(data.getBytes("UTF-8")));
|
||||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
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")));
|
assertTrue(jsResultObject.verifyData(data.getBytes("UTF-8")));
|
||||||
assertEquals(jsResultObject.getETag(), jcObject.getMetadata().getETag().replaceAll("\"",
|
assertEquals(jsResultObject.getETag(), jcObject.getMetadata().getETag().replaceAll("\"",
|
||||||
""));
|
""));
|
||||||
|
@ -444,15 +447,15 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
destinationObject = new S3Object(destinationObjectKey);
|
destinationObject = new S3Object(destinationObjectKey);
|
||||||
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
|
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
|
||||||
destinationObject, false);
|
destinationObject, false);
|
||||||
jcDestinationObject = context.getApi().getObject(bucketName, destinationObject.getKey());
|
jcDestinationObject = getApi().getObject(bucketName, destinationObject.getKey());
|
||||||
// TODO null keys from s3object! assertEquals(jcDestinationObject.getKey(),
|
// TODO null keys from s3object! assertEquals(jcDestinationObject.getKey(),
|
||||||
// destinationObjectKey);
|
// destinationObjectKey);
|
||||||
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName),
|
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName),
|
||||||
sourceMetadataValue);
|
sourceMetadataValue);
|
||||||
assertEquals(copyResult.get("ETag"), jcDestinationObject.getMetadata().getETag());
|
assertEquals(copyResult.get("ETag"), jcDestinationObject.getMetadata().getETag());
|
||||||
// Test destination ACL is unchanged (ie private)
|
// Test destination ACL is unchanged (ie private)
|
||||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = context.getApi().getObjectACL(
|
org.jclouds.aws.s3.domain.AccessControlList jcACL = getApi().getObjectACL(bucketName,
|
||||||
bucketName, destinationObject.getKey());
|
destinationObject.getKey());
|
||||||
assertEquals(jcACL.getGrants().size(), 1);
|
assertEquals(jcACL.getGrants().size(), 1);
|
||||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
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);
|
destinationObject.addMetadata("x-amz-meta-" + metadataName, destinationMetadataValue);
|
||||||
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
|
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
|
||||||
destinationObject, true);
|
destinationObject, true);
|
||||||
jcDestinationObject = context.getApi().getObject(bucketName, destinationObject.getKey());
|
jcDestinationObject = getApi().getObject(bucketName, destinationObject.getKey());
|
||||||
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName),
|
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName),
|
||||||
destinationMetadataValue);
|
destinationMetadataValue);
|
||||||
// Test destination ACL is unchanged (ie private)
|
// 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);
|
assertEquals(jcACL.getGrants().size(), 1);
|
||||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
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,
|
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName,
|
||||||
destinationObject, false);
|
destinationObject, false);
|
||||||
// Test destination ACL is changed (ie public-read)
|
// 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);
|
assertEquals(jcACL.getGrants().size(), 2);
|
||||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
||||||
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
||||||
|
@ -654,7 +657,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
multiService.putObjects(bucket, objects);
|
multiService.putObjects(bucket, objects);
|
||||||
|
|
||||||
assertEquals(countOfUploadCompletions[0], OBJECT_COUNT);
|
assertEquals(countOfUploadCompletions[0], OBJECT_COUNT);
|
||||||
ListBucketResponse theBucket = context.getApi().listBucket(bucketName);
|
ListBucketResponse theBucket = getApi().listBucket(bucketName);
|
||||||
assertEquals(theBucket.size(), OBJECT_COUNT);
|
assertEquals(theBucket.size(), OBJECT_COUNT);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -41,7 +41,7 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
|
||||||
// object.setContentType("application/octetstream");
|
// object.setContentType("application/octetstream");
|
||||||
// //object.setPayload("this is a test");
|
// //object.setPayload("this is a test");
|
||||||
// object.setPayload(test);
|
// object.setPayload(test);
|
||||||
// return context.getApi()Provider.getObject(s3Bucket,
|
// return getApi()Provider.getObject(s3Bucket,
|
||||||
// object.getKey()).get(120,TimeUnit.SECONDS) !=
|
// object.getKey()).get(120,TimeUnit.SECONDS) !=
|
||||||
// S3Object.NOT_FOUND;
|
// S3Object.NOT_FOUND;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
|
||||||
S3Object object = newObject(key);
|
S3Object object = newObject(key);
|
||||||
object.getMetadata().setContentType(contentType);
|
object.getMetadata().setContentType(contentType);
|
||||||
object.setPayload(data);
|
object.setPayload(data);
|
||||||
return context.getApi().putObject(bucket, object) != null;
|
return getApi().putObject(bucket, object) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,11 +62,11 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
|
||||||
S3Object object = newObject(key);
|
S3Object object = newObject(key);
|
||||||
object.getMetadata().setContentType(contentType);
|
object.getMetadata().setContentType(contentType);
|
||||||
object.setPayload(data);
|
object.setPayload(data);
|
||||||
return context.getApi().putObject(bucket, object) != null;
|
return getApi().putObject(bucket, object) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private S3Object newObject(String key) {
|
private S3Object newObject(String key) {
|
||||||
S3Object object = context.getApi().newS3Object();
|
S3Object object = getApi().newS3Object();
|
||||||
object.getMetadata().setKey(key);
|
object.getMetadata().setKey(key);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
|
||||||
object.getMetadata().setContentType(contentType);
|
object.getMetadata().setContentType(contentType);
|
||||||
object.setPayload(data);
|
object.setPayload(data);
|
||||||
object.setContentLength(new Long(data.available()));
|
object.setContentLength(new Long(data.available()));
|
||||||
return context.getApi().putObject(bucket, object) != null;
|
return getApi().putObject(bucket, object) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,6 +87,6 @@ public abstract class BaseJCloudsPerformanceLiveTest extends BasePerformanceLive
|
||||||
S3Object object = newObject(key);
|
S3Object object = newObject(key);
|
||||||
object.getMetadata().setContentType(contentType);
|
object.getMetadata().setContentType(contentType);
|
||||||
object.setPayload(data);
|
object.setPayload(data);
|
||||||
return context.getApi().putObject(bucket, object) != null;
|
return getApi().putObject(bucket, object) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,7 @@ import org.testng.annotations.Test;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public abstract class BasePerformanceLiveTest extends
|
public abstract class BasePerformanceLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
BaseBlobStoreIntegrationTest<S3AsyncClient, S3Client> {
|
|
||||||
static {
|
static {
|
||||||
containerCount = 1;
|
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
|
* using scratch containerName as we are changing location
|
||||||
*
|
*
|
||||||
|
@ -87,7 +90,7 @@ public abstract class BasePerformanceLiveTest extends
|
||||||
protected String createScratchContainerInEU() throws InterruptedException, ExecutionException,
|
protected String createScratchContainerInEU() throws InterruptedException, ExecutionException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
String containerName = getScratchContainerName();
|
String containerName = getScratchContainerName();
|
||||||
context.getApi().putBucketInRegion(Region.EU_WEST_1, containerName);
|
getApi().putBucketInRegion(Region.EU_WEST_1, containerName);
|
||||||
return containerName;
|
return containerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.azure.storage.blob.blobstore;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
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.azure.storage.blob.AzureBlobPropertiesBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
@ -43,21 +41,19 @@ import com.google.inject.Module;
|
||||||
* @see AzureBlobStoreContext
|
* @see AzureBlobStoreContext
|
||||||
*/
|
*/
|
||||||
public class AzureBlobStoreContextFactory {
|
public class AzureBlobStoreContextFactory {
|
||||||
public static BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createContext(
|
public static BlobStoreContext createContext(Properties properties, Module... modules) {
|
||||||
Properties properties, Module... modules) {
|
|
||||||
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(properties).build())
|
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(properties).build())
|
||||||
.withModules(modules).buildContext();
|
.withModules(modules).buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createContext(String user,
|
public static BlobStoreContext createContext(String user, String encodedKey, Module... modules) {
|
||||||
String encodedKey, Module... modules) {
|
|
||||||
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
|
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
|
||||||
.build()).withModules(modules).buildContext();
|
.build()).withModules(modules).buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createContext(
|
public static BlobStoreContext createContext(URI endpoint, String user, String encodedKey,
|
||||||
URI endpoint, String user, String encodedKey, Module... modules) {
|
Module... modules) {
|
||||||
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
|
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
|
||||||
.withEndpoint(endpoint).build()).withModules(modules).buildContext();
|
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,31 +18,25 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.config;
|
package org.jclouds.azure.storage.blob.blobstore.config;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.AzureBlob;
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
|
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobClient;
|
import org.jclouds.azure.storage.blob.AzureBlobClient;
|
||||||
import org.jclouds.azure.storage.blob.blobstore.AzureAsyncBlobStore;
|
import org.jclouds.azure.storage.blob.blobstore.AzureAsyncBlobStore;
|
||||||
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStore;
|
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStore;
|
||||||
import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties;
|
import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties;
|
||||||
import org.jclouds.azure.storage.blob.config.AzureBlobModule;
|
import org.jclouds.azure.storage.blob.config.AzureBlobContextModule;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.InputStreamMap;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,13 +44,12 @@ import com.google.inject.Provides;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AzureBlobStoreContextModule extends AbstractModule {
|
public class AzureBlobStoreContextModule extends AzureBlobContextModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreObjectModule());
|
super.configure();
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
install(new AzureBlobModule());
|
|
||||||
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).asEagerSingleton();
|
||||||
bind(BlobStore.class).to(AzureBlobStore.class).asEagerSingleton();
|
bind(BlobStore.class).to(AzureBlobStore.class).asEagerSingleton();
|
||||||
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
|
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
|
||||||
|
@ -64,14 +57,12 @@ public class AzureBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> provideContext(
|
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
|
||||||
BlobMap.Factory blobMapFactory, InputStreamMap.Factory inputStreamMapFactory,
|
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
||||||
Closer closer, AsyncBlobStore asyncBlobStore, BlobStore blobStore,
|
AsyncBlobStore asynchBlobStore, BlobStore blobStore,
|
||||||
AzureBlobAsyncClient asyncApi, AzureBlobClient defaultApi, @AzureBlob URI endPoint,
|
RestContext<AzureBlobAsyncClient, AzureBlobClient> context) {
|
||||||
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
|
|
||||||
return new BlobStoreContextImpl<AzureBlobAsyncClient, AzureBlobClient>(blobMapFactory,
|
return new BlobStoreContextImpl<AzureBlobAsyncClient, AzureBlobClient>(blobMapFactory,
|
||||||
inputStreamMapFactory, closer, asyncBlobStore, blobStore, asyncApi, defaultApi,
|
inputStreamMapFactory, asynchBlobStore, blobStore, context);
|
||||||
endPoint, account);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
|
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.AzureBlobPropertiesBuilder;
|
||||||
import org.jclouds.azure.storage.blob.blobstore.config.AzureBlobStoreContextModule;
|
import org.jclouds.azure.storage.blob.blobstore.config.AzureBlobStoreContextModule;
|
||||||
import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
|
import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
|
||||||
|
@ -42,9 +41,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of modules configured in AzureBlobContextBuilder
|
* Tests behavior of modules configured in AzureBlobContextBuilder
|
||||||
|
@ -69,21 +66,22 @@ public class AzureBlobStoreContextBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBuildContext() {
|
public void testBuildContext() {
|
||||||
BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> context = newBuilder().buildContext();
|
BlobStoreContext context = newBuilder().buildBlobStoreContext();
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
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.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.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
|
||||||
assertEquals(context.getAccount(), "id");
|
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub"));
|
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
|
||||||
|
.create("https://localhost/azurestub"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBuildInjector() {
|
public void testBuildInjector() {
|
||||||
Injector i = newBuilder().buildInjector();
|
Injector i = newBuilder().buildInjector();
|
||||||
assert i.getInstance(Key
|
assert i.getInstance(BlobStoreContext.class) != null;
|
||||||
.get(new TypeLiteral<BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>>() {
|
|
||||||
})) != null;
|
|
||||||
assert i.getInstance(AzureBlob.class) != null;
|
assert i.getInstance(AzureBlob.class) != null;
|
||||||
assert i.getInstance(Blob.class) != null;
|
assert i.getInstance(Blob.class) != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.azure.storage.blob.blobstore.config;
|
||||||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||||
import static org.testng.Assert.assertEquals;
|
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.blobstore.strategy.FindMD5InBlobProperties;
|
||||||
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
|
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
|
||||||
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
|
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.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -70,14 +66,11 @@ public class AzureBlobStoreModuleTest {
|
||||||
void testContextImpl() {
|
void testContextImpl() {
|
||||||
|
|
||||||
Injector injector = createInjector();
|
Injector injector = createInjector();
|
||||||
BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> handler = injector.getInstance(Key
|
BlobStoreContext handler = injector.getInstance(BlobStoreContext.class);
|
||||||
.get(new TypeLiteral<BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>>() {
|
|
||||||
}));
|
|
||||||
assertEquals(handler.getClass(), BlobStoreContextImpl.class);
|
assertEquals(handler.getClass(), BlobStoreContextImpl.class);
|
||||||
ContainsValueInListStrategy valueList = injector
|
ContainsValueInListStrategy valueList = injector
|
||||||
.getInstance(ContainsValueInListStrategy.class);
|
.getInstance(ContainsValueInListStrategy.class);
|
||||||
|
|
||||||
assertEquals(valueList.getClass(), FindMD5InBlobProperties.class);
|
assertEquals(valueList.getClass(), FindMD5InBlobProperties.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobContainerIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobContainerIntegrationTest")
|
||||||
public class AzureBlobContainerIntegrationTest extends
|
public class AzureBlobContainerIntegrationTest extends BaseContainerIntegrationTest {
|
||||||
BaseContainerIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "azureblob.AzureBlobContainerLiveTest")
|
@Test(groups = { "live" }, testName = "azureblob.AzureBlobContainerLiveTest")
|
||||||
public class AzureBlobContainerLiveTest extends
|
public class AzureBlobContainerLiveTest extends BaseContainerLiveTest {
|
||||||
BaseContainerLiveTest<AzureBlobAsyncClient, AzureBlobClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobInputStreamMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobInputStreamMapIntegrationTest")
|
||||||
public class AzureBlobInputStreamMapIntegrationTest extends
|
public class AzureBlobInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
|
||||||
BaseInputStreamMapIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -20,8 +20,6 @@ package org.jclouds.azure.storage.blob.blobstore.integration;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
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.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -30,8 +28,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobIntegrationTest")
|
||||||
public class AzureBlobIntegrationTest extends
|
public class AzureBlobIntegrationTest extends BaseBlobIntegrationTest {
|
||||||
BaseBlobIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testGetIfMatch() throws InterruptedException, UnsupportedEncodingException {
|
public void testGetIfMatch() throws InterruptedException, UnsupportedEncodingException {
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseBlobLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -28,6 +26,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "azureblob.AzureBlobLiveTest")
|
@Test(groups = { "live" }, testName = "azureblob.AzureBlobLiveTest")
|
||||||
public class AzureBlobLiveTest extends BaseBlobLiveTest<AzureBlobAsyncClient, AzureBlobClient> {
|
public class AzureBlobLiveTest extends BaseBlobLiveTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobMapIntegrationTest")
|
||||||
public class AzureBlobMapIntegrationTest extends
|
public class AzureBlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
|
||||||
BaseBlobMapIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.integration;
|
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.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobServiceIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "azureblob.AzureBlobServiceIntegrationTest")
|
||||||
public class AzureBlobServiceIntegrationTest extends
|
public class AzureBlobServiceIntegrationTest extends BaseServiceIntegrationTest {
|
||||||
BaseServiceIntegrationTest<AzureBlobAsyncClient, AzureBlobClient> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,8 +21,6 @@ package org.jclouds.azure.storage.blob.blobstore.integration;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
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.blobstore.AzureBlobStoreContextFactory;
|
||||||
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
|
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
@ -37,21 +35,18 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AzureBlobTestInitializer extends
|
public class AzureBlobTestInitializer extends BaseTestInitializer {
|
||||||
BaseTestInitializer<AzureBlobAsyncClient, AzureBlobClient> {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createLiveContext(
|
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
|
||||||
Module configurationModule, String url, String app, String account, String key)
|
String account, String key) throws IOException {
|
||||||
throws IOException {
|
return (BlobStoreContext) new BlobStoreContextFactory().createContext("azureblob", account,
|
||||||
return (BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>) new BlobStoreContextFactory()
|
key, ImmutableSet.of(configurationModule, new Log4JLoggingModule()),
|
||||||
.createContext("azureblob", account, key, ImmutableSet.of(configurationModule,
|
new Properties());
|
||||||
new Log4JLoggingModule()), new Properties());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient> createStubContext() {
|
protected BlobStoreContext createStubContext() {
|
||||||
return AzureBlobStoreContextFactory.createContext("user", "pass",
|
return AzureBlobStoreContextFactory.createContext("user", "pass",
|
||||||
new AzureBlobStubClientModule());
|
new AzureBlobStubClientModule());
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import com.google.inject.ImplementedBy;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ImplementedBy(BlobStoreContextImpl.class)
|
@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.
|
* 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();
|
BlobStore getBlobStore();
|
||||||
|
|
||||||
ConsistencyModels getConsistencyModel();
|
ConsistencyModels getConsistencyModel();
|
||||||
|
|
||||||
|
<A, S> RestContext<A, S> getProviderSpecificContext();
|
||||||
|
|
||||||
|
void close();
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@ package org.jclouds.blobstore;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
import org.jclouds.rest.RestContextBuilder;
|
||||||
|
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
@ -52,11 +53,10 @@ public abstract class BlobStoreContextBuilder<A, S> extends RestContextBuilder<A
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public BlobStoreContext buildBlobStoreContext() {
|
||||||
@Override
|
// need the generic type information
|
||||||
public BlobStoreContext<A, S> buildContext() {
|
return (BlobStoreContext) buildInjector().getInstance(
|
||||||
return (BlobStoreContext<A, S>) this.buildInjector().getInstance(
|
Key.get(Types.newParameterizedType(BlobStoreContextImpl.class, asyncClientType
|
||||||
Key.get(Types.newParameterizedType(BlobStoreContext.class,
|
.getType(), syncClientType.getType())));
|
||||||
asyncClientType.getType(), syncClientType.getType())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ import org.jclouds.rest.RestContextFactory;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BlobStoreContextFactory extends
|
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
|
* 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) {
|
public BlobStoreContextFactory(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BlobStoreContext build(BlobStoreContextBuilder<?, ?> contextBuilder) {
|
||||||
|
return contextBuilder.buildBlobStoreContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.blobstore.internal;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
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.attr.ConsistencyModels;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobStoreUtils;
|
import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BlobStoreContextImpl<A, S> extends RestContextImpl<A, S> implements
|
public class BlobStoreContextImpl<X, Y> implements BlobStoreContext {
|
||||||
BlobStoreContext<A, S> {
|
|
||||||
private final BlobMap.Factory blobMapFactory;
|
private final BlobMap.Factory blobMapFactory;
|
||||||
private final InputStreamMap.Factory inputStreamMapFactory;
|
private final InputStreamMap.Factory inputStreamMapFactory;
|
||||||
private final AsyncBlobStore ablobStore;
|
private final AsyncBlobStore ablobStore;
|
||||||
private final BlobStore blobStore;
|
private final BlobStore blobStore;
|
||||||
private final ConsistencyModels consistencyModel;
|
private final ConsistencyModels consistencyModel;
|
||||||
|
private final RestContext<X, Y> providerSpecificContext;
|
||||||
|
|
||||||
|
@Inject
|
||||||
public BlobStoreContextImpl(BlobMap.Factory blobMapFactory,
|
public BlobStoreContextImpl(BlobMap.Factory blobMapFactory,
|
||||||
InputStreamMap.Factory inputStreamMapFactory, Closer closer, AsyncBlobStore ablobStore,
|
InputStreamMap.Factory inputStreamMapFactory, AsyncBlobStore ablobStore,
|
||||||
BlobStore blobStore, A asyncApi, S syncApi, URI endPoint, String account) {
|
BlobStore blobStore, RestContext<X, Y> providerSpecificContext) {
|
||||||
super(closer, asyncApi, syncApi, endPoint, account);
|
this.providerSpecificContext = providerSpecificContext;
|
||||||
Class<?> type;
|
Class<?> type;
|
||||||
if (asyncApi.getClass().isAnnotationPresent(ConsistencyModel.class)) {
|
if (providerSpecificContext.getAsyncApi().getClass().isAnnotationPresent(
|
||||||
type = asyncApi.getClass();
|
ConsistencyModel.class)) {
|
||||||
} else if (asyncApi.getClass().getInterfaces().length > 0
|
type = providerSpecificContext.getAsyncApi().getClass();
|
||||||
&& asyncApi.getClass().getInterfaces()[0]
|
} else if (providerSpecificContext.getAsyncApi().getClass().getInterfaces().length > 0
|
||||||
|
&& providerSpecificContext.getAsyncApi().getClass().getInterfaces()[0]
|
||||||
.isAnnotationPresent(ConsistencyModel.class)) {
|
.isAnnotationPresent(ConsistencyModel.class)) {
|
||||||
type = asyncApi.getClass().getInterfaces()[0];
|
type = providerSpecificContext.getAsyncApi().getClass().getInterfaces()[0];
|
||||||
} else {
|
} 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.consistencyModel = type.getAnnotation(ConsistencyModel.class).value();
|
||||||
this.blobMapFactory = checkNotNull(blobMapFactory, "blobMapFactory");
|
this.blobMapFactory = checkNotNull(blobMapFactory, "blobMapFactory");
|
||||||
|
@ -98,4 +100,15 @@ public class BlobStoreContextImpl<A, S> extends RestContextImpl<A, S> implements
|
||||||
public ConsistencyModels getConsistencyModel() {
|
public ConsistencyModels getConsistencyModel() {
|
||||||
return consistencyModel;
|
return consistencyModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public <A, S> RestContext<A, S> getProviderSpecificContext() {
|
||||||
|
return (RestContext<A, S>) providerSpecificContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
providerSpecificContext.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ public interface BlobStoreConstants {
|
||||||
public static final String PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX = "jclouds.blobstore.directorysuffix";
|
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.
|
* longest time a single synchronous operation can take before throwing an exception.
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.integration;
|
package org.jclouds.blobstore.integration;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -29,6 +27,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration" }, testName = "blobstore.StubBlobIntegrationTest")
|
@Test(groups = { "integration" }, testName = "blobstore.StubBlobIntegrationTest")
|
||||||
public class StubBlobIntegrationTest extends BaseBlobIntegrationTest<AsyncBlobStore, BlobStore> {
|
public class StubBlobIntegrationTest extends BaseBlobIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.integration;
|
package org.jclouds.blobstore.integration;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" }, testName = "blobstore.StubBlobMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "blobstore.StubBlobMapIntegrationTest")
|
||||||
public class StubBlobMapIntegrationTest extends
|
public class StubBlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
|
||||||
BaseBlobMapIntegrationTest<AsyncBlobStore, BlobStore> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -26,19 +26,17 @@ import java.util.concurrent.TimeUnit;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||||
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
|
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
|
||||||
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
|
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.concurrent.internal.SyncProxy;
|
import org.jclouds.concurrent.internal.SyncProxy;
|
||||||
import org.jclouds.lifecycle.Closer;
|
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.AbstractModule;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
@ -91,11 +89,9 @@ public class StubBlobStoreContextBuilder extends BlobStoreContextBuilder<AsyncBl
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> provideContext(BlobMap.Factory blobMapFactory,
|
RestContext<AsyncBlobStore, BlobStore> provideContext(Closer closer,
|
||||||
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
final AsyncBlobStore async, final BlobStore sync) {
|
||||||
AsyncBlobStore asynch, BlobStore synch) {
|
return new RestContextImpl<AsyncBlobStore, BlobStore>(closer, async, sync, URI
|
||||||
return new BlobStoreContextImpl<AsyncBlobStore, BlobStore>(blobMapFactory,
|
|
||||||
inputStreamMapFactory, closer, asynch, synch, asynch, synch, URI
|
|
||||||
.create("http://localhost/blobstub"), "foo");
|
.create("http://localhost/blobstub"), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.integration;
|
package org.jclouds.blobstore.integration;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -28,7 +26,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "blobstore.StubContainerIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "blobstore.StubContainerIntegrationTest")
|
||||||
public class StubContainerIntegrationTest extends
|
public class StubContainerIntegrationTest extends BaseContainerIntegrationTest {
|
||||||
BaseContainerIntegrationTest<AsyncBlobStore, BlobStore> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.integration;
|
package org.jclouds.blobstore.integration;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "blobstore.StubInputStreamMapIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "blobstore.StubInputStreamMapIntegrationTest")
|
||||||
public class StubInputStreamMapIntegrationTest extends
|
public class StubInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
|
||||||
BaseInputStreamMapIntegrationTest<AsyncBlobStore, BlobStore> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.integration;
|
package org.jclouds.blobstore.integration;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -27,7 +25,6 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "integration", "live" }, testName = "blobstore.StubServiceIntegrationTest")
|
@Test(groups = { "integration", "live" }, testName = "blobstore.StubServiceIntegrationTest")
|
||||||
public class StubServiceIntegrationTest extends
|
public class StubServiceIntegrationTest extends BaseServiceIntegrationTest {
|
||||||
BaseServiceIntegrationTest<AsyncBlobStore, BlobStore> {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.integration;
|
package org.jclouds.blobstore.integration;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseTestInitializer;
|
import org.jclouds.blobstore.integration.internal.BaseTestInitializer;
|
||||||
|
|
||||||
|
@ -29,17 +27,17 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class StubTestInitializer extends BaseTestInitializer<AsyncBlobStore, BlobStore> {
|
public class StubTestInitializer extends BaseTestInitializer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<AsyncBlobStore, BlobStore> createLiveContext(
|
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
|
||||||
Module configurationModule, String url, String app, String account, String key) {
|
String account, String key) {
|
||||||
return createStubContext();
|
return createStubContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlobStoreContext<AsyncBlobStore, BlobStore> createStubContext() {
|
protected BlobStoreContext createStubContext() {
|
||||||
return new StubBlobStoreContextBuilder().buildContext();
|
return new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -49,7 +49,7 @@ import org.testng.annotations.Test;
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BaseBlobIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
|
public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testGetIfModifiedSince() throws InterruptedException {
|
public void testGetIfModifiedSince() throws InterruptedException {
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = { "live" }, testName = "blobstore.BlobLiveTest")
|
@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
|
private static final String sysHttpStreamUrl = System
|
||||||
.getProperty("jclouds.blobstore.httpstream.url");
|
.getProperty("jclouds.blobstore.httpstream.url");
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.testng.annotations.Test;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A, S, Blob> {
|
public class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<Blob> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
|
@ -220,7 +220,6 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
|
||||||
map.putAll(newMap);
|
map.putAll(newMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected Map<String, Blob> createMap(BlobStoreContext context, String bucket) {
|
protected Map<String, Blob> createMap(BlobStoreContext context, String bucket) {
|
||||||
return context.createBlobMap(bucket);
|
return context.createBlobMap(bucket);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.inject.Module;
|
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 LOCAL_ENCODING = System.getProperty("file.encoding");
|
||||||
protected static final String XML_STRING_FORMAT = "<apples><apple name=\"%s\"></apple> </apples>";
|
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");
|
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;
|
public static long INCONSISTENCY_WINDOW = 5000;
|
||||||
protected static volatile AtomicInteger containerIndex = new AtomicInteger(0);
|
protected static volatile AtomicInteger containerIndex = new AtomicInteger(0);
|
||||||
|
|
||||||
protected volatile BlobStoreContext<A, S> context;
|
protected volatile BlobStoreContext context;
|
||||||
protected static volatile int containerCount = 10;
|
protected static volatile int containerCount = 10;
|
||||||
public static final String CONTAINER_PREFIX = System.getProperty("user.name") + "-blobstore";
|
public static final String CONTAINER_PREFIX = System.getProperty("user.name") + "-blobstore";
|
||||||
/**
|
/**
|
||||||
|
@ -91,14 +91,14 @@ public class BaseBlobStoreIntegrationTest<A, S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private BlobStoreContext<A, S> getCloudResources(ITestContext testContext)
|
private BlobStoreContext getCloudResources(ITestContext testContext)
|
||||||
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
||||||
Exception {
|
Exception {
|
||||||
String initializerClass = checkNotNull(System.getProperty("jclouds.test.initializer"),
|
String initializerClass = checkNotNull(System.getProperty("jclouds.test.initializer"),
|
||||||
"jclouds.test.initializer");
|
"jclouds.test.initializer");
|
||||||
Class<BaseTestInitializer<A, S>> clazz = (Class<BaseTestInitializer<A, S>>) Class
|
Class<BaseTestInitializer> clazz = (Class<BaseTestInitializer>) Class
|
||||||
.forName(initializerClass);
|
.forName(initializerClass);
|
||||||
BaseTestInitializer<A, S> initializer = clazz.newInstance();
|
BaseTestInitializer initializer = clazz.newInstance();
|
||||||
return initializer.init(createHttpModule(), testContext);
|
return initializer.init(createHttpModule(), testContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
|
||||||
|
|
||||||
private static volatile boolean initialized = false;
|
private static volatile boolean initialized = false;
|
||||||
|
|
||||||
protected void createContainersSharedByAllThreads(BlobStoreContext<A, S> context,
|
protected void createContainersSharedByAllThreads(BlobStoreContext context,
|
||||||
ITestContext testContext) throws Exception {
|
ITestContext testContext) throws Exception {
|
||||||
while (!initialized) {
|
while (!initialized) {
|
||||||
synchronized (BaseBlobStoreIntegrationTest.class) {
|
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) {
|
String containerName) {
|
||||||
try {
|
try {
|
||||||
deleteContainer(context, containerName);
|
deleteContainer(context, containerName);
|
||||||
|
@ -173,7 +173,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
|
||||||
/**
|
/**
|
||||||
* Tries to delete all containers, runs up to two times
|
* 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 {
|
try {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
Iterable<? extends StorageMetadata> testContainers = Iterables.filter(context
|
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,
|
* 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.
|
* 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 {
|
throws InterruptedException {
|
||||||
if (context.getConsistencyModel() == ConsistencyModels.STRICT) {
|
if (context.getConsistencyModel() == ConsistencyModels.STRICT) {
|
||||||
assertion.run();
|
assertion.run();
|
||||||
|
@ -237,7 +237,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
|
||||||
assertConsistencyAware(context, assertion);
|
assertConsistencyAware(context, assertion);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void createContainerAndEnsureEmpty(BlobStoreContext<?, ?> context,
|
protected static void createContainerAndEnsureEmpty(BlobStoreContext context,
|
||||||
final String containerName) throws InterruptedException {
|
final String containerName) throws InterruptedException {
|
||||||
context.getBlobStore().createContainerInLocation("default", containerName);
|
context.getBlobStore().createContainerInLocation("default", containerName);
|
||||||
if (context.getConsistencyModel() == ConsistencyModels.EVENTUAL)
|
if (context.getConsistencyModel() == ConsistencyModels.EVENTUAL)
|
||||||
|
@ -384,7 +384,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
|
||||||
return new JavaUrlHttpCommandExecutorServiceModule();
|
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 {
|
throws InterruptedException {
|
||||||
if (context.getBlobStore().containerExists(name)) {
|
if (context.getBlobStore().containerExists(name)) {
|
||||||
System.err.printf("*** deleting container %s...%n", name);
|
System.err.printf("*** deleting container %s...%n", name);
|
||||||
|
|
|
@ -39,7 +39,7 @@ import com.google.common.base.Throwables;
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BaseContainerIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
|
public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void containerDoesntExist() {
|
public void containerDoesntExist() {
|
||||||
|
|
|
@ -22,6 +22,6 @@ package org.jclouds.blobstore.integration.internal;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BaseContainerLiveTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
|
public class BaseContainerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
|
@ -41,8 +41,7 @@ import org.testng.annotations.Test;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BaseInputStreamMapIntegrationTest<A, S> extends
|
public class BaseInputStreamMapIntegrationTest extends BaseMapIntegrationTest<InputStream> {
|
||||||
BaseMapIntegrationTest<A, S, InputStream> {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
|
@ -191,7 +190,7 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testPutAllFiles() throws InterruptedException{
|
public void testPutAllFiles() throws InterruptedException {
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
Map<String, InputStream> map = createMap(context, bucketName);
|
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)
|
void getOneReturnsAppleAndOldValueIsNull(Map<String, InputStream> map, InputStream old)
|
||||||
throws IOException, InterruptedException
|
throws IOException, InterruptedException {
|
||||||
{
|
|
||||||
assert old == null;
|
assert old == null;
|
||||||
assertEquals(Utils.toStringAndClose(map.get("one")), String
|
assertEquals(Utils.toStringAndClose(map.get("one")), String
|
||||||
.format(XML_STRING_FORMAT, "apple"));
|
.format(XML_STRING_FORMAT, "apple"));
|
||||||
|
@ -245,7 +243,7 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
|
||||||
}
|
}
|
||||||
|
|
||||||
void getOneReturnsBearAndOldValueIsApple(Map<String, InputStream> map, InputStream oldValue)
|
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(map.get("one")), String.format(XML_STRING_FORMAT, "bear"));
|
||||||
assertEquals(Utils.toStringAndClose(oldValue), String.format(XML_STRING_FORMAT, "apple"));
|
assertEquals(Utils.toStringAndClose(oldValue), String.format(XML_STRING_FORMAT, "apple"));
|
||||||
assertConsistencyAwareMapSize(map, 1);
|
assertConsistencyAwareMapSize(map, 1);
|
||||||
|
@ -302,7 +300,7 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
|
||||||
((InputStreamMap) map).putString(key, value);
|
((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);
|
InputStreamMap map = context.createInputStreamMap(bucket);
|
||||||
return (Map<String, InputStream>) map;
|
return (Map<String, InputStream>) map;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.io.Files;
|
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,
|
public abstract void testPutAll() throws InterruptedException, ExecutionException,
|
||||||
TimeoutException;
|
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" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testClear() throws InterruptedException, ExecutionException, TimeoutException {
|
public void testClear() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.testng.annotations.Test;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BaseServiceIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
|
public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
void containerDoesntExist() {
|
void containerDoesntExist() {
|
||||||
|
|
|
@ -25,9 +25,9 @@ import org.testng.ITestContext;
|
||||||
|
|
||||||
import com.google.inject.Module;
|
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 {
|
throws Exception {
|
||||||
String endpoint = System.getProperty("jclouds.test.endpoint");
|
String endpoint = System.getProperty("jclouds.test.endpoint");
|
||||||
String app = System.getProperty("jclouds.test.app");
|
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,
|
protected abstract BlobStoreContext createLiveContext(Module configurationModule, String url,
|
||||||
String url, String app, String account, String key) throws IOException;
|
String app, String account, String key) throws IOException;
|
||||||
}
|
}
|
|
@ -22,8 +22,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
@ -42,13 +40,13 @@ import com.google.inject.util.Types;
|
||||||
@Test(groups = { "unit" }, testName = "blobstore.BaseBlobMapTest")
|
@Test(groups = { "unit" }, testName = "blobstore.BaseBlobMapTest")
|
||||||
public class BaseBlobMapTest {
|
public class BaseBlobMapTest {
|
||||||
|
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context;
|
BlobStoreContext context;
|
||||||
|
|
||||||
InputStreamMapImpl map;
|
InputStreamMapImpl map;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void addDefaultObjectsSoThatTestsWillPass() {
|
void addDefaultObjectsSoThatTestsWillPass() {
|
||||||
context = new StubBlobStoreContextBuilder().buildContext();
|
context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
map = (InputStreamMapImpl) context.createInputStreamMap("test");
|
map = (InputStreamMapImpl) context.createInputStreamMap("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,11 @@ import com.google.inject.ImplementedBy;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ImplementedBy(ComputeServiceContextImpl.class)
|
@ImplementedBy(ComputeServiceContextImpl.class)
|
||||||
public interface ComputeServiceContext<A, S> extends RestContext<A, S> {
|
public interface ComputeServiceContext {
|
||||||
|
|
||||||
ComputeService getComputeService();
|
ComputeService getComputeService();
|
||||||
|
|
||||||
|
<A, S> RestContext<A, S> getProviderSpecificContext();
|
||||||
|
|
||||||
|
void close();
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@ package org.jclouds.compute;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
import org.jclouds.rest.RestContextBuilder;
|
||||||
|
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
@ -46,17 +47,16 @@ public abstract class ComputeServiceContextBuilder<A, S> extends RestContextBuil
|
||||||
this(asyncClientType, syncClientType, new Properties());
|
this(asyncClientType, syncClientType, new Properties());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputeServiceContextBuilder(TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType,
|
public ComputeServiceContextBuilder(TypeLiteral<A> asyncClientType,
|
||||||
Properties properties) {
|
TypeLiteral<S> syncClientType, Properties properties) {
|
||||||
super(asyncClientType, syncClientType, properties);
|
super(asyncClientType, syncClientType, properties);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public ComputeServiceContext buildComputeServiceContext() {
|
||||||
@Override
|
// need the generic type information
|
||||||
public ComputeServiceContext<A, S> buildContext() {
|
return (ComputeServiceContext) buildInjector().getInstance(
|
||||||
return (ComputeServiceContext<A, S>) this.buildInjector().getInstance(
|
Key.get(Types.newParameterizedType(ComputeServiceContextImpl.class, asyncClientType
|
||||||
Key.get(Types.newParameterizedType(ComputeServiceContext.class,
|
.getType(), syncClientType.getType())));
|
||||||
asyncClientType.getType(), syncClientType.getType())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ import org.jclouds.rest.RestContextFactory;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ComputeServiceContextFactory extends
|
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
|
* 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) {
|
public ComputeServiceContextFactory(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ComputeServiceContext build(ComputeServiceContextBuilder<?, ?> contextBuilder) {
|
||||||
|
return contextBuilder.buildComputeServiceContext();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2,28 +2,38 @@ package org.jclouds.compute.internal;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ComputeServiceContextImpl<A, S> extends RestContextImpl<A, S> implements
|
public class ComputeServiceContextImpl<X, Y> implements ComputeServiceContext {
|
||||||
ComputeServiceContext<A, S> {
|
|
||||||
private final ComputeService computeService;
|
private final ComputeService computeService;
|
||||||
|
private final RestContext<X, Y> providerSpecificContext;
|
||||||
|
|
||||||
public ComputeServiceContextImpl(Closer closer, ComputeService computeService, A asyncApi,
|
@Inject
|
||||||
S syncApi, URI endPoint, String account) {
|
public ComputeServiceContextImpl(ComputeService computeService,
|
||||||
super(closer, asyncApi, syncApi, endPoint, account);
|
RestContext<X, Y> providerSpecificContext) {
|
||||||
this.computeService = checkNotNull(computeService, "computeService");
|
this.computeService = checkNotNull(computeService, "computeService");
|
||||||
|
this.providerSpecificContext = providerSpecificContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputeService getComputeService() {
|
public ComputeService getComputeService() {
|
||||||
return computeService;
|
return computeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public <A, S> RestContext<A, S> getProviderSpecificContext() {
|
||||||
|
return (RestContext<A, S>) providerSpecificContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
providerSpecificContext.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,10 @@ package org.jclouds.rest;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import com.google.inject.ImplementedBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an authenticated context to the cloud.
|
* Represents an authenticated context to the cloud.
|
||||||
|
@ -32,6 +35,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ImplementedBy(RestContextImpl.class)
|
||||||
public interface RestContext<A, S> {
|
public interface RestContext<A, S> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
@ -39,7 +40,7 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @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 static Properties NO_PROPERTIES = new Properties();
|
||||||
private final Properties 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);
|
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))
|
* FIXME Comment this // ImmutableSet.<Module>of(new ExecutorServiceModule(myexecutor))
|
||||||
*
|
*
|
||||||
* @param hint
|
* @param hint
|
||||||
* @param account
|
* @param account
|
||||||
|
* nullable, if credentials are present in the overrides
|
||||||
* @param key
|
* @param key
|
||||||
|
* nullable, if credentials are present in the overrides
|
||||||
* @param modules
|
* @param modules
|
||||||
* @param overrides
|
* @param overrides
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@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) {
|
Iterable<? extends Module> modules, Properties overrides) {
|
||||||
checkNotNull(hint, "hint");
|
checkNotNull(hint, "hint");
|
||||||
checkNotNull(account, "account");
|
|
||||||
checkNotNull(key, "key");
|
|
||||||
checkNotNull(modules, "modules");
|
checkNotNull(modules, "modules");
|
||||||
checkNotNull(overrides, "overrides");
|
checkNotNull(overrides, "overrides");
|
||||||
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
|
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
|
||||||
|
@ -147,12 +156,17 @@ public class RestContextFactory<T extends RestContext<?, ?>, B extends RestConte
|
||||||
.forName(propertiesBuilderClassName);
|
.forName(propertiesBuilderClassName);
|
||||||
Class<B> contextBuilderClass = (Class<B>) Class.forName(contextBuilderClassName);
|
Class<B> contextBuilderClass = (Class<B>) Class.forName(contextBuilderClassName);
|
||||||
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(Properties.class)
|
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(Properties.class)
|
||||||
.newInstance(overrides).withCredentials(account, key);
|
.newInstance(overrides);
|
||||||
return (T) contextBuilderClass.getConstructor(Properties.class).newInstance(
|
if (key != null)
|
||||||
builder.build()).withModules(Iterables.toArray(modules, Module.class))
|
builder.withCredentials(account, key);
|
||||||
.buildContext();
|
|
||||||
|
B contextBuilder = (B) contextBuilderClass.getConstructor(Properties.class).newInstance(
|
||||||
|
builder.build()).withModules(Iterables.toArray(modules, Module.class));
|
||||||
|
return build(contextBuilder);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
|
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract T build(B contextBuilder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -40,6 +41,7 @@ public class RestContextImpl<A, S> implements RestContext<A, S> {
|
||||||
private final URI endPoint;
|
private final URI endPoint;
|
||||||
private final String account;
|
private final String account;
|
||||||
|
|
||||||
|
@Inject
|
||||||
public RestContextImpl(Closer closer, A asyncApi, S syncApi, URI endPoint, String account) {
|
public RestContextImpl(Closer closer, A asyncApi, S syncApi, URI endPoint, String account) {
|
||||||
this.asyncApi = asyncApi;
|
this.asyncApi = asyncApi;
|
||||||
this.syncApi = syncApi;
|
this.syncApi = syncApi;
|
||||||
|
|
|
@ -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.appengine.api.labs.taskqueue.TaskOptions.Builder.url;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
@ -36,7 +36,7 @@ import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
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.AddTweetsController;
|
||||||
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
||||||
import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses;
|
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.Queue;
|
||||||
import com.google.appengine.api.labs.taskqueue.QueueFactory;
|
import com.google.appengine.api.labs.taskqueue.QueueFactory;
|
||||||
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;
|
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.collect.Maps;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates servlets (using resources from the {@link SpringAppConfig}) and mappings.
|
* 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 {
|
public class SpringServletConfig extends LoggingConfig implements ServletConfigAware {
|
||||||
private ServletConfig servletConfig;
|
private ServletConfig servletConfig;
|
||||||
|
|
||||||
private Map<String, BlobStoreContext<?, ?>> providerTypeToBlobStoreMap;
|
private Map<String, BlobStoreContext> providerTypeToBlobStoreMap;
|
||||||
private TwitterClient twitterClient;
|
private TwitterClient twitterClient;
|
||||||
private String container;
|
private String container;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initialize() {
|
public void initialize() throws IOException {
|
||||||
Properties props = loadJCloudsProperties();
|
Properties props = loadJCloudsProperties();
|
||||||
logger.trace("About to initialize members.");
|
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
|
// shared across all blobstores and used to retrieve tweets
|
||||||
twitterClient = TwitterContextFactory.createContext(props,
|
twitterClient = TwitterContextFactory.createContext(props, googleModule).getApi();
|
||||||
new GoogleAppEngineConfigurationModule()).getApi();
|
|
||||||
|
|
||||||
// common namespace for storing tweets
|
// common namespace for storing tweets
|
||||||
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
||||||
PROPERTY_TWEETSTORE_CONTAINER);
|
PROPERTY_TWEETSTORE_CONTAINER);
|
||||||
ImmutableList<String> contextBuilderClassNames = ImmutableList.<String>of(
|
BlobStoreContextFactory blobStoreContextFactory = new BlobStoreContextFactory();
|
||||||
checkNotNull(props.getProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
|
|
||||||
PROPERTY_BLOBSTORE_CONTEXTBUILDERS)
|
|
||||||
.split(","));
|
|
||||||
|
|
||||||
// instantiate and store references to all blobstores by provider name
|
// instantiate and store references to all blobstores by provider name
|
||||||
providerTypeToBlobStoreMap = Maps.newHashMap();
|
providerTypeToBlobStoreMap = Maps.newHashMap();
|
||||||
for (String className : contextBuilderClassNames) {
|
for (String hint : Splitter.on(',').split(
|
||||||
Class<BlobStoreContextBuilder<?, ?>> builderClass;
|
checkNotNull(props.getProperty(PROPERTY_BLOBSTORE_CONTEXTS),
|
||||||
Constructor<BlobStoreContextBuilder<?, ?>> constructor;
|
PROPERTY_BLOBSTORE_CONTEXTS))) {
|
||||||
String name;
|
providerTypeToBlobStoreMap.put(hint, blobStoreContextFactory.createContext(hint, modules,
|
||||||
BlobStoreContext<?, ?> context;
|
props));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a queue for submitting store tweet requests
|
// get a queue for submitting store tweet requests
|
||||||
|
@ -117,15 +104,16 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
for (String name : providerTypeToBlobStoreMap.keySet()) {
|
for (String name : providerTypeToBlobStoreMap.keySet()) {
|
||||||
queue.add(url("/store/do").header("context", name).method(Method.GET));
|
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());
|
twitterClient, container, providerTypeToBlobStoreMap.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadJCloudsProperties() {
|
private Properties loadJCloudsProperties() {
|
||||||
logger.trace("About to read properties from '%s'", "/WEB-INF/jclouds.properties");
|
logger.trace("About to read properties from '%s'", "/WEB-INF/jclouds.properties");
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
InputStream input = servletConfig.getServletContext()
|
InputStream input = servletConfig.getServletContext().getResourceAsStream(
|
||||||
.getResourceAsStream("/WEB-INF/jclouds.properties");
|
"/WEB-INF/jclouds.properties");
|
||||||
try {
|
try {
|
||||||
props.load(input);
|
props.load(input);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -176,8 +164,8 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
urlMap.put("/tweets/*", addTweetsController());
|
urlMap.put("/tweets/*", addTweetsController());
|
||||||
mapping.setUrlMap(urlMap);
|
mapping.setUrlMap(urlMap);
|
||||||
/*
|
/*
|
||||||
* "/store" and "/tweets" are part of the servlet mapping and thus stripped
|
* "/store" and "/tweets" are part of the servlet mapping and thus stripped by the mapping if
|
||||||
* by the mapping if using default settings.
|
* using default settings.
|
||||||
*/
|
*/
|
||||||
mapping.setAlwaysUseFullPath(true);
|
mapping.setAlwaysUseFullPath(true);
|
||||||
return mapping;
|
return mapping;
|
||||||
|
@ -191,14 +179,18 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void destroy() throws Exception {
|
public void destroy() throws Exception {
|
||||||
logger.trace("About to close contexts.");
|
logger.trace("About to close contexts.");
|
||||||
for (BlobStoreContext<?, ?> context : providerTypeToBlobStoreMap.values()) {
|
for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
logger.trace("Contexts closed.");
|
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
|
@Override
|
||||||
public void setServletConfig(ServletConfig servletConfig) {
|
public void setServletConfig(ServletConfig servletConfig) {
|
||||||
|
|
|
@ -54,14 +54,14 @@ public class AddTweetsController extends HttpServlet implements
|
||||||
|
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = 3888348023150822683L;
|
private static final long serialVersionUID = 3888348023150822683L;
|
||||||
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
private final Map<String, BlobStoreContext> contexts;
|
||||||
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
|
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AddTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
public AddTweetsController(Map<String, BlobStoreContext> contexts,
|
||||||
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = 7215420527854203714L;
|
private static final long serialVersionUID = 7215420527854203714L;
|
||||||
|
|
||||||
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
private final Map<String, BlobStoreContext> contexts;
|
||||||
private final TwitterClient client;
|
private final TwitterClient client;
|
||||||
private final String container;
|
private final String container;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public StoreTweetsController(
|
public StoreTweetsController(
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts,
|
Map<String, BlobStoreContext> contexts,
|
||||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
|
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
|
||||||
TwitterClient client) {
|
TwitterClient client) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
@ -93,7 +93,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void addMyTweets(String contextName, SortedSet<Status> allAboutMe) {
|
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());
|
"no context for " + contextName + " in " + contexts.keySet());
|
||||||
BlobMap map = context.createBlobMap(container);
|
BlobMap map = context.createBlobMap(container);
|
||||||
for (Status status : allAboutMe) {
|
for (Status status : allAboutMe) {
|
||||||
|
|
|
@ -39,11 +39,11 @@ import com.google.common.collect.Iterables;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
|
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
|
||||||
|
|
||||||
private final Map<String, BlobStoreContext<?,?>> contexts;
|
private final Map<String, BlobStoreContext> contexts;
|
||||||
private final String container;
|
private final String container;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext<?,?>> contexts,
|
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext> contexts,
|
||||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
|
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
@ -53,8 +53,8 @@ public class ServiceToStoredTweetStatuses implements Function<String, Iterable<S
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
public Iterable<StoredTweetStatus> apply(String service) {
|
public Iterable<StoredTweetStatus> apply(String service) {
|
||||||
BlobStoreContext<?, ?> context = contexts.get(service);
|
BlobStoreContext context = contexts.get(service);
|
||||||
String host = context.getEndPoint().getHost();
|
String host = context.getProviderSpecificContext().getEndPoint().getHost();
|
||||||
try {
|
try {
|
||||||
BlobMap blobMap = context.createBlobMap(container);
|
BlobMap blobMap = context.createBlobMap(container);
|
||||||
Set<String> blobs = blobMap.keySet();
|
Set<String> blobs = blobMap.keySet();
|
||||||
|
|
|
@ -25,8 +25,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
@ -47,12 +45,11 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Test(groups = "unit", testName = "tweetstore.AddTweetsControllerTest")
|
@Test(groups = "unit", testName = "tweetstore.AddTweetsControllerTest")
|
||||||
public class AddTweetsControllerTest {
|
public class AddTweetsControllerTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext<?, ?>> createServices(String container)
|
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
|
||||||
throws InterruptedException, ExecutionException {
|
ExecutionException {
|
||||||
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
|
Map<String, BlobStoreContext> services = Maps.newHashMap();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
.buildContext();
|
|
||||||
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
|
@ -65,7 +62,7 @@ public class AddTweetsControllerTest {
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
String container = "container";
|
String container = "container";
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
|
Map<String, BlobStoreContext> contexts = createServices(container);
|
||||||
|
|
||||||
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
||||||
AddTweetsController controller = new AddTweetsController(contexts, function);
|
AddTweetsController controller = new AddTweetsController(contexts, function);
|
||||||
|
|
|
@ -54,19 +54,18 @@ public class StoreTweetsControllerTest {
|
||||||
return createMock(TwitterClient.class);
|
return createMock(TwitterClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, BlobStoreContext<?, ?>> createBlobStores() throws InterruptedException,
|
Map<String, BlobStoreContext> createBlobStores() throws InterruptedException, ExecutionException {
|
||||||
ExecutionException {
|
Map<String, BlobStoreContext> contexts = ImmutableMap.<String, BlobStoreContext> of("test1",
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap
|
new StubBlobStoreContextBuilder().buildBlobStoreContext(), "test2",
|
||||||
.<String, BlobStoreContext<?, ?>> of("test1", new StubBlobStoreContextBuilder()
|
new StubBlobStoreContextBuilder().buildBlobStoreContext());
|
||||||
.buildContext(), "test2", new StubBlobStoreContextBuilder().buildContext());
|
for (BlobStoreContext blobstore : contexts.values()) {
|
||||||
for (BlobStoreContext<?, ?> blobstore : contexts.values()) {
|
|
||||||
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
|
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
|
||||||
}
|
}
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
Map<String, BlobStoreContext<?, ?>> stores = createBlobStores();
|
Map<String, BlobStoreContext> stores = createBlobStores();
|
||||||
StoreTweetsController function = new StoreTweetsController(stores, "favo",
|
StoreTweetsController function = new StoreTweetsController(stores, "favo",
|
||||||
createTwitterClient());
|
createTwitterClient());
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ public class StoreTweetsControllerTest {
|
||||||
function.addMyTweets("test1", allAboutMe);
|
function.addMyTweets("test1", allAboutMe);
|
||||||
function.addMyTweets("test2", 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");
|
BlobMap map = entry.getValue().createBlobMap("favo");
|
||||||
Blob frankBlob = map.get("1");
|
Blob frankBlob = map.get("1");
|
||||||
assertEquals(frankBlob.getMetadata().getName(), "1");
|
assertEquals(frankBlob.getMetadata().getName(), "1");
|
||||||
|
|
|
@ -23,9 +23,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
@ -42,8 +40,7 @@ import org.testng.annotations.Test;
|
||||||
public class KeyToStoredTweetStatusTest {
|
public class KeyToStoredTweetStatusTest {
|
||||||
|
|
||||||
BlobMap createMap() throws InterruptedException, ExecutionException {
|
BlobMap createMap() throws InterruptedException, ExecutionException {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
.buildContext();
|
|
||||||
context.getBlobStore().createContainerInLocation(null, "test1");
|
context.getBlobStore().createContainerInLocation(null, "test1");
|
||||||
return context.createBlobMap("test1");
|
return context.createBlobMap("test1");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@ import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
@ -44,12 +42,11 @@ import com.google.common.collect.Iterables;
|
||||||
@Test(groups = "unit", testName = "tweetstore.ServiceToStoredTweetStatuses")
|
@Test(groups = "unit", testName = "tweetstore.ServiceToStoredTweetStatuses")
|
||||||
public class ServiceToStoredTweetStatusesTest {
|
public class ServiceToStoredTweetStatusesTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext<?, ?>> createServices(String container)
|
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
|
||||||
throws InterruptedException, ExecutionException {
|
ExecutionException {
|
||||||
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
|
Map<String, BlobStoreContext> services = Maps.newHashMap();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
.buildContext();
|
|
||||||
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
|
@ -62,7 +59,7 @@ public class ServiceToStoredTweetStatusesTest {
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
String container = "container";
|
String container = "container";
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
|
Map<String, BlobStoreContext> contexts = createServices(container);
|
||||||
|
|
||||||
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
||||||
|
|
||||||
|
|
|
@ -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.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_ACCOUNT;
|
||||||
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY;
|
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.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_KEY;
|
||||||
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER;
|
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 java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
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.AzureBlobPropertiesBuilder;
|
||||||
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextFactory;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder;
|
|
||||||
import org.jclouds.twitter.TwitterPropertiesBuilder;
|
import org.jclouds.twitter.TwitterPropertiesBuilder;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
@ -66,7 +63,7 @@ public class TweetStoreLiveTest {
|
||||||
|
|
||||||
GoogleDevServer server;
|
GoogleDevServer server;
|
||||||
private URL url;
|
private URL url;
|
||||||
private Iterable<BlobStoreContext<? extends Object, ? extends Object>> contexts;
|
private Iterable<BlobStoreContext> contexts;
|
||||||
private String container;
|
private String container;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
|
@ -77,11 +74,9 @@ public class TweetStoreLiveTest {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, checkNotNull(System
|
props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, checkNotNull(System
|
||||||
.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER));
|
.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER));
|
||||||
props.setProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS,
|
|
||||||
// WATCH THIS.. when adding a new context, you must update the string
|
// WATCH THIS.. when adding a new context, you must update the string
|
||||||
String.format("%s,%s,%s", S3BlobStoreContextBuilder.class.getName(),
|
props.setProperty(PROPERTY_BLOBSTORE_CONTEXTS, "cloudfiles,s3");
|
||||||
CloudFilesBlobStoreContextBuilder.class.getName(),
|
|
||||||
AzureBlobStoreContextBuilder.class.getName()));
|
|
||||||
|
|
||||||
props = new TwitterPropertiesBuilder(props).withCredentials(
|
props = new TwitterPropertiesBuilder(props).withCredentials(
|
||||||
checkNotNull(System.getProperty(PROPERTY_TWITTER_USER), PROPERTY_TWITTER_USER),
|
checkNotNull(System.getProperty(PROPERTY_TWITTER_USER), PROPERTY_TWITTER_USER),
|
||||||
|
@ -112,23 +107,25 @@ public class TweetStoreLiveTest {
|
||||||
TimeoutException, IOException {
|
TimeoutException, IOException {
|
||||||
container = checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER));
|
container = checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER));
|
||||||
BlobStoreContextFactory factory = new BlobStoreContextFactory();
|
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_ACCESSKEYID), PROPERTY_AWS_ACCESSKEYID), System
|
||||||
.getProperty(PROPERTY_AWS_SECRETACCESSKEY, PROPERTY_AWS_SECRETACCESSKEY));
|
.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(
|
.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER), System.getProperty(
|
||||||
PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY));
|
PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY));
|
||||||
|
|
||||||
BlobStoreContext<?, ?> azContext = factory.createContext("azureblob", checkNotNull(System
|
// BlobStoreContext azContext = factory.createContext("azureblob", checkNotNull(System
|
||||||
.getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), PROPERTY_AZURESTORAGE_ACCOUNT), System
|
// .getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), PROPERTY_AZURESTORAGE_ACCOUNT), System
|
||||||
.getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY));
|
// .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;
|
boolean deleted = false;
|
||||||
for (BlobStoreContext<?, ?> context : contexts) {
|
for (BlobStoreContext context : contexts) {
|
||||||
if (context.getBlobStore().containerExists(container)) {
|
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);
|
context.getBlobStore().deleteContainer(container);
|
||||||
deleted = true;
|
deleted = true;
|
||||||
}
|
}
|
||||||
|
@ -137,8 +134,9 @@ public class TweetStoreLiveTest {
|
||||||
System.err.println("sleeping 60 seconds to allow containers to clear");
|
System.err.println("sleeping 60 seconds to allow containers to clear");
|
||||||
Thread.sleep(60000);
|
Thread.sleep(60000);
|
||||||
}
|
}
|
||||||
for (BlobStoreContext<?, ?> context : contexts) {
|
for (BlobStoreContext context : contexts) {
|
||||||
System.err.printf("creating container %s at %s%n", container, context.getEndPoint());
|
System.err.printf("creating container %s at %s%n", container, context
|
||||||
|
.getProviderSpecificContext().getEndPoint());
|
||||||
context.getBlobStore().createContainerInLocation(null, container);
|
context.getBlobStore().createContainerInLocation(null, container);
|
||||||
}
|
}
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
|
@ -162,8 +160,8 @@ public class TweetStoreLiveTest {
|
||||||
@Test(dependsOnMethods = "shouldFail")
|
@Test(dependsOnMethods = "shouldFail")
|
||||||
public void testPrimeContainers() throws IOException, InterruptedException {
|
public void testPrimeContainers() throws IOException, InterruptedException {
|
||||||
URL gurl = new URL(url, "/store/do");
|
URL gurl = new URL(url, "/store/do");
|
||||||
|
// WATCH THIS, you need to add a context each time
|
||||||
for (String context : new String[] { "S3", "Azure", "CloudFiles" }) {
|
for (String context : new String[] { "cloudfiles", "s3" }) {
|
||||||
System.out.println("storing at context: " + context);
|
System.out.println("storing at context: " + context);
|
||||||
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection();
|
||||||
connection.addRequestProperty("X-AppEngine-QueueName", "twitter");
|
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");
|
System.err.println("sleeping 20 seconds to allow for eventual consistency delay");
|
||||||
Thread.sleep(20000);
|
Thread.sleep(20000);
|
||||||
for (BlobStoreContext<?, ?> context : contexts) {
|
for (BlobStoreContext context : contexts) {
|
||||||
assert context.createInputStreamMap(container).size() > 0 : context.getEndPoint();
|
assert context.createInputStreamMap(container).size() > 0 : context
|
||||||
|
.getProviderSpecificContext().getEndPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.appengine.api.labs.taskqueue.TaskOptions.Builder.url;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
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.AddTweetsController;
|
||||||
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
||||||
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
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.Queue;
|
||||||
import com.google.appengine.api.labs.taskqueue.QueueFactory;
|
import com.google.appengine.api.labs.taskqueue.QueueFactory;
|
||||||
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;
|
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.collect.Maps;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.servlet.GuiceServletContextListener;
|
import com.google.inject.servlet.GuiceServletContextListener;
|
||||||
import com.google.inject.servlet.ServletModule;
|
import com.google.inject.servlet.ServletModule;
|
||||||
|
@ -59,44 +62,38 @@ import com.google.inject.util.Jsr330;
|
||||||
*/
|
*/
|
||||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
private Map<String, BlobStoreContext<?, ?>> providerTypeToBlobStoreMap;
|
private Map<String, BlobStoreContext> providerTypeToBlobStoreMap;
|
||||||
private TwitterClient twitterClient;
|
private TwitterClient twitterClient;
|
||||||
private String container;
|
private String container;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
|
|
||||||
|
BlobStoreContextFactory blobStoreContextFactory = null;
|
||||||
|
try {
|
||||||
|
blobStoreContextFactory = new BlobStoreContextFactory();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
}
|
||||||
|
|
||||||
Properties props = loadJCloudsProperties(servletContextEvent);
|
Properties props = loadJCloudsProperties(servletContextEvent);
|
||||||
|
|
||||||
|
Module googleModule = new GoogleAppEngineConfigurationModule();
|
||||||
|
Set<Module> modules = ImmutableSet.<Module> of(googleModule);
|
||||||
// shared across all blobstores and used to retrieve tweets
|
// shared across all blobstores and used to retrieve tweets
|
||||||
twitterClient = TwitterContextFactory.createContext(props,
|
twitterClient = TwitterContextFactory.createContext(props, googleModule).getApi();
|
||||||
new GoogleAppEngineConfigurationModule()).getApi();
|
|
||||||
|
|
||||||
// common namespace for storing tweets.
|
// common namespace for storing tweets
|
||||||
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
||||||
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
|
// instantiate and store references to all blobstores by provider name
|
||||||
providerTypeToBlobStoreMap = Maps.newHashMap();
|
providerTypeToBlobStoreMap = Maps.newHashMap();
|
||||||
for (String className : contextBuilderClassNames) {
|
for (String hint : Splitter.on(',').split(
|
||||||
Class<BlobStoreContextBuilder<?, ?>> builderClass;
|
checkNotNull(props.getProperty(PROPERTY_BLOBSTORE_CONTEXTS),
|
||||||
Constructor<BlobStoreContextBuilder<?, ?>> constructor;
|
PROPERTY_BLOBSTORE_CONTEXTS))) {
|
||||||
String name;
|
providerTypeToBlobStoreMap.put(hint, blobStoreContextFactory.createContext(hint, modules,
|
||||||
BlobStoreContext<?, ?> context;
|
props));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a queue for submitting store tweet requests
|
// get a queue for submitting store tweet requests
|
||||||
|
@ -128,8 +125,8 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
return Guice.createInjector(new ServletModule() {
|
return Guice.createInjector(new ServletModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
protected void configureServlets() {
|
||||||
bind(new TypeLiteral<Map<String, BlobStoreContext<?, ?>>>() {})
|
bind(new TypeLiteral<Map<String, BlobStoreContext>>() {
|
||||||
.toInstance(providerTypeToBlobStoreMap);
|
}).toInstance(providerTypeToBlobStoreMap);
|
||||||
bind(TwitterClient.class).toInstance(twitterClient);
|
bind(TwitterClient.class).toInstance(twitterClient);
|
||||||
bindConstant().annotatedWith(Jsr330.named(PROPERTY_TWEETSTORE_CONTAINER)).to(container);
|
bindConstant().annotatedWith(Jsr330.named(PROPERTY_TWEETSTORE_CONTAINER)).to(container);
|
||||||
serve("/store/*").with(StoreTweetsController.class);
|
serve("/store/*").with(StoreTweetsController.class);
|
||||||
|
@ -140,7 +137,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
||||||
for (BlobStoreContext<?, ?> context : providerTypeToBlobStoreMap.values()) {
|
for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
super.contextDestroyed(servletContextEvent);
|
super.contextDestroyed(servletContextEvent);
|
||||||
|
|
|
@ -54,14 +54,14 @@ public class AddTweetsController extends HttpServlet implements
|
||||||
|
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = 3888348023150822683L;
|
private static final long serialVersionUID = 3888348023150822683L;
|
||||||
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
private final Map<String, BlobStoreContext> contexts;
|
||||||
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
|
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AddTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
AddTweetsController(Map<String, BlobStoreContext> contexts,
|
||||||
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = 7215420527854203714L;
|
private static final long serialVersionUID = 7215420527854203714L;
|
||||||
|
|
||||||
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
private final Map<String, BlobStoreContext> contexts;
|
||||||
private final TwitterClient client;
|
private final TwitterClient client;
|
||||||
private final String container;
|
private final String container;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
StoreTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
StoreTweetsController(Map<String, BlobStoreContext> contexts,
|
||||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
|
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
|
||||||
TwitterClient client) {
|
TwitterClient client) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
@ -92,7 +92,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void addMyTweets(String contextName, SortedSet<Status> allAboutMe) {
|
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());
|
+ contextName + " in " + contexts.keySet());
|
||||||
BlobMap map = context.createBlobMap(container);
|
BlobMap map = context.createBlobMap(container);
|
||||||
for (Status status : allAboutMe) {
|
for (Status status : allAboutMe) {
|
||||||
|
|
|
@ -39,11 +39,11 @@ import com.google.common.collect.Iterables;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
|
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
|
||||||
|
|
||||||
private final Map<String, BlobStoreContext<?,?>> contexts;
|
private final Map<String, BlobStoreContext> contexts;
|
||||||
private final String container;
|
private final String container;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext<?,?>> contexts,
|
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext> contexts,
|
||||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
|
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
@ -53,8 +53,8 @@ public class ServiceToStoredTweetStatuses implements Function<String, Iterable<S
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
public Iterable<StoredTweetStatus> apply(String service) {
|
public Iterable<StoredTweetStatus> apply(String service) {
|
||||||
BlobStoreContext<?, ?> context = contexts.get(service);
|
BlobStoreContext context = contexts.get(service);
|
||||||
String host = context.getEndPoint().getHost();
|
String host = context.getProviderSpecificContext().getEndPoint().getHost();
|
||||||
try {
|
try {
|
||||||
BlobMap blobMap = context.createBlobMap(container);
|
BlobMap blobMap = context.createBlobMap(container);
|
||||||
Set<String> blobs = blobMap.keySet();
|
Set<String> blobs = blobMap.keySet();
|
||||||
|
|
|
@ -25,8 +25,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
@ -47,12 +45,11 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Test(groups = "unit", testName = "tweetstore.AddTweetsControllerTest")
|
@Test(groups = "unit", testName = "tweetstore.AddTweetsControllerTest")
|
||||||
public class AddTweetsControllerTest {
|
public class AddTweetsControllerTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext<?, ?>> createServices(String container)
|
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
|
||||||
throws InterruptedException, ExecutionException {
|
ExecutionException {
|
||||||
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
|
Map<String, BlobStoreContext> services = Maps.newHashMap();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
.buildContext();
|
|
||||||
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
|
@ -65,7 +62,7 @@ public class AddTweetsControllerTest {
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
String container = "container";
|
String container = "container";
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
|
Map<String, BlobStoreContext> contexts = createServices(container);
|
||||||
|
|
||||||
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
||||||
AddTweetsController controller = new AddTweetsController(contexts, function);
|
AddTweetsController controller = new AddTweetsController(contexts, function);
|
||||||
|
|
|
@ -54,19 +54,18 @@ public class StoreTweetsControllerTest {
|
||||||
return createMock(TwitterClient.class);
|
return createMock(TwitterClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, BlobStoreContext<?, ?>> createBlobStores() throws InterruptedException,
|
Map<String, BlobStoreContext> createBlobStores() throws InterruptedException, ExecutionException {
|
||||||
ExecutionException {
|
Map<String, BlobStoreContext> contexts = ImmutableMap.<String, BlobStoreContext> of("test1",
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap
|
new StubBlobStoreContextBuilder().buildBlobStoreContext(), "test2",
|
||||||
.<String, BlobStoreContext<?, ?>> of("test1", new StubBlobStoreContextBuilder()
|
new StubBlobStoreContextBuilder().buildBlobStoreContext());
|
||||||
.buildContext(), "test2", new StubBlobStoreContextBuilder().buildContext());
|
for (BlobStoreContext blobstore : contexts.values()) {
|
||||||
for (BlobStoreContext<?, ?> blobstore : contexts.values()) {
|
|
||||||
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
|
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
|
||||||
}
|
}
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
Map<String, BlobStoreContext<?, ?>> stores = createBlobStores();
|
Map<String, BlobStoreContext> stores = createBlobStores();
|
||||||
StoreTweetsController function = new StoreTweetsController(stores, "favo",
|
StoreTweetsController function = new StoreTweetsController(stores, "favo",
|
||||||
createTwitterClient());
|
createTwitterClient());
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ public class StoreTweetsControllerTest {
|
||||||
function.addMyTweets("test1", allAboutMe);
|
function.addMyTweets("test1", allAboutMe);
|
||||||
function.addMyTweets("test2", 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");
|
BlobMap map = entry.getValue().createBlobMap("favo");
|
||||||
Blob frankBlob = map.get("1");
|
Blob frankBlob = map.get("1");
|
||||||
assertEquals(frankBlob.getMetadata().getName(), "1");
|
assertEquals(frankBlob.getMetadata().getName(), "1");
|
||||||
|
|
|
@ -23,9 +23,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
@ -42,8 +40,7 @@ import org.testng.annotations.Test;
|
||||||
public class KeyToStoredTweetStatusTest {
|
public class KeyToStoredTweetStatusTest {
|
||||||
|
|
||||||
BlobMap createMap() throws InterruptedException, ExecutionException {
|
BlobMap createMap() throws InterruptedException, ExecutionException {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
.buildContext();
|
|
||||||
context.getBlobStore().createContainerInLocation(null, "test1");
|
context.getBlobStore().createContainerInLocation(null, "test1");
|
||||||
return context.createBlobMap("test1");
|
return context.createBlobMap("test1");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@ import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
@ -44,12 +42,11 @@ import com.google.common.collect.Iterables;
|
||||||
@Test(groups = "unit", testName = "tweetstore.ServiceToStoredTweetStatuses")
|
@Test(groups = "unit", testName = "tweetstore.ServiceToStoredTweetStatuses")
|
||||||
public class ServiceToStoredTweetStatusesTest {
|
public class ServiceToStoredTweetStatusesTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext<?, ?>> createServices(String container)
|
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
|
||||||
throws InterruptedException, ExecutionException {
|
ExecutionException {
|
||||||
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
|
Map<String, BlobStoreContext> services = Maps.newHashMap();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
|
||||||
.buildContext();
|
|
||||||
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
|
@ -62,7 +59,7 @@ public class ServiceToStoredTweetStatusesTest {
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
String container = "container";
|
String container = "container";
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
|
Map<String, BlobStoreContext> contexts = createServices(container);
|
||||||
|
|
||||||
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue