openstack-glance: following example in swift and not extending openstack-common BaseListOptions

This commit is contained in:
Adam Lowe 2012-05-31 14:40:45 +01:00
parent fe53765de0
commit 57c11155fb
3 changed files with 34 additions and 45 deletions

View File

@ -48,10 +48,6 @@ public class BaseListOptions extends BaseHttpRequestOptions {
* Indicates where to begin listing. The list will only include objects that occur after the * Indicates where to begin listing. The list will only include objects that occur after the
* offset. This is convenient for pagination: To get the next page of results use the last result * offset. This is convenient for pagination: To get the next page of results use the last result
* number of the current page + current page offset as the offset. * number of the current page + current page offset as the offset.
* <p/>
* This isn't supported by newer openstack API implementations
*
* @see #marker(String) for the new mechanism to set the page offset
*/ */
public BaseListOptions startAt(long offset) { public BaseListOptions startAt(long offset) {
checkState(offset >= 0, "offset must be >= 0"); checkState(offset >= 0, "offset must be >= 0");
@ -59,19 +55,6 @@ public class BaseListOptions extends BaseHttpRequestOptions {
return this; return this;
} }
/**
* The marker parameter is the ID of the last item in the previous list
* (i.e. return the page of items after the marker).
* <p/>
* This is only supported by newer openstack API implementations
*
* @see #startAt for the old mechanism to set the page offset
*/
public BaseListOptions marker(String marker) {
queryParameters.put("marker", checkNotNull(marker, "marker"));
return this;
}
/** /**
* To reduce load on the service, list operations will return a maximum of 1,000 items at a time. * To reduce load on the service, list operations will return a maximum of 1,000 items at a time.
* To navigate the collection, the parameters limit and offset can be set in the URI * To navigate the collection, the parameters limit and offset can be set in the URI
@ -97,14 +80,6 @@ public class BaseListOptions extends BaseHttpRequestOptions {
return options.startAt(prefix); return options.startAt(prefix);
} }
/**
* @see BaseListOptions#marker
*/
public static BaseListOptions marker(String marker) {
BaseListOptions options = new BaseListOptions();
return options.marker(marker);
}
/** /**
* @see BaseListOptions#maxResults * @see BaseListOptions#maxResults
*/ */

View File

@ -18,14 +18,14 @@
*/ */
package org.jclouds.openstack.glance.v1_0.options; package org.jclouds.openstack.glance.v1_0.options;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.openstack.glance.v1_0.options.ImageField.*; import static org.jclouds.openstack.glance.v1_0.options.ImageField.*;
import java.util.Date; import org.jclouds.http.options.BaseHttpRequestOptions;
import org.jclouds.openstack.glance.v1_0.domain.ContainerFormat; import org.jclouds.openstack.glance.v1_0.domain.ContainerFormat;
import org.jclouds.openstack.glance.v1_0.domain.DiskFormat; import org.jclouds.openstack.glance.v1_0.domain.DiskFormat;
import org.jclouds.openstack.glance.v1_0.domain.Image.Status; import org.jclouds.openstack.glance.v1_0.domain.Image.Status;
import org.jclouds.openstack.options.BaseListOptions;
/** /**
* <h2></h2>Usage</h2> The recommended way to instantiate a ListImageOptions object is to statically import * <h2></h2>Usage</h2> The recommended way to instantiate a ListImageOptions object is to statically import
@ -36,13 +36,33 @@ import org.jclouds.openstack.options.BaseListOptions;
* *
* *
* // this will list the first 10 images with the name "name", minimum required disk of 5GB. * // this will list the first 10 images with the name "name", minimum required disk of 5GB.
* list = client.list(name("newName"), maxResults(10), minDisk(5)); * list = client.list(name("newName"), limit(10), minDisk(5));
* <code> * <code>
* *
* @author Adam Lowe * @author Adam Lowe
* @see <a href="http://glance.openstack.org/glanceapi.html"/> * @see <a href="http://glance.openstack.org/glanceapi.html"/>
*/ */
public class ListImageOptions extends BaseListOptions { public class ListImageOptions extends BaseHttpRequestOptions {
public static final ListImageOptions NONE = new ListImageOptions();
/**
* Given a string value x, return object names greater in value than the specified marker.
*/
public ListImageOptions marker(String marker) {
queryParameters.put("marker", checkNotNull(marker, "marker"));
return this;
}
/**
* For an integer value n, limits the number of results to n values.
*/
public ListImageOptions limit(int limit) {
checkState(limit >= 0, "limit must be >= 0");
checkState(limit <= 10000, "limit must be <= 10000");
queryParameters.put("limit", Integer.toString(limit));
return this;
}
/** /**
* Return only those images having a matching name attribute * Return only those images having a matching name attribute
*/ */
@ -228,24 +248,18 @@ public class ListImageOptions extends BaseListOptions {
} }
/** /**
* @see BaseListOptions#maxResults * @see ListImageOptions#limit
*/ */
public static ListImageOptions maxResults(int limit) { public static ListImageOptions limit(int limit) {
return ListImageOptions.class.cast(new ListImageOptions().maxResults(limit)); return new ListImageOptions().limit(limit);
} }
/** /**
* @see BaseListOptions#marker * @see ListImageOptions#marker
*/ */
public static ListImageOptions marker(String marker) { public static ListImageOptions marker(String marker) {
return ListImageOptions.class.cast(new ListImageOptions().marker(marker)); ListImageOptions options = new ListImageOptions();
} return options.marker(marker);
/**
* @see BaseListOptions#changesSince
*/
public static ListImageOptions changesSince(Date ifModifiedSince) {
return ListImageOptions.class.cast(new BaseListOptions().changesSince(ifModifiedSince));
} }
} }
} }

View File

@ -49,7 +49,7 @@ public class ImageClientLiveTest extends BaseGlanceClientLiveTest {
public void testList() throws Exception { public void testList() throws Exception {
for (String zoneId : glanceContext.getApi().getConfiguredRegions()) { for (String zoneId : glanceContext.getApi().getConfiguredRegions()) {
ImageClient client = glanceContext.getApi().getImageClientForRegion(zoneId); ImageClient client = glanceContext.getApi().getImageClientForRegion(zoneId);
Set<Image> response = client.list(ListImageOptions.Builder.maxResults(100)); Set<Image> response = client.list(ListImageOptions.Builder.limit(100));
assert null != response; assert null != response;
for (Image image : response) { for (Image image : response) {
checkImage(image); checkImage(image);
@ -103,7 +103,7 @@ public class ImageClientLiveTest extends BaseGlanceClientLiveTest {
assertEquals(details.getName(), "jclouds-live-test2"); assertEquals(details.getName(), "jclouds-live-test2");
assertEquals(details.getMinDisk(), 10); assertEquals(details.getMinDisk(), 10);
Image fromListing = Iterables.getOnlyElement(client.list(ListImageOptions.Builder.name("jclouds-live-test2"), ListImageOptions.Builder.maxResults(2), ListImageOptions.Builder.containerFormat(ContainerFormat.BARE))); Image fromListing = Iterables.getOnlyElement(client.list(ListImageOptions.Builder.name("jclouds-live-test2"), ListImageOptions.Builder.limit(2), ListImageOptions.Builder.containerFormat(ContainerFormat.BARE)));
assertEquals(fromListing.getId(), details.getId()); assertEquals(fromListing.getId(), details.getId());
assertEquals(fromListing.getSize(), details.getSize()); assertEquals(fromListing.getSize(), details.getSize());
@ -128,7 +128,7 @@ public class ImageClientLiveTest extends BaseGlanceClientLiveTest {
assertEquals(details.getSize().get().longValue(), imageData.getRawContent().length()); assertEquals(details.getSize().get().longValue(), imageData.getRawContent().length());
assertEquals(details.getMinDisk(), 10); assertEquals(details.getMinDisk(), 10);
Image fromListing = Iterables.getOnlyElement(client.list(ListImageOptions.Builder.name("jclouds-live-res-test2"), ListImageOptions.Builder.maxResults(2), ListImageOptions.Builder.containerFormat(ContainerFormat.BARE))); Image fromListing = Iterables.getOnlyElement(client.list(ListImageOptions.Builder.name("jclouds-live-res-test2"), ListImageOptions.Builder.limit(2), ListImageOptions.Builder.containerFormat(ContainerFormat.BARE)));
assertEquals(fromListing.getId(), details.getId()); assertEquals(fromListing.getId(), details.getId());
assertEquals(fromListing.getSize(), details.getSize()); assertEquals(fromListing.getSize(), details.getSize());