Skip to content

Commit

Permalink
Rename master to cluster_manager in the XContent Parser of ClusterHea…
Browse files Browse the repository at this point in the history
…lthResponse (#3432)

Signed-off-by: Tianli Feng <ftianli@amazon.com>
(cherry picked from commit 0b77055)
  • Loading branch information
Tianli Feng authored and github-actions[bot] committed May 25, 2022
1 parent 9f403ae commit 87a61c5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
private static final String TIMED_OUT = "timed_out";
private static final String NUMBER_OF_NODES = "number_of_nodes";
private static final String NUMBER_OF_DATA_NODES = "number_of_data_nodes";
@Deprecated
private static final String DISCOVERED_MASTER = "discovered_master";
private static final String DISCOVERED_CLUSTER_MANAGER = "discovered_cluster_manager";
private static final String NUMBER_OF_PENDING_TASKS = "number_of_pending_tasks";
Expand All @@ -95,6 +96,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
// ClusterStateHealth fields
int numberOfNodes = (int) parsedObjects[i++];
int numberOfDataNodes = (int) parsedObjects[i++];
boolean hasDiscoveredMaster = Boolean.TRUE.equals(parsedObjects[i++]);
boolean hasDiscoveredClusterManager = Boolean.TRUE.equals(parsedObjects[i++]);
int activeShards = (int) parsedObjects[i++];
int relocatingShards = (int) parsedObjects[i++];
Expand Down Expand Up @@ -123,7 +125,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
unassignedShards,
numberOfNodes,
numberOfDataNodes,
hasDiscoveredClusterManager,
hasDiscoveredClusterManager || hasDiscoveredMaster,
activeShardsPercent,
status,
indices
Expand Down Expand Up @@ -157,6 +159,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_NODES));
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_DATA_NODES));
PARSER.declareBoolean(optionalConstructorArg(), new ParseField(DISCOVERED_MASTER));
PARSER.declareBoolean(optionalConstructorArg(), new ParseField(DISCOVERED_CLUSTER_MANAGER));
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 @@ -58,7 +58,7 @@ public final class ClusterStateHealth implements Iterable<ClusterIndexHealth>, W

