@Test(timeout=5000) public void testGetQueueResource() throws Exception { Resource clusterResource = Resource.newInstance(9999, 1, 1); mgr.addToCluserNodeLabels(toSet("red", "blue", "yellow")); mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("host1"), toSet("red"))); mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("host2"), toSet("blue"))); mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("host3"), toSet("yellow"))); mgr.activateNode(NodeId.newInstance("host1", 1), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("host2", 1), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("host3", 1), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("host4", 1), SMALL_RESOURCE); Set<String> q1Label = toSet("red", "blue"); Set<String> q2Label = toSet("blue", "yellow"); Set<String> q3Label = toSet("yellow"); Set<String> q4Label = RMNodeLabelsManager.EMPTY_STRING_SET; Set<String> q5Label = toSet(RMNodeLabelsManager.ANY); Map<String, Set<String>> queueToLabels = new HashMap<String, Set<String>>(); queueToLabels.put("Q1", q1Label); queueToLabels.put("Q2", q2Label); queueToLabels.put("Q3", q3Label); queueToLabels.put("Q4", q4Label); queueToLabels.put("Q5", q5Label); mgr.reinitializeQueueLabels(queueToLabels); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q1", q1Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q2", q2Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q3", q3Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1), mgr.getQueueResource("Q4", q4Label, clusterResource)); Assert.assertEquals(clusterResource, mgr.getQueueResource("Q5", q5Label, clusterResource)); mgr.removeLabelsFromNode(ImmutableMap.of(toNodeId("host2"), toSet("blue"))); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q1", q1Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q2", q2Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q3", q3Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q4", q4Label, clusterResource)); Assert.assertEquals(clusterResource, mgr.getQueueResource("Q5", q5Label, clusterResource)); mgr.deactivateNode(NodeId.newInstance("host1", 1)); mgr.deactivateNode(NodeId.newInstance("host3", 1)); mgr.activateNode(NodeId.newInstance("host3", 1), SMALL_RESOURCE); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q1", q1Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q2", q2Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q3", q3Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q4", q4Label, clusterResource)); Assert.assertEquals(clusterResource, mgr.getQueueResource("Q5", q5Label, clusterResource)); q1Label = toSet("blue"); q2Label = toSet("blue", "red"); q3Label = toSet("red"); q4Label = RMNodeLabelsManager.EMPTY_STRING_SET; q5Label = toSet(RMNodeLabelsManager.ANY); queueToLabels.clear(); queueToLabels.put("Q1", q1Label); queueToLabels.put("Q2", q2Label); queueToLabels.put("Q3", q3Label); queueToLabels.put("Q4", q4Label); queueToLabels.put("Q5", q5Label); mgr.reinitializeQueueLabels(queueToLabels); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q1", q1Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q2", q2Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q3", q3Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2), mgr.getQueueResource("Q4", q4Label, clusterResource)); Assert.assertEquals(clusterResource, mgr.getQueueResource("Q5", q5Label, clusterResource)); mgr.activateNode(NodeId.newInstance("host3", 2), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("host3", 3), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("host4", 2), SMALL_RESOURCE); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q1", q1Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q2", q2Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q3", q3Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3), mgr.getQueueResource("Q4", q4Label, clusterResource)); Assert.assertEquals(clusterResource, mgr.getQueueResource("Q5", q5Label, clusterResource)); mgr.deactivateNode(NodeId.newInstance("host3", 3)); mgr.deactivateNode(NodeId.newInstance("host4", 2)); mgr.deactivateNode(NodeId.newInstance("host4", 1)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1), mgr.getQueueResource("Q1", q1Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1), mgr.getQueueResource("Q2", q2Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1), mgr.getQueueResource("Q3", q3Label, clusterResource)); Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1), mgr.getQueueResource("Q4", q4Label, clusterResource)); Assert.assertEquals(clusterResource, mgr.getQueueResource("Q5", q5Label, clusterResource)); }
public Resource getQueueResource(String queueName, Set<String> queueLabels, Resource clusterResource) { try { readLock.lock(); if (queueLabels.contains(ANY)) { return clusterResource; } Queue q = queueCollections.get(queueName); if (null == q) { return Resources.none(); } return q.resource; } finally { readLock.unlock(); } }
RMNodeLabelsManager extends CommonNodeLabelsManager { public Resource getQueueResource(String queueName, Set<String> queueLabels, Resource clusterResource) { try { readLock.lock(); if (queueLabels.contains(ANY)) { return clusterResource; } Queue q = queueCollections.get(queueName); if (null == q) { return Resources.none(); } return q.resource; } finally { readLock.unlock(); } } }
RMNodeLabelsManager extends CommonNodeLabelsManager { public Resource getQueueResource(String queueName, Set<String> queueLabels, Resource clusterResource) { try { readLock.lock(); if (queueLabels.contains(ANY)) { return clusterResource; } Queue q = queueCollections.get(queueName); if (null == q) { return Resources.none(); } return q.resource; } finally { readLock.unlock(); } }  }
RMNodeLabelsManager extends CommonNodeLabelsManager { public Resource getQueueResource(String queueName, Set<String> queueLabels, Resource clusterResource) { try { readLock.lock(); if (queueLabels.contains(ANY)) { return clusterResource; } Queue q = queueCollections.get(queueName); if (null == q) { return Resources.none(); } return q.resource; } finally { readLock.unlock(); } }  @Override void addLabelsToNode(Map<NodeId, Set<String>> addedLabelsToNode); @Override void removeFromClusterNodeLabels(Collection<String> labelsToRemove); @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); Set<String> getLabelsOnNode(NodeId nodeId); boolean containsNodeLabel(String label); Resource getResourceByLabel(String label, Resource clusterResource); boolean checkAccess(UserGroupInformation user); void setRMContext(RMContext rmContext); List<NodeLabel> pullRMNodeLabelsInfo(); }
RMNodeLabelsManager extends CommonNodeLabelsManager { public Resource getQueueResource(String queueName, Set<String> queueLabels, Resource clusterResource) { try { readLock.lock(); if (queueLabels.contains(ANY)) { return clusterResource; } Queue q = queueCollections.get(queueName); if (null == q) { return Resources.none(); } return q.resource; } finally { readLock.unlock(); } }  @Override void addLabelsToNode(Map<NodeId, Set<String>> addedLabelsToNode); @Override void removeFromClusterNodeLabels(Collection<String> labelsToRemove); @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); Set<String> getLabelsOnNode(NodeId nodeId); boolean containsNodeLabel(String label); Resource getResourceByLabel(String label, Resource clusterResource); boolean checkAccess(UserGroupInformation user); void setRMContext(RMContext rmContext); List<NodeLabel> pullRMNodeLabelsInfo();  }