Skip to content

[Feature/extensions] Adding extensibility support for extension point getNamedWriteables. #54

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

Merged
merged 23 commits into from
Aug 8, 2022

Conversation

joshpalis
Copy link
Member

Signed-off-by: Joshua Palis jpalis@amazon.com

Description

Adds support for registering named writeable entries from extensions and transporting parse requests to extensions to deserialize named writeables that they have registered.

Issues Resolved

opensearch-project/OpenSearch#3495

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.

Signed-off-by: Joshua Palis <jpalis@amazon.com>
@owaiskazi19 owaiskazi19 changed the title adding extensibility support for extension point getNamedWriteables. [Feature/extensions] Adding extensibility support for extension point getNamedWriteables. Jul 15, 2022
Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Looks good as a placeholder for now. Needs some javadocs tho!

@@ -58,6 +71,8 @@
public class ExtensionsRunner {
private ExtensionSettings extensionSettings = readExtensionSettings();
private DiscoveryNode opensearchNode;
private List<NamedWriteableRegistry.Entry> namedWriteables = getNamedWriteables();
final private NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);

public ExtensionsRunner() throws IOException {}
Copy link
Member

Choose a reason for hiding this comment

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

(Style) All of the instance fields should be declared above the constructor. I know this is not part of your PR but you can fix it.

@@ -77,6 +92,14 @@ private ExtensionSettings readExtensionSettings() throws IOException {
return extensionSettings;
}

// current placeholder for extension point override getNamedWriteables()
private List<NamedWriteableRegistry.Entry> getNamedWriteables() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you put the PR number here as a comment so we know where to look for what's intended to replace this? I'm not clear what's being overridden here.

@@ -93,6 +116,66 @@ PluginResponse handlePluginsRequest(PluginRequest pluginRequest) {
return pluginResponse;
}

