From 32292f8408b5906b9f0ec7d42cfcff988f2c8c5d Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 13 Apr 2023 15:11:33 -0700 Subject: [PATCH] Implement getFieldMapping on SDKRestClient (#672) (#681) * Implement getFieldMapping on SDKRestClient * More migration notes * Update to match variable options parameter. --------- (cherry picked from commit 51c321c7a9d9a5b6217935eb31f27472c8a010c9) Signed-off-by: Daniel Widdis Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- PLUGIN_MIGRATION.md | 8 +++++++- src/main/java/org/opensearch/sdk/SDKClient.java | 16 ++++++++++++++++ .../java/org/opensearch/sdk/TestSDKClient.java | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/PLUGIN_MIGRATION.md b/PLUGIN_MIGRATION.md index cdb6411f..fa650b2e 100644 --- a/PLUGIN_MIGRATION.md +++ b/PLUGIN_MIGRATION.md @@ -31,12 +31,18 @@ The `SDKClient` provides two (eventually three) client options. The [Java Client for OpenSearch](https://github.com/opensearch-project/opensearch-java) (`OpenSearchClient`) will be supported with both synchronous and asynchronous clients, and is actively developed along with other language clients and should be used whenever possible. These clients do have significant implementation differences compared to the existing `Client` interface implemented by plugins. +## Change Plugin and OpenSearch TransportAction implementations + The `SDKRestClient` provides wrapper methods matching the `Client` API (but not implementing it), implemented internally with the (soon to be deprecated) `RestHighLevelClient`. While this speeds migration efforts, it should be considered a temporary "bridge" with follow up migration efforts to the `OpenSearchClient` planned. - While the class names and method parameters are the same, the `Request` and `Response` classes are often in different packages. In most cases, other than changing `import` statements, no additional code changes are required. In a few cases, there are minor changes required to interface with the new response class API. The `client.execute(action, request, responseListener)` method is implemented on the SDKClient. -Change the transport action inheritance from HandledTransportAction to directly inherit from `TransportAction`. +For TransportActions internal to the plugin (registered with `getActions()`), change the transport action inheritance from HandledTransportAction to directly inherit from `TransportAction`. + +TransportActions on OpenSearch are not accessible to extensions, and will need to be replaced with functionality from either a client (OpenSearch Client for Java or the SDKRestClient) or some other functionality directly provided by the Extensions SDK. A few examples of the types of changes needed include: + - Some transport actions on OpenSearch, such as the `GetFieldMappingsAction`, are exposed via the REST API and should be called using those clients. + - Some information available from services on OpenSearch, such as the state on ClusterService, stats on IndexingPressure object, and others, are designed for local access and would transfer far more data than needed if implemented directly. Calls to these services should be replaced by REST API calls to endpoints which filter to just the information required. For example, cluster state associated with inidices should use one of the Index API endpoints. Indexing Pressure can be retrieved by Node API endpoints. ### Replace RestHandler with ExtensionRestHandler diff --git a/src/main/java/org/opensearch/sdk/SDKClient.java b/src/main/java/org/opensearch/sdk/SDKClient.java index 6a69c101..d946bb3a 100644 --- a/src/main/java/org/opensearch/sdk/SDKClient.java +++ b/src/main/java/org/opensearch/sdk/SDKClient.java @@ -62,6 +62,8 @@ import org.opensearch.client.RestHighLevelClient; import org.opensearch.client.indices.CreateIndexRequest; import org.opensearch.client.indices.CreateIndexResponse; +import org.opensearch.client.indices.GetFieldMappingsRequest; +import org.opensearch.client.indices.GetFieldMappingsResponse; import org.opensearch.client.indices.GetMappingsRequest; import org.opensearch.client.indices.GetMappingsResponse; import org.opensearch.client.indices.PutMappingRequest; @@ -593,6 +595,20 @@ public Cancellable getMapping(GetMappingsRequest getMappingsRequest, ActionListe return this.indicesClient.getMappingAsync(getMappingsRequest, options, listener); } + /** + * Asynchronously retrieves the field mappings on an index or indices using the Get Field Mapping API. + * + * @param getFieldMappingsRequest the request + * @param listener the listener to be notified upon request completion + * @return cancellable that may be used to cancel the request + */ + public Cancellable getFieldMapping( + GetFieldMappingsRequest getFieldMappingsRequest, + ActionListener listener + ) { + return this.indicesClient.getFieldMappingAsync(getFieldMappingsRequest, options, listener); + } + /** * Asynchronously rolls over an index using the Rollover Index API. * diff --git a/src/test/java/org/opensearch/sdk/TestSDKClient.java b/src/test/java/org/opensearch/sdk/TestSDKClient.java index 4ace09f0..fabef692 100644 --- a/src/test/java/org/opensearch/sdk/TestSDKClient.java +++ b/src/test/java/org/opensearch/sdk/TestSDKClient.java @@ -26,6 +26,7 @@ import org.opensearch.client.Response; import org.opensearch.client.ResponseListener; import org.opensearch.client.indices.CreateIndexRequest; +import org.opensearch.client.indices.GetFieldMappingsRequest; import org.opensearch.client.indices.GetMappingsRequest; import org.opensearch.client.indices.PutMappingRequest; import org.opensearch.client.indices.rollover.RolloverRequest; @@ -124,6 +125,10 @@ public void testSDKIndicesClient() throws Exception { assertInstanceOf(Cancellable.class, indicesClient.delete(new DeleteIndexRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertInstanceOf(Cancellable.class, indicesClient.putSettings(new UpdateSettingsRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertInstanceOf(Cancellable.class, indicesClient.getMapping(new GetMappingsRequest(), ActionListener.wrap(r -> {}, e -> {}))); + assertInstanceOf( + Cancellable.class, + indicesClient.getFieldMapping(new GetFieldMappingsRequest(), ActionListener.wrap(r -> {}, e -> {})) + ); assertInstanceOf(Cancellable.class, indicesClient.putMapping(new PutMappingRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertInstanceOf( Cancellable.class,