Skip to content

Commit a56019a

Browse files
committed
Make discovered_master field optional on the client to support compatibility for opensearch client with odfe
Signed-off-by: Mohit Godwani <[email protected]>
1 parent 8f4aec1 commit a56019a

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
9090
// ClusterStateHealth fields
9191
int numberOfNodes = (int) parsedObjects[i++];
9292
int numberOfDataNodes = (int) parsedObjects[i++];
93-
boolean hasDiscoveredMaster = (boolean) parsedObjects[i++];
93+
boolean hasDiscoveredMaster = Boolean.TRUE.equals(parsedObjects[i++]);
9494
int activeShards = (int) parsedObjects[i++];
9595
int relocatingShards = (int) parsedObjects[i++];
9696
int activePrimaryShards = (int) parsedObjects[i++];
@@ -151,7 +151,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
151151
// ClusterStateHealth fields
152152
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_NODES));
153153
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_DATA_NODES));
154-
PARSER.declareBoolean(constructorArg(), new ParseField(DISCOVERED_MASTER));
154+
PARSER.declareBoolean(optionalConstructorArg(), new ParseField(DISCOVERED_MASTER));
155155
PARSER.declareInt(constructorArg(), new ParseField(ACTIVE_SHARDS));
156156
PARSER.declareInt(constructorArg(), new ParseField(RELOCATING_SHARDS));
157157
PARSER.declareInt(constructorArg(), new ParseField(ACTIVE_PRIMARY_SHARDS));

server/src/test/java/org/opensearch/action/admin/cluster/health/ClusterHealthResponsesTests.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,35 @@ public void testParseFromXContentWithDiscoveredMasterField() throws IOException
228228
NamedXContentRegistry.EMPTY,
229229
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
230230
"{\"cluster_name\":\"535799904437:7-1-3-node\",\"status\":\"green\","
231-
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_master\":false,"
231+
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_master\":true,"
232232
+ "\"active_primary_shards\":4,\"active_shards\":5,\"relocating_shards\":0,\"initializing_shards\":0,"
233233
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,\"number_of_pending_tasks\":0,"
234234
+ "\"number_of_in_flight_fetch\":0,\"task_max_waiting_in_queue_millis\":0,"
235235
+ "\"active_shards_percent_as_number\":100}"
236236
)
237237
) {
238238

239+
ClusterHealthResponse clusterHealth = ClusterHealthResponse.fromXContent(parser);
240+
assertNotNull(clusterHealth);
241+
assertThat(clusterHealth.getClusterName(), Matchers.equalTo("535799904437:7-1-3-node"));
242+
assertThat(clusterHealth.getNumberOfNodes(), Matchers.equalTo(6));
243+
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(true));
244+
}
245+
}
246+
247+
public void testParseFromXContentWithoutDiscoveredMasterField() throws IOException {
248+
try (
249+
XContentParser parser = JsonXContent.jsonXContent.createParser(
250+
NamedXContentRegistry.EMPTY,
251+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
252+
"{\"cluster_name\":\"535799904437:7-1-3-node\",\"status\":\"green\","
253+
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,"
254+
+ "\"active_primary_shards\":4,\"active_shards\":5,\"relocating_shards\":0,\"initializing_shards\":0,"
255+
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,\"number_of_pending_tasks\":0,"
256+
+ "\"number_of_in_flight_fetch\":0,\"task_max_waiting_in_queue_millis\":0,"
257+
+ "\"active_shards_percent_as_number\":100}"
258+
)
259+
) {
239260
ClusterHealthResponse clusterHealth = ClusterHealthResponse.fromXContent(parser);
240261
assertNotNull(clusterHealth);
241262
assertThat(clusterHealth.getClusterName(), Matchers.equalTo("535799904437:7-1-3-node"));

0 commit comments

Comments
 (0)