-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[Feature/extensions] Adding support for registering Transport Actions for extensions #4326
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
saratvemulapalli
merged 5 commits into
opensearch-project:feature/extensions
from
saratvemulapalli:get-actions-api
Sep 1, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e9a351f
Initial commit for registering Transport Actions for extensions
saratvemulapalli 2328fb6
Adding spotless changes
saratvemulapalli 88ebe83
Merge branch 'feature/extensions' into get-actions-api
saratvemulapalli 2f9c064
Addressing comments
saratvemulapalli 1970358
Fixing precommit
saratvemulapalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
server/src/main/java/org/opensearch/extensions/RegisterTransportActionsRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.extensions; | ||
|
|
||
| import org.opensearch.common.io.stream.StreamInput; | ||
| import org.opensearch.common.io.stream.StreamOutput; | ||
| import org.opensearch.transport.TransportRequest; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Request to register extension Transport actions | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class RegisterTransportActionsRequest extends TransportRequest { | ||
saratvemulapalli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private Map<String, Class> transportActions; | ||
saratvemulapalli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public RegisterTransportActionsRequest(Map<String, Class> transportActions) { | ||
| this.transportActions = new HashMap<>(transportActions); | ||
| } | ||
|
|
||
| public RegisterTransportActionsRequest(StreamInput in) throws IOException { | ||
| super(in); | ||
| Map<String, Class> actions = new HashMap<>(); | ||
| int actionCount = in.readVInt(); | ||
| for (int i = 0; i < actionCount; i++) { | ||
| try { | ||
| String actionName = in.readString(); | ||
| Class transportAction = Class.forName(in.readString()); | ||
| actions.put(actionName, transportAction); | ||
| } catch (ClassNotFoundException e) { | ||
| throw new IllegalArgumentException("Could not read transport action"); | ||
| } | ||
| } | ||
| this.transportActions = actions; | ||
| } | ||
|
|
||
| public Map<String, Class> getTransportActions() { | ||
| return transportActions; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeVInt(this.transportActions.size()); | ||
| for (Map.Entry<String, Class> action : transportActions.entrySet()) { | ||
| out.writeString(action.getKey()); | ||
| out.writeString(action.getValue().getName()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "TransportActionsRequest{actions=" + transportActions + "}"; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) return true; | ||
| if (obj == null || getClass() != obj.getClass()) return false; | ||
| RegisterTransportActionsRequest that = (RegisterTransportActionsRequest) obj; | ||
| return Objects.equals(transportActions, that.transportActions); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(transportActions); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
server/src/test/java/org/opensearch/extensions/RegisterTransportActionsRequestTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.extensions; | ||
|
|
||
| import org.junit.Before; | ||
| import org.opensearch.common.collect.Map; | ||
| import org.opensearch.common.io.stream.BytesStreamOutput; | ||
| import org.opensearch.common.io.stream.StreamInput; | ||
| import org.opensearch.test.OpenSearchTestCase; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class RegisterTransportActionsRequestTests extends OpenSearchTestCase { | ||
| private RegisterTransportActionsRequest originalRequest; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| this.originalRequest = new RegisterTransportActionsRequest(Map.of("testAction", Map.class)); | ||
| } | ||
|
|
||
| public void testRegisterTransportActionsRequest() throws IOException { | ||
| BytesStreamOutput output = new BytesStreamOutput(); | ||
| originalRequest.writeTo(output); | ||
| StreamInput input = output.bytes().streamInput(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Comment) I realize that |
||
| RegisterTransportActionsRequest parsedRequest = new RegisterTransportActionsRequest(input); | ||
| assertEquals(parsedRequest.getTransportActions(), originalRequest.getTransportActions()); | ||
| assertEquals(parsedRequest.getTransportActions().get("testAction"), originalRequest.getTransportActions().get("testAction")); | ||
| assertEquals(parsedRequest.getTransportActions().size(), originalRequest.getTransportActions().size()); | ||
| assertEquals(parsedRequest.hashCode(), originalRequest.hashCode()); | ||
| assertTrue(originalRequest.equals(parsedRequest)); | ||
| } | ||
|
|
||
| public void testToString() { | ||
| assertEquals(originalRequest.toString(), "TransportActionsRequest{actions={testAction=class org.opensearch.common.collect.Map}}"); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are we having separate action for extensions?
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.
There is an open issue: #4334. Lets do a sweep all together in a dedicated PR.