From 247c2cdc30612a45037fac5cd982a11f44d177ac Mon Sep 17 00:00:00 2001 From: Joshua Palis Date: Fri, 2 Jun 2023 14:43:54 -0700 Subject: [PATCH] Adding exists/existsAlias to SDK Indices Client (#802) Signed-off-by: Joshua Palis --- .../java/org/opensearch/sdk/SDKClient.java | 23 +++++++++++++++++++ .../org/opensearch/sdk/TestSDKClient.java | 3 +++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/org/opensearch/sdk/SDKClient.java b/src/main/java/org/opensearch/sdk/SDKClient.java index b8f412dc..ab4638b1 100644 --- a/src/main/java/org/opensearch/sdk/SDKClient.java +++ b/src/main/java/org/opensearch/sdk/SDKClient.java @@ -77,6 +77,7 @@ import org.opensearch.client.indices.CreateIndexResponse; import org.opensearch.client.indices.GetFieldMappingsRequest; import org.opensearch.client.indices.GetFieldMappingsResponse; +import org.opensearch.client.indices.GetIndexRequest; import org.opensearch.client.indices.GetMappingsRequest; import org.opensearch.client.indices.GetMappingsResponse; import org.opensearch.client.indices.PutMappingRequest; @@ -738,5 +739,27 @@ public Cancellable rolloverIndex(RolloverRequest rolloverRequest, ActionListener public Cancellable getAliases(GetAliasesRequest getAliasesRequest, ActionListener listener) { return this.indicesClient.getAliasAsync(getAliasesRequest, options, listener); } + + /** + * Asynchronously checks if one or more aliases exist using the Aliases Exist API. + * + * @param getAliasesRequest the request + * @param listener the listener to be notified upon request completion + * @return cancellable that may be used to cancel the request + */ + public Cancellable existsAlias(GetAliasesRequest getAliasesRequest, ActionListener listener) { + return this.indicesClient.existsAliasAsync(getAliasesRequest, options, listener); + } + + /** + * Asynchronously checks if the index (indices) exists or not. + * + * @param getIndexRequest the request + * @param listener the listener to be notified upon request completion + * @return cancellable that may be used to cancel the request + */ + public Cancellable exists(GetIndexRequest getIndexRequest, ActionListener listener) { + return this.indicesClient.existsAsync(getIndexRequest, options, listener); + } } } diff --git a/src/test/java/org/opensearch/sdk/TestSDKClient.java b/src/test/java/org/opensearch/sdk/TestSDKClient.java index e4a6644c..4cb4a52c 100644 --- a/src/test/java/org/opensearch/sdk/TestSDKClient.java +++ b/src/test/java/org/opensearch/sdk/TestSDKClient.java @@ -29,6 +29,7 @@ import org.opensearch.client.ResponseListener; import org.opensearch.client.indices.CreateIndexRequest; import org.opensearch.client.indices.GetFieldMappingsRequest; +import org.opensearch.client.indices.GetIndexRequest; import org.opensearch.client.indices.GetMappingsRequest; import org.opensearch.client.indices.PutMappingRequest; import org.opensearch.client.indices.rollover.RolloverRequest; @@ -153,6 +154,8 @@ public void testSDKIndicesClient() throws Exception { indicesClient.rolloverIndex(new RolloverRequest("", ""), ActionListener.wrap(r -> {}, e -> {})) ); assertInstanceOf(Cancellable.class, indicesClient.getAliases(new GetAliasesRequest(), ActionListener.wrap(r -> {}, e -> {}))); + assertInstanceOf(Cancellable.class, indicesClient.existsAlias(new GetAliasesRequest(), ActionListener.wrap(r -> {}, e -> {}))); + assertInstanceOf(Cancellable.class, indicesClient.exists(new GetIndexRequest(), ActionListener.wrap(r -> {}, e -> {}))); sdkClient.doCloseHighLevelClient(); }