YarnClientUtils { @VisibleForTesting static YarnConfiguration getYarnConfWithRmHaId(Configuration conf) throws IOException { YarnConfiguration yarnConf = new YarnConfiguration(conf); if (yarnConf.get(YarnConfiguration.RM_HA_ID) == null) { String[] rmIds = yarnConf.getStrings(YarnConfiguration.RM_HA_IDS); if ((rmIds != null) && (rmIds.length > 0)) { yarnConf.set(YarnConfiguration.RM_HA_ID, rmIds[0]); } else { throw new IOException("RM_HA_IDS property is not set for HA resource " + "manager"); } } return yarnConf; }  static String getRmPrincipal(Configuration conf); static String getRmPrincipal(String rmPrincipal, Configuration conf); static List<NodeLabel> buildNodeLabelsFromStr(String args); static String generateToken(String server); static final String NO_LABEL_ERR_MSG; }
@Test public void testGetYarnConfWithRmHaId() throws IOException { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_HA_ID, "rm0"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, false); YarnConfiguration result = YarnClientUtils.getYarnConfWithRmHaId(conf); assertSameConf(conf, result); assertEquals("RM_HA_ID was changed when it shouldn't have been: " + result.get(YarnConfiguration.RM_HA_ID), "rm0", result.get(YarnConfiguration.RM_HA_ID)); conf = new Configuration(); conf.set(YarnConfiguration.RM_HA_ID, "rm0"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); result = YarnClientUtils.getYarnConfWithRmHaId(conf); assertSameConf(conf, result); assertEquals("RM_HA_ID was changed when it shouldn't have been: " + result.get(YarnConfiguration.RM_HA_ID), "rm0", result.get(YarnConfiguration.RM_HA_ID)); conf = new Configuration(); conf.set(YarnConfiguration.RM_HA_IDS, "rm0,rm1"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); result = YarnClientUtils.getYarnConfWithRmHaId(conf); assertSameConf(conf, result); assertEquals("RM_HA_ID was not set correctly: " + result.get(YarnConfiguration.RM_HA_ID), "rm0", result.get(YarnConfiguration.RM_HA_ID)); conf = new Configuration(); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); try { YarnClientUtils.getYarnConfWithRmHaId(conf); fail("Allowed invalid HA configuration: HA is enabled, but no RM ID " + "is set"); } catch (IOException ex) { } }