瀏覽代碼

YARN-2012. Fair Scheduler: allow default queue placement rule to take an arbitrary queue (Ashwin Shankar via Sandy Ryza)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1597204 13f79535-47bb-0310-9956-ffa450edef68
Sanford Ryza 11 年之前
父節點
當前提交
6c56612af5

+ 3 - 0
hadoop-yarn-project/CHANGES.txt

@@ -99,6 +99,9 @@ Release 2.5.0 - UNRELEASED
     YARN-1937. Added owner-only ACLs support for Timeline Client and server.
     (Zhijie Shen via vinodkv)
 
+    YARN-2012. Fair Scheduler: allow default queue placement rule to take an
+    arbitrary queue (Ashwin Shankar via Sandy Ryza)
+
   OPTIMIZATIONS
 
   BUG FIXES 

+ 21 - 4
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/QueuePlacementRule.java

@@ -276,21 +276,38 @@ public abstract class QueuePlacementRule {
   }
   
   /**
-   * Places all apps in the default queue
+   * Places apps in the specified default queue. If no default queue is
+   * specified the app is placed in root.default queue.
    */
   public static class Default extends QueuePlacementRule {
+    private String defaultQueueName;
+
+    @Override
+    public void initializeFromXml(Element el)
+        throws AllocationConfigurationException {
+      defaultQueueName = el.getAttribute("queue");
+      if (defaultQueueName != null && !defaultQueueName.isEmpty()) {
+        if (!defaultQueueName.startsWith("root.")) {
+          defaultQueueName = "root." + defaultQueueName;
+        }
+      } else {
+        defaultQueueName = "root." + YarnConfiguration.DEFAULT_QUEUE_NAME;
+      }
+      super.initializeFromXml(el);
+    }
+
     @Override
     protected String getQueueForApp(String requestedQueue, String user,
         Groups groups, Map<FSQueueType, Set<String>> configuredQueues) {
-      return "root." + YarnConfiguration.DEFAULT_QUEUE_NAME;
+      return defaultQueueName;
     }
-    
+
     @Override
     public boolean isTerminal() {
       return true;
     }
   }
-  
+
   /**
    * Rejects all apps
    */

+ 35 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestQueuePlacementPolicy.java

@@ -133,6 +133,22 @@ public class TestQueuePlacementPolicy {
     parse(sb.toString());
   }
   
+  @Test
+  public void testDefaultRuleWithQueueAttribute() throws Exception {
+    // This test covers the use case where we would like default rule
+    // to point to a different queue by default rather than root.default
+    configuredQueues.get(FSQueueType.LEAF).add("root.someDefaultQueue");
+    StringBuffer sb = new StringBuffer();
+    sb.append("<queuePlacementPolicy>");
+    sb.append("  <rule name='specified' create='false' />");
+    sb.append("  <rule name='default' queue='root.someDefaultQueue'/>");
+    sb.append("</queuePlacementPolicy>");
+
+    QueuePlacementPolicy policy = parse(sb.toString());
+    assertEquals("root.someDefaultQueue",
+        policy.assignAppToQueue("root.default", "user1"));
+  }
+  
   @Test
   public void testNestedUserQueueParsingErrors() {
     // No nested rule specified in hierarchical user queue
@@ -311,6 +327,25 @@ public class TestQueuePlacementPolicy {
         policy.assignAppToQueue("root.parent2", "user2"));
   }
   
+  @Test
+  public void testNestedUserQueueDefaultRule() throws Exception {
+    // This test covers the use case where we would like user queues to be
+    // created under a default parent queue
+    configuredQueues.get(FSQueueType.PARENT).add("root.parentq");
+    StringBuffer sb = new StringBuffer();
+    sb.append("<queuePlacementPolicy>");
+    sb.append("  <rule name='specified' create='false' />");
+    sb.append("  <rule name='nestedUserQueue'>");
+    sb.append("       <rule name='default' queue='root.parentq'/>");
+    sb.append("  </rule>");
+    sb.append("  <rule name='default' />");
+    sb.append("</queuePlacementPolicy>");
+
+    QueuePlacementPolicy policy = parse(sb.toString());
+    assertEquals("root.parentq.user1",
+        policy.assignAppToQueue("root.default", "user1"));
+  }
+  
   private QueuePlacementPolicy parse(String str) throws Exception {
     // Read and parse the allocations file.
     DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory

+ 3 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/apt/FairScheduler.apt.vm

@@ -310,7 +310,8 @@ Allocation file format
        to ‘parent’ or by configuring at least one leaf under that queue which makes it a parent.
        See example allocation for a sample use case. 
 
-     * default: the app is placed into the queue named "default".
+     * default: the app is placed into the queue specified in the ‘queue’ attribute of the 
+       default rule. If ‘queue’ attribute is not specified, the app is placed into ‘root.default’ queue.
 
      * reject: the app is rejected.
 
@@ -348,7 +349,7 @@ Allocation file format
     <rule name=“nestedUserQueue”>
         <rule name=“secondaryGroupExistingQueue” create=“false” />
     </rule>
-    <rule name="default" />
+    <rule name="default" queue=“sample_queue” />
   </queuePlacementPolicy>
 </allocations>
 ---