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

Avoid override of routes() in BaseRestHandler to respect the default behavior defined in RestHandler #889

Merged

Conversation

cliu123
Copy link
Member

@cliu123 cliu123 commented Jun 26, 2021

Description

Remove override for routes() in BaseRestHandler to respect default behavior of routes() defined in RestHandler.
This will help developers avoid re-implementing routes() in the subclasses of BaseRestHandler
They can always override the method if they'd like.

Issues Resolved

#694

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@cliu123 cliu123 marked this pull request as draft June 26, 2021 00:40
@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success f719e69883e71682fa7d1150c1f5c98c1299d11f

@opensearch-ci-bot
Copy link
Collaborator

❌   DCO Check Failed f719e69883e71682fa7d1150c1f5c98c1299d11f
Run ./dev-tools/signoff-check.sh remotes/origin/main f719e69883e71682fa7d1150c1f5c98c1299d11f to check locally
Use git commit with -s to add 'Signed-of-by: {EMAIL}' on impacted commits

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Precommit success f719e69883e71682fa7d1150c1f5c98c1299d11f

@CEHENKLE
Copy link
Member

@cliu123 Can you add more information to this PR? Thanks...

@cliu123
Copy link
Member Author

cliu123 commented Jun 29, 2021

@cliu123 Can you add more information to this PR? Thanks...

Sure. This can be post-GA. I'll add more info later.

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success f719e69883e71682fa7d1150c1f5c98c1299d11f

@opensearch-ci-bot
Copy link
Collaborator

❌   DCO Check Failed f719e69883e71682fa7d1150c1f5c98c1299d11f
Run ./dev-tools/signoff-check.sh remotes/origin/main f719e69883e71682fa7d1150c1f5c98c1299d11f to check locally
Use git commit with -s to add 'Signed-of-by: {EMAIL}' on impacted commits

@nknize nknize added v2.0.0 Version 2.0.0 WIP Work in progress enhancement Enhancement or improvement to existing feature or request labels Jul 2, 2021
@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Precommit success f719e69883e71682fa7d1150c1f5c98c1299d11f

@cliu123 cliu123 force-pushed the Return_routes_in_BaseRestHandler branch from f719e69 to 9af8727 Compare July 4, 2021 01:22
@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success 9af872758921add7c07210112a6a89d114daf623

@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 9af872758921add7c07210112a6a89d114daf623

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Precommit success 9af872758921add7c07210112a6a89d114daf623

@cliu123 cliu123 marked this pull request as ready for review July 6, 2021 17:12
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Assuming routes becomes private, how does one add a route?

How will existing implementers of BaseRestHandler need to be changed? I imagine many define routes in their own implementations?

Copy link
Collaborator

@Bukhtawar Bukhtawar left a comment

Choose a reason for hiding this comment

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

Can we add more details on what this PR intends to solve

@cliu123
Copy link
Member Author

cliu123 commented Jul 6, 2021

Can we add more details on what this PR intends to solve

@Bukhtawar The issue #694 describes what this PR intends to solve.

@cliu123
Copy link
Member Author

cliu123 commented Jul 6, 2021

How will existing implementers of BaseRestHandler need to be changed?

They can remove the implementation of the abstract method routes if they do not need that method.

I imagine many define routes in their own implementations?

That is what happens, for example.
@dblock If defining routes field as protected in BaseRestHandler, from what I understand, the implementers would be allowed to add routes. Any thoughts? The intention is not to force implementers to implement the abstract method routes when they do not need the method.

@Bukhtawar
Copy link
Collaborator

From what I understand, we need to also ensure one of routes() or replacedRoutes() are implemented so that an implementer cannot get away without specifying any?

@cliu123
Copy link
Member Author

cliu123 commented Jul 6, 2021

From what I understand, we need to also ensure one of routes() or replacedRoutes() are implemented so that an implementer cannot get away without specifying any?

@Bukhtawar Agree. The intention of this PR is not to force implementers to implement the abstract method routes when they do not need the method. Perhaps routes was designed as an abstract method on purpose to ensure the implementers specify it?

@vrozov
Copy link
Contributor

vrozov commented Jul 6, 2021

Why is it necessary to overwrite the default RestHandler implementation in the BaseRestHandler? Implementing it as abstract does not enforce anything. Yes, it needs to be implemented by all subclasses of BaseRestHandler, but there is no enforcement on the actual return and it can be null or an empty list. The proposed implementation is subject of NullPointerException and subclasses of RestHandler will still need to initialize routes to a list.

@cliu123
Copy link
Member Author

cliu123 commented Jul 6, 2021

