From ccd06fec16bae7da97bc4f61c45d4b471dccebc4 Mon Sep 17 00:00:00 2001 From: kamisamak <1057372918@qq.com> Date: Tue, 29 Dec 2020 21:03:36 -0600 Subject: [PATCH] [Fix][common] only two yarns can be selected(#4314) (#4344) --- .../common/utils/HadoopUtils.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java index a0c2bf4e58..8fa8d72236 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java @@ -649,27 +649,25 @@ public class HadoopUtils implements Closeable { String yarnUrl = "http://%s:" + activeResourceManagerPort + "/ws/v1/cluster/info"; - String state = null; try { + /** - * send http get request to rm1 + * send http get request to rm */ - state = getRMState(String.format(yarnUrl, rmIdArr[0])); - if (Constants.HADOOP_RM_STATE_ACTIVE.equals(state)) { - return rmIdArr[0]; - } else if (Constants.HADOOP_RM_STATE_STANDBY.equals(state)) { - state = getRMState(String.format(yarnUrl, rmIdArr[1])); + for (String rmId : rmIdArr) { + String state = getRMState(String.format(yarnUrl, rmId)); if (Constants.HADOOP_RM_STATE_ACTIVE.equals(state)) { - return rmIdArr[1]; + return rmId; } - } else { - return null; } + } catch (Exception e) { - state = getRMState(String.format(yarnUrl, rmIdArr[1])); - if (Constants.HADOOP_RM_STATE_ACTIVE.equals(state)) { - return rmIdArr[0]; + for (int i = 1; i < rmIdArr.length; i++) { + String state = getRMState(String.format(yarnUrl, rmIdArr[i])); + if (Constants.HADOOP_RM_STATE_ACTIVE.equals(state)) { + return rmIdArr[i]; + } } } return null;