opensearch-sdk-java icon indicating copy to clipboard operation
opensearch-sdk-java copied to clipboard

[FEATURE] Add ability to pass ClusterStateRequest object when requesting Cluster State

Open dbwiddis opened this issue 2 years ago • 1 comments

Is your feature request related to a problem?

Current SDK implementation of getting cluster state is implemented with defaults in the ExtensionRequest fetching the state from the ClusterService:

    TransportResponse handleExtensionRequest(ExtensionRequest extensionRequest) throws Exception {
        switch (extensionRequest.getRequestType()) {
            case REQUEST_EXTENSION_CLUSTER_STATE:
                return new ClusterStateResponse(clusterService.getClusterName(), clusterService.state(), false);

This does not work for use cases where the specific values to be returned are configured, such as in the AD Plugin:

        ClusterStateRequest clusterStateRequest = new ClusterStateRequest()
            .clear()
            .indices(AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN)
            .metadata(true)
            .local(true)
            .indicesOptions(IndicesOptions.strictExpand());

        adminClient.cluster().state(clusterStateRequest, ActionListener.wrap(clusterStateResponse -> {

What solution would you like?

Either create a new transport action or modify the existing cluster state request action to take a ClusterStateRequest object as a parameter. The RestClusterStateAction class can probably called using the opensearch-java client with little overhead.

What alternatives have you considered?

Improving RestHighLevelClient to handle this case. Not desirable as it's on a path for deprecation.

Do you have any additional context?

This is part of the AnomalyDetectionIndices component in the AD plugin.

dbwiddis avatar Jan 23 '23 21:01 dbwiddis

The RestClusterStateAction class can probably called using the opensearch-java client with little overhead.

No, it can't. Don't even try. I did, and failed gloriously. See #667

There's a TransportAction and the requests are writeable. This is trivial using transport.

dbwiddis avatar Apr 10 '23 02:04 dbwiddis