Issue 293: refactored code to provide for api versions and coherent properties for authorization

This commit is contained in:
Adrian Cole 2010-06-28 05:07:36 -07:00
parent 35c83335d2
commit 27f4f69b4c
521 changed files with 8981 additions and 15396 deletions

View File

@ -1,56 +0,0 @@
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
#set( $ucaseProviderName = ${providerName.toUpperCase()} )
/**
*
* Copyright (C) 2010 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 ${package}.compute;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import ${package}.${providerName}ContextBuilder;
import ${package}.${providerName}PropertiesBuilder;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.io.Resources;
/**
* @author ${author}
*/
@Test(groups = "unit", testName = "compute.PropertiesTest")
public class PropertiesTest {
private Properties properties;
@BeforeTest
public void setUp() throws IOException {
properties = new Properties();
properties.load(Resources.newInputStreamSupplier(Resources.getResource("compute.properties"))
.getInput());
}
public void test${providerName}() {
assertEquals(properties.getProperty("${lcaseProviderName}.contextbuilder"),
${providerName}ContextBuilder.class.getName());
assertEquals(properties.getProperty("${lcaseProviderName}.propertiesbuilder"),
${providerName}PropertiesBuilder.class.getName());
}
}

View File

@ -47,7 +47,6 @@ import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.QueryParams;
@ -68,9 +67,8 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="https://community.emc.com/community/labs/atmos_online" /> * @see <a href="https://community.emc.com/community/labs/atmos_online" />
* @author Adrian Cole * @author Adrian Cole
*/ */
@Endpoint(AtmosStorage.class)
@RequestFilters(SignRequest.class) @RequestFilters(SignRequest.class)
@SkipEncoding( { '/' }) @SkipEncoding('/')
public interface AtmosStorageAsyncClient { public interface AtmosStorageAsyncClient {
/** /**
* Creates a default implementation of AtmosObject * Creates a default implementation of AtmosObject

View File

@ -46,13 +46,13 @@ import com.google.inject.Module;
public class AtmosStorageContextBuilder extends public class AtmosStorageContextBuilder extends
BlobStoreContextBuilder<AtmosStorageClient, AtmosStorageAsyncClient> { BlobStoreContextBuilder<AtmosStorageClient, AtmosStorageAsyncClient> {
public AtmosStorageContextBuilder(String providerName, Properties props) { public AtmosStorageContextBuilder(Properties props) {
super(providerName, AtmosStorageClient.class, AtmosStorageAsyncClient.class, props); super(AtmosStorageClient.class, AtmosStorageAsyncClient.class, props);
} }
@Override @Override
protected void addContextModule(String providerName, List<Module> modules) { protected void addContextModule(List<Module> modules) {
modules.add(new AtmosBlobStoreContextModule(providerName)); modules.add(new AtmosBlobStoreContextModule());
} }
@Override @Override

View File

@ -1,58 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.atmosonline.saas;
import java.net.URI;
import java.util.Properties;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Module;
/**
* Creates {@link AtmosBlobStoreContext} instances based on the most commonly requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see AtmosBlobStoreContext
*/
public class AtmosStorageContextFactory {
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new AtmosStorageContextBuilder("atmosstorage", new AtmosStoragePropertiesBuilder(
properties).build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(String uid, String key, Module... modules) {
return new AtmosStorageContextBuilder("atmosstorage", new AtmosStoragePropertiesBuilder(uid,
key).build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(URI endpoint, String uid, String key,
Module... modules) {
return new AtmosStorageContextBuilder("atmosstorage", new AtmosStoragePropertiesBuilder(uid,
key).withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
}
}

View File

@ -1,71 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.atmosonline.saas;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
/**
* Builds properties used in AtmosStorage Connections
*
* @author Adrian Cole
*/
public class AtmosStoragePropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_ENDPOINT,
"https://accesspoint.atmosonline.com");
properties.setProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_SESSIONINTERVAL, "60");
return properties;
}
public AtmosStoragePropertiesBuilder(Properties properties) {
super(properties);
}
public AtmosStoragePropertiesBuilder(String uid, String key) {
super();
withCredentials(uid, key);
}
public AtmosStoragePropertiesBuilder withCredentials(String uid, String key) {
properties.setProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_UID, checkNotNull(uid, "uid"));
properties.setProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY, checkNotNull(key, "key"));
return this;
}
public AtmosStoragePropertiesBuilder withEndpoint(URI endpoint) {
properties.setProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_ENDPOINT, checkNotNull(
endpoint, "endpoint").toString());
return this;
}
public AtmosStoragePropertiesBuilder withTimeStampExpiration(long seconds) {
properties.setProperty(AtmosStorageConstants.PROPERTY_EMCSAAS_SESSIONINTERVAL, seconds + "");
return this;
}
}

View File

@ -52,7 +52,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.concurrent.ConcurrentUtils; import org.jclouds.concurrent.ConcurrentUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
@ -78,7 +78,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider; private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider;
@Inject @Inject
AtmosAsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
Location defaultLocation, Set<? extends Location> locations, Location defaultLocation, Set<? extends Location> locations,

View File

@ -43,7 +43,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.internal.BaseBlobStore;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
@ -64,7 +64,7 @@ public class AtmosBlobStore extends BaseBlobStore {
private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider; private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider;
@Inject @Inject
AtmosBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, Location defaultLocation, AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Location defaultLocation,
Set<? extends Location> locations, AtmosStorageClient sync, ObjectToBlob object2Blob, Set<? extends Location> locations, AtmosStorageClient sync, ObjectToBlob object2Blob,
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
BlobStoreListOptionsToListOptions container2ContainerListOptions, BlobStoreListOptionsToListOptions container2ContainerListOptions,

View File

@ -27,7 +27,6 @@ import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore; import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore;
import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStore; import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStore;
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata; import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
import org.jclouds.atmosonline.saas.config.AtmosStorageContextModule;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
@ -38,8 +37,10 @@ import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.rest.annotations.Provider;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -49,16 +50,11 @@ import com.google.inject.TypeLiteral;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class AtmosBlobStoreContextModule extends AtmosStorageContextModule { public class AtmosBlobStoreContextModule extends AbstractModule {
private final String providerName;
public AtmosBlobStoreContextModule(String providerName) {
this.providerName = providerName;
}
@Override @Override
protected void configure() { protected void configure() {
super.configure();
install(new BlobStoreMapModule()); install(new BlobStoreMapModule());
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL); bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).in(Scopes.SINGLETON); bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).in(Scopes.SINGLETON);
@ -72,7 +68,7 @@ public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
@Provides @Provides
@Singleton @Singleton
Location getLocation() { Location getLocation(@Provider String providerName) {
return new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); return new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
} }

View File

@ -1,62 +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 java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.AtmosStorage;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.http.RequiresHttp;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.HttpAsyncClient;
import org.jclouds.rest.HttpClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
*
* @author Adrian Cole
*/
@RequiresHttp
public class AtmosStorageContextModule extends AbstractModule {
@Override
protected void configure() {
}
@Provides
@Singleton
RestContext<AtmosStorageClient, AtmosStorageAsyncClient> provideContext(
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
AtmosStorageAsyncClient async, AtmosStorageClient defaultApi,
@AtmosStorage URI endPoint,
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) {
return new RestContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>(
closer, http, asyncHttp, defaultApi, async, endPoint, account);
}
}

View File

@ -18,16 +18,11 @@
*/ */
package org.jclouds.atmosonline.saas.config; package org.jclouds.atmosonline.saas.config;
import static org.jclouds.atmosonline.saas.reference.AtmosStorageConstants.PROPERTY_EMCSAAS_ENDPOINT;
import static org.jclouds.atmosonline.saas.reference.AtmosStorageConstants.PROPERTY_EMCSAAS_SESSIONINTERVAL;
import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.AtmosStorage; import org.jclouds.Constants;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient; import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient; import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler; import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler;
@ -41,6 +36,8 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
@ -63,17 +60,11 @@ public class AtmosStorageRestClientModule extends
@Override @Override
protected void configure() { protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
install(new AtmosObjectModule()); install(new AtmosObjectModule());
super.configure(); super.configure();
} }
@Provides
@Singleton
@AtmosStorage
protected URI provideAuthenticationURI(@Named(PROPERTY_EMCSAAS_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Provides @Provides
@TimeStamp @TimeStamp
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) { protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
@ -85,7 +76,7 @@ public class AtmosStorageRestClientModule extends
*/ */
@Provides @Provides
@TimeStamp @TimeStamp
Supplier<String> provideTimeStampCache(@Named(PROPERTY_EMCSAAS_SESSIONINTERVAL) long seconds, Supplier<String> provideTimeStampCache(@Named(Constants.PROPERTY_SESSION_INTERVAL) long seconds,
final DateService dateService) { final DateService dateService) {
return new ExpirableSupplier<String>(new Supplier<String>() { return new ExpirableSupplier<String>(new Supplier<String>() {
public String get() { public String get() {

View File

@ -18,6 +18,9 @@
*/ */
package org.jclouds.atmosonline.saas.filters; package org.jclouds.atmosonline.saas.filters;
import static org.jclouds.Constants.LOGGER_SIGNATURE;
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.util.Patterns.NEWLINE_PATTERN; import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN; import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN;
@ -33,8 +36,6 @@ import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants;
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders; import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
@ -67,13 +68,12 @@ public class SignRequest implements HttpRequestFilter {
Logger logger = Logger.NULL; Logger logger = Logger.NULL;
@Resource @Resource
@Named(Constants.LOGGER_SIGNATURE) @Named(LOGGER_SIGNATURE)
Logger signatureLog = Logger.NULL; Logger signatureLog = Logger.NULL;
@Inject @Inject
public SignRequest(SignatureWire signatureWire, public SignRequest(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String uid,
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String uid, @Named(PROPERTY_CREDENTIAL) String encodedKey,
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY) String encodedKey,
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) { @TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
this.signatureWire = signatureWire; this.signatureWire = signatureWire;
this.uid = uid; this.uid = uid;

View File

@ -1,36 +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.reference;
/**
* Configuration properties and constants used in AtmosStorage connections.
*
* @author Adrian Cole
*/
public interface AtmosStorageConstants {
public static final String PROPERTY_EMCSAAS_ENDPOINT = "jclouds.emcsaas.endpoint";
public static final String PROPERTY_EMCSAAS_UID = "jclouds.emcsaas.uid";
public static final String PROPERTY_EMCSAAS_KEY = "jclouds.emcsaas.key";
/**
* how long do we wait before obtaining a new timestamp for requests. Clocks must be within 5m of
* Atmos.
*/
public static final String PROPERTY_EMCSAAS_SESSIONINTERVAL = "jclouds.emcsaas.sessioninterval";
}

View File

@ -40,16 +40,18 @@ import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.inject.name.Names;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -275,26 +277,34 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
@BeforeClass @BeforeClass
@Override @Override
protected void setupFactory() { protected void setupFactory() throws IOException {
super.setupFactory(); super.setupFactory();
blobToObject = injector.getInstance(BlobToObject.class); blobToObject = injector.getInstance(BlobToObject.class);
} }
@Override @Override
protected Module createModule() { protected Module createModule() {
return new AtmosStorageRestClientModule() { return new TestAtmosStorageRestClientModule();
@Override
protected void configure() {
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";
}
};
} }
@RequiresHttp
@ConfiguresRestClient
private static final class TestAtmosStorageRestClientModule extends AtmosStorageRestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "Thu, 05 Jun 2008 16:38:19 GMT";
}
}
@Override
public ContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("atmosonline", "identity", "credential",
new Properties());
}
} }

View File

@ -0,0 +1,49 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.atmosonline.saas;
import org.jclouds.blobstore.util.BlobStoreUtils;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*
*/
@Test(groups = "unit")
public class ProvidersInPropertiesTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Utils.getSupportedProviders();
assert Iterables.contains(providers, "atmosonline") : providers;
assert Iterables.contains(providers, "synaptic") : providers;
}
@Test
public void testSupportedBlobStoreProviders() {
Iterable<String> providers = BlobStoreUtils.getSupportedProviders();
assert Iterables.contains(providers, "atmosonline") : providers;
assert Iterables.contains(providers, "synaptic") : providers;
}
}

View File

@ -18,23 +18,20 @@
*/ */
package org.jclouds.atmosonline.saas.blobstore.config; package org.jclouds.atmosonline.saas.blobstore.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata; import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.logging.config.NullLoggingModule;
import com.google.inject.name.Names; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestClientTest.MockModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -43,16 +40,10 @@ import com.google.inject.Injector;
public class AtmosBlobStoreModuleTest { public class AtmosBlobStoreModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new AtmosStorageStubClientModule(), return new RestContextFactory().createContextBuilder("atmosonline", "uid", "key", ImmutableSet
new AtmosBlobStoreContextModule("atmos"), new ExecutorServiceModule(sameThreadExecutor(), .<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
sameThreadExecutor()), new AbstractModule() {
@Override
protected void configure() {
Names.bindProperties(binder(), checkNotNull(new AtmosStoragePropertiesBuilder(
"user", "key").build(), "properties"));
}
});
} }
@Test @Test
void testContextImpl() { void testContextImpl() {

View File

@ -26,8 +26,8 @@ import org.testng.annotations.Test;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageContainerIntegrationTest") @Test(groups = "live", testName = "emcsaas.AtmosStorageContainerIntegrationTest")
public class AtmosStorageContainerIntegrationTest extends BaseContainerIntegrationTest { public class AtmosStorageContainerIntegrationLiveTest extends BaseContainerIntegrationTest {
@Override @Override
public void testListContainerMaxResults() throws InterruptedException, public void testListContainerMaxResults() throws InterruptedException,

View File

@ -27,8 +27,8 @@ import org.testng.annotations.Test;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageInputStreamMapIntegrationTest") @Test(groups = "live", testName = "emcsaas.AtmosStorageInputStreamMapIntegrationTest")
public class AtmosStorageInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest { public class AtmosStorageInputStreamMapIntegrationLiveTest extends BaseInputStreamMapIntegrationTest {
@Override @Override
@Test(enabled = false) @Test(enabled = false)

View File

@ -27,7 +27,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageIntegrationTest") @Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageIntegrationTest")
public class AtmosStorageIntegrationTest extends BaseBlobIntegrationTest { public class AtmosStorageIntegrationLiveTest extends BaseBlobIntegrationTest {
@DataProvider(name = "delete") @DataProvider(name = "delete")
// no unicode support // no unicode support

View File

@ -24,7 +24,7 @@ import org.testng.annotations.Test;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageMapIntegrationTest") @Test(groups = "live", testName = "emcsaas.AtmosStorageMapIntegrationTest")
public class AtmosStorageMapIntegrationTest extends BaseBlobMapIntegrationTest { public class AtmosStorageMapIntegrationLiveTest extends BaseBlobMapIntegrationTest {
} }

View File

@ -24,7 +24,7 @@ import org.testng.annotations.Test;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = { "integration", "live" }, testName = "emcsaas.AtmosStorageServiceIntegrationTest") @Test(groups = "live", testName = "emcsaas.AtmosStorageServiceIntegrationTest")
public class AtmosStorageServiceIntegrationTest extends BaseServiceIntegrationTest { public class AtmosStorageServiceIntegrationLiveTest extends BaseServiceIntegrationTest {
} }

View File

@ -21,11 +21,9 @@ package org.jclouds.atmosonline.saas.blobstore.integration;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import org.jclouds.atmosonline.saas.AtmosStorageContextFactory;
import org.jclouds.atmosonline.saas.config.AtmosStorageStubClientModule;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory; import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.integration.internal.BaseTestInitializer; import org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -35,7 +33,7 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class AtmosStorageTestInitializer extends BaseTestInitializer { public class AtmosStorageTestInitializer extends TransientBlobStoreTestInitializer {
@Override @Override
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app, protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
@ -44,10 +42,4 @@ public class AtmosStorageTestInitializer extends BaseTestInitializer {
.of(configurationModule, new Log4JLoggingModule()), new Properties()); .of(configurationModule, new Log4JLoggingModule()), new Properties());
} }
@Override
protected BlobStoreContext createStubContext() {
return AtmosStorageContextFactory.createContext("user", "pass",
new AtmosStorageStubClientModule());
}
} }

View File

@ -1,58 +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 java.net.URI;
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.http.functions.config.ParserModule;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
/**
* adds a stub alternative to invoking AtmosStorage
*
* @author Adrian Cole
*/
@ConfiguresRestClient
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(URI.class).annotatedWith(AtmosStorage.class).toInstance(
URI.create("https://localhost/atmosstub"));
}
@Override
protected void bindAsyncClient() {
bind(AtmosStorageAsyncClient.class).to(StubAtmosStorageAsyncClient.class).asEagerSingleton();
}
}

View File

@ -18,43 +18,40 @@
*/ */
package org.jclouds.atmosonline.saas.filters; package org.jclouds.atmosonline.saas.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Properties;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.atmosonline.saas.AtmosStoragePropertiesBuilder;
import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule; import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders; import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.config.RestModule; import org.jclouds.logging.config.NullLoggingModule;
import com.google.inject.name.Names; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestClientTest.MockModule;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.inject.AbstractModule; import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
@Test(groups = "unit", testName = "emcsaas.SignRequestTest") @Test(groups = "unit", testName = "emcsaas.SignRequestTest")
public class SignRequestTest { public class SignRequestTest {
private static final String KEY = "LJLuryj6zs8ste6Y3jTGQp71xq0="; private static final String KEY = "LJLuryj6zs8ste6Y3jTGQp71xq0=";
private Injector injector;
private SignRequest filter; private SignRequest filter;
@Test @Test
@ -84,24 +81,31 @@ public class SignRequestTest {
@BeforeClass @BeforeClass
protected void createFilter() { protected void createFilter() {
injector = Guice.createInjector(new RestModule(), new AtmosStorageRestClientModule() { Injector injector = new RestContextFactory().createContextBuilder(
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) { "atmosonline",
return "Thu, 05 Jun 2008 16:38:19 GMT"; "user",
KEY,
ImmutableSet.<Module> of(new MockModule(), new TestAtmosStorageRestClientModule(),
new NullLoggingModule()), new Properties()).buildInjector();
}
}, new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()),
new AbstractModule() {
protected void configure() {
Names.bindProperties(binder(), checkNotNull(
new AtmosStoragePropertiesBuilder("user", KEY)).build());
bind(TransformingHttpCommandExecutorService.class).toInstance(
createMock(TransformingHttpCommandExecutorService.class));
}
});
filter = injector.getInstance(SignRequest.class); filter = injector.getInstance(SignRequest.class);
} }
@RequiresHttp
@ConfiguresRestClient
private static final class TestAtmosStorageRestClientModule extends AtmosStorageRestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "Thu, 05 Jun 2008 16:38:19 GMT";
}
}
public HttpRequest newRequest() { public HttpRequest newRequest() {
HttpRequest request = new HttpRequest("POST", URI.create("http://localhost/rest/objects")); HttpRequest request = new HttpRequest("POST", URI.create("http://localhost/rest/objects"));
request.getHeaders().put(AtmosStorageHeaders.LISTABLE_META, "part4/part7/part8=quick"); request.getHeaders().put(AtmosStorageHeaders.LISTABLE_META, "part4/part7/part8=quick");

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.aws.ec2; package org.jclouds.aws;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -34,6 +34,6 @@ import javax.inject.Qualifier;
@Retention(value = RetentionPolicy.RUNTIME) @Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) @Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier @Qualifier
public @interface EC2 { public @interface Region {
} }

View File

@ -0,0 +1,70 @@
/**
*
* 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.config;
import java.util.Date;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.config.AWSRestClientModule;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner;
import com.google.inject.Provides;
/**
* Configures the S3 connection, including logging and http transport.
*
* @author Adrian Cole
*/
@ConfiguresRestClient
@RequiresHttp
public class AWSFormSigningRestClientModule<S, A> extends AWSRestClientModule<S, A> {
public AWSFormSigningRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegates) {
super(syncClientType, asyncClientType, delegates);
}
public AWSFormSigningRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
@Provides
@TimeStamp
protected String provideTimeStamp(final DateService dateService,
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) {
return dateService.iso8601DateFormat(new Date(System.currentTimeMillis()
+ (expiration * 1000)));
}
@Provides
@Singleton
RequestSigner provideRequestSigner(FormSigner in) {
return in;
}
}

View File

@ -0,0 +1,126 @@
/**
*
* 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.config;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.Region;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
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.annotations.Provider;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.name.Names;
/**
* Configures the S3 connection, including logging and http transport.
*
* @author Adrian Cole
*/
@ConfiguresRestClient
@RequiresHttp
public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
public AWSRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegates) {
super(syncClientType, asyncClientType, delegates);
}
public AWSRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
@Provides
@Singleton
@Region
protected Map<String, URI> provideRegions(Injector injector) {
String regionString = injector.getInstance(Key.get(String.class, Names
.named(PROPERTY_REGIONS)));
Map<String, URI> regions = Maps.newLinkedHashMap();
for (String region : Splitter.on(',').split(regionString)) {
regions.put(region, URI.create(injector.getInstance(Key.get(String.class, Names
.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
}
return regions;
}
@Provides
@Singleton
@Region
protected Set<String> provideRegions(@Region Map<String, URI> map) {
return map.keySet();
}
@Provides
@Singleton
@Region
protected String getDefaultRegion(@Provider final URI uri, @Region Map<String, URI> map) {
return Iterables.find(map.entrySet(), new Predicate<Entry<String, URI>>() {
@Override
public boolean apply(Entry<String, URI> input) {
return input.getValue().equals(uri);
}
}).getKey();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
ParseAWSErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AWSClientErrorRetryHandler.class);
}
}

View File

@ -0,0 +1,72 @@
/**
*
* 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.config;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.Region;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class DefaultLocationProvider implements javax.inject.Provider<Location> {
private final String region;
private final Set<? extends Location> set;
@Inject
DefaultLocationProvider(@Region final String region, Set<? extends Location> set) {
this.region = region;
this.set = set;
}
@Override
@Singleton
public Location get() {
try {
Location toReturn = Iterables.find(set, new Predicate<Location>() {
@Override
public boolean apply(Location input) {
switch (input.getScope()) {
case ZONE:
return input.getParent().getId().equals(region);
case REGION:
return input.getId().equals(region);
default:
return false;
}
}
});
return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent();
} catch (NoSuchElementException e) {
throw new IllegalStateException(String.format("region: %s not found in %s", region, set));
}
}
}

View File

@ -16,48 +16,58 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.mezeo.pcs2.config; package org.jclouds.aws.ec2;
import java.net.URI; import java.io.Closeable;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.elb.ELBAsyncClient;
import org.jclouds.aws.elb.ELBClient;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.jclouds.mezeo.pcs2.PCS;
import org.jclouds.mezeo.pcs2.PCSAsyncClient;
import org.jclouds.mezeo.pcs2.PCSClient;
import org.jclouds.mezeo.pcs2.reference.PCSConstants;
import org.jclouds.rest.HttpAsyncClient;
import org.jclouds.rest.HttpClient;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.rest.RestContextFactory;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
* Configures the PCS connection, including logging and http transport.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class PCSContextModule extends AbstractModule { public class ConfigureELBModule extends AbstractModule {
public PCSContextModule(String providerName) { private final Iterable<Module> infra;
private final Properties properties;
ConfigureELBModule(Iterable<Module> infra, Properties properties) {
this.infra = infra;
this.properties = properties;
} }
@Override @Override
protected void configure() { protected void configure() {
} }
/**
* setup ELB with the same parameters as EC2
*/
@Provides @Provides
@Singleton @Singleton
RestContext<PCSClient, PCSAsyncClient> provideContext(Closer closer, ELBClient provideELBClient(Closer closer) {
HttpClient http, HttpAsyncClient asyncHttp, PCSAsyncClient async, final RestContext<ELBClient, ELBAsyncClient> context = new RestContextFactory()
PCSClient defaultApi, @PCS URI endPoint, .createContext("elb", infra, properties);
@Named(PCSConstants.PROPERTY_PCS2_USER) String account) { closer.addToClose(new Closeable() {
return new RestContextImpl<PCSClient, PCSAsyncClient>(closer, http,
asyncHttp, defaultApi, async, endPoint, account);
}
@Override
public void close() {
if (context != null)
context.close();
}
});
return context.getApi();
}
} }

View File

@ -22,7 +22,6 @@ import org.jclouds.aws.ec2.services.AMIAsyncClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient; import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient; import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient; 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.InstanceAsyncClient;
import org.jclouds.aws.ec2.services.KeyPairAsyncClient; import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringAsyncClient; import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
@ -35,6 +34,8 @@ import org.jclouds.rest.annotations.Delegate;
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface EC2AsyncClient { public interface EC2AsyncClient {
public final static String VERSION = "2009-11-30";
/** /**
* Provides asynchronous access to AMI services. * Provides asynchronous access to AMI services.
*/ */
@ -83,9 +84,4 @@ public interface EC2AsyncClient {
@Delegate @Delegate
ElasticBlockStoreAsyncClient getElasticBlockStoreServices(); ElasticBlockStoreAsyncClient getElasticBlockStoreServices();
/**
* Provides asynchronous access to Elastic Load Balancer services.
*/
@Delegate
ElasticLoadBalancerAsyncClient getElasticLoadBalancerServices();
} }

View File

@ -24,7 +24,6 @@ import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionClient; import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreClient; import org.jclouds.aws.ec2.services.ElasticBlockStoreClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressClient; 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.InstanceClient;
import org.jclouds.aws.ec2.services.KeyPairClient; import org.jclouds.aws.ec2.services.KeyPairClient;
import org.jclouds.aws.ec2.services.MonitoringClient; import org.jclouds.aws.ec2.services.MonitoringClient;
@ -87,9 +86,4 @@ public interface EC2Client {
@Delegate @Delegate
ElasticBlockStoreClient getElasticBlockStoreServices(); ElasticBlockStoreClient getElasticBlockStoreServices();
/**
* Provides synchronous access to Elastic Load Balancer services.
*/
@Delegate
ElasticLoadBalancerClient getElasticLoadBalancerServices();
} }

View File

@ -18,16 +18,26 @@
*/ */
package org.jclouds.aws.ec2; package org.jclouds.aws.ec2;
import static com.google.common.base.Predicates.instanceOf;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException;
import java.util.Properties; import java.util.Properties;
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule; import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule;
import org.jclouds.aws.ec2.compute.config.EC2ResolveImagesModule; import org.jclouds.aws.ec2.compute.config.EC2ResolveImagesModule;
import org.jclouds.aws.ec2.config.EC2RestClientModule; import org.jclouds.aws.ec2.config.EC2RestClientModule;
import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.concurrent.config.ConfiguresExecutorService;
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.config.LoggingModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
@ -46,8 +56,8 @@ import com.google.inject.Module;
*/ */
public class EC2ContextBuilder extends ComputeServiceContextBuilder<EC2Client, EC2AsyncClient> { public class EC2ContextBuilder extends ComputeServiceContextBuilder<EC2Client, EC2AsyncClient> {
public EC2ContextBuilder(String providerName, Properties props) { public EC2ContextBuilder(Properties props) {
super(providerName, EC2Client.class, EC2AsyncClient.class, props); super(EC2Client.class, EC2AsyncClient.class, props);
} }
@Override @Override
@ -56,8 +66,8 @@ public class EC2ContextBuilder extends ComputeServiceContextBuilder<EC2Client, E
} }
@Override @Override
protected void addContextModule(String providerName, List<Module> modules) { protected void addContextModule(List<Module> modules) {
modules.add(new EC2ComputeServiceContextModule(providerName)); modules.add(new EC2ComputeServiceContextModule());
} }
@Override @Override
@ -69,4 +79,23 @@ public class EC2ContextBuilder extends ComputeServiceContextBuilder<EC2Client, E
protected void addImageResolutionModule() { protected void addImageResolutionModule() {
modules.add(new EC2ResolveImagesModule()); modules.add(new EC2ResolveImagesModule());
} }
@Override
public Injector buildInjector() {
try {
Iterables.find(modules, Predicates.instanceOf(ConfigureELBModule.class));
} catch (NoSuchElementException e) {
Iterable<Module> infra = Iterables.filter(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ConfiguresExecutorService.class)
|| input.getClass().isAnnotationPresent(
ConfiguresHttpCommandExecutorService.class)
|| instanceOf(LoggingModule.class).apply(input);
}
});
modules.add(new ConfigureELBModule(infra, properties));
}
return super.buildInjector();
}
} }

View File

@ -1,68 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2;
import java.net.URI;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Module;
/**
* Creates {@link EC2ComputeServiceContext} instances based on the most commonly requested
* arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see EC2ComputeServiceContext
*/
public class EC2ContextFactory {
public static ComputeServiceContext createContext(Properties properties, Module... modules) {
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(properties).build())
.withModules(modules).buildComputeServiceContext();
}
public static ComputeServiceContext createContext(String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildComputeServiceContext();
}
public static ComputeServiceContext createContext(Properties properties, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
.buildComputeServiceContext();
}
public static ComputeServiceContext createContext(URI endpoint, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
.buildComputeServiceContext();
}
}

View File

@ -18,14 +18,11 @@
*/ */
package org.jclouds.aws.ec2; package org.jclouds.aws.ec2;
import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.aws.ec2.reference.EC2Constants.*; import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_ENDPOINT; import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_ELB_ENDPOINT;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_EXPIREINTERVAL;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY;
import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.PropertiesBuilder; import org.jclouds.PropertiesBuilder;
@ -39,17 +36,18 @@ public class EC2PropertiesBuilder extends PropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_EC2_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_API_VERSION, EC2AsyncClient.VERSION);
properties.setProperty(PROPERTY_ELB_ENDPOINT, properties.setProperty(PROPERTY_ELB_ENDPOINT,
"https://elasticloadbalancing.us-east-1.amazonaws.com"); "https://elasticloadbalancing.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, "60");
// alestic, canonical, and rightscale // alestic, canonical, and rightscale
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "063491364108,099720109477,411009282317"); properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "063491364108,099720109477,411009282317");
// auth fail sometimes happens in EC2, as the rc.local script that injects the // auth fail sometimes happens in EC2, as the rc.local script that injects the
// authorized key executes after ssh has started // authorized key executes after ssh has started
properties.setProperty("jclouds.ssh.max_retries", "6"); properties.setProperty("jclouds.ssh.max_retries", "6");
properties.setProperty("jclouds.ssh.retryable_messages", properties
"Auth fail,invalid data,End of IO Stream Read,Connection reset,socket is not established"); .setProperty("jclouds.ssh.retryable_messages",
"Auth fail,invalid data,End of IO Stream Read,Connection reset,socket is not established");
return properties; return properties;
} }
@ -57,25 +55,7 @@ public class EC2PropertiesBuilder extends PropertiesBuilder {
super(properties); super(properties);
} }
public EC2PropertiesBuilder(String id, String secret) { public EC2PropertiesBuilder() {
super(); super();
withCredentials(id, secret);
}
public EC2PropertiesBuilder withCredentials(String id, String secret) {
properties.setProperty(PROPERTY_AWS_ACCESSKEYID, checkNotNull(id, "awsAccessKeyId"));
properties.setProperty(PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(secret,
"awsSecretAccessKey"));
return this;
}
public EC2PropertiesBuilder withEndpoint(URI endpoint) {
properties.setProperty(PROPERTY_EC2_ENDPOINT, checkNotNull(endpoint, "endpoint").toString());
return this;
}
public EC2PropertiesBuilder withRequestExpiration(long seconds) {
properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, seconds + "");
return this;
} }
} }

View File

@ -1,39 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a ELB resource.
*
* @author Lili Nader
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface ELB {
}

View File

@ -18,8 +18,8 @@
*/ */
package org.jclouds.aws.ec2; package org.jclouds.aws.ec2;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_ENDPOINT;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_PORT_OPEN; import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_PORT_OPEN;
import java.util.Properties; import java.util.Properties;
@ -33,8 +33,8 @@ public class EucalyptusPropertiesBuilder extends EC2PropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_EC2_ENDPOINT, properties.setProperty(PROPERTY_ENDPOINT,
"http://ecc.eucalyptus.com:8773/services/Eucalyptus"); "http://ecc.eucalyptus.com:8773/services/Eucalyptus");
// TODO // TODO
// properties.setProperty(PROPERTY_ELB_ENDPOINT, // properties.setProperty(PROPERTY_ELB_ENDPOINT,
// "https://elasticloadbalancing.us-east-1.amazonaws.com"); // "https://elasticloadbalancing.us-east-1.amazonaws.com");
@ -48,7 +48,4 @@ public class EucalyptusPropertiesBuilder extends EC2PropertiesBuilder {
super(properties); super(properties);
} }
public EucalyptusPropertiesBuilder(String id, String secret) {
super(id, secret);
}
} }

View File

