Merge pull request #984 from jclouds/ec2-api

carve out EC2Api/EC2AsyncApi for new features
This commit is contained in:
Adrian Cole 2012-11-12 18:08:51 -08:00
commit 88d2cf5610
17 changed files with 358 additions and 121 deletions

View File

@ -0,0 +1,77 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.ec2;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.ec2.features.WindowsApi;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import com.google.inject.Provides;
/**
* Provides access to EC2 features, broken up by feature group. Use of the
* {@link Optional} type allows you to check to see if the underlying
* implementation supports a particular feature before attempting to use it.
* This is useful in clones like OpenStack, CloudStack, or Eucalyptus, which
* track the api, but are always behind Amazon's service. In the case of Amazon
* ({@code aws-ec2}), you can expect all features to be present.
*
*
* Example
*
* <pre>
* Optional&lt;? extends WindowsApi&gt; windowsOption = ec2Client.getWindowsApi();
* checkState(windowsOption.isPresent(), &quot;windows feature required, but not present&quot;);
* </pre>
*
* @author Adrian Cole
* @see EC2AsyncApi
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface EC2Api {
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/**
* Provides synchronous access to Windows features.
*/
@Delegate
@Beta
Optional<? extends WindowsApi> getWindowsApi();
@Delegate
@Beta
Optional<? extends WindowsApi> getWindowsApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
}

View File

@ -0,0 +1,57 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.ec2;
import java.util.Set;
import org.jclouds.ec2.features.WindowsAsyncApi;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import com.google.common.base.Optional;
import com.google.inject.Provides;
/**
* Refer to javadoc for {@link EC2Api}, as this interface is the same, except
* features provide asynchronous return values.
*
* @author Adrian Cole
*/
public interface EC2AsyncApi {
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/**
* Provides asynchronous access to Windows features.
*/
@Delegate
Optional<? extends WindowsAsyncApi> getWindowsApi();
@Delegate
Optional<? extends WindowsAsyncApi> getWindowsApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
}

View File

@ -18,9 +18,6 @@
*/ */
package org.jclouds.ec2; package org.jclouds.ec2;
import java.util.Set;
import org.jclouds.ec2.features.WindowsAsyncApi;
import org.jclouds.ec2.services.AMIAsyncClient; import org.jclouds.ec2.services.AMIAsyncClient;
import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient;
import org.jclouds.ec2.services.ElasticBlockStoreAsyncClient; import org.jclouds.ec2.services.ElasticBlockStoreAsyncClient;
@ -29,29 +26,15 @@ import org.jclouds.ec2.services.InstanceAsyncClient;
import org.jclouds.ec2.services.KeyPairAsyncClient; import org.jclouds.ec2.services.KeyPairAsyncClient;
import org.jclouds.ec2.services.SecurityGroupAsyncClient; import org.jclouds.ec2.services.SecurityGroupAsyncClient;
import org.jclouds.ec2.services.WindowsAsyncClient; import org.jclouds.ec2.services.WindowsAsyncClient;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import com.google.common.annotations.Beta;
import com.google.inject.Provides;
/** /**
* Provides asynchronous access to EC2 services. * Provides asynchronous access to EC2 services.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface EC2AsyncClient { public interface EC2AsyncClient extends EC2AsyncApi {
public static final String VERSION = "2010-06-15"; public static final String VERSION = "2010-06-15";
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/** /**
* Provides asynchronous access to AMI services. * Provides asynchronous access to AMI services.
@ -100,16 +83,4 @@ public interface EC2AsyncClient {
*/ */
@Delegate @Delegate
ElasticBlockStoreAsyncClient getElasticBlockStoreServices(); ElasticBlockStoreAsyncClient getElasticBlockStoreServices();
/**
* Provides asynchronous access to Windows features.
*/
@Delegate
@Beta
WindowsAsyncApi getWindowsApi();
@Delegate
@Beta
WindowsAsyncApi getWindowsApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
} }

View File

@ -18,11 +18,9 @@
*/ */
package org.jclouds.ec2; package org.jclouds.ec2;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.ec2.features.WindowsApi;
import org.jclouds.ec2.services.AMIClient; import org.jclouds.ec2.services.AMIClient;
import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.ec2.services.ElasticBlockStoreClient; import org.jclouds.ec2.services.ElasticBlockStoreClient;
@ -31,14 +29,7 @@ import org.jclouds.ec2.services.InstanceClient;
import org.jclouds.ec2.services.KeyPairClient; import org.jclouds.ec2.services.KeyPairClient;
import org.jclouds.ec2.services.SecurityGroupClient; import org.jclouds.ec2.services.SecurityGroupClient;
import org.jclouds.ec2.services.WindowsClient; import org.jclouds.ec2.services.WindowsClient;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import com.google.common.annotations.Beta;
import com.google.inject.Provides;
/** /**
* Provides synchronous access to EC2 services. * Provides synchronous access to EC2 services.
@ -46,14 +37,7 @@ import com.google.inject.Provides;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface EC2Client { public interface EC2Client extends EC2Api {
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/** /**
* Provides synchronous access to AMI services. * Provides synchronous access to AMI services.
@ -103,16 +87,4 @@ public interface EC2Client {
@Delegate @Delegate
ElasticBlockStoreClient getElasticBlockStoreServices(); ElasticBlockStoreClient getElasticBlockStoreServices();
/**
* Provides synchronous access to Windows features.
*/
@Delegate
@Beta
WindowsApi getWindowsApi();
@Delegate
@Beta
WindowsApi getWindowsApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.ec2.compute.functions; package org.jclouds.ec2.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -44,6 +45,7 @@ import org.jclouds.predicates.RetryablePredicate;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.util.concurrent.Atomics; import com.google.common.util.concurrent.Atomics;
@ -72,12 +74,16 @@ public class PasswordCredentialsFromWindowsInstance implements Function<RunningI
@Override @Override
public LoginCredentials apply(final RunningInstance instance) { public LoginCredentials apply(final RunningInstance instance) {
Optional<? extends WindowsApi> windowsOption = ec2Client.getWindowsApiForRegion(instance.getRegion());
checkState(windowsOption.isPresent(), "windows feature not present in region %s", instance.getRegion());
final WindowsApi windowsApi = windowsOption.get();
LoginCredentials credentials = LoginCredentials.builder().user("Administrator").noPrivateKey().build(); LoginCredentials credentials = LoginCredentials.builder().user("Administrator").noPrivateKey().build();
String privateKey = getPrivateKeyOrNull(instance); String privateKey = getPrivateKeyOrNull(instance);
if (privateKey == null) { if (privateKey == null) {
return credentials; return credentials;
} }
final WindowsApi windowsApi = ec2Client.getWindowsApiForRegion(instance.getRegion());
// The Administrator password will take some time before it is ready - Amazon says // The Administrator password will take some time before it is ready - Amazon says
// sometimes // sometimes
// 15 minutes. // 15 minutes.

View File

@ -20,7 +20,11 @@ package org.jclouds.ec2.config;
import java.util.Map; import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.aws.config.WithZonesFormSigningRestClientModule; import org.jclouds.aws.config.WithZonesFormSigningRestClientModule;
import org.jclouds.ec2.EC2Api;
import org.jclouds.ec2.EC2AsyncApi;
import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.features.WindowsApi; import org.jclouds.ec2.features.WindowsApi;
@ -56,6 +60,7 @@ import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
/** /**
@ -64,7 +69,8 @@ import com.google.inject.Scopes;
* @author Adrian Cole (EDIT: Nick Terry nterry@familysearch.org) * @author Adrian Cole (EDIT: Nick Terry nterry@familysearch.org)
*/ */
@ConfiguresRestClient @ConfiguresRestClient
public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient> extends // EC2Api not EC2Client so that this can be used for new apps that only depend on EC2Api
public class EC2RestClientModule<S extends EC2Api, A extends EC2AsyncApi> extends
WithZonesFormSigningRestClientModule<S, A> { WithZonesFormSigningRestClientModule<S, A> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(AMIClient.class, AMIAsyncClient.class)// .put(AMIClient.class, AMIAsyncClient.class)//
@ -80,6 +86,7 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public EC2RestClientModule() { public EC2RestClientModule() {
// retaining top-level type of EC2Client vs EC2Api until we migrate all functionality up
super(TypeToken.class.cast(TypeToken.of(EC2Client.class)), TypeToken.class.cast(TypeToken.of(EC2AsyncClient.class)), DELEGATE_MAP); super(TypeToken.class.cast(TypeToken.of(EC2Client.class)), TypeToken.class.cast(TypeToken.of(EC2AsyncClient.class)), DELEGATE_MAP);
} }
@ -88,6 +95,27 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
super(syncClientType, asyncClientType, sync2Async); super(syncClientType, asyncClientType, sync2Async);
} }
/**
* so that we can make bindings to {@link EC2Api directly} until we switch
* off {@link @EC2Client}
*/
@Singleton
@Provides
EC2Api provideEC2Api(EC2Client in) {
return in;
}
/**
* so that we can make bindings to {@link EC2AsyncApi directly} until we switch
* off {@link @EC2AsyncClient}
*/
@Singleton
@Provides
EC2AsyncApi provideEC2Api(EC2AsyncClient in) {
return in;
}
@Override @Override
protected void installLocations() { protected void installLocations() {
install(new LocationModule()); install(new LocationModule());

View File

@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.ec2.domain.PasswordData; import org.jclouds.ec2.domain.PasswordData;
import org.jclouds.rest.annotations.SinceApiVersion;
import com.google.common.annotations.Beta; import com.google.common.annotations.Beta;
@ -35,6 +36,7 @@ import com.google.common.annotations.Beta;
*/ */
@Timeout(duration = 45, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 45, timeUnit = TimeUnit.SECONDS)
@Beta @Beta
@SinceApiVersion("2008-08-08")
public interface WindowsApi { public interface WindowsApi {
/** /**

View File

@ -30,6 +30,7 @@ import org.jclouds.ec2.xml.GetPasswordDataResponseHandler;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SinceApiVersion;
import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -48,6 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@VirtualHost @VirtualHost
@Beta @Beta
@SinceApiVersion("2008-08-08")
public interface WindowsAsyncApi { public interface WindowsAsyncApi {
/** /**

View File

@ -22,14 +22,14 @@ package org.jclouds.ec2.compute.internal;
import java.util.Properties; import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.ec2.internal.BaseEC2ExpectTest; import org.jclouds.ec2.internal.BaseEC2ClientExpectTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.inject.Module; import com.google.inject.Module;
public abstract class BaseEC2ComputeServiceContextExpectTest<T> extends BaseEC2ExpectTest<T> implements public abstract class BaseEC2ComputeServiceContextExpectTest<T> extends BaseEC2ClientExpectTest<T> implements
Function<ComputeServiceContext, T> { Function<ComputeServiceContext, T> {
@Override @Override

View File

@ -25,7 +25,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.jclouds.ec2.internal.BaseEC2ExpectTest; import org.jclouds.ec2.internal.BaseEC2ClientExpectTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.location.Region; import org.jclouds.location.Region;
@ -48,7 +48,7 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "EC2RestClientModuleExpectTest") @Test(groups = "unit", testName = "EC2RestClientModuleExpectTest")
public class EC2RestClientModuleExpectTest extends BaseEC2ExpectTest<Injector> { public class EC2RestClientModuleExpectTest extends BaseEC2ClientExpectTest<Injector> {
private Injector injector; private Injector injector;
public EC2RestClientModuleExpectTest() { public EC2RestClientModuleExpectTest() {

View File

@ -23,8 +23,8 @@ import static org.testng.Assert.assertNull;
import java.util.TimeZone; import java.util.TimeZone;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Api;
import org.jclouds.ec2.internal.BaseEC2ExpectTest; import org.jclouds.ec2.internal.BaseEC2ApiExpectTest;
import org.jclouds.ec2.parse.GetPasswordDataResponseTest; import org.jclouds.ec2.parse.GetPasswordDataResponseTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
@ -34,7 +34,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "WindowsApiExpectTest") @Test(groups = "unit", testName = "WindowsApiExpectTest")
public class WindowsApiExpectTest extends BaseEC2ExpectTest<EC2Client> { public class WindowsApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
public WindowsApiExpectTest() { public WindowsApiExpectTest() {
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
@ -63,19 +63,17 @@ public class WindowsApiExpectTest extends BaseEC2ExpectTest<EC2Client> {
HttpResponse getResponse = HttpResponse.builder().statusCode(200) HttpResponse getResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/get_passworddata.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/get_passworddata.xml", "text/xml")).build();
EC2Client apiWhenExist = requestSendsResponse( EC2Api apiWhenExist = requestSendsResponse(get, getResponse);
get, getResponse);
assertEquals(apiWhenExist.getWindowsApi().getPasswordDataForInstance("i-2574e22a").toString(), new GetPasswordDataResponseTest().expected().toString()); assertEquals(apiWhenExist.getWindowsApi().get().getPasswordDataForInstance("i-2574e22a").toString(), new GetPasswordDataResponseTest().expected().toString());
} }
public void testGetPasswordDataWhenResponseIs404() throws Exception { public void testGetPasswordDataWhenResponseIs404() throws Exception {
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
EC2Client apiWhenDontExist = requestSendsResponse( EC2Api apiWhenDontExist = requestSendsResponse(get, getResponse);
get, getResponse);
assertNull(apiWhenDontExist.getWindowsApi().getPasswordDataForInstance("i-2574e22a")); assertNull(apiWhenDontExist.getWindowsApi().get().getPasswordDataForInstance("i-2574e22a"));
} }
} }

View File

@ -18,18 +18,22 @@
*/ */
package org.jclouds.ec2.features; package org.jclouds.ec2.features;
import org.jclouds.ec2.internal.BaseEC2ClientLiveTest; import org.jclouds.ec2.internal.BaseEC2ApiLiveTest;
import org.testng.SkipException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Optional;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", testName = "WindowsApiLiveTest") @Test(groups = "live")
public class WindowsApiLiveTest extends BaseEC2ClientLiveTest { public class WindowsApiLiveTest extends BaseEC2ApiLiveTest {
protected WindowsApi api() { protected WindowsApi api() {
return context.getApi().getWindowsApi(); Optional<? extends WindowsApi> windowsOption = context.getApi().getWindowsApi();
if (!windowsOption.isPresent())
throw new SkipException("windows api not present");
return windowsOption.get();
} }
} }

View File

@ -0,0 +1,66 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.ec2.internal;
import java.util.concurrent.atomic.AtomicInteger;
import org.jclouds.date.DateService;
import org.jclouds.ec2.EC2Api;
import org.jclouds.ec2.EC2AsyncApi;
import org.jclouds.ec2.config.EC2RestClientModule;
import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.base.Supplier;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
public abstract class BaseEC2ApiExpectTest<T> extends BaseEC2ExpectTest<T> {
@ConfiguresRestClient
protected static class TestEC2RestClientModule extends EC2RestClientModule<EC2Api, EC2AsyncApi> {
@Override
protected void configure() {
super.configure();
// predicatable node names
final AtomicInteger suffix = new AtomicInteger();
bind(new TypeLiteral<Supplier<String>>() {
}).toInstance(new Supplier<String>() {
@Override
public String get() {
return suffix.getAndIncrement() + "";
}
});
}
@Override
@Provides
protected String provideTimeStamp(DateService dateService) {
return CONSTANT_DATE;
}
}
@Override
protected Module createModule() {
return new TestEC2RestClientModule();
}
}

View File

@ -0,0 +1,27 @@
package org.jclouds.ec2.internal;
import org.jclouds.apis.BaseContextLiveTest;
import org.jclouds.ec2.EC2Api;
import org.jclouds.ec2.EC2AsyncApi;
import org.jclouds.rest.RestContext;
import com.google.common.reflect.TypeToken;
/**
*
* @author Adrian Cole
*/
public class BaseEC2ApiLiveTest extends BaseContextLiveTest<RestContext<? extends EC2Api, ? extends EC2AsyncApi>> {
public BaseEC2ApiLiveTest() {
provider = "ec2";
}
@Override
protected TypeToken<RestContext<? extends EC2Api, ? extends EC2AsyncApi>> contextType() {
return new TypeToken<RestContext<? extends EC2Api, ? extends EC2AsyncApi>>() {
private static final long serialVersionUID = -5070937833892503232L;
};
}
}

View File

@ -0,0 +1,66 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.ec2.internal;
import java.util.concurrent.atomic.AtomicInteger;
import org.jclouds.date.DateService;
import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.config.EC2RestClientModule;
import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.base.Supplier;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
public abstract class BaseEC2ClientExpectTest<T> extends BaseEC2ExpectTest<T> {
@ConfiguresRestClient
protected static class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
@Override
protected void configure() {
super.configure();
// predicatable node names
final AtomicInteger suffix = new AtomicInteger();
bind(new TypeLiteral<Supplier<String>>() {
}).toInstance(new Supplier<String>() {
@Override
public String get() {
return suffix.getAndIncrement() + "";
}
});
}
@Override
@Provides
protected String provideTimeStamp(DateService dateService) {
return CONSTANT_DATE;
}
}
@Override
protected Module createModule() {
return new TestEC2RestClientModule();
}
}

View File

@ -19,29 +19,20 @@
package org.jclouds.ec2.internal; package org.jclouds.ec2.internal;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.config.EC2RestClientModule;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.rest.internal.BaseRestClientExpectTest;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> { public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z"; protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z";
@ -87,34 +78,4 @@ public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
describeAvailabilityZonesRequestResponse = builder.build(); describeAvailabilityZonesRequestResponse = builder.build();
} }
@ConfiguresRestClient
protected static class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
@Override
protected void configure() {
super.configure();
// predicatable node names
final AtomicInteger suffix = new AtomicInteger();
bind(new TypeLiteral<Supplier<String>>() {
}).toInstance(new Supplier<String>() {
@Override
public String get() {
return suffix.getAndIncrement() + "";
}
});
}
@Override
@Provides
protected String provideTimeStamp(DateService dateService) {
return CONSTANT_DATE;
}
}
@Override
protected Module createModule() {
return new TestEC2RestClientModule();
}
} }

View File

@ -22,7 +22,7 @@ import static org.testng.Assert.assertEquals;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.Volume; import org.jclouds.ec2.domain.Volume;
import org.jclouds.ec2.internal.BaseEC2ExpectTest; import org.jclouds.ec2.internal.BaseEC2ClientExpectTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableMap.Builder;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "EC2ElasticBlockStoreClientExpectTest") @Test(groups = "unit", testName = "EC2ElasticBlockStoreClientExpectTest")
public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ExpectTest<EC2Client> { public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ClientExpectTest<EC2Client> {
Volume creating = Volume.builder() Volume creating = Volume.builder()
.id("vol-2a21e543") .id("vol-2a21e543")
.status(Volume.Status.CREATING) .status(Volume.Status.CREATING)