-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extension Points, initial REST implementation and registering T…
…ransport Actions for extensions (#5518) * Merge second batch of feature/extensions into main Signed-off-by: Ryan Bogan <rbogan@amazon.com> * Update CHANGELOG Signed-off-by: Ryan Bogan <rbogan@amazon.com> * Change logger level from info to bug for one call Signed-off-by: Ryan Bogan <rbogan@amazon.com> * Removed extension NamedWriteableRegistry implementation and added TODO comments Signed-off-by: Ryan Bogan <rbogan@amazon.com> * Rename ExtensionBooleanResponse to AcknowledgedResponse Signed-off-by: Ryan Bogan <rbogan@amazon.com> Signed-off-by: Ryan Bogan <rbogan@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
- Loading branch information
Showing
23 changed files
with
1,599 additions
and
238 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
68 changes: 68 additions & 0 deletions
68
server/src/main/java/org/opensearch/extensions/AcknowledgedResponse.java
This file contains 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,68 @@ | ||
/* | ||
* 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.TransportResponse; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Generic boolean response indicating the status of some previous request sent to the SDK | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class AcknowledgedResponse extends TransportResponse { | ||
|
||
private final boolean status; | ||
|
||
/** | ||
* @param status Boolean indicating the status of the parse request sent to the SDK | ||
*/ | ||
public AcknowledgedResponse(boolean status) { | ||
this.status = status; | ||
} | ||
|
||
public AcknowledgedResponse(StreamInput in) throws IOException { | ||
super(in); | ||
this.status = in.readBoolean(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeBoolean(status); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AcknowledgedResponse{" + "status=" + this.status + "}"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
AcknowledgedResponse that = (AcknowledgedResponse) o; | ||
return Objects.equals(this.status, that.status); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(status); | ||
} | ||
|
||
/** | ||
* Returns a boolean indicating the success of the request sent to the SDK | ||
*/ | ||
public boolean getStatus() { | ||
return this.status; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
server/src/main/java/org/opensearch/extensions/ExtensionReader.java
This file contains 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,45 @@ | ||
/* | ||
* 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 java.net.UnknownHostException; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
|
||
/** | ||
* Reference to a method that transports a parse request to an extension. By convention, this method takes | ||
* a category class used to identify the reader defined within the JVM that the extension is running on. | ||
* Additionally, this method takes in the extension's corresponding DiscoveryNode and a byte array (context) that the | ||
* extension's reader will be applied to. | ||
* | ||
* By convention the extensions' reader is a constructor that takes StreamInput as an argument for most classes and a static method for things like enums. | ||
* Classes will implement this via a constructor (or a static method in the case of enumerations), it's something that should | ||
* look like: | ||
* <pre><code> | ||
* public MyClass(final StreamInput in) throws IOException { | ||
* * this.someValue = in.readVInt(); | ||
* this.someMap = in.readMapOfLists(StreamInput::readString, StreamInput::readString); | ||
* } | ||
* </code></pre> | ||
* | ||
* @opensearch.internal | ||
*/ | ||
@FunctionalInterface | ||
public interface ExtensionReader { | ||
|
||
/** | ||
* Transports category class, and StreamInput (context), to the extension identified by the Discovery Node | ||
* | ||
* @param extensionNode Discovery Node identifying the Extension | ||
* @param categoryClass Super class that the reader extends | ||
* @param context Some context to transport | ||
* @throws UnknownHostException if the extension node host IP address could not be determined | ||
*/ | ||
void parse(DiscoveryNode extensionNode, Class categoryClass, Object context) throws UnknownHostException; | ||
|
||
} |
Oops, something went wrong.