From ec17c60708b132c79f39ff8e74e05d87ecd7cece Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 21 Mar 2023 12:25:00 +0000 Subject: [PATCH] Add option to set headers and sort options in cat requests (#412) * Adding x-amz-content-sha256 header for signed requests (#339) * Adding X-Amz-Content-Sha256 header for signed requests Signed-off-by: Vacha Shah * Adding CHANGELOG entry Signed-off-by: Vacha Shah * Adding documentation comment Signed-off-by: Vacha Shah * Adding tests Signed-off-by: Vacha Shah * Addressing comments Signed-off-by: Vacha Shah * Addressing comments Signed-off-by: Vacha Shah * Removing refresh policy for integ tests for Sigv4 Signed-off-by: Vacha Shah * Updating the developer guide Signed-off-by: Vacha Shah Signed-off-by: Vacha Shah Signed-off-by: MarinaRazumovsky * Fix issue with completion suggester being parsed as term suggester. (#347) * Fix issue with completion suggester being parsed as term suggester. This commit fixes the issue where a completion suggester search request was being parsed as a term suggester and failing due to "Missing required property 'TermSuggestOption.score'" This solution was originally proposed by Github user @apatrida Signed-off-by: Dan Hart * Remove commented code Signed-off-by: Dan Hart * Fix format of changelog item Signed-off-by: Dan Hart Signed-off-by: Dan Hart Signed-off-by: MarinaRazumovsky * Update USER_GUIDE to use exact AWS brand names (#352) Minor update to use exact brand names. "OpenSearch" is rather overloaded to I find it less confusing to be precise in the naming. Signed-off-by: Andrew Ross Signed-off-by: Andrew Ross Signed-off-by: MarinaRazumovsky * Bumps Jackson from 2.14.1 to 2.14.2 (#357) Signed-off-by: Andriy Redko Signed-off-by: MarinaRazumovsky * Bulk UpdateOperation misses upsert options (#353) * Bulk UpdateOperation misses upsert options Signed-off-by: Andriy Redko * Fix formatting Signed-off-by: Andriy Redko --------- Signed-off-by: Andriy Redko Signed-off-by: MarinaRazumovsky * Upgrading compatibility to opensearch 2.5 (#367) * Upgrading compatibility to opensearch 2.5 Signed-off-by: amitai stern <123amitai@gmail.com> * latest 2.4 version Signed-off-by: amitai stern <123amitai@gmail.com> * keep existing compatibility matrix rows, this pr adds a new row for versions of opensearch after 2.3.0 Signed-off-by: amitai stern <123amitai@gmail.com> --------- Signed-off-by: amitai stern <123amitai@gmail.com> Signed-off-by: MarinaRazumovsky * add option to set columns into cat indices request Signed-off-by: MarinaRazumovsky * add changelog Signed-off-by: MarinaRazumovsky * changes in CatRequestBase, IndicesRequest, NodesRequest, RecoveryRequest and add tests Signed-off-by: MarinaRazumovsky * Feature/range aggregation fix 369 (#370) * test: create integration tests for date_range and range aggregation (#369) Signed-off-by: Dominik Szczepanczyk * fix: add a missing key propery to the RangeBucket (#369) Signed-off-by: Dominik Szczepanczyk * docs: add CHANGELOG entry (#369) Signed-off-by: Dominik Szczepanczyk --------- Signed-off-by: Dominik Szczepanczyk Signed-off-by: MarinaRazumovsky * Fixing integration tests (#375) * Fixing integration tests Signed-off-by: Vacha Shah * Updating the test with a non-exact check Signed-off-by: Vacha Shah --------- Signed-off-by: Vacha Shah Signed-off-by: MarinaRazumovsky * Adding bulk request example in user guide (#373) Signed-off-by: Vacha Shah Signed-off-by: MarinaRazumovsky * Fixing issue when tracktotalhits is disabled (#372) * Fixing issue when tracktotalhits is disabled Signed-off-by: Vacha Shah * Update Changelog Signed-off-by: Vacha Shah --------- Signed-off-by: Vacha Shah Co-authored-by: Daniel (dB.) Doubrovkine Signed-off-by: MarinaRazumovsky * changes changelog Signed-off-by: MarinaRazumovsky * Bump io.github.classgraph:classgraph from 4.8.154 to 4.8.156 (#390) * Bump io.github.classgraph:classgraph from 4.8.154 to 4.8.156 Bumps [io.github.classgraph:classgraph](https://github.com/classgraph/classgraph) from 4.8.154 to 4.8.156. - [Release notes](https://github.com/classgraph/classgraph/releases) - [Commits](https://github.com/classgraph/classgraph/compare/classgraph-4.8.154...classgraph-4.8.156) --- updated-dependencies: - dependency-name: io.github.classgraph:classgraph dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Update changelog Signed-off-by: dependabot[bot] --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] Signed-off-by: MarinaRazumovsky * Add 2PR approval to release workflow (#383) Signed-off-by: Sayali Gaikawad Signed-off-by: MarinaRazumovsky * Adding an example to use raw JSON class instead of target classes (#385) Signed-off-by: Vacha Shah Signed-off-by: MarinaRazumovsky * Update Gradle to 8.0.2 (#392) Signed-off-by: Andriy Redko Signed-off-by: MarinaRazumovsky * Add "mappings" field to IndexSettings object (#382) Signed-off-by: Ilya Lukyanovich Signed-off-by: MarinaRazumovsky * Created untriaged issue workflow. (#364) Signed-off-by: dblock Signed-off-by: MarinaRazumovsky * Bump io.github.classgraph:classgraph from 4.8.156 to 4.8.157 in /java-client (#403) * Bump io.github.classgraph:classgraph in /java-client Bumps [io.github.classgraph:classgraph](https://github.com/classgraph/classgraph) from 4.8.156 to 4.8.157. - [Release notes](https://github.com/classgraph/classgraph/releases) - [Commits](https://github.com/classgraph/classgraph/compare/classgraph-4.8.156...classgraph-4.8.157) --- updated-dependencies: - dependency-name: io.github.classgraph:classgraph dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Update changelog Signed-off-by: dependabot[bot] --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] Signed-off-by: MarinaRazumovsky * Add buffered lookahead for Jackson (#338) Signed-off-by: luneo7 Signed-off-by: MarinaRazumovsky * Mask env values for snapshots (#411) Signed-off-by: Sayali Gaikawad Signed-off-by: MarinaRazumovsky * option to set headers and sort into cat requests Signed-off-by: MarinaRazumovsky * fix test Signed-off-by: MarinaRazumovsky * fix changelog Signed-off-by: MarinaRazumovsky * add cat examples into USER_GUID Signed-off-by: MarinaRazumovsky --------- Signed-off-by: Vacha Shah Signed-off-by: MarinaRazumovsky Signed-off-by: Dan Hart Signed-off-by: Andrew Ross Signed-off-by: Andriy Redko Signed-off-by: amitai stern <123amitai@gmail.com> Signed-off-by: Dominik Szczepanczyk Signed-off-by: dependabot[bot] Signed-off-by: Sayali Gaikawad Signed-off-by: Ilya Lukyanovich Signed-off-by: dblock Signed-off-by: luneo7 Co-authored-by: Vacha Shah Co-authored-by: Danny Hart Co-authored-by: Andrew Ross Co-authored-by: Andriy Redko Co-authored-by: amitai stern <123amitai@gmail.com> Co-authored-by: szczepanczykd <48957041+szczepanczykd@users.noreply.github.com> Co-authored-by: Daniel (dB.) Doubrovkine Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] Co-authored-by: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Co-authored-by: Ilya Lukyanovich Co-authored-by: Lucas Rogerio Caetano Ferreira (cherry picked from commit 938170a69a21bb711ff861a0cf1178a8db6a4b90) Signed-off-by: github-actions[bot] Signed-off-by: Andriy Redko --- CHANGELOG.md | 1 + USER_GUIDE.md | 29 + .../client/opensearch/cat/AliasesRequest.java | 15 +- .../opensearch/cat/AllocationRequest.java | 15 +- .../client/opensearch/cat/CatRequestBase.java | 94 ++- .../opensearch/cat/ClusterManagerRequest.java | 15 +- .../client/opensearch/cat/CountRequest.java | 20 +- .../opensearch/cat/FielddataRequest.java | 15 +- .../client/opensearch/cat/HealthRequest.java | 15 +- .../client/opensearch/cat/HelpRequest.java | 49 +- .../client/opensearch/cat/IndicesRequest.java | 584 +++++++++--------- .../opensearch/cat/NodeattrsRequest.java | 49 +- .../client/opensearch/cat/NodesRequest.java | 241 ++++---- .../opensearch/cat/PendingTasksRequest.java | 8 +- .../client/opensearch/cat/PluginsRequest.java | 8 +- .../opensearch/cat/RecoveryRequest.java | 430 ++++++------- .../opensearch/cat/RepositoriesRequest.java | 8 +- .../opensearch/cat/SegmentsRequest.java | 15 +- .../client/opensearch/cat/ShardsRequest.java | 15 +- .../opensearch/cat/SnapshotsRequest.java | 15 +- .../client/opensearch/cat/TasksRequest.java | 15 +- .../opensearch/cat/TemplatesRequest.java | 20 +- .../opensearch/cat/ThreadPoolRequest.java | 15 +- .../integTest/AbstractCatClientIT.java | 219 +++++++ .../OpenSearchJavaClientTestCase.java | 2 +- .../integTest/httpclient5/CatIT.java | 16 + .../integTest/restclient/CatIT.java | 26 + 27 files changed, 1153 insertions(+), 801 deletions(-) create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/CatIT.java create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CatIT.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 19f9f98161..192ddf5999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Require two maintainers to approve release ([#383](https://github.com/opensearch-project/opensearch-java/pull/383)) - Add support for mapping limit settings ([#382](https://github.com/opensearch-project/opensearch-java/pull/382)) - Add buffered lookahead for Jackson ([#338](https://github.com/opensearch-project/opensearch-java/pull/338)) +- Add support for headers and sort parameters in cat requests ([#388](https://github.com/opensearch-project/opensearch-java/issues/388)) ### Dependencies - Bumps `grgit-gradle` from 4.0.1 to 5.0.0 diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 5c8a4be197..21b4b11c58 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -15,6 +15,10 @@ - [Aggregations](#aggregations) - [Delete the document](#delete-the-document) - [Delete the index](#delete-the-index) + - [Cat API](#cat-api) + - [Cat Indices](#cat-indices) + - [Cat Aliases](#cat-aliases) + - [Cat Nodes](#cat-nodes) - [Using different transport options](#using-different-transport-options) - [Amazon Managed OpenSearch](#amazon-managed-opensearch) @@ -199,6 +203,31 @@ DeleteIndexRequest deleteIndexRequest = new DeleteRequest.Builder().index(index) DeleteIndexResponse deleteIndexResponse = client.indices().delete(deleteIndexRequest); ``` +## Cat API + +### Cat Indices +The following sample code cat indices with required headers and sorted by creation date + +```java +IndicesRequest indicesRequest = new IndicesRequest.Builder() + .headers("index,health,status,pri,rep,doc.count,creation.date,creation.date.string").sort("creation.date").build(); +IndicesResponse indicesResponse = javaClient().cat().indices(indicesRequest); +``` + + +### Cat aliases +The following sample code cat aliases with name "test-alias" and sorted by index +```java +AliasesRequest aliasesRequest = new AliasesRequest.Builder().name("test-alias").sort("index").build(); +AliasesResponse aliasesResponse = javaClient().cat().aliases(aliasesRequest); +``` + +### Cat nodes +The following sample code cat nodes sorted by cpu +```java +NodesResponse nodesResponse = javaClient().cat().nodes(r -> r.sort("cpu")); +``` + # Using different transport options ## Amazon Managed OpenSearch diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/AliasesRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/AliasesRequest.java index bcd93f57a7..07bee1a2db 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/AliasesRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/AliasesRequest.java @@ -42,14 +42,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.aliases.Request @@ -67,7 +66,7 @@ public class AliasesRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private AliasesRequest(Builder builder) { - + super(builder); this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards); this.name = ApiTypeHelper.unmodifiable(builder.name); @@ -102,7 +101,7 @@ public final List name() { * Builder for {@link AliasesRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private List expandWildcards; @@ -170,6 +169,11 @@ public AliasesRequest build() { return new AliasesRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -214,8 +218,7 @@ public AliasesRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (ApiTypeHelper.isDefined(request.expandWildcards)) { params.put("expand_wildcards", request.expandWildcards.stream() diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/AllocationRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/AllocationRequest.java index 16681a809e..31c94269e7 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/AllocationRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/AllocationRequest.java @@ -42,14 +42,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.allocation.Request @@ -68,7 +67,7 @@ public class AllocationRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private AllocationRequest(Builder builder) { - + super(builder); this.bytes = builder.bytes; this.nodeId = ApiTypeHelper.unmodifiable(builder.nodeId); @@ -103,7 +102,7 @@ public final List nodeId() { * Builder for {@link AllocationRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private Bytes bytes; @@ -155,6 +154,11 @@ public AllocationRequest build() { return new AllocationRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -200,8 +204,7 @@ public AllocationRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.bytes != null) { params.put("bytes", request.bytes.jsonValue()); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/CatRequestBase.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/CatRequestBase.java index 1ff2f96ce0..1cbb1d9fab 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/CatRequestBase.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/CatRequestBase.java @@ -37,21 +37,99 @@ package org.opensearch.client.opensearch.cat; import org.opensearch.client.opensearch._types.RequestBase; +import org.opensearch.client.util.ObjectBuilder; import org.opensearch.client.util.ObjectBuilderBase; -// typedef: cat._types.CatRequestBase +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; +// typedef: cat._types.CatRequestBase public abstract class CatRequestBase extends RequestBase { - public CatRequestBase() { - } - protected abstract static class AbstractBuilder> - extends - ObjectBuilderBase { - protected abstract BuilderT self(); + @Nullable + private final String headers; + + @Nullable + private final String sort; + + public CatRequestBase() { + this.headers = null; + this.sort = null; + } + + public CatRequestBase(CatRequestBaseBuilder builder) { + this.headers = builder.headers; + this.sort = builder.sort; + } + + protected final Map queryParameters() { + Map params = new HashMap<>(); + if (headers != null && !headers.isBlank()) { + params.put("h", headers); + } + if(sort != null && !sort.isBlank()) { + params.put("s", sort); + } + params.put("format", "json"); + return params; + } + + + /** + * A comma-separated list of headers to limit the returned information + *

+ * API name: {@code h} + */ + public final String headers() { + return this.headers; + } + + /** + * A comma-separated list of headers to sort the returned information + *

+ * API name: {@code s} + *

+ */ + public final String sort() { + return this.sort; + } + + + protected abstract static class CatRequestBaseBuilder extends ObjectBuilderBase implements ObjectBuilder { + + @Nullable + protected String headers; + + @Nullable + protected String sort; + + protected abstract BuilderT self(); + + /** + * A comma-separated list of specific headers to limits the output + *

+ * API name: {@code h} + *

+ */ + public final BuilderT headers(@Nullable String headers) { + this.headers = headers; + return self(); + } + + /** + * A comma-separated list of headers to sort the returned information + *

+ * API name: {@code s} + *

+ */ + public final BuilderT sort(@Nullable String sort) { + this.sort = sort; + return self(); + } - } + } } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/ClusterManagerRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/ClusterManagerRequest.java index 513c6d7cfe..72e6803405 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/ClusterManagerRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/ClusterManagerRequest.java @@ -41,7 +41,6 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import java.util.HashMap; -import java.util.Map; // typedef: cat.cluster_manager.Request @@ -79,12 +78,7 @@ public ClusterManagerRequest() { }, // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER); + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER); /** * Endpoint "{@code cat.cluster_manager}". @@ -104,10 +98,5 @@ public ClusterManagerRequest() { }, // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER); + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/CountRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/CountRequest.java index 0925464f5b..68f48d2f41 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/CountRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/CountRequest.java @@ -41,14 +41,12 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.count.Request @@ -64,7 +62,7 @@ public class CountRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private CountRequest(Builder builder) { - + super(builder); this.index = ApiTypeHelper.unmodifiable(builder.index); } @@ -88,7 +86,7 @@ public final List index() { * Builder for {@link CountRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private List index; @@ -127,6 +125,11 @@ public CountRequest build() { return new CountRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -170,10 +173,5 @@ public CountRequest build() { }, // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, CountResponse._DESERIALIZER); + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, CountResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/FielddataRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/FielddataRequest.java index b47e4d2acf..3d23f6d1e2 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/FielddataRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/FielddataRequest.java @@ -42,14 +42,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.fielddata.Request @@ -68,7 +67,7 @@ public class FielddataRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private FielddataRequest(Builder builder) { - + super(builder); this.bytes = builder.bytes; this.fields = ApiTypeHelper.unmodifiable(builder.fields); @@ -103,7 +102,7 @@ public final List fields() { * Builder for {@link FielddataRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private Bytes bytes; @@ -155,6 +154,11 @@ public FielddataRequest build() { return new FielddataRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -200,8 +204,7 @@ public FielddataRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.bytes != null) { params.put("bytes", request.bytes.jsonValue()); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/HealthRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/HealthRequest.java index 114cddfcf6..a5cd535500 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/HealthRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/HealthRequest.java @@ -40,12 +40,11 @@ import org.opensearch.client.transport.Endpoint; import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; import java.util.function.Function; -import javax.annotation.Nullable; // typedef: cat.health.Request @@ -61,7 +60,7 @@ public class HealthRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private HealthRequest(Builder builder) { - + super(builder); this.ts = builder.ts; } @@ -86,7 +85,7 @@ public final Boolean ts() { * Builder for {@link HealthRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private Boolean ts; @@ -111,6 +110,11 @@ public HealthRequest build() { return new HealthRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -134,8 +138,7 @@ public HealthRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.ts != null) { params.put("ts", String.valueOf(request.ts)); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/HelpRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/HelpRequest.java index c6db7f28c9..df62fd4d8a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/HelpRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/HelpRequest.java @@ -41,48 +41,41 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import java.util.HashMap; -import java.util.Map; // typedef: cat.help.Request /** * Returns help for the Cat APIs. - * */ public class HelpRequest extends CatRequestBase { - public HelpRequest() { - } - - /** - * Singleton instance for {@link HelpRequest}. - */ - public static final HelpRequest _INSTANCE = new HelpRequest(); + public HelpRequest() { + } - // --------------------------------------------------------------------------------------------- + /** + * Singleton instance for {@link HelpRequest}. + */ + public static final HelpRequest _INSTANCE = new HelpRequest(); - /** - * Endpoint "{@code cat.help}". - */ - public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // --------------------------------------------------------------------------------------------- - // Request method - request -> { - return "GET"; + /** + * Endpoint "{@code cat.help}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( - }, + // Request method + request -> { + return "GET"; - // Request path - request -> { - return "/_cat"; + }, - }, + // Request path + request -> { + return "/_cat"; - // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; + }, - }, SimpleEndpoint.emptyMap(), false, HelpResponse._DESERIALIZER); + // Request parameters + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, HelpResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/IndicesRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/IndicesRequest.java index f63fdc2670..a33e0940ca 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/IndicesRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/IndicesRequest.java @@ -44,310 +44,312 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.indices.Request /** * Returns information about indices: number of primaries and replicas, document * counts, disk size, ... - * */ public class IndicesRequest extends CatRequestBase { - @Nullable - private final Bytes bytes; - - private final List expandWildcards; - - @Nullable - private final HealthStatus health; - - @Nullable - private final Boolean includeUnloadedSegments; - - private final List index; - - @Nullable - private final Boolean pri; - - // --------------------------------------------------------------------------------------------- - - private IndicesRequest(Builder builder) { - - this.bytes = builder.bytes; - this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards); - this.health = builder.health; - this.includeUnloadedSegments = builder.includeUnloadedSegments; - this.index = ApiTypeHelper.unmodifiable(builder.index); - this.pri = builder.pri; - - } - - public static IndicesRequest of(Function> fn) { - return fn.apply(new Builder()).build(); - } - - /** - * The unit in which to display byte values - *

