JCLOUDS-686: Remove changesSince() query from base PaginationOptions

This commit is contained in:
Jeremy Daggett 2014-08-26 13:17:07 -07:00 committed by Jeremy Daggett
parent 9384575d1e
commit d309e45725
5 changed files with 99 additions and 57 deletions

View File

@ -30,9 +30,6 @@ import static org.jclouds.http.utils.Queries.queryParser;
/** /**
* Base class for a paginated collection in OpenStack. * Base class for a paginated collection in OpenStack.
* *
* @see <a
* href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Paginated_Collections-d1e325.html">
* docs</a>
*/ */
public class PaginatedCollection<T> extends IterableWithMarker<T> { public class PaginatedCollection<T> extends IterableWithMarker<T> {
private final Iterable<T> resources; private final Iterable<T> resources;

View File

@ -21,15 +21,13 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.Date; import java.util.Date;
import com.google.common.collect.Multimap;
import org.jclouds.http.options.BaseHttpRequestOptions; import org.jclouds.http.options.BaseHttpRequestOptions;
import com.google.common.collect.Multimap;
/** /**
* Options used to control paginated results (aka list commands). * Options used to control paginated results (aka list commands).
* *
* @see <a href=
* "http://docs.openstack.org/api/openstack-compute/2/content/Paginated_Collections-d1e664.html"
* />
*/ */
public class PaginationOptions extends BaseHttpRequestOptions { public class PaginationOptions extends BaseHttpRequestOptions {
/** /**
@ -43,10 +41,15 @@ public class PaginationOptions extends BaseHttpRequestOptions {
} }
/** /**
* Only return objects changed since this time. * Only return objects changed since a specified time.
*
* @deprecated The {@code changes-since} query does not apply to all OpenStack APIs. Please refer to the OpenStack
* Nova {@code ListOptions.changesSince(Date)} and Glance {@code ListImageOptions.changesSince(Date)}.
* This option will be removed in 2.1.
*/ */
public PaginationOptions changesSince(Date ifModifiedSince) { @Deprecated
this.queryParameters.put("changes-since", checkNotNull(ifModifiedSince, "ifModifiedSince").getTime() / 1000 + ""); public PaginationOptions changesSince(Date changesSince) {
this.queryParameters.put("changes-since", checkNotNull(changesSince, "changesSince").getTime() / 1000 + "");
return this; return this;
} }
@ -83,6 +86,18 @@ public class PaginationOptions extends BaseHttpRequestOptions {
return options.queryParameters(queryParams); return options.queryParameters(queryParams);
} }
/**
* @see PaginationOptions#changesSince(Date)
* @deprecated The {@code changes-since} query does not apply to all OpenStack APIs. Please refer to the OpenStack
* Nova {@code ListOptions.changesSince(Date)} and Glance {@code ListImageOptions.changesSince(Date)}.
* This option will be removed in 2.1.
*/
@Deprecated
public static PaginationOptions changesSince(Date changesSince) {
PaginationOptions options = new PaginationOptions();
return options.changesSince(changesSince);
}
/** /**
* @see PaginationOptions#marker(String) * @see PaginationOptions#marker(String)
*/ */
@ -92,20 +107,11 @@ public class PaginationOptions extends BaseHttpRequestOptions {
} }
/** /**
* @see PaginationOptions#limit * @see PaginationOptions#limit(int)
*/ */
public static PaginationOptions limit(int limit) { public static PaginationOptions limit(int limit) {
PaginationOptions options = new PaginationOptions(); PaginationOptions options = new PaginationOptions();
return options.limit(limit); return options.limit(limit);
} }
/**
* @see PaginationOptions#changesSince(Date)
*/
public static PaginationOptions changesSince(Date since) {
PaginationOptions options = new PaginationOptions();
return options.changesSince(since);
}
} }
} }

View File

@ -16,13 +16,10 @@
*/ */
package org.jclouds.openstack.v2_0.options; package org.jclouds.openstack.v2_0.options;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.changesSince;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.limit; import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.limit;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.Date;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -33,13 +30,6 @@ import com.google.common.collect.ImmutableList;
@Test(groups = "unit", testName = "PaginationOptionsTest") @Test(groups = "unit", testName = "PaginationOptionsTest")
public class PaginationOptionsTest { public class PaginationOptionsTest {
public void testChangesSince() {
Date ifModifiedSince = new Date();
PaginationOptions options = new PaginationOptions().changesSince(ifModifiedSince);
assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""),
options.buildQueryParameters().get("changes-since"));
}
public void testMarker() { public void testMarker() {
String marker = "52415800-8b69-11e0-9b19-734f6f006e54"; String marker = "52415800-8b69-11e0-9b19-734f6f006e54";
PaginationOptions options = new PaginationOptions().marker(marker); PaginationOptions options = new PaginationOptions().marker(marker);
@ -52,13 +42,6 @@ public class PaginationOptionsTest {
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("limit")); assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("limit"));
} }
public void testChangesSinceStatic() {
Date ifModifiedSince = new Date();
PaginationOptions options = changesSince(ifModifiedSince);
assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""),
options.buildQueryParameters().get("changes-since"));
}
public void testMarkerStatic() { public void testMarkerStatic() {
String marker = "52415800-8b69-11e0-9b19-734f6f006e54"; String marker = "52415800-8b69-11e0-9b19-734f6f006e54";
PaginationOptions options = marker(marker); PaginationOptions options = marker(marker);

View File

@ -16,39 +16,29 @@
*/ */
package org.jclouds.openstack.nova.v2_0.options; package org.jclouds.openstack.nova.v2_0.options;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date; import java.util.Date;
import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.openstack.v2_0.options.PaginationOptions;
/** /**
* Options used to control the amount of detail in the request. * Options used to control the amount of detail in the request.
* *
* @see PaginationOptions * @see PaginationOptions
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
*/ */
public class ListOptions extends PaginationOptions { public class ListOptions extends PaginationOptions {
public static final ListOptions NONE = new ListOptions(); public static final ListOptions NONE = new ListOptions();
/** /**
* unless used, only the name and id will be returned per row. * Provides detailed results for list operations.
*
* @return
*/ */
public ListOptions withDetails() { public ListOptions withDetails() {
this.pathSuffix = "/detail"; this.pathSuffix = "/detail";
return this; return this;
} }
/**
* {@inheritDoc}
*/
@Override
public ListOptions changesSince(Date ifModifiedSince) {
super.changesSince(ifModifiedSince);
return this;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -56,7 +46,6 @@ public class ListOptions extends PaginationOptions {
public ListOptions limit(int limit) { public ListOptions limit(int limit) {
super.limit(limit); super.limit(limit);
return this; return this;
} }
/** /**
@ -68,6 +57,14 @@ public class ListOptions extends PaginationOptions {
return this; return this;
} }
/**
* Checks for any changes since the given date.
*/
public ListOptions changesSince(Date changesSince) {
this.queryParameters.put("changes-since", checkNotNull(changesSince, "changesSince").getTime() / 1000 + "");
return this;
}
public static class Builder { public static class Builder {
/** /**
@ -87,15 +84,25 @@ public class ListOptions extends PaginationOptions {
} }
/** /**
* @see PaginationOptions#limit(long) * @see PaginationOptions#limit(int)
*/ */
public static ListOptions maxResults(int maxKeys) { public static ListOptions limit(int limit) {
ListOptions options = new ListOptions(); ListOptions options = new ListOptions();
return options.limit(maxKeys); return options.limit(limit);
} }
/** /**
* @see PaginationOptions#changesSince(Date) *
* @see PaginationOptions#limit(int)
* @deprecated Please use {@link #limit(int)} as this builder method will be removed in 2.0.
*/
@Deprecated
public static ListOptions maxResults(int maxKeys) {
return limit(maxKeys);
}
/**
* @see ListOptions#changesSince(Date)
*/ */
public static ListOptions changesSince(Date since) { public static ListOptions changesSince(Date since) {
ListOptions options = new ListOptions(); ListOptions options = new ListOptions();

View File

@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.openstack.nova.v2_0.options;
import static org.jclouds.openstack.nova.v2_0.options.ListOptions.Builder.changesSince;
import static org.testng.Assert.assertEquals;
import java.util.Date;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
/**
* Tests behavior of {@code ListOptions}
*/
@Test(groups = "unit")
public class ListOptionsTest {
public void testChangesSince() {
Date ifModifiedSince = new Date();
ListOptions options = new ListOptions().changesSince(ifModifiedSince);
assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""),
options.buildQueryParameters().get("changes-since"));
}
public void testChangesSinceStatic() {
Date ifModifiedSince = new Date();
PaginationOptions options = changesSince(ifModifiedSince);
assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""),
options.buildQueryParameters().get("changes-since"));
}
}