Why is it necessary to overwrite the default RestHandler implementation in the BaseRestHandler? Implementing it as abstract does not enforce anything. Yes, it needs to be implemented by all subclasses of BaseRestHandler, but there is no enforcement on the actual return and it can be null or an empty list. The proposed implementation is subject of NullPointerException and subclasses of RestHandler will still need to initialize routes to a list.

@vrozov

Why is it necessary to overwrite the default RestHandler implementation in the BaseRestHandler?

IMO, It is actually unnecessary.

Implementing it as abstract does not enforce anything.

Is our goal that the subclasses of BaseRestHandlerdo not have to implement the method routes unless the subclasses really need to implement a custom behavior? If not, the issue #694 will need more details to clarify the goal.

there is no enforcement on the actual return and it can be null or an empty list.

For this purpose, removing the routes() method from the BaseRestHandler will make that happen?

@Bukhtawar
Copy link
Collaborator

Is there a harm returning an empty list and let the contract stay

@cliu123
Copy link
Member Author

cliu123 commented Jul 6, 2021

Is there a harm returning an empty list and let the contract stay

I do not think there is a harm returning an empty list, but looks like BaseRestHandler does not have to override the method routes(), and the abstract class routes() in BaseRestHandler makes subclasses of BaseRestHandler have to implement the method routes() even if the subclasses respects the default behavior defined in RestHandler.

@vrozov
Copy link
Contributor

vrozov commented Jul 6, 2021

Is our goal that the subclasses of BaseRestHandlerdo not have to implement the method routes unless the subclasses really need the method? If not, the issue #694 will need more details to clarify the goal.

@cliu123 The reason RestHandler provides the default implementation of routes() (and other related methods) is to avoid unnecessary reimplementation of the method in the subclasses. By introducing abstract routes() method or introducing protected List<Route> routes to BaseRestHandler, the goal of the default interface implementation is defeated.

@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed dc0b1dd

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Precommit failure dc0b1dd
Log 787

Signed-off-by: cliu123 <lc12251109@gmail.com>
@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 15bf7ae

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success 15bf7ae

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Precommit success 15bf7ae

@vrozov
Copy link
Contributor

vrozov commented Jul 13, 2021

LGTM except for PR title

@cliu123 cliu123 changed the title Return routes in BaseRestHandler Avoid override of routes() in BaseRestHandler to respect the default behavior defined in RestHandler Jul 13, 2021
@cliu123
Copy link
Member Author

cliu123 commented Jul 13, 2021

LGTM except for PR title

@vrozov Changed the PR title

@cliu123 cliu123 requested a review from vrozov July 13, 2021 16:44
@cliu123
Copy link
Member Author

cliu123 commented Jul 13, 2021

@dblock @Bukhtawar How do the changes look to you?

@dblock
Copy link
Member

dblock commented Jul 13, 2021

@dblock @Bukhtawar How do the changes look to you?

Now that the unnecessary implementations have been removed in tests, this makes a lot more sense! Good with me.

You should still update the description in the PR for anyone reading this for the first time.

@dblock
Copy link
Member

dblock commented Jul 13, 2021

start gradle check

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success 15bf7ae
Log 330

Reports 330

@cliu123
Copy link
Member Author

cliu123 commented Jul 14, 2021

You should still update the description in the PR for anyone reading this for the first time.

@dblock Done.

@saratvemulapalli
Copy link
Member

Looks like I missed the whole party of conversation.
I like where we ended up!

@saratvemulapalli saratvemulapalli removed the WIP Work in progress label Jul 14, 2021
@saratvemulapalli
Copy link
Member

@dblock are we waiting for anything else to merge this ?

@dblock dblock merged commit 7241127 into opensearch-project:main Jul 14, 2021
@dblock
Copy link
Member

dblock commented Jul 14, 2021

Merged, thanks @cliu123!

@cliu123
Copy link
Member Author

cliu123 commented Jul 16, 2021

@dblock @saratvemulapalli Are we going to backport this to 1.0 or 1.x(for 1.1.0) branches?

@dblock
Copy link
Member

dblock commented Jul 16, 2021

Since this is not a security fix it definitely doesn't go to 1.0, but I don't see why we wouldn't backport to 1.1. Feel free to make that PR @cliu123 if you need it.

@cliu123 cliu123 deleted the Return_routes_in_BaseRestHandler branch July 21, 2021 05:37
cliu123 added a commit to cliu123/OpenSearch that referenced this pull request Jul 21, 2021
…behavior defined in RestHandler (opensearch-project#889)

Signed-off-by: cliu123 <lc12251109@gmail.com>
dblock pushed a commit that referenced this pull request Jul 22, 2021
…behavior defined in RestHandler (#889) (#991)

Signed-off-by: cliu123 <lc12251109@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement or improvement to existing feature or request v2.0.0 Version 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants