forked from opensearch-project/opensearch-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide Extension API to OpenSearch (opensearch-project#74)
* Provide Extension API to OpenSearch Signed-off-by: Daniel Widdis <widdis@gmail.com> * Fix newline, add test Signed-off-by: Daniel Widdis <widdis@gmail.com> * Clarify Valid API format Signed-off-by: Daniel Widdis <widdis@gmail.com> * Store uniqueID of extensions Signed-off-by: Daniel Widdis <widdis@gmail.com> * Fix errors in merge commit Signed-off-by: Daniel Widdis <widdis@gmail.com> * Rename Api to RestApi Signed-off-by: Daniel Widdis <widdis@gmail.com> * Delay sending REST API until after responding to initialization Signed-off-by: Daniel Widdis <widdis@gmail.com> * Move YAML file to classpath Signed-off-by: Daniel Widdis <widdis@gmail.com> * Temporarily disable failing test for debug Signed-off-by: Daniel Widdis <widdis@gmail.com> * fixed testHandleExtensionInitRequest, added protected transport service setter in ExtensionsRunner for testing purporses Signed-off-by: Joshua Palis <jpalis@amazon.com> * Change transport service setter to package privage Signed-off-by: Daniel Widdis <widdis@gmail.com> * Rename RestApi to RestActions or RestPaths Signed-off-by: Daniel Widdis <widdis@gmail.com> Signed-off-by: Daniel Widdis <widdis@gmail.com> Signed-off-by: Joshua Palis <jpalis@amazon.com> Co-authored-by: Joshua Palis <jpalis@amazon.com>
- Loading branch information
Showing
12 changed files
with
297 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.sdk; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
/** | ||
* This class encapsulates the API of an Extension. | ||
*/ | ||
public class ExtensionRestPaths { | ||
|
||
private List<String> restPaths = new ArrayList<>(); | ||
|
||
/** | ||
* Placeholder field. Eventually will read this from spec file | ||
*/ | ||
public static final String EXTENSION_REST_PATHS_DESCRIPTOR = "/extension_rest_paths.yml"; | ||
|
||
/** | ||
* Jackson requires a default constructor. | ||
*/ | ||
private ExtensionRestPaths() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Gets the REST API Path and Method Strings. | ||
* | ||
* @return a copy of the list containing the REST API Path Strings | ||
*/ | ||
public List<String> getRestPaths() { | ||
return new ArrayList<>(restPaths); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ExtensionRestPaths{restPaths=" + restPaths + "}"; | ||
} | ||
|
||
/** | ||
* Instantiates an instance of this class by reading from a YAML file. | ||
* | ||
* @return An instance of this class. | ||
* @throws IOException if there is an error reading the file. | ||
*/ | ||
static ExtensionRestPaths readFromYaml() throws IOException { | ||
File file = new File(ExtensionRestPaths.class.getResource(EXTENSION_REST_PATHS_DESCRIPTOR).getPath()); | ||
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); | ||
return objectMapper.readValue(file, ExtensionRestPaths.class); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/org/opensearch/sdk/handlers/RegisterRestActionsResponseHandler.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,47 @@ | ||
/* | ||
* 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.sdk.handlers; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.extensions.RegisterRestActionsResponse; | ||
import org.opensearch.sdk.ExtensionsRunner; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportException; | ||
import org.opensearch.transport.TransportResponseHandler; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* This class handles the response from OpenSearch to a {@link ExtensionsRunner#sendRegisterRestActionsRequest(TransportService)} call. | ||
*/ | ||
public class RegisterRestActionsResponseHandler implements TransportResponseHandler<RegisterRestActionsResponse> { | ||
private static final Logger logger = LogManager.getLogger(RegisterRestActionsResponseHandler.class); | ||
|
||
@Override | ||
public void handleResponse(RegisterRestActionsResponse response) { | ||
logger.info("received {}", response); | ||
} | ||
|
||
@Override | ||
public void handleException(TransportException exp) { | ||
logger.info("RegisterActionsRequest failed", exp); | ||
} | ||
|
||
@Override | ||
public String executor() { | ||
return ThreadPool.Names.GENERIC; | ||
} | ||
|
||
@Override | ||
public RegisterRestActionsResponse read(StreamInput in) throws IOException { | ||
return new RegisterRestActionsResponse(in); | ||
} | ||
} |
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,9 @@ | ||
# This is a placeholder for a more formal API definition file, e.g., an OpenAPI | ||
# spec file which can be used to generate documentation and streamline testing | ||
# See https://github.com/opensearch-project/OpenSearch/issues/3090 | ||
# The API will include at least two components, a method (e.g., GET, PUT) and | ||
# parts of a URI (e.g., /_extensions/_sample-extension/api_1) | ||
restPaths: | ||
- GET /api_1 | ||
- PUT /api_2 | ||
- POST /api_3 |
Oops, something went wrong.