- * API name: {@code bytes} - */ - @Nullable - public final Bytes bytes() { - return this.bytes; - } - - /** - * Whether to expand wildcard expression to concrete indices that are open, - * closed or both. - *

- * API name: {@code expand_wildcards} - */ - public final List expandWildcards() { - return this.expandWildcards; - } - - /** - * A health status ("green", "yellow", or "red" to - * filter only indices matching the specified health status - *

- * API name: {@code health} - */ - @Nullable - public final HealthStatus health() { - return this.health; - } - - /** - * If set to true segment stats will include stats for segments that are not - * currently loaded into memory - *

- * API name: {@code include_unloaded_segments} - */ - @Nullable - public final Boolean includeUnloadedSegments() { - return this.includeUnloadedSegments; - } - - /** - * A comma-separated list of index names to limit the returned information - *

- * API name: {@code index} - */ - public final List index() { - return this.index; - } - - /** - * Set to true to return stats only for primary shards - *

- * API name: {@code pri} - */ - @Nullable - public final Boolean pri() { - return this.pri; - } - - // --------------------------------------------------------------------------------------------- - - /** - * Builder for {@link IndicesRequest}. - */ - - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - @Nullable - private Bytes bytes; - - @Nullable - private List expandWildcards; - - @Nullable - private HealthStatus health; - - @Nullable - private Boolean includeUnloadedSegments; - - @Nullable - private List index; - - @Nullable - private Boolean pri; - - /** - * The unit in which to display byte values - *

- * API name: {@code bytes} - */ - public final Builder bytes(@Nullable Bytes value) { - this.bytes = value; - return this; - } - - /** - * Whether to expand wildcard expression to concrete indices that are open, - * closed or both. - *

- * API name: {@code expand_wildcards} - *

- * Adds all elements of list to expandWildcards. - */ - public final Builder expandWildcards(List list) { - this.expandWildcards = _listAddAll(this.expandWildcards, list); - return this; - } - - /** - * Whether to expand wildcard expression to concrete indices that are open, - * closed or both. - *

- * API name: {@code expand_wildcards} - *

- * Adds one or more values to expandWildcards. - */ - public final Builder expandWildcards(ExpandWildcard value, ExpandWildcard... values) { - this.expandWildcards = _listAdd(this.expandWildcards, value, values); - return this; - } - - /** - * A health status ("green", "yellow", or "red" to - * filter only indices matching the specified health status - *

- * API name: {@code health} - */ - public final Builder health(@Nullable HealthStatus value) { - this.health = value; - return this; - } - - /** - * If set to true segment stats will include stats for segments that are not - * currently loaded into memory - *

- * API name: {@code include_unloaded_segments} - */ - public final Builder includeUnloadedSegments(@Nullable Boolean value) { - this.includeUnloadedSegments = value; - return this; - } - - /** - * A comma-separated list of index names to limit the returned information - *

- * API name: {@code index} - *

- * Adds all elements of list to index. - */ - public final Builder index(List list) { - this.index = _listAddAll(this.index, list); - return this; - } - - /** - * A comma-separated list of index names to limit the returned information - *

- * API name: {@code index} - *

- * Adds one or more values to index. - */ - public final Builder index(String value, String... values) { - this.index = _listAdd(this.index, value, values); - return this; - } - - /** - * Set to true to return stats only for primary shards - *

- * API name: {@code pri} - */ - public final Builder pri(@Nullable Boolean value) { - this.pri = value; - return this; - } - - /** - * Builds a {@link IndicesRequest}. - * - * @throws NullPointerException - * if some of the required fields are null. - */ - public IndicesRequest build() { - _checkSingleUse(); - - return new IndicesRequest(this); - } - } - - // --------------------------------------------------------------------------------------------- - - /** - * Endpoint "{@code cat.indices}". - */ - public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( - - // Request method - request -> { - return "GET"; - - }, - - // Request path - request -> { - final int _index = 1 << 0; - - int propsSet = 0; - - if (ApiTypeHelper.isDefined(request.index())) - propsSet |= _index; - - if (propsSet == 0) { - StringBuilder buf = new StringBuilder(); - buf.append("/_cat"); - buf.append("/indices"); - return buf.toString(); - } - if (propsSet == (_index)) { - StringBuilder buf = new StringBuilder(); - buf.append("/_cat"); - buf.append("/indices"); - buf.append("/"); - SimpleEndpoint.pathEncode(request.index.stream().map(v -> v).collect(Collectors.joining(",")), buf); - return buf.toString(); - } - throw SimpleEndpoint.noPathTemplateFound("path"); - - }, - - // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - if (ApiTypeHelper.isDefined(request.expandWildcards)) { - params.put("expand_wildcards", - request.expandWildcards.stream() - .map(v -> v.jsonValue()).collect(Collectors.joining(","))); - } - if (request.bytes != null) { - params.put("bytes", request.bytes.jsonValue()); - } - if (request.pri != null) { - params.put("pri", String.valueOf(request.pri)); - } - if (request.health != null) { - params.put("health", request.health.jsonValue()); - } - if (request.includeUnloadedSegments != null) { - params.put("include_unloaded_segments", String.valueOf(request.includeUnloadedSegments)); - } - return params; - - }, SimpleEndpoint.emptyMap(), false, IndicesResponse._DESERIALIZER); + @Nullable + private final Bytes bytes; + + private final List expandWildcards; + + @Nullable + private final HealthStatus health; + + @Nullable + private final Boolean includeUnloadedSegments; + + private final List index; + + @Nullable + private final Boolean pri; + + + // --------------------------------------------------------------------------------------------- + + private IndicesRequest(Builder builder) { + super(builder); + this.bytes = builder.bytes; + this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards); + this.health = builder.health; + this.includeUnloadedSegments = builder.includeUnloadedSegments; + this.index = ApiTypeHelper.unmodifiable(builder.index); + this.pri = builder.pri; + } + + public static IndicesRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * The unit in which to display byte values + *

