-
Notifications
You must be signed in to change notification settings - Fork 60
[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
[Feature/extensions] Adding extensibility support for extension point getNamedWriteables. #54
Conversation
Signed-off-by: Joshua Palis <jpalis@amazon.com>
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.
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 {} |
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.
(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() { |
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.
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) { |
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.
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
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.
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 |
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.
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 { |
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.
Do we need a lot of nested try
's?
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 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 |
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.
Let's follow the javadoc style here for the comments
// extensions will add named writeable registry entries here | |
// Extensions will add named writeable registry entries here |
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.
Also, is this part incomplete as we are creating an empty ArrayList and returning? Am I missing something here?
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'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(); |
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.
For my education what's type C
?
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.
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); |
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.
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. |
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.
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); |
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.
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 |
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.
// 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 |
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.
// 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 |
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.
// 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 |
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.
// convert input stream to stream input | |
// Convert input stream to stream input |
) | ||
) { | ||
|
||
// apply reader to stream input generated from the request context |
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.
// 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>
private NamedWriteableRegistryApi namedWriteableRegistryApi = new NamedWriteableRegistryApi(); | ||
|
||
/** | ||
* Constructor for ExtensionsRunner |
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.
Any reason for the changing the javadocs here?
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.
Javadocs for the extension runner constructor was missing and it was failing the strict javadoc check
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.
return namedWriteableRegistryApi.handleNamedWriteableRegistryRequest(request); | ||
// Add additional request handlers here | ||
default: | ||
return null; |
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.
Instead of null let's return an exception here?
(request, channel, task) -> channel.sendResponse(handleOpenSearchRequest(request)) | ||
); | ||
|
||
transportService.registerRequestHandler( |
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.
This is another overriden method you are using here. It's missing forceExecution
and canTripCircuitBreaker
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.
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 { |
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.
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) { |
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.
Need test for this function is TestExtensionRunner
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.
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); |
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.
Better name here?
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.
Sure Ill make this change
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.
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( |
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.
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.
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.
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); |
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.
what do we do with this return value?
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.
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>
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.
Thanks a lot for this @joshpalis.
I did one pass, most of the changes look good to me.
Signed-off-by: Joshua Palis <jpalis@amazon.com>
95f0f53
Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
… 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>
… 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>
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.