Merge pull request #773 from grkvlt/openstack-extensions-server

Updating Nova to allow easier definition of OpenStack API providers with extensions
This commit is contained in:
Adrian Cole 2012-08-06 10:20:45 -07:00
commit 4d4c22cff9
3 changed files with 16 additions and 8 deletions

View File

@ -78,6 +78,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -86,11 +87,13 @@ import com.google.inject.Provides;
* @author Adrian Cole * @author Adrian Cole
*/ */
@ConfiguresRestClient @ConfiguresRestClient
public class NovaRestClientModule extends RestClientModule<NovaApi, NovaAsyncApi> { public class NovaRestClientModule<S extends NovaApi, A extends NovaAsyncApi> extends RestClientModule<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(ServerApi.class, ServerAsyncApi.class).put(FlavorApi.class, FlavorAsyncApi.class) .put(ServerApi.class, ServerAsyncApi.class)
.put(ImageApi.class, ImageAsyncApi.class).put(ExtensionApi.class, ExtensionAsyncApi.class) .put(FlavorApi.class, FlavorAsyncApi.class)
.put(ImageApi.class, ImageAsyncApi.class)
.put(ExtensionApi.class, ExtensionAsyncApi.class)
.put(FloatingIPApi.class, FloatingIPAsyncApi.class) .put(FloatingIPApi.class, FloatingIPAsyncApi.class)
.put(SecurityGroupApi.class, SecurityGroupAsyncApi.class) .put(SecurityGroupApi.class, SecurityGroupAsyncApi.class)
.put(KeyPairApi.class, KeyPairAsyncApi.class) .put(KeyPairApi.class, KeyPairAsyncApi.class)
@ -106,9 +109,14 @@ public class NovaRestClientModule extends RestClientModule<NovaApi, NovaAsyncApi
.put(QuotaClassApi.class, QuotaClassAsyncApi.class) .put(QuotaClassApi.class, QuotaClassAsyncApi.class)
.put(VolumeTypeApi.class, VolumeTypeAsyncApi.class) .put(VolumeTypeApi.class, VolumeTypeAsyncApi.class)
.build(); .build();
public NovaRestClientModule() { public NovaRestClientModule() {
super(DELEGATE_MAP); super(TypeToken.class.cast(TypeToken.of(NovaApi.class)), TypeToken.class.cast(TypeToken.of(NovaAsyncApi.class)), DELEGATE_MAP);
}
protected NovaRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
Map<Class<?>, Class<?>> sync2Async) {
super(syncClientType, asyncClientType, sync2Async);
} }
@Override @Override

View File

@ -54,7 +54,7 @@ public interface ServerApi {
* *
* @return all servers (all details) * @return all servers (all details)
*/ */
Set<Server> listServersInDetail(); Set<? extends Server> listServersInDetail();
/** /**
* List details of the specified server * List details of the specified server

View File

@ -86,7 +86,7 @@ public interface ServerAsyncApi {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/servers/detail") @Path("/servers/detail")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Server>> listServersInDetail(); ListenableFuture<? extends Set<? extends Server>> listServersInDetail();
/** /**
* @see ServerApi#getServer * @see ServerApi#getServer
@ -96,7 +96,7 @@ public interface ServerAsyncApi {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/servers/{id}") @Path("/servers/{id}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Server> getServer(@PathParam("id") String id); ListenableFuture<? extends Server> getServer(@PathParam("id") String id);
/** /**
* @see ServerApi#deleteServer * @see ServerApi#deleteServer