Skip to content

Commit

Permalink
Implement getFieldMapping on SDKRestClient (#672) (#681)
Browse files Browse the repository at this point in the history
* Implement getFieldMapping on SDKRestClient



* More migration notes



* Update to match variable options parameter.



---------


(cherry picked from commit 51c321c)

Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent cb86277 commit 32292f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion PLUGIN_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/opensearch/sdk/SDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GetFieldMappingsResponse> listener
) {
return this.indicesClient.getFieldMappingAsync(getFieldMappingsRequest, options, listener);
}

/**
* Asynchronously rolls over an index using the Rollover Index API.
*
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/opensearch/sdk/TestSDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 32292f8

Please sign in to comment.