RMAdminCLI extends HAAdmin { private int addToClusterNodeLabels(String args) throws IOException, YarnException { Set<String> labels = buildNodeLabelsSetFromStr(args); if (directlyAccessNodeLabelStore) { getNodeLabelManagerInstance(getConf()).addToCluserNodeLabels(labels); } else { ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol(); AddToClusterNodeLabelsRequest request = AddToClusterNodeLabelsRequest.newInstance(labels); adminProtocol.addToClusterNodeLabels(request); } return 0; } RMAdminCLI();  RMAdminCLI(Configuration conf); @Override int run(String[] args); @Override void setConf(Configuration conf); static void main(String[] args);  }
@Test public void testAddToClusterNodeLabels() throws Exception { String[] args = { "-addToClusterNodeLabels", "x", "-directlyAccessNodeLabelStore" }; assertEquals(0, rmAdminCLI.run(args)); assertTrue(dummyNodeLabelsManager.getClusterNodeLabels().containsAll( ImmutableSet.of("x"))); args = new String[] { "-addToClusterNodeLabels" }; assertTrue(0 != rmAdminCLI.run(args)); args = new String[] { "-addToClusterNodeLabels", "-directlyAccessNodeLabelStore" }; assertTrue(0 != rmAdminCLI.run(args)); args = new String[] { "-addToClusterNodeLabels", " " }; assertTrue(0 != rmAdminCLI.run(args)); args = new String[] { "-addToClusterNodeLabels", " , " }; assertTrue(0 != rmAdminCLI.run(args)); args = new String[] { "-addToClusterNodeLabels", ",x,,", "-directlyAccessNodeLabelStore" }; assertEquals(0, rmAdminCLI.run(args)); assertTrue(dummyNodeLabelsManager.getClusterNodeLabels().containsAll( ImmutableSet.of("x"))); }