瀏覽代碼

YARN-11461. fix NPE in determineMissingParents (auto queue creation / CS). (#5506)

Change-Id: Iaaaf43a545588eaff8a0a20f6f3c27258a45f390
Tamas Domok 2 年之前
父節點
當前提交
69748aae32

+ 5 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueManager.java

@@ -576,6 +576,11 @@ public class CapacitySchedulerQueueManager implements SchedulerQueueManager<
       firstExistingStaticParent = getQueue(parentCandidate.toString());
       firstExistingStaticParent = getQueue(parentCandidate.toString());
     }
     }
 
 
+    if (firstExistingParent == null || firstExistingStaticParent == null) {
+      throw new SchedulerDynamicEditException("Could not auto-create queue "
+          + queue + " parent queue does not exist.");
+    }
+
     int maximumDepthOfStaticParent = csContext.getConfiguration().getMaximumAutoCreatedQueueDepth(
     int maximumDepthOfStaticParent = csContext.getConfiguration().getMaximumAutoCreatedQueueDepth(
         firstExistingStaticParent.getQueuePath());
         firstExistingStaticParent.getQueuePath());
     if (firstStaticParentDistance > maximumDepthOfStaticParent) {
     if (firstStaticParentDistance > maximumDepthOfStaticParent) {

+ 11 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreation.java

@@ -1251,6 +1251,17 @@ public class TestCapacitySchedulerNewQueueAutoCreation
     Assert.assertNull("root.e.e1-auto should have been removed", eAuto);
     Assert.assertNull("root.e.e1-auto should have been removed", eAuto);
   }
   }
 
 
+  @Test()
+  public void testAutoCreateInvalidParent() throws Exception {
+    startScheduler();
+    Assert.assertThrows(SchedulerDynamicEditException.class,
+        () -> createQueue("invalid.queue"));
+    Assert.assertThrows(SchedulerDynamicEditException.class,
+        () -> createQueue("invalid.queue.longer"));
+    Assert.assertThrows(SchedulerDynamicEditException.class,
+        () -> createQueue("invalidQueue"));
+  }
+
   protected AbstractLeafQueue createQueue(String queuePath) throws YarnException,
   protected AbstractLeafQueue createQueue(String queuePath) throws YarnException,
       IOException {
       IOException {
     return autoQueueHandler.createQueue(new QueuePath(queuePath));
     return autoQueueHandler.createQueue(new QueuePath(queuePath));