sadanand48 commented on code in PR #9611:
URL: https://github.com/apache/ozone/pull/9611#discussion_r2689399814
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/SafeModeCheckSubcommand.java:
##########
@@ -45,12 +71,106 @@ public void execute(ScmClient scmClient) throws
IOException {
System.out.println("SCM is out of safe mode.");
}
if (isVerbose()) {
- for (Map.Entry<String, Pair<Boolean, String>> entry :
- scmClient.getSafeModeRuleStatuses().entrySet()) {
- Pair<Boolean, String> value = entry.getValue();
- System.out.printf("validated:%s, %s, %s%n",
- value.getLeft(), entry.getKey(), value.getRight());
+ printSafeModeRules(scmClient.getSafeModeRuleStatuses());
+ }
+ }
+
+ private void executeForSpecificNodeInHA(ScmClient scmClient, String
serviceId) throws IOException {
+ String scmAddress = getScmOption().getScm();
+
+ System.out.println("Service ID: " + serviceId);
+
+ final OzoneConfiguration conf = getOzoneConf();
+
+ List<SCMNodeInfo> nodes = SCMNodeInfo.buildNodeInfo(conf);
+
+ // Find the node matching the --scm address
+ List<SCMNodeInfo> matchedNodes = nodes.stream()
+ .filter(node -> matchesAddress(node, scmAddress))
+ .collect(Collectors.toList());
+
+ if (matchedNodes.isEmpty()) {
+ throw new IOException("Specified --scm address " + scmAddress +
+ " does not match any node in service " + serviceId +
+ ". Available nodes: " + nodes.stream()
+ .map(n -> n.getScmClientAddress() + " [" + n.getNodeId() + "]")
+ .collect(Collectors.joining(", ")));
+ }
+
+ queryNode(scmClient, matchedNodes.get(0));
+ }
+
+ private void executeForAllNodes(ScmClient scmClient) throws IOException {
+ final OzoneConfiguration conf = getOzoneConf();
+ String serviceId = HddsUtils.getScmServiceId(conf);
+
+ if (serviceId == null) {
+ executeForSingleNode(scmClient);
+ return;
+ }
+
+ System.out.println("Service ID: " + serviceId);
+ List<SCMNodeInfo> nodes = SCMNodeInfo.buildNodeInfo(conf);
+
+ for (SCMNodeInfo node : nodes) {
+ queryNode(scmClient, node);
+ }
+ }
+
+ private void queryNode(ScmClient scmClient, SCMNodeInfo node) {
+ String nodeId = node.getNodeId();
+
+ try {
+ boolean inSafeMode = scmClient.inSafeModeForNode(nodeId);
+
+ System.out.printf("%s [%s]: %s%n",
+ node.getScmClientAddress(),
+ nodeId,
+ inSafeMode ? "IN SAFE MODE" : "OUT OF SAFE MODE");
+
+ if (isVerbose()) {
+ Map<String, Pair<Boolean, String>> rules =
scmClient.getSafeModeRuleStatusesForNode(nodeId);
+ if (rules != null && !rules.isEmpty()) {
+ printSafeModeRules(rules);
+ }
}
+ } catch (Exception e) {
+ System.out.printf("%s [%s]: ERROR: Failed to get safe mode status -
%s%n",
+ node.getScmClientAddress(), nodeId, e.getMessage());
+ }
+ }
+
+ /**
+ * Check if the given SCMNodeInfo matches the target address.
+ * Tries to match by direct string comparison and by resolved address.
+ */
+ private boolean matchesAddress(SCMNodeInfo node, String targetAddress) {
+ String nodeAddress = node.getScmClientAddress();
+
+ // Direct match
+ if (nodeAddress.equals(targetAddress)) {
+ return true;
+ }
+
+ // Try normalizing both addresses and comparing
+ try {
+ InetSocketAddress target = NetUtils.createSocketAddr(targetAddress);
+ InetSocketAddress nodeAddr = NetUtils.createSocketAddr(nodeAddress);
+
+ // Match by resolved IP and port
+ return target.getPort() == nodeAddr.getPort() &&
+ target.getAddress().equals(nodeAddr.getAddress());
+ } catch (Exception e) {
+ // If address resolution fails, no match
+ return false;
Review Comment:
nit : Log the exception here before returning false
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]