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

Pass REST params and content to extensions #163

Merged
merged 8 commits into from
Sep 30, 2022

Conversation

dbwiddis
Copy link
Member

@dbwiddis dbwiddis commented Sep 29, 2022

Companion PR on OpenSearch: #4633

  • Gradle checks will fail until companion PR is merged. They pass locally after publishToMavenLocal.
  • OpenSearch PR will break SDK build due to a class rename, merge these together.

Description

Passes the params() from the original RestRequest object to extensions. Internally tracks the consumed params (similar to the RestRequest class) when they are consumed with the param(key) method (similar to existing plugin usage).

During the process, realized that the RestExecuteOnExtensionRequest class (in OpenSearch) completely duplicated the ExtensionRestHandler class (here), so removed the SDK duplicate and renamed the "Execute" class as ExtensionRestHandler.

Additionally added xContentType and content as well as getters for the params that will enable AD extension functionality.

Remaining TODO to be handled as part of #132 is to instantiate the parser on the SDK side. All that's needed from the REST request is the xContentType.

Issues Resolved

Fixes #111

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.

@dbwiddis
Copy link
Member Author

Flipping this into draft to handle all the pieces @owaiskazi19 referenced in #58 (comment)

@dbwiddis dbwiddis marked this pull request as draft September 29, 2022 19:13
@dbwiddis dbwiddis changed the title Pass REST params to extensions Pass REST params and content to extensions Sep 30, 2022
@dbwiddis dbwiddis marked this pull request as ready for review September 30, 2022 04:00
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

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

Gradle check won't pass until opensearch-project/OpenSearch#4633 is merged.

@codecov-commenter
Copy link

Codecov Report

Merging #163 (ca71302) into main (0bdd6b4) will increase coverage by 1.13%.
The diff coverage is 96.00%.

@@             Coverage Diff              @@
##               main     #163      +/-   ##
============================================
+ Coverage     64.60%   65.73%   +1.13%     
+ Complexity       99       94       -5     
============================================
  Files            25       24       -1     
  Lines           500      464      -36     
  Branches         18       13       -5     
============================================
- Hits            323      305      -18     
+ Misses          169      151      -18     
  Partials          8        8              
Impacted Files Coverage Δ
...main/java/org/opensearch/sdk/ExtensionsRunner.java 67.44% <ø> (ø)
...rch/sdk/handlers/ExtensionsRestRequestHandler.java 42.85% <66.66%> (+9.52%) ⬆️
.../org/opensearch/sdk/ExtensionRestPathRegistry.java 100.00% <100.00%> (ø)
...java/org/opensearch/sdk/ExtensionRestResponse.java 100.00% <100.00%> (ø)
...ch/sdk/sample/helloworld/rest/RestHelloAction.java 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

}
return new ExtensionRestResponse(request, OK, "Updated the world's name to " + worldName);
}

Copy link
Member

Choose a reason for hiding this comment

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

Can we have a sample POST request too here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can I do that as part of #165?

Copy link
Member

Choose a reason for hiding this comment

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

Sure @dbwiddis! Not blocking this PR :)

@@ -9,6 +9,7 @@

import java.util.List;

import org.opensearch.extensions.rest.ExtensionRestRequest;
Copy link
Member

Choose a reason for hiding this comment

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

Thinking out loud. Why are we keeping ExtensionRestRequest in OpenSearch and not in SDK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the previous RestSendToExtensionRequest entirely duplicated it. Literally all the lines were the same except for a few naming differences.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also it makes sense (see #165) to move the ExtensionRestResponse there as well since it's really the same thing as the BytesRestResponse with some tweaks.

Copy link
Member

@owaiskazi19 owaiskazi19 Sep 30, 2022

Choose a reason for hiding this comment

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

This answers my questions. Just one thing to add can we keep the name as RestSendToExtensionRequest instead of ExtensionRestRequest for better understanding. Can be address in the next PR

Copy link
Member Author

Choose a reason for hiding this comment

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

Let’s discuss on #165, because both classes are part of the API we expect extension authors to use. The ExtensionRestRequest is the argument type for the handleRequest method and it closely parallels the same method on plugins and I’d really like similar names.

@owaiskazi19 owaiskazi19 merged commit 7218f6e into opensearch-project:main Sep 30, 2022
@dbwiddis dbwiddis deleted the params branch September 30, 2022 23:00
kokibas pushed a commit to kokibas/opensearch-sdk-java that referenced this pull request Mar 17, 2023
* Rename/merge duplicate ExtensionRestRequest implementations

Signed-off-by: Daniel Widdis <[email protected]>

* Track consumed params inside request object

Signed-off-by: Daniel Widdis <[email protected]>

* Put back test for the "this will never happen" case

Signed-off-by: Daniel Widdis <[email protected]>

* Add content and expand param getters

Signed-off-by: Daniel Widdis <[email protected]>

* Rebase to main and update after conficts

Signed-off-by: Daniel Widdis <[email protected]>

* More merge conflict cleanup

Signed-off-by: Daniel Widdis <[email protected]>

* Whitespace diff reduction

Signed-off-by: Daniel Widdis <[email protected]>

* Change uri to path in RestRequest handling

Signed-off-by: Daniel Widdis <[email protected]>

Signed-off-by: Daniel Widdis <[email protected]>
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.

[FEATURE] Pass REST params to extensions
5 participants