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,