Skip to content

Commit

Permalink
Fixing cluster stats response for role types and adding search role t…
Browse files Browse the repository at this point in the history
…ype (opensearch-project#848)

* Fixing cluster stats response for role types and adding search role type

Signed-off-by: Vacha Shah <[email protected]>

* Add CHANGELOG

Signed-off-by: Vacha Shah <[email protected]>

---------

Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah authored Feb 15, 2024
1 parent fa5919d commit 638d9b9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 210 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
## [Unreleased 2.x]

### Added
- Add search role type for nodes in cluster stats ([#848](https://github.com/opensearch-project/opensearch-java/pull/848))

### Dependencies

Expand All @@ -48,6 +49,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
### Removed

### Fixed
- Fix ClusterStatsResponse field deserialization ([#848](https://github.com/opensearch-project/opensearch-java/pull/848))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// ---------------------------------------------------------------------------------------------

Expand All @@ -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<Builder, ObjectBuilder<ClusterNodeCount>> fn) {
Expand Down Expand Up @@ -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}
*/
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}

}

Expand All @@ -276,24 +184,9 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<C

private Integer total;

private Integer votingOnly;

private Integer dataCold;

@Nullable
private Integer dataFrozen;

private Integer dataContent;

private Integer dataWarm;

private Integer dataHot;

private Integer ml;

private Integer remoteClusterClient;

private Integer transform;
private Integer search;

/**
* Required - API name: {@code coordinating_only}
Expand Down Expand Up @@ -335,62 +228,6 @@ public final Builder total(int value) {
return this;
}

/**
* Required - API name: {@code voting_only}
*/
public final Builder votingOnly(int value) {
this.votingOnly = value;
return this;
}

/**
* Required - API name: {@code data_cold}
*/
public final Builder dataCold(int value) {
this.dataCold = value;
return this;
}

/**
* API name: {@code data_frozen}
*/
public final Builder dataFrozen(@Nullable Integer value) {
this.dataFrozen = value;
return this;
}

/**
* Required - API name: {@code data_content}
*/
public final Builder dataContent(int value) {
this.dataContent = value;
return this;
}

/**
* Required - API name: {@code data_warm}
*/
public final Builder dataWarm(int value) {
this.dataWarm = value;
return this;
}

/**
* Required - API name: {@code data_hot}
*/
public final Builder dataHot(int value) {
this.dataHot = value;
return this;
}

/**
* Required - API name: {@code ml}
*/
public final Builder ml(int value) {
this.ml = value;
return this;
}

/**
* Required - API name: {@code remote_cluster_client}
*/
Expand All @@ -400,10 +237,11 @@ public final Builder remoteClusterClient(int value) {
}

/**
* Required - API name: {@code transform}
* API name: {@code search}
*/
public final Builder transform(int value) {
this.transform = value;
@Nullable
public final Builder search(int value) {
this.search = value;
return this;
}

Expand Down Expand Up @@ -437,15 +275,8 @@ protected static void setupClusterNodeCountDeserializer(ObjectDeserializer<Clust
op.add(Builder::ingest, JsonpDeserializer.integerDeserializer(), "ingest");
op.add(Builder::clusterManager, JsonpDeserializer.integerDeserializer(), "cluster_manager");
op.add(Builder::total, JsonpDeserializer.integerDeserializer(), "total");
op.add(Builder::votingOnly, JsonpDeserializer.integerDeserializer(), "voting_only");
op.add(Builder::dataCold, JsonpDeserializer.integerDeserializer(), "data_cold");
op.add(Builder::dataFrozen, JsonpDeserializer.integerDeserializer(), "data_frozen");
op.add(Builder::dataContent, JsonpDeserializer.integerDeserializer(), "data_content");
op.add(Builder::dataWarm, JsonpDeserializer.integerDeserializer(), "data_warm");
op.add(Builder::dataHot, JsonpDeserializer.integerDeserializer(), "data_hot");
op.add(Builder::ml, JsonpDeserializer.integerDeserializer(), "ml");
op.add(Builder::remoteClusterClient, JsonpDeserializer.integerDeserializer(), "remote_cluster_client");
op.add(Builder::transform, JsonpDeserializer.integerDeserializer(), "transform");
op.add(Builder::search, JsonpDeserializer.integerDeserializer(), "search");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@
public class NodePackagingType implements JsonpSerializable {
private final int count;

private final String flavor;

private final String type;

// ---------------------------------------------------------------------------------------------

private NodePackagingType(Builder builder) {

this.count = ApiTypeHelper.requireNonNull(builder.count, this, "count");
this.flavor = ApiTypeHelper.requireNonNull(builder.flavor, this, "flavor");
this.type = ApiTypeHelper.requireNonNull(builder.type, this, "type");

}
Expand All @@ -75,13 +72,6 @@ public final int count() {
return this.count;
}

/**
* Required - API name: {@code flavor}
*/
public final String flavor() {
return this.flavor;
}

/**
* Required - API name: {@code type}
*/
Expand All @@ -103,9 +93,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("count");
generator.write(this.count);

generator.writeKey("flavor");
generator.write(this.flavor);

generator.writeKey("type");
generator.write(this.type);

Expand All @@ -120,8 +107,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<NodePackagingType> {
private Integer count;

private String flavor;

private String type;

/**
Expand All @@ -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}
*/
Expand Down Expand Up @@ -174,7 +151,6 @@ public NodePackagingType build() {
protected static void setupNodePackagingTypeDeserializer(ObjectDeserializer<NodePackagingType.Builder> op) {

op.add(Builder::count, JsonpDeserializer.integerDeserializer(), "count");
op.add(Builder::flavor, JsonpDeserializer.stringDeserializer(), "flavor");
op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 638d9b9

Please sign in to comment.