NamedWriteableRegistryResponse handleNamedWriteableRegistryRequest(NamedWriteableRegistryRequest request) {
Copy link
Member

Choose a reason for hiding this comment

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

Its nice to see how we are adding more extension points support for the SDK.
This is expanding ExtensionsRunner.

Instead could you write a new class (may be NamedWriteableRegistryApi) which is constructed during the bootstrap of extension, populate namedWritables and write up functions which handle the request, parseRequest etc

Copy link
Member Author

Choose a reason for hiding this comment

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

Great suggestion, I'll definitely add this change in my next commit

try {
C c = streamInput.readNamedWriteable(categoryClass);

// TODO : current parse response to OpenSearch includes only the status of the parse request. Further research
Copy link
Member

Choose a reason for hiding this comment

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

Lets open up follow up issues for everything we haven't taken care of.

boolean status = false;

// extract data from request and procress fully qualified category class name into class instance
try {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a lot of nested try's?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went ahead and removed the nested try's from the response handlers. As per Dan's suggestions, I will now handle Class object creation within the request/response constructors

…ltExtensionPointRequest. Modifed NamedWriteableRegistryResponse handler to pass in category class instead of fully qualified class name, since transport response/request files will now handle manipulation of the data

Signed-off-by: Joshua Palis <jpalis@amazon.com>
private List<NamedWriteableRegistry.Entry> getNamedWriteables() {

List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();
// extensions will add named writeable registry entries here
Copy link
Member

Choose a reason for hiding this comment

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

Let's follow the javadoc style here for the comments

Suggested change
// extensions will add named writeable registry entries here
// Extensions will add named writeable registry entries here

Copy link
Member

Choose a reason for hiding this comment

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

Also, is this part incomplete as we are creating an empty ArrayList and returning? Am I missing something 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.

I'll convert this to an api that the Extension can use to pass in their named writeable entries, as per Sarat's comment

boolean status = false;

// extract data from request and procress fully qualified category class name into class instance
Class<C> categoryClass = (Class<C>) request.getCategoryClass();
Copy link
Member

Choose a reason for hiding this comment

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

For my education what's type C?

Copy link
Member Author

Choose a reason for hiding this comment

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

Type C denotes the class of the writeable object. There are many various classes that implement the writeable class, however they are all expected to extend the NamedWriteable class. By casting the category class sent over from OpenSearch with this type, we can ensure that the category class entries extend NamedWriteables

// reader from provided registry
// reader is then applied to the StreamInput object generated from the byte array (context)
try {
C c = streamInput.readNamedWriteable(categoryClass);
Copy link
Member

@owaiskazi19 owaiskazi19 Jul 19, 2022

Choose a reason for hiding this comment

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

Right naming here?


// TODO : current parse response to OpenSearch includes only the status of the parse request. Further research
// needed to determine the workflow for extensions to utilize parsed objects after deserialization but this will be
// within the scope of dynamic registration.
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 link this TODO with an issue?

Signed-off-by: Joshua Palis <jpalis@amazon.com>

// apply reader to stream input generated from the request context
try {
C c = streamInput.readNamedWriteable(categoryClass);
Copy link
Member

Choose a reason for hiding this comment

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

Right naming here as well?

*/
public NamedWriteableRegistryResponse handleNamedWriteableRegistryRequest(OpenSearchRequest request) {
logger.info("Registering Named Writeable Registry Request recieved from OpenSearch.");
// iterate through Extensions's named writeables and add to extension entries
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// iterate through Extensions's named writeables and add to extension entries
// Iterate through Extensions's named writeables and add to extension entries

Class<C> categoryClass = (Class<C>) request.getCategoryClass();
byte[] context = request.getContext();

// transform byte array context into an input stream
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// transform byte array context into an input stream
// Transform byte array context into an input stream

logger.info("Registering Named Writeable Registry Parse request from OpenSearch");
boolean status = false;

// extract data from request and procress fully qualified category class name into class instance
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// extract data from request and procress fully qualified category class name into class instance
// Extract data from request and procress fully qualified category class name into class instance

// transform byte array context into an input stream
try (InputStream inputStream = new ByteArrayInputStream(context, 0, context.length)) {

// convert input stream to stream input
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// convert input stream to stream input
// Convert input stream to stream input

)
) {

// apply reader to stream input generated from the request context
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// apply reader to stream input generated from the request context
// Apply reader to stream input generated from the request context

Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
…o Api to return the NamedWriteableRegistry for testing purposes

Signed-off-by: Joshua Palis <jpalis@amazon.com>
@joshpalis joshpalis marked this pull request as ready for review July 21, 2022 21:22
@joshpalis joshpalis requested a review from a team July 21, 2022 21:22
private NamedWriteableRegistryApi namedWriteableRegistryApi = new NamedWriteableRegistryApi();

/**
* Constructor for ExtensionsRunner
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for the changing the javadocs 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.

Javadocs for the extension runner constructor was missing and it was failing the strict javadoc check

Copy link
Member

Choose a reason for hiding this comment

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

return namedWriteableRegistryApi.handleNamedWriteableRegistryRequest(request);
// Add additional request handlers here
default:
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of null let's return an exception here?

(request, channel, task) -> channel.sendResponse(handleOpenSearchRequest(request))
);

transportService.registerRequestHandler(
Copy link
Member

Choose a reason for hiding this comment

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

This is another overriden method you are using here. It's missing forceExecution and canTripCircuitBreaker

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catch, I'll make that change and update the corresponding test

/**
* Api used to handle named writeable registry requests from OpenSearch
*/
public class NamedWriteableRegistryApi {
Copy link
Member

Choose a reason for hiding this comment

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

NamedWriteableRegistryAPI, better name?

Signed-off-by: Joshua Palis <jpalis@amazon.com>
* @param request The request to handle.
* @return A response to OpenSearch for the corresponding API
*/
TransportResponse handleOpenSearchRequest(OpenSearchRequest request) {
Copy link
Member

Choose a reason for hiding this comment

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

Need test for this function is TestExtensionRunner

Copy link
Member Author

Choose a reason for hiding this comment

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

just added the test

Signed-off-by: Joshua Palis <jpalis@amazon.com>
…ption if the request handler is not present

Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
…ModuleNameResponse with ExtensionBooleanResponse

Signed-off-by: Joshua Palis <jpalis@amazon.com>
…to the Parse request

Signed-off-by: Joshua Palis <jpalis@amazon.com>
…ted logger to use this class instead

Signed-off-by: Joshua Palis <jpalis@amazon.com>

// Apply reader to stream input generated from the request context
try {
C c = streamInput.readNamedWriteable(categoryClass);
Copy link
Member

Choose a reason for hiding this comment

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

Better name 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.

Sure Ill make this change

owaiskazi19
owaiskazi19 previously approved these changes Jul 29, 2022
Copy link
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

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

One last comment and rest LGTM! Thanks for incorporating all the changes!

Signed-off-by: Joshua Palis <jpalis@amazon.com>
* @throws IOException if InputStream generated from the byte array is unsuccessfully closed
* @return A response acknowledging the request to parse has executed successfully
*/
public <C extends NamedWriteable> ExtensionBooleanResponse handleNamedWriteableRegistryParseRequest(
Copy link
Member

Choose a reason for hiding this comment

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

Something's not right with this generic. I'm used to seeing them in the method signature (e.g., as the type of request). But in this case you've more narrowly scoped the argument, meaning there's no real reason to use C later on. You already know the NamedWritable interface applies and you could cast it directly elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good callout, since we already verify that the NamedWriteable interface already applies prior to sending the parse request across the wire, I'll remove the the generic scope


// Apply reader to stream input generated from the request context
try {
C namedWriteable = streamInput.readNamedWriteable(categoryClass);
Copy link
Member

Choose a reason for hiding this comment

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

what do we do with this return value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, the scope of this PR consists of enabling extensions to register named writeables and handle deserialization requests from OpenSearch. Here we assume that any named writeable that an extension creates will be used only by the extension, thus maintaining the separation of concerns between OpenSearch and the extension. The question of how the named writeable object is used within the extension after it is created still requires additional research and is in the wider scope of dynamic registration. I will create another issue and link this here at this point, but as for now, if deserialization is successful, we notify OpenSearch about the status of the parse request with a boolean response.

Signed-off-by: Joshua Palis <jpalis@amazon.com>
Copy link
Member

@saratvemulapalli saratvemulapalli left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this @joshpalis.
I did one pass, most of the changes look good to me.

@joshpalis joshpalis requested a review from ryanbogan August 4, 2022 20:45
ryanbogan
ryanbogan previously approved these changes Aug 8, 2022
Signed-off-by: Joshua Palis <jpalis@amazon.com>
@joshpalis joshpalis dismissed stale reviews from ryanbogan and saratvemulapalli via 95f0f53 August 8, 2022 20:48
Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
@saratvemulapalli saratvemulapalli merged commit 06cb467 into opensearch-project:main Aug 8, 2022
@joshpalis joshpalis deleted the namedwriteables branch August 8, 2022 21:16
kokibas pushed a commit to kokibas/opensearch-sdk-java that referenced this pull request Mar 17, 2023
… getNamedWriteables. (opensearch-project#54)

* adding extensibility support for extension point getNamedWriteables.

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* removed NamedWriteableRegistryRequest and replaced with generic DefaultExtensionPointRequest. Modifed NamedWriteableRegistryResponse handler to pass in category class instead of fully qualified class name, since transport response/request files will now handle  manipulation of the data

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments, fixing code comment format

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* fixing javadocs issues, updating extensionrunner tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Added unit tests for NamedWriteableRegistryApi, added getter method to Api to return the NamedWriteableRegistry for testing purposes

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Added test for handling opensearch requests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Addressing PR comments : changed invalid parse request test name

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* modified default action for handleOpenSearch request to throw an exception if the request handler is not present

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Addedtest for invalid category class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* reverting ExtensionsRunner constructor javadocs

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* updated BooleanResponse to ExtensionBooleanResponse, replaced IndicesModuleNameResponse with ExtensionBooleanResponse

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Updated unit tests to pass in a StreamInput rather than a byte array to the Parse request

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* NamedWriteableRegistry API was using the ExtensionRunner logger, updated logger to use this class instead

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* updated name of parsed object

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments, linking addtional issues to TODO

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Fixing import conflict

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* removing netty4/shared group factory imports

Signed-off-by: Joshua Palis <jpalis@amazon.com>
caokyhieu pushed a commit to caokyhieu/opensearch-sdk-java that referenced this pull request Aug 15, 2025
… getNamedWriteables. (opensearch-project#54)

* adding extensibility support for extension point getNamedWriteables.

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* removed NamedWriteableRegistryRequest and replaced with generic DefaultExtensionPointRequest. Modifed NamedWriteableRegistryResponse handler to pass in category class instead of fully qualified class name, since transport response/request files will now handle  manipulation of the data

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments, fixing code comment format

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* fixing javadocs issues, updating extensionrunner tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Added unit tests for NamedWriteableRegistryApi, added getter method to Api to return the NamedWriteableRegistry for testing purposes

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Added test for handling opensearch requests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Addressing PR comments : changed invalid parse request test name

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* modified default action for handleOpenSearch request to throw an exception if the request handler is not present

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Addedtest for invalid category class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* reverting ExtensionsRunner constructor javadocs

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* updated BooleanResponse to ExtensionBooleanResponse, replaced IndicesModuleNameResponse with ExtensionBooleanResponse

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Updated unit tests to pass in a StreamInput rather than a byte array to the Parse request

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* NamedWriteableRegistry API was using the ExtensionRunner logger, updated logger to use this class instead

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* updated name of parsed object

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* addressing PR comments, linking addtional issues to TODO

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Fixing import conflict

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* removing netty4/shared group factory imports

Signed-off-by: Joshua Palis <jpalis@amazon.com>
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.

5 participants