mirror of https://github.com/apache/jclouds.git
carve out EC2Api/EC2AsyncApi for new features
This commit is contained in:
parent
0838276f21
commit
36adaa8c96
|
@ -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<? extends WindowsApi> windowsOption = ec2Client.getWindowsApi();
|
||||
* checkState(windowsOption.isPresent(), "windows feature required, but not present");
|
||||
* </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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
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.AvailabilityZoneAndRegionAsyncClient;
|
||||
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.SecurityGroupAsyncClient;
|
||||
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.EndpointParam;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to EC2 services.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface EC2AsyncClient {
|
||||
public final static String VERSION = "2010-06-15";
|
||||
/**
|
||||
*
|
||||
* @return the Region codes configured
|
||||
*/
|
||||
@Provides
|
||||
@Region
|
||||
Set<String> getConfiguredRegions();
|
||||
public interface EC2AsyncClient extends EC2AsyncApi {
|
||||
public static final String VERSION = "2010-06-15";
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to AMI services.
|
||||
|
@ -100,16 +83,4 @@ public interface EC2AsyncClient {
|
|||
*/
|
||||
@Delegate
|
||||
ElasticBlockStoreAsyncClient getElasticBlockStoreServices();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Windows features.
|
||||
*/
|
||||
@Delegate
|
||||
@Beta
|
||||
WindowsAsyncApi getWindowsApi();
|
||||
|
||||
@Delegate
|
||||
@Beta
|
||||
WindowsAsyncApi getWindowsApiForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
}
|
||||
|
|
|
@ -18,11 +18,9 @@
|
|||
*/
|
||||
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.ec2.services.AMIClient;
|
||||
import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient;
|
||||
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.SecurityGroupClient;
|
||||
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.EndpointParam;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to EC2 services.
|
||||
|
@ -46,14 +37,7 @@ import com.google.inject.Provides;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
public interface EC2Client {
|
||||
/**
|
||||
*
|
||||
* @return the Region codes configured
|
||||
*/
|
||||
@Provides
|
||||
@Region
|
||||
Set<String> getConfiguredRegions();
|
||||
public interface EC2Client extends EC2Api {
|
||||
|
||||
/**
|
||||
* Provides synchronous access to AMI services.
|
||||
|
@ -102,17 +86,5 @@ public interface EC2Client {
|
|||
*/
|
||||
@Delegate
|
||||
ElasticBlockStoreClient getElasticBlockStoreServices();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Windows features.
|
||||
*/
|
||||
@Delegate
|
||||
@Beta
|
||||
WindowsApi getWindowsApi();
|
||||
|
||||
@Delegate
|
||||
@Beta
|
||||
WindowsApi getWindowsApiForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.ec2.compute.functions;
|
||||
|
||||
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.TimeUnit;
|
||||
|
@ -44,6 +45,7 @@ import org.jclouds.predicates.RetryablePredicate;
|
|||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
|
@ -71,12 +73,16 @@ public class PasswordCredentialsFromWindowsInstance implements Function<RunningI
|
|||
|
||||
@Override
|
||||
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();
|
||||
String privateKey = getPrivateKeyOrNull(instance);
|
||||
if (privateKey == null) {
|
||||
return credentials;
|
||||
}
|
||||
final WindowsApi windowsApi = ec2Client.getWindowsApiForRegion(instance.getRegion());
|
||||
// The Administrator password will take some time before it is ready - Amazon says
|
||||
// sometimes
|
||||
// 15 minutes.
|
||||
|
@ -114,4 +120,4 @@ public class PasswordCredentialsFromWindowsInstance implements Function<RunningI
|
|||
return keyPair != null ? keyPair.getKeyMaterial() : null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,11 @@ package org.jclouds.ec2.config;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.EC2Client;
|
||||
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.reflect.TypeToken;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
|
@ -64,7 +69,8 @@ import com.google.inject.Scopes;
|
|||
* @author Adrian Cole (EDIT: Nick Terry nterry@familysearch.org)
|
||||
*/
|
||||
@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> {
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(AMIClient.class, AMIAsyncClient.class)//
|
||||
|
@ -80,6 +86,7 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -88,6 +95,27 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
|
|||
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
|
||||
protected void installLocations() {
|
||||
install(new LocationModule());
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.ec2.domain.PasswordData;
|
||||
import org.jclouds.rest.annotations.SinceApiVersion;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
|
||||
|
@ -35,6 +36,7 @@ import com.google.common.annotations.Beta;
|
|||
*/
|
||||
@Timeout(duration = 45, timeUnit = TimeUnit.SECONDS)
|
||||
@Beta
|
||||
@SinceApiVersion("2008-08-08")
|
||||
public interface WindowsApi {
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.jclouds.ec2.xml.GetPasswordDataResponseHandler;
|
|||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.FormParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SinceApiVersion;
|
||||
import org.jclouds.rest.annotations.VirtualHost;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
@ -48,6 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@RequestFilters(FormSigner.class)
|
||||
@VirtualHost
|
||||
@Beta
|
||||
@SinceApiVersion("2008-08-08")
|
||||
public interface WindowsAsyncApi {
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,14 +22,14 @@ package org.jclouds.ec2.compute.internal;
|
|||
import java.util.Properties;
|
||||
|
||||
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.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
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.HttpResponse;
|
||||
import org.jclouds.location.Region;
|
||||
|
@ -48,7 +48,7 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EC2RestClientModuleExpectTest")
|
||||
public class EC2RestClientModuleExpectTest extends BaseEC2ExpectTest<Injector> {
|
||||
public class EC2RestClientModuleExpectTest extends BaseEC2ClientExpectTest<Injector> {
|
||||
private Injector injector;
|
||||
|
||||
public EC2RestClientModuleExpectTest() {
|
||||
|
|
|
@ -23,8 +23,8 @@ import static org.testng.Assert.assertNull;
|
|||
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.internal.BaseEC2ExpectTest;
|
||||
import org.jclouds.ec2.EC2Api;
|
||||
import org.jclouds.ec2.internal.BaseEC2ApiExpectTest;
|
||||
import org.jclouds.ec2.parse.GetPasswordDataResponseTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
@ -34,7 +34,7 @@ import org.testng.annotations.Test;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "WindowsApiExpectTest")
|
||||
public class WindowsApiExpectTest extends BaseEC2ExpectTest<EC2Client> {
|
||||
public class WindowsApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
|
||||
|
||||
public WindowsApiExpectTest() {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
|
@ -63,19 +63,17 @@ public class WindowsApiExpectTest extends BaseEC2ExpectTest<EC2Client> {
|
|||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_passworddata.xml", "text/xml")).build();
|
||||
|
||||
EC2Client apiWhenExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
EC2Api apiWhenExist = requestSendsResponse(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 {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
EC2Client apiWhenDontExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
EC2Api apiWhenDontExist = requestSendsResponse(get, getResponse);
|
||||
|
||||
assertNull(apiWhenDontExist.getWindowsApi().getPasswordDataForInstance("i-2574e22a"));
|
||||
assertNull(apiWhenDontExist.getWindowsApi().get().getPasswordDataForInstance("i-2574e22a"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,18 +18,22 @@
|
|||
*/
|
||||
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 com.google.common.base.Optional;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", testName = "WindowsApiLiveTest")
|
||||
public class WindowsApiLiveTest extends BaseEC2ClientLiveTest {
|
||||
|
||||
|
||||
@Test(groups = "live")
|
||||
public class WindowsApiLiveTest extends BaseEC2ApiLiveTest {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -19,29 +19,20 @@
|
|||
package org.jclouds.ec2.internal;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.aws.filters.FormSigner;
|
||||
import org.jclouds.date.DateService;
|
||||
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.HttpResponse;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.internal.BaseRestClientExpectTest;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
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> {
|
||||
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();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
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.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableMap.Builder;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EC2ElasticBlockStoreClientExpectTest")
|
||||
public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ExpectTest<EC2Client> {
|
||||
public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ClientExpectTest<EC2Client> {
|
||||
|
||||
public void testCreateVolumeInAvailabilityZone() {
|
||||
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
|
||||
|
|
Loading…
Reference in New Issue