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}
*/
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) {
super(providerName, new TypeLiteral<${providerName}AsyncClient>() {},

View File

@ -83,7 +83,7 @@ public class ${providerName}ComputeServiceContextModule extends ${providerName}C
bind(new TypeLiteral<ComputeServiceContext>() {
})
.to(
new TypeLiteral<ComputeServiceContextImpl<${providerName}AsyncClient, ${providerName}Client>>() {
new TypeLiteral<ComputeServiceContextImpl<${providerName}Client, ${providerName}AsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(${providerName}AddNodeWithTagStrategy.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 {
@SuppressWarnings("unused")
RestContext<${providerName}AsyncClient, ${providerName}Client> tmContext = new ComputeServiceContextFactory()
RestContext<${providerName}Client, ${providerName}AsyncClient> tmContext = new ComputeServiceContextFactory()
.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>
@ -16,32 +19,6 @@
* 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};
import java.lang.annotation.ElementType;

View File

@ -26,15 +26,20 @@
*/
package ${package};
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.filters.BasicAuthentication;
import ${package}.${providerName}Client;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -48,24 +53,32 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Endpoint(${providerName}.class)
@RequestFilters(BasicAuthentication.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface ${providerName}AsyncClient {
/*
* TODO: define interface methods for ${providerName}
*/
/**
* @see ${providerName}AsyncClient#list()
* @see ${providerName}Client#list()
*/
@GET
@Path("/item")
@Path("/items")
ListenableFuture<String> list();
/**
* @see ${providerName}AsyncClient#get(String)
* @see ${providerName}Client#get(long)
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/item/{itemId}")
@Path("/items/{itemId}")
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_dollar = '$' )
#set( $symbol_escape = '\' )
@ -66,6 +48,11 @@ public interface ${providerName}Client {
String list();
/**
* @return null, if not found
*/
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 com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
*
* @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) {
super(providerName, new TypeLiteral<${providerName}AsyncClient>() {
}, new TypeLiteral<${providerName}Client>() {
}, props);
super(providerName, ${providerName}Client.class, ${providerName}AsyncClient.class, props);
checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER));
checkNotNull(properties.getProperty(${providerName}Constants.PROPERTY_${ucaseProviderName}_PASSWORD));
}

View File

@ -52,19 +52,19 @@ import com.google.inject.Module;
*/
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) {
return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(user, password).build())
.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) {
return new ${providerName}ContextBuilder("${artifactId}", new ${providerName}PropertiesBuilder(user, password).withEndpoint(endpoint).build())
.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())
.withModules(modules).buildContext();
}

View File

@ -77,9 +77,9 @@ public class ${providerName}ContextModule extends AbstractModule {
@Provides
@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) {
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.Singleton;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.HttpErrorHandler;
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.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.encryption.EncryptionService;
import ${package}.${providerName};
import ${package}.${providerName}Client;
import ${package}.${providerName}AsyncClient;
import ${package}.reference.${providerName}Constants;
import ${package}.handlers.${providerName}ErrorHandler;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -70,12 +73,11 @@ import com.google.inject.Provides;
*/
@RequiresHttp
@ConfiguresRestClient
public class ${providerName}RestClientModule extends AbstractModule {
public class ${providerName}RestClientModule extends
RestClientModule<${providerName}Client, ${providerName}AsyncClient> {
@Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
public ${providerName}RestClientModule() {
super(${providerName}Client.class, ${providerName}AsyncClient.class);
}
@Provides
@ -88,19 +90,6 @@ public class ${providerName}RestClientModule extends AbstractModule {
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
@Singleton
@${providerName}
@ -108,10 +97,17 @@ public class ${providerName}RestClientModule extends AbstractModule {
return URI.create(endpoint);
}
@Override
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() {
// TODO
}

View File

@ -27,34 +27,27 @@
*/
package ${package};
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import javax.inject.Singleton;
import org.jclouds.encryption.EncryptionService;
import ${package}.config.${providerName}RestClientModule;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/**
* 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);
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
// 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");
// 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);
// 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);
assertRequestLineEquals(httpRequest, "GET ${providerEndpoint}/item/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
// 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
protected void checkFilters(GeneratedHttpRequest<${providerName}AsyncClient> httpRequest) {
assertEquals(httpRequest.getFilters().size(), 1);
@ -123,28 +133,13 @@ public class ${providerName}AsyncClientTest extends RestClientTest<${providerNam
@Override
protected Module createModule() {
return new AbstractModule() {
return new ${providerName}RestClientModule() {
@Override
protected void configure() {
Jsr330.bindProperties(binder(), new ${providerName}PropertiesBuilder(
new Properties()).build());
bind(URI.class).annotatedWith(${providerName}.class).toInstance(
URI.create("${providerEndpoint}"));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
Names.bindProperties(binder(), new ${providerName}PropertiesBuilder("user", "key").build());
install(new NullLoggingModule());
super.configure();
}
});
}
@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.Module;
import com.google.inject.TypeLiteral;
/**
* Creates {@link AtmosBlobStoreContext} or {@link Injector} instances based on the most commonly
@ -45,12 +44,10 @@ import com.google.inject.TypeLiteral;
* @see AtmosBlobStoreContext
*/
public class AtmosStorageContextBuilder extends
BlobStoreContextBuilder<AtmosStorageAsyncClient, AtmosStorageClient> {
BlobStoreContextBuilder<AtmosStorageClient, AtmosStorageAsyncClient> {
public AtmosStorageContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<AtmosStorageAsyncClient>() {
}, new TypeLiteral<AtmosStorageClient>() {
}, props);
super(providerName, AtmosStorageClient.class, AtmosStorageAsyncClient.class, props);
}
@Override

View File

@ -65,7 +65,7 @@ public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
bind(BlobStore.class).to(AtmosBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class)
.to(
new TypeLiteral<BlobStoreContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>>() {
new TypeLiteral<BlobStoreContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>>() {
}).in(Scopes.SINGLETON);
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.UserMetadata;
import org.jclouds.atmosonline.saas.domain.internal.AtmosObjectImpl;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.encryption.EncryptionService;
import com.google.inject.AbstractModule;
@ -45,6 +46,8 @@ public class AtmosObjectModule extends AbstractModule {
*/
@Override
protected void configure() {
// for converters
install(new BlobStoreObjectModule());
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.AtmosStorageClient;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.http.RequiresHttp;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
@ -35,28 +34,25 @@ import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@RequiresHttp
public class AtmosStorageContextModule extends AbstractModule {
@Override
protected void configure() {
// for converters to work.
install(new BlobStoreObjectModule<AtmosStorageAsyncClient, AtmosStorageClient>(
new TypeLiteral<AtmosStorageAsyncClient>() {
}, new TypeLiteral<AtmosStorageClient>() {
}));
install(new AtmosObjectModule());
}
@Provides
@Singleton
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> provideContext(Closer closer,
RestContext<AtmosStorageClient, AtmosStorageAsyncClient> provideContext(Closer closer,
AtmosStorageAsyncClient async, AtmosStorageClient defaultApi,
@AtmosStorage URI endPoint,
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) {
return new RestContextImpl<AtmosStorageAsyncClient, AtmosStorageClient>(closer, async,
return new RestContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>(closer, async,
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.ParseAtmosStorageErrorFromXmlContent;
import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
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.ServerError;
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.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -57,7 +55,18 @@ import com.google.inject.Provides;
*/
@ConfiguresRestClient
@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
@Singleton
@AtmosStorage
@ -65,25 +74,6 @@ public class AtmosStorageRestClientModule extends AbstractModule {
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
@TimeStamp
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
@ -104,6 +94,7 @@ public class AtmosStorageRestClientModule extends AbstractModule {
}, seconds, TimeUnit.SECONDS);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAtmosStorageErrorFromXmlContent.class);
@ -113,6 +104,7 @@ public class AtmosStorageRestClientModule extends AbstractModule {
ParseAtmosStorageErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AtmosStorageClientErrorRetryHandler.class);

View File

@ -18,19 +18,17 @@
*/
package org.jclouds.atmosonline.saas;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import javax.ws.rs.core.HttpHeaders;
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.filters.SignRequest;
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.ReturnEndpointIfAlreadyExists;
import org.jclouds.atmosonline.saas.options.ListOptions;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
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 com.google.inject.AbstractModule;
import com.google.common.base.Supplier;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -79,7 +73,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method);
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");
assertPayloadEquals(httpMethod, null);
@ -98,7 +92,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"directory");
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");
assertPayloadEquals(httpMethod, null);
@ -118,7 +112,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
new ListOptions().limit(1).token("asda"));
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\nx-emc-limit: 1\nx-emc-token: asda\n");
assertPayloadEquals(httpMethod, null);
@ -139,7 +133,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"directory", new ListOptions().limit(1).token("asda"));
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\nx-emc-limit: 1\nx-emc-token: asda\n");
assertPayloadEquals(httpMethod, null);
@ -158,7 +152,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir");
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");
assertPayloadEquals(httpMethod, null);
@ -177,7 +171,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB));
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
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
assertPayloadEquals(httpMethod, "hello");
@ -197,7 +191,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB));
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
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
assertPayloadEquals(httpMethod, "hello");
@ -216,7 +210,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir/file");
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");
assertPayloadEquals(httpMethod, null);
@ -234,7 +228,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir/file");
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");
assertPayloadEquals(httpMethod, null);
@ -251,7 +245,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
"dir/file");
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");
assertPayloadEquals(httpMethod, null);
@ -288,33 +282,19 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
@Override
protected Module createModule() {
return new AbstractModule() {
return new AtmosStorageRestClientModule() {
@Override
protected void configure() {
install(new BlobStoreObjectModule<AtmosStorageAsyncClient, AtmosStorageClient>(
new TypeLiteral<AtmosStorageAsyncClient>() {
}, new TypeLiteral<AtmosStorageClient>() {
}));
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);
Names.bindProperties(binder(), new AtmosStoragePropertiesBuilder(new Properties())
.withCredentials("uid", "key").build());
install(new NullLoggingModule());
super.configure();
}
@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");
BlobStoreContext blobStoreContext = new BlobStoreContextFactory().createContext(
"atmosonline", uid, key, ImmutableSet.<Module> of(new Log4JLoggingModule()));
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> context = blobStoreContext
RestContext<AtmosStorageClient, AtmosStorageAsyncClient> context = blobStoreContext
.getProviderSpecificContext();
connection = context.getApi();
for (DirectoryEntry entry : connection.listDirectories()) {

View File

@ -18,21 +18,21 @@
*/
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 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.config.AtmosStorageStubClientModule;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.util.Jsr330;
import com.google.inject.name.Names;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -43,31 +43,16 @@ import com.google.inject.Injector;
public class AtmosBlobStoreModuleTest {
Injector createInjector() {
return Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()), new JDKLoggingModule(), new AtmosStorageStubClientModule(),
new AtmosBlobStoreContextModule("atmos") {
return Guice.createInjector(new AtmosStorageStubClientModule(),
new AtmosBlobStoreContextModule("atmos"), new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()), new AbstractModule() {
@Override
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(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();
Names.bindProperties(binder(), checkNotNull(new AtmosStoragePropertiesBuilder(
"user", "key").build(), "properties"));
}
});
}
@Test
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 javax.inject.Singleton;
import org.jclouds.atmosonline.saas.AtmosStorage;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.internal.StubAtmosStorageAsyncClient;
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 com.google.inject.AbstractModule;
import com.google.inject.Provides;
import org.jclouds.rest.config.RestClientModule;
/**
* adds a stub alternative to invoking AtmosStorage
@ -39,19 +35,24 @@ import com.google.inject.Provides;
* @author Adrian Cole
*/
@ConfiguresRestClient
public class AtmosStorageStubClientModule extends AbstractModule {
public class AtmosStorageStubClientModule extends
RestClientModule<AtmosStorageClient, AtmosStorageAsyncClient> {
public AtmosStorageStubClientModule() {
super(AtmosStorageClient.class, AtmosStorageAsyncClient.class);
}
protected void configure() {
super.configure();
install(new AtmosObjectModule());
install(new ParserModule());
install(new TransientBlobStoreModule());
bind(AtmosStorageAsyncClient.class).to(StubAtmosStorageAsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(AtmosStorage.class).toInstance(
URI.create("https://localhost/azurestub"));
URI.create("https://localhost/atmosstub"));
}
@Provides
@Singleton
public AtmosStorageClient provideClient(AtmosStorageAsyncClient client)
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
return SyncProxy.create(AtmosStorageClient.class, client);
@Override
protected void bindAsyncClient() {
bind(AtmosStorageAsyncClient.class).to(StubAtmosStorageAsyncClient.class).asEagerSingleton();
}
}

View File

@ -18,7 +18,9 @@
*/
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 org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
@ -29,21 +31,23 @@ import java.security.NoSuchAlgorithmException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.TimeStamp;
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.testng.annotations.BeforeClass;
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;
import com.google.inject.Provides;
@Test(groups = "unit", testName = "emcsaas.SignRequestTest")
public class SignRequestTest {
@ -80,24 +84,18 @@ public class SignRequestTest {
@BeforeClass
protected void createFilter() {
injector = Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()), new AbstractModule() {
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() {
injector = Guice.createInjector(new RestModule(), new AtmosStorageRestClientModule() {
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
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);

View File

@ -18,6 +18,9 @@
*/
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 {
/**
* EU (Ireland)
* <p/>
@ -73,8 +75,12 @@ public class Region {
public static final String US_WEST_1 = "us-west-1";
/**
* Region in Singapore, launched April 28, 2010.
* This region improves latency for Asia-based users
* Region in Singapore, launched April 28, 2010. This region improves latency for Asia-based
* users
*/
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;
import org.jclouds.aws.ec2.internal.EC2AsyncClientImpl;
import org.jclouds.aws.ec2.services.AMIAsyncClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient;
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.MonitoringAsyncClient;
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
import com.google.inject.ImplementedBy;
import org.jclouds.rest.annotations.Delegate;
/**
* Provides asynchronous access to EC2 services.
*
* @author Adrian Cole
*/
@ImplementedBy(EC2AsyncClientImpl.class)
public interface EC2AsyncClient {
/**
* Provides asynchronous access to AMI services.
*/
@Delegate
AMIAsyncClient getAMIServices();
/**
* Provides asynchronous access to Elastic IP Address services.
*/
@Delegate
ElasticIPAddressAsyncClient getElasticIPAddressServices();
/**
* Provides asynchronous access to Instance services.
*/
@Delegate
InstanceAsyncClient getInstanceServices();
/**
* Provides asynchronous access to KeyPair services.
*/
@Delegate
KeyPairAsyncClient getKeyPairServices();
/**
* Provides asynchronous access to SecurityGroup services.
*/
@Delegate
SecurityGroupAsyncClient getSecurityGroupServices();
/**
* Provides asynchronous access to Monitoring services.
*/
@Delegate
MonitoringAsyncClient getMonitoringServices();
/**
* Provides asynchronous access to Availability Zones and Regions services.
*/
@Delegate
AvailabilityZoneAndRegionAsyncClient getAvailabilityZoneAndRegionServices();
/**
* Provides asynchronous access to Elastic Block Store services.
*/
@Delegate
ElasticBlockStoreAsyncClient getElasticBlockStoreServices();
/**
* Provides asynchronous access to Elastic Load Balancer services.
*/
@Delegate
ElasticLoadBalancerAsyncClient getElasticLoadBalancerServices();
}

View File

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

View File

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

View File

@ -92,7 +92,7 @@ import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.logging.Logger;
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.Predicate;
@ -129,7 +129,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
bind(TemplateOptions.class).to(EC2TemplateOptions.class);
bind(ComputeService.class).to(EC2ComputeService.class);
bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<EC2AsyncClient, EC2Client>>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class);
bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class);
@ -139,7 +139,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
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);
}
@ -160,7 +160,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides
@Named("DEFAULT")
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
@ -171,13 +172,13 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final InstanceClient client;
private final EC2Client client;
private final Map<String, URI> regionMap;
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
private final ExecutorService executor;
@Inject
protected EC2ListNodesStrategy(InstanceClient client, @EC2 Map<String, URI> regionMap,
protected EC2ListNodesStrategy(EC2Client client, @EC2 Map<String, URI> regionMap,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = client;
@ -204,7 +205,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Override
public Void call() throws Exception {
Iterables.addAll(nodes, Iterables.transform(Iterables.concat(client
.describeInstancesInRegion(region)),
.getInstanceServices().describeInstancesInRegion(region)),
runningInstanceToNodeMetadata));
return null;
}
@ -223,11 +224,11 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Singleton
public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
private final InstanceClient client;
private final EC2Client client;
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
@Inject
protected EC2GetNodeMetadataStrategy(InstanceClient client,
protected EC2GetNodeMetadataStrategy(EC2Client client,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
this.client = client;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
@ -239,7 +240,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
String region = parts[0];
String instanceId = parts[1];
RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion(
client, region, instanceId));
client.getInstanceServices(), region, instanceId));
return runningInstanceToNodeMetadata.apply(runningInstance);
}
@ -250,8 +251,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
private final InstanceClient client;
@Inject
protected EC2RebootNodeStrategy(InstanceClient client) {
this.client = client;
protected EC2RebootNodeStrategy(EC2Client client) {
this.client = client.getInstanceServices();
}
@Override

View File

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

View File

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

View File

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

View File

@ -35,11 +35,11 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.RunningInstance;
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.Template;
import org.jclouds.compute.reference.ComputeServiceConstants;
@ -65,7 +65,7 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
protected Logger logger = Logger.NULL;
@VisibleForTesting
final InstanceClient instanceClient;
final EC2Client client;
@VisibleForTesting
final CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
@VisibleForTesting
@ -77,11 +77,11 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
@Inject
EC2RunNodesAndAddToSetStrategy(
InstanceClient instanceClient,
EC2Client client,
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions,
@Named("RUNNING") Predicate<RunningInstance> instanceStateRunning,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata, ComputeUtils utils) {
this.instanceClient = instanceClient;
this.client = client;
this.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
this.instanceStateRunning = instanceStateRunning;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
@ -129,14 +129,16 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
if (logger.isDebugEnabled())
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,
count, instanceOptions);
return client.getInstanceServices().runInstancesInRegion(region, zone,
template.getImage().getProviderId(), 1, count, instanceOptions);
}
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
@Singleton
RestContext<EC2AsyncClient, EC2Client> provideContext(Closer closer, EC2AsyncClient defaultApi,
RestContext<EC2Client, EC2AsyncClient> provideContext(Closer closer, EC2AsyncClient defaultApi,
EC2Client synchApi, @EC2 URI endPoint,
@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);
}

View File

@ -28,6 +28,8 @@ import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
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.domain.AvailabilityZoneInfo;
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.AWSRedirectionRetryHandler;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler;
@ -70,13 +71,12 @@ import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.ConfiguresRestClient;
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.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -86,7 +86,23 @@ import com.google.inject.Provides;
*/
@RequiresHttp
@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
@Singleton
@ -110,12 +126,6 @@ public class EC2RestClientModule extends AbstractModule {
return new RetryablePredicate<IPSocket>(open, 130, 1, TimeUnit.SECONDS);
}
@Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
}
@Provides
@Singleton
@ELB
@ -152,7 +162,7 @@ public class EC2RestClientModule extends AbstractModule {
@Provides
@Singleton
@EC2
Map<String, URI> provideRegions(AvailabilityZoneAndRegionClient client) {
Map<String, URI> provideRegions(EC2Client client) {
// http://code.google.com/p/google-guice/issues/detail?id=483
// guice doesn't remember when singleton providers throw exceptions.
// in this case, if describeRegions fails, it is called again for
@ -161,7 +171,7 @@ public class EC2RestClientModule extends AbstractModule {
if (regionException != null)
throw regionException;
try {
return client.describeRegions();
return client.getAvailabilityZoneAndRegionServices().describeRegions();
} catch (RuntimeException e) {
this.regionException = e;
throw e;
@ -170,11 +180,12 @@ public class EC2RestClientModule extends AbstractModule {
@Provides
@Singleton
Map<String, String> provideAvailabilityZoneToRegions(AvailabilityZoneAndRegionClient client,
Map<String, String> provideAvailabilityZoneToRegions(EC2Client client,
@EC2 Map<String, URI> regions) {
Map<String, String> map = Maps.newHashMap();
for (String region : regions.keySet()) {
for (AvailabilityZoneInfo zoneInfo : client.describeAvailabilityZonesInRegion(region)) {
for (AvailabilityZoneInfo zoneInfo : client.getAvailabilityZoneAndRegionServices()
.describeAvailabilityZonesInRegion(region)) {
map.put(zoneInfo.getZone(), region);
}
}
@ -195,129 +206,6 @@ public class EC2RestClientModule extends AbstractModule {
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
@Singleton
@EC2
@ -325,6 +213,7 @@ public class EC2RestClientModule extends AbstractModule {
return URI.create(endpoint);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class);
@ -334,6 +223,7 @@ public class EC2RestClientModule extends AbstractModule {
ParseAWSErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
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 org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.logging.Logger;
import com.google.common.base.Predicate;
@ -39,13 +39,13 @@ import com.google.inject.Inject;
@Singleton
public class InstanceHasIpAddress implements Predicate<RunningInstance> {
private final InstanceClient client;
private final EC2Client client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public InstanceHasIpAddress(InstanceClient client) {
public InstanceHasIpAddress(EC2Client client) {
this.client = client;
}
@ -62,7 +62,7 @@ public class InstanceHasIpAddress implements Predicate<RunningInstance> {
}
private RunningInstance refresh(RunningInstance instance) {
return Iterables.getOnlyElement(Iterables.getOnlyElement(client.describeInstancesInRegion(
instance.getRegion(), instance.getId())));
return Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices()
.describeInstancesInRegion(instance.getRegion(), instance.getId())));
}
}

View File

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

View File

@ -23,9 +23,9 @@ import java.util.NoSuchElementException;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.logging.Logger;
import com.google.common.base.Predicate;
@ -41,13 +41,13 @@ import com.google.inject.Inject;
@Singleton
public class InstanceStateTerminated implements Predicate<RunningInstance> {
private final InstanceClient client;
private final EC2Client client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public InstanceStateTerminated(InstanceClient client) {
public InstanceStateTerminated(EC2Client client) {
this.client = client;
}
@ -64,7 +64,7 @@ public class InstanceStateTerminated implements Predicate<RunningInstance> {
}
private RunningInstance refresh(RunningInstance instance) {
return Iterables.getOnlyElement(Iterables.getOnlyElement(client.describeInstancesInRegion(
instance.getRegion(), instance.getId())));
return Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices()
.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.Module;
import com.google.inject.TypeLiteral;
/**
* 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
* @see S3Context
*/
public class S3ContextBuilder extends BlobStoreContextBuilder<S3AsyncClient, S3Client> {
public class S3ContextBuilder extends BlobStoreContextBuilder<S3Client, S3AsyncClient> {
public S3ContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<S3AsyncClient>() {
}, new TypeLiteral<S3Client>() {
}, props);
super(providerName, S3Client.class, S3AsyncClient.class, props);
}
@Override
protected void addContextModule(String providerName,List<Module> modules) {
protected void addContextModule(String providerName, List<Module> modules) {
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(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class).to(
new TypeLiteral<BlobStoreContextImpl<S3AsyncClient, S3Client>>() {
new TypeLiteral<BlobStoreContextImpl<S3Client, S3AsyncClient>>() {
}).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.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link S3ContextModule}; requires {@link S3AsyncClient} bound.
@ -45,19 +43,14 @@ public class S3ContextModule extends AbstractModule {
@Override
protected void configure() {
// for converters
install(new BlobStoreObjectModule<S3AsyncClient, S3Client>(new TypeLiteral<S3AsyncClient>() {
}, new TypeLiteral<S3Client>() {
}));
install(new S3ObjectModule());
}
@Provides
@Singleton
RestContext<S3AsyncClient, S3Client> provideContext(Closer closer, S3AsyncClient defaultApi,
RestContext<S3Client, S3AsyncClient> provideContext(Closer closer, S3AsyncClient defaultApi,
S3Client syncApi, @S3 URI endPoint,
@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);
}

View File

@ -24,11 +24,11 @@ import javax.inject.Provider;
import org.jclouds.aws.s3.domain.MutableObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.domain.internal.S3ObjectImpl;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.encryption.EncryptionService;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
/**
* Configures the domain object mappings needed for all S3 implementations
@ -43,7 +43,9 @@ public class S3ObjectModule extends AbstractModule {
*/
@Override
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 {

View File

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

View File

@ -29,7 +29,6 @@ import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* 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
* @see SQSContext
*/
public class SQSContextBuilder extends RestContextBuilder<SQSAsyncClient, SQSClient> {
public class SQSContextBuilder extends RestContextBuilder<SQSClient, SQSAsyncClient> {
public SQSContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<SQSAsyncClient>() {
}, new TypeLiteral<SQSClient>() {
}, props);
super(providerName, SQSClient.class, SQSAsyncClient.class, props);
}
@Override

View File

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

View File

@ -52,10 +52,10 @@ public class SQSContextModule extends AbstractModule {
@Provides
@Singleton
RestContext<SQSAsyncClient, SQSClient> provideContext(Closer closer, SQSAsyncClient defaultApi,
RestContext<SQSClient, SQSAsyncClient> provideContext(Closer closer, SQSAsyncClient defaultApi,
SQSClient synchApi, @SQS URI endPoint,
@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);
}

View File

@ -34,7 +34,6 @@ import org.jclouds.aws.sqs.SQS;
import org.jclouds.aws.sqs.SQSAsyncClient;
import org.jclouds.aws.sqs.SQSClient;
import org.jclouds.aws.sqs.reference.SQSConstants;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler;
@ -45,11 +44,10 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;
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.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -59,12 +57,10 @@ import com.google.inject.Provides;
*/
@RequiresHttp
@ConfiguresRestClient
public class SQSRestClientModule extends AbstractModule {
public class SQSRestClientModule extends RestClientModule<SQSClient, SQSAsyncClient> {
@Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
public SQSRestClientModule() {
super(SQSClient.class, SQSAsyncClient.class);
}
@Provides
@ -75,19 +71,6 @@ public class SQSRestClientModule extends AbstractModule {
+ (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
@Singleton
@SQS
@ -121,6 +104,7 @@ public class SQSRestClientModule extends AbstractModule {
return in;
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class);
@ -130,6 +114,7 @@ public class SQSRestClientModule extends AbstractModule {
ParseAWSErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class);

View File

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

View File

@ -136,8 +136,8 @@ public class EBSBootEC2ClientLiveTest {
VolumeAttached volumeAttached = injector.getInstance(VolumeAttached.class);
attachTester = new RetryablePredicate<Attachment>(volumeAttached, 60, 1, TimeUnit.SECONDS);
runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client
.getInstanceServices()), 180, 5, TimeUnit.SECONDS);
runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client),
180, 5, TimeUnit.SECONDS);
InstanceStateStopped instanceStateStopped = injector.getInstance(InstanceStateStopped.class);
stoppedTester = new RetryablePredicate<RunningInstance>(instanceStateStopped, 60, 1,
@ -272,8 +272,8 @@ public class EBSBootEC2ClientLiveTest {
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume")
void testBundleInstance() {
SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22),
"ubuntu", keyPair.getKeyMaterial().getBytes());
SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), "ubuntu",
keyPair.getKeyMaterial().getBytes());
try {
ssh.connect();
} 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();
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().getOsFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Jsr330;
import com.google.inject.name.Names;
import org.testng.annotations.BeforeTest;
import com.google.common.collect.ImmutableMap;
@ -76,7 +76,7 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
return new AbstractModule() {
@Override
protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder("user", "key")
Names.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder("user", "key")
.build(), "properties"));
bind(URI.class).annotatedWith(EC2.class).toInstance(
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")
public class ElasticBlockStoreClientLiveTest {
private ElasticBlockStoreClient client;
private RestContext<EC2AsyncClient, EC2Client> context;
private RestContext<EC2Client, EC2AsyncClient> context;
private String volumeId;
private Snapshot snapshot;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
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.Test;
@ -68,15 +68,15 @@ public class FormSignerTest {
sameThreadExecutor(), sameThreadExecutor()), new AbstractModule() {
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to(
bindConstant().annotatedWith(Names.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to(
"foo");
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY))
bindConstant().annotatedWith(Names.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY))
.to("bar");
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_EXPIREINTERVAL))
bindConstant().annotatedWith(Names.named(AWSConstants.PROPERTY_AWS_EXPIREINTERVAL))
.to(30);
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_IO_WORKER_THREADS))
.to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_USER_THREADS)).to("1");
}
@SuppressWarnings("unused")

View File

@ -18,17 +18,16 @@
*/
package org.jclouds.aws.s3;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import org.jclouds.aws.domain.Region;
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.BucketLogging;
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.PayerHandler;
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
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.ReturnTrueIf2xx;
import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
import com.google.inject.name.Names;
import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
@ -91,19 +87,27 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "s3.S3ClientTest")
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 {
Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?location HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
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,
"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);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -117,8 +121,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("getBucketPayer", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -134,9 +138,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
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,
"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(
httpMethod,
"<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",
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,
"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(
httpMethod,
"<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());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -188,8 +192,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("bucketExists", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "HEAD http://bucket.stub:8080/?max-keys=0 HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -219,9 +223,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
"sourceBucket", "sourceObject", "destinationbucket", "destinationObject");
assertRequestLineEquals(httpMethod,
"PUT http://destinationbucket.stub:8080/destinationObject HTTP/1.1");
"PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
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);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -236,8 +240,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("deleteBucketIfEmpty", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "DELETE http://bucket.stub:8080/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -252,8 +256,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object");
assertRequestLineEquals(httpMethod, "DELETE http://bucket.stub:8080/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
@ -268,8 +272,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("getBucketACL", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -286,8 +290,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod,
@ -304,8 +308,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/object?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -321,8 +325,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object");
assertRequestLineEquals(httpMethod, "HEAD http://bucket.stub:8080/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -338,8 +342,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"object");
assertRequestLineEquals(httpMethod, "HEAD http://bucket.stub:8080/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseObjectMetadataFromHeaders.class);
@ -353,8 +357,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("listOwnedBuckets");
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://stub:8080/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: stub\n");
assertRequestLineEquals(httpMethod, "GET https://s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -375,9 +379,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
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,
"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(
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>");
@ -396,8 +400,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method,
(String) null, "bucket");
assertRequestLineEquals(httpMethod, "PUT http://bucket.stub:8080/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Content-Length: 0\nHost: bucket.stub\n");
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
@ -414,9 +418,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method,
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,
"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(
httpMethod,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>");
@ -436,9 +440,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
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,
"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");
assertResponseParserClassEquals(method, httpMethod, ParseETagHeader.class);
@ -454,9 +458,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
"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,
"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(
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>");
@ -472,8 +476,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("getBucketLogging", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET http://bucket.stub:8080/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -488,9 +492,9 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("disableBucketLogging", String.class);
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,
"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,
"<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 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,
"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(
"/s3/bucket_logging.xml")));
@ -547,30 +551,18 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
@Override
protected Module createModule() {
return new AbstractModule() {
return new S3RestClientModule() {
@Override
protected void configure() {
install(new BlobStoreObjectModule<S3AsyncClient, S3Client>(
new TypeLiteral<S3AsyncClient>() {
}, new TypeLiteral<S3Client>() {
}));
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;
}
});
Names.bindProperties(binder(), new S3PropertiesBuilder(new Properties())
.withCredentials("user", "key").build());
install(new NullLoggingModule());
super.configure();
}
@SuppressWarnings("unused")
@Provides
@TimeStamp
String provide() {
return "timestamp";
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "2009-11-08T15:54:08.897Z";
}
};
}

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.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
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.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.s3.S3PropertiesBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule;
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.DelegatingRetryHandler;
import org.jclouds.util.Jsr330;
import org.jclouds.rest.config.RestModule;
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;
import com.google.inject.name.Names;
/**
* @author Adrian Cole
@ -50,14 +49,21 @@ import com.google.inject.Injector;
public class S3RestClientModuleTest {
Injector createInjector() {
return Guice.createInjector(new S3RestClientModule(), new ExecutorServiceModule(
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
return Guice.createInjector(new S3RestClientModule(), new RestModule() {
@Override
protected void configure() {
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
super.configure();
}
}, new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() {
@Override
protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user",
Names.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user",
"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.util.Set;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.internal.StubS3AsyncClient;
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.config.RestClientModule;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.internal.ImmutableSet;
/**
* adds a stub alternative to invoking S3
@ -44,24 +39,26 @@ import com.google.inject.internal.ImmutableSet;
* @author Adrian Cole
*/
@ConfiguresRestClient
public class S3StubClientModule extends AbstractModule {
public class S3StubClientModule extends RestClientModule<S3Client, S3AsyncClient> {
public S3StubClientModule() {
super(S3Client.class, S3AsyncClient.class);
}
protected void configure() {
super.configure();
install(new S3ObjectModule());
install(new ParserModule());
install(new TransientBlobStoreModule());
bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("https://localhost/s3stub"));
bind(String.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD);
bind(new TypeLiteral<Set<String>>() {
}).annotatedWith(S3.class).toInstance(
ImmutableSet.of(Region.US_STANDARD, Region.US_WEST_1, Region.EU_WEST_1));
}).annotatedWith(S3.class).toInstance(Region.ALL);
}
@Provides
@Singleton
public S3Client provideClient(S3AsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(S3Client.class, client);
@Override
protected void bindAsyncClient() {
bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton();
}
}

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

View File

@ -33,6 +33,7 @@ import java.util.concurrent.ExecutorService;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
@ -84,6 +85,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole
* @author James Murty
*/
@Singleton
public class StubS3AsyncClient implements S3AsyncClient {
private final DateService dateService;
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;

View File

@ -19,26 +19,25 @@
package org.jclouds.aws.s3.util;
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 java.io.IOException;
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.s3.S3PropertiesBuilder;
import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.aws.s3.reference.S3Headers;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
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.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
@ -61,17 +60,15 @@ public class S3UtilsTest {
@BeforeTest
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() {
@Override
protected void configure() {
bind(ExecutorService.class).toInstance(Executors.newCachedThreadPool());
Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder("user", "key")
.build(), "properties"));
bind(UriBuilder.class).to(UriBuilderImpl.class);
Names.bindProperties(binder(), checkNotNull(
new S3PropertiesBuilder("foo", "bar")).build());
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
}
});
utils = injector.getInstance(S3Utils.class);
response = new HttpResponse();

View File

@ -18,38 +18,35 @@
*/
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 java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Singleton;
import javax.inject.Named;
import org.jclouds.aws.domain.Region;
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.ListQueuesOptions;
import org.jclouds.aws.sqs.reference.SQSConstants;
import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.aws.sqs.xml.RegexQueueHandler;
import org.jclouds.date.TimeStamp;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
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 org.jclouds.util.Jsr330;
import com.google.inject.name.Names;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.common.collect.Iterables;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
@ -59,6 +56,7 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "sqs.SQSAsyncClientTest")
public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException,
IOException {
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,
(String) null);
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: default\n");
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
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");
assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class);
@ -85,9 +84,10 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null,
ListQueuesOptions.Builder.queuePrefix("prefix"));
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: default\n");
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
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");
assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class);
@ -104,9 +104,10 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null,
"queueName");
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: default\n");
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
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");
assertResponseParserClassEquals(method, httpMethod, RegexQueueHandler.class);
@ -123,9 +124,10 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null,
"queueName", CreateQueueOptions.Builder.defaultVisibilityTimeout(45));
assertRequestLineEquals(httpMethod, "POST https://default/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: default\n");
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Content-Length: 85\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&DefaultVisibilityTimeout=45");
@ -136,6 +138,14 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
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
protected void checkFilters(GeneratedHttpRequest<SQSAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
@ -150,40 +160,20 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
@Override
protected Module createModule() {
return new AbstractModule() {
return new SQSRestClientModule() {
@Override
protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder(new Properties())
.build(), "properties"));
bind(URI.class).annotatedWith(SQS.class).toInstance(URI.create("https://default"));
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to(
"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;
}
});
Names.bindProperties(binder(), new SQSPropertiesBuilder(new Properties())
.withCredentials("user", "key").build());
install(new NullLoggingModule());
super.configure();
}
@SuppressWarnings("unused")
@Provides
@TimeStamp
String provide() {
@Override
protected String provideTimeStamp(final DateService dateService,
@Named(SQSConstants.PROPERTY_AWS_EXPIREINTERVAL) final int expiration) {
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 RestContext<SQSAsyncClient, SQSClient> context;
private RestContext<SQSClient, SQSAsyncClient> context;
private EncryptionService encryptionService = new JCEEncryptionService();
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.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals;
import java.net.URI;
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.handlers.AWSClientErrorRetryHandler;
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.SQSPropertiesBuilder;
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.DelegatingRetryHandler;
import org.jclouds.util.Jsr330;
import org.jclouds.rest.config.RestModule;
import com.google.inject.name.Names;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -55,14 +54,21 @@ import com.google.inject.Key;
public class SQSRestClientModuleTest {
Injector createInjector() {
return Guice.createInjector(new SQSRestClientModule(), new ExecutorServiceModule(
sameThreadExecutor(), sameThreadExecutor()), new ParserModule(),
return Guice.createInjector(new SQSRestClientModule(), new RestModule() {
@Override
protected void configure() {
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
super.configure();
}
}, new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() {
@Override
protected void configure() {
Jsr330.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder("user",
Names.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder("user",
"key").build(), "properties"));
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
}

View File

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

View File

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

View File

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

View File

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

View File

@ -59,7 +59,7 @@ public class AzureBlobStoreContextModule extends AzureBlobContextModule {
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(AzureBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class).to(
new TypeLiteral<BlobStoreContextImpl<AzureBlobAsyncClient, AzureBlobClient>>() {
new TypeLiteral<BlobStoreContextImpl<AzureBlobClient, AzureBlobAsyncClient>>() {
}).in(Scopes.SINGLETON);
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.AzureBlobClient;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.http.RequiresHttp;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
@ -35,26 +34,24 @@ import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
@RequiresHttp
public class AzureBlobContextModule extends AbstractModule {
@Override
protected void configure() {
// for converters
install(new BlobStoreObjectModule<AzureBlobAsyncClient, AzureBlobClient>(
new TypeLiteral<AzureBlobAsyncClient>() {
}, new TypeLiteral<AzureBlobClient>() {
})); install(new AzureBlobModule());
}
@Provides
@Singleton
RestContext<AzureBlobAsyncClient, AzureBlobClient> provideContext(Closer closer,
RestContext<AzureBlobClient, AzureBlobAsyncClient> provideContext(Closer closer,
AzureBlobAsyncClient asyncApi, AzureBlobClient defaultApi, @AzureBlob URI endPoint,
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
return new RestContextImpl<AzureBlobAsyncClient, AzureBlobClient>(closer, asyncApi,
return new RestContextImpl<AzureBlobClient, AzureBlobAsyncClient>(closer, asyncApi,
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.MutableBlobProperties;
import org.jclouds.azure.storage.blob.domain.internal.AzureBlobImpl;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.encryption.EncryptionService;
import com.google.inject.AbstractModule;
@ -43,6 +44,8 @@ public class AzureBlobModule extends AbstractModule {
*/
@Override
protected void configure() {
// for converters
install(new BlobStoreObjectModule());
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.blob.AzureBlobAsyncClient;
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.config.AzureStorageRestClientModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import com.google.inject.Provides;
@ -45,7 +40,18 @@ import com.google.inject.Provides;
*/
@ConfiguresRestClient
@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
@Singleton
@ -55,22 +61,4 @@ public class AzureBlobRestClientModule extends AzureStorageRestClientModule {
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 org.jclouds.azure.storage.handlers.AzureStorageClientErrorRetryHandler;
import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent;
import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
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.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
@ -46,7 +48,11 @@ import com.google.inject.Provides;
*/
@ConfiguresRestClient
@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
@TimeStamp
@ -59,7 +65,7 @@ public class AzureStorageRestClientModule extends AbstractModule {
*/
@Provides
@TimeStamp
Supplier<String> provideTimeStampCache(
protected Supplier<String> provideTimeStampCache(
@Named(PROPERTY_AZURESTORAGE_SESSIONINTERVAL) long seconds,
final DateService dateService) {
return new ExpirableSupplier<String>(new Supplier<String>() {
@ -70,11 +76,6 @@ public class AzureStorageRestClientModule extends AbstractModule {
}
@Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
}
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAzureStorageErrorFromXmlContent.class);
@ -84,7 +85,10 @@ public class AzureStorageRestClientModule extends AbstractModule {
ParseAzureStorageErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AzureStorageClientErrorRetryHandler.class);
}
}

View File

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

View File

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

View File

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

View File

@ -47,10 +47,10 @@ public class AzureQueueContextModule extends AbstractModule {
@Provides
@Singleton
RestContext<AzureQueueAsyncClient, AzureQueueClient> provideContext(Closer closer,
RestContext<AzureQueueClient, AzureQueueAsyncClient> provideContext(Closer closer,
AzureQueueAsyncClient asynchApi, AzureQueueClient defaultApi, @AzureQueue URI endPoint,
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
return new RestContextImpl<AzureQueueAsyncClient, AzureQueueClient>(closer, asynchApi,
return new RestContextImpl<AzureQueueClient, AzureQueueAsyncClient>(closer, asynchApi,
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.AzureQueueClient;
import org.jclouds.azure.storage.queue.reference.AzureQueueConstants;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import com.google.inject.Provides;
@ -42,7 +40,12 @@ import com.google.inject.Provides;
*/
@ConfiguresRestClient
@RequiresHttp
public class AzureQueueRestClientModule extends AzureStorageRestClientModule {
public class AzureQueueRestClientModule extends
AzureStorageRestClientModule<AzureQueueClient, AzureQueueAsyncClient> {
public AzureQueueRestClientModule() {
super(AzureQueueClient.class, AzureQueueAsyncClient.class);
}
@Provides
@Singleton
@ -52,17 +55,4 @@ public class AzureQueueRestClientModule extends AzureStorageRestClientModule {
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;
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.options.ListOptions.Builder.maxResults;
import static org.testng.Assert.assertEquals;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import javax.ws.rs.HttpMethod;
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.ReturnFalseIfContainerAlreadyExists;
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
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.reference.AzureStorageConstants;
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.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.config.RestModule;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
import org.testng.annotations.BeforeClass;
import com.google.inject.name.Names;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
@ -72,7 +63,7 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "azureblob.AzureBlobAsyncClientTest")
public class AzureBlobAsyncClientTest {
public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClient> {
public void testListContainers() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
@ -358,31 +349,29 @@ public class AzureBlobAsyncClientTest {
MapHttp4xxCodesToExceptions.class);
}
@BeforeClass
void setupFactory() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Jsr330.bindProperties(this.binder(), new AzureBlobPropertiesBuilder("user", "key")
.build());
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>>() {
}));
protected void checkFilters(GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
}
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;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
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.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.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.util.Jsr330;
import com.google.inject.name.Names;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -43,21 +43,13 @@ import com.google.inject.Injector;
public class AzureBlobStoreModuleTest {
Injector createInjector() {
return Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()), new JDKLoggingModule(), new AzureBlobStubClientModule(),
new AzureBlobStoreContextModule() {
return Guice.createInjector(new AzureBlobStubClientModule(),
new AzureBlobStoreContextModule(), new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()), new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT))
.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();
Names.bindProperties(binder(), checkNotNull(new AzureBlobPropertiesBuilder(
"user", "secret").build(), "properties"));
}
});
}

View File

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

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

View File

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

View File

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

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