added retry handler for io exceptions, created modular rest client, swapped generic type args on restcontext

This commit is contained in:
Adrian Cole 2010-06-06 23:01:48 -07:00
parent 18e9294b89
commit 84ad021268
266 changed files with 2981 additions and 3649 deletions

View File

@ -43,7 +43,7 @@ import com.google.inject.TypeLiteral;
/** /**
* @author ${author} * @author ${author}
*/ */
public class ${providerName}ContextBuilder extends ComputeServiceContextBuilder<${providerName}AsyncClient, ${providerName}Client> { public class ${providerName}ContextBuilder extends ComputeServiceContextBuilder<${providerName}Client, ${providerName}AsyncClient> {
public ${providerName}ContextBuilder(String providerName, Properties props) { public ${providerName}ContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<${providerName}AsyncClient>() {}, super(providerName, new TypeLiteral<${providerName}AsyncClient>() {},

View File

@ -83,7 +83,7 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
bind(new TypeLiteral<ComputeServiceContext>() { bind(new TypeLiteral<ComputeServiceContext>() {
}) })
.to( .to(
new TypeLiteral<ComputeServiceContextImpl<${providerName}AsyncClient, ${providerName}Client>>() { new TypeLiteral<ComputeServiceContextImpl<${providerName}Client, ${providerName}AsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(${providerName}AddNodeWithTagStrategy.class); bind(AddNodeWithTagStrategy.class).to(${providerName}AddNodeWithTagStrategy.class);
bind(ListNodesStrategy.class).to(${providerName}ListNodesStrategy.class); bind(ListNodesStrategy.class).to(${providerName}ListNodesStrategy.class);

View File

@ -63,7 +63,7 @@ public class ${providerName}ComputeServiceLiveTest extends BaseComputeServiceLiv
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<${providerName}AsyncClient, ${providerName}Client> tmContext = new ComputeServiceContextFactory() RestContext<${providerName}Client, ${providerName}AsyncClient> tmContext = new ComputeServiceContextFactory()
.createContext(service, user, password).getProviderSpecificContext(); .createContext(service, user, password).getProviderSpecificContext();
} }

View File

@ -1,3 +1,6 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/** /**
* *
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com> * Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
@ -16,32 +19,6 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
#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}; package ${package};
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;

View File

@ -26,15 +26,20 @@
*/ */
package ${package}; package ${package};
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import ${package}.${providerName}Client;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -48,24 +53,32 @@ import com.google.common.util.concurrent.ListenableFuture;
*/ */
@Endpoint(${providerName}.class) @Endpoint(${providerName}.class)
@RequestFilters(BasicAuthentication.class) @RequestFilters(BasicAuthentication.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface ${providerName}AsyncClient { public interface ${providerName}AsyncClient {
/* /*
* TODO: define interface methods for ${providerName} * TODO: define interface methods for ${providerName}
*/ */
/** /**
* @see ${providerName}AsyncClient#list() * @see ${providerName}Client#list()
*/ */
@GET @GET
@Path("/item") @Path("/items")
ListenableFuture<String> list(); ListenableFuture<String> list();
/** /**
* @see ${providerName}AsyncClient#get(String) * @see ${providerName}Client#get(long)
*/ */
@GET @GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/item/{itemId}") @Path("/items/{itemId}")
ListenableFuture<String> get(@PathParam("itemId") long id); ListenableFuture<String> get(@PathParam("itemId") long id);
/**
* @see ${providerName}Client#delete
*/
@DELETE
@Path("/items/{itemId}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> delete(@PathParam("itemId") long id);
} }

View File

@ -1,21 +1,3 @@
/**
*
* 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( $symbol_pound = '#' ) #set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' ) #set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' ) #set( $symbol_escape = '\' )
@ -66,6 +48,11 @@ public interface ${providerName}Client {
String list(); String list();
/**
* @return null, if not found
*/
String get(long id); String get(long id);
void delete(long id);
} }

View File

@ -41,18 +41,15 @@ import ${package}.config.${providerName}RestClientModule;
import ${package}.reference.${providerName}Constants; import ${package}.reference.${providerName}Constants;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/** /**
* *
* @author ${author} * @author ${author}
*/ */
public class ${providerName}ContextBuilder extends RestContextBuilder<${providerName}AsyncClient, ${providerName}Client> { public class ${providerName}ContextBuilder extends RestContextBuilder<${providerName}Client, ${providerName}AsyncClient> {
public ${providerName}ContextBuilder(String providerName, Properties props) { public ${providerName}ContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<${providerName}AsyncClient>() { super(providerName, ${providerName}Client.class, ${providerName}AsyncClient.class, props);
}, new TypeLiteral<${providerName}Client>() {
}, props);
checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER)); checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER));
checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_PASSWORD)); checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_PASSWORD));
} }

View File

@ -52,19 +52,19 @@ import com.google.inject.Module;
*/ */
public class ${providerName}ContextFactory { public class ${providerName}ContextFactory {
public static RestContext<${providerName}AsyncClient, ${providerName}Client> createContext(String user, String password, public static RestContext<${providerName}Client, ${providerName}AsyncClient> createContext(String user, String password,
Module... modules) { Module... modules) {
return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(user, password).build()) return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(user, password).build())
.withModules(modules).buildContext(); .withModules(modules).buildContext();
} }
public static RestContext<${providerName}AsyncClient, ${providerName}Client> createContext(URI endpoint, String user, String password, public static RestContext<${providerName}Client, ${providerName}AsyncClient> createContext(URI endpoint, String user, String password,
Module... modules) { Module... modules) {
return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(user, password).withEndpoint(endpoint).build()) return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(user, password).withEndpoint(endpoint).build())
.withModules(modules).buildContext(); .withModules(modules).buildContext();
} }
public static RestContext<${providerName}AsyncClient, ${providerName}Client> createContext(Properties properties, Module... modules) { public static RestContext<${providerName}Client, ${providerName}AsyncClient> createContext(Properties properties, Module... modules) {
return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(properties).build()) return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(properties).build())
.withModules(modules).buildContext(); .withModules(modules).buildContext();
} }

View File

@ -77,9 +77,9 @@ public class ${providerName}ContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
RestContext<${providerName}AsyncClient, ${providerName}Client> provideContext(Closer closer, ${providerName}AsyncClient asyncApi, RestContext<${providerName}Client, ${providerName}AsyncClient> provideContext(Closer closer, ${providerName}AsyncClient asyncApi,
${providerName}Client syncApi, @${providerName} URI endPoint, @Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER) String account) { ${providerName}Client syncApi, @${providerName} URI endPoint, @Named(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER) String account) {
return new RestContextImpl<${providerName}AsyncClient, ${providerName}Client>(closer, asyncApi, syncApi, endPoint, account); return new RestContextImpl<${providerName}Client, ${providerName}AsyncClient>(closer, asyncApi, syncApi, endPoint, account);
} }
} }

View File

@ -48,19 +48,22 @@ import java.net.URI;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import ${package}.${providerName}; import ${package}.${providerName};
import ${package}.${providerName}Client; import ${package}.${providerName}Client;
import ${package}.${providerName}AsyncClient; import ${package}.${providerName}AsyncClient;
import ${package}.reference.${providerName}Constants; import ${package}.reference.${providerName}Constants;
import ${package}.handlers.${providerName}ErrorHandler;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -70,12 +73,11 @@ import com.google.inject.Provides;
*/ */
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public class ${providerName}RestClientModule extends AbstractModule { public class ${providerName}RestClientModule extends
RestClientModule<${providerName}Client, ${providerName}AsyncClient> {
@Override public ${providerName}RestClientModule() {
protected void configure() { super(${providerName}Client.class, ${providerName}AsyncClient.class);
bindErrorHandlers();
bindRetryHandlers();
} }
@Provides @Provides
@ -88,19 +90,6 @@ public class ${providerName}RestClientModule extends AbstractModule {
return new BasicAuthentication(user, password, encryptionService); return new BasicAuthentication(user, password, encryptionService);
} }
@Provides
@Singleton
protected ${providerName}AsyncClient provideClient(RestClientFactory factory) {
return factory.create(${providerName}AsyncClient.class);
}
@Provides
@Singleton
public ${providerName}Client provideClient(${providerName}AsyncClient provider) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(${providerName}Client.class, provider);
}
@Provides @Provides
@Singleton @Singleton
@${providerName} @${providerName}
@ -108,10 +97,17 @@ public class ${providerName}RestClientModule extends AbstractModule {
return URI.create(endpoint); return URI.create(endpoint);
} }
@Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
// TODO bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
${providerName}ErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
${providerName}ErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
${providerName}ErrorHandler.class);
} }
@Override
protected void bindRetryHandlers() { protected void bindRetryHandlers() {
// TODO // TODO
} }

View File

@ -27,34 +27,27 @@
*/ */
package ${package}; package ${package};
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import javax.inject.Singleton; import ${package}.config.${providerName}RestClientModule;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.logging.Logger; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/** /**
* Tests annotation parsing of {@code ${providerName}AsyncClient} * Tests annotation parsing of {@code ${providerName}AsyncClient}
@ -70,7 +63,7 @@ public class ${providerName}AsyncClientTest extends RestClientTest<${providerNam
GeneratedHttpRequest<${providerName}AsyncClient> httpRequest = processor.createRequest(method); GeneratedHttpRequest<${providerName}AsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item HTTP/1.1");
assertHeadersEqual(httpRequest, ""); assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
// now make sure request filters apply by replaying // now make sure request filters apply by replaying
@ -79,7 +72,7 @@ public class ${providerName}AsyncClientTest extends RestClientTest<${providerNam
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item HTTP/1.1");
// for example, using basic authentication, we should get "only one" header // for example, using basic authentication, we should get "only one" header
assertHeadersEqual(httpRequest, "Authorization: Basic Zm9vOmJhcg==\n"); assertHeadersEqual(httpRequest, "Accept: application/json\nAuthorization: Basic Zm9vOmJhcg==\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
// TODO: insert expected response class, which probably extends ParseJson // TODO: insert expected response class, which probably extends ParseJson
@ -96,7 +89,7 @@ public class ${providerName}AsyncClientTest extends RestClientTest<${providerNam
GeneratedHttpRequest<${providerName}AsyncClient> httpRequest = processor.createRequest(method, 1); GeneratedHttpRequest<${providerName}AsyncClient> httpRequest = processor.createRequest(method, 1);
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item/1 HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item/1 HTTP/1.1");
assertHeadersEqual(httpRequest, ""); assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
// TODO: insert expected response class, which probably extends ParseJson // TODO: insert expected response class, which probably extends ParseJson
@ -109,6 +102,23 @@ public class ${providerName}AsyncClientTest extends RestClientTest<${providerNam
} }
public void testDelete() throws SecurityException, NoSuchMethodException, IOException {
Method method = ${providerName}AsyncClient.class.getMethod("delete", long.class);
GeneratedHttpRequest<${providerName}AsyncClient> httpRequest = processor.createRequest(
method, 1);
assertRequestLineEquals(httpRequest,
"DELETE ${providerEndpoint}/item/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override @Override
protected void checkFilters(GeneratedHttpRequest<${providerName}AsyncClient> httpRequest) { protected void checkFilters(GeneratedHttpRequest<${providerName}AsyncClient> httpRequest) {
assertEquals(httpRequest.getFilters().size(), 1); assertEquals(httpRequest.getFilters().size(), 1);
@ -123,28 +133,13 @@ public class ${providerName}AsyncClientTest extends RestClientTest<${providerNam
@Override @Override
protected Module createModule() { protected Module createModule() {
return new AbstractModule() { return new ${providerName}RestClientModule() {
@Override @Override
protected void configure() { protected void configure() {
Jsr330.bindProperties(binder(), new ${providerName}PropertiesBuilder( Names.bindProperties(binder(), new ${providerName}PropertiesBuilder("user", "key").build());
new Properties()).build()); install(new NullLoggingModule());
bind(URI.class).annotatedWith(${providerName}.class).toInstance( super.configure();
URI.create("${providerEndpoint}"));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
} }
});
}
@SuppressWarnings("unused")
@Provides
@Singleton
public BasicAuthentication provideBasicAuthentication(EncryptionService encryptionService)
throws UnsupportedEncodingException {
return new BasicAuthentication("foo", "bar", encryptionService);
}
}; };
} }
} }

View File

@ -29,7 +29,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/** /**
* Creates {@link AtmosBlobStoreContext} or {@link Injector} instances based on the most commonly * Creates {@link AtmosBlobStoreContext} or {@link Injector} instances based on the most commonly
@ -45,12 +44,10 @@ import com.google.inject.TypeLiteral;
* @see AtmosBlobStoreContext * @see AtmosBlobStoreContext
*/ */
public class AtmosStorageContextBuilder extends public class AtmosStorageContextBuilder extends
BlobStoreContextBuilder<AtmosStorageAsyncClient, AtmosStorageClient> { BlobStoreContextBuilder<AtmosStorageClient, AtmosStorageAsyncClient> {
public AtmosStorageContextBuilder(String providerName, Properties props) { public AtmosStorageContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<AtmosStorageAsyncClient>() { super(providerName, AtmosStorageClient.class, AtmosStorageAsyncClient.class, props);
}, new TypeLiteral<AtmosStorageClient>() {
}, props);
} }
@Override @Override

View File

@ -65,7 +65,7 @@ public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
bind(BlobStore.class).to(AtmosBlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(AtmosBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class) bind(BlobStoreContext.class)
.to( .to(
new TypeLiteral<BlobStoreContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>>() { new TypeLiteral<BlobStoreContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class); bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
} }

View File

@ -26,6 +26,7 @@ import org.jclouds.atmosonline.saas.domain.MutableContentMetadata;
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.domain.internal.AtmosObjectImpl; import org.jclouds.atmosonline.saas.domain.internal.AtmosObjectImpl;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -45,6 +46,8 @@ public class AtmosObjectModule extends AbstractModule {
*/ */
@Override @Override
protected void configure() { protected void configure() {
// for converters
install(new BlobStoreObjectModule());
bind(AtmosObject.Factory.class).to(AtmosObjectFactory.class).in(Scopes.SINGLETON); bind(AtmosObject.Factory.class).to(AtmosObjectFactory.class).in(Scopes.SINGLETON);
} }

View File

@ -27,7 +27,6 @@ import org.jclouds.atmosonline.saas.AtmosStorage;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient; import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient; import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants; import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -35,28 +34,25 @@ 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;
/**
*
* @author Adrian Cole
*/
@RequiresHttp @RequiresHttp
public class AtmosStorageContextModule extends AbstractModule { public class AtmosStorageContextModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
// for converters to work.
install(new BlobStoreObjectModule<AtmosStorageAsyncClient, AtmosStorageClient>(
new TypeLiteral<AtmosStorageAsyncClient>() {
}, new TypeLiteral<AtmosStorageClient>() {
}));
install(new AtmosObjectModule());
} }
@Provides @Provides
@Singleton @Singleton
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> provideContext(Closer closer, RestContext<AtmosStorageClient, AtmosStorageAsyncClient> provideContext(Closer closer,
AtmosStorageAsyncClient async, AtmosStorageClient defaultApi, AtmosStorageAsyncClient async, AtmosStorageClient defaultApi,
@AtmosStorage URI endPoint, @AtmosStorage URI endPoint,
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) { @Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) {
return new RestContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>(closer, async, return new RestContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>(closer, async,
defaultApi, endPoint, account); defaultApi, endPoint, account);
} }

View File

@ -33,7 +33,6 @@ import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler; import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler;
import org.jclouds.atmosonline.saas.handlers.ParseAtmosStorageErrorFromXmlContent; import org.jclouds.atmosonline.saas.handlers.ParseAtmosStorageErrorFromXmlContent;
import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
@ -43,10 +42,9 @@ import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -57,7 +55,18 @@ import com.google.inject.Provides;
*/ */
@ConfiguresRestClient @ConfiguresRestClient
@RequiresHttp @RequiresHttp
public class AtmosStorageRestClientModule extends AbstractModule { public class AtmosStorageRestClientModule extends
RestClientModule<AtmosStorageClient, AtmosStorageAsyncClient> {
public AtmosStorageRestClientModule() {
super(AtmosStorageClient.class, AtmosStorageAsyncClient.class);
}
@Override
protected void configure() {
install(new AtmosObjectModule());
super.configure();
}
@Provides @Provides
@Singleton @Singleton
@AtmosStorage @AtmosStorage
@ -65,25 +74,6 @@ public class AtmosStorageRestClientModule extends AbstractModule {
return URI.create(endpoint); return URI.create(endpoint);
} }
@Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
}
@Provides
@Singleton
protected AtmosStorageAsyncClient provideAsyncClient(RestClientFactory factory) {
return factory.create(AtmosStorageAsyncClient.class);
}
@Provides
@Singleton
public AtmosStorageClient provideClient(AtmosStorageAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(AtmosStorageClient.class, client);
}
@Provides @Provides
@TimeStamp @TimeStamp
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) { protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
@ -104,6 +94,7 @@ public class AtmosStorageRestClientModule extends AbstractModule {
}, seconds, TimeUnit.SECONDS); }, seconds, TimeUnit.SECONDS);
} }
@Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAtmosStorageErrorFromXmlContent.class); ParseAtmosStorageErrorFromXmlContent.class);
@ -113,6 +104,7 @@ public class AtmosStorageRestClientModule extends AbstractModule {
ParseAtmosStorageErrorFromXmlContent.class); ParseAtmosStorageErrorFromXmlContent.class);
} }
@Override
protected void bindRetryHandlers() { protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to( bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AtmosStorageClientErrorRetryHandler.class); AtmosStorageClientErrorRetryHandler.class);

View File

