This is an automated email from the ASF dual-hosted git repository.
sammichen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new d716bf4 HDDS-5402 Support list node based on NodeOperationalState and
NodeState options in printTopology CLI (#2645)
d716bf4 is described below
commit d716bf47ac165e7bfb0d79a9edadecb826638eec
Author: cchenax <[email protected]>
AuthorDate: Thu Sep 16 09:52:38 2021 +0800
HDDS-5402 Support list node based on NodeOperationalState and NodeState
options in printTopology CLI (#2645)
---
.../hadoop/hdds/scm/cli/TopologySubcommand.java | 46 +++++++++++++++++++++-
.../dist/src/main/smoketest/topology/cli.robot | 6 +++
2 files changed, 50 insertions(+), 2 deletions(-)
diff --git
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/TopologySubcommand.java
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/TopologySubcommand.java
index e6888b8..4714761 100644
---
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/TopologySubcommand.java
+++
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/TopologySubcommand.java
@@ -23,8 +23,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.InvalidPropertiesFormatException;
import java.util.List;
import java.util.TreeSet;
+import java.util.stream.Collectors;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.cli.OzoneAdmin;
@@ -68,6 +70,18 @@ public class TopologySubcommand extends ScmSubcommand
description = "Print Topology with full node infos")
private boolean fullInfo;
+ @CommandLine.Option(names = {"--operational-state"},
+ description = "Only show datanodes in a specific operational state " +
+ "(IN_SERVICE, DECOMMISSIONING, " +
+ "DECOMMISSIONED, ENTERING_MAINTENANCE, " +
+ "IN_MAINTENANCE)")
+ private String nodeOperationalState;
+
+ @CommandLine.Option(names = {"--node-state"},
+ description = "Only show datanodes in a specific node state(" +
+ " HEALTHY, STALE, DEAD)")
+ private String nodeState;
+
@Override
public void execute(ScmClient scmClient) throws IOException {
for (HddsProtos.NodeState state : STATES) {
@@ -76,6 +90,35 @@ public class TopologySubcommand extends ScmSubcommand
if (nodes != null && nodes.size() > 0) {
// show node state
System.out.println("State = " + state.toString());
+ if (nodeOperationalState != null) {
+ if (nodeOperationalState.equals("IN_SERVICE") ||
+ nodeOperationalState.equals("DECOMMISSIONING") ||
+ nodeOperationalState.equals("DECOMMISSIONED") ||
+ nodeOperationalState.equals("ENTERING_MAINTENANCE") ||
+ nodeOperationalState.equals("IN_MAINTENANCE")) {
+ nodes = nodes.stream().filter(
+ info -> info.getNodeOperationalStates(0).toString()
+
.equals(nodeOperationalState)).collect(Collectors.toList());
+ } else {
+ throw new InvalidPropertiesFormatException(
+ "the nodeOperationalState isn't " +
+ "IN_SERVICE/DECOMMISSIONING/DECOMMISSIONED/" +
+ "ENTERING_MAINTENANCE/IN_MAINTENANCE " +
+ "the nodeOperationalState is " + nodeState);
+ }
+ }
+ if (nodeState != null) {
+ if (nodeState.equals("HEALTHY")
+ || nodeState.equals("STALE")
+ || nodeState.equals("DEAD")) {
+ nodes = nodes.stream().filter(
+ info -> info.getNodeStates(0).toString()
+ .equals(nodeState)).collect(Collectors.toList());
+ } else {
+ throw new InvalidPropertiesFormatException("the nodeState isn't " +
+ "HEALTHY/STALE/DEAD the nodeState is " + nodeState);
+ }
+ }
if (order) {
printOrderedByLocation(nodes);
} else {
@@ -98,7 +141,6 @@ public class TopologySubcommand extends ScmSubcommand
new HashMap<>();
HashMap<DatanodeDetails, HddsProtos.NodeOperationalState> state =
new HashMap<>();
-
for (HddsProtos.Node node : nodes) {
String location = node.getNodeID().getNetworkLocation();
if (location != null && !tree.containsKey(location)) {
@@ -115,7 +157,7 @@ public class TopologySubcommand extends ScmSubcommand
System.out.println("Location: " + location);
tree.get(location).forEach(n -> {
System.out.println(" " + n.getIpAddress() + "(" + n.getHostName()
- + ") "+state.get(n));
+ + ") " + state.get(n));
});
});
}
diff --git a/hadoop-ozone/dist/src/main/smoketest/topology/cli.robot
b/hadoop-ozone/dist/src/main/smoketest/topology/cli.robot
index bbe7a1b..3af6fd1 100644
--- a/hadoop-ozone/dist/src/main/smoketest/topology/cli.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/topology/cli.robot
@@ -31,3 +31,9 @@ Run printTopology -o
${output} = Execute ozone admin printTopology -o
Should contain ${output} Location: /rack2
Should contain ${output}
10.5.0.7(ozone-topology_datanode_4_1.ozone-topology_net) IN_SERVICE
+Run printTopology --operational-state IN_SERVICE
+ ${output} = Execute ozone admin printTopology
--operational-state IN_SERVICE
+ Should contain ${output}
10.5.0.7(ozone-topology_datanode_4_1.ozone-topology_net) IN_SERVICE /rack2
+Run printTopology --node-state HEALTHY
+ ${output} = Execute ozone admin printTopology
--node-state HEALTHY
+ Should contain ${output}
10.5.0.7(ozone-topology_datanode_4_1.ozone-topology_net) IN_SERVICE /rack2
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]