Skip to content

Commit 87a61c5

Browse files
Tianli Fenggithub-actions[bot]
authored andcommitted
Rename master to cluster_manager in the XContent Parser of ClusterHealthResponse (#3432)
Signed-off-by: Tianli Feng <ftianli@amazon.com> (cherry picked from commit 0b77055)
1 parent 9f403ae commit 87a61c5

3 files changed

Lines changed: 57 additions & 16 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
7171
private static final String TIMED_OUT = "timed_out";
7272
private static final String NUMBER_OF_NODES = "number_of_nodes";
7373
private static final String NUMBER_OF_DATA_NODES = "number_of_data_nodes";
74+
@Deprecated
7475
private static final String DISCOVERED_MASTER = "discovered_master";
7576
private static final String DISCOVERED_CLUSTER_MANAGER = "discovered_cluster_manager";
7677
private static final String NUMBER_OF_PENDING_TASKS = "number_of_pending_tasks";
@@ -95,6 +96,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
9596
// ClusterStateHealth fields
9697
int numberOfNodes = (int) parsedObjects[i++];
9798
int numberOfDataNodes = (int) parsedObjects[i++];
99+
boolean hasDiscoveredMaster = Boolean.TRUE.equals(parsedObjects[i++]);
98100
boolean hasDiscoveredClusterManager = Boolean.TRUE.equals(parsedObjects[i++]);
99101
int activeShards = (int) parsedObjects[i++];
100102
int relocatingShards = (int) parsedObjects[i++];
@@ -123,7 +125,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
123125
unassignedShards,
124126
numberOfNodes,
125127
numberOfDataNodes,
126-
hasDiscoveredClusterManager,
128+
hasDiscoveredClusterManager || hasDiscoveredMaster,
127129
activeShardsPercent,
128130
status,
129131
indices
@@ -157,6 +159,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
157159
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_NODES));
158160
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_DATA_NODES));
159161
PARSER.declareBoolean(optionalConstructorArg(), new ParseField(DISCOVERED_MASTER));
162+
PARSER.declareBoolean(optionalConstructorArg(), new ParseField(DISCOVERED_CLUSTER_MANAGER));
160163
PARSER.declareInt(constructorArg(), new ParseField(ACTIVE_SHARDS));
161164
PARSER.declareInt(constructorArg(), new ParseField(RELOCATING_SHARDS));
162165
PARSER.declareInt(constructorArg(), new ParseField(ACTIVE_PRIMARY_SHARDS));

server/src/main/java/org/opensearch/cluster/health/ClusterStateHealth.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public final class ClusterStateHealth implements Iterable<ClusterIndexHealth>, W
5858