@ -18,19 +18,17 @@
*/ */
package org.jclouds.atmosonline.saas; package org.jclouds.atmosonline.saas;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties; import java.util.Properties;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.atmosonline.saas.blobstore.functions.BlobToObject; import org.jclouds.atmosonline.saas.blobstore.functions.BlobToObject;
import org.jclouds.atmosonline.saas.config.AtmosObjectModule; import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
import org.jclouds.atmosonline.saas.domain.AtmosObject; import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.atmosonline.saas.filters.SignRequest; import org.jclouds.atmosonline.saas.filters.SignRequest;
import org.jclouds.atmosonline.saas.functions.ParseDirectoryListFromContentAndHeaders; import org.jclouds.atmosonline.saas.functions.ParseDirectoryListFromContentAndHeaders;
@ -38,28 +36,24 @@ 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.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
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.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.common.base.Supplier;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -79,7 +73,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method); GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"GET http://accesspoint.emccis.com/rest/namespace HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -98,7 +92,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"directory"); "directory");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"GET http://accesspoint.emccis.com/rest/namespace/directory/ HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -118,7 +112,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
new ListOptions().limit(1).token("asda")); new ListOptions().limit(1).token("asda"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"GET http://accesspoint.emccis.com/rest/namespace HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n"); + ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -139,7 +133,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"directory", new ListOptions().limit(1).token("asda")); "directory", new ListOptions().limit(1).token("asda"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"GET http://accesspoint.emccis.com/rest/namespace/directory/ HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n"); + ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -158,7 +152,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir"); "dir");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"POST http://accesspoint.emccis.com/rest/namespace/dir/ HTTP/1.1"); "POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -177,7 +171,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB)); "dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"POST http://accesspoint.emccis.com/rest/namespace/dir/hello HTTP/1.1"); "POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n"); + ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(httpMethod, "hello");
@ -197,7 +191,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB)); "dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"PUT http://accesspoint.emccis.com/rest/namespace/dir/hello HTTP/1.1"); "PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n"); + ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(httpMethod, "hello");
@ -216,7 +210,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir/file"); "dir/file");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"GET http://accesspoint.emccis.com/rest/namespace/dir/file HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -234,7 +228,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir/file"); "dir/file");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"HEAD http://accesspoint.emccis.com/rest/namespace/dir/file HTTP/1.1"); "HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -251,7 +245,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir/file"); "dir/file");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"DELETE http://accesspoint.emccis.com/rest/namespace/dir/file HTTP/1.1"); "DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -288,33 +282,19 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
@Override @Override
protected Module createModule() { protected Module createModule() {
return new AbstractModule() { return new AtmosStorageRestClientModule() {
@Override @Override
protected void configure() { protected void configure() {
install(new BlobStoreObjectModule<AtmosStorageAsyncClient, AtmosStorageClient>( Names.bindProperties(binder(), new AtmosStoragePropertiesBuilder(new Properties())
new TypeLiteral<AtmosStorageAsyncClient>() { .withCredentials("uid", "key").build());
}, new TypeLiteral<AtmosStorageClient>() { install(new NullLoggingModule());
})); super.configure();
install(new AtmosObjectModule());
Jsr330.bindProperties(binder(), checkNotNull(new AtmosStoragePropertiesBuilder(
new Properties()).build(), "properties"));
bind(URI.class).annotatedWith(AtmosStorage.class).toInstance(
URI.create("http://accesspoint.emccis.com"));
bind(String.class).annotatedWith(TimeStamp.class).toInstance("timestamp");
bindConstant().annotatedWith(Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID))
.to("uid");
bindConstant().annotatedWith(Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY))
.to(Base64.encodeBytes("key".getBytes()));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
bindConstant().annotatedWith(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_SESSIONINTERVAL)).to(1l);
} }
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "2009-11-08T15:54:08.897Z";
}
}; };
} }
} }

View File

@ -120,7 +120,7 @@ public class AtmosStorageClientLiveTest {
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
BlobStoreContext blobStoreContext = new BlobStoreContextFactory().createContext( BlobStoreContext blobStoreContext = new BlobStoreContextFactory().createContext(
"atmosonline", uid, key, ImmutableSet.<Module> of(new Log4JLoggingModule())); "atmosonline", uid, key, ImmutableSet.<Module> of(new Log4JLoggingModule()));
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> context = blobStoreContext RestContext<AtmosStorageClient, AtmosStorageAsyncClient> context = blobStoreContext
.getProviderSpecificContext(); .getProviderSpecificContext();
connection = context.getApi(); connection = context.getApi();
for (DirectoryEntry entry : connection.listDirectories()) { for (DirectoryEntry entry : connection.listDirectories()) {

View File

@ -18,21 +18,21 @@
*/ */
package org.jclouds.atmosonline.saas.blobstore.config; package org.jclouds.atmosonline.saas.blobstore.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.Constants; import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata; import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule; import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
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.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule; import com.google.inject.name.Names;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -43,31 +43,16 @@ import com.google.inject.Injector;
public class AtmosBlobStoreModuleTest { public class AtmosBlobStoreModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(), return Guice.createInjector(new AtmosStorageStubClientModule(),
sameThreadExecutor()), new JDKLoggingModule(), new AtmosStorageStubClientModule(), new AtmosBlobStoreContextModule("atmos"), new ExecutorServiceModule(sameThreadExecutor(),
new AtmosBlobStoreContextModule("atmos") { sameThreadExecutor()), new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith( Names.bindProperties(binder(), checkNotNull(new AtmosStoragePropertiesBuilder(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID)).to("user"); "user", "key").build(), "properties"));
bindConstant().annotatedWith(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY)).to("key");
bindConstant().annotatedWith(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_ENDPOINT)).to(
"http://localhost");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
super.configure();
} }
}); });
} }
@Test @Test
void testContextImpl() { void testContextImpl() {

View File

@ -1,123 +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.config;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler;
import org.jclouds.atmosonline.saas.handlers.ParseAtmosStorageErrorFromXmlContent;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.http.handlers.RedirectionRetryHandler;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "emcsaas.AtmosStorageRestClientModuleTest")
public class AtmosStorageRestClientModuleTest {
Injector createInjector() {
return Guice.createInjector(new AtmosStorageRestClientModule(), new ExecutorServiceModule(
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_ENDPOINT)).to(
"http://localhost");
bindConstant().annotatedWith(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID)).to("uid");
bindConstant().annotatedWith(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY)).to(
new String(Base64.encodeBytes("key".getBytes())));
bindConstant().annotatedWith(
Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_SESSIONINTERVAL))
.to("2");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
}
@Test
void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException {
AtmosStorageRestClientModule module = new AtmosStorageRestClientModule();
Supplier<String> map = module.provideTimeStampCache(1, new SimpleDateFormatDateService());
String timeStamp = map.get();
for (int i = 0; i < 10; i++)
map.get();
assertEquals(timeStamp, map.get());
Thread.sleep(1001);
assertFalse(timeStamp.equals(map.get()));
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(),
ParseAtmosStorageErrorFromXmlContent.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(),
ParseAtmosStorageErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AtmosStorageClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class);
}
}

View File

@ -20,18 +20,14 @@ package org.jclouds.atmosonline.saas.config;
import java.net.URI; import java.net.URI;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.AtmosStorage; import org.jclouds.atmosonline.saas.AtmosStorage;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient; import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient; import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.internal.StubAtmosStorageAsyncClient; import org.jclouds.atmosonline.saas.internal.StubAtmosStorageAsyncClient;
import org.jclouds.blobstore.config.TransientBlobStoreModule; import org.jclouds.blobstore.config.TransientBlobStoreModule;
import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/** /**
* adds a stub alternative to invoking AtmosStorage * adds a stub alternative to invoking AtmosStorage
@ -39,19 +35,24 @@ import com.google.inject.Provides;
* @author Adrian Cole * @author Adrian Cole
*/ */
@ConfiguresRestClient @ConfiguresRestClient
public class AtmosStorageStubClientModule extends AbstractModule { public class AtmosStorageStubClientModule extends
RestClientModule<AtmosStorageClient, AtmosStorageAsyncClient> {
public AtmosStorageStubClientModule() {
super(AtmosStorageClient.class, AtmosStorageAsyncClient.class);
}
protected void configure() { protected void configure() {
super.configure();
install(new AtmosObjectModule());
install(new ParserModule());
install(new TransientBlobStoreModule()); install(new TransientBlobStoreModule());
bind(AtmosStorageAsyncClient.class).to(StubAtmosStorageAsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(AtmosStorage.class).toInstance( bind(URI.class).annotatedWith(AtmosStorage.class).toInstance(
URI.create("https://localhost/azurestub")); URI.create("https://localhost/atmosstub"));
} }
@Provides @Override
@Singleton protected void bindAsyncClient() {
public AtmosStorageClient provideClient(AtmosStorageAsyncClient client) bind(AtmosStorageAsyncClient.class).to(StubAtmosStorageAsyncClient.class).asEagerSingleton();
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(AtmosStorageClient.class, client);
} }
} }

View File

@ -18,7 +18,9 @@
*/ */
package org.jclouds.atmosonline.saas.filters; package org.jclouds.atmosonline.saas.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -29,21 +31,23 @@ import java.security.NoSuchAlgorithmException;
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.Constants; import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants; import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders; import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.util.Jsr330; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.rest.config.RestModule;
import com.google.inject.name.Names;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides;
@Test(groups = "unit", testName = "emcsaas.SignRequestTest") @Test(groups = "unit", testName = "emcsaas.SignRequestTest")
public class SignRequestTest { public class SignRequestTest {
@ -80,24 +84,18 @@ public class SignRequestTest {
@BeforeClass @BeforeClass
protected void createFilter() { protected void createFilter() {
injector = Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(), injector = Guice.createInjector(new RestModule(), new AtmosStorageRestClientModule() {
sameThreadExecutor()), new AbstractModule() { protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID))
.to("user");
bindConstant().annotatedWith(Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY))
.to(KEY);
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
.to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
}
@SuppressWarnings("unused")
@Provides
@TimeStamp
String getDate() {
return "Thu, 05 Jun 2008 16:38:19 GMT"; return "Thu, 05 Jun 2008 16:38:19 GMT";
}
}, new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() {
protected void configure() {
Names.bindProperties(binder(), checkNotNull(
new AtmosStoragePropertiesBuilder("user", KEY)).build());
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
} }
}); });
filter = injector.getInstance(SignRequest.class); filter = injector.getInstance(SignRequest.class);

View File

@ -18,6 +18,9 @@
*/ */
package org.jclouds.aws.domain; package org.jclouds.aws.domain;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
/** /**
* *
@ -29,7 +32,6 @@ package org.jclouds.aws.domain;
* *
*/ */
public class Region { public class Region {
/** /**
* EU (Ireland) * EU (Ireland)
* <p/> * <p/>
@ -73,8 +75,12 @@ public class Region {
public static final String US_WEST_1 = "us-west-1"; public static final String US_WEST_1 = "us-west-1";
/** /**
* Region in Singapore, launched April 28, 2010. * Region in Singapore, launched April 28, 2010. This region improves latency for Asia-based
* This region improves latency for Asia-based users * users
*/ */
public static final String AP_SOUTHEAST_1 = "ap-southeast-1"; public static final String AP_SOUTHEAST_1 = "ap-southeast-1";
public static Set<String> ALL = ImmutableSet.of(EU_WEST_1, US_STANDARD, US_EAST_1, US_WEST_1,
AP_SOUTHEAST_1);
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.aws.ec2; package org.jclouds.aws.ec2;
import org.jclouds.aws.ec2.internal.EC2AsyncClientImpl;
import org.jclouds.aws.ec2.services.AMIAsyncClient; import org.jclouds.aws.ec2.services.AMIAsyncClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient; import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient; import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient;
@ -28,58 +27,65 @@ import org.jclouds.aws.ec2.services.InstanceAsyncClient;
import org.jclouds.aws.ec2.services.KeyPairAsyncClient; import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringAsyncClient; import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient; import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
import org.jclouds.rest.annotations.Delegate;
import com.google.inject.ImplementedBy;
/** /**
* Provides asynchronous access to EC2 services. * Provides asynchronous access to EC2 services.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ImplementedBy(EC2AsyncClientImpl.class)
public interface EC2AsyncClient { public interface EC2AsyncClient {
/** /**
* Provides asynchronous access to AMI services. * Provides asynchronous access to AMI services.
*/ */
@Delegate
AMIAsyncClient getAMIServices(); AMIAsyncClient getAMIServices();
/** /**
* Provides asynchronous access to Elastic IP Address services. * Provides asynchronous access to Elastic IP Address services.
*/ */
@Delegate
ElasticIPAddressAsyncClient getElasticIPAddressServices(); ElasticIPAddressAsyncClient getElasticIPAddressServices();
/** /**
* Provides asynchronous access to Instance services. * Provides asynchronous access to Instance services.
*/ */
@Delegate
InstanceAsyncClient getInstanceServices(); InstanceAsyncClient getInstanceServices();
/** /**
* Provides asynchronous access to KeyPair services. * Provides asynchronous access to KeyPair services.
*/ */
@Delegate
KeyPairAsyncClient getKeyPairServices(); KeyPairAsyncClient getKeyPairServices();
/** /**
* Provides asynchronous access to SecurityGroup services. * Provides asynchronous access to SecurityGroup services.
*/ */
@Delegate
SecurityGroupAsyncClient getSecurityGroupServices(); SecurityGroupAsyncClient getSecurityGroupServices();
/** /**
* Provides asynchronous access to Monitoring services. * Provides asynchronous access to Monitoring services.
*/ */
@Delegate
MonitoringAsyncClient getMonitoringServices(); MonitoringAsyncClient getMonitoringServices();
/** /**
* Provides asynchronous access to Availability Zones and Regions services. * Provides asynchronous access to Availability Zones and Regions services.
*/ */
@Delegate
AvailabilityZoneAndRegionAsyncClient getAvailabilityZoneAndRegionServices(); AvailabilityZoneAndRegionAsyncClient getAvailabilityZoneAndRegionServices();
/** /**
* Provides asynchronous access to Elastic Block Store services. * Provides asynchronous access to Elastic Block Store services.
*/ */
@Delegate
ElasticBlockStoreAsyncClient getElasticBlockStoreServices(); ElasticBlockStoreAsyncClient getElasticBlockStoreServices();
/** /**
* Provides asynchronous access to Elastic Load Balancer services. * Provides asynchronous access to Elastic Load Balancer services.
*/ */
@Delegate
ElasticLoadBalancerAsyncClient getElasticLoadBalancerServices(); ElasticLoadBalancerAsyncClient getElasticLoadBalancerServices();
} }

View File

@ -18,7 +18,8 @@
*/ */
package org.jclouds.aws.ec2; package org.jclouds.aws.ec2;
import org.jclouds.aws.ec2.internal.EC2ClientImpl; import java.util.concurrent.TimeUnit;
import org.jclouds.aws.ec2.services.AMIClient; import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionClient; import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreClient; import org.jclouds.aws.ec2.services.ElasticBlockStoreClient;
@ -28,58 +29,67 @@ import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.aws.ec2.services.KeyPairClient; import org.jclouds.aws.ec2.services.KeyPairClient;
import org.jclouds.aws.ec2.services.MonitoringClient; import org.jclouds.aws.ec2.services.MonitoringClient;
import org.jclouds.aws.ec2.services.SecurityGroupClient; import org.jclouds.aws.ec2.services.SecurityGroupClient;
import org.jclouds.concurrent.Timeout;
import com.google.inject.ImplementedBy; import org.jclouds.rest.annotations.Delegate;
/** /**
* Provides synchronous access to EC2 services. * Provides synchronous access to EC2 services.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ImplementedBy(EC2ClientImpl.class) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface EC2Client { public interface EC2Client {
/** /**
* Provides synchronous access to AMI services. * Provides synchronous access to AMI services.
*/ */
@Delegate
AMIClient getAMIServices(); AMIClient getAMIServices();
/** /**
* Provides synchronous access to Elastic IP Address services. * Provides synchronous access to Elastic IP Address services.
*/ */
@Delegate
ElasticIPAddressClient getElasticIPAddressServices(); ElasticIPAddressClient getElasticIPAddressServices();
/** /**
* Provides synchronous access to Instance services. * Provides synchronous access to Instance services.
*/ */
@Delegate
InstanceClient getInstanceServices(); InstanceClient getInstanceServices();
/** /**
* Provides synchronous access to KeyPair services. * Provides synchronous access to KeyPair services.
*/ */
@Delegate
KeyPairClient getKeyPairServices(); KeyPairClient getKeyPairServices();
/** /**
* Provides synchronous access to SecurityGroup services. * Provides synchronous access to SecurityGroup services.
*/ */
@Delegate
SecurityGroupClient getSecurityGroupServices(); SecurityGroupClient getSecurityGroupServices();
/** /**
* Provides synchronous access to Monitoring services. * Provides synchronous access to Monitoring services.
*/ */
@Delegate
MonitoringClient getMonitoringServices(); MonitoringClient getMonitoringServices();
/** /**
* Provides synchronous access to Availability Zones and Regions services. * Provides synchronous access to Availability Zones and Regions services.
*/ */
@Delegate
AvailabilityZoneAndRegionClient getAvailabilityZoneAndRegionServices(); AvailabilityZoneAndRegionClient getAvailabilityZoneAndRegionServices();
/** /**
* Provides synchronous access to Elastic Block Store services. * Provides synchronous access to Elastic Block Store services.
*/ */
@Delegate
ElasticBlockStoreClient getElasticBlockStoreServices(); ElasticBlockStoreClient getElasticBlockStoreServices();
/** /**
* Provides synchronous access to Elastic Load Balancer services. * Provides synchronous access to Elastic Load Balancer services.
*/ */
@Delegate
ElasticLoadBalancerClient getElasticLoadBalancerServices(); ElasticLoadBalancerClient getElasticLoadBalancerServices();
} }

View File

@ -30,7 +30,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/** /**
* Creates {@link EC2ComputeServiceContext} or {@link Injector} instances based on the most commonly * Creates {@link EC2ComputeServiceContext} or {@link Injector} instances based on the most commonly
@ -45,12 +44,10 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole * @author Adrian Cole
* @see EC2ComputeServiceContext * @see EC2ComputeServiceContext
*/ */
public class EC2ContextBuilder extends ComputeServiceContextBuilder<EC2AsyncClient, EC2Client> { public class EC2ContextBuilder extends ComputeServiceContextBuilder<EC2Client, EC2AsyncClient> {
public EC2ContextBuilder(String providerName, Properties props) { public EC2ContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<EC2AsyncClient>() { super(providerName, EC2Client.class, EC2AsyncClient.class, props);
}, new TypeLiteral<EC2Client>() {
}, props);
} }
@Override @Override

View File

@ -92,7 +92,7 @@ import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -129,7 +129,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
bind(TemplateOptions.class).to(EC2TemplateOptions.class); bind(TemplateOptions.class).to(EC2TemplateOptions.class);
bind(ComputeService.class).to(EC2ComputeService.class); bind(ComputeService.class).to(EC2ComputeService.class);
bind(new TypeLiteral<ComputeServiceContext>() { bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<EC2AsyncClient, EC2Client>>() { }).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class); bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class);
bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class); bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class);
@ -139,7 +139,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class); bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class); bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() { bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() {
}).annotatedWith(Jsr330.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class) }).annotatedWith(Names.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class)
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
} }
@ -160,7 +160,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides @Provides
@Named("DEFAULT") @Named("DEFAULT")
protected TemplateBuilder provideTemplate(TemplateBuilder template) { protected TemplateBuilder provideTemplate(TemplateBuilder template) {
return template.architecture(Architecture.X86_32).osFamily(UBUNTU).imageNameMatches(".*10\\.?04.*"); return template.architecture(Architecture.X86_32).osFamily(UBUNTU).imageNameMatches(
".*10\\.?04.*");
} }
// TODO make this more efficient for listNodes(); currently RunningInstanceToNodeMetadata is slow // TODO make this more efficient for listNodes(); currently RunningInstanceToNodeMetadata is slow
@ -171,13 +172,13 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final InstanceClient client; private final EC2Client client;
private final Map<String, URI> regionMap; private final Map<String, URI> regionMap;
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata; private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
private final ExecutorService executor; private final ExecutorService executor;
@Inject @Inject
protected EC2ListNodesStrategy(InstanceClient client, @EC2 Map<String, URI> regionMap, protected EC2ListNodesStrategy(EC2Client client, @EC2 Map<String, URI> regionMap,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata, RunningInstanceToNodeMetadata runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = client; this.client = client;
@ -204,7 +205,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
Iterables.addAll(nodes, Iterables.transform(Iterables.concat(client Iterables.addAll(nodes, Iterables.transform(Iterables.concat(client
.describeInstancesInRegion(region)), .getInstanceServices().describeInstancesInRegion(region)),
runningInstanceToNodeMetadata)); runningInstanceToNodeMetadata));
return null; return null;
} }
@ -223,11 +224,11 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Singleton @Singleton
public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy { public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
private final InstanceClient client; private final EC2Client client;
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata; private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
@Inject @Inject
protected EC2GetNodeMetadataStrategy(InstanceClient client, protected EC2GetNodeMetadataStrategy(EC2Client client,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) { RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
this.client = client; this.client = client;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata; this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
@ -239,7 +240,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
String region = parts[0]; String region = parts[0];
String instanceId = parts[1]; String instanceId = parts[1];
RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion( RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion(
client, region, instanceId)); client.getInstanceServices(), region, instanceId));
return runningInstanceToNodeMetadata.apply(runningInstance); return runningInstanceToNodeMetadata.apply(runningInstance);
} }
@ -250,8 +251,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
private final InstanceClient client; private final InstanceClient client;
@Inject @Inject
protected EC2RebootNodeStrategy(InstanceClient client) { protected EC2RebootNodeStrategy(EC2Client client) {
this.client = client; this.client = client.getInstanceServices();
} }
@Override @Override

