Skip to content

Commit

Permalink
Adding health() to SDK cluster admin client (#810)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <[email protected]>
(cherry picked from commit ff1440c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jun 7, 2023
1 parent 1824e4f commit f08ba61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/org/opensearch/sdk/SDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.opensearch.action.ActionRequest;
import org.opensearch.action.ActionResponse;
import org.opensearch.action.ActionType;
import org.opensearch.action.admin.cluster.health.ClusterHealthRequest;
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
import org.opensearch.action.admin.indices.alias.get.GetAliasesRequest;
Expand Down Expand Up @@ -596,6 +598,18 @@ public Cancellable updateSettings(
return clusterClient.putSettingsAsync(clusterUpdateSettingsRequest, options, listener);
}

/**
* Asynchronously get cluster health using the Cluster Health API.
*
* If timeout occurred, {@link ClusterHealthResponse} will have isTimedOut() == true and status() == RestStatus.REQUEST_TIMEOUT
* @param clusterHealthRequest the request
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable health(ClusterHealthRequest clusterHealthRequest, ActionListener<ClusterHealthResponse> listener) {
return clusterClient.healthAsync(clusterHealthRequest, options, listener);
}

// TODO: Implement state()
// https:/opensearch-project/opensearch-sdk-java/issues/354
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/opensearch/sdk/TestSDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.junit.jupiter.api.Test;
import org.opensearch.action.ActionListener;
import org.opensearch.action.admin.cluster.health.ClusterHealthRequest;
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.opensearch.action.admin.indices.alias.get.GetAliasesRequest;
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest;
Expand Down Expand Up @@ -130,6 +131,7 @@ public void testSDKClusterAdminClient() throws Exception {
Cancellable.class,
clusterAdminClient.updateSettings(new ClusterUpdateSettingsRequest(), ActionListener.wrap(r -> {}, e -> {}))
);
assertInstanceOf(Cancellable.class, clusterAdminClient.health(new ClusterHealthRequest(), ActionListener.wrap(r -> {}, e -> {})));

sdkClient.doCloseHighLevelClient();
}
Expand Down

0 comments on commit f08ba61

Please sign in to comment.