Making more OpenStack Nova APIs extensible using generic return values

This commit is contained in:
Andrew Donald Kennedy 2012-08-09 15:55:35 +01:00
parent c679e73ce1
commit 8c544ddef0
7 changed files with 10 additions and 10 deletions

View File

@ -159,12 +159,12 @@ public class NovaComputeServiceAdapter implements
Set<String> zones = zoneIds.get(); Set<String> zones = zoneIds.get();
checkState(zones.size() > 0, "no zones found in supplier %s", zoneIds); checkState(zones.size() > 0, "no zones found in supplier %s", zoneIds);
for (final String zoneId : zones) { for (final String zoneId : zones) {
Set<Image> images = novaApi.getImageApiForZone(zoneId).listImagesInDetail(); Set<? extends Image> images = novaApi.getImageApiForZone(zoneId).listImagesInDetail();
if (images.size() == 0) { if (images.size() == 0) {
logger.debug("no images found in zone %s", zoneId); logger.debug("no images found in zone %s", zoneId);
continue; continue;
} }
Iterable<Image> active = filter(images, ImagePredicates.statusEquals(Image.Status.ACTIVE)); Iterable<? extends Image> active = filter(images, ImagePredicates.statusEquals(Image.Status.ACTIVE));
if (images.size() == 0) { if (images.size() == 0) {
logger.debug("no images with status active in zone %s; non-active: %s", zoneId, logger.debug("no images with status active in zone %s; non-active: %s", zoneId,
transform(active, new Function<Image, String>() { transform(active, new Function<Image, String>() {

View File

@ -50,7 +50,7 @@ public interface FlavorApi {
* *
* @return all flavors (all details) * @return all flavors (all details)
*/ */
Set<Flavor> listFlavorsInDetail(); Set<? extends Flavor> listFlavorsInDetail();
/** /**
* List details of the specified flavor * List details of the specified flavor

View File

@ -71,7 +71,7 @@ public interface FlavorAsyncApi {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/flavors/detail") @Path("/flavors/detail")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Flavor>> listFlavorsInDetail(); ListenableFuture<? extends Set<? extends Flavor>> listFlavorsInDetail();
/** /**
* @see FlavorApi#getFlavor * @see FlavorApi#getFlavor
@ -81,6 +81,6 @@ public interface FlavorAsyncApi {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/flavors/{id}") @Path("/flavors/{id}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Flavor> getFlavor(@PathParam("id") String id); ListenableFuture<? extends Flavor> getFlavor(@PathParam("id") String id);
} }

View File

@ -50,7 +50,7 @@ public interface ImageApi {
* *
* @return all images (all details) * @return all images (all details)
*/ */
Set<Image> listImagesInDetail(); Set<? extends Image> listImagesInDetail();
/** /**
* List details of the specified image * List details of the specified image

View File

@ -69,7 +69,7 @@ public interface ImageAsyncApi {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/images/detail") @Path("/images/detail")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Image>> listImagesInDetail(); ListenableFuture<? extends Set<? extends Image>> listImagesInDetail();
/** /**
* @see ImageApi#getImage * @see ImageApi#getImage
@ -79,7 +79,7 @@ public interface ImageAsyncApi {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/images/{id}") @Path("/images/{id}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Image> getImage(@PathParam("id") String id); ListenableFuture<? extends Image> getImage(@PathParam("id") String id);
/** /**
* @see ImageApi#deleteImage * @see ImageApi#deleteImage

View File

@ -66,7 +66,7 @@ public class FlavorApiLiveTest extends BaseNovaApiLiveTest {
public void testListFlavorsInDetail() throws Exception { public void testListFlavorsInDetail() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) { for (String zoneId : novaContext.getApi().getConfiguredZones()) {
FlavorApi api = novaContext.getApi().getFlavorApiForZone(zoneId); FlavorApi api = novaContext.getApi().getFlavorApiForZone(zoneId);
Set<Flavor> response = api.listFlavorsInDetail(); Set<? extends Flavor> response = api.listFlavorsInDetail();
assert null != response; assert null != response;
assertTrue(response.size() >= 0); assertTrue(response.size() >= 0);
for (Flavor flavor : response) { for (Flavor flavor : response) {

View File

@ -58,7 +58,7 @@ public class ImageApiLiveTest extends BaseNovaApiLiveTest {
public void testListImagesInDetail() throws Exception { public void testListImagesInDetail() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) { for (String zoneId : novaContext.getApi().getConfiguredZones()) {
ImageApi api = novaContext.getApi().getImageApiForZone(zoneId); ImageApi api = novaContext.getApi().getImageApiForZone(zoneId);
Set<Image> response = api.listImagesInDetail(); Set<? extends Image> response = api.listImagesInDetail();
assertNotNull(response); assertNotNull(response);
assertTrue(response.size() >= 0); assertTrue(response.size() >= 0);
for (Image image : response) { for (Image image : response) {