Skip to content

Commit

Permalink
Make discovered_master field optional on the client to support compat…
Browse files Browse the repository at this point in the history
…ibility for opensearch client with odfe (opensearch-project#2641)

Signed-off-by: Mohit Godwani <[email protected]>
  • Loading branch information
mgodwan authored Mar 29, 2022
1 parent fb5cebb commit ec4fe70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
// ClusterStateHealth fields
int numberOfNodes = (int) parsedObjects[i++];
int numberOfDataNodes = (int) parsedObjects[i++];
boolean hasDiscoveredMaster = (boolean) parsedObjects[i++];
boolean hasDiscoveredMaster = Boolean.TRUE.equals(parsedObjects[i++]);
int activeShards = (int) parsedObjects[i++];
int relocatingShards = (int) parsedObjects[i++];
int activePrimaryShards = (int) parsedObjects[i++];
Expand Down Expand Up @@ -151,7 +151,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
// ClusterStateHealth fields
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_NODES));
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_DATA_NODES));
PARSER.declareBoolean(constructorArg(), new ParseField(DISCOVERED_MASTER));
PARSER.declareBoolean(optionalConstructorArg(), new ParseField(DISCOVERED_MASTER));
PARSER.declareInt(constructorArg(), new ParseField(ACTIVE_SHARDS));
PARSER.declareInt(constructorArg(), new ParseField(RELOCATING_SHARDS));
PARSER.declareInt(constructorArg(), new ParseField(ACTIVE_PRIMARY_SHARDS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,35 @@ public void testParseFromXContentWithDiscoveredMasterField() throws IOException
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
"{\"cluster_name\":\"535799904437:7-1-3-node\",\"status\":\"green\","
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_master\":false,"
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_master\":true,"
+ "\"active_primary_shards\":4,\"active_shards\":5,\"relocating_shards\":0,\"initializing_shards\":0,"
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,\"number_of_pending_tasks\":0,"
+ "\"number_of_in_flight_fetch\":0,\"task_max_waiting_in_queue_millis\":0,"
+ "\"active_shards_percent_as_number\":100}"
)
) {

ClusterHealthResponse clusterHealth = ClusterHealthResponse.fromXContent(parser);
assertNotNull(clusterHealth);
assertThat(clusterHealth.getClusterName(), Matchers.equalTo("535799904437:7-1-3-node"));
assertThat(clusterHealth.getNumberOfNodes(), Matchers.equalTo(6));
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(true));
}
}

public void testParseFromXContentWithoutDiscoveredMasterField() throws IOException {
try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
"{\"cluster_name\":\"535799904437:7-1-3-node\",\"status\":\"green\","
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,"
+ "\"active_primary_shards\":4,\"active_shards\":5,\"relocating_shards\":0,\"initializing_shards\":0,"
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,\"number_of_pending_tasks\":0,"
+ "\"number_of_in_flight_fetch\":0,\"task_max_waiting_in_queue_millis\":0,"
+ "\"active_shards_percent_as_number\":100}"
)
) {
ClusterHealthResponse clusterHealth = ClusterHealthResponse.fromXContent(parser);
assertNotNull(clusterHealth);
assertThat(clusterHealth.getClusterName(), Matchers.equalTo("535799904437:7-1-3-node"));
Expand Down

0 comments on commit ec4fe70

Please sign in to comment.