From b07f140e74b1ebc845f2b5de053afdec5974d6e5 Mon Sep 17 00:00:00 2001 From: Vacha Shah Date: Thu, 15 Feb 2024 06:08:15 +0000 Subject: [PATCH] Fixing cluster stats response for role types and adding search role type Signed-off-by: Vacha Shah --- .../cluster/stats/ClusterNodeCount.java | 203 ++---------------- .../cluster/stats/NodePackagingType.java | 24 --- .../integTest/AbstractClusterClientIT.java | 13 ++ 3 files changed, 30 insertions(+), 210 deletions(-) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/stats/ClusterNodeCount.java b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/stats/ClusterNodeCount.java index 17f9a8d370..e69ada6575 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/stats/ClusterNodeCount.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/stats/ClusterNodeCount.java @@ -59,24 +59,10 @@ public class ClusterNodeCount implements JsonpSerializable { private final int total; - private final int votingOnly; - - private final int dataCold; - - @Nullable - private final Integer dataFrozen; - - private final int dataContent; - - private final int dataWarm; - - private final int dataHot; - - private final int ml; - private final int remoteClusterClient; - private final int transform; + @Nullable + private final Integer search; // --------------------------------------------------------------------------------------------- @@ -87,16 +73,8 @@ private ClusterNodeCount(Builder builder) { this.ingest = ApiTypeHelper.requireNonNull(builder.ingest, this, "ingest"); this.clusterManager = ApiTypeHelper.requireNonNull(builder.clusterManager, this, "clusterManager"); this.total = ApiTypeHelper.requireNonNull(builder.total, this, "total"); - this.votingOnly = ApiTypeHelper.requireNonNull(builder.votingOnly, this, "votingOnly"); - this.dataCold = ApiTypeHelper.requireNonNull(builder.dataCold, this, "dataCold"); - this.dataFrozen = builder.dataFrozen; - this.dataContent = ApiTypeHelper.requireNonNull(builder.dataContent, this, "dataContent"); - this.dataWarm = ApiTypeHelper.requireNonNull(builder.dataWarm, this, "dataWarm"); - this.dataHot = ApiTypeHelper.requireNonNull(builder.dataHot, this, "dataHot"); - this.ml = ApiTypeHelper.requireNonNull(builder.ml, this, "ml"); this.remoteClusterClient = ApiTypeHelper.requireNonNull(builder.remoteClusterClient, this, "remoteClusterClient"); - this.transform = ApiTypeHelper.requireNonNull(builder.transform, this, "transform"); - + this.search = builder.search; } public static ClusterNodeCount of(Function> fn) { @@ -138,56 +116,6 @@ public final int total() { return this.total; } - /** - * Required - API name: {@code voting_only} - */ - public final int votingOnly() { - return this.votingOnly; - } - - /** - * Required - API name: {@code data_cold} - */ - public final int dataCold() { - return this.dataCold; - } - - /** - * API name: {@code data_frozen} - */ - @Nullable - public final Integer dataFrozen() { - return this.dataFrozen; - } - - /** - * Required - API name: {@code data_content} - */ - public final int dataContent() { - return this.dataContent; - } - - /** - * Required - API name: {@code data_warm} - */ - public final int dataWarm() { - return this.dataWarm; - } - - /** - * Required - API name: {@code data_hot} - */ - public final int dataHot() { - return this.dataHot; - } - - /** - * Required - API name: {@code ml} - */ - public final int ml() { - return this.ml; - } - /** * Required - API name: {@code remote_cluster_client} */ @@ -196,10 +124,11 @@ public final int remoteClusterClient() { } /** - * Required - API name: {@code transform} + * API name: {@code search} */ - public final int transform() { - return this.transform; + @Nullable + public final Integer search() { + return this.search; } /** @@ -228,34 +157,13 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("total"); generator.write(this.total); - generator.writeKey("voting_only"); - generator.write(this.votingOnly); - - generator.writeKey("data_cold"); - generator.write(this.dataCold); - - if (this.dataFrozen != null) { - generator.writeKey("data_frozen"); - generator.write(this.dataFrozen); - - } - generator.writeKey("data_content"); - generator.write(this.dataContent); - - generator.writeKey("data_warm"); - generator.write(this.dataWarm); - - generator.writeKey("data_hot"); - generator.write(this.dataHot); - - generator.writeKey("ml"); - generator.write(this.ml); - generator.writeKey("remote_cluster_client"); generator.write(this.remoteClusterClient); - generator.writeKey("transform"); - generator.write(this.transform); + if (this.search != null) { + generator.writeKey("search"); + generator.write(this.search); + } } @@ -276,24 +184,9 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Integer count; - private String flavor; - private String type; /** @@ -132,14 +117,6 @@ public final Builder count(int value) { return this; } - /** - * Required - API name: {@code flavor} - */ - public final Builder flavor(String value) { - this.flavor = value; - return this; - } - /** * Required - API name: {@code type} */ @@ -174,7 +151,6 @@ public NodePackagingType build() { protected static void setupNodePackagingTypeDeserializer(ObjectDeserializer op) { op.add(Builder::count, JsonpDeserializer.integerDeserializer(), "count"); - op.add(Builder::flavor, JsonpDeserializer.stringDeserializer(), "flavor"); op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type"); } diff --git a/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java b/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java index 4aac7cb5ca..f5f0c682de 100644 --- a/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java +++ b/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java @@ -22,6 +22,8 @@ import org.opensearch.client.opensearch._types.HealthStatus; import org.opensearch.client.opensearch._types.Level; import org.opensearch.client.opensearch._types.OpenSearchException; +import org.opensearch.client.opensearch.cluster.ClusterStatsRequest; +import org.opensearch.client.opensearch.cluster.ClusterStatsResponse; import org.opensearch.client.opensearch.cluster.GetClusterSettingsRequest; import org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse; import org.opensearch.client.opensearch.cluster.HealthRequest; @@ -300,4 +302,15 @@ public void testClusterHealthNotFoundIndex() throws IOException { assertNotNull(e); } } + + public void testClusterStats() throws IOException { + OpenSearchClient openSearchClient = javaClient(); + javaClient().indices().create(b -> b.index("index")); + ClusterStatsRequest request = new ClusterStatsRequest.Builder().build(); + ClusterStatsResponse response = openSearchClient.cluster().stats(request); + assertNotNull(response); + assertNotNull(response.clusterName()); + assertNotEquals(response.nodes().count().total(), 0); + assertNotEquals(response.indices().count(), 0); + } }