5959
private final int numberOfNodes;
6060
private final int numberOfDataNodes;
61-
private final boolean hasDiscoveredMaster;
61+
private final boolean hasDiscoveredClusterManager;
6262
private final int activeShards;
6363
private final int relocatingShards;
6464
private final int activePrimaryShards;
@@ -86,7 +86,7 @@ public ClusterStateHealth(final ClusterState clusterState) {
8686
public ClusterStateHealth(final ClusterState clusterState, final String[] concreteIndices) {
8787
numberOfNodes = clusterState.nodes().getSize();
8888
numberOfDataNodes = clusterState.nodes().getDataNodes().size();
89-
hasDiscoveredMaster = clusterState.nodes().getMasterNodeId() != null;
89+
hasDiscoveredClusterManager = clusterState.nodes().getMasterNodeId() != null;
9090
indices = new HashMap<>();
9191
for (String index : concreteIndices) {
9292
IndexRoutingTable indexRoutingTable = clusterState.routingTable().index(index);
@@ -155,9 +155,9 @@ public ClusterStateHealth(final StreamInput in) throws IOException {
155155
numberOfNodes = in.readVInt();
156156
numberOfDataNodes = in.readVInt();
157157
if (in.getVersion().onOrAfter(Version.V_1_0_0)) {
158-
hasDiscoveredMaster = in.readBoolean();
158+
hasDiscoveredClusterManager = in.readBoolean();
159159
} else {
160-
hasDiscoveredMaster = true;
160+
hasDiscoveredClusterManager = true;
161161
}
162162
status = ClusterHealthStatus.fromValue(in.readByte());
163163
int size = in.readVInt();
@@ -180,7 +180,7 @@ public ClusterStateHealth(
180180
int unassignedShards,
181181
int numberOfNodes,
182182
int numberOfDataNodes,
183-
boolean hasDiscoveredMaster,
183+
boolean hasDiscoveredClusterManager,
184184
double activeShardsPercent,
185185
ClusterHealthStatus status,
186186
Map<String, ClusterIndexHealth> indices
@@ -192,7 +192,7 @@ public ClusterStateHealth(
192192
this.unassignedShards = unassignedShards;
193193
this.numberOfNodes = numberOfNodes;
194194
this.numberOfDataNodes = numberOfDataNodes;
195-
this.hasDiscoveredMaster = hasDiscoveredMaster;
195+
this.hasDiscoveredClusterManager = hasDiscoveredClusterManager;
196196
this.activeShardsPercent = activeShardsPercent;
197197
this.status = status;
198198
this.indices = indices;
@@ -239,7 +239,7 @@ public double getActiveShardsPercent() {
239239
}
240240

241241
public boolean hasDiscoveredMaster() {
242-
return hasDiscoveredMaster;
242+
return hasDiscoveredClusterManager;
243243
}
244244

245245
@Override
@@ -257,7 +257,7 @@ public void writeTo(final StreamOutput out) throws IOException {
257257
out.writeVInt(numberOfNodes);
258258
out.writeVInt(numberOfDataNodes);
259259
if (out.getVersion().onOrAfter(Version.V_1_0_0)) {
260-
out.writeBoolean(hasDiscoveredMaster);
260+
out.writeBoolean(hasDiscoveredClusterManager);
261261
}
262262
out.writeByte(status.value());
263263
out.writeVInt(indices.size());
@@ -274,8 +274,8 @@ public String toString() {
274274
+ numberOfNodes
275275
+ ", numberOfDataNodes="
276276
+ numberOfDataNodes
277-
+ ", hasDiscoveredMaster="
278-
+ hasDiscoveredMaster
277+
+ ", hasDiscoveredClusterManager="
278+
+ hasDiscoveredClusterManager
279279
+ ", activeShards="
280280
+ activeShards
281281
+ ", relocatingShards="
@@ -302,7 +302,7 @@ public boolean equals(Object o) {
302302
ClusterStateHealth that = (ClusterStateHealth) o;
303303
return numberOfNodes == that.numberOfNodes
304304
&& numberOfDataNodes == that.numberOfDataNodes
305-
&& hasDiscoveredMaster == that.hasDiscoveredMaster
305+
&& hasDiscoveredClusterManager == that.hasDiscoveredClusterManager
306306
&& activeShards == that.activeShards
307307
&& relocatingShards == that.relocatingShards
308308
&& activePrimaryShards == that.activePrimaryShards
@@ -318,7 +318,7 @@ public int hashCode() {
318318
return Objects.hash(
319319
numberOfNodes,
320320
numberOfDataNodes,
321-
hasDiscoveredMaster,
321+
hasDiscoveredClusterManager,
322322
activeShards,
323323
relocatingShards,
324324
activePrimaryShards,

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ ClusterHealthResponse maybeSerialize(ClusterHealthResponse clusterHealth) throws
222222
return clusterHealth;
223223
}
224224

225-
public void testParseFromXContentWithDiscoveredMasterField() throws IOException {
225+
public void testParseFromXContentWithDiscoveredClusterManagerField() throws IOException {
226226
try (
227227
XContentParser parser = JsonXContent.jsonXContent.createParser(
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\":true,"
231+
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_cluster_manager\":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,"
@@ -244,7 +244,7 @@ public void testParseFromXContentWithDiscoveredMasterField() throws IOException
244244
}
245245
}
246246

247-
public void testParseFromXContentWithoutDiscoveredMasterField() throws IOException {
247+
public void testParseFromXContentWithoutDiscoveredClusterManagerField() throws IOException {
248248
try (
249249
XContentParser parser = JsonXContent.jsonXContent.createParser(
250250
NamedXContentRegistry.EMPTY,
@@ -265,6 +265,44 @@ public void testParseFromXContentWithoutDiscoveredMasterField() throws IOExcepti
265265
}
266266
}
267267

268+
/**
269+
* Validate the ClusterHealthResponse can be parsed from JsonXContent that contains the deprecated "discovered_master" field.
270+
* As of 2.0, to support inclusive language, "discovered_master" field will be replaced by "discovered_cluster_manager".
271+
*/
272+
public void testParseFromXContentWithDeprecatedDiscoveredMasterField() throws IOException {
273+
try (
274+
XContentParser parser = JsonXContent.jsonXContent.createParser(
275+
NamedXContentRegistry.EMPTY,
276+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
277+
"{\"cluster_name\":\"opensearch-cluster\",\"status\":\"green\",\"timed_out\":false,"
278+
+ "\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_cluster_manager\":true,\"discovered_master\":true,"
279+
+ "\"active_primary_shards\":4,\"active_shards\":5,\"relocating_shards\":0,\"initializing_shards\":0,"
280+
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,\"number_of_pending_tasks\":0,"
281+
+ "\"number_of_in_flight_fetch\":0,\"task_max_waiting_in_queue_millis\":0,"
282+
+ "\"active_shards_percent_as_number\":100}"
283+
)
284+
) {
285+
ClusterHealthResponse clusterHealth = ClusterHealthResponse.fromXContent(parser);
286+
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(true));
287+
}
288+
289+
try (
290+
XContentParser parser = JsonXContent.jsonXContent.createParser(
291+
NamedXContentRegistry.EMPTY,
292+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
293+
"{\"cluster_name\":\"opensearch-cluster\",\"status\":\"green\","
294+
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_master\":true,"
295+
+ "\"active_primary_shards\":4,\"active_shards\":5,\"relocating_shards\":0,\"initializing_shards\":0,"
296+
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,\"number_of_pending_tasks\":0,"
297+
+ "\"number_of_in_flight_fetch\":0,\"task_max_waiting_in_queue_millis\":0,"
298+
+ "\"active_shards_percent_as_number\":100}"
299+
)
300+
) {
301+
ClusterHealthResponse clusterHealth = ClusterHealthResponse.fromXContent(parser);
302+
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(true));
303+
}
304+
}
305+
268306
@Override
269307
protected ClusterHealthResponse doParseInstance(XContentParser parser) {
270308
return ClusterHealthResponse.fromXContent(parser);

0 commit comments

Comments
 (0)