RMNodeLabelsManager extends CommonNodeLabelsManager { protected void checkRemoveFromClusterNodeLabelsOfQueue( Collection<String> labelsToRemove) throws IOException { for (String label : labelsToRemove) { label = normalizeLabel(label); for (Entry<String, Queue> entry : queueCollections.entrySet()) { String queueName = entry.getKey(); Set<String> queueLabels = entry.getValue().accessibleNodeLabels; if (queueLabels.contains(label)) { throw new IOException("Cannot remove label=" + label + ", because queue=" + queueName + " is using this label. " + "Please remove label on queue before remove the label"); } } } }  @Override void addLabelsToNode(Map<NodeId, Set<String>> addedLabelsToNode); @Override void removeFromClusterNodeLabels(Collection<String> labelsToRemove); @Override void addToCluserNodeLabels(Collection<NodeLabel> labels); @Override void removeLabelsFromNode(Map<NodeId, Set<String>> removeLabelsFromNode); @Override void replaceLabelsOnNode(Map<NodeId, Set<String>> replaceLabelsToNode); void activateNode(NodeId nodeId, Resource resource); void deactivateNode(NodeId nodeId); void updateNodeResource(NodeId node, Resource newResource); void reinitializeQueueLabels(Map<String, Set<String>> queueToLabels); Resource getQueueResource(String queueName, Set<String> queueLabels,
      Resource clusterResource); int getActiveNMCountPerLabel(String label); Set<String> getLabelsOnNode(NodeId nodeId); boolean containsNodeLabel(String label); Resource getResourceByLabel(String label, Resource clusterResource); boolean checkAccess(UserGroupInformation user); void setRMContext(RMContext rmContext); List<RMNodeLabel> pullRMNodeLabelsInfo();  }
@Test(timeout = 60000) public void testcheckRemoveFromClusterNodeLabelsOfQueue() throws Exception { lmgr = new RMNodeLabelsManager(); Configuration conf = new Configuration(); File tempDir = File.createTempFile("nlb", ".tmp"); tempDir.delete(); tempDir.mkdirs(); tempDir.deleteOnExit(); conf.set(YarnConfiguration.FS_NODE_LABELS_STORE_ROOT_DIR, tempDir.getAbsolutePath()); conf.setBoolean(YarnConfiguration.NODE_LABELS_ENABLED, true); conf.set(YarnConfiguration.RM_SCHEDULER, "org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler"); Configuration withQueueLabels = getConfigurationWithQueueLabels(conf); MockRM rm = initRM(conf); lmgr.addToCluserNodeLabels(toSet(NodeLabel.newInstance("x", false))); lmgr.removeFromClusterNodeLabels(Arrays.asList(new String[] { "x" })); lmgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("x")); rm.stop(); class TestRMLabelManger extends RMNodeLabelsManager { @Override protected void checkRemoveFromClusterNodeLabelsOfQueue( Collection<String> labelsToRemove) throws IOException { checkQueueCall = true; } } lmgr = new TestRMLabelManger(); MockRM rm2 = initRM(withQueueLabels); Assert.assertFalse( "checkRemoveFromClusterNodeLabelsOfQueue should not be called" + "on recovery", checkQueueCall); lmgr.removeFromClusterNodeLabels(Arrays.asList(new String[] { "x" })); Assert .assertTrue("checkRemoveFromClusterNodeLabelsOfQueue should be called " + "since its not recovery", checkQueueCall); rm2.stop(); }