p-szucs commented on code in PR #7813: URL: https://github.com/apache/hadoop/pull/7813#discussion_r2228193192
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java: ########## @@ -107,17 +107,29 @@ public static void setNMWebAppHostNameAndPort(Configuration conf, */ public static <T, R> R execOnActiveRM(Configuration conf, ThrowingBiFunction<String, T, R> func, T arg) throws Exception { - int haIndex = 0; + int activeRMIndex = 0; + int rmCount = 1; + if (HAUtil.isHAEnabled(conf)) { + ArrayList<String> rmIds = (ArrayList<String>) HAUtil.getRMHAIds(conf); + rmCount = rmIds.size(); String activeRMId = RMHAUtils.findActiveRMHAId(conf); if (activeRMId != null) { - haIndex = new ArrayList<>(HAUtil.getRMHAIds(conf)).indexOf(activeRMId); - } else { - throw new ConnectException("No Active RM available"); + activeRMIndex = rmIds.indexOf(activeRMId); + } + } + + // In HA mode activeRMId can be fetched only if user have permission to check service states. + // Otherwise, we find the active one by iterating through the RMs + for (int i = activeRMIndex; i < rmCount; i++) { + try { + String rmAddress = getRMWebAppURLWithScheme(conf, i); + return func.apply(rmAddress, arg); + } catch (Exception e) { + // Ignore and try next RM if there are any Review Comment: Fixed -- 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: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org