diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java index 60ade2dbca..66e945fc2f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java @@ -99,6 +99,8 @@ public class CommonNodeLabelsManager extends AbstractService { protected ConcurrentMap nodeCollections = new ConcurrentHashMap(); + protected RMNodeLabel noNodeLabel; + protected final ReadLock readLock; protected final WriteLock writeLock; @@ -225,7 +227,8 @@ protected void serviceInit(Configuration conf) throws Exception { isCentralizedNodeLabelConfiguration = YarnConfiguration.isCentralizedNodeLabelConfiguration(conf); - labelCollections.put(NO_LABEL, new RMNodeLabel(NO_LABEL)); + noNodeLabel = new RMNodeLabel(NO_LABEL); + labelCollections.put(NO_LABEL, noNodeLabel); } /** @@ -947,6 +950,9 @@ public List getClusterNodeLabels() { } public boolean isExclusiveNodeLabel(String nodeLabel) throws IOException { + if (nodeLabel.equals(NO_LABEL)) { + return noNodeLabel.getIsExclusive(); + } try { readLock.lock(); RMNodeLabel label = labelCollections.get(nodeLabel); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java index 79b25edc14..507f696d05 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java @@ -519,12 +519,16 @@ private void updateResourceMappings(Map before, public Resource getResourceByLabel(String label, Resource clusterResource) { label = normalizeLabel(label); + if (label.equals(NO_LABEL)) { + return noNodeLabel.getResource(); + } try { readLock.lock(); - if (null == labelCollections.get(label)) { + RMNodeLabel nodeLabel = labelCollections.get(label); + if (nodeLabel == null) { return Resources.none(); } - return labelCollections.get(label).getResource(); + return nodeLabel.getResource(); } finally { readLock.unlock(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/ResourceUsage.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/ResourceUsage.java index 28573792ae..6f0c7d20a8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/ResourceUsage.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/ResourceUsage.java @@ -28,7 +28,6 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager; -import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.util.resource.Resources; /** @@ -46,6 +45,7 @@ public class ResourceUsage { private Map usages; // short for no-label :) private static final String NL = CommonNodeLabelsManager.NO_LABEL; + private final UsageByLabel usageNoLabel; public ResourceUsage() { ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); @@ -53,7 +53,8 @@ public ResourceUsage() { writeLock = lock.writeLock(); usages = new HashMap(); - usages.put(NL, new UsageByLabel(NL)); + usageNoLabel = new UsageByLabel(NL); + usages.put(NL, usageNoLabel); } // Usage enum here to make implement cleaner @@ -323,10 +324,9 @@ private static Resource normalize(Resource res) { } private Resource _get(String label, ResourceType type) { - if (label == null) { - label = RMNodeLabelsManager.NO_LABEL; + if (label == null || label.equals(NL)) { + return normalize(usageNoLabel.resArr[type.idx]); } - try { readLock.lock(); UsageByLabel usage = usages.get(label); @@ -362,8 +362,8 @@ public Resource getAllUsed() { } private UsageByLabel getAndAddIfMissing(String label) { - if (label == null) { - label = RMNodeLabelsManager.NO_LABEL; + if (label == null || label.equals(NL)) { + return usageNoLabel; } if (!usages.containsKey(label)) { UsageByLabel u = new UsageByLabel(label); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java index 03fc2065bf..8a6504002a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java @@ -52,6 +52,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.MockAsm; import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager; +import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; @@ -229,12 +230,15 @@ public static CapacityScheduler mockCapacityScheduler() throws IOException { setupQueueConfiguration(conf); CapacityScheduler cs = new CapacityScheduler(); - cs.setConf(new YarnConfiguration()); + YarnConfiguration yarnConf = new YarnConfiguration(); + cs.setConf(yarnConf); RMContext rmContext = new RMContextImpl(null, null, null, null, null, null, new RMContainerTokenSecretManager(conf), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM(), null); - rmContext.setNodeLabelManager(new NullRMNodeLabelsManager()); + RMNodeLabelsManager labelManager = new NullRMNodeLabelsManager(); + labelManager.init(yarnConf); + rmContext.setNodeLabelManager(labelManager); cs.setRMContext(rmContext); cs.init(conf); return cs;