hanishakoneru commented on a change in pull request #2491:
URL: https://github.com/apache/ozone/pull/2491#discussion_r745165171



##########
File path: 
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
##########
@@ -697,4 +701,78 @@ public static String normalizeKey(String keyName,
     }
     return omHosts;
   }
+
+  /**
+   * Get a list of all OM details (address and ports) from the specified 
config.
+   */
+  public static List<OMNodeDetails> getAllOMAddresses(OzoneConfiguration conf,
+      String omServiceId, String currentOMNodeId) {
+
+    List<OMNodeDetails> omNodesList = new ArrayList<>();
+    Collection<String> omNodeIds = OmUtils.getOMNodeIds(conf, omServiceId);
+
+    String rpcAddrStr, hostAddr, httpAddr, httpsAddr;
+    int rpcPort, ratisPort;
+    if (omNodeIds.size() == 0) {
+      //Check if it is non-HA cluster
+      rpcAddrStr = OmUtils.getOmRpcAddress(conf, OZONE_OM_ADDRESS_KEY);
+      if (rpcAddrStr == null || rpcAddrStr.isEmpty()) {
+        return omNodesList;
+      }
+      hostAddr = HddsUtils.getHostName(rpcAddrStr).orElse(null);
+      rpcPort = HddsUtils.getHostPort(rpcAddrStr).orElse(0);
+      ratisPort = conf.getInt(OZONE_OM_RATIS_PORT_KEY,
+          OZONE_OM_RATIS_PORT_DEFAULT);
+      httpAddr = OmUtils.getHttpAddressForOMPeerNode(conf,
+          null, null, hostAddr);
+      httpsAddr = OmUtils.getHttpsAddressForOMPeerNode(conf,
+          null, null, hostAddr);
+
+      omNodesList.add(new OMNodeDetails.Builder()
+          .setOMNodeId(currentOMNodeId)
+          .setHostAddress(hostAddr)
+          .setRpcPort(rpcPort)
+          .setRatisPort(ratisPort)
+          .setHttpAddress(httpAddr)
+          .setHttpsAddress(httpsAddr)
+          .build());
+      return omNodesList;
+    }
+
+    for (String nodeId : omNodeIds) {
+      try {
+        OMNodeDetails omNodeDetails = OMNodeDetails.getOMNodeDetailsFromConf(
+            conf, omServiceId, nodeId);
+        omNodesList.add(omNodeDetails);
+      } catch (IOException e) {
+        String omRpcAddressStr = OMNodeDetails.getOMNodeAddressFromConf(conf,
+            omServiceId, nodeId);
+        LOG.error("OM {} is present in config file but it's address {} could " 
+
+            "not be resolved. Hence, OM {} is not added to list of peer 
nodes.",
+            nodeId, omRpcAddressStr, nodeId);
+      }
+    }
+
+    return omNodesList;
+  }
+
+  public static String getOMAddressListPrintString(List<OMNodeDetails> omList) 
{

Review comment:
       Done.




-- 
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]

Reply via email to