-
Notifications
You must be signed in to change notification settings - Fork 58
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 Extension API interfaces and implement in sample Hello World extension #109
Add Extension API interfaces and implement in sample Hello World extension #109
Conversation
8a92b1d
to
8d4a8aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that #86 is no longer necessary with these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the test name change, LGTM! Thanks for adding to the design document, the ExtensionAction diagram definitely helped me gain a better understanding of the workflow. I also agree that this change makes #86 obsolete, should I go ahead and close this bug out now?
src/test/java/org/opensearch/sdk/sample/rest/TestRestHelloAction.java
Outdated
Show resolved
Hide resolved
@owaiskazi19 and @saratvemulapalli, after reviewing #80 and #105 I can already see a need for name changes in my implementation. What I have implemented in the
|
Thanks @dbwiddis. I love these changes. Its a great start of helping extension authors write simple extensions.
|
Changes look good to me. I'll do another pass once we merge #101 and opensearch-project/OpenSearch#4282 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helloworld API awesome!
Even if we add that, it includes HTTP headers, potentially including basic authentication (user/password). For security purposes these are not being sent to extensions, and it's difficult or impossible to remove or filter them from an existing object.
Could you create an issue for this to be followed up on? One way we could manage this more securely is to deep copy then remove/unset all headers from the request before its passed along to the extension.
Might be worthwhile to ask, besides the method, path, body - do extensions need any other functionality to support a given REST request?
@@ -18,6 +18,9 @@ | |||
import org.opensearch.common.io.stream.NamedWriteableRegistry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExtensionsRunner is getting big, could we compartmentalize this functionality? Maybe there is a pattern like configuration/registration/request handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good problem to have :)
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
741fecb
to
c251278
Compare
@peternied already created with #111 and comments on #37. The challenge with a "deep copy" is we still have to send it across Transport, so we're stuck "disassembling" the For now, passing the pieces seems easiest but we can always change it (up through version 0.9.99.999) as we iterate on new extensions and see what's needed.
I think as we migrate plugins to extensions this will answer itself. |
@saratvemulapalli @ryanbogan @joshpalis @owaiskazi19 Have rebased this PR on main after merge of #101 which invalidated earlier reviews. No changes, though, would like to get this merged today before I submit yet another PR building on this, addressing #112 |
…nsion (opensearch-project#109) * Forward REST requests from OpenSearch to Extension Signed-off-by: Daniel Widdis <widdis@gmail.com> * Update DESIGN Signed-off-by: Daniel Widdis <widdis@gmail.com> * Remove nodeId from Rest API request Signed-off-by: Daniel Widdis <widdis@gmail.com> * Create sample Hello World extension Signed-off-by: Daniel Widdis <widdis@gmail.com> * Typo fix Signed-off-by: Daniel Widdis <widdis@gmail.com> * Rename ExtensionAction to ExtensionRestHandler Signed-off-by: Daniel Widdis <widdis@gmail.com> Signed-off-by: Daniel Widdis <widdis@gmail.com>
Description
This PR creates new interfaces
Extension
andExtensionRestHandler
which developers will implement when writing new Extensions, and demonstrates their use in a sampleHelloWorldExtension
which responds as expected to its registered OpenSearch REST request:The
Extension
interface requires two methods to be implemented by developers.getExtensionSettings()
which theExtensionsRunner
needs to bind the host and port.getExtensionRestHandlers()
which obtains a list of objects implementing theExtensionRestHandler
interface, which will handle the REST requests registered with OpenSearch.The
ExtensionRestHandler
interface requires two methods to be implemented by developers.routes()
which corresponds directly to theroutes()
method required by theRestHandler
interface implemented by plugins.handleRequest()
which is analogous to the logic eventually called by theRestHandler
'shandleRequest()
method, implemented in plugins with theprepareRequest()
method.#102 discussed possibly implementing the
RestHandler
interface in extensions to speed migrating plugins, but presented the following challenges:prepareRequest()
ispublic RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client)
. This involves aChannel
andClient
to handle aRestRequest
:RestRequest
isn't yet configured to be deserialized to send over transportChannel
,Client
, andRestRequest
objects with appropriate information, but that introduces a lot of complexity and overhead (and duplication) when instead we can just send and return only the information that we really need to.The
ExtensionRestHandler
interface still corresponds very closely to the Plugin action implementation ofBaseRestHandler
.Presently the action method takes only the method and URI and returns a String, as the scope of this PR is to implement that functionality. This signature is envisioned to change over time as we add new features. For example:
RestRequest
object (excluding the HTML headers) may be relevant (not sure yet).In addition to the interface implementations and sample extension, this PR also:
ExtensionsRunner
to:run()
method to instantiate using the settings of an Extension.ExtensionRestPaths
class (and yml and test files) as it is replaced by theExtension
API implementation (and tests).extension.yml
file to the classpath at/sample/extension-settings.yml
as part of the sample extension implementation. This may make [BUG] Package extension.yml file #86 no longer needed.build.gradle
to execute themain()
method of the sample extension rather than runningExtensionsRunner
. I believe this is closer to the intent of the SDK.Issues Resolved
Closes #102.
Removes the need for #86.
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.