Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Make discovered_master field optional on the client to support compatibility for OpenSearch client with ODFE #2652

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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