@ -44,7 +44,8 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.config.DefaultLocationProvider;
import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.EC2ComputeService; import org.jclouds.aws.ec2.compute.EC2ComputeService;
@ -61,7 +62,6 @@ import org.jclouds.aws.ec2.compute.strategy.EC2DestroyLoadBalancerStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyNodeStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2DestroyNodeStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2LoadBalanceNodesStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2LoadBalanceNodesStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
import org.jclouds.aws.ec2.config.EC2ContextModule;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.domain.Image.ImageType; import org.jclouds.aws.ec2.domain.Image.ImageType;
@ -95,6 +95,9 @@ import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.annotations.Provider;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -106,58 +109,49 @@ import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.name.Names; import com.google.inject.name.Names;
/** /**
* Configures the {@link ComputeServiceContext}; requires * Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound.
* {@link EC2ComputeService} bound.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class EC2ComputeServiceContextModule extends EC2ContextModule { public class EC2ComputeServiceContextModule extends AbstractModule {
private final String providerName;
public EC2ComputeServiceContextModule(String providerName) {
this.providerName = providerName;
}
@Provides @Provides
@Singleton @Singleton
@Named("PRESENT") @Named("PRESENT")
protected Predicate<RunningInstance> instancePresent(InstancePresent present) { protected Predicate<RunningInstance> instancePresent(InstancePresent present) {
return new RetryablePredicate<RunningInstance>(present, 3000, 200, return new RetryablePredicate<RunningInstance>(present, 3000, 200, TimeUnit.MILLISECONDS);
TimeUnit.MILLISECONDS);
} }
@Override @Override
protected void configure() { protected void configure() {
super.configure();
install(new ComputeServiceTimeoutsModule()); install(new ComputeServiceTimeoutsModule());
bind(Location.class).toProvider(DefaultLocationProvider.class).in(Scopes.SINGLETON);
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class); bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
bind(TemplateOptions.class).to(EC2TemplateOptions.class); bind(TemplateOptions.class).to(EC2TemplateOptions.class);
bind(ComputeService.class).to(EC2ComputeService.class); bind(ComputeService.class).to(EC2ComputeService.class);
bind(new TypeLiteral<ComputeServiceContext>() { bind(new TypeLiteral<ComputeServiceContext>() {
}) }).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
.to( }).in(Scopes.SINGLETON);
new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() { bind(new TypeLiteral<RestContext<EC2Client, EC2AsyncClient>>() {
}).in(Scopes.SINGLETON); }).to(new TypeLiteral<RestContextImpl<EC2Client, EC2AsyncClient>>() {
bind(LoadBalanceNodesStrategy.class) }).in(Scopes.SINGLETON);
.to(EC2LoadBalanceNodesStrategy.class); bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class);
bind(DestroyLoadBalancerStrategy.class).to( bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class);
EC2DestroyLoadBalancerStrategy.class); bind(RunNodesAndAddToSetStrategy.class).to(EC2RunNodesAndAddToSetStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(
EC2RunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(EC2ListNodesStrategy.class); bind(ListNodesStrategy.class).to(EC2ListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class); bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class); bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class); bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() { bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() {
}).annotatedWith(Names.named("volumeMapping")).to( }).annotatedWith(Names.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class)
RunningInstanceToStorageMappingUnix.class).in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
} }
@Provides @Provides
@ -176,12 +170,10 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides @Provides
@Named("DEFAULT") @Named("DEFAULT")
protected TemplateBuilder provideTemplate(@EC2 String region, protected TemplateBuilder provideTemplate(@Region String region, TemplateBuilder template) {
TemplateBuilder template) { return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template
return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() .architecture(Architecture.X86_32).osFamily(UBUNTU).imageNameMatches(".*10\\.?04.*")
: template.architecture(Architecture.X86_32).osFamily(UBUNTU) .osDescriptionMatches("^ubuntu-images.*");
.imageNameMatches(".*10\\.?04.*").osDescriptionMatches(
"^ubuntu-images.*");
} }
// TODO make this more efficient for listNodes(); currently // TODO make this more efficient for listNodes(); currently
@ -199,10 +191,9 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
private final ExecutorService executor; private final ExecutorService executor;
@Inject @Inject
protected EC2ListNodesStrategy(EC2Client client, protected EC2ListNodesStrategy(EC2Client client, @Region Map<String, URI> regionMap,
@EC2 Map<String, URI> regionMap, RunningInstanceToNodeMetadata runningInstanceToNodeMetadata,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = client; this.client = client;
this.regionMap = regionMap; this.regionMap = regionMap;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata; this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
@ -216,44 +207,42 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Override @Override
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching( public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
Predicate<ComputeMetadata> filter) { Predicate<ComputeMetadata> filter) {
final Set<NodeMetadata> nodes = Sets.newHashSet(); final Set<NodeMetadata> nodes = Sets.newHashSet();
Map<String, ListenableFuture<?>> parallelResponses = Maps.newHashMap(); Map<String, ListenableFuture<?>> parallelResponses = Maps.newHashMap();
for (final String region : regionMap.keySet()) { for (final String region : regionMap.keySet()) {
parallelResponses.put(region, ConcurrentUtils.makeListenable( parallelResponses.put(region, ConcurrentUtils.makeListenable(executor
executor.submit(new Callable<Void>() { .submit(new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
Iterables.addAll(nodes, Iterables.transform(Iterables Iterables.addAll(nodes, Iterables.transform(Iterables.concat(client
.concat(client.getInstanceServices() .getInstanceServices().describeInstancesInRegion(region)),
.describeInstancesInRegion(region)), runningInstanceToNodeMetadata));
runningInstanceToNodeMetadata)); return null;
return null; }
} }), executor));
}), executor));
} }
Map<String, Exception> exceptions = awaitCompletion(parallelResponses, Map<String, Exception> exceptions = awaitCompletion(parallelResponses, executor, null,
executor, null, logger, "nodes"); logger, "nodes");
if (exceptions.size() > 0) if (exceptions.size() > 0)
throw new RuntimeException(String.format( throw new RuntimeException(String.format("error parsing nodes in regions: %s",
"error parsing nodes in regions: %s", exceptions)); exceptions));
return Iterables.filter(nodes, filter); return Iterables.filter(nodes, filter);
} }
} }
@Singleton @Singleton
public static class EC2GetNodeMetadataStrategy implements public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
GetNodeMetadataStrategy {
private final EC2Client client; private final EC2Client client;
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata; private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
@Inject @Inject
protected EC2GetNodeMetadataStrategy(EC2Client client, protected EC2GetNodeMetadataStrategy(EC2Client client,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) { RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
this.client = client; this.client = client;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata; this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
} }
@ -265,8 +254,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
String instanceId = parts[1]; String instanceId = parts[1];
try { try {
RunningInstance runningInstance = Iterables RunningInstance runningInstance = Iterables
.getOnlyElement(getAllRunningInstancesInRegion(client .getOnlyElement(getAllRunningInstancesInRegion(client.getInstanceServices(),
.getInstanceServices(), region, instanceId)); region, instanceId));
return runningInstanceToNodeMetadata.apply(runningInstance); return runningInstanceToNodeMetadata.apply(runningInstance);
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
return null; return null;
@ -281,8 +270,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
private final GetNodeMetadataStrategy getNode; private final GetNodeMetadataStrategy getNode;
@Inject @Inject
protected EC2RebootNodeStrategy(EC2Client client, protected EC2RebootNodeStrategy(EC2Client client, GetNodeMetadataStrategy getNode) {
GetNodeMetadataStrategy getNode) {
this.client = client.getInstanceServices(); this.client = client.getInstanceServices();
this.getNode = getNode; this.getNode = getNode;
} }
@ -300,8 +288,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides @Provides
@Singleton @Singleton
protected final Map<RegionAndName, KeyPair> credentialsMap( protected final Map<RegionAndName, KeyPair> credentialsMap(CreateUniqueKeyPair in) {
CreateUniqueKeyPair in) {
// doesn't seem to clear when someone issues remove(key) // doesn't seem to clear when someone issues remove(key)
// return new MapMaker().makeComputingMap(in); // return new MapMaker().makeComputingMap(in);
return Maps.newLinkedHashMap(); return Maps.newLinkedHashMap();
@ -309,8 +296,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides @Provides
@Singleton @Singleton
protected final Map<RegionAndName, String> securityGroupMap( protected final Map<RegionAndName, String> securityGroupMap(CreateSecurityGroupIfNeeded in) {
CreateSecurityGroupIfNeeded in) {
// doesn't seem to clear when someone issues remove(key) // doesn't seem to clear when someone issues remove(key)
// return new MapMaker().makeComputingMap(in); // return new MapMaker().makeComputingMap(in);
return Maps.newLinkedHashMap(); return Maps.newLinkedHashMap();
@ -330,43 +316,26 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides @Provides
@Singleton @Singleton
Set<? extends Size> provideSizes() { Set<? extends Size> provideSizes() {
return ImmutableSet.of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, return ImmutableSet.of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE,
EC2Size.M1_LARGE, EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE,
EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE); EC2Size.M2_4XLARGE);
} }
@Provides @Provides
@Singleton @Singleton
Set<? extends Location> provideLocations( Set<? extends Location> provideLocations(Map<String, String> availabilityZoneToRegionMap,
Map<String, String> availabilityZoneToRegionMap) { @Provider String providerName) {
Location ec2 = new LocationImpl(LocationScope.PROVIDER, providerName, Location ec2 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
providerName, null);
Set<Location> locations = Sets.newLinkedHashSet(); Set<Location> locations = Sets.newLinkedHashSet();
for (String zone : availabilityZoneToRegionMap.keySet()) { for (String zone : availabilityZoneToRegionMap.keySet()) {
Location region = new LocationImpl(LocationScope.REGION, Location region = new LocationImpl(LocationScope.REGION, availabilityZoneToRegionMap
availabilityZoneToRegionMap.get(zone), .get(zone), availabilityZoneToRegionMap.get(zone), ec2);
availabilityZoneToRegionMap.get(zone), ec2);
locations.add(region); locations.add(region);
locations locations.add(new LocationImpl(LocationScope.ZONE, zone, zone, region));
.add(new LocationImpl(LocationScope.ZONE, zone, zone, region));
} }
return locations; return locations;
} }
@Provides
@Singleton
Location getDefaultLocation(@EC2 final String region,
Set<? extends Location> set) {
return Iterables.find(set, new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getId().equals(region);
}
});
}
private static class LogHolder { private static class LogHolder {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -383,28 +352,26 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
} }
@Provides @Provides
protected Set<? extends Image> provideImages( protected Set<? extends Image> provideImages(Map<RegionAndName, ? extends Image> map) {
Map<RegionAndName, ? extends Image> map) {
return ImmutableSet.copyOf(map.values()); return ImmutableSet.copyOf(map.values());
} }
@Provides @Provides
@Singleton @Singleton
protected ConcurrentMap<RegionAndName, Image> provideImageMap( protected ConcurrentMap<RegionAndName, Image> provideImageMap(
RegionAndIdToImage regionAndIdToImage) { RegionAndIdToImage regionAndIdToImage) {
return new MapMaker().makeComputingMap(regionAndIdToImage); return new MapMaker().makeComputingMap(regionAndIdToImage);
} }
@Provides @Provides
@Singleton @Singleton
protected Map<RegionAndName, ? extends Image> provideImages( protected Map<RegionAndName, ? extends Image> provideImages(final EC2Client sync,
final EC2Client sync, @EC2 Map<String, URI> regionMap, @Region Map<String, URI> regionMap, final LogHolder holder,
final LogHolder holder, Function<ComputeMetadata, String> indexer, Function<ComputeMetadata, String> indexer,
@Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners, @Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners, final ImageParser parser,
final ImageParser parser, final ConcurrentMap<RegionAndName, Image> images,
final ConcurrentMap<RegionAndName, Image> images, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor)
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) throws InterruptedException, ExecutionException, TimeoutException {
throws InterruptedException, ExecutionException, TimeoutException {
if (amiOwners.length == 0) { if (amiOwners.length == 0) {
holder.logger.debug(">> no owners specified, skipping image parsing"); holder.logger.debug(">> no owners specified, skipping image parsing");
} else { } else {
@ -417,31 +384,30 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
else else
options = ownedBy(amiOwners); options = ownedBy(amiOwners);
for (final String region : regionMap.keySet()) { for (final String region : regionMap.keySet()) {
parallelResponses.put(region, ConcurrentUtils.makeListenable( parallelResponses.put(region, ConcurrentUtils.makeListenable(executor
executor.submit(new Callable<Void>() { .submit(new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
for (final org.jclouds.aws.ec2.domain.Image from : sync for (final org.jclouds.aws.ec2.domain.Image from : sync.getAMIServices()
.getAMIServices().describeImagesInRegion(region, .describeImagesInRegion(region, options)) {
options)) { Image image = parser.apply(from);
Image image = parser.apply(from); if (image != null)
if (image != null) images
images.put(new RegionAndName(region, image .put(new RegionAndName(region, image.getProviderId()),
.getProviderId()), image); image);
else if (from.getImageType() == ImageType.MACHINE) else if (from.getImageType() == ImageType.MACHINE)
holder.logger.trace("<< image(%s) didn't parse", holder.logger.trace("<< image(%s) didn't parse", from.getId());
from.getId()); }
return null;
} }
return null; }), executor));
}
}), executor));
} }
Map<String, Exception> exceptions = awaitCompletion(parallelResponses, Map<String, Exception> exceptions = awaitCompletion(parallelResponses, executor, null,
executor, null, holder.logger, "images"); holder.logger, "images");
if (exceptions.size() > 0) if (exceptions.size() > 0)
throw new RuntimeException(String.format( throw new RuntimeException(String.format("error parsing images in regions: %s",
"error parsing images in regions: %s", exceptions)); exceptions));
holder.logger.debug("<< images(%d)", images.size()); holder.logger.debug("<< images(%d)", images.size());
} }

View File

@ -19,8 +19,8 @@
package org.jclouds.aws.ec2.compute.functions; package org.jclouds.aws.ec2.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeUtils.parseOsFamilyOrNull; import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull;
import static org.jclouds.compute.util.ComputeUtils.parseVersionOrReturnEmptyString; import static org.jclouds.compute.util.ComputeServiceUtils.parseVersionOrReturnEmptyString;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
@ -54,22 +54,21 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class ImageParser implements public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, Image> {
Function<org.jclouds.aws.ec2.domain.Image, Image> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
public static final Pattern CANONICAL_PATTERN = Pattern public static final Pattern CANONICAL_PATTERN = Pattern
.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?"); .compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
// ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml // ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml
public static final Pattern RIGHTSCALE_PATTERN = Pattern public static final Pattern RIGHTSCALE_PATTERN = Pattern
.compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); .compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
// ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha // ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha
public static final Pattern RIGHTIMAGE_PATTERN = Pattern public static final Pattern RIGHTIMAGE_PATTERN = Pattern
.compile("[^/]*/RightImage_([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); .compile("[^/]*/RightImage_([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Set<? extends Location> locations; private final Set<? extends Location> locations;
@ -77,11 +76,9 @@ public class ImageParser implements
private final Location defaultLocation; private final Location defaultLocation;
@Inject @Inject
ImageParser( ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, Set<? extends Location> locations, Location defaultLocation) {
Set<? extends Location> locations, Location defaultLocation) { this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
this.credentialProvider = checkNotNull(credentialProvider,
"credentialProvider");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
@ -99,8 +96,8 @@ public class ImageParser implements
} }
OsFamily os = parseOsFamilyOrNull(from.getImageLocation()); OsFamily os = parseOsFamilyOrNull(from.getImageLocation());
String name = parseVersionOrReturnEmptyString(os, from.getImageLocation()); String name = parseVersionOrReturnEmptyString(os, from.getImageLocation());
String description = from.getDescription() != null ? from String description = from.getDescription() != null ? from.getDescription() : from
.getDescription() : from.getImageLocation(); .getImageLocation();
String osDescription = from.getImageLocation(); String osDescription = from.getImageLocation();
String version = ""; String version = "";
@ -128,24 +125,24 @@ public class ImageParser implements
}); });
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
System.err.printf("unknown region %s for image %s; not in %s", from System.err.printf("unknown region %s for image %s; not in %s", from.getRegion(), from
.getRegion(), from.getId(), locations); .getId(), locations);
location = new LocationImpl(LocationScope.REGION, from.getRegion(), location = new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(),
from.getRegion(), defaultLocation.getParent()); defaultLocation.getParent());
} }
return new ImageImpl( return new ImageImpl(
from.getId(), from.getId(),
name, name,
from.getRegion() + "/" + from.getId(), from.getRegion() + "/" + from.getId(),
location, location,
null, null,
ImmutableMap.<String, String> of("owner", from.getImageOwnerId()), ImmutableMap.<String, String> of("owner", from.getImageOwnerId()),
description, description,
version, version,
os, os,
osDescription, osDescription,
from.getArchitecture() == org.jclouds.aws.ec2.domain.Image.Architecture.I386 ? Architecture.X86_32 from.getArchitecture() == org.jclouds.aws.ec2.domain.Image.Architecture.I386 ? Architecture.X86_32
: Architecture.X86_64, defaultCredentials); : Architecture.X86_64, defaultCredentials);
} }
@ -155,8 +152,8 @@ public class ImageParser implements
* if no configured matcher matches the manifest. * if no configured matcher matches the manifest.
*/ */
private Matcher getMatcherAndFind(String manifest) { private Matcher getMatcherAndFind(String manifest) {
for (Pattern pattern : new Pattern[] { CANONICAL_PATTERN, for (Pattern pattern : new Pattern[] { CANONICAL_PATTERN, RIGHTIMAGE_PATTERN,
RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) { RIGHTSCALE_PATTERN }) {
Matcher matcher = pattern.matcher(manifest); Matcher matcher = pattern.matcher(manifest);
if (matcher.find()) if (matcher.find())
return matcher; return matcher;

View File

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

View File

@ -28,10 +28,9 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.util.EC2Utils.GetRegionFromLocation; import org.jclouds.aws.ec2.util.EC2Utils.GetRegionFromLocation;
import org.jclouds.aws.elb.ELBClient;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.LoadBalanceNodesStrategy; import org.jclouds.compute.strategy.LoadBalanceNodesStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -46,13 +45,13 @@ public class EC2LoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final EC2Client ec2Client; protected final ELBClient elbClient;
protected final GetRegionFromLocation getRegionFromLocation; protected final GetRegionFromLocation getRegionFromLocation;
@Inject @Inject
protected EC2LoadBalanceNodesStrategy(EC2Client ec2Client, protected EC2LoadBalanceNodesStrategy(ELBClient elbClient,
GetRegionFromLocation getRegionFromLocation) { GetRegionFromLocation getRegionFromLocation) {
this.ec2Client = ec2Client; this.elbClient = elbClient;
this.getRegionFromLocation = getRegionFromLocation; this.getRegionFromLocation = getRegionFromLocation;
} }
@ -69,8 +68,6 @@ public class EC2LoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {
availabilityZone = az; availabilityZone = az;
} }
ElasticLoadBalancerClient elbClient = ec2Client.getElasticLoadBalancerServices();
dnsName = elbClient.createLoadBalancerInRegion(region, name, protocol, loadBalancerPort, dnsName = elbClient.createLoadBalancerInRegion(region, name, protocol, loadBalancerPort,
instancePort, availabilityZone); instancePort, availabilityZone);

View File

@ -1,62 +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 java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.HttpAsyncClient;
import org.jclouds.rest.HttpClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
* Configures the EC2 connection, including logging and http transport.
*
* @author Adrian Cole
*/
public class EC2ContextModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(CDateAdapter.class);
}
@Provides
@Singleton
RestContext<EC2Client, EC2AsyncClient> provideContext(Closer closer,
HttpClient http, HttpAsyncClient asyncHttp, EC2AsyncClient defaultApi,
EC2Client synchApi, @EC2 URI endPoint,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
return new RestContextImpl<EC2Client, EC2AsyncClient>(closer, http,
asyncHttp, synchApi, defaultApi, endPoint, account);
}
}

View File

@ -19,19 +19,15 @@
package org.jclouds.aws.ec2.config; package org.jclouds.aws.ec2.config;
import java.net.URI; import java.net.URI;
import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.config.AWSFormSigningRestClientModule;
import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.ELB;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo; import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.reference.EC2Constants;
import org.jclouds.aws.ec2.services.AMIAsyncClient; import org.jclouds.aws.ec2.services.AMIAsyncClient;
import org.jclouds.aws.ec2.services.AMIClient; import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient; import org.jclouds.aws.ec2.services.AvailabilityZoneAndRegionAsyncClient;
@ -40,8 +36,6 @@ import org.jclouds.aws.ec2.services.ElasticBlockStoreAsyncClient;
import org.jclouds.aws.ec2.services.ElasticBlockStoreClient; import org.jclouds.aws.ec2.services.ElasticBlockStoreClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient; import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
import org.jclouds.aws.ec2.services.ElasticIPAddressClient; import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerAsyncClient;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.services.InstanceAsyncClient; import org.jclouds.aws.ec2.services.InstanceAsyncClient;
import org.jclouds.aws.ec2.services.InstanceClient; import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.aws.ec2.services.KeyPairAsyncClient; import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
@ -50,25 +44,12 @@ import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringClient; import org.jclouds.aws.ec2.services.MonitoringClient;
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient; import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
import org.jclouds.aws.ec2.services.SecurityGroupClient; import org.jclouds.aws.ec2.services.SecurityGroupClient;
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.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.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.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -78,73 +59,28 @@ import com.google.inject.Provides;
*/ */
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public class EC2RestClientModule extends public class EC2RestClientModule extends AWSFormSigningRestClientModule<EC2Client, EC2AsyncClient> {
RestClientModule<EC2Client, EC2AsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap
.<Class<?>, Class<?>> builder()// .<Class<?>, Class<?>> builder()//
.put(AMIClient.class, AMIAsyncClient.class)// .put(AMIClient.class, AMIAsyncClient.class)//
.put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)// .put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)//
.put(InstanceClient.class, InstanceAsyncClient.class)// .put(InstanceClient.class, InstanceAsyncClient.class)//
.put(KeyPairClient.class, KeyPairAsyncClient.class)// .put(KeyPairClient.class, KeyPairAsyncClient.class)//
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)// .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)//
.put(MonitoringClient.class, MonitoringAsyncClient.class)// .put(MonitoringClient.class, MonitoringAsyncClient.class)//
.put(AvailabilityZoneAndRegionClient.class, .put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)//
AvailabilityZoneAndRegionAsyncClient.class)// .put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)//
.put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)// .build();
.put(ElasticLoadBalancerClient.class,
ElasticLoadBalancerAsyncClient.class)//
.build();
public EC2RestClientModule() { public EC2RestClientModule() {
super(EC2Client.class, EC2AsyncClient.class, DELEGATE_MAP); super(EC2Client.class, EC2AsyncClient.class, DELEGATE_MAP);
} }
@Provides
@Singleton
@ELB
protected URI provideELBURI(
@Named(EC2Constants.PROPERTY_ELB_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Provides
@Singleton
@ELB
Map<String, URI> provideELBRegions() {
return ImmutableMap
.<String, URI> of(
Region.US_EAST_1,
URI
.create("https://elasticloadbalancing.us-east-1.amazonaws.com"),
Region.US_WEST_1,
URI
.create("https://elasticloadbalancing.us-west-1.amazonaws.com"),
Region.EU_WEST_1,
URI
.create("https://elasticloadbalancing.eu-west-1.amazonaws.com"),
Region.AP_SOUTHEAST_1,
URI
.create("https://elasticloadbalancing.ap-southeast-1.amazonaws.com"));
}
@Provides
@Singleton
@EC2
String provideCurrentRegion(@EC2 Map<String, URI> regionMap,
@EC2 URI currentUri) {
ImmutableBiMap<URI, String> map = ImmutableBiMap.<String, URI> builder()
.putAll(regionMap).build().inverse();
String region = map.get(currentUri);
assert region != null : currentUri + " not in " + map;
return region;
}
private RuntimeException regionException = null; private RuntimeException regionException = null;
@Provides @Override
@Singleton protected Map<String, URI> provideRegions(Injector injector) {
@EC2
Map<String, URI> provideRegions(EC2Client client) {
// http://code.google.com/p/google-guice/issues/detail?id=483 // http://code.google.com/p/google-guice/issues/detail?id=483
// guice doesn't remember when singleton providers throw exceptions. // guice doesn't remember when singleton providers throw exceptions.
// in this case, if describeRegions fails, it is called again for // in this case, if describeRegions fails, it is called again for
@ -152,6 +88,7 @@ public class EC2RestClientModule extends
// we remember the last exception trusting that guice is single-threaded // we remember the last exception trusting that guice is single-threaded
if (regionException != null) if (regionException != null)
throw regionException; throw regionException;
EC2Client client = injector.getInstance(EC2Client.class);
try { try {
return client.getAvailabilityZoneAndRegionServices().describeRegions(); return client.getAvailabilityZoneAndRegionServices().describeRegions();
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -162,56 +99,16 @@ public class EC2RestClientModule extends
@Provides @Provides
@Singleton @Singleton
Map<String, String> provideAvailabilityZoneToRegions(EC2Client client, protected Map<String, String> provideAvailabilityZoneToRegions(EC2Client client,
@EC2 Map<String, URI> regions) { @Region Map<String, URI> regions) {
Map<String, String> map = Maps.newHashMap(); Map<String, String> map = Maps.newHashMap();
for (String region : regions.keySet()) { for (String region : regions.keySet()) {
for (AvailabilityZoneInfo zoneInfo : client for (AvailabilityZoneInfo zoneInfo : client.getAvailabilityZoneAndRegionServices()
.getAvailabilityZoneAndRegionServices() .describeAvailabilityZonesInRegion(region)) {
.describeAvailabilityZonesInRegion(region)) {
map.put(zoneInfo.getZone(), region); map.put(zoneInfo.getZone(), region);
} }
} }
return map; return map;
} }
@Provides
@TimeStamp
protected String provideTimeStamp(final DateService dateService,
@Named(EC2Constants.PROPERTY_AWS_EXPIREINTERVAL) final int expiration) {
return dateService.iso8601DateFormat(new Date(System.currentTimeMillis()
+ (expiration * 1000)));
}
@Provides
@Singleton
RequestSigner provideRequestSigner(FormSigner in) {
return in;
}
@Provides
@Singleton
@EC2
protected URI provideURI(
@Named(EC2Constants.PROPERTY_EC2_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
ParseAWSErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AWSClientErrorRetryHandler.class);
}
} }

View File

@ -24,7 +24,7 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -38,7 +38,7 @@ public class AvailabilityZoneToEndpoint implements Function<Object, URI> {
private final Map<String, URI> regionToEndpoint; private final Map<String, URI> regionToEndpoint;
@Inject @Inject
public AvailabilityZoneToEndpoint(@EC2 Map<String, URI> regionToEndpoint, public AvailabilityZoneToEndpoint(@Region Map<String, URI> regionToEndpoint,
Map<String, String> availabilityZoneToRegion) { Map<String, String> availabilityZoneToRegion) {
this.regionToEndpoint = regionToEndpoint; this.regionToEndpoint = regionToEndpoint;
this.availabilityZoneToRegion = availabilityZoneToRegion; this.availabilityZoneToRegion = availabilityZoneToRegion;

View File

@ -1,50 +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.functions;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.ELB;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ELBRegionToEndpoint implements Function<Object, URI> {
private final Map<String, URI> regionToEndpoint;
private final URI defaultUri;
@Inject
public ELBRegionToEndpoint(@ELB Map<String, URI> regionToEndpoint, @ELB URI defaultUri) {
this.regionToEndpoint = regionToEndpoint;
this.defaultUri = defaultUri;
}
public URI apply(Object from) {
return from == null ? defaultUri : regionToEndpoint.get(from);
}
}

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.aws.ec2.reference; package org.jclouds.aws.ec2.reference;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeService;
/** /**
@ -26,8 +25,7 @@ import org.jclouds.compute.ComputeService;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface EC2Constants extends AWSConstants { public interface EC2Constants{
public static final String PROPERTY_EC2_ENDPOINT = "jclouds.ec2.endpoint";
/** /**
* Listing the universe of amis is extremely expensive. set this to a comma separated value of * Listing the universe of amis is extremely expensive. set this to a comma separated value of
* the ami owners you wish to use in {@link ComputeService} * the ami owners you wish to use in {@link ComputeService}

View File

@ -29,13 +29,13 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.binders.BindProductCodesToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindProductCodesToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindUserGroupsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindUserGroupsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindUserIdsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindUserIdsToIndexedFormParams;
import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.Image;
import org.jclouds.aws.ec2.domain.Permission; import org.jclouds.aws.ec2.domain.Permission;
import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice; import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.options.CreateImageOptions; import org.jclouds.aws.ec2.options.CreateImageOptions;
import org.jclouds.aws.ec2.options.DescribeImagesOptions; import org.jclouds.aws.ec2.options.DescribeImagesOptions;
import org.jclouds.aws.ec2.options.RegisterImageBackedByEbsOptions; import org.jclouds.aws.ec2.options.RegisterImageBackedByEbsOptions;
@ -46,6 +46,7 @@ import org.jclouds.aws.ec2.xml.ImageIdHandler;
import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.PermissionHandler;
import org.jclouds.aws.ec2.xml.ProductCodesHandler; import org.jclouds.aws.ec2.xml.ProductCodesHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
@ -62,7 +63,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface AMIAsyncClient { public interface AMIAsyncClient {

View File

@ -29,15 +29,14 @@ import javax.annotation.Nullable;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo; import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions; import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions;
import org.jclouds.aws.ec2.options.DescribeRegionsOptions; import org.jclouds.aws.ec2.options.DescribeRegionsOptions;
import org.jclouds.aws.ec2.xml.DescribeAvailabilityZonesResponseHandler; import org.jclouds.aws.ec2.xml.DescribeAvailabilityZonesResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeRegionsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeRegionsResponseHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
@ -53,7 +52,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface AvailabilityZoneAndRegionAsyncClient { public interface AvailabilityZoneAndRegionAsyncClient {
@ -72,7 +71,6 @@ public interface AvailabilityZoneAndRegionAsyncClient {
* @see AvailabilityZoneAndRegionClient#describeRegions * @see AvailabilityZoneAndRegionClient#describeRegions
*/ */
@POST @POST
@Endpoint(EC2.class)
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "DescribeRegions") @FormParams(keys = ACTION, values = "DescribeRegions")
@XMLResponseParser(DescribeRegionsResponseHandler.class) @XMLResponseParser(DescribeRegionsResponseHandler.class)

View File

@ -28,6 +28,7 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.binders.BindUserGroupsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindUserGroupsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindUserIdsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindUserIdsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindVolumeIdsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindVolumeIdsToIndexedFormParams;
@ -36,7 +37,6 @@ import org.jclouds.aws.ec2.domain.Permission;
import org.jclouds.aws.ec2.domain.Snapshot; import org.jclouds.aws.ec2.domain.Snapshot;
import org.jclouds.aws.ec2.domain.Volume; import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.aws.ec2.functions.AvailabilityZoneToEndpoint; import org.jclouds.aws.ec2.functions.AvailabilityZoneToEndpoint;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.functions.ReturnVoidOnVolumeAvailable; import org.jclouds.aws.ec2.functions.ReturnVoidOnVolumeAvailable;
import org.jclouds.aws.ec2.options.CreateSnapshotOptions; import org.jclouds.aws.ec2.options.CreateSnapshotOptions;
import org.jclouds.aws.ec2.options.DescribeSnapshotsOptions; import org.jclouds.aws.ec2.options.DescribeSnapshotsOptions;
@ -48,6 +48,7 @@ import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler;
import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.PermissionHandler;
import org.jclouds.aws.ec2.xml.SnapshotHandler; import org.jclouds.aws.ec2.xml.SnapshotHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
@ -65,7 +66,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface ElasticBlockStoreAsyncClient { public interface ElasticBlockStoreAsyncClient {

View File

@ -28,12 +28,13 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.binders.BindPublicIpsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindPublicIpsToIndexedFormParams;
import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair; import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler; import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler; import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
@ -50,7 +51,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface ElasticIPAddressAsyncClient { public interface ElasticIPAddressAsyncClient {
@ -72,8 +73,7 @@ public interface ElasticIPAddressAsyncClient {
@FormParams(keys = ACTION, values = "AssociateAddress") @FormParams(keys = ACTION, values = "AssociateAddress")
ListenableFuture<Void> associateAddressInRegion( ListenableFuture<Void> associateAddressInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("PublicIp") String publicIp, @FormParam("PublicIp") String publicIp, @FormParam("InstanceId") String instanceId);
@FormParam("InstanceId") String instanceId);
/** /**
* @see BaseEC2Client#disassociateAddressInRegion * @see BaseEC2Client#disassociateAddressInRegion

View File

@ -29,13 +29,16 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.binders.BindBlockDeviceMappingToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindBlockDeviceMappingToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.IfNotNullBindAvailabilityZoneToFormParam; import org.jclouds.aws.ec2.binders.IfNotNullBindAvailabilityZoneToFormParam;
import org.jclouds.aws.ec2.domain.*; import org.jclouds.aws.ec2.domain.BlockDeviceMapping;
import org.jclouds.aws.ec2.domain.InstanceStateChange;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.aws.ec2.functions.ConvertUnencodedBytesToBase64EncodedString; import org.jclouds.aws.ec2.functions.ConvertUnencodedBytesToBase64EncodedString;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.options.RunInstancesOptions; import org.jclouds.aws.ec2.options.RunInstancesOptions;
import org.jclouds.aws.ec2.xml.BlockDeviceMappingHandler; import org.jclouds.aws.ec2.xml.BlockDeviceMappingHandler;
import org.jclouds.aws.ec2.xml.BooleanValueHandler; import org.jclouds.aws.ec2.xml.BooleanValueHandler;
@ -47,6 +50,7 @@ import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.StringValueHandler; import org.jclouds.aws.ec2.xml.StringValueHandler;
import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler; import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
@ -64,7 +68,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface InstanceAsyncClient { public interface InstanceAsyncClient {
@ -300,8 +304,7 @@ public interface InstanceAsyncClient {
@FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "instanceType" }) @FormParams(keys = { ACTION, "Attribute" }, values = { "ModifyInstanceAttribute", "instanceType" })
ListenableFuture<Void> setInstanceTypeForInstanceInRegion( ListenableFuture<Void> setInstanceTypeForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("InstanceId") String instanceId, @FormParam("InstanceId") String instanceId, @FormParam("Value") String instanceType);
@FormParam("Value") String instanceType);
/** /**
* @see AMIClient#setInstanceInitiatedShutdownBehaviorForInstanceInRegion * @see AMIClient#setInstanceInitiatedShutdownBehaviorForInstanceInRegion

View File

@ -28,12 +28,13 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.binders.BindKeyNameToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindKeyNameToIndexedFormParams;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler;
import org.jclouds.aws.ec2.xml.KeyPairResponseHandler; import org.jclouds.aws.ec2.xml.KeyPairResponseHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
@ -50,7 +51,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface KeyPairAsyncClient { public interface KeyPairAsyncClient {

View File

@ -28,11 +28,12 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.aws.ec2.domain.MonitoringState; import org.jclouds.aws.ec2.domain.MonitoringState;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.xml.MonitoringStateHandler; import org.jclouds.aws.ec2.xml.MonitoringStateHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
@ -49,7 +50,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface MonitoringAsyncClient { public interface MonitoringAsyncClient {

View File

@ -28,15 +28,16 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.binders.BindGroupNameToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindGroupNameToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindUserIdGroupPairToSourceSecurityGroupFormParams; import org.jclouds.aws.ec2.binders.BindUserIdGroupPairToSourceSecurityGroupFormParams;
import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.SecurityGroup; import org.jclouds.aws.ec2.domain.SecurityGroup;
import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.aws.ec2.domain.UserIdGroupPair;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound; import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound;
import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
@ -54,7 +55,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-30") @FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface SecurityGroupAsyncClient { public interface SecurityGroupAsyncClient {
@ -91,7 +92,8 @@ public interface SecurityGroupAsyncClient {
@BinderParam(BindGroupNameToIndexedFormParams.class) String... securityGroupNames); @BinderParam(BindGroupNameToIndexedFormParams.class) String... securityGroupNames);
/** /**
* @see BaseEC2Client#authorizeSecurityGroupIngressInRegion(@Nullable Region, String,UserIdGroupPair) * @see BaseEC2Client#authorizeSecurityGroupIngressInRegion(@Nullable Region,
* String,UserIdGroupPair)
*/ */
@POST @POST
@Path("/") @Path("/")
@ -115,7 +117,8 @@ public interface SecurityGroupAsyncClient {
@FormParam("ToPort") int toPort, @FormParam("CidrIp") String cidrIp); @FormParam("ToPort") int toPort, @FormParam("CidrIp") String cidrIp);
/** /**
* @see BaseEC2Client#revokeSecurityGroupIngressInRegion(@Nullable Region, String,UserIdGroupPair) * @see BaseEC2Client#revokeSecurityGroupIngressInRegion(@Nullable Region,
* String,UserIdGroupPair)
*/ */
@POST @POST
@Path("/") @Path("/")

View File

@ -23,7 +23,7 @@ import java.util.Date;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
@ -42,7 +42,7 @@ public class AttachmentHandler extends ParseSax.HandlerWithResult<Attachment> {
@Inject @Inject
protected DateService dateService; protected DateService dateService;
@Inject @Inject
@EC2 @Region
String defaultRegion; String defaultRegion;
private String volumeId; private String volumeId;
private String instanceId; private String instanceId;

View File

@ -26,7 +26,7 @@ import java.util.SortedSet;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.Reservation;
@ -53,7 +53,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
@Inject @Inject
public BaseReservationHandler(DateService dateService, public BaseReservationHandler(DateService dateService,
@EC2 String defaultRegion) { @Region String defaultRegion) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
} }

View File

@ -27,7 +27,7 @@ import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.Attachment; import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.domain.Volume; import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
@ -51,7 +51,7 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerWithResult<Volu
@Inject @Inject
protected DateService dateService; protected DateService dateService;
@Inject @Inject
@EC2 @Region
String defaultRegion; String defaultRegion;
@Inject @Inject
protected Map<String, String> availabilityZoneToRegion; protected Map<String, String> availabilityZoneToRegion;

View File

@ -23,7 +23,7 @@ import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair; import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.http.functions.ParseSax.HandlerWithResult;
@ -44,7 +44,7 @@ public class DescribeAddressesResponseHandler extends
private String ipAddress; private String ipAddress;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@Inject @Inject
@EC2 @Region
String defaultRegion; String defaultRegion;
private String instanceId; private String instanceId;

View File

@ -24,7 +24,7 @@ import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.Image;
import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RootDeviceType;
import org.jclouds.aws.ec2.domain.Image.Architecture; import org.jclouds.aws.ec2.domain.Image.Architecture;
@ -51,7 +51,7 @@ import com.google.common.collect.Sets;
public class DescribeImagesResponseHandler extends ParseSax.HandlerWithResult<Set<Image>> { public class DescribeImagesResponseHandler extends ParseSax.HandlerWithResult<Set<Image>> {
@Inject @Inject
public DescribeImagesResponseHandler(@EC2 String defaultRegion) { public DescribeImagesResponseHandler(@Region String defaultRegion) {
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
} }

View File

@ -22,7 +22,7 @@ import java.util.SortedSet;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
@ -41,7 +41,7 @@ public class DescribeInstancesResponseHandler extends
private SortedSet<Reservation> reservations = Sets.newTreeSet(); private SortedSet<Reservation> reservations = Sets.newTreeSet();
@Inject @Inject
DescribeInstancesResponseHandler(DateService dateService, @EC2 String defaultRegion) { DescribeInstancesResponseHandler(DateService dateService, @Region String defaultRegion) {
super(dateService, defaultRegion); super(dateService, defaultRegion);
} }

View File

@ -22,7 +22,7 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -38,7 +38,7 @@ import com.google.common.collect.Sets;
*/ */
public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerWithResult<Set<KeyPair>> { public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerWithResult<Set<KeyPair>> {
@Inject @Inject
@EC2 @Region
String defaultRegion; String defaultRegion;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();

View File

@ -22,7 +22,7 @@ import java.util.SortedSet;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.IpPermission; import org.jclouds.aws.ec2.domain.IpPermission;
import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.SecurityGroup; import org.jclouds.aws.ec2.domain.SecurityGroup;
@ -43,7 +43,7 @@ import com.google.common.collect.Sets;
public class DescribeSecurityGroupsResponseHandler extends public class DescribeSecurityGroupsResponseHandler extends
ParseSax.HandlerWithResult<SortedSet<SecurityGroup>> { ParseSax.HandlerWithResult<SortedSet<SecurityGroup>> {
@Inject @Inject
@EC2 @Region
String defaultRegion; String defaultRegion;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();

View File

@ -22,7 +22,7 @@ import java.util.SortedSet;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.InstanceStateChange; import org.jclouds.aws.ec2.domain.InstanceStateChange;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
@ -49,7 +49,7 @@ import com.google.common.collect.Sets;
public class InstanceStateChangeHandler extends HandlerWithResult<SortedSet<InstanceStateChange>> { public class InstanceStateChangeHandler extends HandlerWithResult<SortedSet<InstanceStateChange>> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@Inject @Inject
@EC2 @Region
String defaultRegion; String defaultRegion;
SortedSet<InstanceStateChange> instances = Sets.newTreeSet(); SortedSet<InstanceStateChange> instances = Sets.newTreeSet();

View File

@ -20,7 +20,7 @@ package org.jclouds.aws.ec2.xml;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -34,7 +34,7 @@ import org.jclouds.http.functions.ParseSax;
*/ */
public class KeyPairResponseHandler extends ParseSax.HandlerWithResult<KeyPair> { public class KeyPairResponseHandler extends ParseSax.HandlerWithResult<KeyPair> {
@Inject @Inject
@EC2 @Region
String defaultRegion; String defaultRegion;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private String keyFingerprint; private String keyFingerprint;

View File

@ -20,7 +20,7 @@ package org.jclouds.aws.ec2.xml;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
@ -35,7 +35,7 @@ import org.jclouds.date.DateService;
public class RunInstancesResponseHandler extends BaseReservationHandler<Reservation> { public class RunInstancesResponseHandler extends BaseReservationHandler<Reservation> {
@Inject @Inject
RunInstancesResponseHandler(DateService dateService, @EC2 String defaultRegion) { RunInstancesResponseHandler(DateService dateService, @Region String defaultRegion) {
super(dateService, defaultRegion); super(dateService, defaultRegion);
} }

View File

@ -22,7 +22,7 @@ import java.util.Date;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.Snapshot; import org.jclouds.aws.ec2.domain.Snapshot;
import org.jclouds.aws.ec2.domain.Snapshot.Status; import org.jclouds.aws.ec2.domain.Snapshot.Status;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
@ -50,7 +50,7 @@ public class SnapshotHandler extends ParseSax.HandlerWithResult<Snapshot> {
private String ownerAlias; private String ownerAlias;
@Inject @Inject
public SnapshotHandler(DateService dateService, @EC2 String defaultRegion) { public SnapshotHandler(DateService dateService, @Region String defaultRegion) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
} }

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.aws.ec2.services; package org.jclouds.aws.elb;
import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION; import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION;
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
@ -28,13 +28,13 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.ec2.binders.BindELBInstanceIdsToIndexedFormParams;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer;
import org.jclouds.aws.ec2.functions.ELBRegionToEndpoint;
import org.jclouds.aws.ec2.xml.CreateLoadBalancerResponseHandler; import org.jclouds.aws.ec2.xml.CreateLoadBalancerResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeLoadBalancersResponseHandler;
import org.jclouds.aws.ec2.xml.RegisterInstancesWithLoadBalancerResponseHandler; import org.jclouds.aws.ec2.xml.RegisterInstancesWithLoadBalancerResponseHandler;
import org.jclouds.aws.elb.binders.BindELBInstanceIdsToIndexedFormParams;
import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.aws.elb.xml.DescribeLoadBalancersResponseHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
@ -51,18 +51,20 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Lili Nader * @author Lili Nader
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-25") @FormParams(keys = VERSION, values = ELBAsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface ElasticLoadBalancerAsyncClient { public interface ELBAsyncClient {
public static final String VERSION = "2009-11-25";
/** /**
* @see ElasticLoadBalancerClient#createLoadBalancerInRegion * @see ELBClient#createLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(CreateLoadBalancerResponseHandler.class) @XMLResponseParser(CreateLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "CreateLoadBalancer") @FormParams(keys = ACTION, values = "CreateLoadBalancer")
ListenableFuture<String> createLoadBalancerInRegion( ListenableFuture<String> createLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@FormParam("Listeners.member.1.Protocol") String protocol, @FormParam("Listeners.member.1.Protocol") String protocol,
@FormParam("Listeners.member.1.LoadBalancerPort") int loadBalancerPort, @FormParam("Listeners.member.1.LoadBalancerPort") int loadBalancerPort,
@ -70,47 +72,47 @@ public interface ElasticLoadBalancerAsyncClient {
@FormParam("AvailabilityZones.member.1") String availabilityZone); @FormParam("AvailabilityZones.member.1") String availabilityZone);
/** /**
* @see ElasticLoadBalancerClient#deleteLoadBalancerInRegion * @see ELBClient#deleteLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "DeleteLoadBalancer") @FormParams(keys = ACTION, values = "DeleteLoadBalancer")
ListenableFuture<Void> deleteLoadBalancerInRegion( ListenableFuture<Void> deleteLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name); @FormParam("LoadBalancerName") String name);
/** /**
* @see ElasticLoadBalancerClient#registerInstancesWithLoadBalancerInRegion * @see ELBClient#registerInstancesWithLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(RegisterInstancesWithLoadBalancerResponseHandler.class) @XMLResponseParser(RegisterInstancesWithLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "RegisterInstancesWithLoadBalancer") @FormParams(keys = ACTION, values = "RegisterInstancesWithLoadBalancer")
ListenableFuture<? extends Set<String>> registerInstancesWithLoadBalancerInRegion( ListenableFuture<? extends Set<String>> registerInstancesWithLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds); @BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds);
/** /**
* @see ElasticLoadBalancerClient#deregisterInstancesWithLoadBalancerInRegion * @see ELBClient#deregisterInstancesWithLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "DeregisterInstancesFromLoadBalancer") @FormParams(keys = ACTION, values = "DeregisterInstancesFromLoadBalancer")
ListenableFuture<Void> deregisterInstancesWithLoadBalancerInRegion( ListenableFuture<Void> deregisterInstancesWithLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds); @BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds);
/** /**
* @see ElasticLoadBalancerClient#describeLoadBalancersInRegion * @see ELBClient#describeLoadBalancersInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(DescribeLoadBalancersResponseHandler.class) @XMLResponseParser(DescribeLoadBalancersResponseHandler.class)
@FormParams(keys = ACTION, values = "DescribeLoadBalancers") @FormParams(keys = ACTION, values = "DescribeLoadBalancers")
ListenableFuture<? extends Set<ElasticLoadBalancer>> describeLoadBalancersInRegion( ListenableFuture<? extends Set<LoadBalancer>> describeLoadBalancersInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") @Nullable String name); @FormParam("LoadBalancerName") @Nullable String name);
} }

View File

@ -16,14 +16,14 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.aws.ec2.services; package org.jclouds.aws.elb;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer; import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
/** /**
@ -33,7 +33,7 @@ import org.jclouds.concurrent.Timeout;
* @author Lili Nader * @author Lili Nader
*/ */
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface ElasticLoadBalancerClient { public interface ELBClient {
/** /**
* Creates a load balancer * Creates a load balancer
@ -91,7 +91,6 @@ public interface ElasticLoadBalancerClient {
void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name, void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name,
String... instanceIds); String... instanceIds);
Set<ElasticLoadBalancer> describeLoadBalancersInRegion(@Nullable String region, Set<LoadBalancer> describeLoadBalancersInRegion(@Nullable String region, @Nullable String name);
@Nullable String name);
} }

View File

@ -0,0 +1,37 @@
package org.jclouds.aws.elb;
import java.util.List;
import java.util.Properties;
import org.jclouds.aws.elb.config.ELBRestClientModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* Creates {@link ELBContext} or {@link Injector} instances based on the most commonly requested
* arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see ELBContext
*/
public class ELBContextBuilder extends RestContextBuilder<ELBClient, ELBAsyncClient> {
public ELBContextBuilder(Properties props) {
super(ELBClient.class, ELBAsyncClient.class, props);
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new ELBRestClientModule());
}
}

View File

@ -0,0 +1,65 @@
/**
*
* 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.elb;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.aws.domain.Region;
import com.google.common.base.Joiner;
/**
* Builds properties used in ELB Clients
*
* @author Adrian Cole
*/
public class ELBPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, ELBAsyncClient.VERSION);
properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_EAST_1,
Region.US_WEST_1, Region.EU_WEST_1, Region.AP_SOUTHEAST_1));
properties.setProperty(PROPERTY_ENDPOINT,
"https://elasticloadbalancing.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_EAST_1,
"https://elasticloadbalancing.us-east-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_WEST_1,
"https://elasticloadbalancing.us-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.EU_WEST_1,
"https://elasticloadbalancing.eu-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.AP_SOUTHEAST_1,
"https://elasticloadbalancing.ap-southeast-1.amazonaws.com");
return properties;
}
public ELBPropertiesBuilder() {
super();
}
public ELBPropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.elb.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -0,0 +1,39 @@
/**
*
* 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.elb.config;
import org.jclouds.aws.config.AWSFormSigningRestClientModule;
import org.jclouds.aws.elb.ELBAsyncClient;
import org.jclouds.aws.elb.ELBClient;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
/**
* Configures the ELB connection.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class ELBRestClientModule extends AWSFormSigningRestClientModule<ELBClient, ELBAsyncClient> {
public ELBRestClientModule() {
super(ELBClient.class, ELBAsyncClient.class);
}
}

View File

@ -17,7 +17,7 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.aws.ec2.domain; package org.jclouds.aws.elb.domain;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -27,7 +27,7 @@ import java.util.Set;
* *
* @author Lili Nader * @author Lili Nader
*/ */
public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer> { public class LoadBalancer implements Comparable<LoadBalancer> {
private String region; private String region;
private String name; private String name;
@ -38,14 +38,14 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer> {
private LBCookieStickinessPolicy lBCookieStickinessPolicy; private LBCookieStickinessPolicy lBCookieStickinessPolicy;
private Set<LoadBalancerListener> loadBalancerListeners; private Set<LoadBalancerListener> loadBalancerListeners;
public ElasticLoadBalancer() { public LoadBalancer() {
super(); super();
this.instanceIds = new HashSet<String>(); this.instanceIds = new HashSet<String>();
this.availabilityZones = new HashSet<String>(); this.availabilityZones = new HashSet<String>();
this.loadBalancerListeners = new HashSet<LoadBalancerListener>(); this.loadBalancerListeners = new HashSet<LoadBalancerListener>();
} }
public ElasticLoadBalancer(String region, String name, Set<String> instanceIds, public LoadBalancer(String region, String name, Set<String> instanceIds,
Set<String> availabilityZones, String dnsName) { Set<String> availabilityZones, String dnsName) {
super(); super();
this.region = region; this.region = region;
@ -121,7 +121,7 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer> {
} }
@Override @Override
public int compareTo(ElasticLoadBalancer that) { public int compareTo(LoadBalancer that) {
return name.compareTo(that.name); return name.compareTo(that.name);
} }
@ -151,7 +151,7 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer> {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
ElasticLoadBalancer other = (ElasticLoadBalancer) obj; LoadBalancer other = (LoadBalancer) obj;
if (appCookieStickinessPolicy == null) { if (appCookieStickinessPolicy == null) {
if (other.appCookieStickinessPolicy != null) if (other.appCookieStickinessPolicy != null)
return false; return false;

View File

@ -16,19 +16,19 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.aws.ec2.xml; package org.jclouds.aws.elb.xml;
import java.util.Set; import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer.AppCookieStickinessPolicy;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer.LBCookieStickinessPolicy;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer.LoadBalancerListener;
import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.aws.elb.domain.LoadBalancer;
import org.jclouds.aws.elb.domain.LoadBalancer.AppCookieStickinessPolicy;
import org.jclouds.aws.elb.domain.LoadBalancer.LBCookieStickinessPolicy;
import org.jclouds.aws.elb.domain.LoadBalancer.LoadBalancerListener;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -42,9 +42,9 @@ import com.google.common.collect.Sets;
* @author Lili Nadar * @author Lili Nadar
*/ */
public class DescribeLoadBalancersResponseHandler extends public class DescribeLoadBalancersResponseHandler extends
ParseSax.HandlerWithResult<Set<ElasticLoadBalancer>> { ParseSax.HandlerWithResult<Set<LoadBalancer>> {
@Inject @Inject
public DescribeLoadBalancersResponseHandler(@EC2 String defaultRegion) { public DescribeLoadBalancersResponseHandler(@Region String defaultRegion) {
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
this.listenerHandler = new LoadBalancerListenerHandler(); this.listenerHandler = new LoadBalancerListenerHandler();
} }
@ -55,7 +55,7 @@ public class DescribeLoadBalancersResponseHandler extends
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private Set<ElasticLoadBalancer> contents = Sets.newLinkedHashSet(); private Set<LoadBalancer> contents = Sets.newLinkedHashSet();
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private final String defaultRegion; private final String defaultRegion;
private final LoadBalancerListenerHandler listenerHandler; private final LoadBalancerListenerHandler listenerHandler;
@ -68,7 +68,7 @@ public class DescribeLoadBalancersResponseHandler extends
// TODO unused? // TODO unused?
private boolean inLoadBalancerDescriptions = false; private boolean inLoadBalancerDescriptions = false;
private ElasticLoadBalancer elb; private LoadBalancer elb;
// TODO unused? // TODO unused?
private AppCookieStickinessPolicy appCookieStickinessPolicy; private AppCookieStickinessPolicy appCookieStickinessPolicy;
// TODO unused? // TODO unused?
@ -93,7 +93,7 @@ public class DescribeLoadBalancersResponseHandler extends
if (qName.equals("member")) { if (qName.equals("member")) {
if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones)) { || inLBCookieStickinessPolicies || inAvailabilityZones)) {
elb = new ElasticLoadBalancer(); elb = new LoadBalancer();
} }
} }
} }
@ -149,7 +149,7 @@ public class DescribeLoadBalancersResponseHandler extends
} }
@Override @Override
public Set<ElasticLoadBalancer> getResult() { public Set<LoadBalancer> getResult() {
return contents; return contents;
} }

View File

@ -41,7 +41,6 @@ import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
@ -83,8 +82,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
@Inject @Inject
public FormSigner(SignatureWire signatureWire, public FormSigner(SignatureWire signatureWire,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String accessKey, @Named(Constants.PROPERTY_IDENTITY) String accessKey,
@Named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY) String secretKey, @Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
@TimeStamp Provider<String> dateService, EncryptionService encryptionService) { @TimeStamp Provider<String> dateService, EncryptionService encryptionService) {
this.signatureWire = signatureWire; this.signatureWire = signatureWire;
this.accessKey = accessKey; this.accessKey = accessKey;

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.aws.sqs.functions; package org.jclouds.aws.functions;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
@ -24,7 +24,8 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.Region;
import org.jclouds.rest.annotations.Provider;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -38,7 +39,7 @@ public class RegionToEndpoint implements Function<Object, URI> {
private final URI defaultUri; private final URI defaultUri;
@Inject @Inject
public RegionToEndpoint(@SQS Map<String, URI> regionToEndpoint, @SQS URI defaultUri) { public RegionToEndpoint(@Region Map<String, URI> regionToEndpoint, @Provider URI defaultUri) {
this.regionToEndpoint = regionToEndpoint; this.regionToEndpoint = regionToEndpoint;
this.defaultUri = defaultUri; this.defaultUri = defaultUri;
} }

View File

@ -25,7 +25,6 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import org.jclouds.aws.domain.AWSError; import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.aws.util.AWSUtils; import org.jclouds.aws.util.AWSUtils;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
@ -62,7 +61,7 @@ public class AWSRedirectionRetryHandler extends RedirectionRetryHandler {
try { try {
AWSError error = utils.parseAWSErrorFromContent(command, response, new String( AWSError error = utils.parseAWSErrorFromContent(command, response, new String(
content)); content));
String host = error.getDetails().get(AWSConstants.ENDPOINT); String host = error.getDetails().get("Endpoint");
if (host != null) { if (host != null) {
if (host.equals(command.getRequest().getEndpoint().getHost())) { if (host.equals(command.getRequest().getEndpoint().getHost())) {
// must be an amazon error related to // must be an amazon error related to

View File

@ -18,20 +18,13 @@
*/ */
package org.jclouds.aws.reference; package org.jclouds.aws.reference;
import org.jclouds.Constants;
/** /**
* Configuration properties and constants used in AWS connections. * Configuration properties and constants used in amazon connections.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface AWSConstants extends Constants { public interface AWSConstants {
public static final String ENDPOINT = "Endpoint"; public static final String PROPERTY_REGIONS = "jclouds.aws.regions";
public static final String PROPERTY_AWS_SECRETACCESSKEY = "jclouds.aws.secretaccesskey"; public static final String PROPERTY_DEFAULT_REGIONS = "jclouds.aws.default_regions";
public static final String PROPERTY_AWS_ACCESSKEYID = "jclouds.aws.accesskeyid";
/**
* how long do we wait before expiring requests.
*/
public static final String PROPERTY_AWS_EXPIREINTERVAL = "jclouds.aws.expireinterval";
} }

View File

@ -1,10 +1,10 @@
package org.jclouds.aws.s3; package org.jclouds.aws.s3;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_DEFAULT_REGIONS;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_AUTH_TAG; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_AUTH_TAG;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_DEFAULT_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_ENDPOINT;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_HEADER_TAG; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_HEADER_TAG;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_SERVICE_EXPR; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_SERVICE_EXPR;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
@ -22,19 +22,17 @@ public class GoogleStoragePropertiesBuilder extends S3PropertiesBuilder {
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-goog-meta-"); properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-goog-meta-");
properties.setProperty(PROPERTY_S3_AUTH_TAG, "GOOG1"); properties.setProperty(PROPERTY_S3_AUTH_TAG, "GOOG1");
properties.setProperty(PROPERTY_S3_HEADER_TAG, "goog"); properties.setProperty(PROPERTY_S3_HEADER_TAG, "goog");
properties.setProperty(PROPERTY_S3_SERVICE_EXPR, properties.setProperty(PROPERTY_S3_SERVICE_EXPR, "\\.commondatastorage\\.googleapis\\.com");
"\\.commondatastorage\\.googleapis\\.com");
return properties; return properties;
} }
@Override @Override
protected Properties addEndpoints(Properties properties) { protected Properties addEndpoints(Properties properties) {
properties.setProperty(PROPERTY_S3_REGIONS, "GoogleStorage"); properties.setProperty(PROPERTY_REGIONS, "GoogleStorage");
properties.setProperty(PROPERTY_S3_DEFAULT_REGIONS, "GoogleStorage"); properties.setProperty(PROPERTY_DEFAULT_REGIONS, "GoogleStorage");
properties.setProperty(PROPERTY_S3_ENDPOINT, properties.setProperty(PROPERTY_ENDPOINT, "https://commondatastorage.googleapis.com");
"https://commondatastorage.googleapis.com"); properties.setProperty(PROPERTY_ENDPOINT + ".GoogleStorage",
properties.setProperty(PROPERTY_S3_ENDPOINT + ".GoogleStorage", "https://commondatastorage.googleapis.com");
"https://commondatastorage.googleapis.com");
return properties; return properties;
} }
@ -42,7 +40,4 @@ public class GoogleStoragePropertiesBuilder extends S3PropertiesBuilder {
super(properties); super(properties);
} }
public GoogleStoragePropertiesBuilder(String id, String secret) {
super(id, secret);
}
} }

View File

@ -71,7 +71,6 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.http.functions.ParseETagHeader; import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers; import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.HostPrefixParam; import org.jclouds.rest.annotations.HostPrefixParam;
@ -102,9 +101,9 @@ import com.google.common.util.concurrent.ListenableFuture;
@VirtualHost @VirtualHost
@SkipEncoding('/') @SkipEncoding('/')
@RequestFilters(RequestAuthorizeSignature.class) @RequestFilters(RequestAuthorizeSignature.class)
@Endpoint(S3.class)
@BlobScope(CONTAINER) @BlobScope(CONTAINER)
public interface S3AsyncClient { public interface S3AsyncClient {
public static final String VERSION = "2006-03-01";
/** /**
* Creates a default implementation of S3Object * Creates a default implementation of S3Object

View File

@ -45,13 +45,13 @@ import com.google.inject.Module;
*/ */
public class S3ContextBuilder extends BlobStoreContextBuilder<S3Client, S3AsyncClient> { public class S3ContextBuilder extends BlobStoreContextBuilder<S3Client, S3AsyncClient> {
public S3ContextBuilder(String providerName, Properties props) { public S3ContextBuilder(Properties props) {
super(providerName, S3Client.class, S3AsyncClient.class, props); super(S3Client.class, S3AsyncClient.class, props);
} }
@Override @Override
protected void addContextModule(String providerName, List<Module> modules) { protected void addContextModule(List<Module> modules) {
modules.add(new S3BlobStoreContextModule(providerName)); modules.add(new S3BlobStoreContextModule());
} }
@Override @Override

View File

@ -1,67 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.s3;
import java.net.URI;
import java.util.Properties;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Module;
/**
* Creates {@link S3Context} instances based on the most commonly requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see S3AsyncClient
*/
public class S3ContextFactory {
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(properties).build()).withModules(
modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(Properties properties, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
.buildBlobStoreContext();
}
public static BlobStoreContext createContext(String awsAccessKeyId, String awsSecretAccessKey,
Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
.build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(URI endpoint, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
}
}

View File

@ -18,27 +18,22 @@
*/ */
package org.jclouds.aws.s3; package org.jclouds.aws.s3;
import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_DEFAULT_REGIONS;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_AUTH_TAG; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_AUTH_TAG;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_DEFAULT_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_ENDPOINT;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_HEADER_TAG; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_HEADER_TAG;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_SERVICE_EXPR; import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_SERVICE_EXPR;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_SESSIONINTERVAL;
import static org.jclouds.blobstore.reference.BlobStoreConstants.DIRECTORY_SUFFIX_FOLDER; import static org.jclouds.blobstore.reference.BlobStoreConstants.DIRECTORY_SUFFIX_FOLDER;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.PropertiesBuilder; import org.jclouds.PropertiesBuilder;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.reference.S3Constants;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -51,38 +46,32 @@ public class S3PropertiesBuilder extends PropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, S3AsyncClient.VERSION);
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-amz-meta-"); properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-amz-meta-");
properties.setProperty(PROPERTY_S3_AUTH_TAG, "AWS"); properties.setProperty(PROPERTY_S3_AUTH_TAG, "AWS");
properties.setProperty(PROPERTY_S3_HEADER_TAG, "aws"); properties.setProperty(PROPERTY_S3_HEADER_TAG, "aws");
properties.setProperty(PROPERTY_S3_SERVICE_EXPR, properties.setProperty(PROPERTY_S3_SERVICE_EXPR, "\\.s3[^.]*\\.amazonaws\\.com");
"\\.s3[^.]*\\.amazonaws\\.com");
properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true");
addEndpoints(properties); addEndpoints(properties);
properties.setProperty(PROPERTY_S3_SESSIONINTERVAL, "60"); properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX, DIRECTORY_SUFFIX_FOLDER);
properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX,
DIRECTORY_SUFFIX_FOLDER);
return properties; return properties;
} }
protected Properties addEndpoints(Properties properties) { protected Properties addEndpoints(Properties properties) {
properties.setProperty(PROPERTY_S3_REGIONS, Joiner.on(',').join( properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_STANDARD,
Region.US_STANDARD, Region.US_EAST_1, Region.US_WEST_1, "EU", Region.US_EAST_1, Region.US_WEST_1, "EU", Region.AP_SOUTHEAST_1));
Region.AP_SOUTHEAST_1)); properties.setProperty(PROPERTY_DEFAULT_REGIONS, Joiner.on(',').join(Region.US_STANDARD,
properties.setProperty(PROPERTY_S3_DEFAULT_REGIONS, Joiner.on(',').join( Region.US_EAST_1));
Region.US_STANDARD, Region.US_EAST_1)); properties.setProperty(PROPERTY_ENDPOINT, "https://s3.amazonaws.com");
properties.setProperty(PROPERTY_S3_ENDPOINT, "https://s3.amazonaws.com"); properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_STANDARD,
properties.setProperty(PROPERTY_S3_ENDPOINT + "." + Region.US_STANDARD, "https://s3.amazonaws.com");
"https://s3.amazonaws.com"); properties
properties.setProperty(PROPERTY_S3_ENDPOINT + "." + Region.US_EAST_1, .setProperty(PROPERTY_ENDPOINT + "." + Region.US_EAST_1, "https://s3.amazonaws.com");
"https://s3.amazonaws.com"); properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_WEST_1,
properties.setProperty(PROPERTY_S3_ENDPOINT + "." + Region.US_WEST_1, "https://s3-us-west-1.amazonaws.com");
"https://s3-us-west-1.amazonaws.com"); properties.setProperty(PROPERTY_ENDPOINT + "." + "EU", "https://s3-eu-west-1.amazonaws.com");
properties.setProperty(PROPERTY_S3_ENDPOINT + "." + "EU", properties.setProperty(PROPERTY_ENDPOINT + "." + Region.AP_SOUTHEAST_1,
"https://s3-eu-west-1.amazonaws.com"); "https://s3-ap-southeast-1.amazonaws.com");
properties.setProperty(
PROPERTY_S3_ENDPOINT + "." + Region.AP_SOUTHEAST_1,
"https://s3-ap-southeast-1.amazonaws.com");
return properties; return properties;
} }
@ -90,29 +79,8 @@ public class S3PropertiesBuilder extends PropertiesBuilder {
super(properties); super(properties);
} }
public S3PropertiesBuilder(String id, String secret) { public S3PropertiesBuilder() {
super(); super();
withCredentials(id, secret);
}
@Override
public S3PropertiesBuilder withCredentials(String id, String secret) {
properties.setProperty(PROPERTY_AWS_ACCESSKEYID, checkNotNull(id,
"awsAccessKeyId"));
properties.setProperty(PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(secret,
"awsSecretAccessKey"));
return this;
}
public S3PropertiesBuilder withEndpoint(URI endpoint) {
properties.setProperty(S3Constants.PROPERTY_S3_ENDPOINT, checkNotNull(
endpoint, "endpoint").toString());
return this;
}
public S3PropertiesBuilder withTimeStampExpiration(long seconds) {
properties.setProperty(PROPERTY_S3_SESSIONINTERVAL, seconds + "");
return this;
} }
protected S3PropertiesBuilder withMetaPrefix(String prefix) { protected S3PropertiesBuilder withMetaPrefix(String prefix) {

View File

@ -1,8 +1,8 @@
package org.jclouds.aws.s3; package org.jclouds.aws.s3;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_DEFAULT_REGIONS; import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_ENDPOINT; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_DEFAULT_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_REGIONS; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import java.util.Properties; import java.util.Properties;
@ -14,12 +14,11 @@ import java.util.Properties;
public class WalrusPropertiesBuilder extends S3PropertiesBuilder { public class WalrusPropertiesBuilder extends S3PropertiesBuilder {
@Override @Override
protected Properties addEndpoints(Properties properties) { protected Properties addEndpoints(Properties properties) {
properties.setProperty(PROPERTY_S3_REGIONS, "Walrus"); properties.setProperty(PROPERTY_REGIONS, "Walrus");
properties.setProperty(PROPERTY_S3_DEFAULT_REGIONS, "Walrus"); properties.setProperty(PROPERTY_DEFAULT_REGIONS, "Walrus");
properties.setProperty(PROPERTY_S3_ENDPOINT, properties.setProperty(PROPERTY_ENDPOINT, "http://ecc.eucalyptus.com:8773/services/Walrus");
"http://ecc.eucalyptus.com:8773/services/Walrus"); properties.setProperty(PROPERTY_ENDPOINT + ".Walrus",
properties.setProperty(PROPERTY_S3_ENDPOINT + ".Walrus", "http://ecc.eucalyptus.com:8773/services/Walrus");
"http://ecc.eucalyptus.com:8773/services/Walrus");
return properties; return properties;
} }
@ -27,7 +26,4 @@ public class WalrusPropertiesBuilder extends S3PropertiesBuilder {
super(properties); super(properties);
} }
public WalrusPropertiesBuilder(String id, String secret) {
super(id, secret);
}
} }

View File

@ -55,7 +55,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
@ -82,7 +82,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider; private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider;
@Inject @Inject
S3AsyncBlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
Location defaultLocation, Set<? extends Location> locations, S3AsyncClient async, Location defaultLocation, Set<? extends Location> locations, S3AsyncClient async,
S3Client sync, BucketToResourceMetadata bucket2ResourceMd, S3Client sync, BucketToResourceMetadata bucket2ResourceMd,

View File

@ -48,7 +48,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.internal.BaseBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
@ -74,7 +74,7 @@ public class S3BlobStore extends BaseBlobStore {
private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider; private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider;
@Inject @Inject
S3BlobStore(BlobStoreContext context, BlobStoreUtils blobUtils, Location defaultLocation, S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Location defaultLocation,
Set<? extends Location> locations, S3Client sync, Set<? extends Location> locations, S3Client sync,
BucketToResourceMetadata bucket2ResourceMd, BucketToResourceMetadata bucket2ResourceMd,
ContainerToBucketListOptions container2BucketListOptions, ContainerToBucketListOptions container2BucketListOptions,

View File

@ -22,12 +22,12 @@ import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.s3.S3; import org.jclouds.aws.Region;
import org.jclouds.aws.config.DefaultLocationProvider;
import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore; import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore;
import org.jclouds.aws.s3.blobstore.S3BlobStore; import org.jclouds.aws.s3.blobstore.S3BlobStore;
import org.jclouds.aws.s3.config.S3ContextModule;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
@ -37,10 +37,10 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.rest.annotations.Provider;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -50,17 +50,12 @@ import com.google.inject.TypeLiteral;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class S3BlobStoreContextModule extends S3ContextModule { public class S3BlobStoreContextModule extends AbstractModule {
private final String providerName;
public S3BlobStoreContextModule(String providerName) {
this.providerName = providerName;
}
@Override @Override
protected void configure() { protected void configure() {
super.configure();
install(new BlobStoreMapModule()); install(new BlobStoreMapModule());
bind(Location.class).toProvider(DefaultLocationProvider.class).in(Scopes.SINGLETON);
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL); bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON); bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON);
@ -71,20 +66,8 @@ public class S3BlobStoreContextModule extends S3ContextModule {
@Provides @Provides
@Singleton @Singleton
Location getDefaultLocation(@S3 final String region, Set<? extends Location> locations) { Set<? extends Location> provideLocations(@Region Set<String> regions,
return Iterables.find(locations, new Predicate<Location>() { @Provider String providerName) {
@Override
public boolean apply(Location input) {
return input.getId().equals(region);
}
});
}
@Provides
@Singleton
Set<? extends Location> provideLocations(@S3 Set<String> regions) {
Set<Location> locations = Sets.newHashSet(); Set<Location> locations = Sets.newHashSet();
Location s3 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location s3 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
for (String zone : regions) { for (String zone : regions) {

View File

@ -1,60 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.s3.config;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.HttpAsyncClient;
import org.jclouds.rest.HttpClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
* Configures the {@link S3ContextModule}; requires {@link S3AsyncClient} bound.
*
* @author Adrian Cole
*/
public class S3ContextModule extends AbstractModule {
@Override
protected void configure() {
}
@Provides
@Singleton
RestContext<S3Client, S3AsyncClient> provideContext(Closer closer,
HttpClient http, HttpAsyncClient asyncHttp, S3AsyncClient defaultApi,
S3Client syncApi, @S3 URI endPoint,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
return new RestContextImpl<S3Client, S3AsyncClient>(closer, http,
asyncHttp, syncApi, defaultApi, endPoint, account);
}
}

View File

@ -18,46 +18,28 @@
*/ */
package org.jclouds.aws.s3.config; package org.jclouds.aws.s3.config;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.Constants;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.config.AWSRestClientModule;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.filters.RequestAuthorizeSignature; import org.jclouds.aws.s3.filters.RequestAuthorizeSignature;
import org.jclouds.aws.s3.reference.S3Constants;
import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.name.Names;
/** /**
* Configures the S3 connection, including logging and http transport. * Configures the S3 connection, including logging and http transport.
@ -66,8 +48,7 @@ import com.google.inject.name.Names;
*/ */
@ConfiguresRestClient @ConfiguresRestClient
@RequiresHttp @RequiresHttp
public class S3RestClientModule extends public class S3RestClientModule extends AWSRestClientModule<S3Client, S3AsyncClient> {
RestClientModule<S3Client, S3AsyncClient> {
public S3RestClientModule() { public S3RestClientModule() {
super(S3Client.class, S3AsyncClient.class); super(S3Client.class, S3AsyncClient.class);
} }
@ -75,6 +56,7 @@ public class S3RestClientModule extends
@Override @Override
protected void configure() { protected void configure() {
install(new S3ObjectModule()); install(new S3ObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
bind(RequestAuthorizeSignature.class).in(Scopes.SINGLETON); bind(RequestAuthorizeSignature.class).in(Scopes.SINGLETON);
super.configure(); super.configure();
} }
@ -96,76 +78,13 @@ public class S3RestClientModule extends
*/ */
@Provides @Provides
@TimeStamp @TimeStamp
Supplier<String> provideTimeStampCache( @Singleton
@Named(S3Constants.PROPERTY_S3_SESSIONINTERVAL) long seconds, Supplier<String> provideTimeStampCache(@Named(Constants.PROPERTY_SESSION_INTERVAL) long seconds,
final DateService dateService) { final DateService dateService) {
return new ExpirableSupplier<String>(new Supplier<String>() { return new ExpirableSupplier<String>(new Supplier<String>() {
public String get() { public String get() {
return dateService.rfc822DateFormat(); return dateService.rfc822DateFormat();
} }
}, seconds, TimeUnit.SECONDS); }, seconds, TimeUnit.SECONDS);
} }
@Provides
@Singleton
@S3
Map<String, URI> provideRegions(
@Named(S3Constants.PROPERTY_S3_REGIONS) String regionString,
Injector injector) {
Map<String, URI> regions = Maps.newLinkedHashMap();
for (String region : Splitter.on(',').split(regionString)) {
regions.put(region, URI.create(injector.getInstance(Key.get(
String.class, Names.named(S3Constants.PROPERTY_S3_ENDPOINT + "."
+ region)))));
}
return regions;
}
@Provides
@Singleton
@S3
Set<String> provideRegions(@S3 Map<String, URI> map) {
return map.keySet();
}
@Provides
@Singleton
@S3
protected URI provideS3URI(
@Named(S3Constants.PROPERTY_S3_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Provides
@Singleton
@S3
String getDefaultRegion(@S3 final URI uri, @S3 Map<String, URI> map) {
return Iterables.find(map.entrySet(),
new Predicate<Entry<String, URI>>() {
@Override
public boolean apply(Entry<String, URI> input) {
return input.getValue().equals(uri);
}
}).getKey();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
ParseAWSErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AWSClientErrorRetryHandler.class);
}
} }

View File

@ -45,19 +45,19 @@ public enum CannedAccessPolicy {
*/ */
PRIVATE("private"), PRIVATE("private"),
/** /**
* Owner gets FULL_CONTROL and the anonymous principal is granted READ * Owner gets FULL_CONTROL and the anonymous identity is granted READ
* access. If this policy is used on an object, it can be read from a * access. If this policy is used on an object, it can be read from a
* browser with no authentication. * browser with no authentication.
*/ */
PUBLIC_READ("public-read"), PUBLIC_READ("public-read"),
/** /**
* Owner gets FULL_CONTROL, the anonymous principal is granted READ and * Owner gets FULL_CONTROL, the anonymous identity is granted READ and
* WRITE access. This can be a useful policy to apply to a bucket, but is * WRITE access. This can be a useful policy to apply to a bucket, but is
* generally not recommended. * generally not recommended.
*/ */
PUBLIC_READ_WRITE("public-read-write"), PUBLIC_READ_WRITE("public-read-write"),
/** /**
* Owner gets FULL_CONTROL, and any principal authenticated as a registered * Owner gets FULL_CONTROL, and any identity authenticated as a registered
* Amazon S3 user is granted READ access. * Amazon S3 user is granted READ access.
*/ */
AUTHENTICATED_READ("authenticated-read"); AUTHENTICATED_READ("authenticated-read");

View File

@ -52,20 +52,17 @@ import com.google.common.collect.ImmutableSet;
/** /**
* Signs the S3 request. * Signs the S3 request.
* *
* @see <a href= * @see <a href= "http://docs.amazonwebservices.com/AmazonS3/latest/RESTAuthentication.html" />
* "http://docs.amazonwebservices.com/AmazonS3/latest/RESTAuthentication.html"
* />
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
@Singleton @Singleton
public class RequestAuthorizeSignature implements HttpRequestFilter, public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSigner {
RequestSigner {
private final String[] firstHeadersToSign = new String[] { "Content-MD5", private final String[] firstHeadersToSign = new String[] { "Content-MD5",
HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE }; HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE };
public static Set<String> SPECIAL_QUERIES = ImmutableSet.of("acl", public static Set<String> SPECIAL_QUERIES = ImmutableSet.of("acl", "torrent", "logging",
"torrent", "logging", "location", "requestPayment"); "location", "requestPayment");
private final SignatureWire signatureWire; private final SignatureWire signatureWire;
private final String accessKey; private final String accessKey;
private final String secretKey; private final String secretKey;
@ -82,13 +79,12 @@ public class RequestAuthorizeSignature implements HttpRequestFilter,
@Inject @Inject
public RequestAuthorizeSignature(SignatureWire signatureWire, public RequestAuthorizeSignature(SignatureWire signatureWire,
@Named(S3Constants.PROPERTY_S3_AUTH_TAG) String authTag, @Named(S3Constants.PROPERTY_S3_AUTH_TAG) String authTag,
@Named(S3Constants.PROPERTY_S3_SERVICE_EXPR) String srvExpr, @Named(S3Constants.PROPERTY_S3_SERVICE_EXPR) String srvExpr,
@Named(S3Constants.PROPERTY_S3_HEADER_TAG) String headerTag, @Named(S3Constants.PROPERTY_S3_HEADER_TAG) String headerTag,
@Named(S3Constants.PROPERTY_AWS_ACCESSKEYID) String accessKey, @Named(Constants.PROPERTY_IDENTITY) String accessKey,
@Named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY) String secretKey, @Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
@TimeStamp Provider<String> timeStampProvider, @TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
EncryptionService encryptionService) {
this.srvExpr = srvExpr; this.srvExpr = srvExpr;
this.headerTag = headerTag; this.headerTag = headerTag;
this.authTag = authTag; this.authTag = authTag;
@ -121,21 +117,18 @@ public class RequestAuthorizeSignature implements HttpRequestFilter,
} }
private void calculateAndReplaceAuthHeader(HttpRequest request, String toSign) private void calculateAndReplaceAuthHeader(HttpRequest request, String toSign)
throws HttpException { throws HttpException {
String signature = sign(toSign); String signature = sign(toSign);
if (signatureWire.enabled()) if (signatureWire.enabled())
signatureWire.input(Utils.toInputStream(signature)); signatureWire.input(Utils.toInputStream(signature));
request.getHeaders().replaceValues( request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION,
HttpHeaders.AUTHORIZATION, Collections.singletonList(authTag + " " + accessKey + ":" + signature));
Collections.singletonList(authTag + " " + accessKey + ":"
+ signature));
} }
public String sign(String toSign) { public String sign(String toSign) {
String signature; String signature;
try { try {
signature = encryptionService.hmacSha1Base64(toSign, secretKey signature = encryptionService.hmacSha1Base64(toSign, secretKey.getBytes());
.getBytes());
} catch (Exception e) { } catch (Exception e) {
throw new HttpException("error signing request", e); throw new HttpException("error signing request", e);
} }
@ -148,7 +141,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter,
private void replaceDateHeader(HttpRequest request) { private void replaceDateHeader(HttpRequest request) {
request.getHeaders().replaceValues(HttpHeaders.DATE, request.getHeaders().replaceValues(HttpHeaders.DATE,
Collections.singletonList(timeStampProvider.get())); Collections.singletonList(timeStampProvider.get()));
} }
private void appendAmzHeaders(HttpRequest request, StringBuilder toSign) { private void appendAmzHeaders(HttpRequest request, StringBuilder toSign) {
@ -157,8 +150,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter,
if (header.startsWith("x-" + headerTag + "-")) { if (header.startsWith("x-" + headerTag + "-")) {
toSign.append(header.toLowerCase()).append(":"); toSign.append(header.toLowerCase()).append(":");
for (String value : request.getHeaders().get(header)) { for (String value : request.getHeaders().get(header)) {
toSign.append(Utils.replaceAll(value, NEWLINE_PATTERN, "")) toSign.append(Utils.replaceAll(value, NEWLINE_PATTERN, "")).append(",");
.append(",");
} }
toSign.deleteCharAt(toSign.lastIndexOf(",")); toSign.deleteCharAt(toSign.lastIndexOf(","));
toSign.append("\n"); toSign.append("\n");
@ -168,8 +160,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter,
private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) { private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
for (String header : firstHeadersToSign) for (String header : firstHeadersToSign)
toSign.append(valueOrEmpty(request.getHeaders().get(header))).append( toSign.append(valueOrEmpty(request.getHeaders().get(header))).append("\n");
"\n");
} }
@VisibleForTesting @VisibleForTesting
@ -177,7 +168,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter,
String hostHeader = request.getFirstHeaderOrNull(HttpHeaders.HOST); String hostHeader = request.getFirstHeaderOrNull(HttpHeaders.HOST);
if (hostHeader == null) if (hostHeader == null)
hostHeader = checkNotNull(request.getEndpoint().getHost(), hostHeader = checkNotNull(request.getEndpoint().getHost(),
"request.getEndPoint().getHost()"); "request.getEndPoint().getHost()");
if (hostHeader.matches(".*" + srvExpr)) if (hostHeader.matches(".*" + srvExpr))
toSign.append("/").append(hostHeader.replaceAll(srvExpr, "")); toSign.append("/").append(hostHeader.replaceAll(srvExpr, ""));
} }
@ -208,7 +199,6 @@ public class RequestAuthorizeSignature implements HttpRequestFilter,
} }
private String valueOrEmpty(Collection<String> collection) { private String valueOrEmpty(Collection<String> collection) {
return (collection != null && collection.size() >= 1) ? collection return (collection != null && collection.size() >= 1) ? collection.iterator().next() : "";
.iterator().next() : "";
} }
} }

View File

@ -20,8 +20,8 @@
package org.jclouds.aws.s3.functions; package org.jclouds.aws.s3.functions;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_DEFAULT_REGIONS; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_DEFAULT_REGIONS;
import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_S3_REGIONS; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -35,8 +35,8 @@ import com.google.common.collect.Iterables;
/** /**
* *
* Depending on your latency and legal requirements, you can specify a location * Depending on your latency and legal requirements, you can specify a location constraint that will
* constraint that will affect where your data physically resides. * affect where your data physically resides.
* *
* @author Adrian Cole * @author Adrian Cole
* *
@ -48,9 +48,8 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
private final Iterable<String> regions; private final Iterable<String> regions;
@Inject @Inject
BindRegionToXmlPayload( BindRegionToXmlPayload(@Named(PROPERTY_DEFAULT_REGIONS) String defaultRegions,
@Named(PROPERTY_S3_DEFAULT_REGIONS) String defaultRegions, @Named(PROPERTY_REGIONS) String regions) {
@Named(PROPERTY_S3_REGIONS) String regions) {
this.defaultRegions = Splitter.on(',').split(defaultRegions); this.defaultRegions = Splitter.on(',').split(defaultRegions);
this.regions = Splitter.on(',').split(regions); this.regions = Splitter.on(',').split(regions);
} }
@ -58,8 +57,7 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
@Override @Override
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
input = input == null ? Iterables.get(defaultRegions, 0) : input; input = input == null ? Iterables.get(defaultRegions, 0) : input;
checkArgument(input instanceof String, checkArgument(input instanceof String, "this binder is only valid for Region!");
"this binder is only valid for Region!");
String constraint = (String) input; String constraint = (String) input;
String value = null; String value = null;
if (Iterables.contains(defaultRegions, constraint)) { if (Iterables.contains(defaultRegions, constraint)) {
@ -71,9 +69,9 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
throw new IllegalStateException("unimplemented location: " + constraint); throw new IllegalStateException("unimplemented location: " + constraint);
} }
String payload = String String payload = String
.format( .format(
"<CreateBucketConfiguration><LocationConstraint>%s</LocationConstraint></CreateBucketConfiguration>", "<CreateBucketConfiguration><LocationConstraint>%s</LocationConstraint></CreateBucketConfiguration>",
value); value);
super.bindToRequest(request, payload); super.bindToRequest(request, payload);
} }

View File

@ -18,14 +18,12 @@
*/ */
package org.jclouds.aws.s3.reference; package org.jclouds.aws.s3.reference;
import org.jclouds.aws.reference.AWSConstants;
/** /**
* Configuration properties and constants used in S3 connections. * Configuration properties and constants used in S3 connections.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface S3Constants extends AWSConstants, S3Headers { public interface S3Constants {
/** /**
* S3 service's XML Namespace, as used in XML request and response documents. * S3 service's XML Namespace, as used in XML request and response documents.
@ -35,15 +33,9 @@ public interface S3Constants extends AWSConstants, S3Headers {
public static final String MARKER = "marker"; public static final String MARKER = "marker";
public static final String MAX_KEYS = "max-keys"; public static final String MAX_KEYS = "max-keys";
public static final String DELIMITER = "delimiter"; public static final String DELIMITER = "delimiter";
public static final String PROPERTY_S3_ENDPOINT = "jclouds.s3.endpoint";
public static final String PROPERTY_S3_REGIONS = "jclouds.s3.regions";
public static final String PROPERTY_S3_DEFAULT_REGIONS = "jclouds.s3.default-regions";
public static final String PROPERTY_S3_SERVICE_EXPR = "jclouds.service.expr"; public static final String PROPERTY_S3_SERVICE_EXPR = "jclouds.service.expr";
/**
* how long do we wait before obtaining a new timestamp for requests.
*/
public static final String PROPERTY_S3_SESSIONINTERVAL = "jclouds.s3.sessioninterval";
public static final String PROPERTY_S3_AUTH_TAG = "jclouds.s3.auth.tag"; public static final String PROPERTY_S3_AUTH_TAG = "jclouds.s3.auth.tag";
public static final String PROPERTY_S3_HEADER_TAG = "jclouds.s3.header.tag"; public static final String PROPERTY_S3_HEADER_TAG = "jclouds.s3.header.tag";

View File

@ -29,9 +29,9 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.functions.RegionToEndpoint;
import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.aws.sqs.functions.QueueLocation; import org.jclouds.aws.sqs.functions.QueueLocation;
import org.jclouds.aws.sqs.functions.RegionToEndpoint;
import org.jclouds.aws.sqs.options.CreateQueueOptions; import org.jclouds.aws.sqs.options.CreateQueueOptions;
import org.jclouds.aws.sqs.options.ListQueuesOptions; import org.jclouds.aws.sqs.options.ListQueuesOptions;
import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler;
@ -52,9 +52,10 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-02-01") @FormParams(keys = VERSION, values = SQSAsyncClient.VERSION)
@VirtualHost @VirtualHost
public interface SQSAsyncClient { public interface SQSAsyncClient {
public static final String VERSION = "2009-02-01";
/** /**
* @see SQSClient#listQueuesInRegion * @see SQSClient#listQueuesInRegion

View File

@ -21,7 +21,6 @@ package org.jclouds.aws.sqs;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.jclouds.aws.sqs.config.SQSContextModule;
import org.jclouds.aws.sqs.config.SQSRestClientModule; import org.jclouds.aws.sqs.config.SQSRestClientModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.logging.jdk.config.JDKLoggingModule;
@ -45,23 +44,12 @@ import com.google.inject.Module;
*/ */
public class SQSContextBuilder extends RestContextBuilder<SQSClient, SQSAsyncClient> { public class SQSContextBuilder extends RestContextBuilder<SQSClient, SQSAsyncClient> {
public SQSContextBuilder(String providerName, Properties props) { public SQSContextBuilder(Properties props) {
super(providerName, SQSClient.class, SQSAsyncClient.class, props); super(SQSClient.class, SQSAsyncClient.class, props);
}
@Override
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new SQSContextModule(providerName));
} }
@Override @Override
protected void addClientModule(List<Module> modules) { protected void addClientModule(List<Module> modules) {
modules.add(new SQSRestClientModule()); modules.add(new SQSRestClientModule());
} }
@Override
public SQSContextBuilder withModules(Module... modules) {
return (SQSContextBuilder) super.withModules(modules);
}
} }

View File

@ -1,68 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.sqs;
import java.net.URI;
import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext;
import com.google.inject.Module;
/**
* Creates {@link SQSContext} instances based on the most commonly requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see SQSAsyncClient
*/
public class SQSContextFactory {
public static RestContext<SQSClient, SQSAsyncClient> createContext(Properties properties,
Module... modules) {
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(properties).build())
.withModules(modules).buildContext();
}
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<SQSClient, SQSAsyncClient> createContext(String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildContext();
}
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)
.buildContext();
}
}

View File

@ -18,20 +18,16 @@
*/ */
package org.jclouds.aws.sqs; package org.jclouds.aws.sqs;
import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_EXPIREINTERVAL; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY;
import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT;
import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT_AP_SOUTHEAST_1;
import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT_EU_WEST_1;
import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1;
import static org.jclouds.aws.sqs.reference.SQSConstants.PROPERTY_SQS_ENDPOINT_US_WEST_1;
import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.PropertiesBuilder; import org.jclouds.PropertiesBuilder;
import org.jclouds.aws.domain.Region;
import com.google.common.base.Joiner;
/** /**
* Builds properties used in SQS Clients * Builds properties used in SQS Clients
@ -42,42 +38,27 @@ public class SQSPropertiesBuilder extends PropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_SQS_ENDPOINT, "https://sqs.us-east-1.amazonaws.com"); properties.setProperty(PROPERTY_API_VERSION, SQSAsyncClient.VERSION);
properties properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_EAST_1,
.setProperty(PROPERTY_SQS_ENDPOINT_US_EAST_1, "https://sqs.us-east-1.amazonaws.com"); Region.US_WEST_1, Region.EU_WEST_1, Region.AP_SOUTHEAST_1));
properties properties.setProperty(PROPERTY_ENDPOINT, "https://sqs.us-east-1.amazonaws.com");
.setProperty(PROPERTY_SQS_ENDPOINT_US_WEST_1, "https://sqs.us-west-1.amazonaws.com"); properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_EAST_1,
properties "https://sqs.us-east-1.amazonaws.com");
.setProperty(PROPERTY_SQS_ENDPOINT_EU_WEST_1, "https://sqs.eu-west-1.amazonaws.com"); properties.setProperty(PROPERTY_ENDPOINT + "." + Region.US_WEST_1,
properties.setProperty(PROPERTY_SQS_ENDPOINT_AP_SOUTHEAST_1, "https://sqs.us-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.EU_WEST_1,
"https://sqs.eu-west-1.amazonaws.com");
properties.setProperty(PROPERTY_ENDPOINT + "." + Region.AP_SOUTHEAST_1,
"https://sqs.ap-southeast-1.amazonaws.com"); "https://sqs.ap-southeast-1.amazonaws.com");
properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, "60");
return properties; return properties;
} }
public SQSPropertiesBuilder() {
super();
}
public SQSPropertiesBuilder(Properties properties) { public SQSPropertiesBuilder(Properties properties) {
super(properties); super(properties);
} }
public SQSPropertiesBuilder(String id, String secret) {
super();
withCredentials(id, secret);
}
public SQSPropertiesBuilder withCredentials(String id, String secret) {
properties.setProperty(PROPERTY_AWS_ACCESSKEYID, checkNotNull(id, "awsAccessKeyId"));
properties.setProperty(PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(secret,
"awsSecretAccessKey"));
return this;
}
public SQSPropertiesBuilder withEndpoint(URI endpoint) {
properties.setProperty(PROPERTY_SQS_ENDPOINT, checkNotNull(endpoint, "endpoint").toString());
return this;
}
public SQSPropertiesBuilder withRequestExpiration(long seconds) {
properties.setProperty(PROPERTY_AWS_EXPIREINTERVAL, seconds + "");
return this;
}
} }

View File

@ -1,65 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.sqs.config;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.aws.sqs.SQS;
import org.jclouds.aws.sqs.SQSAsyncClient;
import org.jclouds.aws.sqs.SQSClient;
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.HttpAsyncClient;
import org.jclouds.rest.HttpClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
* Configures the SQS connection, including logging and http transport.
*
* @author Adrian Cole
*/
public class SQSContextModule extends AbstractModule {
public SQSContextModule(String providerName) {
}
@Override
protected void configure() {
bind(DateAdapter.class).to(CDateAdapter.class);
}
@Provides
@Singleton
RestContext<SQSClient, SQSAsyncClient> provideContext(Closer closer,
HttpClient http, HttpAsyncClient asyncHttp, SQSAsyncClient defaultApi,
SQSClient synchApi, @SQS URI endPoint,
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
return new RestContextImpl<SQSClient, SQSAsyncClient>(closer, http,
asyncHttp, synchApi, defaultApi, endPoint, account);
}
}

View File

@ -18,37 +18,11 @@
*/ */
package org.jclouds.aws.sqs.config; package org.jclouds.aws.sqs.config;
import java.net.URI; import org.jclouds.aws.config.AWSFormSigningRestClientModule;
import java.util.Date;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
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.aws.sqs.SQS;
import org.jclouds.aws.sqs.SQSAsyncClient; import org.jclouds.aws.sqs.SQSAsyncClient;
import org.jclouds.aws.sqs.SQSClient; import org.jclouds.aws.sqs.SQSClient;
import org.jclouds.aws.sqs.reference.SQSConstants;
import org.jclouds.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.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.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
/** /**
* Configures the SQS connection. * Configures the SQS connection.
@ -57,68 +31,10 @@ import com.google.inject.Provides;
*/ */
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public class SQSRestClientModule extends RestClientModule<SQSClient, SQSAsyncClient> { public class SQSRestClientModule extends AWSFormSigningRestClientModule<SQSClient, SQSAsyncClient> {
public SQSRestClientModule() { public SQSRestClientModule() {
super(SQSClient.class, SQSAsyncClient.class); super(SQSClient.class, SQSAsyncClient.class);
} }
@Provides
@TimeStamp
protected String provideTimeStamp(final DateService dateService,
@Named(SQSConstants.PROPERTY_AWS_EXPIREINTERVAL) final int expiration) {
return dateService.iso8601DateFormat(new Date(System.currentTimeMillis()
+ (expiration * 1000)));
}
@Provides
@Singleton
@SQS
Map<String, URI> provideRegions(
@Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_EAST_1) String useast,
@Named(SQSConstants.PROPERTY_SQS_ENDPOINT_US_WEST_1) String uswest,
@Named(SQSConstants.PROPERTY_SQS_ENDPOINT_EU_WEST_1) String euwest,
@Named(SQSConstants.PROPERTY_SQS_ENDPOINT_AP_SOUTHEAST_1) String apsoutheast) {
return ImmutableMap.<String, URI> of(Region.US_EAST_1, URI.create(useast), Region.US_WEST_1,
URI.create(uswest), Region.EU_WEST_1, URI.create(euwest), Region.AP_SOUTHEAST_1, URI
.create(apsoutheast));
}
@Provides
@Singleton
@SQS
protected URI provideURI(@Named(SQSConstants.PROPERTY_SQS_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Provides
@Singleton
@SQS
String getDefaultRegion(@SQS URI uri, @SQS Map<String, URI> map) {
return ImmutableBiMap.<String, URI> builder().putAll(map).build().inverse().get(uri);
}
@Provides
@Singleton
RequestSigner provideRequestSigner(FormSigner in) {
return in;
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
ParseAWSErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
ParseAWSErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
AWSRedirectionRetryHandler.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AWSClientErrorRetryHandler.class);
}
} }

View File

@ -1,36 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.sqs.reference;
import org.jclouds.aws.reference.AWSConstants;
/**
* Configuration properties and constants used in SQS connections.
*
* @author Adrian Cole
*/
public interface SQSConstants extends AWSConstants {
public static final String PROPERTY_SQS_ENDPOINT = "jclouds.sqs.endpoint";
public static final String PROPERTY_SQS_ENDPOINT_EU_WEST_1 = "jclouds.sqs.endpoint.eu_west_1";
public static final String PROPERTY_SQS_ENDPOINT_US_EAST_1 = "jclouds.sqs.endpoint.us_east_1";
public static final String PROPERTY_SQS_ENDPOINT_US_WEST_1 = "jclouds.sqs.endpoint.us_west_1";
public static final String PROPERTY_SQS_ENDPOINT_AP_SOUTHEAST_1 = "jclouds.sqs.endpoint.ap_southeast_1";
}

View File

@ -25,7 +25,7 @@ import javax.inject.Inject;
import javax.inject.Provider; import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.Region;
import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -46,7 +46,7 @@ public class QueueHandler extends ParseSax.HandlerWithResult<Queue> {
private final Provider<UriBuilder> uriBuilderProvider; private final Provider<UriBuilder> uriBuilderProvider;
@Inject @Inject
QueueHandler(Provider<UriBuilder> uriBuilderProvider, @SQS Map<String, URI> regionMap) { QueueHandler(Provider<UriBuilder> uriBuilderProvider, @Region Map<String, URI> regionMap) {
this.uriBuilderProvider = uriBuilderProvider; this.uriBuilderProvider = uriBuilderProvider;
this.regionBiMap = ImmutableBiMap.<String, URI> builder().putAll(regionMap).build(); this.regionBiMap = ImmutableBiMap.<String, URI> builder().putAll(regionMap).build();
} }

View File

@ -26,7 +26,7 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.sqs.SQS; import org.jclouds.aws.Region;
import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler; import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
@ -45,7 +45,7 @@ import com.google.common.base.Throwables;
public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements
Function<HttpResponse, Set<Queue>> { Function<HttpResponse, Set<Queue>> {
@Inject @Inject
RegexListQueuesResponseHandler(@SQS Map<String, URI> regionMap) { RegexListQueuesResponseHandler(@Region Map<String, URI> regionMap) {
super(regionMap); super(regionMap);
} }

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