View File

@ -24,8 +24,8 @@ import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
@ -43,17 +43,17 @@ public final class RegionAndIdToImage implements Function<RegionAndName, Image>
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final ImageParser parser; private final ImageParser parser;
private final AMIClient sync; private final EC2Client sync;
@Inject @Inject
public RegionAndIdToImage(ImageParser parser, AMIClient sync) { public RegionAndIdToImage(ImageParser parser, EC2Client sync) {
this.parser = parser; this.parser = parser;
this.sync = sync; this.sync = sync;
} }
public Image apply(RegionAndName key) { public Image apply(RegionAndName key) {
try { try {
org.jclouds.aws.ec2.domain.Image image = Iterables.getOnlyElement(sync org.jclouds.aws.ec2.domain.Image image = Iterables.getOnlyElement(sync.getAMIServices()
.describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); .describeImagesInRegion(key.getRegion(), imageIds(key.getName())));
return parser.apply(image); return parser.apply(image);
} catch (ResourceNotFoundException e) { } catch (ResourceNotFoundException e) {

View File

@ -33,12 +33,12 @@ import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.options.DescribeImagesOptions; import org.jclouds.aws.ec2.options.DescribeImagesOptions;
import org.jclouds.aws.ec2.services.AMIClient;
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;
@ -118,7 +118,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
.put(InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN, .put(InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN,
NodeState.PENDING).put(InstanceState.TERMINATED, NodeState.TERMINATED).build(); NodeState.PENDING).put(InstanceState.TERMINATED, NodeState.TERMINATED).build();
private final AMIClient amiClient; private final EC2Client client;
private final Map<RegionAndName, KeyPair> credentialsMap; private final Map<RegionAndName, KeyPair> credentialsMap;
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Provider<Set<? extends Image>> images; private final Provider<Set<? extends Image>> images;
@ -128,14 +128,14 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
@Inject @Inject
RunningInstanceToNodeMetadata( RunningInstanceToNodeMetadata(
AMIClient amiClient, EC2Client client,
Map<RegionAndName, KeyPair> credentialsMap, Map<RegionAndName, KeyPair> credentialsMap,
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
Provider<Set<? extends Image>> images, // to facilitate on-demand refresh of image list Provider<Set<? extends Image>> images, // to facilitate on-demand refresh of image list
ConcurrentMap<RegionAndName, Image> imageMap, ConcurrentMap<RegionAndName, Image> imageMap,
Set<? extends Location> locations, Set<? extends Location> locations,
@Named("volumeMapping") Function<RunningInstance, Map<String, String>> instanceToStorageMapping) { @Named("volumeMapping") Function<RunningInstance, Map<String, String>> instanceToStorageMapping) {
this.amiClient = checkNotNull(amiClient, "amiClient"); this.client = checkNotNull(client, "client");
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
@ -267,9 +267,9 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
@VisibleForTesting @VisibleForTesting
String getLoginAccountFor(RunningInstance from) { String getLoginAccountFor(RunningInstance from) {
org.jclouds.aws.ec2.domain.Image image = Iterables.getOnlyElement(amiClient org.jclouds.aws.ec2.domain.Image image = Iterables.getOnlyElement(client.getAMIServices()
.describeImagesInRegion(from.getRegion(), DescribeImagesOptions.Builder .describeImagesInRegion(from.getRegion(),
.imageIds(from.getImageId()))); DescribeImagesOptions.Builder.imageIds(from.getImageId())));
return checkNotNull(credentialProvider.execute(image), "login from image: " return checkNotNull(credentialProvider.execute(image), "login from image: "
+ from.getImageId()).account; + from.getImageId()).account;
} }

View File

@ -28,7 +28,7 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy; import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy;
@ -44,11 +44,11 @@ public class EC2DestroyLoadBalancerStrategy implements DestroyLoadBalancerStrate
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final ElasticLoadBalancerClient elbClient; private final EC2Client client;
@Inject @Inject
protected EC2DestroyLoadBalancerStrategy(ElasticLoadBalancerClient elbClient) { protected EC2DestroyLoadBalancerStrategy(EC2Client client) {
this.elbClient = checkNotNull(elbClient, "elbClient"); this.client = checkNotNull(client, "client");
} }
@Override @Override
@ -56,7 +56,7 @@ public class EC2DestroyLoadBalancerStrategy implements DestroyLoadBalancerStrate
Map<String, String> tuple = EC2Utils.getLoadBalancerNameAndRegionFromDnsName(loadBalancer); Map<String, String> tuple = EC2Utils.getLoadBalancerNameAndRegionFromDnsName(loadBalancer);
// Only one load balancer per DNS name is expected // Only one load balancer per DNS name is expected
for (String key : tuple.keySet()) { for (String key : tuple.keySet()) {
elbClient.deleteLoadBalancerInRegion(key, tuple.get(key)); client.getElasticLoadBalancerServices().deleteLoadBalancerInRegion(key, tuple.get(key));
} }
return true; return true;
} }

View File

@ -35,11 +35,11 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata; import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.options.RunInstancesOptions; import org.jclouds.aws.ec2.options.RunInstancesOptions;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
@ -65,7 +65,7 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@VisibleForTesting @VisibleForTesting
final InstanceClient instanceClient; final EC2Client client;
@VisibleForTesting @VisibleForTesting
final CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions; final CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
@VisibleForTesting @VisibleForTesting
@ -77,11 +77,11 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
@Inject @Inject
EC2RunNodesAndAddToSetStrategy( EC2RunNodesAndAddToSetStrategy(
InstanceClient instanceClient, EC2Client client,
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions, CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions,
@Named("RUNNING") Predicate<RunningInstance> instanceStateRunning, @Named("RUNNING") Predicate<RunningInstance> instanceStateRunning,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata, ComputeUtils utils) { RunningInstanceToNodeMetadata runningInstanceToNodeMetadata, ComputeUtils utils) {
this.instanceClient = instanceClient; this.client = client;
this.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions; this.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
this.instanceStateRunning = instanceStateRunning; this.instanceStateRunning = instanceStateRunning;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata; this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
@ -129,14 +129,16 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count, logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count,
region, zone, template.getImage().getProviderId(), instanceOptions.buildFormParameters()); region, zone, template.getImage().getProviderId(), instanceOptions
.buildFormParameters());
return instanceClient.runInstancesInRegion(region, zone, template.getImage().getProviderId(), 1, return client.getInstanceServices().runInstancesInRegion(region, zone,
count, instanceOptions); template.getImage().getProviderId(), 1, count, instanceOptions);
} }
private Iterable<RunningInstance> getInstances(String region, Iterable<String> ids) { private Iterable<RunningInstance> getInstances(String region, Iterable<String> ids) {
return concat(instanceClient.describeInstancesInRegion(region, toArray(ids, String.class))); return concat(client.getInstanceServices().describeInstancesInRegion(region,
toArray(ids, String.class)));
} }
} }

View File

@ -49,10 +49,10 @@ public class EC2ContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
RestContext<EC2AsyncClient, EC2Client> provideContext(Closer closer, EC2AsyncClient defaultApi, RestContext<EC2Client, EC2AsyncClient> provideContext(Closer closer, EC2AsyncClient defaultApi,
EC2Client synchApi, @EC2 URI endPoint, EC2Client synchApi, @EC2 URI endPoint,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) { @Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
return new RestContextImpl<EC2AsyncClient, EC2Client>(closer, defaultApi, synchApi, endPoint, return new RestContextImpl<EC2Client, EC2AsyncClient>(closer, defaultApi, synchApi, endPoint,
account); account);
} }

View File

@ -28,6 +28,8 @@ import javax.inject.Singleton;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.ELB; import org.jclouds.aws.ec2.ELB;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo; import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
@ -56,7 +58,6 @@ import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
@ -70,13 +71,12 @@ import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -86,7 +86,23 @@ import com.google.inject.Provides;
*/ */
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public class EC2RestClientModule extends AbstractModule { public class EC2RestClientModule extends RestClientModule<EC2Client, EC2AsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap
.<Class<?>, Class<?>> builder()//
.put(AMIClient.class, AMIAsyncClient.class)//
.put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)//
.put(InstanceClient.class, InstanceAsyncClient.class)//
.put(KeyPairClient.class, KeyPairAsyncClient.class)//
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)//
.put(MonitoringClient.class, MonitoringAsyncClient.class)//
.put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)//
.put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)//
.put(ElasticLoadBalancerClient.class, ElasticLoadBalancerAsyncClient.class)//
.build();
public EC2RestClientModule() {
super(EC2Client.class, EC2AsyncClient.class, DELEGATE_MAP);
}
@Provides @Provides
@Singleton @Singleton
@ -110,12 +126,6 @@ public class EC2RestClientModule extends AbstractModule {
return new RetryablePredicate<IPSocket>(open, 130, 1, TimeUnit.SECONDS); return new RetryablePredicate<IPSocket>(open, 130, 1, TimeUnit.SECONDS);
} }
@Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
}
@Provides @Provides
@Singleton @Singleton
@ELB @ELB
@ -152,7 +162,7 @@ public class EC2RestClientModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
@EC2 @EC2
Map<String, URI> provideRegions(AvailabilityZoneAndRegionClient client) { Map<String, URI> provideRegions(EC2Client client) {
// http://code.google.com/p/google-guice/issues/detail?id=483 // http://code.google.com/p/google-guice/issues/detail?id=483
// guice doesn't remember when singleton providers throw exceptions. // guice doesn't remember when singleton providers throw exceptions.
// in this case, if describeRegions fails, it is called again for // in this case, if describeRegions fails, it is called again for
@ -161,7 +171,7 @@ public class EC2RestClientModule extends AbstractModule {
if (regionException != null) if (regionException != null)
throw regionException; throw regionException;
try { try {
return client.describeRegions(); return client.getAvailabilityZoneAndRegionServices().describeRegions();
} catch (RuntimeException e) { } catch (RuntimeException e) {
this.regionException = e; this.regionException = e;
throw e; throw e;
@ -170,11 +180,12 @@ public class EC2RestClientModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
Map<String, String> provideAvailabilityZoneToRegions(AvailabilityZoneAndRegionClient client, Map<String, String> provideAvailabilityZoneToRegions(EC2Client client,
@EC2 Map<String, URI> regions) { @EC2 Map<String, URI> regions) {
Map<String, String> map = Maps.newHashMap(); Map<String, String> map = Maps.newHashMap();
for (String region : regions.keySet()) { for (String region : regions.keySet()) {
for (AvailabilityZoneInfo zoneInfo : client.describeAvailabilityZonesInRegion(region)) { for (AvailabilityZoneInfo zoneInfo : client.getAvailabilityZoneAndRegionServices()
.describeAvailabilityZonesInRegion(region)) {
map.put(zoneInfo.getZone(), region); map.put(zoneInfo.getZone(), region);
} }
} }
@ -195,129 +206,6 @@ public class EC2RestClientModule extends AbstractModule {
return in; return in;
} }
@Provides
@Singleton
protected AMIAsyncClient provideAMIAsyncClient(RestClientFactory factory) {
return factory.create(AMIAsyncClient.class);
}
@Provides
@Singleton
public AMIClient provideAMIClient(AMIAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(AMIClient.class, client);
}
@Provides
@Singleton
protected ElasticIPAddressAsyncClient provideElasticIPAddressAsyncClient(
RestClientFactory factory) {
return factory.create(ElasticIPAddressAsyncClient.class);
}
@Provides
@Singleton
protected ElasticLoadBalancerAsyncClient provideElasticLoadBalancerAsyncClient(
RestClientFactory factory) {
return factory.create(ElasticLoadBalancerAsyncClient.class);
}
@Provides
@Singleton
public ElasticIPAddressClient provideElasticIPAddressClient(ElasticIPAddressAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(ElasticIPAddressClient.class, client);
}
@Provides
@Singleton
protected InstanceAsyncClient provideInstanceAsyncClient(RestClientFactory factory) {
return factory.create(InstanceAsyncClient.class);
}
@Provides
@Singleton
public InstanceClient provideInstanceClient(InstanceAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(InstanceClient.class, client);
}
@Provides
@Singleton
protected KeyPairAsyncClient provideKeyPairAsyncClient(RestClientFactory factory) {
return factory.create(KeyPairAsyncClient.class);
}
@Provides
@Singleton
public KeyPairClient provideKeyPairClient(KeyPairAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(KeyPairClient.class, client);
}
@Provides
@Singleton
protected SecurityGroupAsyncClient provideSecurityGroupAsyncClient(RestClientFactory factory) {
return factory.create(SecurityGroupAsyncClient.class);
}
@Provides
@Singleton
public SecurityGroupClient provideSecurityGroupClient(SecurityGroupAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(SecurityGroupClient.class, client);
}
@Provides
@Singleton
protected MonitoringAsyncClient provideMonitoringAsyncClient(RestClientFactory factory) {
return factory.create(MonitoringAsyncClient.class);
}
@Provides
@Singleton
public MonitoringClient provideMonitoringClient(MonitoringAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(MonitoringClient.class, client);
}
@Provides
@Singleton
protected AvailabilityZoneAndRegionAsyncClient provideAvailabilityZoneAndRegionAsyncClient(
RestClientFactory factory) {
return factory.create(AvailabilityZoneAndRegionAsyncClient.class);
}
@Provides
@Singleton
public AvailabilityZoneAndRegionClient provideAvailabilityZoneAndRegionClient(
AvailabilityZoneAndRegionAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(AvailabilityZoneAndRegionClient.class, client);
}
@Provides
@Singleton
protected ElasticBlockStoreAsyncClient provideElasticBlockStoreAsyncClient(
RestClientFactory factory) {
return factory.create(ElasticBlockStoreAsyncClient.class);
}
@Provides
@Singleton
public ElasticBlockStoreClient provideElasticBlockStoreClient(ElasticBlockStoreAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(ElasticBlockStoreClient.class, client);
}
@Provides
@Singleton
public ElasticLoadBalancerClient provideElasticLoadBalancerClient(
ElasticLoadBalancerAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(ElasticLoadBalancerClient.class, client);
}
@Provides @Provides
@Singleton @Singleton
@EC2 @EC2
@ -325,6 +213,7 @@ public class EC2RestClientModule extends AbstractModule {
return URI.create(endpoint); return URI.create(endpoint);
} }
@Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class); ParseAWSErrorFromXmlContent.class);
@ -334,6 +223,7 @@ public class EC2RestClientModule extends AbstractModule {
ParseAWSErrorFromXmlContent.class); ParseAWSErrorFromXmlContent.class);
} }
@Override
protected void bindRetryHandlers() { protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to( bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class); AWSRedirectionRetryHandler.class);

View File

