mirror of https://github.com/apache/jclouds.git
refactored configuration module so that Issue 201 could occur. linked context with objects created from it
This commit is contained in:
parent
17429154b9
commit
b190651247
|
@ -1,121 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
#set( $lcaseClientName = ${clientName.toLowerCase()} )
|
|
||||||
#set( $ucaseClientName = ${clientName.toUpperCase()} )
|
|
||||||
#set( $symbol_pound = '#' )
|
|
||||||
#set( $symbol_dollar = '$' )
|
|
||||||
#set( $symbol_escape = '\' )
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package ${package};
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import ${package}.config.${clientName}RestClientModule;
|
|
||||||
import ${package}.reference.${clientName}Constants;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in ${clientName}ContextBuilder
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "${lcaseClientName}.${clientName}ContextBuilderTest")
|
|
||||||
public class ${clientName}ContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
${clientName}ContextBuilder builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_ENDPOINT),
|
|
||||||
"${clientEndpoint}");
|
|
||||||
assertEquals(builder.getProperties().getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_USER),
|
|
||||||
"user");
|
|
||||||
assertEquals(builder.getProperties().getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_PASSWORD),
|
|
||||||
"password");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContext<${clientName}AsyncClient, ${clientName}Client> context = newBuilder().buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAccount(), "user");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("${clientEndpoint}"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<RestContext<${clientName}AsyncClient, ${clientName}Client>>() {
|
|
||||||
})) != null; // TODO: test all things taken from context
|
|
||||||
assert i.getInstance(BasicAuthentication.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
${clientName}ContextBuilder builder = newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), ${clientName}RestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ${clientName}ContextBuilder newBuilder() {
|
|
||||||
${clientName}ContextBuilder builder = new ${clientName}ContextBuilder(new ${clientName}PropertiesBuilder(
|
|
||||||
"user", "password").build());
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
${clientName}ContextBuilder builder = newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), ${clientName}RestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -43,8 +43,6 @@ import org.jclouds.atmosonline.saas.functions.ParseObjectFromHeadersAndHttpConte
|
||||||
import org.jclouds.atmosonline.saas.functions.ParseSystemMetadataFromHeaders;
|
import org.jclouds.atmosonline.saas.functions.ParseSystemMetadataFromHeaders;
|
||||||
import org.jclouds.atmosonline.saas.functions.ReturnEndpointIfAlreadyExists;
|
import org.jclouds.atmosonline.saas.functions.ReturnEndpointIfAlreadyExists;
|
||||||
import org.jclouds.atmosonline.saas.options.ListOptions;
|
import org.jclouds.atmosonline.saas.options.ListOptions;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
|
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
|
||||||
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
@ -73,7 +71,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@Endpoint(AtmosStorage.class)
|
@Endpoint(AtmosStorage.class)
|
||||||
@RequestFilters(SignRequest.class)
|
@RequestFilters(SignRequest.class)
|
||||||
@SkipEncoding( { '/' })
|
@SkipEncoding( { '/' })
|
||||||
@ConsistencyModel(ConsistencyModels.EVENTUAL)
|
|
||||||
public interface AtmosStorageAsyncClient {
|
public interface AtmosStorageAsyncClient {
|
||||||
/**
|
/**
|
||||||
* Creates a default implementation of AtmosObject
|
* Creates a default implementation of AtmosObject
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.jclouds.atmosonline.saas.blobstore.functions.ObjectToBlobMetadata;
|
||||||
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
||||||
import org.jclouds.atmosonline.saas.options.ListOptions;
|
import org.jclouds.atmosonline.saas.options.ListOptions;
|
||||||
import org.jclouds.atmosonline.saas.util.AtmosStorageUtils;
|
import org.jclouds.atmosonline.saas.util.AtmosStorageUtils;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -70,14 +71,14 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AtmosAsyncBlobStore(BlobStoreUtils blobUtils,
|
AtmosAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
AtmosStorageAsyncClient async, AtmosStorageClient sync, ObjectToBlob object2Blob,
|
AtmosStorageAsyncClient async, AtmosStorageClient sync, ObjectToBlob object2Blob,
|
||||||
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
||||||
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
||||||
DirectoryEntryListToResourceMetadataList container2ResourceList,
|
DirectoryEntryListToResourceMetadataList container2ResourceList,
|
||||||
EncryptionService encryptionService, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
EncryptionService encryptionService, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
||||||
super(blobUtils, service);
|
super(context, blobUtils, service);
|
||||||
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
||||||
this.sync = checkNotNull(sync, "sync");
|
this.sync = checkNotNull(sync, "sync");
|
||||||
this.async = checkNotNull(async, "async");
|
this.async = checkNotNull(async, "async");
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.jclouds.atmosonline.saas.blobstore.functions.ObjectToBlob;
|
||||||
import org.jclouds.atmosonline.saas.blobstore.functions.ObjectToBlobMetadata;
|
import org.jclouds.atmosonline.saas.blobstore.functions.ObjectToBlobMetadata;
|
||||||
import org.jclouds.atmosonline.saas.options.ListOptions;
|
import org.jclouds.atmosonline.saas.options.ListOptions;
|
||||||
import org.jclouds.atmosonline.saas.util.AtmosStorageUtils;
|
import org.jclouds.atmosonline.saas.util.AtmosStorageUtils;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -57,12 +58,12 @@ public class AtmosBlobStore extends BaseBlobStore {
|
||||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AtmosBlobStore(BlobStoreUtils blobUtils, AtmosStorageClient sync, ObjectToBlob object2Blob,
|
AtmosBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, AtmosStorageClient sync,
|
||||||
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
||||||
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
||||||
DirectoryEntryListToResourceMetadataList container2ResourceList,
|
DirectoryEntryListToResourceMetadataList container2ResourceList,
|
||||||
EncryptionService encryptionService, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
EncryptionService encryptionService, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
||||||
super(blobUtils);
|
super(context, blobUtils);
|
||||||
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
||||||
this.sync = checkNotNull(sync, "sync");
|
this.sync = checkNotNull(sync, "sync");
|
||||||
this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions,
|
this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions,
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.blobstore.config;
|
package org.jclouds.atmosonline.saas.blobstore.config;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -27,17 +25,15 @@ 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.config.AtmosStorageContextModule;
|
import org.jclouds.atmosonline.saas.config.AtmosStorageContextModule;
|
||||||
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.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
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.rest.RestContext;
|
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link AtmosBlobStoreContext}; requires {@link AtmosAsyncBlobStore} bound.
|
* Configures the {@link AtmosBlobStoreContext}; requires {@link AtmosAsyncBlobStore} bound.
|
||||||
|
@ -50,19 +46,14 @@ public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).asEagerSingleton();
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
|
||||||
bind(BlobStore.class).to(AtmosBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
bind(BlobStore.class).to(AtmosBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
bind(BlobStoreContext.class)
|
||||||
|
.to(
|
||||||
|
new TypeLiteral<BlobStoreContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
|
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
|
|
||||||
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
|
||||||
AsyncBlobStore asynchBlobStore, BlobStore blobStore,
|
|
||||||
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> context) {
|
|
||||||
return new BlobStoreContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>(blobMapFactory,
|
|
||||||
inputStreamMapFactory, asynchBlobStore, blobStore, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
public class AtmosStorageContextModule extends AbstractModule {
|
public class AtmosStorageContextModule extends AbstractModule {
|
||||||
|
@ -42,7 +43,10 @@ public class AtmosStorageContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
// for converters to work.
|
// for converters to work.
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<AtmosStorageAsyncClient, AtmosStorageClient>(
|
||||||
|
new TypeLiteral<AtmosStorageAsyncClient>() {
|
||||||
|
}, new TypeLiteral<AtmosStorageClient>() {
|
||||||
|
}));
|
||||||
install(new AtmosObjectModule());
|
install(new AtmosObjectModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,7 +289,10 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
|
||||||
return new AbstractModule() {
|
return new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<AtmosStorageAsyncClient, AtmosStorageClient>(
|
||||||
|
new TypeLiteral<AtmosStorageAsyncClient>() {
|
||||||
|
}, new TypeLiteral<AtmosStorageClient>() {
|
||||||
|
}));
|
||||||
install(new AtmosObjectModule());
|
install(new AtmosObjectModule());
|
||||||
bind(URI.class).annotatedWith(AtmosStorage.class).toInstance(
|
bind(URI.class).annotatedWith(AtmosStorage.class).toInstance(
|
||||||
URI.create("http://accesspoint.emccis.com"));
|
URI.create("http://accesspoint.emccis.com"));
|
||||||
|
|
|
@ -1,112 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.atmosonline.saas;
|
|
||||||
|
|
||||||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
|
||||||
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorageContextBuilder;
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStorageClient;
|
|
||||||
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
|
|
||||||
import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore;
|
|
||||||
import org.jclouds.atmosonline.saas.blobstore.config.AtmosBlobStoreContextModule;
|
|
||||||
import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
|
|
||||||
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
|
|
||||||
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
|
||||||
import org.jclouds.atmosonline.saas.domain.internal.AtmosObjectImpl;
|
|
||||||
import org.jclouds.atmosonline.saas.internal.StubAtmosStorageAsyncClient;
|
|
||||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.domain.internal.BlobImpl;
|
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in AtmosStorageContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "emcsaas.AtmosStorageContextBuilderTest")
|
|
||||||
public class AtmosStorageContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
BlobStoreContextBuilder<AtmosStorageAsyncClient, AtmosStorageClient> builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_USER_METADATA_PREFIX), null);
|
|
||||||
assertEquals(builder.getProperties().getProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_UID),
|
|
||||||
"id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY),
|
|
||||||
"secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlobStoreContextBuilder<AtmosStorageAsyncClient, AtmosStorageClient> newBuilder() {
|
|
||||||
return new AtmosStorageContextBuilder(new AtmosStoragePropertiesBuilder("id", "secret")
|
|
||||||
.build()).withModules(new AtmosStorageStubClientModule(), new ExecutorServiceModule(
|
|
||||||
sameThreadExecutor(), sameThreadExecutor()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
BlobStoreContext context = newBuilder().buildBlobStoreContext();
|
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAsyncApi().getClass(),
|
|
||||||
StubAtmosStorageAsyncClient.class);
|
|
||||||
assertEquals(context.getAsyncBlobStore().getClass(), AtmosAsyncBlobStore.class);
|
|
||||||
assertEquals(((AtmosStorageAsyncClient) context.getProviderSpecificContext().getAsyncApi())
|
|
||||||
.newObject().getClass(), AtmosObjectImpl.class);
|
|
||||||
assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
|
|
||||||
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
|
|
||||||
.create("https://localhost/azurestub"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(BlobStoreContext.class) != null;
|
|
||||||
assert i.getInstance(AtmosObject.class) != null;
|
|
||||||
assert i.getInstance(Blob.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
AtmosStorageContextBuilder builder = (AtmosStorageContextBuilder) newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), AtmosBlobStoreContextModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
AtmosStorageContextBuilder builder = (AtmosStorageContextBuilder) newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), AtmosStorageRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -40,8 +40,6 @@ import org.jclouds.atmosonline.saas.domain.DirectoryEntry;
|
||||||
import org.jclouds.atmosonline.saas.domain.SystemMetadata;
|
import org.jclouds.atmosonline.saas.domain.SystemMetadata;
|
||||||
import org.jclouds.atmosonline.saas.domain.UserMetadata;
|
import org.jclouds.atmosonline.saas.domain.UserMetadata;
|
||||||
import org.jclouds.atmosonline.saas.options.ListOptions;
|
import org.jclouds.atmosonline.saas.options.ListOptions;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
||||||
|
@ -58,7 +56,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@ConsistencyModel(ConsistencyModels.STRICT)
|
|
||||||
public class StubAtmosStorageAsyncClient implements AtmosStorageAsyncClient {
|
public class StubAtmosStorageAsyncClient implements AtmosStorageAsyncClient {
|
||||||
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
||||||
private final StubAsyncBlobStore blobStore;
|
private final StubAsyncBlobStore blobStore;
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.aws.ec2.compute.domain.KeyPairCredentials;
|
||||||
import org.jclouds.aws.ec2.compute.domain.PortsRegionTag;
|
import org.jclouds.aws.ec2.compute.domain.PortsRegionTag;
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionTag;
|
import org.jclouds.aws.ec2.compute.domain.RegionTag;
|
||||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.NodeState;
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
@ -63,7 +64,8 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
protected final Predicate<RunningInstance> instanceStateTerminated;
|
protected final Predicate<RunningInstance> instanceStateTerminated;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected EC2ComputeService(Provider<Map<String, ? extends Image>> images,
|
protected EC2ComputeService(ComputeServiceContext context,
|
||||||
|
Provider<Map<String, ? extends Image>> images,
|
||||||
Provider<Map<String, ? extends Size>> sizes,
|
Provider<Map<String, ? extends Size>> sizes,
|
||||||
Provider<Map<String, ? extends Location>> locations,
|
Provider<Map<String, ? extends Location>> locations,
|
||||||
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
|
@ -75,7 +77,7 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
Map<RegionTag, KeyPairCredentials> credentialsMap,
|
Map<RegionTag, KeyPairCredentials> credentialsMap,
|
||||||
Map<PortsRegionTag, String> securityGroupMap,
|
Map<PortsRegionTag, String> securityGroupMap,
|
||||||
@Named("TERMINATED") Predicate<RunningInstance> instanceStateTerminated) {
|
@Named("TERMINATED") Predicate<RunningInstance> instanceStateTerminated) {
|
||||||
super(images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
super(context, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
||||||
templateBuilderProvider, utils, executor);
|
templateBuilderProvider, utils, executor);
|
||||||
this.ec2Client = ec2Client;
|
this.ec2Client = ec2Client;
|
||||||
|
|
|
@ -62,8 +62,6 @@ import org.jclouds.aws.s3.xml.ListBucketHandler;
|
||||||
import org.jclouds.aws.s3.xml.LocationConstraintHandler;
|
import org.jclouds.aws.s3.xml.LocationConstraintHandler;
|
||||||
import org.jclouds.aws.s3.xml.PayerHandler;
|
import org.jclouds.aws.s3.xml.PayerHandler;
|
||||||
import org.jclouds.blobstore.attr.BlobScope;
|
import org.jclouds.blobstore.attr.BlobScope;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
|
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
|
||||||
import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
|
import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
|
||||||
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
|
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
|
||||||
|
@ -104,7 +102,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@RequestFilters(RequestAuthorizeSignature.class)
|
@RequestFilters(RequestAuthorizeSignature.class)
|
||||||
@Endpoint(S3.class)
|
@Endpoint(S3.class)
|
||||||
@BlobScope(CONTAINER)
|
@BlobScope(CONTAINER)
|
||||||
@ConsistencyModel(ConsistencyModels.EVENTUAL)
|
|
||||||
public interface S3AsyncClient {
|
public interface S3AsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,6 +43,7 @@ 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.ListBucketOptions;
|
import org.jclouds.aws.s3.options.ListBucketOptions;
|
||||||
import org.jclouds.aws.s3.util.S3Utils;
|
import org.jclouds.aws.s3.util.S3Utils;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -76,14 +77,14 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
private final ObjectToBlobMetadata object2BlobMd;
|
private final ObjectToBlobMetadata object2BlobMd;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
S3AsyncBlobStore(BlobStoreUtils blobUtils,
|
S3AsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, S3AsyncClient async,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, S3AsyncClient async,
|
||||||
S3Client sync, BucketToResourceMetadata bucket2ResourceMd,
|
S3Client sync, BucketToResourceMetadata bucket2ResourceMd,
|
||||||
ContainerToBucketListOptions container2BucketListOptions,
|
ContainerToBucketListOptions container2BucketListOptions,
|
||||||
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
||||||
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
|
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
|
||||||
ObjectToBlobMetadata object2BlobMd) {
|
ObjectToBlobMetadata object2BlobMd) {
|
||||||
super(blobUtils, service);
|
super(context, blobUtils, service);
|
||||||
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
||||||
this.async = checkNotNull(async, "async");
|
this.async = checkNotNull(async, "async");
|
||||||
this.sync = checkNotNull(sync, "sync");
|
this.sync = checkNotNull(sync, "sync");
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.jclouds.aws.s3.blobstore.functions.ObjectToBlobMetadata;
|
||||||
import org.jclouds.aws.s3.domain.BucketMetadata;
|
import org.jclouds.aws.s3.domain.BucketMetadata;
|
||||||
import org.jclouds.aws.s3.options.ListBucketOptions;
|
import org.jclouds.aws.s3.options.ListBucketOptions;
|
||||||
import org.jclouds.aws.s3.util.S3Utils;
|
import org.jclouds.aws.s3.util.S3Utils;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -68,12 +69,13 @@ public class S3BlobStore extends BaseBlobStore {
|
||||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
S3BlobStore(BlobStoreUtils blobUtils, S3Client sync, BucketToResourceMetadata bucket2ResourceMd,
|
S3BlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, S3Client sync,
|
||||||
|
BucketToResourceMetadata bucket2ResourceMd,
|
||||||
ContainerToBucketListOptions container2BucketListOptions,
|
ContainerToBucketListOptions container2BucketListOptions,
|
||||||
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
||||||
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
|
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
|
||||||
ObjectToBlobMetadata object2BlobMd) {
|
ObjectToBlobMetadata object2BlobMd) {
|
||||||
super(blobUtils);
|
super(context, blobUtils);
|
||||||
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
||||||
this.sync = checkNotNull(sync, "sync");
|
this.sync = checkNotNull(sync, "sync");
|
||||||
this.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd");
|
this.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd");
|
||||||
|
|
|
@ -18,24 +18,20 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.blobstore.config;
|
package org.jclouds.aws.s3.blobstore.config;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
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.S3ContextModule;
|
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.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.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.lifecycle.Closer;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link S3BlobStoreContext}; requires {@link S3AsyncBlobStore} bound.
|
* Configures the {@link S3BlobStoreContext}; requires {@link S3AsyncBlobStore} bound.
|
||||||
|
@ -48,18 +44,11 @@ public class S3BlobStoreContextModule extends S3ContextModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).asEagerSingleton();
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
|
||||||
bind(BlobStore.class).to(S3BlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
bind(BlobStoreContext.class).to(
|
||||||
|
new TypeLiteral<BlobStoreContextImpl<S3AsyncClient, S3Client>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
|
|
||||||
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
|
||||||
S3AsyncBlobStore asynchBlobStore, S3BlobStore blobStore,
|
|
||||||
RestContext<S3AsyncClient, S3Client> context) {
|
|
||||||
return new BlobStoreContextImpl<S3AsyncClient, S3Client>(blobMapFactory,
|
|
||||||
inputStreamMapFactory, asynchBlobStore, blobStore, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link S3ContextModule}; requires {@link S3AsyncClient} bound.
|
* Configures the {@link S3ContextModule}; requires {@link S3AsyncClient} bound.
|
||||||
|
@ -45,7 +46,9 @@ public class S3ContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
// for converters
|
// for converters
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<S3AsyncClient, S3Client>(new TypeLiteral<S3AsyncClient>() {
|
||||||
|
}, new TypeLiteral<S3Client>() {
|
||||||
|
}));
|
||||||
install(new S3ObjectModule());
|
install(new S3ObjectModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.aws.ec2;
|
|
||||||
|
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID;
|
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.config.EC2RestClientModule;
|
|
||||||
import org.jclouds.aws.ec2.reference.EC2Constants;
|
|
||||||
import org.jclouds.aws.filters.FormSigner;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in EC2ContextBuilderT
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "ec2.EC2ContextBuilderTest")
|
|
||||||
public class EC2ContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
EC2ContextBuilder builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(EC2Constants.PROPERTY_EC2_ENDPOINT),
|
|
||||||
"https://ec2.us-east-1.amazonaws.com");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_ACCESSKEYID), "id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_SECRETACCESSKEY), "secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContext<EC2AsyncClient, EC2Client> context = newBuilder().buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAccount(), "id");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://ec2.us-east-1.amazonaws.com"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<RestContext<EC2AsyncClient, EC2Client>>() {
|
|
||||||
})) != null; // TODO: test all things taken from context
|
|
||||||
assert i.getInstance(FormSigner.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
EC2ContextBuilder builder = newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), EC2RestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private EC2ContextBuilder newBuilder() {
|
|
||||||
EC2ContextBuilder builder = new EC2ContextBuilder(new EC2PropertiesBuilder("id", "secret")
|
|
||||||
.build());
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
EC2ContextBuilder builder = newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), EC2RestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -24,12 +24,14 @@
|
||||||
|
|
||||||
package org.jclouds.aws.ec2.compute;
|
package org.jclouds.aws.ec2.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.lang.String.format;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import org.jclouds.aws.ec2.compute.domain.EC2Size;
|
import org.jclouds.aws.ec2.compute.domain.EC2Size;
|
||||||
import org.jclouds.compute.domain.*;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.domain.internal.ImageImpl;
|
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
@ -37,16 +39,16 @@ import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.net.URI;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import static java.lang.String.format;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests compute service specifically to EC2.
|
* Tests compute service specifically to EC2.
|
||||||
*
|
*
|
||||||
* These tests are designed to verify the local
|
* These tests are designed to verify the local functionality of jclouds, rather than the
|
||||||
* functionality of jclouds, rather than the interaction
|
* interaction with Amazon Web Services.
|
||||||
* with Amazon Web Services.
|
|
||||||
*
|
*
|
||||||
* @see EC2ComputeServiceLiveTest
|
* @see EC2ComputeServiceLiveTest
|
||||||
*
|
*
|
||||||
|
@ -55,85 +57,68 @@ import static java.lang.String.format;
|
||||||
public class EC2ComputeServiceTest {
|
public class EC2ComputeServiceTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that {@link TemplateBuilderImpl} would
|
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
|
||||||
* choose the correct size of the instance, based on
|
* on {@link org.jclouds.compute.domain.Size} from {@link EC2Size}.
|
||||||
* {@link org.jclouds.compute.domain.Size} from {@link EC2Size}.
|
|
||||||
*
|
*
|
||||||
* Expected size: m2.xlarge
|
* Expected size: m2.xlarge
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTemplateChoiceForInstanceBySizeId() throws Exception {
|
public void testTemplateChoiceForInstanceBySizeId() throws Exception {
|
||||||
Template template = newTemplateBuilder().
|
Template template = newTemplateBuilder().architecture(Architecture.X86_64)
|
||||||
architecture(Architecture.X86_64).sizeId("m2.xlarge").
|
.sizeId("m2.xlarge").locationId("us-east-1").build();
|
||||||
locationId("us-east-1").
|
|
||||||
build();
|
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
assert EC2Size.M2_XLARGE.equals(template.getSize()) :
|
assert EC2Size.M2_XLARGE.equals(template.getSize()) : format(
|
||||||
format("Incorrect image determined by the template. Expected: %s. Found: %s.",
|
"Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge",
|
||||||
"m2.xlarge", String.valueOf(template.getSize()));
|
String.valueOf(template.getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that {@link TemplateBuilderImpl} would
|
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
|
||||||
* choose the correct size of the instance, based on
|
* on physical attributes (# of cores, ram, etc).
|
||||||
* physical attributes (# of cores, ram, etc).
|
|
||||||
*
|
*
|
||||||
* Expected size: m2.xlarge
|
* Expected size: m2.xlarge
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTemplateChoiceForInstanceByAttributes() throws Exception {
|
public void testTemplateChoiceForInstanceByAttributes() throws Exception {
|
||||||
Template template = newTemplateBuilder().
|
Template template = newTemplateBuilder().architecture(Architecture.X86_64).minRam(17510)
|
||||||
architecture(Architecture.X86_64).
|
.minCores(6.5).smallest().locationId("us-east-1").build();
|
||||||
minRam(17510).minCores(6.5).smallest().
|
|
||||||
locationId("us-east-1").
|
|
||||||
build();
|
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
assert EC2Size.M2_XLARGE.equals(template.getSize()) :
|
assert EC2Size.M2_XLARGE.equals(template.getSize()) : format(
|
||||||
format("Incorrect image determined by the template. Expected: %s. Found: %s.",
|
"Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge",
|
||||||
"m2.xlarge", String.valueOf(template.getSize()));
|
String.valueOf(template.getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}.
|
* Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}.
|
||||||
*
|
*
|
||||||
* Verifies that {@link TemplateBuilderImpl} would
|
* Verifies that {@link TemplateBuilderImpl} would not choose the insufficient size of the
|
||||||
* not choose the insufficient size of the instance, based on
|
* instance, based on physical attributes (# of cores, ram, etc).
|
||||||
* physical attributes (# of cores, ram, etc).
|
|
||||||
*
|
*
|
||||||
* Expected size: anything but m2.xlarge
|
* Expected size: anything but m2.xlarge
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
|
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
|
||||||
Template template = newTemplateBuilder().
|
Template template = newTemplateBuilder().architecture(Architecture.X86_64).minRam(17510)
|
||||||
architecture(Architecture.X86_64).
|
.minCores(6.7).smallest().locationId("us-east-1").build();
|
||||||
minRam(17510).minCores(6.7).smallest().
|
|
||||||
locationId("us-east-1").
|
|
||||||
build();
|
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
assert ! EC2Size.M2_XLARGE.equals(template.getSize()) :
|
assert !EC2Size.M2_XLARGE.equals(template.getSize()) : format(
|
||||||
format("Incorrect image determined by the template. Expected: not %s. Found: %s.",
|
"Incorrect image determined by the template. Expected: not %s. Found: %s.",
|
||||||
"m2.xlarge", String.valueOf(template.getSize()));
|
"m2.xlarge", String.valueOf(template.getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private TemplateBuilder newTemplateBuilder() {
|
private TemplateBuilder newTemplateBuilder() {
|
||||||
Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null, true);
|
Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null, true);
|
||||||
Image image = new ImageImpl("ami-image", "image", "us-east-1", null,
|
Image image = new ImageImpl("ami-image", "image", "us-east-1", null, Maps
|
||||||
Maps.<String,String>newHashMap(), "description", "1.0",
|
.<String, String> newHashMap(), "description", "1.0", null, "ubuntu",
|
||||||
null, "ubuntu", Architecture.X86_64);
|
Architecture.X86_64);
|
||||||
|
|
||||||
return new TemplateBuilderImpl(ImmutableMap.of("us-east-1", location),
|
return new TemplateBuilderImpl(ImmutableMap.of("us-east-1", location), ImmutableMap.of(
|
||||||
ImmutableMap.of("ami-image", image),
|
"ami-image", image), Maps.uniqueIndex(ImmutableSet.of(EC2Size.C1_MEDIUM,
|
||||||
Maps.uniqueIndex(ImmutableSet.of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE,
|
EC2Size.C1_XLARGE, EC2Size.M1_LARGE, EC2Size.M1_SMALL, EC2Size.M1_XLARGE,
|
||||||
EC2Size.M1_LARGE, EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M2_XLARGE,
|
EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE), indexer()), location);
|
||||||
EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE), indexer()),
|
|
||||||
location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Function<ComputeMetadata, String> indexer() {
|
Function<ComputeMetadata, String> indexer() {
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.xml;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.Attachment;
|
import org.jclouds.aws.ec2.domain.Attachment;
|
||||||
|
@ -46,12 +45,10 @@ public class BlockDeviceMappingHandlerTest extends BaseHandlerTest {
|
||||||
|
|
||||||
DateService dateService = injector.getInstance(DateService.class);
|
DateService dateService = injector.getInstance(DateService.class);
|
||||||
Map<String, EbsBlockDevice> expected = ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1",
|
Map<String, EbsBlockDevice> expected = ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1",
|
||||||
new EbsBlockDevice("vol-d74b82be", Attachment.Status.ATTACHED,
|
new EbsBlockDevice("vol-d74b82be", Attachment.Status.ATTACHED, dateService
|
||||||
dateService.iso8601DateParse("2010-02-20T18:25:26.000Z"), true),
|
.iso8601DateParse("2010-02-20T18:25:26.000Z"), true), "/dev/sdf",
|
||||||
"/dev/sdf",
|
new EbsBlockDevice("vol-another", Attachment.Status.DETACHED, dateService
|
||||||
new EbsBlockDevice("vol-another", Attachment.Status.DETACHED,
|
.iso8601DateParse("2010-02-20T19:26:26.000Z"), false));
|
||||||
dateService.iso8601DateParse("2010-02-20T19:26:26.000Z"), false)
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, EbsBlockDevice> result = factory.create(
|
Map<String, EbsBlockDevice> result = factory.create(
|
||||||
injector.getInstance(BlockDeviceMappingHandler.class)).parse(is);
|
injector.getInstance(BlockDeviceMappingHandler.class)).parse(is);
|
||||||
|
|
|
@ -540,7 +540,10 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
return new AbstractModule() {
|
return new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<S3AsyncClient, S3Client>(
|
||||||
|
new TypeLiteral<S3AsyncClient>() {
|
||||||
|
}, new TypeLiteral<S3Client>() {
|
||||||
|
}));
|
||||||
install(new S3ObjectModule());
|
install(new S3ObjectModule());
|
||||||
bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("http://stub:8080"));
|
bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("http://stub:8080"));
|
||||||
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to(
|
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to(
|
||||||
|
|
|
@ -1,111 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.aws.s3;
|
|
||||||
|
|
||||||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID;
|
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY;
|
|
||||||
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.aws.s3.S3AsyncClient;
|
|
||||||
import org.jclouds.aws.s3.S3ContextBuilder;
|
|
||||||
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
|
||||||
import org.jclouds.aws.s3.blobstore.config.S3BlobStoreContextModule;
|
|
||||||
import org.jclouds.aws.s3.config.S3RestClientModule;
|
|
||||||
import org.jclouds.aws.s3.config.S3StubClientModule;
|
|
||||||
import org.jclouds.aws.s3.domain.S3Object;
|
|
||||||
import org.jclouds.aws.s3.domain.internal.S3ObjectImpl;
|
|
||||||
import org.jclouds.aws.s3.internal.StubS3AsyncClient;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.domain.internal.BlobImpl;
|
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in S3ContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "s3.S3ContextBuilderTest")
|
|
||||||
public class S3ContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
S3ContextBuilder builder = new S3ContextBuilder(new S3PropertiesBuilder(
|
|
||||||
"id", "secret").build());
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_USER_METADATA_PREFIX),
|
|
||||||
"x-amz-meta-");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_ACCESSKEYID), "id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_SECRETACCESSKEY), "secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
BlobStoreContext context = new S3ContextBuilder(new S3PropertiesBuilder("id",
|
|
||||||
"secret").build()).withModules(
|
|
||||||
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
|
|
||||||
new S3StubClientModule()).buildBlobStoreContext();
|
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAsyncApi().getClass(),
|
|
||||||
StubS3AsyncClient.class);
|
|
||||||
// assertEquals(context.getAsyncBlobStore().getClass(), S3AsyncBlobStore.class);
|
|
||||||
assertEquals(((S3AsyncClient) context.getProviderSpecificContext().getAsyncApi())
|
|
||||||
.newS3Object().getClass(), S3ObjectImpl.class);
|
|
||||||
assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
|
|
||||||
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
|
|
||||||
.create("https://localhost/s3stub"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = new S3ContextBuilder(new S3PropertiesBuilder("id", "secret").build())
|
|
||||||
.withModules(new S3StubClientModule()).buildInjector();
|
|
||||||
assert i.getInstance(BlobStoreContext.class) != null;
|
|
||||||
assert i.getInstance(S3Object.class) != null;
|
|
||||||
assert i.getInstance(Blob.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
S3ContextBuilder builder = (S3ContextBuilder) new S3ContextBuilder(
|
|
||||||
new S3PropertiesBuilder("id", "secret").build())
|
|
||||||
.withModules(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), S3BlobStoreContextModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
S3ContextBuilder builder = new S3ContextBuilder(new S3PropertiesBuilder(
|
|
||||||
"id", "secret").build());
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), S3RestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -64,9 +64,13 @@ public class S3BlobStoreModuleTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testContextImpl() {
|
void testContextImplAndSingleton() {
|
||||||
BlobStoreContext context = createInjector().getInstance(BlobStoreContext.class);
|
Injector i = createInjector();
|
||||||
|
BlobStoreContext context = i.getInstance(BlobStoreContext.class);
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
||||||
|
assertEquals(context, i.getInstance(BlobStoreContext.class));
|
||||||
|
assertEquals(context.getAsyncBlobStore().getContext().getAsyncBlobStore(), context.getAsyncBlobStore());
|
||||||
|
assertEquals(context.getBlobStore().getContext().getBlobStore(), context.getBlobStore());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -59,8 +59,6 @@ import org.jclouds.aws.s3.options.PutBucketOptions;
|
||||||
import org.jclouds.aws.s3.options.PutObjectOptions;
|
import org.jclouds.aws.s3.options.PutObjectOptions;
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
|
@ -82,7 +80,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @author James Murty
|
* @author James Murty
|
||||||
*/
|
*/
|
||||||
@ConsistencyModel(ConsistencyModels.STRICT)
|
|
||||||
public class StubS3AsyncClient implements S3AsyncClient {
|
public class StubS3AsyncClient implements S3AsyncClient {
|
||||||
private final DateService dateService;
|
private final DateService dateService;
|
||||||
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.aws.sqs;
|
|
||||||
|
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID;
|
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.aws.filters.FormSigner;
|
|
||||||
import org.jclouds.aws.sqs.config.SQSRestClientModule;
|
|
||||||
import org.jclouds.aws.sqs.reference.SQSConstants;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in SQSContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "sqs.SQSContextBuilderTest")
|
|
||||||
public class SQSContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
SQSContextBuilder builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties()
|
|
||||||
.getProperty(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1),
|
|
||||||
"https://queue.amazonaws.com");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_ACCESSKEYID), "id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_AWS_SECRETACCESSKEY), "secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContext<SQSAsyncClient, SQSClient> context = newBuilder().buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAccount(), "id");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://queue.amazonaws.com"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<RestContext<SQSAsyncClient, SQSClient>>() {
|
|
||||||
})) != null; // TODO: test all things taken from context
|
|
||||||
assert i.getInstance(FormSigner.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
SQSContextBuilder builder = newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), SQSRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SQSContextBuilder newBuilder() {
|
|
||||||
SQSContextBuilder builder = new SQSContextBuilder(new SQSPropertiesBuilder("id", "secret")
|
|
||||||
.build());
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
SQSContextBuilder builder = newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), SQSRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -40,15 +40,13 @@ import org.jclouds.azure.storage.blob.functions.ParseContainerPropertiesFromHead
|
||||||
import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists;
|
import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists;
|
||||||
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
||||||
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
||||||
|
import org.jclouds.azure.storage.blob.predicates.validators.ContainerNameValidator;
|
||||||
import org.jclouds.azure.storage.blob.xml.AccountNameEnumerationResultsHandler;
|
import org.jclouds.azure.storage.blob.xml.AccountNameEnumerationResultsHandler;
|
||||||
import org.jclouds.azure.storage.blob.xml.ContainerNameEnumerationResultsHandler;
|
import org.jclouds.azure.storage.blob.xml.ContainerNameEnumerationResultsHandler;
|
||||||
import org.jclouds.azure.storage.blob.predicates.validators.ContainerNameValidator;
|
|
||||||
import org.jclouds.azure.storage.domain.BoundedSet;
|
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||||
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
|
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix;
|
import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix;
|
||||||
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
|
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
|
||||||
import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
|
import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
|
||||||
|
@ -57,7 +55,17 @@ import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
|
||||||
import org.jclouds.http.functions.ParseETagHeader;
|
import org.jclouds.http.functions.ParseETagHeader;
|
||||||
import org.jclouds.http.functions.ReturnTrueOn404;
|
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.rest.annotations.*;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
|
import org.jclouds.rest.annotations.Endpoint;
|
||||||
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
|
import org.jclouds.rest.annotations.Headers;
|
||||||
|
import org.jclouds.rest.annotations.ParamParser;
|
||||||
|
import org.jclouds.rest.annotations.ParamValidators;
|
||||||
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
import org.jclouds.rest.annotations.SkipEncoding;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
@ -77,7 +85,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@RequestFilters(SharedKeyLiteAuthentication.class)
|
@RequestFilters(SharedKeyLiteAuthentication.class)
|
||||||
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-09-19")
|
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-09-19")
|
||||||
@Endpoint(AzureBlob.class)
|
@Endpoint(AzureBlob.class)
|
||||||
@ConsistencyModel(ConsistencyModels.STRICT)
|
|
||||||
public interface AzureBlobAsyncClient {
|
public interface AzureBlobAsyncClient {
|
||||||
|
|
||||||
public org.jclouds.azure.storage.blob.domain.AzureBlob newBlob();
|
public org.jclouds.azure.storage.blob.domain.AzureBlob newBlob();
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.jclouds.azure.storage.blob.domain.ContainerProperties;
|
||||||
import org.jclouds.azure.storage.blob.domain.ListBlobsResponse;
|
import org.jclouds.azure.storage.blob.domain.ListBlobsResponse;
|
||||||
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
||||||
import org.jclouds.azure.storage.domain.BoundedSet;
|
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -72,14 +73,14 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AzureAsyncBlobStore(BlobStoreUtils blobUtils,
|
AzureAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
AzureBlobAsyncClient async, ContainerToResourceMetadata container2ResourceMd,
|
AzureBlobAsyncClient async, ContainerToResourceMetadata container2ResourceMd,
|
||||||
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
||||||
ListBlobsResponseToResourceList azure2BlobStoreResourceList,
|
ListBlobsResponseToResourceList azure2BlobStoreResourceList,
|
||||||
AzureBlobToBlob azureBlob2Blob, BlobToAzureBlob blob2AzureBlob,
|
AzureBlobToBlob azureBlob2Blob, BlobToAzureBlob blob2AzureBlob,
|
||||||
BlobPropertiesToBlobMetadata blob2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
BlobPropertiesToBlobMetadata blob2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
||||||
super(blobUtils, service);
|
super(context, blobUtils, service);
|
||||||
this.async = checkNotNull(async, "async");
|
this.async = checkNotNull(async, "async");
|
||||||
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
|
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
|
||||||
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,
|
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,
|
||||||
|
@ -224,7 +225,8 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
|
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
|
||||||
return compose(async.getBlobProperties(container, key), new Function<BlobProperties, BlobMetadata>() {
|
return compose(async.getBlobProperties(container, key),
|
||||||
|
new Function<BlobProperties, BlobMetadata>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlobMetadata apply(BlobProperties from) {
|
public BlobMetadata apply(BlobProperties from) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.azure.storage.blob.blobstore.functions.ListOptionsToListBlobs
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerProperties;
|
import org.jclouds.azure.storage.blob.domain.ContainerProperties;
|
||||||
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
||||||
import org.jclouds.azure.storage.domain.BoundedSet;
|
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -63,13 +64,13 @@ public class AzureBlobStore extends BaseBlobStore {
|
||||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AzureBlobStore(BlobStoreUtils blobUtils, AzureBlobClient sync,
|
AzureBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, AzureBlobClient sync,
|
||||||
ContainerToResourceMetadata container2ResourceMd,
|
ContainerToResourceMetadata container2ResourceMd,
|
||||||
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
||||||
ListBlobsResponseToResourceList azure2BlobStoreResourceList,
|
ListBlobsResponseToResourceList azure2BlobStoreResourceList,
|
||||||
AzureBlobToBlob azureBlob2Blob, BlobToAzureBlob blob2AzureBlob,
|
AzureBlobToBlob azureBlob2Blob, BlobToAzureBlob blob2AzureBlob,
|
||||||
BlobPropertiesToBlobMetadata blob2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
BlobPropertiesToBlobMetadata blob2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions) {
|
||||||
super(blobUtils);
|
super(context, blobUtils);
|
||||||
this.sync = checkNotNull(sync, "sync");
|
this.sync = checkNotNull(sync, "sync");
|
||||||
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
|
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
|
||||||
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,
|
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.blobstore.config;
|
package org.jclouds.azure.storage.blob.blobstore.config;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -27,17 +25,15 @@ 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.AzureBlobContextModule;
|
import org.jclouds.azure.storage.blob.config.AzureBlobContextModule;
|
||||||
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.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
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.rest.RestContext;
|
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link AzureBlobStoreContext}; requires {@link AzureAsyncBlobStore} bound.
|
* Configures the {@link AzureBlobStoreContext}; requires {@link AzureAsyncBlobStore} bound.
|
||||||
|
@ -50,19 +46,13 @@ public class AzureBlobStoreContextModule extends AzureBlobContextModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).asEagerSingleton();
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
bind(BlobStore.class).to(AzureBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
bind(BlobStore.class).to(AzureBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
bind(BlobStoreContext.class).to(
|
||||||
|
new TypeLiteral<BlobStoreContextImpl<AzureBlobAsyncClient, AzureBlobClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
|
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
|
|
||||||
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
|
||||||
AzureAsyncBlobStore asynchBlobStore, AzureBlobStore blobStore,
|
|
||||||
RestContext<AzureBlobAsyncClient, AzureBlobClient> context) {
|
|
||||||
return new BlobStoreContextImpl<AzureBlobAsyncClient, AzureBlobClient>(blobMapFactory,
|
|
||||||
inputStreamMapFactory, asynchBlobStore, blobStore, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
public class AzureBlobContextModule extends AbstractModule {
|
public class AzureBlobContextModule extends AbstractModule {
|
||||||
|
@ -42,8 +43,10 @@ public class AzureBlobContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
// for converters
|
// for converters
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<AzureBlobAsyncClient, AzureBlobClient>(
|
||||||
install(new AzureBlobModule());
|
new TypeLiteral<AzureBlobAsyncClient>() {
|
||||||
|
}, new TypeLiteral<AzureBlobClient>() {
|
||||||
|
})); install(new AzureBlobModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.azure.storage.blob;
|
|
||||||
|
|
||||||
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobClient;
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobContextBuilder;
|
|
||||||
import org.jclouds.azure.storage.blob.blobstore.AzureAsyncBlobStore;
|
|
||||||
import org.jclouds.azure.storage.blob.blobstore.config.AzureBlobStoreContextModule;
|
|
||||||
import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
|
|
||||||
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
|
|
||||||
import org.jclouds.azure.storage.blob.domain.AzureBlob;
|
|
||||||
import org.jclouds.azure.storage.blob.domain.internal.AzureBlobImpl;
|
|
||||||
import org.jclouds.azure.storage.blob.internal.StubAzureBlobAsyncClient;
|
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.domain.internal.BlobImpl;
|
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in AzureBlobContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "azureblob.AzureBlobContextBuilderTest")
|
|
||||||
public class AzureBlobContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
BlobStoreContextBuilder<AzureBlobAsyncClient, AzureBlobClient> builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_USER_METADATA_PREFIX), "x-ms-meta-");
|
|
||||||
assertEquals(builder.getProperties().getProperty(
|
|
||||||
AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT), "id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(
|
|
||||||
AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY), "secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlobStoreContextBuilder<AzureBlobAsyncClient, AzureBlobClient> newBuilder() {
|
|
||||||
return new AzureBlobContextBuilder(new AzureBlobPropertiesBuilder("id", "secret")
|
|
||||||
.build()).withModules(new AzureBlobStubClientModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
BlobStoreContext context = newBuilder().buildBlobStoreContext();
|
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAsyncApi().getClass(),
|
|
||||||
StubAzureBlobAsyncClient.class);
|
|
||||||
assertEquals(context.getAsyncBlobStore().getClass(), AzureAsyncBlobStore.class);
|
|
||||||
assertEquals(((AzureBlobAsyncClient) context.getProviderSpecificContext().getAsyncApi())
|
|
||||||
.newBlob().getClass(), AzureBlobImpl.class);
|
|
||||||
assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
|
|
||||||
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
|
|
||||||
.create("https://localhost/azurestub"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(BlobStoreContext.class) != null;
|
|
||||||
assert i.getInstance(AzureBlob.class) != null;
|
|
||||||
assert i.getInstance(Blob.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
AzureBlobContextBuilder builder = (AzureBlobContextBuilder) newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), AzureBlobStoreContextModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
AzureBlobContextBuilder builder = (AzureBlobContextBuilder) newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), AzureBlobRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -45,8 +45,6 @@ import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
||||||
import org.jclouds.azure.storage.domain.BoundedSet;
|
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||||
import org.jclouds.azure.storage.domain.internal.BoundedHashSet;
|
import org.jclouds.azure.storage.domain.internal.BoundedHashSet;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
||||||
|
@ -63,7 +61,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@ConsistencyModel(ConsistencyModels.STRICT)
|
|
||||||
public class StubAzureBlobAsyncClient implements AzureBlobAsyncClient {
|
public class StubAzureBlobAsyncClient implements AzureBlobAsyncClient {
|
||||||
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
||||||
private final StubAsyncBlobStore blobStore;
|
private final StubAsyncBlobStore blobStore;
|
||||||
|
|
|
@ -33,6 +33,10 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
* @see AsyncBlobStore
|
* @see AsyncBlobStore
|
||||||
*/
|
*/
|
||||||
public interface AsyncBlobStore {
|
public interface AsyncBlobStore {
|
||||||
|
/**
|
||||||
|
* @see BlobStore#getContext
|
||||||
|
*/
|
||||||
|
BlobStoreContext getContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BlobStore#newBlob
|
* @see BlobStore#newBlob
|
||||||
|
|
|
@ -34,6 +34,10 @@ import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
* @see BlobStoreContextFactory
|
* @see BlobStoreContextFactory
|
||||||
*/
|
*/
|
||||||
public interface BlobStore {
|
public interface BlobStore {
|
||||||
|
/**
|
||||||
|
* @return a reference to the context that created this BlobStore.
|
||||||
|
*/
|
||||||
|
BlobStoreContext getContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new blob with the specified name.
|
* creates a new blob with the specified name.
|
||||||
|
|
|
@ -18,13 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a cloud that has key-value storage functionality. This object is scoped to a service
|
* Represents a cloud that has key-value storage functionality. This object is scoped to a service
|
||||||
* and an account.
|
* and an account.
|
||||||
|
@ -32,7 +29,6 @@ import com.google.inject.ImplementedBy;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ImplementedBy(BlobStoreContextImpl.class)
|
|
||||||
public interface BlobStoreContext {
|
public interface BlobStoreContext {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,7 +92,7 @@ public interface BlobStoreContext {
|
||||||
*
|
*
|
||||||
* @return best guess at the consistency model used in this BlobStore.
|
* @return best guess at the consistency model used in this BlobStore.
|
||||||
*/
|
*/
|
||||||
ConsistencyModels getConsistencyModel();
|
ConsistencyModel getConsistencyModel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,13 +20,10 @@ package org.jclouds.blobstore;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
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.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.util.Types;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -49,9 +46,6 @@ public abstract class BlobStoreContextBuilder<A, S> extends RestContextBuilder<A
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlobStoreContext buildBlobStoreContext() {
|
public BlobStoreContext buildBlobStoreContext() {
|
||||||
// need the generic type information
|
return buildInjector().getInstance(BlobStoreContext.class);
|
||||||
return (BlobStoreContext) buildInjector().getInstance(
|
|
||||||
Key.get(Types.newParameterizedType(BlobStoreContextImpl.class, asyncClientType
|
|
||||||
.getType(), syncClientType.getType())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,18 +18,21 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.attr;
|
package org.jclouds.blobstore.attr;
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.METHOD;
|
/**
|
||||||
import static java.lang.annotation.ElementType.TYPE;
|
* Represents the ways data can become consistent in distributed systems.
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
import java.lang.annotation.Retention;
|
*
|
||||||
import java.lang.annotation.Target;
|
*/
|
||||||
|
public enum ConsistencyModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* Eventually, all updates will propagate through the system. However, reads do not always return
|
||||||
|
* the latest write.
|
||||||
*/
|
*/
|
||||||
@Target( { TYPE, METHOD })
|
EVENTUAL,
|
||||||
@Retention(RUNTIME)
|
/**
|
||||||
public @interface ConsistencyModel {
|
* Reads return the latest write.
|
||||||
ConsistencyModels value();
|
*/
|
||||||
|
STRICT
|
||||||
}
|
}
|
|
@ -1,38 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.blobstore.attr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the ways data can become consistent in distributed systems.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum ConsistencyModels {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Eventually, all updates will propagate through the system. However, reads do not always return
|
|
||||||
* the latest write.
|
|
||||||
*/
|
|
||||||
EVENTUAL,
|
|
||||||
/**
|
|
||||||
* Reads return the latest write.
|
|
||||||
*/
|
|
||||||
STRICT
|
|
||||||
}
|
|
|
@ -29,13 +29,23 @@ import org.jclouds.encryption.EncryptionService;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the domain object mappings needed for all Blob implementations
|
* Configures the domain object mappings needed for all Blob implementations
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BlobStoreObjectModule extends AbstractModule {
|
public class BlobStoreObjectModule<A, S> extends AbstractModule {
|
||||||
|
protected final TypeLiteral<A> asyncClientType;
|
||||||
|
protected final TypeLiteral<S> syncClientType;
|
||||||
|
|
||||||
|
public BlobStoreObjectModule(TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType) {
|
||||||
|
// type erasure makes looking up a concrete impl that has externally defined type variables a
|
||||||
|
// pain
|
||||||
|
this.asyncClientType = asyncClientType;
|
||||||
|
this.syncClientType = syncClientType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* explicit factories are created here as it has been shown that Assisted Inject is extremely
|
* explicit factories are created here as it has been shown that Assisted Inject is extremely
|
||||||
|
|
|
@ -32,6 +32,7 @@ import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -51,16 +52,23 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*/
|
*/
|
||||||
public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
|
public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
|
||||||
|
|
||||||
|
protected final BlobStoreContext context;
|
||||||
protected final BlobStoreUtils blobUtils;
|
protected final BlobStoreUtils blobUtils;
|
||||||
protected final ExecutorService service;
|
protected final ExecutorService service;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected BaseAsyncBlobStore(BlobStoreUtils blobUtils,
|
protected BaseAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
|
||||||
|
this.context = checkNotNull(context, "context");
|
||||||
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
||||||
this.service = checkNotNull(service, "service");
|
this.service = checkNotNull(service, "service");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobStoreContext getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invokes {@link BlobStoreUtilsImpl#newBlob }
|
* invokes {@link BlobStoreUtilsImpl#newBlob }
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
|
import org.jclouds.blobstore.ListableMap;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
|
@ -47,7 +48,7 @@ import com.google.inject.Inject;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public abstract class BaseBlobMap<V> implements Map<String, V> {
|
public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
protected final BlobStore blobstore;
|
protected final BlobStore blobstore;
|
||||||
protected final String containerName;
|
protected final String containerName;
|
||||||
protected final Function<String, String> prefixer;
|
protected final Function<String, String> prefixer;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursi
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -41,13 +42,20 @@ import com.google.common.base.Supplier;
|
||||||
*/
|
*/
|
||||||
public abstract class BaseBlobStore implements BlobStore {
|
public abstract class BaseBlobStore implements BlobStore {
|
||||||
|
|
||||||
|
protected final BlobStoreContext context;
|
||||||
protected final BlobStoreUtils blobUtils;
|
protected final BlobStoreUtils blobUtils;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected BaseBlobStore(BlobStoreUtils blobUtils) {
|
protected BaseBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils) {
|
||||||
|
this.context = checkNotNull(context, "context");
|
||||||
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobStoreContext getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invokes {@link BlobStoreUtilsImpl#newBlob }
|
* invokes {@link BlobStoreUtilsImpl#newBlob }
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.blobstore.internal;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
|
@ -28,74 +29,68 @@ 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.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class BlobStoreContextImpl<X, Y> implements BlobStoreContext {
|
public class BlobStoreContextImpl<X, Y> implements BlobStoreContext {
|
||||||
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 RestContext<X, Y> providerSpecificContext;
|
private final RestContext<X, Y> providerSpecificContext;
|
||||||
|
private final ConsistencyModel consistencyModel;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BlobStoreContextImpl(BlobMap.Factory blobMapFactory,
|
public BlobStoreContextImpl(BlobMap.Factory blobMapFactory, ConsistencyModel consistencyModel,
|
||||||
InputStreamMap.Factory inputStreamMapFactory, AsyncBlobStore ablobStore,
|
InputStreamMap.Factory inputStreamMapFactory, AsyncBlobStore ablobStore,
|
||||||
BlobStore blobStore, RestContext<X, Y> providerSpecificContext) {
|
BlobStore blobStore, RestContext<X, Y> providerSpecificContext) {
|
||||||
this.providerSpecificContext = providerSpecificContext;
|
this.providerSpecificContext = providerSpecificContext;
|
||||||
Class<?> type;
|
this.consistencyModel = checkNotNull(consistencyModel, "consistencyModel");
|
||||||
if (providerSpecificContext.getAsyncApi().getClass().isAnnotationPresent(
|
|
||||||
ConsistencyModel.class)) {
|
|
||||||
type = providerSpecificContext.getAsyncApi().getClass();
|
|
||||||
} else if (providerSpecificContext.getAsyncApi().getClass().getInterfaces().length > 0
|
|
||||||
&& providerSpecificContext.getAsyncApi().getClass().getInterfaces()[0]
|
|
||||||
.isAnnotationPresent(ConsistencyModel.class)) {
|
|
||||||
type = providerSpecificContext.getAsyncApi().getClass().getInterfaces()[0];
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("@ConsistencyModel needed on "
|
|
||||||
+ providerSpecificContext.getAsyncApi().getClass());
|
|
||||||
}
|
|
||||||
this.consistencyModel = type.getAnnotation(ConsistencyModel.class).value();
|
|
||||||
this.blobMapFactory = checkNotNull(blobMapFactory, "blobMapFactory");
|
this.blobMapFactory = checkNotNull(blobMapFactory, "blobMapFactory");
|
||||||
this.inputStreamMapFactory = checkNotNull(inputStreamMapFactory, "inputStreamMapFactory");
|
this.inputStreamMapFactory = checkNotNull(inputStreamMapFactory, "inputStreamMapFactory");
|
||||||
this.ablobStore = checkNotNull(ablobStore, "ablobStore");
|
this.ablobStore = checkNotNull(ablobStore, "ablobStore");
|
||||||
this.blobStore = checkNotNull(blobStore, "blobStore");
|
this.blobStore = checkNotNull(blobStore, "blobStore");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsistencyModel getConsistencyModel() {
|
||||||
|
return consistencyModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlobMap createBlobMap(String container, ListContainerOptions options) {
|
public BlobMap createBlobMap(String container, ListContainerOptions options) {
|
||||||
return blobMapFactory.create(container, options);
|
return blobMapFactory.create(container, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlobMap createBlobMap(String container) {
|
public BlobMap createBlobMap(String container) {
|
||||||
return blobMapFactory.create(container, ListContainerOptions.NONE);
|
return blobMapFactory.create(container, ListContainerOptions.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public InputStreamMap createInputStreamMap(String container, ListContainerOptions options) {
|
public InputStreamMap createInputStreamMap(String container, ListContainerOptions options) {
|
||||||
return inputStreamMapFactory.create(container, options);
|
return inputStreamMapFactory.create(container, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public InputStreamMap createInputStreamMap(String container) {
|
public InputStreamMap createInputStreamMap(String container) {
|
||||||
return inputStreamMapFactory.create(container, ListContainerOptions.NONE);
|
return inputStreamMapFactory.create(container, ListContainerOptions.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlobStore getBlobStore() {
|
public BlobStore getBlobStore() {
|
||||||
return blobStore;
|
return blobStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public AsyncBlobStore getAsyncBlobStore() {
|
public AsyncBlobStore getAsyncBlobStore() {
|
||||||
return ablobStore;
|
return ablobStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConsistencyModels getConsistencyModel() {
|
|
||||||
return consistencyModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <A, S> RestContext<A, S> getProviderSpecificContext() {
|
public <A, S> RestContext<A, S> getProviderSpecificContext() {
|
||||||
|
|
|
@ -27,15 +27,13 @@ import java.net.URI;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.Blob.Factory;
|
||||||
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests parsing of a request
|
* Tests parsing of a request
|
||||||
*
|
*
|
||||||
|
@ -50,7 +48,7 @@ public class BindBlobToMultipartFormTest {
|
||||||
public static final Blob TEST_BLOB;
|
public static final Blob TEST_BLOB;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
blobProvider = Guice.createInjector(new BlobStoreObjectModule()).getInstance(
|
blobProvider = new StubBlobStoreContextBuilder().buildInjector().getInstance(
|
||||||
Blob.Factory.class);
|
Blob.Factory.class);
|
||||||
StringBuilder builder = new StringBuilder("--");
|
StringBuilder builder = new StringBuilder("--");
|
||||||
addData(BOUNDRY, "hello", builder);
|
addData(BOUNDRY, "hello", builder);
|
||||||
|
@ -71,7 +69,8 @@ public class BindBlobToMultipartFormTest {
|
||||||
HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001"));
|
HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001"));
|
||||||
binder.bindToRequest(request, TEST_BLOB);
|
binder.bindToRequest(request, TEST_BLOB);
|
||||||
|
|
||||||
assertEquals(Utils.toStringAndClose((InputStream) request.getPayload().getRawContent()), EXPECTS);
|
assertEquals(Utils.toStringAndClose((InputStream) request.getPayload().getRawContent()),
|
||||||
|
EXPECTS);
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 131 + "");
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 131 + "");
|
||||||
|
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE),
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE),
|
||||||
|
|
|
@ -28,6 +28,8 @@ import java.util.Collections;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
|
@ -40,6 +42,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -49,8 +52,11 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
blobProvider = Guice.createInjector(new BlobStoreObjectModule()).getInstance(
|
blobProvider = Guice.createInjector(
|
||||||
Blob.Factory.class);
|
new BlobStoreObjectModule<AsyncBlobStore, BlobStore>(
|
||||||
|
new TypeLiteral<AsyncBlobStore>() {
|
||||||
|
}, new TypeLiteral<BlobStore>() {
|
||||||
|
})).getInstance(Blob.Factory.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
|
|
@ -27,11 +27,14 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
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.attr.ConsistencyModel;
|
||||||
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;
|
||||||
|
@ -41,6 +44,7 @@ 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;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,13 +73,18 @@ public class StubBlobStoreContextBuilder extends BlobStoreContextBuilder<AsyncBl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addContextModule(List<Module> modules) {
|
public void addContextModule(List<Module> modules) {
|
||||||
modules.add(new BlobStoreObjectModule());
|
modules.add(new BlobStoreObjectModule<AsyncBlobStore, BlobStore>(
|
||||||
|
new TypeLiteral<AsyncBlobStore>() {
|
||||||
|
}, new TypeLiteral<BlobStore>() {
|
||||||
|
}));
|
||||||
modules.add(new BlobStoreMapModule());
|
modules.add(new BlobStoreMapModule());
|
||||||
modules.add(new AbstractModule() {
|
modules.add(new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(AsyncBlobStore.class).to(StubAsyncBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(StubAsyncBlobStore.class).asEagerSingleton();
|
||||||
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
|
bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<AsyncBlobStore, BlobStore>>(){}).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
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;
|
||||||
|
@ -205,7 +205,7 @@ public class BaseBlobStoreIntegrationTest {
|
||||||
*/
|
*/
|
||||||
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() == ConsistencyModel.STRICT) {
|
||||||
assertion.run();
|
assertion.run();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,7 +232,7 @@ public class BaseBlobStoreIntegrationTest {
|
||||||
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() == ConsistencyModel.EVENTUAL)
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
context.getBlobStore().clearContainer(containerName);
|
context.getBlobStore().clearContainer(containerName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,9 @@ import javax.inject.Named;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
|
@ -96,7 +95,6 @@ import com.google.inject.internal.Nullable;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @author James Murty
|
* @author James Murty
|
||||||
*/
|
*/
|
||||||
@ConsistencyModel(ConsistencyModels.STRICT)
|
|
||||||
public class StubAsyncBlobStore extends BaseAsyncBlobStore {
|
public class StubAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
|
|
||||||
protected final DateService dateService;
|
protected final DateService dateService;
|
||||||
|
@ -107,13 +105,14 @@ public class StubAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
protected final Factory blobFactory;
|
protected final Factory blobFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected StubAsyncBlobStore(DateService dateService, EncryptionService encryptionService,
|
protected StubAsyncBlobStore(BlobStoreContext context, DateService dateService,
|
||||||
|
EncryptionService encryptionService,
|
||||||
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
|
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory,
|
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory,
|
||||||
BlobStoreUtils blobUtils,
|
BlobStoreUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
|
||||||
super(blobUtils, service);
|
super(context, blobUtils, service);
|
||||||
this.blobFactory = blobFactory;
|
this.blobFactory = blobFactory;
|
||||||
this.dateService = dateService;
|
this.dateService = dateService;
|
||||||
this.encryptionService = encryptionService;
|
this.encryptionService = encryptionService;
|
||||||
|
|
|
@ -39,6 +39,12 @@ import com.google.inject.ImplementedBy;
|
||||||
*/
|
*/
|
||||||
@ImplementedBy(BaseComputeService.class)
|
@ImplementedBy(BaseComputeService.class)
|
||||||
public interface ComputeService {
|
public interface ComputeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a reference to the context that created this ComputeService.
|
||||||
|
*/
|
||||||
|
ComputeServiceContext getContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a new template builder for this service
|
* Makes a new template builder for this service
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -42,6 +42,7 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.compute.ComputeService;
|
import org.jclouds.compute.ComputeService;
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
import org.jclouds.compute.domain.ComputeType;
|
import org.jclouds.compute.domain.ComputeType;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -78,6 +79,8 @@ public class BaseComputeService implements ComputeService {
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
protected final ComputeServiceContext context;
|
||||||
protected final Provider<Map<String, ? extends Image>> images;
|
protected final Provider<Map<String, ? extends Image>> images;
|
||||||
protected final Provider<Map<String, ? extends Size>> sizes;
|
protected final Provider<Map<String, ? extends Size>> sizes;
|
||||||
protected final Provider<Map<String, ? extends Location>> locations;
|
protected final Provider<Map<String, ? extends Location>> locations;
|
||||||
|
@ -119,7 +122,8 @@ public class BaseComputeService implements ComputeService {
|
||||||
};
|
};
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected BaseComputeService(Provider<Map<String, ? extends Image>> images,
|
protected BaseComputeService(ComputeServiceContext context,
|
||||||
|
Provider<Map<String, ? extends Image>> images,
|
||||||
Provider<Map<String, ? extends Size>> sizes,
|
Provider<Map<String, ? extends Size>> sizes,
|
||||||
Provider<Map<String, ? extends Location>> locations,
|
Provider<Map<String, ? extends Location>> locations,
|
||||||
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
|
@ -127,17 +131,26 @@ public class BaseComputeService implements ComputeService {
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, ComputeUtils utils,
|
Provider<TemplateBuilder> templateBuilderProvider, ComputeUtils utils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||||
this.images = images;
|
this.context = checkNotNull(context, "context");
|
||||||
this.sizes = sizes;
|
this.images = checkNotNull(images, "images");
|
||||||
this.locations = locations;
|
this.sizes = checkNotNull(sizes, "sizes");
|
||||||
this.listNodesStrategy = listNodesStrategy;
|
this.locations = checkNotNull(locations, "locations");
|
||||||
this.getNodeMetadataStrategy = getNodeMetadataStrategy;
|
this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy");
|
||||||
this.runNodesAndAddToSetStrategy = runNodesAndAddToSetStrategy;
|
this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy,
|
||||||
this.rebootNodeStrategy = rebootNodeStrategy;
|
"getNodeMetadataStrategy");
|
||||||
this.destroyNodeStrategy = destroyNodeStrategy;
|
this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy,
|
||||||
this.templateBuilderProvider = templateBuilderProvider;
|
"runNodesAndAddToSetStrategy");
|
||||||
this.utils = utils;
|
this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy");
|
||||||
this.executor = executor;
|
this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy");
|
||||||
|
this.templateBuilderProvider = checkNotNull(templateBuilderProvider,
|
||||||
|
"templateBuilderProvider");
|
||||||
|
this.utils = checkNotNull(utils, "utils");
|
||||||
|
this.executor = checkNotNull(executor, "executor");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ComputeServiceContext getContext() {
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,7 +10,6 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import com.google.common.primitives.Doubles;
|
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -30,7 +29,7 @@ import com.google.common.collect.ComparisonChain;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Doubles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -88,6 +88,11 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
protected Template template;
|
protected Template template;
|
||||||
protected Map<String, String> keyPair;
|
protected Map<String, String> keyPair;
|
||||||
|
|
||||||
|
@Test(groups = { "live" })
|
||||||
|
void canGetContext() {
|
||||||
|
assertEquals(context.getComputeService().getContext(), context);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,
|
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,
|
||||||
IOException {
|
IOException {
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.gogrid;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
|
||||||
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
|
||||||
import org.jclouds.gogrid.services.GridServerAsyncClient;
|
|
||||||
import org.jclouds.gogrid.services.GridServerClient;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.gogrid.config.GoGridRestClientModule;
|
|
||||||
import org.jclouds.gogrid.reference.GoGridConstants;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in GoGridContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "gogrid.GoGridContextBuilderTest")
|
|
||||||
public class GoGridContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
GoGridContextBuilder builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_ENDPOINT),
|
|
||||||
"https://api.gogrid.com/api");
|
|
||||||
assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_USER),
|
|
||||||
"user");
|
|
||||||
assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_PASSWORD),
|
|
||||||
"password");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContext<GoGridAsyncClient, GoGridClient> context = newBuilder().buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAccount(), "user");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://api.gogrid.com/api"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<RestContext<GoGridAsyncClient, GoGridClient>>() {
|
|
||||||
})) != null;
|
|
||||||
assert i.getInstance(SharedKeyLiteAuthentication.class) != null;
|
|
||||||
assert i.getInstance(ParseServerListFromJsonResponse.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
GoGridContextBuilder builder = newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GoGridContextBuilder newBuilder() {
|
|
||||||
GoGridContextBuilder builder = new GoGridContextBuilder(new GoGridPropertiesBuilder(
|
|
||||||
"user", "password").build());
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
GoGridContextBuilder builder = newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the PCS connection, including logging and http transport.
|
* Configures the PCS connection, including logging and http transport.
|
||||||
|
@ -43,7 +44,10 @@ import com.google.inject.Provides;
|
||||||
public class PCSContextModule extends AbstractModule {
|
public class PCSContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<PCSAsyncClient, PCSClient>(
|
||||||
|
new TypeLiteral<PCSAsyncClient>() {
|
||||||
|
}, new TypeLiteral<PCSClient>() {
|
||||||
|
}));
|
||||||
install(new PCSObjectModule());
|
install(new PCSObjectModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,8 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
|
||||||
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
|
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||||
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
assertEquals(processor
|
||||||
|
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||||
ReturnVoidOnNotFoundOr404.class);
|
ReturnVoidOnNotFoundOr404.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +136,9 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
|
||||||
ContainerHandler.class);
|
ContainerHandler.class);
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||||
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class);
|
assertEquals(processor
|
||||||
|
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||||
|
MapHttp4xxCodesToExceptions.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFileInfo() throws SecurityException, NoSuchMethodException {
|
public void testGetFileInfo() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -150,7 +153,8 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
|
||||||
FileHandler.class);
|
FileHandler.class);
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||||
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
assertEquals(processor
|
||||||
|
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||||
ReturnNullOnKeyNotFound.class);
|
ReturnNullOnKeyNotFound.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +224,8 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
|
||||||
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
|
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||||
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
assertEquals(processor
|
||||||
|
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||||
ReturnVoidOnNotFoundOr404.class);
|
ReturnVoidOnNotFoundOr404.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +243,9 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
||||||
.singletonList("application/unknown"));
|
.singletonList("application/unknown"));
|
||||||
assertEquals("bar", httpMethod.getPayload().getRawContent());
|
assertEquals("bar", httpMethod.getPayload().getRawContent());
|
||||||
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class);
|
assertEquals(processor
|
||||||
|
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||||
|
MapHttp4xxCodesToExceptions.class);
|
||||||
assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
|
||||||
CloseContentAndReturn.class);
|
CloseContentAndReturn.class);
|
||||||
}
|
}
|
||||||
|
@ -253,7 +260,9 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
|
||||||
assertEquals(httpMethod.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1");
|
assertEquals(httpMethod.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1");
|
||||||
|
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class);
|
assertEquals(processor
|
||||||
|
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||||
|
MapHttp4xxCodesToExceptions.class);
|
||||||
assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
|
||||||
AddMetadataItemIntoMap.class);
|
AddMetadataItemIntoMap.class);
|
||||||
}
|
}
|
||||||
|
@ -285,7 +294,10 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new PCSObjectModule());
|
install(new PCSObjectModule());
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<PCSAsyncClient, PCSClient>(
|
||||||
|
new TypeLiteral<PCSAsyncClient>() {
|
||||||
|
}, new TypeLiteral<PCSClient>() {
|
||||||
|
}));
|
||||||
bind(URI.class).annotatedWith(PCS.class)
|
bind(URI.class).annotatedWith(PCS.class)
|
||||||
.toInstance(URI.create("http://localhost:8080"));
|
.toInstance(URI.create("http://localhost:8080"));
|
||||||
bind(URI.class).annotatedWith(RootContainer.class).toInstance(
|
bind(URI.class).annotatedWith(RootContainer.class).toInstance(
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.mezeo.pcs2;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
|
||||||
import org.jclouds.mezeo.pcs2.config.PCSRestClientModule;
|
|
||||||
import org.jclouds.mezeo.pcs2.reference.PCSConstants;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in RestContext<PCSClient>Builder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "cloudfiles.PCSContextBuilderTest")
|
|
||||||
public class PCSContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
PCSContextBuilder builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(PCSConstants.PROPERTY_PCS2_ENDPOINT),
|
|
||||||
"https://localhost/pcsblob");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PCSConstants.PROPERTY_PCS2_USER), "id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PCSConstants.PROPERTY_PCS2_PASSWORD),
|
|
||||||
"secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContext<PCSAsyncClient,PCSClient> context = newBuilder().buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAccount(), "id");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://localhost/pcsblob"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<RestContext<PCSAsyncClient,PCSClient>>() {
|
|
||||||
})) != null; // TODO: test all things taken from context
|
|
||||||
assert i.getInstance(BasicAuthentication.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
PCSContextBuilder builder = newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), PCSRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PCSContextBuilder newBuilder() {
|
|
||||||
PCSContextBuilder builder = new PCSContextBuilder(new PCSPropertiesBuilder(URI
|
|
||||||
.create("https://localhost/pcsblob"), "id", "secret").build());
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
PCSContextBuilder builder = newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), PCSRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -35,13 +35,17 @@ import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
public class SDNContextModule extends AbstractModule {
|
public class SDNContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
// for converters to work.
|
// for converters to work.
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<SDNAsyncClient, SDNClient>(
|
||||||
|
new TypeLiteral<SDNAsyncClient>() {
|
||||||
|
}, new TypeLiteral<SDNClient>() {
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -28,8 +28,8 @@ import java.util.Map;
|
||||||
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
|
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.http.functions.ReturnStringIf200;
|
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||||
|
import org.jclouds.http.functions.ReturnStringIf200;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.logging.Logger.LoggerFactory;
|
import org.jclouds.logging.Logger.LoggerFactory;
|
||||||
import org.jclouds.nirvanix.sdn.filters.AddSessionTokenToRequest;
|
import org.jclouds.nirvanix.sdn.filters.AddSessionTokenToRequest;
|
||||||
|
@ -182,7 +182,10 @@ public class SDNClientTest extends RestClientTest<SDNAsyncClient> {
|
||||||
return new AbstractModule() {
|
return new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<SDNAsyncClient, SDNClient>(
|
||||||
|
new TypeLiteral<SDNAsyncClient>() {
|
||||||
|
}, new TypeLiteral<SDNClient>() {
|
||||||
|
}));
|
||||||
bind(URI.class).annotatedWith(SDN.class).toInstance(URI.create("http://stub:8080"));
|
bind(URI.class).annotatedWith(SDN.class).toInstance(URI.create("http://stub:8080"));
|
||||||
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
||||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||||
|
|
|
@ -32,8 +32,6 @@ import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModels;
|
|
||||||
import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix;
|
import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
|
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
|
||||||
|
@ -92,7 +90,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
@RequestFilters(AuthenticateRequest.class)
|
@RequestFilters(AuthenticateRequest.class)
|
||||||
@Endpoint(CloudFiles.class)
|
@Endpoint(CloudFiles.class)
|
||||||
@ConsistencyModel(ConsistencyModels.STRICT)
|
|
||||||
public interface CloudFilesAsyncClient {
|
public interface CloudFilesAsyncClient {
|
||||||
|
|
||||||
CFObject newCFObject();
|
CFObject newCFObject();
|
||||||
|
@ -209,8 +206,8 @@ public interface CloudFilesAsyncClient {
|
||||||
@QueryParams(keys = "format", values = "json")
|
@QueryParams(keys = "format", values = "json")
|
||||||
@ResponseParser(ParseObjectInfoListFromJsonResponse.class)
|
@ResponseParser(ParseObjectInfoListFromJsonResponse.class)
|
||||||
@Path("{container}")
|
@Path("{container}")
|
||||||
ListenableFuture<PageSet<ObjectInfo>> listObjects(
|
ListenableFuture<PageSet<ObjectInfo>> listObjects(@PathParam("container") String container,
|
||||||
@PathParam("container") String container, ListContainerOptions... options);
|
ListContainerOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see CloudFilesClient#containerExists
|
* @see CloudFilesClient#containerExists
|
||||||
|
|
|
@ -28,6 +28,7 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -72,14 +73,14 @@ public class CloudFilesAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CloudFilesAsyncBlobStore(BlobStoreUtils blobUtils,
|
CloudFilesAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, CloudFilesClient sync,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, CloudFilesClient sync,
|
||||||
CloudFilesAsyncClient async, ContainerToResourceMetadata container2ResourceMd,
|
CloudFilesAsyncClient async, ContainerToResourceMetadata container2ResourceMd,
|
||||||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob,
|
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob,
|
||||||
BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
||||||
BlobToHttpGetOptions blob2ObjectGetOptions) {
|
BlobToHttpGetOptions blob2ObjectGetOptions) {
|
||||||
super(blobUtils, service);
|
super(context, blobUtils, service);
|
||||||
this.sync = sync;
|
this.sync = sync;
|
||||||
this.async = async;
|
this.async = async;
|
||||||
this.container2ResourceMd = container2ResourceMd;
|
this.container2ResourceMd = container2ResourceMd;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Set;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -61,13 +62,13 @@ public class CloudFilesBlobStore extends BaseBlobStore {
|
||||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CloudFilesBlobStore(BlobStoreUtils blobUtils, CloudFilesClient sync,
|
CloudFilesBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, CloudFilesClient sync,
|
||||||
ContainerToResourceMetadata container2ResourceMd,
|
ContainerToResourceMetadata container2ResourceMd,
|
||||||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob,
|
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob,
|
||||||
BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
||||||
BlobToHttpGetOptions blob2ObjectGetOptions) {
|
BlobToHttpGetOptions blob2ObjectGetOptions) {
|
||||||
super(blobUtils);
|
super(context, blobUtils);
|
||||||
this.sync = sync;
|
this.sync = sync;
|
||||||
this.container2ResourceMd = container2ResourceMd;
|
this.container2ResourceMd = container2ResourceMd;
|
||||||
this.container2ContainerListOptions = container2ContainerListOptions;
|
this.container2ContainerListOptions = container2ContainerListOptions;
|
||||||
|
|
|
@ -18,24 +18,20 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles.blobstore.config;
|
package org.jclouds.rackspace.cloudfiles.blobstore.config;
|
||||||
|
|
||||||
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.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.lifecycle.Closer;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesAsyncBlobStore;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesAsyncBlobStore;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStore;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStore;
|
||||||
import org.jclouds.rackspace.cloudfiles.config.CloudFilesContextModule;
|
import org.jclouds.rackspace.cloudfiles.config.CloudFilesContextModule;
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link CloudFilesBlobStoreContext}; requires {@link CloudFilesAsyncBlobStore}
|
* Configures the {@link CloudFilesBlobStoreContext}; requires {@link CloudFilesAsyncBlobStore}
|
||||||
|
@ -49,18 +45,12 @@ public class CloudFilesBlobStoreContextModule extends CloudFilesContextModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(AsyncBlobStore.class).to(CloudFilesAsyncBlobStore.class).asEagerSingleton();
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
bind(BlobStore.class).to(CloudFilesBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(CloudFilesAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||||
}
|
bind(BlobStore.class).to(CloudFilesBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
bind(BlobStoreContext.class).to(
|
||||||
@Provides
|
new TypeLiteral<BlobStoreContextImpl<CloudFilesAsyncClient, CloudFilesClient>>() {
|
||||||
@Singleton
|
}).in(Scopes.SINGLETON);
|
||||||
BlobStoreContext provideContext(BlobMap.Factory blobMapFactory,
|
|
||||||
InputStreamMap.Factory inputStreamMapFactory, Closer closer,
|
|
||||||
CloudFilesAsyncBlobStore asynchBlobStore, CloudFilesBlobStore blobStore,
|
|
||||||
RestContext<CloudFilesAsyncClient, CloudFilesClient> context) {
|
|
||||||
return new BlobStoreContextImpl<CloudFilesAsyncClient, CloudFilesClient>(blobMapFactory,
|
|
||||||
inputStreamMapFactory, asynchBlobStore, blobStore, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link CloudFilesContextModule}; requires {@link CloudFilesAsyncClient} bound.
|
* Configures the {@link CloudFilesContextModule}; requires {@link CloudFilesAsyncClient} bound.
|
||||||
|
@ -45,7 +46,10 @@ public class CloudFilesContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
// for converters to work.
|
// for converters to work.
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule<CloudFilesAsyncClient, CloudFilesClient>(
|
||||||
|
new TypeLiteral<CloudFilesAsyncClient>() {
|
||||||
|
}, new TypeLiteral<CloudFilesClient>() {
|
||||||
|
}));
|
||||||
install(new CFObjectModule());
|
install(new CFObjectModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,112 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
|
||||||
|
|
||||||
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.domain.internal.BlobImpl;
|
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|
||||||
import org.jclouds.rackspace.StubRackspaceAuthenticationModule;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesContextBuilder;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesAsyncBlobStore;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.config.CloudFilesRestClientModule;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.config.CloudFilesStubClientModule;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.CFObject;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.internal.CFObjectImpl;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.internal.StubCloudFilesAsyncClient;
|
|
||||||
import org.jclouds.rackspace.reference.RackspaceConstants;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in CloudFilesContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "cloudfiles.CloudFilesContextBuilderTest")
|
|
||||||
public class CloudFilesContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
BlobStoreContextBuilder<CloudFilesAsyncClient, CloudFilesClient> builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_USER_METADATA_PREFIX),
|
|
||||||
"X-Object-Meta-");
|
|
||||||
assertEquals(builder.getProperties().getProperty(RackspaceConstants.PROPERTY_RACKSPACE_USER),
|
|
||||||
"id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(RackspaceConstants.PROPERTY_RACKSPACE_KEY),
|
|
||||||
"secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlobStoreContextBuilder<CloudFilesAsyncClient, CloudFilesClient> newBuilder() {
|
|
||||||
return new CloudFilesContextBuilder(new CloudFilesPropertiesBuilder("id", "secret")
|
|
||||||
.build()).withModules(new CloudFilesStubClientModule(),
|
|
||||||
new StubRackspaceAuthenticationModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
BlobStoreContext context = newBuilder().buildBlobStoreContext();
|
|
||||||
assertEquals(context.getClass(), BlobStoreContextImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAsyncApi().getClass(),
|
|
||||||
StubCloudFilesAsyncClient.class);
|
|
||||||
assertEquals(context.getAsyncBlobStore().getClass(), CloudFilesAsyncBlobStore.class);
|
|
||||||
assertEquals(((CloudFilesAsyncClient) context.getProviderSpecificContext().getAsyncApi())
|
|
||||||
.newCFObject().getClass(), CFObjectImpl.class);
|
|
||||||
assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
|
|
||||||
assertEquals(context.getProviderSpecificContext().getAccount(), "id");
|
|
||||||
assertEquals(context.getProviderSpecificContext().getEndPoint(), URI
|
|
||||||
.create("http://localhost/rackspacestub/cloudfiles"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(BlobStoreContext.class) != null;
|
|
||||||
assert i.getInstance(CFObject.class) != null;
|
|
||||||
assert i.getInstance(Blob.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
CloudFilesContextBuilder builder = (CloudFilesContextBuilder) newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), CloudFilesBlobStoreContextModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
CloudFilesContextBuilder builder = (CloudFilesContextBuilder) newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), CloudFilesRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.rimuhosting.miro.config.RimuHostingRestClientModule;
|
|
||||||
import org.jclouds.rimuhosting.miro.filters.RimuHostingAuthentication;
|
|
||||||
import org.jclouds.rimuhosting.miro.reference.RimuHostingConstants;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in RimuHostingContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "rimuhosting.RimuHostingContextBuilderTest")
|
|
||||||
public class RimuHostingContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
RimuHostingContextBuilder builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT),
|
|
||||||
"https://rimuhosting.com/r");
|
|
||||||
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY),
|
|
||||||
"password");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContext<RimuHostingAsyncClient, RimuHostingClient> context = newBuilder().buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAccount(), "password");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://rimuhosting.com/r"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<RestContext<RimuHostingAsyncClient, RimuHostingClient>>() {
|
|
||||||
})) != null; // TODO: test all things taken from context
|
|
||||||
assert i.getInstance(RimuHostingAuthentication.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
RimuHostingContextBuilder builder = newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), RimuHostingRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RimuHostingContextBuilder newBuilder() {
|
|
||||||
RimuHostingContextBuilder builder = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder("password").build());
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
RimuHostingContextBuilder builder = newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), RimuHostingRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.twitter;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.twitter.config.TwitterRestClientModule;
|
|
||||||
import org.jclouds.twitter.reference.TwitterConstants;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in TwitterContextBuilderT
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "twitter.TwitterContextBuilderTest")
|
|
||||||
public class TwitterContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
TwitterContextBuilder builder = newBuilder();
|
|
||||||
assertEquals(builder.getProperties().getProperty(TwitterConstants.PROPERTY_TWITTER_ENDPOINT),
|
|
||||||
"http://twitter.com");
|
|
||||||
assertEquals(builder.getProperties().getProperty(TwitterConstants.PROPERTY_TWITTER_USER),
|
|
||||||
"user");
|
|
||||||
assertEquals(builder.getProperties().getProperty(TwitterConstants.PROPERTY_TWITTER_PASSWORD),
|
|
||||||
"password");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContext<TwitterAsyncClient, TwitterClient> context = newBuilder().buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAccount(), "user");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("http://twitter.com"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = newBuilder().buildInjector();
|
|
||||||
assert i.getInstance(Key
|
|
||||||
.get(new TypeLiteral<RestContext<TwitterAsyncClient, TwitterClient>>() {
|
|
||||||
})) != null; // TODO: test all things taken from context
|
|
||||||
assert i.getInstance(BasicAuthentication.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
TwitterContextBuilder builder = newBuilder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), TwitterRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TwitterContextBuilder newBuilder() {
|
|
||||||
TwitterContextBuilder builder = new TwitterContextBuilder(new TwitterPropertiesBuilder(
|
|
||||||
"user", "password").build());
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
TwitterContextBuilder builder = newBuilder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), TwitterRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -81,6 +81,7 @@ import org.jclouds.vcloud.domain.VAppStatus;
|
||||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||||
import org.jclouds.vcloud.domain.VDC;
|
import org.jclouds.vcloud.domain.VDC;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
|
@ -180,9 +181,10 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String tag, String name, Template template) {
|
public NodeMetadata execute(String tag, String name, Template template) {
|
||||||
Map<String, String> metaMap = computeClient.start(template.getLocation().getId(), name,
|
Map<String, String> metaMap = computeClient.start(template.getLocation().getId(), name,
|
||||||
template.getImage().getId(), Double.valueOf(template.getSize().getCores()).intValue(), template.getSize()
|
template.getImage().getId(), Double.valueOf(template.getSize().getCores())
|
||||||
.getRam(), template.getSize().getDisk() * 1024 * 1024l, ImmutableMap
|
.intValue(), template.getSize().getRam(),
|
||||||
.<String, String> of(), template.getOptions().getInboundPorts());
|
template.getSize().getDisk() * 1024 * 1024l, ImmutableMap.<String, String> of(),
|
||||||
|
template.getOptions().getInboundPorts());
|
||||||
VApp vApp = client.getVApp(metaMap.get("id"));
|
VApp vApp = client.getVApp(metaMap.get("id"));
|
||||||
return newCreateNodeResponse(tag, template, metaMap, vApp);
|
return newCreateNodeResponse(tag, template, metaMap, vApp);
|
||||||
}
|
}
|
||||||
|
@ -202,6 +204,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class VCloudListNodesStrategy extends VCloudGetNodeMetadata implements
|
public static class VCloudListNodesStrategy extends VCloudGetNodeMetadata implements
|
||||||
ListNodesStrategy {
|
ListNodesStrategy {
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected VCloudListNodesStrategy(VCloudClient client, VCloudComputeClient computeClient,
|
protected VCloudListNodesStrategy(VCloudClient client, VCloudComputeClient computeClient,
|
||||||
|
@ -215,13 +219,27 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
|
||||||
for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) {
|
for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) {
|
||||||
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
|
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
|
||||||
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) {
|
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||||
nodes.add(getNodeMetadataByIdInVDC(vdc.getId(), resource.getId()));
|
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void addVAppToSetRetryingIfNotYetPresent(Set<ComputeMetadata> nodes, NamedResource vdc,
|
||||||
|
NamedResource resource) {
|
||||||
|
NodeMetadata node = null;
|
||||||
|
while (node == null) {
|
||||||
|
try {
|
||||||
|
node = getNodeMetadataByIdInVDC(vdc.getId(), resource.getId());
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
logger.warn("vApp %s not yet present in vdc %s", resource.getId(), vdc.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodes.add(node);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|
|
@ -1,163 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ====================================================================
|
|
||||||
*/
|
|
||||||
package org.jclouds.vcloud;
|
|
||||||
|
|
||||||
import static org.easymock.classextension.EasyMock.createMock;
|
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
|
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
|
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.concurrent.internal.SyncProxy;
|
|
||||||
import org.jclouds.predicates.AddressReachable;
|
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
|
||||||
import org.jclouds.predicates.SocketOpen;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.vcloud.config.VCloudContextModule;
|
|
||||||
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
|
||||||
import org.jclouds.vcloud.domain.VApp;
|
|
||||||
import org.jclouds.vcloud.endpoints.Org;
|
|
||||||
import org.jclouds.vcloud.predicates.TaskSuccess;
|
|
||||||
import org.jclouds.vcloud.predicates.VAppNotFound;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in VCloudContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "vcloud.VCloudContextBuilderTest")
|
|
||||||
public class VCloudContextBuilderTest {
|
|
||||||
VCloudAsyncClient connection = createMock(VCloudAsyncClient.class);
|
|
||||||
|
|
||||||
@ConfiguresRestClient
|
|
||||||
private final class StubClientModule extends AbstractModule {
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org"));
|
|
||||||
bind(VCloudAsyncClient.class).toInstance(connection);
|
|
||||||
}
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
|
||||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 10, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Predicate<InetAddress> addressTester(AddressReachable reachable) {
|
|
||||||
return new RetryablePredicate<InetAddress>(reachable, 60, 5, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Predicate<String> successTester(TaskSuccess success) {
|
|
||||||
return new RetryablePredicate<String>(success, 600, 10, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named("NOT_FOUND")
|
|
||||||
protected Predicate<VApp> successTester(VAppNotFound notFound) {
|
|
||||||
return new RetryablePredicate<VApp>(notFound, 5, 1, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
public VCloudClient provideClient(VCloudAsyncClient client) throws IllegalArgumentException,
|
|
||||||
SecurityException, NoSuchMethodException {
|
|
||||||
return SyncProxy.create(VCloudClient.class, client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
RestContextBuilder<VCloudAsyncClient, VCloudClient> builder = builder();
|
|
||||||
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_ENDPOINT),
|
|
||||||
"http://localhost");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_USER), "id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_KEY), "secret");
|
|
||||||
assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_SESSIONINTERVAL), "480");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
RestContextBuilder<VCloudAsyncClient, VCloudClient> builder = builder();
|
|
||||||
RestContext<VCloudAsyncClient, VCloudClient> context = builder.buildContext();
|
|
||||||
assertEquals(context.getClass(), RestContextImpl.class);
|
|
||||||
assertEquals(context.getAsyncApi(), connection);
|
|
||||||
assertEquals(context.getAccount(), "id");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("http://org"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public RestContextBuilder<VCloudAsyncClient, VCloudClient> builder() {
|
|
||||||
return new VCloudContextBuilder(new VCloudPropertiesBuilder(URI.create("http://localhost"),
|
|
||||||
"id", "secret").build()).withModules(new StubClientModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
RestContextBuilder<VCloudAsyncClient, VCloudClient> builder = builder();
|
|
||||||
Injector i = builder.buildInjector();
|
|
||||||
assert i.getInstance(Key.get(URI.class, Org.class)) != null;
|
|
||||||
assert i.getInstance(Key.get(new TypeLiteral<RestContext<VCloudAsyncClient, VCloudClient>>() {
|
|
||||||
})) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
VCloudContextBuilder builder = (VCloudContextBuilder) builder();
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), VCloudContextModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
VCloudContextBuilder builder = (VCloudContextBuilder) builder();
|
|
||||||
builder.addClientModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), VCloudRestClientModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue