Skip to content
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

Pagination #84

Merged
merged 6 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void getGroupList(KafkaAdminClient ac, Promise prom, Pattern patte
.filter(i -> i != null)
.collect(Collectors.toList());

if (pageRequest.getSize() * (pageRequest.getPage() - 1) > list.size()) {
if (pageRequest.getSize() * (pageRequest.getPage() - 1) >= list.size()) {
MikeEdgar marked this conversation as resolved.
Show resolved Hide resolved
return Future.failedFuture(new InvalidRequestException("Requested pagination incorrect. Beginning of list greater than full list size (" + list.size() + ")"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static void getTopicList(KafkaAdminClient ac, Promise prom, Pattern patte
fullTopicDescriptions.sort(new CommonHandler.TopicComparator(orderByInput.getField()));
}

if ((pageRequest.getPage() - 1) * pageRequest.getSize() > fullTopicDescriptions.size()) {
if ((pageRequest.getPage() - 1) * pageRequest.getSize() >= fullTopicDescriptions.size()) {
return Future.failedFuture(new InvalidRequestException("Requested pagination incorrect. Beginning of list greater than full list size (" + fullTopicDescriptions.size() + ")"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ public void listTopics(RoutingContext routingContext) {
httpMetrics.getListTopicsCounter().increment();
httpMetrics.getRequestsCounter().increment();
String filter = routingContext.queryParams().get("filter");
String size = routingContext.queryParams().get("size") == null ? "10" : routingContext.queryParams().get("size");
String page = routingContext.queryParams().get("page") == null ? "1" : routingContext.queryParams().get("page");
Types.SortDirectionEnum sortReverse = Types.SortDirectionEnum.fromString(routingContext.queryParams().get("order"));
String sortKey = routingContext.queryParams().get("orderKey") == null ? "name" : routingContext.queryParams().get("orderKey");
Types.OrderByInput orderBy = new Types.OrderByInput();
Expand All @@ -235,16 +233,7 @@ public void listTopics(RoutingContext routingContext) {
prom.fail(ac.cause());
} else {
try {
int pageInt = Integer.parseInt(page);
int sizeInt = Integer.parseInt(size);
if (sizeInt < 1 || pageInt < 1) {
throw new InvalidRequestException("Size and page have to be positive integers.");
}
Types.PageRequest pageRequest = new Types.PageRequest();
pageRequest.setPage(pageInt);
pageRequest.setSize(sizeInt);

TopicOperations.getTopicList(ac.result(), prom, pattern, pageRequest, orderBy);
TopicOperations.getTopicList(ac.result(), prom, pattern, parsePageRequest(routingContext), orderBy);
} catch (NumberFormatException | InvalidRequestException e) {
prom.fail(e);
processResponse(prom, routingContext, HttpResponseStatus.BAD_REQUEST, httpMetrics, httpMetrics.getListTopicRequestTimer(), requestTimerSample);
Expand All @@ -263,8 +252,6 @@ public void listGroups(RoutingContext routingContext) {
httpMetrics.getRequestsCounter().increment();
String topicFilter = routingContext.queryParams().get("topic");
String consumerGroupIdFilter = routingContext.queryParams().get("group-id-filter") == null ? "" : routingContext.queryParams().get("group-id-filter");
String size = routingContext.queryParams().get("size") == null ? "10" : routingContext.queryParams().get("size");
String page = routingContext.queryParams().get("page") == null ? "1" : routingContext.queryParams().get("page");

Types.SortDirectionEnum sortReverse = Types.SortDirectionEnum.fromString(routingContext.queryParams().get("order"));
String sortKey = routingContext.queryParams().get("orderKey") == null ? "name" : routingContext.queryParams().get("orderKey");
Expand All @@ -285,15 +272,7 @@ public void listGroups(RoutingContext routingContext) {
prom.fail(ac.cause());
} else {
try {
int pageInt = Integer.parseInt(page);
int sizeInt = Integer.parseInt(size);
if (sizeInt < 1 || pageInt < 1) {
throw new InvalidRequestException("Size and page have to be positive integers.");
}
Types.PageRequest pageRequest = new Types.PageRequest();
pageRequest.setPage(pageInt);
pageRequest.setSize(sizeInt);
ConsumerGroupOperations.getGroupList(ac.result(), prom, pattern, pageRequest, consumerGroupIdFilter, orderBy);
ConsumerGroupOperations.getGroupList(ac.result(), prom, pattern, parsePageRequest(routingContext), consumerGroupIdFilter, orderBy);
} catch (NumberFormatException | InvalidRequestException e) {
prom.fail(e);
processResponse(prom, routingContext, HttpResponseStatus.BAD_REQUEST, httpMetrics, httpMetrics.getListGroupsRequestTimer(), requestTimerSample);
Expand Down Expand Up @@ -427,4 +406,20 @@ public void errorHandler(RoutingContext routingContext) {
prom.fail(routingContext.failure());
processResponse(prom, routingContext, HttpResponseStatus.OK, httpMetrics, httpMetrics.getOpenApiRequestTimer(), requestTimerSample);
}

private Types.PageRequest parsePageRequest(RoutingContext routingContext) {
String size = routingContext.queryParams().get("size") == null ? "10" : routingContext.queryParams().get("size");
String page = routingContext.queryParams().get("page") == null ? "1" : routingContext.queryParams().get("page");

int pageInt = Integer.parseInt(page);
int sizeInt = Integer.parseInt(size);
if (sizeInt < 1 || pageInt < 1) {
throw new InvalidRequestException("Size and page have to be positive integers.");
}
Types.PageRequest pageRequest = new Types.PageRequest();
pageRequest.setPage(pageInt);
pageRequest.setSize(sizeInt);

return pageRequest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,45 +123,6 @@ public int compareTo(Topic topic) {
}
}

public static class TopicList {
private List<Topic> items;
private Integer page;
private Integer size;
private Integer total;

public List<Topic> getItems() {
return items;
}

public void setItems(List<Topic> items) {
this.items = items;
}

public Integer getPage() {
return page;
}

public void setPage(Integer page) {
this.page = page;
}

public Integer getSize() {
return size;
}

public void setSize(Integer size) {
this.size = size;
}

public Integer getTotal() {
return total;
}

public void setTotal(Integer total) {
this.total = total;
}
}

public static class NewTopicConfigEntry {
private String key;
private String value;
Expand Down Expand Up @@ -346,16 +307,16 @@ public void setState(String state) {
}
}

public static class ConsumerGroupList {
private List<ConsumerGroupDescription> items;
public static class PagedResponse<T> {
private List<T> items;
private Integer size;
private Integer page;
private Integer total;

public List<ConsumerGroupDescription> getItems() {
public List<T> getItems() {
return items;
}
public void setItems(List<ConsumerGroupDescription> items) {
public void setItems(List<T> items) {
this.items = items;
}

Expand Down Expand Up @@ -384,6 +345,12 @@ public void setTotal(Integer total) {
}
}

public static class ConsumerGroupList extends PagedResponse<ConsumerGroupDescription> {
}

public static class TopicList extends PagedResponse<Topic> {
}

public static class Consumer {
private String memberId;
private String groupId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ paths:
summary: API endpoints for consumer groups under a Kafka topic
get:
parameters:
- name: sizr
description: Maximum number of consumer groups to returned on single page
- name: size
description: Maximum number of consumer groups to return on single page
schema:
type: integer
in: query
Expand Down