@ -1,150 +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.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.services.AMIAsyncClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerAsyncClient;
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
/**
*
* @author Adrian Cole
*/
@Singleton
public class EC2AsyncClientImpl implements EC2AsyncClient {
private final AMIAsyncClient AMIServices;
private final ElasticIPAddressAsyncClient elasticIPAddressServices;
private final InstanceAsyncClient instanceServices;
private final KeyPairAsyncClient keyPairServices;
private final SecurityGroupAsyncClient securityGroupServices;
private final MonitoringAsyncClient monitoringServices;
private final AvailabilityZoneAndRegionAsyncClient availabilityZoneAndRegionServices;
private final ElasticBlockStoreAsyncClient elasticBlockStoreServices;
private final ElasticLoadBalancerAsyncClient elasticLoadBalancerAsyncClient;
@Inject
public EC2AsyncClientImpl(AMIAsyncClient AMIServices,
ElasticIPAddressAsyncClient elasticIPAddressServices,
InstanceAsyncClient instanceServices, KeyPairAsyncClient keyPairServices,
SecurityGroupAsyncClient securityGroupServices,
MonitoringAsyncClient monitoringServices,
AvailabilityZoneAndRegionAsyncClient availabilityZoneAndRegionServices,
ElasticBlockStoreAsyncClient elasticBlockStoreServices,
ElasticLoadBalancerAsyncClient elasticLoadBalancerAsyncClient) {
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
"elasticIPAddressServices");
this.instanceServices = checkNotNull(instanceServices, "instanceServices");
this.keyPairServices = checkNotNull(keyPairServices, "keyPairServices");
this.securityGroupServices = checkNotNull(securityGroupServices, "securityGroupServices");
this.monitoringServices = checkNotNull(monitoringServices, "monitoringServices");
this.availabilityZoneAndRegionServices = checkNotNull(availabilityZoneAndRegionServices,
"availabilityZoneAndRegionServices");
this.elasticBlockStoreServices = checkNotNull(elasticBlockStoreServices,
"elasticBlockStoreServices");
this.elasticLoadBalancerAsyncClient = checkNotNull(elasticLoadBalancerAsyncClient,
"elasticLoadBalancerAsyncClient");
}
/**
* {@inheritDoc}
*/
@Override
public AMIAsyncClient getAMIServices() {
return AMIServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticIPAddressAsyncClient getElasticIPAddressServices() {
return elasticIPAddressServices;
}
/**
* {@inheritDoc}
*/
@Override
public InstanceAsyncClient getInstanceServices() {
return instanceServices;
}
/**
* {@inheritDoc}
*/
@Override
public KeyPairAsyncClient getKeyPairServices() {
return keyPairServices;
}
/**
* {@inheritDoc}
*/
@Override
public SecurityGroupAsyncClient getSecurityGroupServices() {
return securityGroupServices;
}
/**
* {@inheritDoc}
*/
@Override
public MonitoringAsyncClient getMonitoringServices() {
return monitoringServices;
}
/**
* {@inheritDoc}
*/
@Override
public AvailabilityZoneAndRegionAsyncClient getAvailabilityZoneAndRegionServices() {
return availabilityZoneAndRegionServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticBlockStoreAsyncClient getElasticBlockStoreServices() {
return elasticBlockStoreServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticLoadBalancerAsyncClient getElasticLoadBalancerServices() {
return elasticLoadBalancerAsyncClient;
}
}

View File

@ -1,148 +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.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.aws.ec2.services.KeyPairClient;
import org.jclouds.aws.ec2.services.MonitoringClient;
import org.jclouds.aws.ec2.services.SecurityGroupClient;
/**
*
* @author Adrian Cole
*/
@Singleton
public class EC2ClientImpl implements EC2Client {
private final AMIClient AMIServices;
private final ElasticIPAddressClient elasticIPAddressServices;
private final InstanceClient instanceServices;
private final KeyPairClient keyPairServices;
private final SecurityGroupClient securityGroupServices;
private final MonitoringClient monitoringServices;
private final AvailabilityZoneAndRegionClient availabilityZoneAndRegionServices;
private final ElasticBlockStoreClient elasticBlockStoreServices;
private final ElasticLoadBalancerClient elasticLoadBalancerClient;
@Inject
public EC2ClientImpl(AMIClient AMIServices, ElasticIPAddressClient elasticIPAddressServices,
InstanceClient instanceServices, KeyPairClient keyPairServices,
SecurityGroupClient securityGroupServices, MonitoringClient monitoringServices,
AvailabilityZoneAndRegionClient availabilityZoneAndRegionServices,
ElasticBlockStoreClient elasticBlockStoreServices,
ElasticLoadBalancerClient elasticLoadBalancerClient) {
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
"elasticIPAddressServices");
this.instanceServices = checkNotNull(instanceServices, "instanceServices");
this.keyPairServices = checkNotNull(keyPairServices, "keyPairServices");
this.securityGroupServices = checkNotNull(securityGroupServices, "securityGroupServices");
this.monitoringServices = checkNotNull(monitoringServices, "monitoringServices");
this.availabilityZoneAndRegionServices = checkNotNull(availabilityZoneAndRegionServices,
"availabilityZoneAndRegionServices");
this.elasticBlockStoreServices = checkNotNull(elasticBlockStoreServices,
"elasticBlockStoreServices");
this.elasticLoadBalancerClient = checkNotNull(elasticLoadBalancerClient,
"elasticLoadBalancerClient");
}
/**
* {@inheritDoc}
*/
@Override
public AMIClient getAMIServices() {
return AMIServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticIPAddressClient getElasticIPAddressServices() {
return elasticIPAddressServices;
}
/**
* {@inheritDoc}
*/
@Override
public InstanceClient getInstanceServices() {
return instanceServices;
}
/**
* {@inheritDoc}
*/
@Override
public KeyPairClient getKeyPairServices() {
return keyPairServices;
}
/**
* {@inheritDoc}
*/
@Override
public SecurityGroupClient getSecurityGroupServices() {
return securityGroupServices;
}
/**
* {@inheritDoc}
*/
@Override
public MonitoringClient getMonitoringServices() {
return monitoringServices;
}
/**
* {@inheritDoc}
*/
@Override
public AvailabilityZoneAndRegionClient getAvailabilityZoneAndRegionServices() {
return availabilityZoneAndRegionServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticBlockStoreClient getElasticBlockStoreServices() {
return elasticBlockStoreServices;
}
/**
* {@inheritDoc}
*/
@Override
public ElasticLoadBalancerClient getElasticLoadBalancerServices() {
return elasticLoadBalancerClient;
}
}

View File

@ -22,8 +22,8 @@ import javax.annotation.Resource;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -39,13 +39,13 @@ import com.google.inject.Inject;
@Singleton @Singleton
public class InstanceHasIpAddress implements Predicate<RunningInstance> { public class InstanceHasIpAddress implements Predicate<RunningInstance> {
private final InstanceClient client; private final EC2Client client;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject @Inject
public InstanceHasIpAddress(InstanceClient client) { public InstanceHasIpAddress(EC2Client client) {
this.client = client; this.client = client;
} }
@ -62,7 +62,7 @@ public class InstanceHasIpAddress implements Predicate<RunningInstance> {
} }
private RunningInstance refresh(RunningInstance instance) { private RunningInstance refresh(RunningInstance instance) {
return Iterables.getOnlyElement(Iterables.getOnlyElement(client.describeInstancesInRegion( return Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices()
instance.getRegion(), instance.getId()))); .describeInstancesInRegion(instance.getRegion(), instance.getId())));
} }
} }

View File

@ -22,9 +22,9 @@ import javax.annotation.Resource;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -40,13 +40,13 @@ import com.google.inject.Inject;
@Singleton @Singleton
public class InstanceStateRunning implements Predicate<RunningInstance> { public class InstanceStateRunning implements Predicate<RunningInstance> {
private final InstanceClient client; private final EC2Client client;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject @Inject
public InstanceStateRunning(InstanceClient client) { public InstanceStateRunning(EC2Client client) {
this.client = client; this.client = client;
} }
@ -65,7 +65,7 @@ public class InstanceStateRunning implements Predicate<RunningInstance> {
} }
private RunningInstance refresh(RunningInstance instance) { private RunningInstance refresh(RunningInstance instance) {
return Iterables.getOnlyElement(Iterables.getOnlyElement(client.describeInstancesInRegion( return Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices()
instance.getRegion(), instance.getId()))); .describeInstancesInRegion(instance.getRegion(), instance.getId())));
} }
} }

View File

@ -23,9 +23,9 @@ import java.util.NoSuchElementException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -41,13 +41,13 @@ import com.google.inject.Inject;
@Singleton @Singleton
public class InstanceStateTerminated implements Predicate<RunningInstance> { public class InstanceStateTerminated implements Predicate<RunningInstance> {
private final InstanceClient client; private final EC2Client client;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject @Inject
public InstanceStateTerminated(InstanceClient client) { public InstanceStateTerminated(EC2Client client) {
this.client = client; this.client = client;
} }
@ -64,7 +64,7 @@ public class InstanceStateTerminated implements Predicate<RunningInstance> {
} }
private RunningInstance refresh(RunningInstance instance) { private RunningInstance refresh(RunningInstance instance) {
return Iterables.getOnlyElement(Iterables.getOnlyElement(client.describeInstancesInRegion( return Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices()
instance.getRegion(), instance.getId()))); .describeInstancesInRegion(instance.getRegion(), instance.getId())));
} }
} }

View File

@ -29,7 +29,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/** /**
* Creates {@link S3Context} or {@link Injector} instances based on the most commonly requested * Creates {@link S3Context} or {@link Injector} instances based on the most commonly requested
@ -44,16 +43,14 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole, Andrew Newdigate * @author Adrian Cole, Andrew Newdigate
* @see S3Context * @see S3Context
*/ */
public class S3ContextBuilder extends BlobStoreContextBuilder<S3AsyncClient, S3Client> { public class S3ContextBuilder extends BlobStoreContextBuilder<S3Client, S3AsyncClient> {
public S3ContextBuilder(String providerName, Properties props) { public S3ContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<S3AsyncClient>() { super(providerName, S3Client.class, S3AsyncClient.class, props);
}, new TypeLiteral<S3Client>() {
}, props);
} }
@Override @Override
protected void addContextModule(String providerName,List<Module> modules) { protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new S3BlobStoreContextModule(providerName)); modules.add(new S3BlobStoreContextModule(providerName));
} }

View File

@ -65,7 +65,7 @@ public class S3BlobStoreContextModule extends S3ContextModule {
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON); bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class).to( bind(BlobStoreContext.class).to(
new TypeLiteral<BlobStoreContextImpl<S3AsyncClient, S3Client>>() { new TypeLiteral<BlobStoreContextImpl<S3Client, S3AsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
} }

View File

@ -27,14 +27,12 @@ import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.aws.s3.S3; import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl; 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,19 +43,14 @@ public class S3ContextModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
// for converters
install(new BlobStoreObjectModule<S3AsyncClient, S3Client>(new TypeLiteral<S3AsyncClient>() {
}, new TypeLiteral<S3Client>() {
}));
install(new S3ObjectModule());
} }
@Provides @Provides
@Singleton @Singleton
RestContext<S3AsyncClient, S3Client> provideContext(Closer closer, S3AsyncClient defaultApi, RestContext<S3Client, S3AsyncClient> provideContext(Closer closer, S3AsyncClient defaultApi,
S3Client syncApi, @S3 URI endPoint, S3Client syncApi, @S3 URI endPoint,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) { @Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
return new RestContextImpl<S3AsyncClient, S3Client>(closer, defaultApi, syncApi, endPoint, return new RestContextImpl<S3Client, S3AsyncClient>(closer, defaultApi, syncApi, endPoint,
account); account);
} }

View File

@ -24,11 +24,11 @@ import javax.inject.Provider;
import org.jclouds.aws.s3.domain.MutableObjectMetadata; import org.jclouds.aws.s3.domain.MutableObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.domain.internal.S3ObjectImpl; import org.jclouds.aws.s3.domain.internal.S3ObjectImpl;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.encryption.EncryptionService; 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;
/** /**
* Configures the domain object mappings needed for all S3 implementations * Configures the domain object mappings needed for all S3 implementations
@ -43,7 +43,9 @@ public class S3ObjectModule extends AbstractModule {
*/ */
@Override @Override
protected void configure() { protected void configure() {
bind(S3Object.Factory.class).to(S3ObjectFactory.class).in(Scopes.SINGLETON); // for converters
install(new BlobStoreObjectModule());
bind(S3Object.Factory.class).to(S3ObjectFactory.class).asEagerSingleton();
} }
private static class S3ObjectFactory implements S3Object.Factory { private static class S3ObjectFactory implements S3Object.Factory {

View File

@ -36,7 +36,6 @@ import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.filters.RequestAuthorizeSignature; import org.jclouds.aws.s3.filters.RequestAuthorizeSignature;
import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.reference.S3Constants;
import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
@ -47,12 +46,11 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
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;
@ -63,7 +61,17 @@ import com.google.inject.Scopes;
*/ */
@ConfiguresRestClient @ConfiguresRestClient
@RequiresHttp @RequiresHttp
public class S3RestClientModule extends AbstractModule { public class S3RestClientModule extends RestClientModule<S3Client, S3AsyncClient> {
public S3RestClientModule() {
super(S3Client.class, S3AsyncClient.class);
}
@Override
protected void configure() {
install(new S3ObjectModule());
bind(RequestAuthorizeSignature.class).in(Scopes.SINGLETON);
super.configure();
}
@Provides @Provides
@TimeStamp @TimeStamp
@ -92,13 +100,6 @@ public class S3RestClientModule extends AbstractModule {
}, seconds, TimeUnit.SECONDS); }, seconds, TimeUnit.SECONDS);
} }
@Override
protected void configure() {
bind(RequestAuthorizeSignature.class).in(Scopes.SINGLETON);
bindErrorHandlers();
bindRetryHandlers();
}
@Provides @Provides
@Singleton @Singleton
@S3 @S3
@ -133,19 +134,7 @@ public class S3RestClientModule extends AbstractModule {
return ImmutableBiMap.<String, URI> builder().putAll(map).build().inverse().get(uri); return ImmutableBiMap.<String, URI> builder().putAll(map).build().inverse().get(uri);
} }
@Provides @Override
@Singleton
protected S3AsyncClient provideAsyncClient(RestClientFactory factory) {
return factory.create(S3AsyncClient.class);
}
@Provides
@Singleton
public S3Client provideClient(S3AsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(S3Client.class, client);
}
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class); ParseAWSErrorFromXmlContent.class);
@ -155,6 +144,7 @@ public class S3RestClientModule extends AbstractModule {
ParseAWSErrorFromXmlContent.class); ParseAWSErrorFromXmlContent.class);
} }
@Override
protected void bindRetryHandlers() { protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to( bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class); AWSRedirectionRetryHandler.class);

View File

@ -29,7 +29,6 @@ import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/** /**
* Creates {@link SQSContext} or {@link Injector} instances based on the most commonly requested * Creates {@link SQSContext} or {@link Injector} instances based on the most commonly requested
@ -44,12 +43,10 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole * @author Adrian Cole
* @see SQSContext * @see SQSContext
*/ */
public class SQSContextBuilder extends RestContextBuilder<SQSAsyncClient, SQSClient> { public class SQSContextBuilder extends RestContextBuilder<SQSClient, SQSAsyncClient> {
public SQSContextBuilder(String providerName, Properties props) { public SQSContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<SQSAsyncClient>() { super(providerName, SQSClient.class, SQSAsyncClient.class, props);
}, new TypeLiteral<SQSClient>() {
}, props);
} }
@Override @Override

View File

@ -41,25 +41,25 @@ import com.google.inject.Module;
*/ */
public class SQSContextFactory { public class SQSContextFactory {
public static RestContext<SQSAsyncClient, SQSClient> createContext(Properties properties, public static RestContext<SQSClient, SQSAsyncClient> createContext(Properties properties,
Module... modules) { Module... modules) {
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(properties).build()) return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(properties).build())
.withModules(modules).buildContext(); .withModules(modules).buildContext();
} }
public static RestContext<SQSAsyncClient, SQSClient> createContext(Properties properties, public static RestContext<SQSClient, SQSAsyncClient> createContext(Properties properties,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(properties).withCredentials( return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext(); awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext();
} }
public static RestContext<SQSAsyncClient, SQSClient> createContext(String awsAccessKeyId, public static RestContext<SQSClient, SQSAsyncClient> createContext(String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) { String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(awsAccessKeyId, return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildContext(); awsSecretAccessKey).build()).withModules(modules).buildContext();
} }
public static RestContext<SQSAsyncClient, SQSClient> createContext(URI endpoint, public static RestContext<SQSClient, SQSAsyncClient> createContext(URI endpoint,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) { String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(awsAccessKeyId, return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules) awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)

View File

@ -52,10 +52,10 @@ public class SQSContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
RestContext<SQSAsyncClient, SQSClient> provideContext(Closer closer, SQSAsyncClient defaultApi, RestContext<SQSClient, SQSAsyncClient> provideContext(Closer closer, SQSAsyncClient defaultApi,
SQSClient synchApi, @SQS URI endPoint, SQSClient synchApi, @SQS URI endPoint,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) { @Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
return new RestContextImpl<SQSAsyncClient, SQSClient>(closer, defaultApi, synchApi, endPoint, return new RestContextImpl<SQSClient, SQSAsyncClient>(closer, defaultApi, synchApi, endPoint,
account); account);
} }

View File

@ -34,7 +34,6 @@ import org.jclouds.aws.sqs.SQS;
import org.jclouds.aws.sqs.SQSAsyncClient; import org.jclouds.aws.sqs.SQSAsyncClient;
import org.jclouds.aws.sqs.SQSClient; import org.jclouds.aws.sqs.SQSClient;
import org.jclouds.aws.sqs.reference.SQSConstants; import org.jclouds.aws.sqs.reference.SQSConstants;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
@ -45,11 +44,10 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -59,12 +57,10 @@ import com.google.inject.Provides;
*/ */
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public class SQSRestClientModule extends AbstractModule { public class SQSRestClientModule extends RestClientModule<SQSClient, SQSAsyncClient> {
@Override public SQSRestClientModule() {
protected void configure() { super(SQSClient.class, SQSAsyncClient.class);
bindErrorHandlers();
bindRetryHandlers();
} }
@Provides @Provides
@ -75,19 +71,6 @@ public class SQSRestClientModule extends AbstractModule {
+ (expiration * 1000))); + (expiration * 1000)));
} }
@Provides
@Singleton
protected SQSAsyncClient provideAsyncClient(RestClientFactory factory) {
return factory.create(SQSAsyncClient.class);
}
@Provides
@Singleton
public SQSClient provideClient(SQSAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(SQSClient.class, client);
}
@Provides @Provides
@Singleton @Singleton
@SQS @SQS
@ -121,6 +104,7 @@ public class SQSRestClientModule extends AbstractModule {
return in; return in;
} }
@Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class); ParseAWSErrorFromXmlContent.class);
@ -130,6 +114,7 @@ public class SQSRestClientModule extends AbstractModule {
ParseAWSErrorFromXmlContent.class); ParseAWSErrorFromXmlContent.class);
} }
@Override
protected void bindRetryHandlers() { protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to( bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class); AWSRedirectionRetryHandler.class);

View File

@ -97,10 +97,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
.buildInjector(); .buildInjector();
client = injector.getInstance(EC2Client.class); client = injector.getInstance(EC2Client.class);
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client),
.getInstanceServices()), 180, 5, TimeUnit.SECONDS); 180, 5, TimeUnit.SECONDS);
hasIpTester = new RetryablePredicate<RunningInstance>(new InstanceHasIpAddress(client hasIpTester = new RetryablePredicate<RunningInstance>(new InstanceHasIpAddress(client), 180, 5, TimeUnit.SECONDS);
.getInstanceServices()), 180, 5, TimeUnit.SECONDS);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 180, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<IPSocket>(socketOpen, 180, 1, TimeUnit.SECONDS);
} }

View File

@ -136,8 +136,8 @@ public class EBSBootEC2ClientLiveTest {
VolumeAttached volumeAttached = injector.getInstance(VolumeAttached.class); VolumeAttached volumeAttached = injector.getInstance(VolumeAttached.class);
attachTester = new RetryablePredicate<Attachment>(volumeAttached, 60, 1, TimeUnit.SECONDS); attachTester = new RetryablePredicate<Attachment>(volumeAttached, 60, 1, TimeUnit.SECONDS);
runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client),
.getInstanceServices()), 180, 5, TimeUnit.SECONDS); 180, 5, TimeUnit.SECONDS);
InstanceStateStopped instanceStateStopped = injector.getInstance(InstanceStateStopped.class); InstanceStateStopped instanceStateStopped = injector.getInstance(InstanceStateStopped.class);
stoppedTester = new RetryablePredicate<RunningInstance>(instanceStateStopped, 60, 1, stoppedTester = new RetryablePredicate<RunningInstance>(instanceStateStopped, 60, 1,
@ -272,8 +272,8 @@ public class EBSBootEC2ClientLiveTest {
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") @Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume")
void testBundleInstance() { void testBundleInstance() {
SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), "ubuntu",
"ubuntu", keyPair.getKeyMaterial().getBytes()); keyPair.getKeyMaterial().getBytes());
try { try {
ssh.connect(); ssh.connect();
} catch (SshException e) {// try twice in case there is a network timeout } catch (SshException e) {// try twice in case there is a network timeout

View File

@ -0,0 +1,91 @@
package org.jclouds.aws.ec2;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import org.jclouds.date.DateService;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.inject.name.Names;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code EC2Client}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.EC2ClientTest")
public class EC2AsyncClientTest extends RestClientTest<EC2AsyncClient> {
private EC2AsyncClient asyncClient;
private EC2Client syncClient;
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException,
ExecutionException {
assert syncClient.getAMIServices() != null;
assert syncClient.getAvailabilityZoneAndRegionServices() != null;
assert syncClient.getElasticBlockStoreServices() != null;
assert syncClient.getElasticIPAddressServices() != null;
assert syncClient.getElasticLoadBalancerServices() != null;
assert syncClient.getInstanceServices() != null;
assert syncClient.getKeyPairServices() != null;
assert syncClient.getMonitoringServices() != null;
assert syncClient.getSecurityGroupServices() != null;
}
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException,
ExecutionException {
assert asyncClient.getAMIServices() != null;
assert asyncClient.getAvailabilityZoneAndRegionServices() != null;
assert asyncClient.getElasticBlockStoreServices() != null;
assert asyncClient.getElasticIPAddressServices() != null;
assert asyncClient.getElasticLoadBalancerServices() != null;
assert asyncClient.getInstanceServices() != null;
assert asyncClient.getKeyPairServices() != null;
assert asyncClient.getMonitoringServices() != null;
assert asyncClient.getSecurityGroupServices() != null;
}
@Override
protected TypeLiteral<RestAnnotationProcessor<EC2AsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<EC2AsyncClient>>() {
};
}
@BeforeClass
@Override
protected void setupFactory() {
super.setupFactory();
asyncClient = injector.getInstance(EC2AsyncClient.class);
syncClient = injector.getInstance(EC2Client.class);
}
@Override
protected Module createModule() {
return new org.jclouds.aws.ec2.config.EC2RestClientModule() {
@Override
protected void configure() {
Names.bindProperties(binder(), new EC2PropertiesBuilder(new Properties())
.withCredentials("user", "key").build());
install(new NullLoggingModule());
super.configure();
}
@Override
protected String provideTimeStamp(DateService dateService, int expiration) {
return "2009-11-08T15:54:08.897Z";
}
};
}
@Override
protected void checkFilters(GeneratedHttpRequest<EC2AsyncClient> httpMethod) {
}
}

View File

@ -68,7 +68,7 @@ public class EC2TemplateBuilderLiveTest {
Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); Template defaultTemplate = newContext.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
assertEquals(defaultTemplate.getImage().getName(), "9.10"); assertEquals(defaultTemplate.getImage().getName(), "10.04");
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_32); assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_32);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1"); assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");

View File

@ -28,6 +28,7 @@ import static org.testng.Assert.assertEquals;
import java.util.Set; import java.util.Set;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.services.AMIClient; import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
@ -46,23 +47,27 @@ public class RegionAndIdToImageTest {
public void testApply() { public void testApply() {
ImageParser parser = createMock(ImageParser.class); ImageParser parser = createMock(ImageParser.class);
EC2Client caller = createMock(EC2Client.class);
AMIClient client = createMock(AMIClient.class); AMIClient client = createMock(AMIClient.class);
org.jclouds.aws.ec2.domain.Image ec2Image = createMock(org.jclouds.aws.ec2.domain.Image.class); org.jclouds.aws.ec2.domain.Image ec2Image = createMock(org.jclouds.aws.ec2.domain.Image.class);
Image image = createNiceMock(Image.class); Image image = createNiceMock(Image.class);
Set<org.jclouds.aws.ec2.domain.Image> images = ImmutableSet Set<org.jclouds.aws.ec2.domain.Image> images = ImmutableSet
.<org.jclouds.aws.ec2.domain.Image> of(ec2Image); .<org.jclouds.aws.ec2.domain.Image> of(ec2Image);
expect(caller.getAMIServices()).andReturn(client).atLeastOnce();
expect(client.describeImagesInRegion("region", imageIds("ami"))).andReturn(images); expect(client.describeImagesInRegion("region", imageIds("ami"))).andReturn(images);
expect(parser.apply(ec2Image)).andReturn(image); expect(parser.apply(ec2Image)).andReturn(image);
replay(caller);
replay(image); replay(image);
replay(parser); replay(parser);
replay(client); replay(client);
RegionAndIdToImage function = new RegionAndIdToImage(parser, client); RegionAndIdToImage function = new RegionAndIdToImage(parser, caller);
assertEquals(function.apply(new RegionAndName("region", "ami")), image); assertEquals(function.apply(new RegionAndName("region", "ami")), image);
verify(caller);
verify(image); verify(image);
verify(parser); verify(parser);
verify(client); verify(client);
@ -73,23 +78,27 @@ public class RegionAndIdToImageTest {
public void testApplyNotFound() { public void testApplyNotFound() {
ImageParser parser = createMock(ImageParser.class); ImageParser parser = createMock(ImageParser.class);
EC2Client caller = createMock(EC2Client.class);
AMIClient client = createMock(AMIClient.class); AMIClient client = createMock(AMIClient.class);
org.jclouds.aws.ec2.domain.Image ec2Image = createMock(org.jclouds.aws.ec2.domain.Image.class); org.jclouds.aws.ec2.domain.Image ec2Image = createMock(org.jclouds.aws.ec2.domain.Image.class);
Image image = createNiceMock(Image.class); Image image = createNiceMock(Image.class);
Set<org.jclouds.aws.ec2.domain.Image> images = ImmutableSet Set<org.jclouds.aws.ec2.domain.Image> images = ImmutableSet
.<org.jclouds.aws.ec2.domain.Image> of(ec2Image); .<org.jclouds.aws.ec2.domain.Image> of(ec2Image);
expect(caller.getAMIServices()).andReturn(client).atLeastOnce();
expect(client.describeImagesInRegion("region", imageIds("ami"))).andReturn(images); expect(client.describeImagesInRegion("region", imageIds("ami"))).andReturn(images);
expect(parser.apply(ec2Image)).andThrow(new ResourceNotFoundException()); expect(parser.apply(ec2Image)).andThrow(new ResourceNotFoundException());
replay(caller);
replay(image); replay(image);
replay(parser); replay(parser);
replay(client); replay(client);
RegionAndIdToImage function = new RegionAndIdToImage(parser, client); RegionAndIdToImage function = new RegionAndIdToImage(parser, caller);
assertEquals(function.apply(new RegionAndName("region", "ami")), null); assertEquals(function.apply(new RegionAndName("region", "ami")), null);
verify(caller);
verify(image); verify(image);
verify(parser); verify(parser);
verify(client); verify(client);

View File

@ -33,6 +33,7 @@ import java.util.concurrent.ConcurrentMap;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.Image;
@ -74,7 +75,9 @@ public class RunningInstanceToNodeMetadataTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testImageNotFoundAndLazyReturnsNull() throws UnknownHostException { public void testImageNotFoundAndLazyReturnsNull() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
@ -105,12 +108,13 @@ public class RunningInstanceToNodeMetadataTest {
replay(imageMap); replay(imageMap);
replay(jcImage); replay(jcImage);
replay(client);
replay(amiClient); replay(amiClient);
replay(credentialsMap); replay(credentialsMap);
replay(credentialProvider); replay(credentialProvider);
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client,
credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations, credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations,
new RunningInstanceToStorageMappingUnix()); new RunningInstanceToStorageMappingUnix());
@ -122,6 +126,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(imageMap); verify(imageMap);
verify(jcImage); verify(jcImage);
verify(client);
verify(amiClient); verify(amiClient);
verify(credentialsMap); verify(credentialsMap);
verify(credentialProvider); verify(credentialProvider);
@ -131,6 +136,7 @@ public class RunningInstanceToNodeMetadataTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testImageNotFoundAndLazyFailsWithNPE() throws UnknownHostException { public void testImageNotFoundAndLazyFailsWithNPE() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
@ -163,12 +169,13 @@ public class RunningInstanceToNodeMetadataTest {
replay(imageMap); replay(imageMap);
replay(jcImage); replay(jcImage);
replay(client);
replay(amiClient); replay(amiClient);
replay(credentialsMap); replay(credentialsMap);
replay(credentialProvider); replay(credentialProvider);
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client,
credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations, credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations,
new RunningInstanceToStorageMappingUnix()); new RunningInstanceToStorageMappingUnix());
@ -180,6 +187,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(imageMap); verify(imageMap);
verify(jcImage); verify(jcImage);
verify(client);
verify(amiClient); verify(amiClient);
verify(credentialsMap); verify(credentialsMap);
verify(credentialProvider); verify(credentialProvider);
@ -189,6 +197,7 @@ public class RunningInstanceToNodeMetadataTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testImageNotFoundAndLazySucceeds() throws UnknownHostException { public void testImageNotFoundAndLazySucceeds() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
@ -224,12 +233,13 @@ public class RunningInstanceToNodeMetadataTest {
replay(lateImage); replay(lateImage);
replay(imageMap); replay(imageMap);
replay(jcImage); replay(jcImage);
replay(client);
replay(amiClient); replay(amiClient);
replay(credentialsMap); replay(credentialsMap);
replay(credentialProvider); replay(credentialProvider);
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client,
credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations, credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations,
new RunningInstanceToStorageMappingUnix()); new RunningInstanceToStorageMappingUnix());
@ -242,6 +252,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(lateImage); verify(lateImage);
verify(imageMap); verify(imageMap);
verify(jcImage); verify(jcImage);
verify(client);
verify(amiClient); verify(amiClient);
verify(credentialsMap); verify(credentialsMap);
verify(credentialProvider); verify(credentialProvider);
@ -252,6 +263,7 @@ public class RunningInstanceToNodeMetadataTest {
@Test @Test
public void testApplyWithNoSecurityGroupCreatesTagOfIdPrefixedByTagAndNullCredentials() public void testApplyWithNoSecurityGroupCreatesTagOfIdPrefixedByTagAndNullCredentials()
throws UnknownHostException { throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
@ -282,12 +294,13 @@ public class RunningInstanceToNodeMetadataTest {
replay(imageMap); replay(imageMap);
replay(jcImage); replay(jcImage);
replay(client);
replay(amiClient); replay(amiClient);
replay(credentialsMap); replay(credentialsMap);
replay(credentialProvider); replay(credentialProvider);
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client,
credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations, credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations,
new RunningInstanceToStorageMappingUnix()); new RunningInstanceToStorageMappingUnix());
@ -299,6 +312,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(imageMap); verify(imageMap);
verify(jcImage); verify(jcImage);
verify(client);
verify(amiClient); verify(amiClient);
verify(credentialsMap); verify(credentialsMap);
verify(credentialProvider); verify(credentialProvider);
@ -309,6 +323,7 @@ public class RunningInstanceToNodeMetadataTest {
@Test @Test
public void testApplyWithNoKeyPairCreatesTagOfParsedSecurityGroupAndNullCredentials() public void testApplyWithNoKeyPairCreatesTagOfParsedSecurityGroupAndNullCredentials()
throws UnknownHostException { throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
@ -338,12 +353,13 @@ public class RunningInstanceToNodeMetadataTest {
replay(imageMap); replay(imageMap);
replay(jcImage); replay(jcImage);
replay(client);
replay(amiClient); replay(amiClient);
replay(credentialsMap); replay(credentialsMap);
replay(credentialProvider); replay(credentialProvider);
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client,
credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations, credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations,
new RunningInstanceToStorageMappingUnix()); new RunningInstanceToStorageMappingUnix());
@ -355,6 +371,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(imageMap); verify(imageMap);
verify(jcImage); verify(jcImage);
verify(client);
verify(amiClient); verify(amiClient);
verify(credentialsMap); verify(credentialsMap);
verify(credentialProvider); verify(credentialProvider);
@ -365,7 +382,9 @@ public class RunningInstanceToNodeMetadataTest {
@Test @Test
public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt()
throws UnknownHostException { throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
@ -404,13 +423,14 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
replay(imageMap); replay(imageMap);
replay(client);
replay(amiClient); replay(amiClient);
replay(credentialsMap); replay(credentialsMap);
replay(credentialProvider); replay(credentialProvider);
replay(instance); replay(instance);
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client,
credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations, credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations,
new RunningInstanceToStorageMappingUnix()); new RunningInstanceToStorageMappingUnix());
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
@ -423,6 +443,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(imageMap); verify(imageMap);
verify(jcImage); verify(jcImage);
verify(client);
verify(amiClient); verify(amiClient);
verify(credentialsMap); verify(credentialsMap);
verify(credentialProvider); verify(credentialProvider);
@ -433,7 +454,9 @@ public class RunningInstanceToNodeMetadataTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testApplyWithTwoSecurityGroups() throws UnknownHostException { public void testApplyWithTwoSecurityGroups() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
@ -473,13 +496,14 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
replay(imageMap); replay(imageMap);
replay(client);
replay(amiClient); replay(amiClient);
replay(credentialsMap); replay(credentialsMap);
replay(credentialProvider); replay(credentialProvider);
replay(instance); replay(instance);
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client,
credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations, credentialsMap, credentialProvider, new ImageProvider(jcImage), imageMap, locations,
new RunningInstanceToStorageMappingUnix()); new RunningInstanceToStorageMappingUnix());
@ -493,6 +517,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(imageMap); verify(imageMap);
verify(jcImage); verify(jcImage);
verify(client);
verify(amiClient); verify(amiClient);
verify(credentialsMap); verify(credentialsMap);
verify(credentialProvider); verify(credentialProvider);

View File

@ -30,6 +30,7 @@ import java.util.Set;
import org.easymock.IArgumentMatcher; import org.easymock.IArgumentMatcher;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.EC2Size; import org.jclouds.aws.ec2.compute.domain.EC2Size;
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata; import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
@ -95,6 +96,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
// setup mocks // setup mocks
EC2RunNodesAndAddToSetStrategy strategy = setupStrategy(); EC2RunNodesAndAddToSetStrategy strategy = setupStrategy();
InputParams input = new InputParams(location); InputParams input = new InputParams(location);
InstanceClient instanceClient = createMock(InstanceClient.class);
RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class); RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Reservation reservation = new Reservation(region, ImmutableSet.<String> of(), ImmutableSet Reservation reservation = new Reservation(region, ImmutableSet.<String> of(), ImmutableSet
@ -102,19 +104,19 @@ public class EC2RunNodesAndAddToSetStrategyTest {
NodeMetadata nodeMetadata = createMock(NodeMetadata.class); NodeMetadata nodeMetadata = createMock(NodeMetadata.class);
// setup expectations // setup expectations
expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
expect( expect(
strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region,
input.tag, input.template)).andReturn(ec2Options); input.tag, input.template)).andReturn(ec2Options);
expect(input.template.getLocation()).andReturn(input.location).atLeastOnce(); expect(input.template.getLocation()).andReturn(input.location).atLeastOnce();
expect(input.template.getImage()).andReturn(input.image).atLeastOnce(); expect(input.template.getImage()).andReturn(input.image).atLeastOnce();
expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce(); expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce();
expect( expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options))
strategy.instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, .andReturn(reservation);
ec2Options)).andReturn(reservation);
expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce(); expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
expect(strategy.instanceStateRunning.apply(instance)).andReturn(true); expect(strategy.instanceStateRunning.apply(instance)).andReturn(true);
expect(strategy.instanceClient.describeInstancesInRegion(region, instanceCreatedId)) expect(instanceClient.describeInstancesInRegion(region, instanceCreatedId)).andReturn(
.andReturn(ImmutableSet.of(reservation)); ImmutableSet.of(reservation));
expect(input.template.getOptions()).andReturn(input.options).atLeastOnce(); expect(input.template.getOptions()).andReturn(input.options).atLeastOnce();
expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata); expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata);
@ -124,6 +126,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
eq(input.badNodes))).andReturn(null); eq(input.badNodes))).andReturn(null);
// replay mocks // replay mocks
replay(instanceClient);
replay(ec2Options); replay(ec2Options);
replay(instance); replay(instance);
replay(nodeMetadata); replay(nodeMetadata);
@ -134,6 +137,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
strategy.execute(input.tag, input.count, input.template, input.nodes, input.badNodes); strategy.execute(input.tag, input.count, input.template, input.nodes, input.badNodes);
// verify mocks // verify mocks
verify(instanceClient);
verify(ec2Options); verify(ec2Options);
verify(instance); verify(instance);
verify(nodeMetadata); verify(nodeMetadata);
@ -186,7 +190,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
private void verifyStrategy(EC2RunNodesAndAddToSetStrategy strategy) { private void verifyStrategy(EC2RunNodesAndAddToSetStrategy strategy) {
verify(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions); verify(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions);
verify(strategy.instanceClient); verify(strategy.client);
verify(strategy.instanceStateRunning); verify(strategy.instanceStateRunning);
verify(strategy.runningInstanceToNodeMetadata); verify(strategy.runningInstanceToNodeMetadata);
verify(strategy.utils); verify(strategy.utils);
@ -194,20 +198,19 @@ public class EC2RunNodesAndAddToSetStrategyTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private EC2RunNodesAndAddToSetStrategy setupStrategy() { private EC2RunNodesAndAddToSetStrategy setupStrategy() {
EC2Client client = createMock(EC2Client.class);
InstanceClient instanceClient = createMock(InstanceClient.class);
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createMock(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class); CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createMock(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class);
Predicate<RunningInstance> instanceStateRunning = createMock(Predicate.class); Predicate<RunningInstance> instanceStateRunning = createMock(Predicate.class);
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata = createMock(RunningInstanceToNodeMetadata.class); RunningInstanceToNodeMetadata runningInstanceToNodeMetadata = createMock(RunningInstanceToNodeMetadata.class);
ComputeUtils utils = createMock(ComputeUtils.class); ComputeUtils utils = createMock(ComputeUtils.class);
return new EC2RunNodesAndAddToSetStrategy(instanceClient, return new EC2RunNodesAndAddToSetStrategy(client,
createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions, instanceStateRunning, createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions, instanceStateRunning,
runningInstanceToNodeMetadata, utils); runningInstanceToNodeMetadata, utils);
} }
private void replayStrategy(EC2RunNodesAndAddToSetStrategy strategy) { private void replayStrategy(EC2RunNodesAndAddToSetStrategy strategy) {
replay(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions); replay(strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions);
replay(strategy.instanceClient); replay(strategy.client);
replay(strategy.instanceStateRunning); replay(strategy.instanceStateRunning);
replay(strategy.runningInstanceToNodeMetadata); replay(strategy.runningInstanceToNodeMetadata);
replay(strategy.utils); replay(strategy.utils);

View File

@ -1,74 +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.config;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.testng.Assert.assertEquals;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.EC2PropertiesBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.EC2ContextModuleTest")
public class EC2ContextModuleTest {
Injector createInjector() {
return Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()), new EC2RestClientModule(), new RestModule(),
new JavaUrlHttpCommandExecutorServiceModule(), new JDKLoggingModule(),
new EC2ContextModule() {
@Override
protected void configure() {
Jsr330.bindProperties(this.binder(), new EC2PropertiesBuilder("user", "key")
.build());
super.configure();
}
});
}
@Test
void testM1SMALLIsSmallest() {
// TODO
}
@Test
void testContextImpl() {
RestContext<EC2AsyncClient, EC2Client> handler = createInjector().getInstance(
Key.get(new TypeLiteral<RestContext<EC2AsyncClient, EC2Client>>() {
}));
assertEquals(handler.getClass(), RestContextImpl.class);
}
}

View File

@ -1,87 +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.config;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.aws.ec2.EC2PropertiesBuilder;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.EC2RestClientModuleTest")
public class EC2RestClientModuleTest {
Injector createInjector() {
return Guice.createInjector(new EC2RestClientModule(), new ExecutorServiceModule(
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
new AbstractModule() {
@Override
protected void configure() {
Jsr330.bindProperties(this.binder(), new EC2PropertiesBuilder("user", "key")
.build());
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AWSClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(),
AWSRedirectionRetryHandler.class);
}
}

View File

@ -61,7 +61,7 @@ public class AMIClientLiveTest {
private String imageId = "ami-cdf819a4"; private String imageId = "ami-cdf819a4";
private static final String DEFAULT_MANIFEST = "adrianimages/image.manifest.xml"; private static final String DEFAULT_MANIFEST = "adrianimages/image.manifest.xml";
private static final String DEFAULT_SNAPSHOT = "TODO"; private static final String DEFAULT_SNAPSHOT = "TODO";
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
private Set<String> imagesToDeregister = Sets.newHashSet(); private Set<String> imagesToDeregister = Sets.newHashSet();

View File

@ -54,7 +54,7 @@ import com.google.inject.internal.Lists;
public class AvailabilityZoneAndRegionClientLiveTest { public class AvailabilityZoneAndRegionClientLiveTest {
private AvailabilityZoneAndRegionClient client; private AvailabilityZoneAndRegionClient client;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {

View File

@ -37,7 +37,7 @@ import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -76,7 +76,7 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
return new AbstractModule() { return new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder("user", "key") Names.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder("user", "key")
.build(), "properties")); .build(), "properties"));
bind(URI.class).annotatedWith(EC2.class).toInstance( bind(URI.class).annotatedWith(EC2.class).toInstance(
URI.create("https://ec2.amazonaws.com")); URI.create("https://ec2.amazonaws.com"));

View File

@ -56,7 +56,7 @@ import com.google.inject.internal.Lists;
@Test(groups = "live", sequential = true, testName = "ec2.ElasticBlockStoreClientLiveTest") @Test(groups = "live", sequential = true, testName = "ec2.ElasticBlockStoreClientLiveTest")
public class ElasticBlockStoreClientLiveTest { public class ElasticBlockStoreClientLiveTest {
private ElasticBlockStoreClient client; private ElasticBlockStoreClient client;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
private String volumeId; private String volumeId;
private Snapshot snapshot; private Snapshot snapshot;

View File

@ -47,7 +47,7 @@ import com.google.inject.internal.Lists;
public class ElasticIPAddressClientLiveTest { public class ElasticIPAddressClientLiveTest {
private ElasticIPAddressClient client; private ElasticIPAddressClient client;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {

View File

@ -48,7 +48,7 @@ import com.google.inject.internal.Lists;
public class ElasticLoadBalancerClientLiveTest { public class ElasticLoadBalancerClientLiveTest {
private ElasticLoadBalancerClient client; private ElasticLoadBalancerClient client;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {

View File

@ -47,7 +47,7 @@ public class InstanceClientLiveTest {
private InstanceClient client; private InstanceClient client;
private String user; private String user;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {

View File

@ -47,7 +47,7 @@ import com.google.inject.internal.Lists;
public class KeyPairClientLiveTest { public class KeyPairClientLiveTest {
private KeyPairClient client; private KeyPairClient client;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {

View File

@ -42,7 +42,7 @@ public class MonitoringClientLiveTest {
private MonitoringClient client; private MonitoringClient client;
private static final String DEFAULT_INSTANCE = "i-TODO"; private static final String DEFAULT_INSTANCE = "i-TODO";
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {

View File

@ -55,7 +55,7 @@ import com.google.inject.internal.Lists;
public class SecurityGroupClientLiveTest { public class SecurityGroupClientLiveTest {
private SecurityGroupClient client; private SecurityGroupClient client;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2Client, EC2AsyncClient> context;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {

View File

@ -31,7 +31,7 @@ import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -68,15 +68,15 @@ public class FormSignerTest {
sameThreadExecutor(), sameThreadExecutor()), new AbstractModule() { sameThreadExecutor(), sameThreadExecutor()), new AbstractModule() {
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( bindConstant().annotatedWith(Names.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to(
"foo"); "foo");
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY)) bindConstant().annotatedWith(Names.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY))
.to("bar"); .to("bar");
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_EXPIREINTERVAL)) bindConstant().annotatedWith(Names.named(AWSConstants.PROPERTY_AWS_EXPIREINTERVAL))
.to(30); .to(30);
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)) bindConstant().annotatedWith(Names.named(Constants.PROPERTY_IO_WORKER_THREADS))
.to("1"); .to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1"); bindConstant().annotatedWith(Names.named(Constants.PROPERTY_USER_THREADS)).to("1");
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -18,17 +18,16 @@
*/ */
package org.jclouds.aws.s3; package org.jclouds.aws.s3;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.util.Properties;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.blobstore.functions.BlobToObject; import org.jclouds.aws.s3.blobstore.functions.BlobToObject;
import org.jclouds.aws.s3.config.S3ObjectModule; import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.domain.BucketLogging; import org.jclouds.aws.s3.domain.BucketLogging;
import org.jclouds.aws.s3.domain.CannedAccessPolicy; import org.jclouds.aws.s3.domain.CannedAccessPolicy;
@ -54,7 +53,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.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
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;
@ -66,21 +64,19 @@ import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
@ -91,19 +87,27 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "s3.S3ClientTest") @Test(groups = "unit", testName = "s3.S3ClientTest")
public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> { public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class,
String.class, Array.newInstance(PutBucketOptions.class, 0).getClass());
for (String region : Region.ALL) {
processor.createRequest(method, region, "bucket-name");
}
}
public void testGetBucketLocation() throws SecurityException, NoSuchMethodException, IOException { public void testGetBucketLocation() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class); Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?location HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
filter.filter(httpMethod); filter.filter(httpMethod);
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?location HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Authorization: AWS user:mlDjMMEYSR8md0v9S0JOZSoqWSA=\nDate: timestamp\nHost: bucket.stub\n"); "Authorization: AWS user:PSckzQGGr4MAsmqKtbMJtTNFx3A=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -117,8 +121,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("getBucketPayer", String.class); Method method = S3AsyncClient.class.getMethod("getBucketPayer", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?requestPayment HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -134,9 +138,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
Payer.BUCKET_OWNER); Payer.BUCKET_OWNER);
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/?requestPayment HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 133\nContent-Type: text/xml\nHost: bucket.stub\n"); "Content-Length: 133\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>"); "<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>");
@ -154,9 +158,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
Payer.REQUESTER); Payer.REQUESTER);
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/?requestPayment HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 131\nContent-Type: text/xml\nHost: bucket.stub\n"); "Content-Length: 131\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>"); "<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>");
@ -173,8 +177,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
ListBucketOptions.class, 0).getClass()); ListBucketOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -188,8 +192,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("bucketExists", String.class); Method method = S3AsyncClient.class.getMethod("bucketExists", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "HEAD http://bucket.stub:8080/?max-keys=0 HTTP/1.1"); assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -219,9 +223,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
"sourceBucket", "sourceObject", "destinationbucket", "destinationObject"); "sourceBucket", "sourceObject", "destinationbucket", "destinationObject");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"PUT http://destinationbucket.stub:8080/destinationObject HTTP/1.1"); "PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 0\nHost: destinationbucket.stub\nx-amz-copy-source: /sourceBucket/sourceObject\n"); "Content-Length: 0\nHost: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -236,8 +240,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("deleteBucketIfEmpty", String.class); Method method = S3AsyncClient.class.getMethod("deleteBucketIfEmpty", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "DELETE http://bucket.stub:8080/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -252,8 +256,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object"); "object");
assertRequestLineEquals(httpMethod, "DELETE http://bucket.stub:8080/object HTTP/1.1"); assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
@ -268,8 +272,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("getBucketACL", String.class); Method method = S3AsyncClient.class.getMethod("getBucketACL", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?acl HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -286,8 +290,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object"); "object");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/object HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, httpMethod,
@ -304,8 +308,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object"); "object");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/object?acl HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -321,8 +325,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object"); "object");
assertRequestLineEquals(httpMethod, "HEAD http://bucket.stub:8080/object HTTP/1.1"); assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -338,8 +342,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object"); "object");
assertRequestLineEquals(httpMethod, "HEAD http://bucket.stub:8080/object HTTP/1.1"); assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseObjectMetadataFromHeaders.class); assertResponseParserClassEquals(method, httpMethod, ParseObjectMetadataFromHeaders.class);
@ -353,8 +357,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("listOwnedBuckets"); Method method = S3AsyncClient.class.getMethod("listOwnedBuckets");
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://stub:8080/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: stub\n"); assertHeadersEqual(httpMethod, "Host: s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -375,9 +379,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/?acl HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.stub\n"); "Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"); "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
@ -396,8 +400,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method,
(String) null, "bucket"); (String) null, "bucket");
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Content-Length: 0\nHost: bucket.stub\n"); assertHeadersEqual(httpMethod, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -414,9 +418,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method,
Region.EU_WEST_1, "bucket"); Region.EU_WEST_1, "bucket");
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 98\nContent-Type: application/unknown\nHost: bucket.stub\n"); "Content-Length: 98\nContent-Type: application/unknown\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>"); "<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>");
@ -436,9 +440,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
blobToS3Object.apply(BindBlobToMultipartFormTest.TEST_BLOB)); blobToS3Object.apply(BindBlobToMultipartFormTest.TEST_BLOB));
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/hello HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 5\nContent-Type: text/plain\nHost: bucket.stub\n"); "Content-Length: 5\nContent-Type: text/plain\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(httpMethod, "hello");
assertResponseParserClassEquals(method, httpMethod, ParseETagHeader.class); assertResponseParserClassEquals(method, httpMethod, ParseETagHeader.class);
@ -454,9 +458,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"key", AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); "key", AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/key?acl HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.stub\n"); "Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"); "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
@ -472,8 +476,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("getBucketLogging", String.class); Method method = S3AsyncClient.class.getMethod("getBucketLogging", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?logging HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -488,9 +492,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("disableBucketLogging", String.class); Method method = S3AsyncClient.class.getMethod("disableBucketLogging", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/?logging HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 70\nContent-Type: text/xml\nHost: bucket.stub\n"); "Content-Length: 70\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>"); "<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>");
@ -509,9 +513,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
new BucketLogging("mylogs", "access_log-", ImmutableSet.<Grant> of(new Grant( new BucketLogging("mylogs", "access_log-", ImmutableSet.<Grant> of(new Grant(
new EmailAddressGrantee("adrian@jclouds.org"), Permission.FULL_CONTROL)))); new EmailAddressGrantee("adrian@jclouds.org"), Permission.FULL_CONTROL))));
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/?logging HTTP/1.1"); assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 433\nContent-Type: text/xml\nHost: bucket.stub\n"); "Content-Length: 433\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
"/s3/bucket_logging.xml"))); "/s3/bucket_logging.xml")));
@ -547,30 +551,18 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
@Override @Override
protected Module createModule() { protected Module createModule() {
return new AbstractModule() { return new S3RestClientModule() {
@Override @Override
protected void configure() { protected void configure() {
install(new BlobStoreObjectModule<S3AsyncClient, S3Client>( Names.bindProperties(binder(), new S3PropertiesBuilder(new Properties())
new TypeLiteral<S3AsyncClient>() { .withCredentials("user", "key").build());
}, new TypeLiteral<S3Client>() { install(new NullLoggingModule());
})); super.configure();
install(new S3ObjectModule());
Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user", "key")
.build(), "properties"));
bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("http://stub:8080"));
bind(String.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD);
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
} }
@SuppressWarnings("unused") @Override
@Provides protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
@TimeStamp return "2009-11-08T15:54:08.897Z";
String provide() {
return "timestamp";
} }
}; };
} }

