Skip to content

Adding pagination utility #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 18, 2019
Merged

Adding pagination utility #527

merged 6 commits into from
Mar 18, 2019

Conversation

karthikkondapally
Copy link
Contributor

pagination tool #523
@brendandburns @yue9944882

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 13, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 13, 2019
private Integer limit;
private String _continue;

public PagerParams() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add/expand the tests so that they actually cover the pagination.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. add let's add test when the list receives a 400 due to invalid limit or continue, maybe expecting a checked exception here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added 2 more tests for failure cases.

/**
* Pagination in kubernetes list call depends on continue and limit variable
*
* @param listFunc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either document the parameters, or delete these. (and below)

@@ -0,0 +1,107 @@
package io.kubernetes.client.pager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add copyright boilerplate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

@@ -0,0 +1,30 @@
package io.kubernetes.client.util;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add boilerplate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -0,0 +1,30 @@
package io.kubernetes.client.util;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that this is in a different package than Pager. move to pager? or util.pager

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to pager package.


public class PagerParams {

private Integer limit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I prefer int to Integer but I don't feel strongly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public class PagerParams {

private Integer limit;
private String _continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove underscore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't continue a reserved key word?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, but perhaps continueToken? underscore is pretty unusual in Java variable names...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to continueToken.

return _continue;
}

public void setContinue(String _continue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove underscore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continueToken as above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to continueToken.

@brendandburns
Copy link
Contributor

This is great! Some small-ish comments.

public class PagerParams {

private Integer limit;
private String _continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't continue a reserved key word?

import java.lang.reflect.Type;
import java.util.function.Function;

public class Pager {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't want to make the pager shared by multiple resource types, better make it type parameterized.

Suggested change
public class Pager {
public class Pager<ApiType, ApiListType> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

*
* @return Object
*/
public <T> T next() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/<ApiType>/<T>/g

client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
}

@Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. add let's add test when the list receives a 400 due to invalid limit or continue, maybe expecting a checked exception here?

public static void main(String[] args) throws IOException {

ApiClient client = Config.defaultClient();
client.getHttpClient().setReadTimeout(60, TimeUnit.SECONDS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(might be an unrelated question) what's the point of this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just prevents timeouts for large bodies/slow connections. I think the default is 10 seconds?

It could be that this is cargo-cult copied from other examples :)


public class PagerParams {

private Integer limit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return limit;
}

public void setLimit(Integer limit) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about making the limit an immutable value here? (which is, settable by constructor but didn't have setter/getter). otherwise, what's the use-case of changing page size dynamically?

@brendandburns
Copy link
Contributor

This is good enough for now, I'd still like to see a little more coverage in the unit tests, but we can defer to an additional PR.

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, kondapally1989

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Mar 18, 2019
@brendandburns
Copy link
Contributor

@yue9944882 @adohe @kondapally1989

Let's move this into the extended module (separate PR after this merges is fine)

@k8s-ci-robot k8s-ci-robot merged commit d600430 into kubernetes-client:master Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants