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

Add Pageable to applicable controllers to prevent issue in PagedResourcesAssembler #1383

Closed
wants to merge 2 commits into from

Conversation

donovanmuller
Copy link
Contributor

@donovanmuller donovanmuller commented Apr 22, 2017

Fixes #1382

If Spring Boot were to be updated to 1.5.3, it would bring in spring-data-commons:1.13.3.RELEASE which includes a fix for DATACMNS-1042 (Self link created with pagination request parameters) in spring-projects/spring-data-commons@a8ff4ea. This commit breaks certain controllers using the PagedResourcesAssembler in spring-cloud-dataflow-server-core.

For example, the following exception will be thrown (using the local server for testing) when requesting http://localhost:9393/apps:

2017-04-22 22:24:45.941 ERROR 2253 --- [nio-9393-exec-8] o.s.c.d.s.c.RestControllerAdvice         : Caught exception while handling a request

java.lang.IllegalArgumentException: Page size must not be less than one!
	at org.springframework.data.domain.AbstractPageRequest.<init>(AbstractPageRequest.java:47) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
	at org.springframework.data.domain.PageRequest.<init>(PageRequest.java:63) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
	at org.springframework.data.web.PagedResourcesAssembler.addPaginationLinks(PagedResourcesAssembler.java:222) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
	at org.springframework.data.web.PagedResourcesAssembler.createResource(PagedResourcesAssembler.java:205) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
	at org.springframework.data.web.PagedResourcesAssembler.toResource(PagedResourcesAssembler.java:115) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
	at org.springframework.cloud.dataflow.server.controller.AppRegistryController.list(AppRegistryController.java:...) ~[classes/:na]
...

The reason this happens is because a new PageImpl, with default values of 0 for page and page size, is being shipped to the PagedResourcesAssembler. This (new) line in PagedResourcesAssembler creates a new PageRequest with the passed in Pageable and is where the size < 1 check blows up because size == 0.

So we need to add a Pageable param (with sane defaults provided by PageableHandlerMethodArgumentResolver) to the affected controller methods and use that when building the PageImpl.

Also changed the default page size to 2000 on the REST templates to match DEFAULT_MAX_PAGE_SIZE, since 10000 would be converted to 2000 anyway.

* The newer version of spring-data-commons unearthed a shortcoming in
the handling of PagedResourcesAssembler's.
Added Pageable support where necessary
* Adjusted the default page size to 2000
(the same as org.springframework.data.web.PageableHandlerMethodArgumentResolver#DEFAULT_MAX_PAGE_SIZE)
@donovanmuller
Copy link
Contributor Author

A before and after for StreamDefinitionController#listRelated

screen shot 2017-04-22 at 10 24 58 pm

screen shot 2017-04-22 at 10 38 13 pm

@donovanmuller donovanmuller changed the title Bumped Spring Boot to 1.5.3 Add Pageable to applicable controllers to prevent issue in PagedResourcesAssembler Apr 23, 2017
@ilayaperumalg
Copy link
Contributor

@donovanmuller I haven't been able to reproduce the issue with spring-data-commons:1.13.3.RELEASE. it definitely makes sense to have Pageable injected into PageImpl. Merging this change.

@@ -116,7 +117,8 @@ public AppRegistryController(AppRegistry appRegistry,
}
}
Collections.sort(list);
return pagedResourcesAssembler.toResource(new PageImpl<>(list), assembler);
return pagedResourcesAssembler
.toResource(new PageImpl<>(list, pageable, appRegistry.findAll().size()), assembler);
Copy link
Contributor

Choose a reason for hiding this comment

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

The appRegistry.findAll() can be reused from what we computed above in the same method.

Copy link
Contributor

Choose a reason for hiding this comment

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

will fix while merging.

@ilayaperumalg
Copy link
Contributor

@donovanmuller Thank you for the contribution. Merged the PR as 2184068 along with eae98f4

@sabbyanandan
Copy link
Contributor

Thanks, @donovanmuller and @ilayaperumalg. Unfortunately, this commit has a side effect on Flo's pagination (#1397). We may have to revert the commit and investigate the applicability of PR and it's side effects post 1.2.0.

trisberg added a commit to trisberg/spring-cloud-dataflow that referenced this pull request Apr 25, 2017
- revert commit 2184068

- revert commit eae98f4

These pagination changes will be made after 1.2.0 GA
trisberg added a commit to trisberg/spring-cloud-dataflow that referenced this pull request Apr 25, 2017
- revert commit 2184068

- revert commit eae98f4

These pagination changes will be made after 1.2.0 GA
@trisberg
Copy link
Member

Revert PR: #1400

Let's make these changes after 1.2.0.RELEASE

@trisberg trisberg reopened this Apr 25, 2017
@trisberg trisberg added the in pr label Apr 25, 2017
@ilayaperumalg
Copy link
Contributor

The root cause of this issue is that AppRegistry doesn't have findAll(Pageable) method in its implementation. Since AppRegistryController always returns PagedResources, the UI that expects the paginated resources from AppRegistryController goes into the loop.

As a follow up, I have created this story: #1401

@ilayaperumalg ilayaperumalg changed the title Add Pageable to applicable controllers to prevent issue in PagedResourcesAssembler [DO NOT MERGE YET] Add Pageable to applicable controllers to prevent issue in PagedResourcesAssembler Apr 27, 2017
@kalvarez2
Copy link

So, what version of spring-boot does work?

@kalvarez2
Copy link

so... I am trying to write an implementation of spring-cloud-deployer-spi at version 1.2.0.RELEASE. It is an spring-boot app, so my parent is spring-boot-starter-parent at version "1.4.6.RELEASE", also trried at version "1.5.2.RELEASE". The app boots just fine, but then I am getting this error when trying to use the UI... what version should I set on my pom for the parent or for -spi to get this error to go away?

@vijaykalidindi
Copy link

Same problem here. Is there any workaround while the fix is being worked on?

@SuperMohit
Copy link

Hi,
I am facing same issue. Is there work around? or which version should I use to make this work?

@sabbyanandan
Copy link
Contributor

Hi, @kalvarez2, @vijaykalidindi, @SuperMohit. The fix is underway via #1545. Once this is merged (hopefully today), we will update the relevant bits associated with this PR and release it in the upcoming 1.2.2.RELEASE.

Thanks for the patience.

@ilayaperumalg ilayaperumalg changed the title [DO NOT MERGE YET] Add Pageable to applicable controllers to prevent issue in PagedResourcesAssembler Add Pageable to applicable controllers to prevent issue in PagedResourcesAssembler Jun 27, 2017
@ilayaperumalg
Copy link
Contributor

This can be closed as #1545 is merged with the changes from this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update to Spring Boot 1.5.4
7 participants