View File

@ -20,28 +20,27 @@ package org.jclouds.aws.s3.config;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.aws.s3.S3PropertiesBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.util.Jsr330; import org.jclouds.rest.config.RestModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -50,14 +49,21 @@ import com.google.inject.Injector;
public class S3RestClientModuleTest { public class S3RestClientModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new S3RestClientModule(), new ExecutorServiceModule( return Guice.createInjector(new S3RestClientModule(), new RestModule() {
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
@Override
protected void configure() {
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
super.configure();
}
}, new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() { new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user", Names.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user",
"key").build(), "properties")); "key").build(), "properties"));
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -21,22 +21,17 @@ package org.jclouds.aws.s3.config;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.S3; import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.internal.StubS3AsyncClient; import org.jclouds.aws.s3.internal.StubS3AsyncClient;
import org.jclouds.blobstore.config.TransientBlobStoreModule; import org.jclouds.blobstore.config.TransientBlobStoreModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.internal.ImmutableSet;
/** /**
* adds a stub alternative to invoking S3 * adds a stub alternative to invoking S3
@ -44,24 +39,26 @@ import com.google.inject.internal.ImmutableSet;
* @author Adrian Cole * @author Adrian Cole
*/ */
@ConfiguresRestClient @ConfiguresRestClient
public class S3StubClientModule extends AbstractModule { public class S3StubClientModule extends RestClientModule<S3Client, S3AsyncClient> {
public S3StubClientModule() {
super(S3Client.class, S3AsyncClient.class);
}
protected void configure() { protected void configure() {
super.configure();
install(new S3ObjectModule());
install(new ParserModule()); install(new ParserModule());
install(new TransientBlobStoreModule()); install(new TransientBlobStoreModule());
bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("https://localhost/s3stub")); bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("https://localhost/s3stub"));
bind(String.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD); bind(String.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD);
bind(new TypeLiteral<Set<String>>() { bind(new TypeLiteral<Set<String>>() {
}).annotatedWith(S3.class).toInstance( }).annotatedWith(S3.class).toInstance(Region.ALL);
ImmutableSet.of(Region.US_STANDARD, Region.US_WEST_1, Region.EU_WEST_1));
} }
@Provides @Override
@Singleton protected void bindAsyncClient() {
public S3Client provideClient(S3AsyncClient client) throws IllegalArgumentException, bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton();
SecurityException, NoSuchMethodException {
return SyncProxy.create(S3Client.class, client);
} }
} }

View File

@ -20,21 +20,21 @@ package org.jclouds.aws.s3.filters;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.aws.s3.S3PropertiesBuilder;
import org.jclouds.aws.s3.config.S3RestClientModule; import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.util.Jsr330; import org.jclouds.rest.config.RestModule;
import com.google.inject.name.Names;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -139,14 +139,14 @@ public class RequestAuthorizeSignatureTest {
*/ */
@BeforeClass @BeforeClass
protected void createFilter() { protected void createFilter() {
injector = Guice.createInjector(new S3RestClientModule(), new ExecutorServiceModule( injector = Guice.createInjector(new RestModule(), new S3RestClientModule(),
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(), new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() { new AbstractModule() {
protected void configure() { protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull( Names.bindProperties(binder(), checkNotNull(
new S3PropertiesBuilder("foo", "bar")).build()); new S3PropertiesBuilder("foo", "bar")).build());
bind(UriBuilder.class).to(UriBuilderImpl.class); bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
} }
}); });
filter = injector.getInstance(RequestAuthorizeSignature.class); filter = injector.getInstance(RequestAuthorizeSignature.class);

View File

@ -33,6 +33,7 @@ import java.util.concurrent.ExecutorService;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
@ -84,6 +85,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
* @author James Murty * @author James Murty
*/ */
@Singleton
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;

View File

@ -19,26 +19,25 @@
package org.jclouds.aws.s3.util; package org.jclouds.aws.s3.util;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.aws.domain.AWSError; import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.aws.s3.S3PropertiesBuilder;
import org.jclouds.aws.s3.config.S3RestClientModule; import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.aws.s3.reference.S3Headers; import org.jclouds.aws.s3.reference.S3Headers;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.util.Jsr330; import org.jclouds.rest.config.RestModule;
import com.google.inject.name.Names;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
@ -61,17 +60,15 @@ public class S3UtilsTest {
@BeforeTest @BeforeTest
protected void setUpInjector() { protected void setUpInjector() {
Injector injector = Guice.createInjector(new S3RestClientModule(), new ParserModule(), Injector injector = Guice.createInjector(new RestModule(), new S3RestClientModule(),
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() { new AbstractModule() {
@Override
protected void configure() { protected void configure() {
bind(ExecutorService.class).toInstance(Executors.newCachedThreadPool()); Names.bindProperties(binder(), checkNotNull(
Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user", "key") new S3PropertiesBuilder("foo", "bar")).build());
.build(), "properties")); bind(TransformingHttpCommandExecutorService.class).toInstance(
bind(UriBuilder.class).to(UriBuilderImpl.class); createMock(TransformingHttpCommandExecutorService.class));
} }
}); });
utils = injector.getInstance(S3Utils.class); utils = injector.getInstance(S3Utils.class);
response = new HttpResponse(); response = new HttpResponse();

View File

@ -18,38 +18,35 @@
*/ */
package org.jclouds.aws.sqs; package org.jclouds.aws.sqs;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.inject.Singleton; import javax.inject.Named;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.sqs.config.SQSRestClientModule;
import org.jclouds.aws.sqs.options.CreateQueueOptions; import org.jclouds.aws.sqs.options.CreateQueueOptions;
import org.jclouds.aws.sqs.options.ListQueuesOptions; import org.jclouds.aws.sqs.options.ListQueuesOptions;
import org.jclouds.aws.sqs.reference.SQSConstants;
import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.aws.sqs.xml.RegexQueueHandler; import org.jclouds.aws.sqs.xml.RegexQueueHandler;
import org.jclouds.date.TimeStamp; import org.jclouds.date.DateService;
import org.jclouds.logging.Logger; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
@ -59,6 +56,7 @@ import com.google.inject.TypeLiteral;
*/ */
@Test(groups = "unit", testName = "sqs.SQSAsyncClientTest") @Test(groups = "unit", testName = "sqs.SQSAsyncClientTest")
public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> { public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException, public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array
@ -66,9 +64,10 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method,
(String) null); (String) null);
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
"Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); httpMethod,
"Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues"); assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues");
assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class); assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class);
@ -85,9 +84,10 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null, GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null,
ListQueuesOptions.Builder.queuePrefix("prefix")); ListQueuesOptions.Builder.queuePrefix("prefix"));
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); httpMethod,
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix"); assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix");
assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class); assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class);
@ -104,9 +104,10 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null, GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null,
"queueName"); "queueName");
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); httpMethod,
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName"); assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName");
assertResponseParserClassEquals(method, httpMethod, RegexQueueHandler.class); assertResponseParserClassEquals(method, httpMethod, RegexQueueHandler.class);
@ -123,9 +124,10 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null, GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null,
"queueName", CreateQueueOptions.Builder.defaultVisibilityTimeout(45)); "queueName", CreateQueueOptions.Builder.defaultVisibilityTimeout(45));
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
"Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: default\n"); httpMethod,
"Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45"); "Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45");
@ -136,6 +138,14 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
checkFilters(httpMethod); checkFilters(httpMethod);
} }
public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException {
Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class,
String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass());
for (String region : Iterables.filter(Region.ALL, not(equalTo("us-standard")))) {
processor.createRequest(method, region, "queueName");
}
}
@Override @Override
protected void checkFilters(GeneratedHttpRequest<SQSAsyncClient> httpMethod) { protected void checkFilters(GeneratedHttpRequest<SQSAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().size(), 1);
@ -150,40 +160,20 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
@Override @Override
protected Module createModule() { protected Module createModule() {
return new AbstractModule() { return new SQSRestClientModule() {
@Override @Override
protected void configure() { protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder(new Properties()) Names.bindProperties(binder(), new SQSPropertiesBuilder(new Properties())
.build(), "properties")); .withCredentials("user", "key").build());
bind(URI.class).annotatedWith(SQS.class).toInstance(URI.create("https://default")); install(new NullLoggingModule());
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( super.configure();
"user");
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY))
.to("key");
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
} }
@SuppressWarnings("unused") @Override
@Provides protected String provideTimeStamp(final DateService dateService,
@TimeStamp @Named(SQSConstants.PROPERTY_AWS_EXPIREINTERVAL) final int expiration) {
String provide() {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";
} }
@SuppressWarnings("unused")
@Singleton
@Provides
@SQS
Map<String, URI> provideMap() {
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI
.create("https://sqs.eu-west-1.amazonaws.com"), Region.US_EAST_1, URI
.create("https://sqs.us-east-1.amazonaws.com"), Region.US_WEST_1, URI
.create("https://sqs.us-west-1.amazonaws.com"));
}
}; };
} }
} }