private final int numberOfNodes;
private final int numberOfDataNodes;
private final boolean hasDiscoveredMaster;
private final boolean hasDiscoveredClusterManager;
private final int activeShards;
private final int relocatingShards;
private final int activePrimaryShards;
Expand Down Expand Up @@ -86,7 +86,7 @@ public ClusterStateHealth(final ClusterState clusterState) {
public ClusterStateHealth(final ClusterState clusterState, final String[] concreteIndices) {
numberOfNodes = clusterState.nodes().getSize();
numberOfDataNodes = clusterState.nodes().getDataNodes().size();
hasDiscoveredMaster = clusterState.nodes().getMasterNodeId() != null;
hasDiscoveredClusterManager = clusterState.nodes().getMasterNodeId() != null;
indices = new HashMap<>();
for (String index : concreteIndices) {
IndexRoutingTable indexRoutingTable = clusterState.routingTable().index(index);
Expand Down Expand Up @@ -155,9 +155,9 @@ public ClusterStateHealth(final StreamInput in) throws IOException {
numberOfNodes = in.readVInt();
numberOfDataNodes = in.readVInt();
if (in.getVersion().onOrAfter(Version.V_1_0_0)) {
hasDiscoveredMaster = in.readBoolean();
hasDiscoveredClusterManager = in.readBoolean();
} else {
hasDiscoveredMaster = true;
hasDiscoveredClusterManager = true;
}
status = ClusterHealthStatus.fromValue(in.readByte());
int size = in.readVInt();
Expand All @@ -180,7 +180,7 @@ public ClusterStateHealth(
int unassignedShards,
int numberOfNodes,
int numberOfDataNodes,
boolean hasDiscoveredMaster,
boolean hasDiscoveredClusterManager,
double activeShardsPercent,
ClusterHealthStatus status,
Map<String, ClusterIndexHealth> indices
Expand All @@ -192,7 +192,7 @@ public ClusterStateHealth(
this.unassignedShards = unassignedShards;
this.numberOfNodes = numberOfNodes;
this.numberOfDataNodes = numberOfDataNodes;
this.hasDiscoveredMaster = hasDiscoveredMaster;
this.hasDiscoveredClusterManager = hasDiscoveredClusterManager;
this.activeShardsPercent = activeShardsPercent;
this.status = status;
this.indices = indices;
Expand Down Expand Up @@ -239,7 +239,7 @@ public double getActiveShardsPercent() {
}

public boolean hasDiscoveredMaster() {
return hasDiscoveredMaster;
return hasDiscoveredClusterManager;
}

@Override
Expand All @@ -257,7 +257,7 @@ public void writeTo(final StreamOutput out) throws IOException {
out.writeVInt(numberOfNodes);
out.writeVInt(numberOfDataNodes);
if (out.getVersion().onOrAfter(Version.V_1_0_0)) {
out.writeBoolean(hasDiscoveredMaster);
out.writeBoolean(hasDiscoveredClusterManager);
}
out.writeByte(status.value());
out.writeVInt(indices.size());
Expand All @@ -274,8 +274,8 @@ public String toString() {
+ numberOfNodes
+ ", numberOfDataNodes="
+ numberOfDataNodes
+ ", hasDiscoveredMaster="
+ hasDiscoveredMaster
+ ", hasDiscoveredClusterManager="
+ hasDiscoveredClusterManager
+ ", activeShards="
+ activeShards
+ ", relocatingShards="
Expand All @@ -302,7 +302,7 @@ public boolean equals(Object o) {
ClusterStateHealth that = (ClusterStateHealth) o;
return numberOfNodes == that.numberOfNodes
&& numberOfDataNodes == that.numberOfDataNodes
&& hasDiscoveredMaster == that.hasDiscoveredMaster
&& hasDiscoveredClusterManager == that.hasDiscoveredClusterManager
&& activeShards == that.activeShards
&& relocatingShards == that.relocatingShards
&& activePrimaryShards == that.activePrimaryShards
Expand All @@ -318,7 +318,7 @@ public int hashCode() {
return Objects.hash(
numberOfNodes,
numberOfDataNodes,
hasDiscoveredMaster,
hasDiscoveredClusterManager,
activeShards,
relocatingShards,
activePrimaryShards,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ ClusterHealthResponse maybeSerialize(ClusterHealthResponse clusterHealth) throws
return clusterHealth;
}

public void testParseFromXContentWithDiscoveredMasterField() throws IOException {
public void testParseFromXContentWithDiscoveredClusterManagerField() 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,\"discovered_master\":true,"
+ "\"timed_out\":false,\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_cluster_manager\":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,"
Expand All @@ -244,7 +244,7 @@ public void testParseFromXContentWithDiscoveredMasterField() throws IOException
}
}

public void testParseFromXContentWithoutDiscoveredMasterField() throws IOException {
public void testParseFromXContentWithoutDiscoveredClusterManagerField() throws IOException {
try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
Expand All @@ -265,6 +265,44 @@ public void testParseFromXContentWithoutDiscoveredMasterField() throws IOExcepti
}
}

/**
* Validate the ClusterHealthResponse can be parsed from JsonXContent that contains the deprecated "discovered_master" field.
* As of 2.0, to support inclusive language, "discovered_master" field will be replaced by "discovered_cluster_manager".
*/
public void testParseFromXContentWithDeprecatedDiscoveredMasterField() throws IOException {
try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
"{\"cluster_name\":\"opensearch-cluster\",\"status\":\"green\",\"timed_out\":false,"
+ "\"number_of_nodes\":6,\"number_of_data_nodes\":3,\"discovered_cluster_manager\":true,\"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);
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(true));
}

try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
"{\"cluster_name\":\"opensearch-cluster\",\"status\":\"green\","
+ "\"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);
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(true));
}
}

@Override
protected ClusterHealthResponse doParseInstance(XContentParser parser) {
return ClusterHealthResponse.fromXContent(parser);
Expand Down

0 comments on commit 87a61c5

Please sign in to comment.