YarnClientUtils { public static String getRmPrincipal(Configuration conf) throws IOException { String principal = conf.get(YarnConfiguration.RM_PRINCIPAL); String prepared = null; if (principal != null) { prepared = getRmPrincipal(principal, conf); } return prepared; }  static String getRmPrincipal(Configuration conf); static String getRmPrincipal(String rmPrincipal, Configuration conf); static List<NodeLabel> buildNodeLabelsFromStr(String args); static final String NO_LABEL_ERR_MSG; }
@Test public void testGetRMPrincipalStandAlone_Configuration() throws IOException { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS, "myhost"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, false); String result = YarnClientUtils.getRmPrincipal(conf); assertNull("The hostname translation did return null when the principal is " + "missing from the conf: " + result, result); conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS, "myhost"); conf.set(YarnConfiguration.RM_PRINCIPAL, "test/_HOST@REALM"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, false); result = YarnClientUtils.getRmPrincipal(conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/myhost@REALM", result); conf.set(YarnConfiguration.RM_PRINCIPAL, "test/yourhost@REALM"); result = YarnClientUtils.getRmPrincipal(conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/yourhost@REALM", result); }
@Test public void testGetRMPrincipalHA_Configuration() throws IOException { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS, "myhost"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); String result = YarnClientUtils.getRmPrincipal(conf); assertNull("The hostname translation did return null when the principal is " + "missing from the conf: " + result, result); conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS + ".rm0", "myhost"); conf.set(YarnConfiguration.RM_PRINCIPAL, "test/_HOST@REALM"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_IDS, "rm0"); result = YarnClientUtils.getRmPrincipal(conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/myhost@REALM", result); conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS + ".rm0", "myhost"); conf.set(YarnConfiguration.RM_PRINCIPAL, "test/_HOST@REALM"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); try { result = YarnClientUtils.getRmPrincipal(conf); fail("The hostname translation succeeded even though no RM ids were " + "set: " + result); } catch (IOException ex) { } conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS + ".rm0", "myhost"); conf.set(YarnConfiguration.RM_PRINCIPAL, "test/_HOST@REALM"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_ID, "rm0"); result = YarnClientUtils.getRmPrincipal(conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/myhost@REALM", result); conf.set(YarnConfiguration.RM_PRINCIPAL, "test/yourhost@REALM"); result = YarnClientUtils.getRmPrincipal(conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/yourhost@REALM", result); }
@Test public void testGetRMPrincipalStandAlone_String() throws IOException { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS, "myhost"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, false); String result = YarnClientUtils.getRmPrincipal("test/_HOST@REALM", conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/myhost@REALM", result); result = YarnClientUtils.getRmPrincipal("test/yourhost@REALM", conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/yourhost@REALM", result); try { result = YarnClientUtils.getRmPrincipal(null, conf); fail("The hostname translation succeeded even though the RM principal " + "was null: " + result); } catch (IllegalArgumentException ex) { } }
@Test public void testGetRMPrincipalHA_String() throws IOException { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS + ".rm0", "myhost"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_IDS, "rm0"); String result = YarnClientUtils.getRmPrincipal("test/_HOST@REALM", conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/myhost@REALM", result); try { result = YarnClientUtils.getRmPrincipal(null, conf); fail("The hostname translation succeeded even though the RM principal " + "was null: " + result); } catch (IllegalArgumentException ex) { } conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS + ".rm0", "myhost"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); try { YarnClientUtils.getRmPrincipal("test/_HOST@REALM", conf); fail("The hostname translation succeeded even though no RM ids were set"); } catch (IOException ex) { } conf = new Configuration(); conf.set(YarnConfiguration.RM_ADDRESS + ".rm0", "myhost"); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_ID, "rm0"); result = YarnClientUtils.getRmPrincipal("test/_HOST@REALM", conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/myhost@REALM", result); result = YarnClientUtils.getRmPrincipal("test/yourhost@REALM", conf); assertEquals("The hostname translation did not produce the expected " + "results: " + result, "test/yourhost@REALM", result); }