View File

@ -50,7 +50,7 @@ public class SQSClientLiveTest {
private SQSClient client; private SQSClient client;
private RestContext<SQSAsyncClient, SQSClient> context; private RestContext<SQSClient, SQSAsyncClient> context;
private EncryptionService encryptionService = new JCEEncryptionService(); private EncryptionService encryptionService = new JCEEncryptionService();
private Set<Queue> queues = Sets.newHashSet(); private Set<Queue> queues = Sets.newHashSet();

View File

@ -21,14 +21,12 @@ package org.jclouds.aws.sqs.config;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
@ -36,10 +34,11 @@ import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.sqs.SQS;
import org.jclouds.aws.sqs.SQSPropertiesBuilder; import org.jclouds.aws.sqs.SQSPropertiesBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.util.Jsr330; import org.jclouds.rest.config.RestModule;
import com.google.inject.name.Names;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -55,14 +54,21 @@ import com.google.inject.Key;
public class SQSRestClientModuleTest { public class SQSRestClientModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new SQSRestClientModule(), new ExecutorServiceModule( return Guice.createInjector(new SQSRestClientModule(), new RestModule() {
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
@Override
protected void configure() {
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
super.configure();
}
}, new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() { new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder("user", Names.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder("user",
"key").build(), "properties")); "key").build(), "properties"));
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -82,7 +82,7 @@ public class MainApp {
} }
// Use Provider API // Use Provider API
RestContext<S3AsyncClient, S3Client> providerContext = context RestContext<S3Client, S3AsyncClient> providerContext = context
.getProviderSpecificContext(); .getProviderSpecificContext();
providerContext.getApi().getBucketLogging(containerName); providerContext.getApi().getBucketLogging(containerName);

View File

@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.demos.createlamp;
import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.asType; import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.asType;
import static org.jclouds.scriptbuilder.domain.Statements.exec; import static org.jclouds.scriptbuilder.domain.Statements.exec;
import java.net.InetSocketAddress;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -37,13 +36,12 @@ import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.predicates.InstanceStateRunning; import org.jclouds.aws.ec2.predicates.InstanceStateRunning;
import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.scriptbuilder.ScriptBuilder; import org.jclouds.scriptbuilder.ScriptBuilder;
import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.ssh.jsch.predicates.InetSocketAddressConnect;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -74,7 +72,7 @@ public class MainApp {
String name = args[3]; String name = args[3];
// Init // Init
RestContext<EC2AsyncClient, EC2Client> context = EC2ContextFactory.createContext(accesskeyid, RestContext<EC2Client, EC2AsyncClient> context = EC2ContextFactory.createContext(accesskeyid,
secretkey).getProviderSpecificContext(); secretkey).getProviderSpecificContext();
// Get a synchronous client // Get a synchronous client
@ -147,8 +145,8 @@ public class MainApp {
System.out.printf("%d: creating security group: %s%n", System.currentTimeMillis(), name); System.out.printf("%d: creating security group: %s%n", System.currentTimeMillis(), name);
client.getSecurityGroupServices().createSecurityGroupInRegion(null, name, name); client.getSecurityGroupServices().createSecurityGroupInRegion(null, name, name);
for (int port : new int[] { 80, 8080, 443, 22 }) { for (int port : new int[] { 80, 8080, 443, 22 }) {
client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, name,
name, IpProtocol.TCP, port, port, "0.0.0.0/0"); IpProtocol.TCP, port, port, "0.0.0.0/0");
} }
} }
@ -165,8 +163,13 @@ public class MainApp {
.build(OsFamily.UNIX); .build(OsFamily.UNIX);
System.out.printf("%d: running instance%n", System.currentTimeMillis()); System.out.printf("%d: running instance%n", System.currentTimeMillis());
Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow
null, // allow ec2 to chose an availability zone // ec2
// to
// chose
// an
// availability
// zone
"ami-ccf615a5", // alestic ami allows auto-invoke of user data scripts "ami-ccf615a5", // alestic ami allows auto-invoke of user data scripts
1, // minimum instances 1, // minimum instances
1, // maximum instances 1, // maximum instances
@ -183,7 +186,7 @@ public class MainApp {
throws TimeoutException { throws TimeoutException {
// create utilities that wait for the instance to finish // create utilities that wait for the instance to finish
RetryablePredicate<RunningInstance> runningTester = new RetryablePredicate<RunningInstance>( RetryablePredicate<RunningInstance> runningTester = new RetryablePredicate<RunningInstance>(
new InstanceStateRunning(client.getInstanceServices()), 180, 5, TimeUnit.SECONDS); new InstanceStateRunning(client), 180, 5, TimeUnit.SECONDS);
System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance
.getId()); .getId());
@ -214,8 +217,8 @@ public class MainApp {
private static RunningInstance findInstanceById(EC2Client client, String instanceId) { private static RunningInstance findInstanceById(EC2Client client, String instanceId) {
// search my account for the instance I just created // search my account for the instance I just created
Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion( Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion(null,
null, instanceId); // last parameter (ids) narrows the search instanceId); // last parameter (ids) narrows the search
// since we refined by instanceId there should only be one instance // since we refined by instanceId there should only be one instance
return Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); return Iterables.getOnlyElement(Iterables.getOnlyElement(reservations));
@ -223,8 +226,7 @@ public class MainApp {
private static RunningInstance findInstanceByKeyName(EC2Client client, final String keyName) { private static RunningInstance findInstanceByKeyName(EC2Client client, final String keyName) {
// search my account for the instance I just created // search my account for the instance I just created
Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion( Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion(null);
null);
// extract all the instances from all reservations // extract all the instances from all reservations
Set<RunningInstance> allInstances = Sets.newHashSet(); Set<RunningInstance> allInstances = Sets.newHashSet();

View File

@ -52,7 +52,7 @@
<dependency> <dependency>
<groupId>com.google.code.guice</groupId> <groupId>com.google.code.guice</groupId>
<artifactId>guice-servlet</artifactId> <artifactId>guice-servlet</artifactId>
<version>2.1-r1128</version> <version>2.1-r1172</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>displaytag</groupId> <groupId>displaytag</groupId>

View File

@ -81,7 +81,7 @@ public class SpeedTest {
String queueName = args[2]; String queueName = args[2];
int messageCount = Integer.parseInt(args[3]); int messageCount = Integer.parseInt(args[3]);
RestContext<SQSAsyncClient, SQSClient> context = isEnterprise ? SQSContextFactory RestContext<SQSClient, SQSAsyncClient> context = isEnterprise ? SQSContextFactory
.createContext(accesskeyid, secretkey, new NullLoggingModule(), .createContext(accesskeyid, secretkey, new NullLoggingModule(),
new EnterpriseConfigurationModule()) : SQSContextFactory.createContext( new EnterpriseConfigurationModule()) : SQSContextFactory.createContext(
accesskeyid, secretkey, new NullLoggingModule()); accesskeyid, secretkey, new NullLoggingModule());
@ -119,7 +119,7 @@ public class SpeedTest {
} }
private static void runTests(int messageCount, String contextName, private static void runTests(int messageCount, String contextName,
RestContext<SQSAsyncClient, SQSClient> context, Set<Queue> queues) RestContext<SQSClient, SQSAsyncClient> context, Set<Queue> queues)
throws InterruptedException { throws InterruptedException {
String message = "1"; String message = "1";
long timeOut = messageCount * 200; // minimum rate should be at least 5/second long timeOut = messageCount * 200; // minimum rate should be at least 5/second
@ -150,7 +150,7 @@ public class SpeedTest {
} }
private static void createQueues(String queueName, private static void createQueues(String queueName,
RestContext<SQSAsyncClient, SQSClient> nullLoggingDefaultContext, Set<Queue> queues) { RestContext<SQSClient, SQSAsyncClient> nullLoggingDefaultContext, Set<Queue> queues) {
for (String region : REGIONS) { for (String region : REGIONS) {
logger.info("creating queue: %s in region %s", queueName, region); logger.info("creating queue: %s in region %s", queueName, region);
queues.add(nullLoggingDefaultContext.getApi().createQueueInRegion(region, queueName)); queues.add(nullLoggingDefaultContext.getApi().createQueueInRegion(region, queueName));
@ -158,7 +158,7 @@ public class SpeedTest {
} }
private static boolean purgeQueues(String queueName, private static boolean purgeQueues(String queueName,
RestContext<SQSAsyncClient, SQSClient> nullLoggingDefaultContext) { RestContext<SQSClient, SQSAsyncClient> nullLoggingDefaultContext) {
boolean deleted = false; boolean deleted = false;
for (String region : REGIONS) { for (String region : REGIONS) {
try { try {

View File

@ -29,7 +29,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/** /**
* Creates {@link AzureBlobStoreContext} or {@link Injector} instances based on the most commonly * Creates {@link AzureBlobStoreContext} or {@link Injector} instances based on the most commonly
@ -45,12 +44,10 @@ import com.google.inject.TypeLiteral;
* @see AzureBlobStoreContext * @see AzureBlobStoreContext
*/ */
public class AzureBlobContextBuilder extends public class AzureBlobContextBuilder extends
BlobStoreContextBuilder<AzureBlobAsyncClient, AzureBlobClient> { BlobStoreContextBuilder<AzureBlobClient, AzureBlobAsyncClient> {
public AzureBlobContextBuilder(String providerName, Properties props) { public AzureBlobContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<AzureBlobAsyncClient>() { super(providerName, AzureBlobClient.class, AzureBlobAsyncClient.class, props);
}, new TypeLiteral<AzureBlobClient>() {
}, props);
} }
@Override @Override

View File

@ -59,7 +59,7 @@ public class AzureBlobStoreContextModule extends AzureBlobContextModule {
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).in(Scopes.SINGLETON); bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(AzureBlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(AzureBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class).to( bind(BlobStoreContext.class).to(
new TypeLiteral<BlobStoreContextImpl<AzureBlobAsyncClient, AzureBlobClient>>() { new TypeLiteral<BlobStoreContextImpl<AzureBlobClient, AzureBlobAsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class); bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
} }

View File

@ -27,7 +27,6 @@ import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient; import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient; import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.reference.AzureStorageConstants; import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -35,26 +34,24 @@ 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;
/**
*
* @author Adrian Cole
*/
@RequiresHttp @RequiresHttp
public class AzureBlobContextModule extends AbstractModule { public class AzureBlobContextModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
// for converters
install(new BlobStoreObjectModule<AzureBlobAsyncClient, AzureBlobClient>(
new TypeLiteral<AzureBlobAsyncClient>() {
}, new TypeLiteral<AzureBlobClient>() {
})); install(new AzureBlobModule());
} }
@Provides @Provides
@Singleton @Singleton
RestContext<AzureBlobAsyncClient, AzureBlobClient> provideContext(Closer closer, RestContext<AzureBlobClient, AzureBlobAsyncClient> provideContext(Closer closer,
AzureBlobAsyncClient asyncApi, AzureBlobClient defaultApi, @AzureBlob URI endPoint, AzureBlobAsyncClient asyncApi, AzureBlobClient defaultApi, @AzureBlob URI endPoint,
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) { @Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
return new RestContextImpl<AzureBlobAsyncClient, AzureBlobClient>(closer, asyncApi, return new RestContextImpl<AzureBlobClient, AzureBlobAsyncClient>(closer, asyncApi,
defaultApi, endPoint, account); defaultApi, endPoint, account);
} }

View File

@ -24,6 +24,7 @@ import javax.inject.Provider;
import org.jclouds.azure.storage.blob.domain.AzureBlob; import org.jclouds.azure.storage.blob.domain.AzureBlob;
import org.jclouds.azure.storage.blob.domain.MutableBlobProperties; import org.jclouds.azure.storage.blob.domain.MutableBlobProperties;
import org.jclouds.azure.storage.blob.domain.internal.AzureBlobImpl; import org.jclouds.azure.storage.blob.domain.internal.AzureBlobImpl;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -43,6 +44,8 @@ public class AzureBlobModule extends AbstractModule {
*/ */
@Override @Override
protected void configure() { protected void configure() {
// for converters
install(new BlobStoreObjectModule());
bind(AzureBlob.Factory.class).to(AzureBlobFactory.class).in(Scopes.SINGLETON); bind(AzureBlob.Factory.class).to(AzureBlobFactory.class).in(Scopes.SINGLETON);
} }

View File

@ -26,15 +26,10 @@ import javax.inject.Singleton;
import org.jclouds.azure.storage.AzureBlob; import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient; import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient; import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.handlers.AzureBlobClientErrorRetryHandler;
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants; import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
import org.jclouds.azure.storage.config.AzureStorageRestClientModule; import org.jclouds.azure.storage.config.AzureStorageRestClientModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -45,7 +40,18 @@ import com.google.inject.Provides;
*/ */
@ConfiguresRestClient @ConfiguresRestClient
@RequiresHttp @RequiresHttp
public class AzureBlobRestClientModule extends AzureStorageRestClientModule { public class AzureBlobRestClientModule extends
AzureStorageRestClientModule<AzureBlobClient, AzureBlobAsyncClient> {
public AzureBlobRestClientModule() {
super(AzureBlobClient.class, AzureBlobAsyncClient.class);
}
@Override
protected void configure() {
install(new AzureBlobModule());
super.configure();
}
@Provides @Provides
@Singleton @Singleton
@ -55,22 +61,4 @@ public class AzureBlobRestClientModule extends AzureStorageRestClientModule {
return URI.create(endpoint); return URI.create(endpoint);
} }
@Provides
@Singleton
protected AzureBlobAsyncClient provideAsyncClient(RestClientFactory factory) {
return factory.create(AzureBlobAsyncClient.class);
}
@Provides
@Singleton
public AzureBlobClient provideClient(AzureBlobAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(AzureBlobClient.class, client);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AzureBlobClientErrorRetryHandler.class);
}
} }

View File

@ -24,19 +24,21 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
import org.jclouds.azure.storage.handlers.AzureStorageClientErrorRetryHandler;
import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent; import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent;
import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -46,7 +48,11 @@ import com.google.inject.Provides;
*/ */
@ConfiguresRestClient @ConfiguresRestClient
@RequiresHttp @RequiresHttp
public class AzureStorageRestClientModule extends AbstractModule { public class AzureStorageRestClientModule<S, A> extends RestClientModule<S, A> {
public AzureStorageRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
@Provides @Provides
@TimeStamp @TimeStamp
@ -59,7 +65,7 @@ public class AzureStorageRestClientModule extends AbstractModule {
*/ */
@Provides @Provides
@TimeStamp @TimeStamp
Supplier<String> provideTimeStampCache( protected Supplier<String> provideTimeStampCache(
@Named(PROPERTY_AZURESTORAGE_SESSIONINTERVAL) long seconds, @Named(PROPERTY_AZURESTORAGE_SESSIONINTERVAL) long seconds,
final DateService dateService) { final DateService dateService) {
return new ExpirableSupplier<String>(new Supplier<String>() { return new ExpirableSupplier<String>(new Supplier<String>() {
@ -70,11 +76,6 @@ public class AzureStorageRestClientModule extends AbstractModule {
} }
@Override @Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
}
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAzureStorageErrorFromXmlContent.class); ParseAzureStorageErrorFromXmlContent.class);
@ -84,7 +85,10 @@ public class AzureStorageRestClientModule extends AbstractModule {
ParseAzureStorageErrorFromXmlContent.class); ParseAzureStorageErrorFromXmlContent.class);
} }
@Override
protected void bindRetryHandlers() { protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AzureStorageClientErrorRetryHandler.class);
} }
} }

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.azure.storage.blob.handlers; package org.jclouds.azure.storage.handlers;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -41,7 +41,7 @@ import com.google.inject.Inject;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class AzureBlobClientErrorRetryHandler implements HttpRetryHandler { public class AzureStorageClientErrorRetryHandler implements HttpRetryHandler {
@Inject(optional = true) @Inject(optional = true)
@Named(Constants.PROPERTY_MAX_RETRIES) @Named(Constants.PROPERTY_MAX_RETRIES)
@ -54,7 +54,7 @@ public class AzureBlobClientErrorRetryHandler implements HttpRetryHandler {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject @Inject
public AzureBlobClientErrorRetryHandler(BackoffLimitedRetryHandler backoffHandler, public AzureStorageClientErrorRetryHandler(BackoffLimitedRetryHandler backoffHandler,
AzureStorageUtils utils) { AzureStorageUtils utils) {
this.backoffHandler = backoffHandler; this.backoffHandler = backoffHandler;
this.utils = utils; this.utils = utils;

View File

@ -29,7 +29,6 @@ import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/** /**
* Creates {@link AzureQueueContext} or {@link Injector} instances based on the most commonly * Creates {@link AzureQueueContext} or {@link Injector} instances based on the most commonly
@ -45,12 +44,10 @@ import com.google.inject.TypeLiteral;
* @see AzureQueueContext * @see AzureQueueContext
*/ */
public class AzureQueueContextBuilder extends public class AzureQueueContextBuilder extends
RestContextBuilder<AzureQueueAsyncClient, AzureQueueClient> { RestContextBuilder<AzureQueueClient, AzureQueueAsyncClient> {
public AzureQueueContextBuilder(String providerName, Properties properties) { public AzureQueueContextBuilder(String providerName, Properties properties) {
super(providerName, new TypeLiteral<AzureQueueAsyncClient>() { super(providerName, AzureQueueClient.class, AzureQueueAsyncClient.class, properties);
}, new TypeLiteral<AzureQueueClient>() {
}, properties);
} }
@Override @Override

View File

@ -41,25 +41,25 @@ import com.google.inject.Module;
*/ */
public class AzureQueueContextFactory { public class AzureQueueContextFactory {
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext( public static RestContext<AzureQueueClient, AzureQueueAsyncClient> createContext(
Properties properties, Module... modules) { Properties properties, Module... modules) {
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(properties) return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(properties)
.build()).withModules(modules).buildContext(); .build()).withModules(modules).buildContext();
} }
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext( public static RestContext<AzureQueueClient, AzureQueueAsyncClient> createContext(
Properties properties, String account, String encodedKey, Module... modules) { Properties properties, String account, String encodedKey, Module... modules) {
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(properties) return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(properties)
.withCredentials(account, encodedKey).build()).withModules(modules).buildContext(); .withCredentials(account, encodedKey).build()).withModules(modules).buildContext();
} }
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext(String account, public static RestContext<AzureQueueClient, AzureQueueAsyncClient> createContext(String account,
String encodedKey, Module... modules) { String encodedKey, Module... modules) {
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(account, return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(account,
encodedKey).build()).withModules(modules).buildContext(); encodedKey).build()).withModules(modules).buildContext();
} }
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext(URI endpoint, public static RestContext<AzureQueueClient, AzureQueueAsyncClient> createContext(URI endpoint,
String account, String encodedKey, Module... modules) { String account, String encodedKey, Module... modules) {
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(account, return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(account,
encodedKey).withEndpoint(endpoint).build()).withModules(modules).buildContext(); encodedKey).withEndpoint(endpoint).build()).withModules(modules).buildContext();

View File

@ -47,10 +47,10 @@ public class AzureQueueContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
RestContext<AzureQueueAsyncClient, AzureQueueClient> provideContext(Closer closer, RestContext<AzureQueueClient, AzureQueueAsyncClient> provideContext(Closer closer,
AzureQueueAsyncClient asynchApi, AzureQueueClient defaultApi, @AzureQueue URI endPoint, AzureQueueAsyncClient asynchApi, AzureQueueClient defaultApi, @AzureQueue URI endPoint,
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) { @Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
return new RestContextImpl<AzureQueueAsyncClient, AzureQueueClient>(closer, asynchApi, return new RestContextImpl<AzureQueueClient, AzureQueueAsyncClient>(closer, asynchApi,
defaultApi, endPoint, account); defaultApi, endPoint, account);
} }

View File

@ -28,10 +28,8 @@ import org.jclouds.azure.storage.config.AzureStorageRestClientModule;
import org.jclouds.azure.storage.queue.AzureQueueAsyncClient; import org.jclouds.azure.storage.queue.AzureQueueAsyncClient;
import org.jclouds.azure.storage.queue.AzureQueueClient; import org.jclouds.azure.storage.queue.AzureQueueClient;
import org.jclouds.azure.storage.queue.reference.AzureQueueConstants; import org.jclouds.azure.storage.queue.reference.AzureQueueConstants;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -42,7 +40,12 @@ import com.google.inject.Provides;
*/ */
@ConfiguresRestClient @ConfiguresRestClient
@RequiresHttp @RequiresHttp
public class AzureQueueRestClientModule extends AzureStorageRestClientModule { public class AzureQueueRestClientModule extends
AzureStorageRestClientModule<AzureQueueClient, AzureQueueAsyncClient> {
public AzureQueueRestClientModule() {
super(AzureQueueClient.class, AzureQueueAsyncClient.class);
}
@Provides @Provides
@Singleton @Singleton
@ -52,17 +55,4 @@ public class AzureQueueRestClientModule extends AzureStorageRestClientModule {
return URI.create(endpoint); return URI.create(endpoint);
} }
@Provides
@Singleton
protected AzureQueueAsyncClient provideAsyncClient(RestClientFactory factory) {
return factory.create(AzureQueueAsyncClient.class);
}
@Provides
@Singleton
public AzureQueueClient provideClient(AzureQueueAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(AzureQueueClient.class, client);
}
} }

View File

@ -18,52 +18,43 @@
*/ */
package org.jclouds.azure.storage.blob; package org.jclouds.azure.storage.blob;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.jclouds.azure.storage.blob.options.CreateContainerOptions.Builder.withPublicAcl; import static org.jclouds.azure.storage.blob.options.CreateContainerOptions.Builder.withPublicAcl;
import static org.jclouds.azure.storage.options.ListOptions.Builder.maxResults; import static org.jclouds.azure.storage.options.ListOptions.Builder.maxResults;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.azure.storage.AzureBlob; import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
import org.jclouds.azure.storage.blob.functions.ParseContainerPropertiesFromHeaders; import org.jclouds.azure.storage.blob.functions.ParseContainerPropertiesFromHeaders;
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.config.AzureStorageRestClientModule; 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.AzureStorageConstants;
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnTrueOn404; import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.logging.Logger; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.inject.AbstractModule; import com.google.inject.Module;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
@ -72,7 +63,7 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "azureblob.AzureBlobAsyncClientTest") @Test(groups = "unit", testName = "azureblob.AzureBlobAsyncClientTest")
public class AzureBlobAsyncClientTest { public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClient> {
public void testListContainers() throws SecurityException, NoSuchMethodException { public void testListContainers() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance( Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
@ -358,31 +349,29 @@ public class AzureBlobAsyncClientTest {
MapHttp4xxCodesToExceptions.class); MapHttp4xxCodesToExceptions.class);
} }
@BeforeClass
void setupFactory() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() { protected void checkFilters(GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod) {
Jsr330.bindProperties(this.binder(), new AzureBlobPropertiesBuilder("user", "key") assertEquals(httpMethod.getFilters().size(), 1);
.build()); assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
bind(URI.class).annotatedWith(AzureBlob.class).toInstance(
URI.create("http://myaccount.blob.core.windows.net"));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL)).to(
1l);
}
}, new AzureStorageRestClientModule(), new RestModule(), new ExecutorServiceModule(
sameThreadExecutor(), sameThreadExecutor()),
new JavaUrlHttpCommandExecutorServiceModule());
processor = injector.getInstance(Key
.get(new TypeLiteral<RestAnnotationProcessor<AzureBlobAsyncClient>>() {
}));
} }
RestAnnotationProcessor<AzureBlobAsyncClient> processor; @Override
protected TypeLiteral<RestAnnotationProcessor<AzureBlobAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<AzureBlobAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new AzureBlobRestClientModule() {
@Override
protected void configure() {
Names.bindProperties(binder(), new AzureBlobPropertiesBuilder(new Properties())
.withCredentials("myaccount", "key").build());
install(new NullLoggingModule());
super.configure();
}
};
}
} }

View File

@ -18,21 +18,21 @@
*/ */
package org.jclouds.azure.storage.blob.blobstore.config; package org.jclouds.azure.storage.blob.blobstore.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties; import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties;
import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule; import org.jclouds.azure.storage.blob.config.AzureBlobStubClientModule;
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
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.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule; import com.google.inject.name.Names;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -43,21 +43,13 @@ import com.google.inject.Injector;
public class AzureBlobStoreModuleTest { public class AzureBlobStoreModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(), return Guice.createInjector(new AzureBlobStubClientModule(),
sameThreadExecutor()), new JDKLoggingModule(), new AzureBlobStubClientModule(), new AzureBlobStoreContextModule(), new ExecutorServiceModule(sameThreadExecutor(),
new AzureBlobStoreContextModule() { sameThreadExecutor()), new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith( Names.bindProperties(binder(), checkNotNull(new AzureBlobPropertiesBuilder(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT)) "user", "secret").build(), "properties"));
.to("user");
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
"key");
bindConstant().annotatedWith(
Jsr330.named(AzureBlobConstants.PROPERTY_AZUREBLOB_ENDPOINT)).to(
"http://localhost");
super.configure();
} }
}); });
} }

View File

@ -20,19 +20,14 @@ package org.jclouds.azure.storage.blob.config;
import java.net.URI; import java.net.URI;
import javax.inject.Singleton;
import org.jclouds.azure.storage.AzureBlob; import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient; import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient; import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.internal.StubAzureBlobAsyncClient; import org.jclouds.azure.storage.blob.internal.StubAzureBlobAsyncClient;
import org.jclouds.blobstore.config.TransientBlobStoreModule; import org.jclouds.blobstore.config.TransientBlobStoreModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/** /**
* adds a stub alternative to invoking AzureBlob * adds a stub alternative to invoking AzureBlob
@ -40,21 +35,24 @@ import com.google.inject.Provides;
* @author Adrian Cole * @author Adrian Cole
*/ */
@ConfiguresRestClient @ConfiguresRestClient
public class AzureBlobStubClientModule extends AbstractModule { public class AzureBlobStubClientModule extends
RestClientModule<AzureBlobClient, AzureBlobAsyncClient> {
public AzureBlobStubClientModule() {
super(AzureBlobClient.class, AzureBlobAsyncClient.class);
}
protected void configure() { protected void configure() {
super.configure();
install(new AzureBlobModule());
install(new ParserModule()); install(new ParserModule());
install(new TransientBlobStoreModule()); install(new TransientBlobStoreModule());
bind(AzureBlobAsyncClient.class).to(StubAzureBlobAsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(AzureBlob.class).toInstance( bind(URI.class).annotatedWith(AzureBlob.class).toInstance(
URI.create("https://localhost/azurestub")); URI.create("https://localhost/azurestub"));
} }
@Provides @Override
@Singleton protected void bindAsyncClient() {
public AzureBlobClient provideClient(AzureBlobAsyncClient client) bind(AzureBlobAsyncClient.class).to(StubAzureBlobAsyncClient.class).asEagerSingleton();
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(AzureBlobClient.class, client);
} }
} }

View File

@ -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.azure.storage.blob.config;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.azure.storage.blob.handlers.AzureBlobClientErrorRetryHandler;
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.http.handlers.RedirectionRetryHandler;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "s3.RestAzureBlobClientModuleTest")
public class RestAzureBlobClientModuleTest {
Injector createInjector() {
return Guice.createInjector(new AzureBlobRestClientModule(), new ExecutorServiceModule(
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(
Jsr330.named(AzureBlobConstants.PROPERTY_AZURESTORAGE_ACCOUNT)).to(
"user");
bindConstant().annotatedWith(
Jsr330.named(AzureBlobConstants.PROPERTY_AZURESTORAGE_KEY)).to(
Base64.encodeBytes("secret".getBytes()));
bindConstant().annotatedWith(
Jsr330.named(AzureBlobConstants.PROPERTY_AZUREBLOB_ENDPOINT)).to(
"http://localhost");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
bindConstant()
.annotatedWith(
Jsr330
.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL))
.to(1l);
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(),
ParseAzureStorageErrorFromXmlContent.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(),
ParseAzureStorageErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AzureBlobClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class);
}
}