+ * API name: {@code bytes} + */ + @Nullable + public final Bytes bytes() { + return this.bytes; + } + + /** + * Whether to expand wildcard expression to concrete indices that are open, + * closed or both. + *

+ * API name: {@code expand_wildcards} + */ + public final List expandWildcards() { + return this.expandWildcards; + } + + /** + * A health status ("green", "yellow", or "red" to + * filter only indices matching the specified health status + *

+ * API name: {@code health} + */ + @Nullable + public final HealthStatus health() { + return this.health; + } + + /** + * If set to true segment stats will include stats for segments that are not + * currently loaded into memory + *

+ * API name: {@code include_unloaded_segments} + */ + @Nullable + public final Boolean includeUnloadedSegments() { + return this.includeUnloadedSegments; + } + + /** + * A comma-separated list of index names to limit the returned information + *

+ * API name: {@code index} + */ + public final List index() { + return this.index; + } + + /** + * Set to true to return stats only for primary shards + *

+ * API name: {@code pri} + */ + @Nullable + public final Boolean pri() { + return this.pri; + } + + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link IndicesRequest}. + */ + + public static class Builder extends CatRequestBaseBuilder { + @Nullable + private Bytes bytes; + + @Nullable + private List expandWildcards; + + @Nullable + private HealthStatus health; + + @Nullable + private Boolean includeUnloadedSegments; + + @Nullable + private List index; + + @Nullable + private Boolean pri; + + /** + * The unit in which to display byte values + *

+ * API name: {@code bytes} + */ + public final Builder bytes(@Nullable Bytes value) { + this.bytes = value; + return this; + } + + /** + * Whether to expand wildcard expression to concrete indices that are open, + * closed or both. + *

+ * API name: {@code expand_wildcards} + *

+ * Adds all elements of list to expandWildcards. + */ + public final Builder expandWildcards(List list) { + this.expandWildcards = _listAddAll(this.expandWildcards, list); + return this; + } + + /** + * Whether to expand wildcard expression to concrete indices that are open, + * closed or both. + *

+ * API name: {@code expand_wildcards} + *

+ * Adds one or more values to expandWildcards. + */ + public final Builder expandWildcards(ExpandWildcard value, ExpandWildcard... values) { + this.expandWildcards = _listAdd(this.expandWildcards, value, values); + return this; + } + + /** + * A health status ("green", "yellow", or "red" to + * filter only indices matching the specified health status + *

+ * API name: {@code health} + */ + public final Builder health(@Nullable HealthStatus value) { + this.health = value; + return this; + } + + /** + * If set to true segment stats will include stats for segments that are not + * currently loaded into memory + *

+ * API name: {@code include_unloaded_segments} + */ + public final Builder includeUnloadedSegments(@Nullable Boolean value) { + this.includeUnloadedSegments = value; + return this; + } + + /** + * A comma-separated list of index names to limit the returned information + *

+ * API name: {@code index} + *

+ * Adds all elements of list to index. + */ + public final Builder index(List list) { + this.index = _listAddAll(this.index, list); + return this; + } + + /** + * A comma-separated list of index names to limit the returned information + *

+ * API name: {@code index} + *

+ * Adds one or more values to index. + */ + public final Builder index(String value, String... values) { + this.index = _listAdd(this.index, value, values); + return this; + } + + /** + * Set to true to return stats only for primary shards + *

+ * API name: {@code pri} + */ + public final Builder pri(@Nullable Boolean value) { + this.pri = value; + return this; + } + + @Override + protected Builder self() { + return this; + } + + /** + * Builds a {@link IndicesRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public IndicesRequest build() { + _checkSingleUse(); + + return new IndicesRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code cat.indices}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + + // Request method + request -> { + return "GET"; + + }, + + // Request path + request -> { + final int _index = 1 << 0; + + int propsSet = 0; + + if (ApiTypeHelper.isDefined(request.index())) + propsSet |= _index; + + if (propsSet == 0) { + StringBuilder buf = new StringBuilder(); + buf.append("/_cat"); + buf.append("/indices"); + return buf.toString(); + } + if (propsSet == (_index)) { + StringBuilder buf = new StringBuilder(); + buf.append("/_cat"); + buf.append("/indices"); + buf.append("/"); + SimpleEndpoint.pathEncode(request.index.stream().map(v -> v).collect(Collectors.joining(",")), buf); + return buf.toString(); + } + throw SimpleEndpoint.noPathTemplateFound("path"); + + }, + + // Request parameters + request -> { + Map params = new HashMap<>(request.queryParameters()); + if (ApiTypeHelper.isDefined(request.expandWildcards)) { + params.put("expand_wildcards", + request.expandWildcards.stream() + .map(v -> v.jsonValue()).collect(Collectors.joining(","))); + } + if (request.bytes != null) { + params.put("bytes", request.bytes.jsonValue()); + } + if (request.pri != null) { + params.put("pri", String.valueOf(request.pri)); + } + if (request.health != null) { + params.put("health", request.health.jsonValue()); + } + if (request.includeUnloadedSegments != null) { + params.put("include_unloaded_segments", String.valueOf(request.includeUnloadedSegments)); + } + return params; + + }, SimpleEndpoint.emptyMap(), false, IndicesResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodeattrsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodeattrsRequest.java index 9f43e1be1f..1ec4511c6e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodeattrsRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodeattrsRequest.java @@ -41,48 +41,41 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import java.util.HashMap; -import java.util.Map; // typedef: cat.nodeattrs.Request /** * Returns information about custom node attributes. - * */ public class NodeattrsRequest extends CatRequestBase { - public NodeattrsRequest() { - } + public NodeattrsRequest() { + } - /** - * Singleton instance for {@link NodeattrsRequest}. - */ - public static final NodeattrsRequest _INSTANCE = new NodeattrsRequest(); + /** + * Singleton instance for {@link NodeattrsRequest}. + */ + public static final NodeattrsRequest _INSTANCE = new NodeattrsRequest(); - // --------------------------------------------------------------------------------------------- + // --------------------------------------------------------------------------------------------- - /** - * Endpoint "{@code cat.nodeattrs}". - */ - public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + /** + * Endpoint "{@code cat.nodeattrs}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( - // Request method - request -> { - return "GET"; + // Request method + request -> { + return "GET"; - }, + }, - // Request path - request -> { - return "/_cat/nodeattrs"; + // Request path + request -> { + return "/_cat/nodeattrs"; - }, + }, - // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, NodeattrsResponse._DESERIALIZER); + // Request parameters + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, NodeattrsResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodesRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodesRequest.java index 6d925aa82e..a0bf3c5d10 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodesRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/NodesRequest.java @@ -41,136 +41,137 @@ import org.opensearch.client.transport.Endpoint; import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; import java.util.function.Function; -import javax.annotation.Nullable; // typedef: cat.nodes.Request /** * Returns basic statistics about performance of cluster nodes. - * */ public class NodesRequest extends CatRequestBase { - @Nullable - private final Bytes bytes; - - @Nullable - private final Boolean fullId; - - // --------------------------------------------------------------------------------------------- - - private NodesRequest(Builder builder) { - - this.bytes = builder.bytes; - this.fullId = builder.fullId; - - } - - public static NodesRequest of(Function> fn) { - return fn.apply(new Builder()).build(); - } - - /** - * The unit in which to display byte values - *

- * API name: {@code bytes} - */ - @Nullable - public final Bytes bytes() { - return this.bytes; - } - - /** - * Return the full node ID instead of the shortened version (default: false) - *

- * API name: {@code full_id} - */ - @Nullable - public final Boolean fullId() { - return this.fullId; - } - - // --------------------------------------------------------------------------------------------- - - /** - * Builder for {@link NodesRequest}. - */ - - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - @Nullable - private Bytes bytes; - - @Nullable - private Boolean fullId; - - /** - * The unit in which to display byte values - *

- * API name: {@code bytes} - */ - public final Builder bytes(@Nullable Bytes value) { - this.bytes = value; - return this; - } - - /** - * Return the full node ID instead of the shortened version (default: false) - *

- * API name: {@code full_id} - */ - public final Builder fullId(@Nullable Boolean value) { - this.fullId = value; - return this; - } - - /** - * Builds a {@link NodesRequest}. - * - * @throws NullPointerException - * if some of the required fields are null. - */ - public NodesRequest build() { - _checkSingleUse(); - - return new NodesRequest(this); - } - } - - // --------------------------------------------------------------------------------------------- - - /** - * Endpoint "{@code cat.nodes}". - */ - public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( - - // Request method - request -> { - return "GET"; - - }, - - // Request path - request -> { - return "/_cat/nodes"; - - }, - - // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - if (request.bytes != null) { - params.put("bytes", request.bytes.jsonValue()); - } - if (request.fullId != null) { - params.put("full_id", String.valueOf(request.fullId)); - } - return params; - - }, SimpleEndpoint.emptyMap(), false, NodesResponse._DESERIALIZER); + @Nullable + private final Bytes bytes; + + @Nullable + private final Boolean fullId; + + // --------------------------------------------------------------------------------------------- + + private NodesRequest(Builder builder) { + super(builder); + this.bytes = builder.bytes; + this.fullId = builder.fullId; + + } + + public static NodesRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * The unit in which to display byte values + *

+ * API name: {@code bytes} + */ + @Nullable + public final Bytes bytes() { + return this.bytes; + } + + /** + * Return the full node ID instead of the shortened version (default: false) + *

+ * API name: {@code full_id} + */ + @Nullable + public final Boolean fullId() { + return this.fullId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link NodesRequest}. + */ + + public static class Builder extends CatRequestBaseBuilder { + @Nullable + private Bytes bytes; + + @Nullable + private Boolean fullId; + + /** + * The unit in which to display byte values + *

+ * API name: {@code bytes} + */ + public final Builder bytes(@Nullable Bytes value) { + this.bytes = value; + return this; + } + + /** + * Return the full node ID instead of the shortened version (default: false) + *

+ * API name: {@code full_id} + */ + public final Builder fullId(@Nullable Boolean value) { + this.fullId = value; + return this; + } + + /** + * Builds a {@link NodesRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public NodesRequest build() { + _checkSingleUse(); + + return new NodesRequest(this); + } + + @Override + protected Builder self() { + return this; + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code cat.nodes}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + + // Request method + request -> { + return "GET"; + + }, + + // Request path + request -> { + return "/_cat/nodes"; + + }, + + // Request parameters + request -> { + Map params = new HashMap<>(request.queryParameters()); + if (request.bytes != null) { + params.put("bytes", request.bytes.jsonValue()); + } + if (request.fullId != null) { + params.put("full_id", String.valueOf(request.fullId)); + } + return params; + + }, SimpleEndpoint.emptyMap(), false, NodesResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/PendingTasksRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/PendingTasksRequest.java index 25e5526607..a228b5ac74 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/PendingTasksRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/PendingTasksRequest.java @@ -41,7 +41,6 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import java.util.HashMap; -import java.util.Map; // typedef: cat.pending_tasks.Request @@ -79,10 +78,5 @@ public PendingTasksRequest() { }, // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, PendingTasksResponse._DESERIALIZER); + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, PendingTasksResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/PluginsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/PluginsRequest.java index f20d504f78..f256c1db4c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/PluginsRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/PluginsRequest.java @@ -41,7 +41,6 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import java.util.HashMap; -import java.util.Map; // typedef: cat.plugins.Request @@ -79,10 +78,5 @@ public PluginsRequest() { }, // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, PluginsResponse._DESERIALIZER); + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, PluginsResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/RecoveryRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/RecoveryRequest.java index 8762d3bcda..afb9469791 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/RecoveryRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/RecoveryRequest.java @@ -42,233 +42,233 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.recovery.Request /** * Returns information about index shard recoveries, both on-going completed. - * */ public class RecoveryRequest extends CatRequestBase { - @Nullable - private final Boolean activeOnly; - - @Nullable - private final Bytes bytes; - - @Nullable - private final Boolean detailed; - - private final List index; - - // --------------------------------------------------------------------------------------------- - - private RecoveryRequest(Builder builder) { - - this.activeOnly = builder.activeOnly; - this.bytes = builder.bytes; - this.detailed = builder.detailed; - this.index = ApiTypeHelper.unmodifiable(builder.index); - - } - - public static RecoveryRequest of(Function> fn) { - return fn.apply(new Builder()).build(); - } - - /** - * If true, the response only includes ongoing shard recoveries - *

- * API name: {@code active_only} - */ - @Nullable - public final Boolean activeOnly() { - return this.activeOnly; - } - - /** - * The unit in which to display byte values - *

- * API name: {@code bytes} - */ - @Nullable - public final Bytes bytes() { - return this.bytes; - } - - /** - * If true, the response includes detailed information about shard - * recoveries - *

- * API name: {@code detailed} - */ - @Nullable - public final Boolean detailed() { - return this.detailed; - } - - /** - * Comma-separated list or wildcard expression of index names to limit the - * returned information - *

- * API name: {@code index} - */ - public final List index() { - return this.index; - } - - // --------------------------------------------------------------------------------------------- - - /** - * Builder for {@link RecoveryRequest}. - */ - - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - @Nullable - private Boolean activeOnly; - - @Nullable - private Bytes bytes; - - @Nullable - private Boolean detailed; - - @Nullable - private List index; - - /** - * If true, the response only includes ongoing shard recoveries - *

- * API name: {@code active_only} - */ - public final Builder activeOnly(@Nullable Boolean value) { - this.activeOnly = value; - return this; - } - - /** - * The unit in which to display byte values - *

- * API name: {@code bytes} - */ - public final Builder bytes(@Nullable Bytes value) { - this.bytes = value; - return this; - } - - /** - * If true, the response includes detailed information about shard - * recoveries - *

- * API name: {@code detailed} - */ - public final Builder detailed(@Nullable Boolean value) { - this.detailed = value; - return this; - } - - /** - * Comma-separated list or wildcard expression of index names to limit the - * returned information - *

- * API name: {@code index} - *

- * Adds all elements of list to index. - */ - public final Builder index(List list) { - this.index = _listAddAll(this.index, list); - return this; - } - - /** - * Comma-separated list or wildcard expression of index names to limit the - * returned information - *

- * API name: {@code index} - *

- * Adds one or more values to index. - */ - public final Builder index(String value, String... values) { - this.index = _listAdd(this.index, value, values); - return this; - } - - /** - * Builds a {@link RecoveryRequest}. - * - * @throws NullPointerException - * if some of the required fields are null. - */ - public RecoveryRequest build() { - _checkSingleUse(); - - return new RecoveryRequest(this); - } - } - - // --------------------------------------------------------------------------------------------- - - /** - * Endpoint "{@code cat.recovery}". - */ - public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( - - // Request method - request -> { - return "GET"; - - }, - - // Request path - request -> { - final int _index = 1 << 0; - - int propsSet = 0; - - if (ApiTypeHelper.isDefined(request.index())) - propsSet |= _index; - - if (propsSet == 0) { - StringBuilder buf = new StringBuilder(); - buf.append("/_cat"); - buf.append("/recovery"); - return buf.toString(); - } - if (propsSet == (_index)) { - StringBuilder buf = new StringBuilder(); - buf.append("/_cat"); - buf.append("/recovery"); - buf.append("/"); - SimpleEndpoint.pathEncode(request.index.stream().map(v -> v).collect(Collectors.joining(",")), buf); - return buf.toString(); - } - throw SimpleEndpoint.noPathTemplateFound("path"); - - }, - - // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - if (request.detailed != null) { - params.put("detailed", String.valueOf(request.detailed)); - } - if (request.activeOnly != null) { - params.put("active_only", String.valueOf(request.activeOnly)); - } - if (request.bytes != null) { - params.put("bytes", request.bytes.jsonValue()); - } - return params; - - }, SimpleEndpoint.emptyMap(), false, RecoveryResponse._DESERIALIZER); + @Nullable + private final Boolean activeOnly; + + @Nullable + private final Bytes bytes; + + @Nullable + private final Boolean detailed; + + private final List index; + + // --------------------------------------------------------------------------------------------- + + private RecoveryRequest(Builder builder) { + super(builder); + this.activeOnly = builder.activeOnly; + this.bytes = builder.bytes; + this.detailed = builder.detailed; + this.index = ApiTypeHelper.unmodifiable(builder.index); + + } + + public static RecoveryRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * If true, the response only includes ongoing shard recoveries + *

+ * API name: {@code active_only} + */ + @Nullable + public final Boolean activeOnly() { + return this.activeOnly; + } + + /** + * The unit in which to display byte values + *

+ * API name: {@code bytes} + */ + @Nullable + public final Bytes bytes() { + return this.bytes; + } + + /** + * If true, the response includes detailed information about shard + * recoveries + *

+ * API name: {@code detailed} + */ + @Nullable + public final Boolean detailed() { + return this.detailed; + } + + /** + * Comma-separated list or wildcard expression of index names to limit the + * returned information + *

+ * API name: {@code index} + */ + public final List index() { + return this.index; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link RecoveryRequest}. + */ + + public static class Builder extends CatRequestBaseBuilder { + @Nullable + private Boolean activeOnly; + + @Nullable + private Bytes bytes; + + @Nullable + private Boolean detailed; + + @Nullable + private List index; + + /** + * If true, the response only includes ongoing shard recoveries + *

+ * API name: {@code active_only} + */ + public final Builder activeOnly(@Nullable Boolean value) { + this.activeOnly = value; + return this; + } + + /** + * The unit in which to display byte values + *

+ * API name: {@code bytes} + */ + public final Builder bytes(@Nullable Bytes value) { + this.bytes = value; + return this; + } + + /** + * If true, the response includes detailed information about shard + * recoveries + *

+ * API name: {@code detailed} + */ + public final Builder detailed(@Nullable Boolean value) { + this.detailed = value; + return this; + } + + /** + * Comma-separated list or wildcard expression of index names to limit the + * returned information + *

+ * API name: {@code index} + *

+ * Adds all elements of list to index. + */ + public final Builder index(List list) { + this.index = _listAddAll(this.index, list); + return this; + } + + /** + * Comma-separated list or wildcard expression of index names to limit the + * returned information + *

+ * API name: {@code index} + *

+ * Adds one or more values to index. + */ + public final Builder index(String value, String... values) { + this.index = _listAdd(this.index, value, values); + return this; + } + + /** + * Builds a {@link RecoveryRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public RecoveryRequest build() { + _checkSingleUse(); + + return new RecoveryRequest(this); + } + + @Override + protected Builder self() { + return this; + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code cat.recovery}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + + // Request method + request -> { + return "GET"; + + }, + + // Request path + request -> { + final int _index = 1 << 0; + + int propsSet = 0; + + if (ApiTypeHelper.isDefined(request.index())) propsSet |= _index; + + if (propsSet == 0) { + StringBuilder buf = new StringBuilder(); + buf.append("/_cat"); + buf.append("/recovery"); + return buf.toString(); + } + if (propsSet == (_index)) { + StringBuilder buf = new StringBuilder(); + buf.append("/_cat"); + buf.append("/recovery"); + buf.append("/"); + SimpleEndpoint.pathEncode(request.index.stream().map(v -> v).collect(Collectors.joining(",")), buf); + return buf.toString(); + } + throw SimpleEndpoint.noPathTemplateFound("path"); + + }, + + // Request parameters + request -> { + Map params = new HashMap<>(request.queryParameters()); + if (request.detailed != null) { + params.put("detailed", String.valueOf(request.detailed)); + } + if (request.activeOnly != null) { + params.put("active_only", String.valueOf(request.activeOnly)); + } + if (request.bytes != null) { + params.put("bytes", request.bytes.jsonValue()); + } + return params; + + }, SimpleEndpoint.emptyMap(), false, RecoveryResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/RepositoriesRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/RepositoriesRequest.java index 49bff51dd9..c903f8285e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/RepositoriesRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/RepositoriesRequest.java @@ -41,7 +41,6 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import java.util.HashMap; -import java.util.Map; // typedef: cat.repositories.Request @@ -79,10 +78,5 @@ public RepositoriesRequest() { }, // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, RepositoriesResponse._DESERIALIZER); + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, RepositoriesResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/SegmentsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/SegmentsRequest.java index 6c2adce21e..10af4ad191 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/SegmentsRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/SegmentsRequest.java @@ -42,14 +42,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.segments.Request @@ -67,7 +66,7 @@ public class SegmentsRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private SegmentsRequest(Builder builder) { - + super(builder); this.bytes = builder.bytes; this.index = ApiTypeHelper.unmodifiable(builder.index); @@ -102,7 +101,7 @@ public final List index() { * Builder for {@link SegmentsRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private Bytes bytes; @@ -154,6 +153,11 @@ public SegmentsRequest build() { return new SegmentsRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -198,8 +202,7 @@ public SegmentsRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.bytes != null) { params.put("bytes", request.bytes.jsonValue()); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/ShardsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/ShardsRequest.java index 229d47ddad..96c09ee559 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/ShardsRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/ShardsRequest.java @@ -42,14 +42,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.shards.Request @@ -67,7 +66,7 @@ public class ShardsRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private ShardsRequest(Builder builder) { - + super(builder); this.bytes = builder.bytes; this.index = ApiTypeHelper.unmodifiable(builder.index); @@ -102,7 +101,7 @@ public final List index() { * Builder for {@link ShardsRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private Bytes bytes; @@ -154,6 +153,11 @@ public ShardsRequest build() { return new ShardsRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -198,8 +202,7 @@ public ShardsRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.bytes != null) { params.put("bytes", request.bytes.jsonValue()); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/SnapshotsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/SnapshotsRequest.java index ea05c89761..70bf7a5abc 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/SnapshotsRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/SnapshotsRequest.java @@ -41,14 +41,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.snapshots.Request @@ -66,7 +65,7 @@ public class SnapshotsRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private SnapshotsRequest(Builder builder) { - + super(builder); this.ignoreUnavailable = builder.ignoreUnavailable; this.repository = ApiTypeHelper.unmodifiable(builder.repository); @@ -101,7 +100,7 @@ public final List repository() { * Builder for {@link SnapshotsRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private Boolean ignoreUnavailable; @@ -153,6 +152,11 @@ public SnapshotsRequest build() { return new SnapshotsRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -198,8 +202,7 @@ public SnapshotsRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.ignoreUnavailable != null) { params.put("ignore_unavailable", String.valueOf(request.ignoreUnavailable)); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/TasksRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/TasksRequest.java index ee1dc86744..0c7d44eb89 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/TasksRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/TasksRequest.java @@ -41,14 +41,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.tasks.Request @@ -72,7 +71,7 @@ public class TasksRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private TasksRequest(Builder builder) { - + super(builder); this.actions = ApiTypeHelper.unmodifiable(builder.actions); this.detailed = builder.detailed; this.nodeId = ApiTypeHelper.unmodifiable(builder.nodeId); @@ -125,7 +124,7 @@ public final Long parentTask() { * Builder for {@link TasksRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private List actions; @@ -213,6 +212,11 @@ public TasksRequest build() { return new TasksRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -236,8 +240,7 @@ public TasksRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.detailed != null) { params.put("detailed", String.valueOf(request.detailed)); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/TemplatesRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/TemplatesRequest.java index 8ebdfe1795..28c0aec995 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/TemplatesRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/TemplatesRequest.java @@ -40,12 +40,10 @@ import org.opensearch.client.transport.Endpoint; import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; -import java.util.Map; import java.util.function.Function; -import javax.annotation.Nullable; // typedef: cat.templates.Request @@ -61,7 +59,7 @@ public class TemplatesRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private TemplatesRequest(Builder builder) { - + super(builder); this.name = builder.name; } @@ -86,7 +84,7 @@ public final String name() { * Builder for {@link TemplatesRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private String name; @@ -111,6 +109,11 @@ public TemplatesRequest build() { return new TemplatesRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -154,10 +157,5 @@ public TemplatesRequest build() { }, // Request parameters - request -> { - Map params = new HashMap<>(); - params.put("format", "json"); - return params; - - }, SimpleEndpoint.emptyMap(), false, TemplatesResponse._DESERIALIZER); + request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, TemplatesResponse._DESERIALIZER); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/ThreadPoolRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/ThreadPoolRequest.java index 90be667ebb..856487d47d 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/ThreadPoolRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/ThreadPoolRequest.java @@ -42,14 +42,13 @@ import org.opensearch.client.transport.endpoints.SimpleEndpoint; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -import org.opensearch.client.util.ObjectBuilderBase; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; // typedef: cat.thread_pool.Request @@ -68,7 +67,7 @@ public class ThreadPoolRequest extends CatRequestBase { // --------------------------------------------------------------------------------------------- private ThreadPoolRequest(Builder builder) { - + super(builder); this.size = builder.size; this.threadPoolPatterns = ApiTypeHelper.unmodifiable(builder.threadPoolPatterns); @@ -104,7 +103,7 @@ public final List threadPoolPatterns() { * Builder for {@link ThreadPoolRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends CatRequestBaseBuilder { @Nullable private ThreadPoolSize size; @@ -158,6 +157,11 @@ public ThreadPoolRequest build() { return new ThreadPoolRequest(this); } + + @Override + protected Builder self() { + return this; + } } // --------------------------------------------------------------------------------------------- @@ -204,8 +208,7 @@ public ThreadPoolRequest build() { // Request parameters request -> { - Map params = new HashMap<>(); - params.put("format", "json"); + Map params = new HashMap<>(request.queryParameters()); if (request.size != null) { params.put("size", request.size.jsonValue()); } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java new file mode 100644 index 0000000000..af9f9caeb0 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java @@ -0,0 +1,219 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.integTest; + +import org.opensearch.client.opensearch._types.Bytes; +import org.opensearch.client.opensearch._types.Refresh; +import org.opensearch.client.opensearch._types.Result; +import org.opensearch.client.opensearch.cat.AliasesResponse; +import org.opensearch.client.opensearch.cat.AllocationResponse; +import org.opensearch.client.opensearch.cat.IndicesResponse; +import org.opensearch.client.opensearch.cat.NodesResponse; +import org.opensearch.client.opensearch.cat.PluginsResponse; +import org.opensearch.client.opensearch.cat.RecoveryResponse; +import org.opensearch.client.opensearch.cat.SegmentsResponse; +import org.opensearch.client.opensearch.cat.ShardsResponse; +import org.opensearch.client.opensearch.cat.aliases.AliasesRecord; +import org.opensearch.client.opensearch.cat.allocation.AllocationRecord; +import org.opensearch.client.opensearch.cat.indices.IndicesRecord; +import org.opensearch.client.opensearch.cat.nodes.NodesRecord; +import org.opensearch.client.opensearch.cat.recovery.RecoveryRecord; +import org.opensearch.client.opensearch.cat.segments.SegmentsRecord; +import org.opensearch.client.opensearch.cat.shards.ShardsRecord; +import org.opensearch.client.opensearch.core.IndexResponse; +import org.opensearch.client.opensearch.indices.CreateIndexResponse; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public abstract class AbstractCatClientIT extends OpenSearchJavaClientTestCase { + + public void testCatNodes() throws Exception { + NodesResponse nodesResponse = javaClient().cat().nodes(r -> r.bytes(Bytes.Bytes).fullId(true) + .headers("id,ip,name,version,pid,heap.percent,ram.percent,cpu,load_1m,load_5m,load_15m,node.role")); + + assertNotNull(nodesResponse.valueBody()); + assertTrue(nodesResponse.valueBody().size() > 0); + + NodesRecord nodesRecord = nodesResponse.valueBody().get(0); + + assertNotNull(nodesRecord.id()); + assertNotNull(nodesRecord.ip()); + assertNotNull(nodesRecord.name()); + assertNotNull(nodesRecord.version()); + assertNotNull(nodesRecord.pid()); + assertNotNull(nodesRecord.heapPercent()); + assertNotNull(nodesRecord.ramPercent()); + assertNotNull(nodesRecord.cpu()); + assertNotNull(nodesRecord.load1m()); + assertNotNull(nodesRecord.load5m()); + assertNotNull(nodesRecord.load15m()); + assertNotNull(nodesRecord.nodeRole()); + } + + public void testCatIndices() throws Exception { + createIndex("my-index-for-cat-test"); + + IndicesResponse indicesResponse = javaClient().cat().indices(r -> r.headers("index,health,status,uuid,pri,rep,docs.count," + + "docs.deleted,store.size,pri.store.size,creation.date,creation.date.string").bytes(Bytes.Bytes)); + + assertNotNull(indicesResponse.valueBody()); + assertTrue(indicesResponse.valueBody().size() > 0); + + IndicesRecord indicesRecord = indicesResponse.valueBody().get(0); + + assertNotNull(indicesRecord.index()); + assertNotNull(indicesRecord.health()); + assertNotNull(indicesRecord.status()); + assertNotNull(indicesRecord.uuid()); + assertNotNull(indicesRecord.pri()); + assertNotNull(indicesRecord.rep()); + assertNotNull(indicesRecord.docsCount()); + assertNotNull(indicesRecord.docsDeleted()); + assertNotNull(indicesRecord.storeSize()); + assertNotNull(indicesRecord.priStoreSize()); + assertNotNull(indicesRecord.creationDate()); + assertNotNull(indicesRecord.creationDateString()); + } + + public void testCatRecovery() throws Exception { + createIndex("test-cat-recovery-index"); + RecoveryResponse recoveryResponse = javaClient().cat().recovery(r -> r.headers("index,shard,type,stage,source_host,source_node," + + "target_host,target_node,repository,snapshot,files,files_recovered,files_percent,files_total").bytes(Bytes.Bytes)); + + assertNotNull("recoveryResponse.valueBody() is null", recoveryResponse.valueBody()); + assertTrue("recoveryResponse.valueBody().size() == 0", recoveryResponse.valueBody().size() > 0); + + RecoveryRecord recoveryRecord = recoveryResponse.valueBody().get(0); + + assertNotNull(recoveryRecord.index()); + assertNotNull(recoveryRecord.shard()); + assertNotNull(recoveryRecord.type()); + assertNotNull(recoveryRecord.stage()); + assertNotNull(recoveryRecord.sourceHost()); + assertNotNull(recoveryRecord.sourceNode()); + assertNotNull(recoveryRecord.targetHost()); + assertNotNull(recoveryRecord.targetNode()); + assertNotNull(recoveryRecord.repository()); + assertNotNull(recoveryRecord.snapshot()); + assertNotNull(recoveryRecord.files()); + assertNotNull(recoveryRecord.filesRecovered()); + assertNotNull(recoveryRecord.filesPercent()); + assertNotNull(recoveryRecord.filesTotal()); + } + + public void testCatAliases() throws Exception { + String indexName = "test-aliases-index"; + String alias = "new-alias"; + createIndex(indexName); + assertTrue(javaClient().indices().putAlias(r -> r.index(indexName).name(alias).isWriteIndex(true)).acknowledged()); + + AliasesResponse aliasesResponse = javaClient().cat().aliases(r -> + r.headers("alias,index,is_write_index,routing.index,routing.search").sort("is_write_index")); + + assertNotNull(aliasesResponse.valueBody()); + assertTrue(aliasesResponse.valueBody().size() > 0); + + AliasesRecord aliasRecord = aliasesResponse.valueBody().stream().filter(aliasesRecord -> aliasesRecord.alias().equals(alias)) + .findAny().get(); + + assertTrue(aliasRecord.index().equals(indexName)); + assertTrue(aliasRecord.isWriteIndex().equals(Boolean.TRUE.toString())); + assertNotNull(aliasRecord.routingIndex()); + assertNotNull(aliasRecord.routingSearch()); + assertNull(aliasRecord.filter()); + } + + public void testCatShards() throws Exception { + createIndex("test-cat-shards-index-1"); + createIndex("test-cat-shards-index-3"); + createIndex("test-cat-shards-index-2"); + createIndex("a-test-cat-shards-index"); + + ShardsResponse shardsResponse = javaClient().cat().shards(r -> r.headers("index,shard,prirep,state,store").sort("index") + .bytes(Bytes.Bytes)); + assertNotNull(shardsResponse.valueBody()); + assertTrue(shardsResponse.valueBody().size() > 0); + + ShardsRecord shardsRecord = shardsResponse.valueBody().get(0); + + assertNotNull(shardsRecord.index()); + assertNotNull(shardsRecord.shard()); + assertNotNull(shardsRecord.prirep()); + assertNotNull(shardsRecord.state()); + assertNotNull(shardsRecord.store()); + assertNull(shardsRecord.node()); + assertNull(shardsRecord.ip()); + + List indices = shardsResponse.valueBody().stream().map(shardRecord -> shardRecord.index()).collect(Collectors.toList()); + assertTrue(indices.equals(indices.stream().sorted().collect(Collectors.toList()))); + } + + public void testCatAllocation() throws Exception { + createIndex("test-cat-allocations-index"); + + AllocationResponse allocationResponse = javaClient().cat().allocation(r -> + r.headers("ip,node,shards,disk.indices,disk.used,disk.avail,disk.total,disk.percent").sort("ip")); + assertNotNull(allocationResponse.valueBody()); + assertTrue(allocationResponse.valueBody().size() > 0); + + AllocationRecord allocationRecord = allocationResponse.valueBody().stream().filter(allocation -> + !allocation.node().equals("UNASSIGNED")).findAny().get(); + assertNotNull(allocationRecord.ip()); + assertNotNull(allocationRecord.node()); + assertNotNull(allocationRecord.shards()); + assertNotNull(allocationRecord.diskIndices()); + assertNotNull(allocationRecord.diskUsed()); + assertNotNull(allocationRecord.diskAvail()); + assertNotNull(allocationRecord.diskTotal()); + assertNotNull(allocationRecord.diskPercent()); + assertNull(allocationRecord.host()); + } + + public void testCatPlugins() throws Exception { + assumeTrue("There are no plugins installed when HTTP is used", isHttps()); + PluginsResponse pluginsResponse = javaClient().cat().plugins(); + assertNotNull(pluginsResponse.valueBody()); + assertTrue(pluginsResponse.valueBody().size() > 0); + } + + public void testCatSegments() throws Exception { + createIndex("cat-segments-test-index"); + + final IndexResponse index = javaClient().index(b -> b + .index("test-cat-segments-index") + .id("id") + .refresh(Refresh.True) + .document(Map.of("test-cat-segments-key", "test-cat-segments-value"))); + + assertTrue(index.result() == Result.Created); + + SegmentsResponse segmentsResponse = javaClient().cat().segments(r -> r.headers("index,shard,id,segment,size")); + assertNotNull("segmentsResponse.valueBody() is null", segmentsResponse.valueBody()); + assertTrue("segmentsResponse.valueBody().size() == 0", segmentsResponse.valueBody().size() > 0); + + SegmentsRecord segmentsRecord = segmentsResponse.valueBody().get(0); + + assertNotNull(segmentsRecord.id()); + assertNotNull(segmentsRecord.index()); + assertNotNull(segmentsRecord.shard()); + assertNotNull(segmentsRecord.segment()); + assertNotNull(segmentsRecord.size()); + assertNull(segmentsRecord.ip()); + assertNull(segmentsRecord.prirep()); + } + + private void createIndex(String indexName) throws Exception { + CreateIndexResponse createResponse = javaClient().indices().create(b -> b.index(indexName)); + assertTrue(createResponse.acknowledged()); + assertTrue(createResponse.shardsAcknowledged()); + } + +} diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java index 11c748762f..fc6d8af05d 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java @@ -130,7 +130,7 @@ protected String getTestRestCluster() { protected void wipeAllOSIndices() throws IOException { final IndicesResponse response = adminJavaClient() .cat() - .indices(r -> r.expandWildcards(ExpandWildcard.All)); + .indices(r -> r.headers("index,creation.date").expandWildcards(ExpandWildcard.All)); for (IndicesRecord index : response.valueBody()) { if (index.index() != null && !".opendistro_security".equals(index.index())) { diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/CatIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/CatIT.java new file mode 100644 index 0000000000..f152e23268 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/CatIT.java @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.integTest.httpclient5; + +import org.opensearch.client.opensearch.integTest.AbstractCatClientIT; + +public class CatIT extends AbstractCatClientIT implements HttpClient5TransportSupport { +} + + diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CatIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CatIT.java new file mode 100644 index 0000000000..a00207e882 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CatIT.java @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.integTest.restclient; + +import org.apache.http.HttpHost; +import org.opensearch.client.json.jackson.JacksonJsonpMapper; +import org.opensearch.client.opensearch.integTest.AbstractCatClientIT; +import org.opensearch.client.transport.OpenSearchTransport; +import org.opensearch.client.transport.rest_client.RestClientTransport; +import org.opensearch.common.settings.Settings; + +import java.io.IOException; + +public class CatIT extends AbstractCatClientIT { + @Override + public OpenSearchTransport buildTransport(Settings settings, HttpHost[] hosts) throws IOException { + return new RestClientTransport(buildClient(settings, hosts), new JacksonJsonpMapper()); + } + +}