Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.x] Implement getFieldMapping on SDKRestClient #681

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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