View File

@ -18,26 +18,24 @@
*/ */
package org.jclouds.azure.storage.config; package org.jclouds.azure.storage.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT; import static org.easymock.classextension.EasyMock.createMock;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import javax.ws.rs.core.UriBuilder; import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
import org.jboss.resteasy.specimpl.UriBuilderImpl; import org.jclouds.azure.storage.handlers.AzureStorageClientErrorRetryHandler;
import org.jclouds.Constants;
import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent; import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler;
import org.jclouds.util.Jsr330; import org.jclouds.rest.config.RestModule;
import com.google.inject.name.Names;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -52,33 +50,29 @@ import com.google.inject.Injector;
public class AzureStorageRestClientModuleTest { public class AzureStorageRestClientModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new AzureStorageRestClientModule(), new ExecutorServiceModule( return Guice.createInjector(new AzureBlobRestClientModule(), new RestModule() {
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
@Override
protected void configure() {
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
super.configure();
}
}, new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() { new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_AZURESTORAGE_ACCOUNT)).to( Names.bindProperties(binder(), checkNotNull(new AzureBlobPropertiesBuilder(
"user"); "user", "secret").build(), "properties"));
bindConstant().annotatedWith(Jsr330.named(PROPERTY_AZURESTORAGE_KEY)).to(
"secret");
bindConstant().annotatedWith(
Jsr330.named(PROPERTY_AZURESTORAGE_SESSIONINTERVAL)).to("2");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }
@SuppressWarnings("unchecked")
@Test @Test
void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException { void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException {
AzureStorageRestClientModule module = new AzureStorageRestClientModule(); AzureStorageRestClientModule module = new AzureBlobRestClientModule();
Supplier<String> map = module.provideTimeStampCache(1, new SimpleDateFormatDateService()); Supplier<String> map = module.provideTimeStampCache(1, new SimpleDateFormatDateService());
String timeStamp = map.get(); String timeStamp = map.get();
@ -106,7 +100,8 @@ public class AzureStorageRestClientModuleTest {
@Test @Test
void testClientRetryHandler() { void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY); assertEquals(handler.getClientErrorRetryHandler().getClass(),
AzureStorageClientErrorRetryHandler.class);
} }
@Test @Test

View File

@ -18,8 +18,9 @@
*/ */
package org.jclouds.azure.storage.filters; package org.jclouds.azure.storage.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL; import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
@ -27,14 +28,14 @@ import java.net.URI;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants; import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
import org.jclouds.azure.storage.config.AzureStorageRestClientModule; import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.encryption.internal.Base64; import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.util.Jsr330; import org.jclouds.rest.config.RestModule;
import com.google.inject.name.Names;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -137,29 +138,15 @@ public class SharedKeyLiteAuthenticationTest {
*/ */
@BeforeClass @BeforeClass
protected void createFilter() { protected void createFilter() {
injector = Guice.createInjector(new ParserModule(), new ExecutorServiceModule( injector = Guice.createInjector(new RestModule(), new AzureBlobRestClientModule(),
sameThreadExecutor(), sameThreadExecutor()), new AzureStorageRestClientModule(), new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() { new AbstractModule() {
protected void configure() { protected void configure() {
bindConstant().annotatedWith( Names.bindProperties(binder(), checkNotNull(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT)) new AzureBlobPropertiesBuilder(ACCOUNT, KEY)).build());
.to(ACCOUNT); bind(TransformingHttpCommandExecutorService.class).toInstance(
bindConstant().annotatedWith( createMock(TransformingHttpCommandExecutorService.class));
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY))
.to(KEY);
bindConstant().annotatedWith(
Jsr330.named(PROPERTY_AZURESTORAGE_SESSIONINTERVAL)).to("1");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
} }
}); });
filter = injector.getInstance(SharedKeyLiteAuthentication.class); filter = injector.getInstance(SharedKeyLiteAuthentication.class);
} }

View File

@ -25,35 +25,29 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collections; import java.util.Collections;
import java.util.Properties;
import javax.inject.Singleton;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import org.jclouds.azure.storage.AzureQueue;
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
import org.jclouds.azure.storage.options.CreateOptions; import org.jclouds.azure.storage.options.CreateOptions;
import org.jclouds.azure.storage.options.ListOptions; import org.jclouds.azure.storage.options.ListOptions;
import org.jclouds.azure.storage.queue.config.AzureQueueRestClientModule;
import org.jclouds.azure.storage.queue.options.PutMessageOptions; import org.jclouds.azure.storage.queue.options.PutMessageOptions;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.logging.Logger; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import com.google.inject.name.Names;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
@ -73,7 +67,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method,
new Object[] {}); new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.queue.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/"); assertEquals(httpMethod.getEndpoint().getPath(), "/");
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list"); assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(httpMethod.getMethod(), HttpMethod.GET);
@ -92,7 +86,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method,
new Object[] { maxResults(1).marker("marker").prefix("prefix") }); new Object[] { maxResults(1).marker("marker").prefix("prefix") });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.queue.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/"); assertEquals(httpMethod.getEndpoint().getPath(), "/");
assert httpMethod.getEndpoint().getQuery().contains("comp=list"); assert httpMethod.getEndpoint().getQuery().contains("comp=list");
assert httpMethod.getEndpoint().getQuery().contains("marker=marker"); assert httpMethod.getEndpoint().getQuery().contains("marker=marker");
@ -115,7 +109,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method,
new Object[] { "queue" }); new Object[] { "queue" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.queue.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/queue"); assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
assertEquals(httpMethod.getEndpoint().getQuery(), null); assertEquals(httpMethod.getEndpoint().getQuery(), null);
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
@ -137,7 +131,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method,
new Object[] { "queue", withMetadata(ImmutableMultimap.of("foo", "bar")) }); new Object[] { "queue", withMetadata(ImmutableMultimap.of("foo", "bar")) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.queue.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/queue"); assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
assertEquals(httpMethod.getEndpoint().getQuery(), null); assertEquals(httpMethod.getEndpoint().getQuery(), null);
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
@ -159,7 +153,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method,
new Object[] { "queue" }); new Object[] { "queue" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.queue.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/queue"); assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
assertEquals(httpMethod.getEndpoint().getQuery(), null); assertEquals(httpMethod.getEndpoint().getQuery(), null);
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
@ -180,7 +174,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method,
"queue", "message"); "queue", "message");
assertRequestLineEquals(httpMethod, "POST http://localhost:8080/queue/messages HTTP/1.1"); assertRequestLineEquals(httpMethod,
"POST https://myaccount.queue.core.windows.net/queue/messages HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n"); "Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
@ -200,7 +195,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
"queue", "message", PutMessageOptions.Builder.withTTL(3)); "queue", "message", PutMessageOptions.Builder.withTTL(3));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"POST http://localhost:8080/queue/messages?messagettl=3 HTTP/1.1"); "POST https://myaccount.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(httpMethod,
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n"); "Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
@ -218,7 +213,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod = processor.createRequest(method,
"queue"); "queue");
assertRequestLineEquals(httpMethod, "DELETE http://localhost:8080/queue/messages HTTP/1.1"); assertRequestLineEquals(httpMethod,
"DELETE https://myaccount.queue.core.windows.net/queue/messages HTTP/1.1");
assertHeadersEqual(httpMethod, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(httpMethod, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -243,30 +239,15 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
@Override @Override
protected Module createModule() { protected Module createModule() {
return new AbstractModule() { return new AzureQueueRestClientModule() {
@Override @Override
protected void configure() { protected void configure() {
bind(URI.class).annotatedWith(AzureQueue.class).toInstance( Names.bindProperties(binder(), new AzureQueuePropertiesBuilder(new Properties())
URI.create("http://localhost:8080")); .withCredentials("myaccount", "key").build());
Jsr330.bindProperties(this.binder(), new AzureQueuePropertiesBuilder("user", "key") install(new NullLoggingModule());
.build()); super.configure();
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL)).to(
1l);
} }
@SuppressWarnings("unused")
@Provides
@TimeStamp
@Singleton
String provideTS() {
return "timestamp";
}
}; };
} }
} }

View File

@ -99,7 +99,7 @@ public interface BlobStoreContext {
* @return a context you can use to the access provider or vendor specific api underlying this * @return a context you can use to the access provider or vendor specific api underlying this
* context. * context.
*/ */
<A, S> RestContext<A, S> getProviderSpecificContext(); <S, A> RestContext<S, A> getProviderSpecificContext();
/** /**
* closes threads and resources related to this connection. * closes threads and resources related to this connection.

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