hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rkan...@apache.org
Subject [1/2] hadoop git commit: YARN-7841. Cleanup AllocationFileLoaderService's reloadAllocations method (snemeth via rkanter)
Date Tue, 06 Feb 2018 22:37:22 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 4304fcd5b -> 814d701d4


http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAllocationFileLoaderService.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAllocationFileLoaderService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAllocationFileLoaderService.java
index c46ecd9..4a7461d 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAllocationFileLoaderService.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAllocationFileLoaderService.java
@@ -27,12 +27,12 @@ import org.apache.hadoop.yarn.api.records.QueueACL;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationSchedulerConfiguration;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.QueuePlacementRule.NestedUserQueue;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile.AllocationFileWriter;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.DominantResourceFairnessPolicy;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy;
 import org.apache.hadoop.yarn.util.ControlledClock;
 import org.apache.hadoop.yarn.util.resource.Resources;
 import org.junit.Test;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
@@ -43,7 +43,6 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
@@ -51,7 +50,7 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 public class TestAllocationFileLoaderService {
-  
+
   final static String TEST_DIR = new File(System.getProperty("test.build.data",
       "/tmp")).getAbsolutePath();
 
@@ -112,7 +111,7 @@ public class TestAllocationFileLoaderService {
       fail("Unable to access allocation file from classpath: " + e);
     }
   }
-  
+
   @Test (timeout = 10000)
   public void testReload() throws Exception {
     PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
@@ -127,7 +126,7 @@ public class TestAllocationFileLoaderService {
     out.println("  </queuePlacementPolicy>");
     out.println("</allocations>");
     out.close();
-    
+
     ControlledClock clock = new ControlledClock();
     clock.setTime(0);
     Configuration conf = new Configuration();
@@ -141,7 +140,7 @@ public class TestAllocationFileLoaderService {
     allocLoader.setReloadListener(confHolder);
     allocLoader.reloadAllocations();
     AllocationConfiguration allocConf = confHolder.allocConf;
-    
+
     // Verify conf
     QueuePlacementPolicy policy = allocConf.getPlacementPolicy();
     List<QueuePlacementRule> rules = policy.getRules();
@@ -154,9 +153,9 @@ public class TestAllocationFileLoaderService {
         .contains("root.queueA"));
     assertTrue(allocConf.getConfiguredQueues().get(FSQueueType.LEAF)
         .contains("root.queueB"));
-    
+
     confHolder.allocConf = null;
-    
+
     // Modify file and advance the clock
     out = new PrintWriter(new FileWriter(ALLOC_FILE));
     out.println("<?xml version=\"1.0\"?>");
@@ -166,22 +165,22 @@ public class TestAllocationFileLoaderService {
     out.println("  </queue>");
     out.println("  <queuePlacementPolicy>");
     out.println("    <rule name='specified' />");
-    out.println("    <rule name='nestedUserQueue' >");  
+    out.println("    <rule name='nestedUserQueue' >");
     out.println("         <rule name='primaryGroup' />");
     out.println("    </rule>");
     out.println("    <rule name='default' />");
     out.println("  </queuePlacementPolicy>");
     out.println("</allocations>");
     out.close();
-    
+
     clock.tickMsec(System.currentTimeMillis()
         + AllocationFileLoaderService.ALLOC_RELOAD_WAIT_MS + 10000);
     allocLoader.start();
-    
+
     while (confHolder.allocConf == null) {
       Thread.sleep(20);
     }
-    
+
     // Verify conf
     allocConf = confHolder.allocConf;
     policy = allocConf.getPlacementPolicy();
@@ -199,91 +198,89 @@ public class TestAllocationFileLoaderService {
     assertTrue(allocConf.getConfiguredQueues().get(FSQueueType.LEAF)
         .contains("root.queueB"));
   }
-  
+
   @Test
   public void testAllocationFileParsing() throws Exception {
     Configuration conf = new Configuration();
     conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE);
     AllocationFileLoaderService allocLoader = new AllocationFileLoaderService();
 
-    PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
-    out.println("<?xml version=\"1.0\"?>");
-    out.println("<allocations>");
-    // Give queue A a minimum of 1024 M
-    out.println("<queue name=\"queueA\">");
-    out.println("<minResources>1024mb,0vcores</minResources>");
-    out.println("<maxResources>2048mb,10vcores</maxResources>");
-    out.println("</queue>");
-    // Give queue B a minimum of 2048 M
-    out.println("<queue name=\"queueB\">");
-    out.println("<minResources>2048mb,0vcores</minResources>");
-    out.println("<maxResources>5120mb,110vcores</maxResources>");
-    out.println("<aclAdministerApps>alice,bob admins</aclAdministerApps>");
-    out.println("<schedulingPolicy>fair</schedulingPolicy>");
-    out.println("</queue>");
-    // Give queue C no minimum
-    out.println("<queue name=\"queueC\">");
-    out.println("<minResources>5120mb,0vcores</minResources>");
-    out.println("<aclSubmitApps>alice,bob admins</aclSubmitApps>");
-    out.println("</queue>");
-    // Give queue D a limit of 3 running apps and 0.4f maxAMShare
-    out.println("<queue name=\"queueD\">");
-    out.println("<maxRunningApps>3</maxRunningApps>");
-    out.println("<maxAMShare>0.4</maxAMShare>");
-    out.println("</queue>");
-    // Give queue E a preemption timeout of one minute
-    out.println("<queue name=\"queueE\">");
-    out.println("<minSharePreemptionTimeout>60</minSharePreemptionTimeout>");
-    out.println("</queue>");
-    // Make queue F a parent queue without configured leaf queues using the
-    // 'type' attribute
-    out.println("<queue name=\"queueF\" type=\"parent\" >");
-    out.println("<maxChildResources>2048mb,64vcores</maxChildResources>");
-    out.println("</queue>");
-    // Create hierarchical queues G,H, with different min/fair share preemption
-    // timeouts and preemption thresholds. Also add a child default to make sure
-    // it doesn't impact queue H.
-    out.println("<queue name=\"queueG\">");
-    out.println("<maxChildResources>2048mb,64vcores</maxChildResources>");
-    out.println("<fairSharePreemptionTimeout>120</fairSharePreemptionTimeout>");
-    out.println("<minSharePreemptionTimeout>50</minSharePreemptionTimeout>");
-    out.println("<fairSharePreemptionThreshold>0.6</fairSharePreemptionThreshold>");
-    out.println("   <queue name=\"queueH\">");
-    out.println("   <fairSharePreemptionTimeout>180</fairSharePreemptionTimeout>");
-    out.println("   <minSharePreemptionTimeout>40</minSharePreemptionTimeout>");
-    out.println("   <fairSharePreemptionThreshold>0.7</fairSharePreemptionThreshold>");
-    out.println("   </queue>");
-    out.println("</queue>");
-    // Set default limit of apps per queue to 15
-    out.println("<queueMaxAppsDefault>15</queueMaxAppsDefault>");
-    // Set default limit of max resource per queue to 4G and 100 cores
-    out.println("<queueMaxResourcesDefault>4096mb,100vcores</queueMaxResourcesDefault>");
-    // Set default limit of apps per user to 5
-    out.println("<userMaxAppsDefault>5</userMaxAppsDefault>");
-    // Set default limit of AMResourceShare to 0.5f
-    out.println("<queueMaxAMShareDefault>0.5f</queueMaxAMShareDefault>");
-    // Give user1 a limit of 10 jobs
-    out.println("<user name=\"user1\">");
-    out.println("<maxRunningApps>10</maxRunningApps>");
-    out.println("</user>");
-    // Set default min share preemption timeout to 2 minutes
-    out.println("<defaultMinSharePreemptionTimeout>120"
-        + "</defaultMinSharePreemptionTimeout>");
-    // Set default fair share preemption timeout to 5 minutes
-    out.println("<defaultFairSharePreemptionTimeout>300</defaultFairSharePreemptionTimeout>");
-    // Set default fair share preemption threshold to 0.4
-    out.println("<defaultFairSharePreemptionThreshold>0.4</defaultFairSharePreemptionThreshold>");
-    // Set default scheduling policy to DRF
-    out.println("<defaultQueueSchedulingPolicy>drf</defaultQueueSchedulingPolicy>");
-    out.println("</allocations>");
-    out.close();
-    
+    AllocationFileWriter
+            .create()
+            // Give queue A a minimum of 1024 M
+            .queue("queueA")
+              .minResources("1024mb,0vcores")
+              .maxResources("2048mb,10vcores")
+            .buildQueue()
+            // Give queue B a minimum of 2048 M
+            .queue("queueB")
+                .minResources("2048mb,0vcores")
+                .maxResources("5120mb,110vcores")
+                .aclAdministerApps("alice,bob admins")
+                .schedulingPolicy("fair")
+            .buildQueue()
+            // Give queue C no minimum
+            .queue("queueC")
+              .minResources("5120mb,0vcores")
+              .aclSubmitApps("alice,bob admins")
+            .buildQueue()
+            // Give queue D a limit of 3 running apps and 0.4f maxAMShare
+            .queue("queueD")
+              .maxRunningApps(3)
+              .maxAMShare(0.4)
+            .buildQueue()
+            // Give queue E a preemption timeout of one minute
+            .queue("queueE")
+              .minSharePreemptionTimeout(60)
+            .buildQueue()
+            // Make queue F a parent queue without configured leaf queues
+            // using the 'type' attribute
+            .queue("queueF")
+              .parent(true)
+              .maxChildResources("2048mb,64vcores")
+            .buildQueue()
+            .queue("queueG")
+              .maxChildResources("2048mb,64vcores")
+              .fairSharePreemptionTimeout(120)
+              .minSharePreemptionTimeout(50)
+              .fairSharePreemptionThreshold(0.6)
+            // Create hierarchical queues G,H, with different min/fair
+            // share preemption timeouts and preemption thresholds.
+            // Also add a child default to make sure it doesn't impact queue H.
+              .subQueue("queueH")
+                .fairSharePreemptionTimeout(180)
+                .minSharePreemptionTimeout(40)
+                .fairSharePreemptionThreshold(0.7)
+              .buildSubQueue()
+            .buildQueue()
+            // Set default limit of apps per queue to 15
+            .queueMaxAppsDefault(15)
+            // Set default limit of max resource per queue to 4G and 100 cores
+            .queueMaxResourcesDefault("4096mb,100vcores")
+            // Set default limit of apps per user to 5
+            .userMaxAppsDefault(5)
+            // Set default limit of AMResourceShare to 0.5f
+            .queueMaxAMShareDefault(0.5)
+            // Set default min share preemption timeout to 2 minutes
+            .defaultMinSharePreemptionTimeout(120)
+            // Set default fair share preemption timeout to 5 minutes
+            .defaultFairSharePreemptionTimeout(300)
+            // Set default fair share preemption threshold to 0.4
+            .defaultFairSharePreemptionThreshold(0.4)
+            // Set default scheduling policy to DRF
+            .defaultQueueSchedulingPolicy("drf")
+            // Give user1 a limit of 10 jobs
+            .userSettings("user1")
+              .maxRunningApps(10)
+            .build()
+            .writeToFile(ALLOC_FILE);
+
     allocLoader.init(conf);
     ReloadListener confHolder = new ReloadListener();
     allocLoader.setReloadListener(confHolder);
     allocLoader.reloadAllocations();
     AllocationConfiguration queueConf = confHolder.allocConf;
-    
+
     assertEquals(6, queueConf.getConfiguredQueues().get(FSQueueType.LEAF).size());
     assertEquals(Resources.createResource(0),
         queueConf.getMinResources("root." + YarnConfiguration.DEFAULT_QUEUE_NAME));
@@ -443,7 +440,7 @@ public class TestAllocationFileLoaderService {
     assertEquals(DominantResourceFairnessPolicy.NAME,
         queueConf.getSchedulingPolicy("root.newqueue").getName());
   }
-  
+
   @Test
   public void testBackwardsCompatibleAllocationFileParsing() throws Exception {
     Configuration conf = new Configuration();
@@ -492,7 +489,7 @@ public class TestAllocationFileLoaderService {
     out.println("<defaultFairSharePreemptionThreshold>0.6</defaultFairSharePreemptionThreshold>");
     out.println("</allocations>");
     out.close();
-    
+
     allocLoader.init(conf);
     ReloadListener confHolder = new ReloadListener();
     allocLoader.setReloadListener(confHolder);
@@ -571,27 +568,27 @@ public class TestAllocationFileLoaderService {
     assertEquals(.3f,
         queueConf.getFairSharePreemptionThreshold("root.queueE"), 0.01);
   }
-  
+
   @Test
   public void testSimplePlacementPolicyFromConf() throws Exception {
     Configuration conf = new Configuration();
     conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE);
     conf.setBoolean(FairSchedulerConfiguration.ALLOW_UNDECLARED_POOLS, false);
     conf.setBoolean(FairSchedulerConfiguration.USER_AS_DEFAULT_QUEUE, false);
-    
+
     PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
     out.println("<?xml version=\"1.0\"?>");
     out.println("<allocations>");
     out.println("</allocations>");
     out.close();
-    
+
     AllocationFileLoaderService allocLoader = new AllocationFileLoaderService();
     allocLoader.init(conf);
     ReloadListener confHolder = new ReloadListener();
     allocLoader.setReloadListener(confHolder);
     allocLoader.reloadAllocations();
     AllocationConfiguration allocConf = confHolder.allocConf;
-    
+
     QueuePlacementPolicy placementPolicy = allocConf.getPlacementPolicy();
     List<QueuePlacementRule> rules = placementPolicy.getRules();
     assertEquals(2, rules.size());
@@ -599,7 +596,7 @@ public class TestAllocationFileLoaderService {
     assertEquals(false, rules.get(0).create);
     assertEquals(QueuePlacementRule.Default.class, rules.get(1).getClass());
   }
-  
+
   /**
    * Verify that you can't place queues at the same level as the root queue in
    * the allocations file.
@@ -618,7 +615,7 @@ public class TestAllocationFileLoaderService {
     out.println("</queue>");
     out.println("</allocations>");
     out.close();
-    
+
     AllocationFileLoaderService allocLoader = new AllocationFileLoaderService();
     allocLoader.init(conf);
     ReloadListener confHolder = new ReloadListener();
@@ -890,7 +887,7 @@ public class TestAllocationFileLoaderService {
 
   private class ReloadListener implements AllocationFileLoaderService.Listener {
     public AllocationConfiguration allocConf;
-    
+
     @Override
     public void onReload(AllocationConfiguration info) {
       allocConf = info;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueue.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueue.java
new file mode 100644
index 0000000..f1afe69
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueue.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+
+class AllocationFileQueue {
+  private final AllocationFileQueueProperties properties;
+  private final List<AllocationFileQueue> subQueues;
+
+  AllocationFileQueue(AllocationFileQueueProperties properties,
+      List<AllocationFileQueue> subQueues) {
+    this.properties = properties;
+    this.subQueues = subQueues;
+  }
+
+  String render() {
+    StringWriter sw = new StringWriter();
+    PrintWriter pw = new PrintWriter(sw);
+    printStartTag(pw);
+    AllocationFileWriter.printQueues(pw, subQueues);
+    AllocationFileWriter.addIfPresent(pw, "minResources",
+            properties::getMinResources);
+    AllocationFileWriter.addIfPresent(pw, "maxResources",
+            properties::getMaxResources);
+    AllocationFileWriter.addIfPresent(pw, "aclAdministerApps",
+            properties::getAclAdministerApps);
+    AllocationFileWriter.addIfPresent(pw, "aclSubmitApps",
+            properties::getAclSubmitApps);
+    AllocationFileWriter.addIfPresent(pw, "schedulingPolicy",
+            properties::getSchedulingPolicy);
+    AllocationFileWriter.addIfPresent(pw, "maxRunningApps",
+        () -> AllocationFileWriter
+            .createNumberSupplier(properties.getMaxRunningApps()));
+    AllocationFileWriter.addIfPresent(pw, "maxAMShare",
+        () -> AllocationFileWriter.createNumberSupplier(properties
+                .getMaxAMShare()));
+    AllocationFileWriter.addIfPresent(pw, "minSharePreemptionTimeout",
+        () -> AllocationFileWriter
+            .createNumberSupplier(properties.getMinSharePreemptionTimeout()));
+    AllocationFileWriter.addIfPresent(pw, "maxChildResources",
+            properties::getMaxChildResources);
+    AllocationFileWriter.addIfPresent(pw, "fairSharePreemptionTimeout",
+        () -> AllocationFileWriter
+            .createNumberSupplier(properties.getFairSharePreemptionTimeout()));
+    AllocationFileWriter.addIfPresent(pw, "fairSharePreemptionThreshold",
+        () -> AllocationFileWriter
+            .createNumberSupplier(
+                    properties.getFairSharePreemptionThreshold()));
+    printEndTag(pw);
+    pw.close();
+    return sw.toString();
+  }
+
+  private void printStartTag(PrintWriter pw) {
+    pw.print("<queue name=\"" + properties.getQueueName() + "\" ");
+    if (properties.getParent()) {
+      pw.print("type=\"parent\"");
+    }
+    pw.println(">");
+  }
+
+  private void printEndTag(PrintWriter pw) {
+    pw.println("</queue>");
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueBuilder.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueBuilder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueBuilder.java
new file mode 100644
index 0000000..a2faf1d
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueBuilder.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile;
+
+/**
+ * Abstract base class for building simple queues and subqueues for testcases.
+ * Currently there are two concrete types subclassed from this class:
+ * {@link AllocationFileSimpleQueueBuilder} and
+ * {@link AllocationFileSubQueueBuilder}.
+ * The intention of having this class to group the common properties of
+ * simple queues and subqueues by methods delegating calls to a
+ * queuePropertiesBuilder instance.
+ */
+public abstract class AllocationFileQueueBuilder {
+  final AllocationFileQueueProperties.Builder queuePropertiesBuilder;
+
+  AllocationFileQueueBuilder() {
+    this.queuePropertiesBuilder =
+        AllocationFileQueueProperties.Builder.create();
+  }
+
+  public AllocationFileQueueBuilder parent(boolean parent) {
+    this.queuePropertiesBuilder.parent(parent);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder minResources(String value) {
+    this.queuePropertiesBuilder.minResources(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder maxResources(String value) {
+    this.queuePropertiesBuilder.maxResources(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder aclAdministerApps(String value) {
+    this.queuePropertiesBuilder.aclAdministerApps(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder aclSubmitApps(String value) {
+    this.queuePropertiesBuilder.aclSubmitApps(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder schedulingPolicy(String value) {
+    this.queuePropertiesBuilder.schedulingPolicy(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder maxRunningApps(int value) {
+    this.queuePropertiesBuilder.maxRunningApps(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder maxAMShare(double value) {
+    this.queuePropertiesBuilder.maxAMShare(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder minSharePreemptionTimeout(int value) {
+    this.queuePropertiesBuilder.minSharePreemptionTimeout(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder maxChildResources(String value) {
+    this.queuePropertiesBuilder.maxChildResources(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder fairSharePreemptionTimeout(Integer value) {
+    this.queuePropertiesBuilder.fairSharePreemptionTimeout(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder fairSharePreemptionThreshold(
+      double value) {
+    this.queuePropertiesBuilder.fairSharePreemptionThreshold(value);
+    return this;
+  }
+
+  public AllocationFileQueueBuilder subQueue(String queueName) {
+    if (this instanceof AllocationFileSimpleQueueBuilder) {
+      return new AllocationFileSubQueueBuilder(
+          (AllocationFileSimpleQueueBuilder) this, queueName);
+    } else {
+      throw new IllegalStateException(
+          "subQueue can only be invoked on instances of "
+              + AllocationFileSimpleQueueBuilder.class);
+    }
+  }
+
+  public abstract AllocationFileWriter buildQueue();
+
+  public abstract AllocationFileSimpleQueueBuilder buildSubQueue();
+
+  AllocationFileQueueProperties.Builder getqueuePropertiesBuilder() {
+    return queuePropertiesBuilder;
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueProperties.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueProperties.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueProperties.java
new file mode 100644
index 0000000..2c01144
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileQueueProperties.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile;
+
+/**
+ * The purpose of this class is to store all properties of a queue.
+ */
+public class AllocationFileQueueProperties {
+  private final String queueName;
+  private final String minResources;
+  private final String maxResources;
+  private final String aclAdministerApps;
+  private final String aclSubmitApps;
+  private final String schedulingPolicy;
+  private final Integer maxRunningApps;
+  private final Double maxAMShare;
+  private final Integer minSharePreemptionTimeout;
+  private final Boolean parent;
+  private final String maxChildResources;
+  private final Integer fairSharePreemptionTimeout;
+  private final Double fairSharePreemptionThreshold;
+
+  AllocationFileQueueProperties(Builder builder) {
+    this.queueName = builder.queueName;
+    this.parent = builder.parent;
+    this.minResources = builder.minResources;
+    this.maxResources = builder.maxResources;
+    this.aclAdministerApps = builder.aclAdministerApps;
+    this.aclSubmitApps = builder.aclSubmitApps;
+    this.schedulingPolicy = builder.schedulingPolicy;
+    this.maxRunningApps = builder.maxRunningApps;
+    this.maxAMShare = builder.maxAMShare;
+    this.minSharePreemptionTimeout = builder.minSharePreemptionTimeout;
+    this.maxChildResources = builder.maxChildResources;
+    this.fairSharePreemptionTimeout = builder.fairSharePreemptionTimeout;
+    this.fairSharePreemptionThreshold = builder.fairSharePreemptionThreshold;
+  }
+
+  public String getQueueName() {
+    return queueName;
+  }
+
+  public String getMinResources() {
+    return minResources;
+  }
+
+  public String getMaxResources() {
+    return maxResources;
+  }
+
+  public String getAclAdministerApps() {
+    return aclAdministerApps;
+  }
+
+  public String getAclSubmitApps() {
+    return aclSubmitApps;
+  }
+
+  public String getSchedulingPolicy() {
+    return schedulingPolicy;
+  }
+
+  public Integer getMaxRunningApps() {
+    return maxRunningApps;
+  }
+
+  public Double getMaxAMShare() {
+    return maxAMShare;
+  }
+
+  public Integer getMinSharePreemptionTimeout() {
+    return minSharePreemptionTimeout;
+  }
+
+  public Boolean getParent() {
+    return parent;
+  }
+
+  public String getMaxChildResources() {
+    return maxChildResources;
+  }
+
+  public Integer getFairSharePreemptionTimeout() {
+    return fairSharePreemptionTimeout;
+  }
+
+  public Double getFairSharePreemptionThreshold() {
+    return fairSharePreemptionThreshold;
+  }
+
+  /**
+   * Builder class for {@link AllocationFileQueueProperties}.
+   */
+  public static final class Builder {
+    private String queueName;
+    private Boolean parent = false;
+    private String minResources;
+    private String maxResources;
+    private String aclAdministerApps;
+    private String aclSubmitApps;
+    private String schedulingPolicy;
+    private Integer maxRunningApps;
+    private Double maxAMShare;
+    private Integer minSharePreemptionTimeout;
+    private String maxChildResources;
+    private Integer fairSharePreemptionTimeout;
+    private Double fairSharePreemptionThreshold;
+
+    Builder() {
+    }
+
+    public static Builder create() {
+      return new Builder();
+    }
+
+    public Builder queueName(String queueName) {
+      this.queueName = queueName;
+      return this;
+    }
+
+    public Builder minResources(String minResources) {
+      this.minResources = minResources;
+      return this;
+    }
+
+    public Builder maxResources(String maxResources) {
+      this.maxResources = maxResources;
+      return this;
+    }
+
+    public Builder aclAdministerApps(String aclAdministerApps) {
+      this.aclAdministerApps = aclAdministerApps;
+      return this;
+    }
+
+    public Builder aclSubmitApps(String aclSubmitApps) {
+      this.aclSubmitApps = aclSubmitApps;
+      return this;
+    }
+
+    public Builder schedulingPolicy(String schedulingPolicy) {
+      this.schedulingPolicy = schedulingPolicy;
+      return this;
+    }
+
+    public Builder maxRunningApps(Integer maxRunningApps) {
+      this.maxRunningApps = maxRunningApps;
+      return this;
+    }
+
+    public Builder maxAMShare(Double maxAMShare) {
+      this.maxAMShare = maxAMShare;
+      return this;
+    }
+
+    public Builder minSharePreemptionTimeout(
+        Integer minSharePreemptionTimeout) {
+      this.minSharePreemptionTimeout = minSharePreemptionTimeout;
+      return this;
+    }
+
+    public Builder parent(Boolean parent) {
+      this.parent = parent;
+      return this;
+    }
+
+    public Builder maxChildResources(String maxChildResources) {
+      this.maxChildResources = maxChildResources;
+      return this;
+    }
+
+    public Builder fairSharePreemptionTimeout(
+        Integer fairSharePreemptionTimeout) {
+      this.fairSharePreemptionTimeout = fairSharePreemptionTimeout;
+      return this;
+    }
+
+    public Builder fairSharePreemptionThreshold(
+        Double fairSharePreemptionThreshold) {
+      this.fairSharePreemptionThreshold = fairSharePreemptionThreshold;
+      return this;
+    }
+
+    public AllocationFileQueueProperties build() {
+      return new AllocationFileQueueProperties(this);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSimpleQueueBuilder.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSimpleQueueBuilder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSimpleQueueBuilder.java
new file mode 100644
index 0000000..93d100e
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSimpleQueueBuilder.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Queue builder that can build a simple queue with its properties.
+ * Subqueues can be added with {@link #addSubQueue(AllocationFileQueue)}.
+ */
+public class AllocationFileSimpleQueueBuilder
+    extends AllocationFileQueueBuilder {
+  private final AllocationFileWriter allocationFileWriter;
+  private final List<AllocationFileQueue> subQueues = new ArrayList<>();
+
+  AllocationFileSimpleQueueBuilder(AllocationFileWriter allocationFileWriter,
+      String queueName) {
+    this.allocationFileWriter = allocationFileWriter;
+    getqueuePropertiesBuilder().queueName(queueName);
+  }
+
+  void addSubQueue(AllocationFileQueue queue) {
+    subQueues.add(queue);
+  }
+
+  @Override
+  public AllocationFileWriter buildQueue() {
+    AllocationFileQueueProperties queueProperties =
+            getqueuePropertiesBuilder().build();
+    AllocationFileQueue queue =
+        new AllocationFileQueue(queueProperties, subQueues);
+
+    if (allocationFileWriter != null) {
+      allocationFileWriter.addQueue(queue);
+    } else {
+      throw new IllegalStateException(
+          "allocationFileWriter field has to be set on a " + getClass());
+    }
+
+    return allocationFileWriter;
+  }
+
+  @Override
+  public AllocationFileSimpleQueueBuilder buildSubQueue() {
+    throw new IllegalStateException(
+        "buildSubQueue is not supported in " + getClass());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSubQueueBuilder.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSubQueueBuilder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSubQueueBuilder.java
new file mode 100644
index 0000000..728aedc
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileSubQueueBuilder.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile;
+
+import com.google.common.collect.Lists;
+
+
+/**
+ * Queue builder that can build a subqueue with its properties.
+ */
+public class AllocationFileSubQueueBuilder extends AllocationFileQueueBuilder {
+  private AllocationFileSimpleQueueBuilder parentQueueBuilder;
+
+  AllocationFileSubQueueBuilder(
+      AllocationFileSimpleQueueBuilder parentQueueBuilder, String queueName) {
+    getqueuePropertiesBuilder().queueName(queueName);
+    this.parentQueueBuilder = parentQueueBuilder;
+  }
+
+  @Override
+  public AllocationFileWriter buildQueue() {
+    throw new IllegalStateException(
+        "BuildQueue is not supported in " + getClass());
+  }
+
+  public AllocationFileSimpleQueueBuilder buildSubQueue() {
+    AllocationFileQueueProperties queueProperties =
+            getqueuePropertiesBuilder().build();
+    AllocationFileQueue queue =
+        new AllocationFileQueue(queueProperties, Lists.newArrayList());
+
+    if (parentQueueBuilder != null) {
+      parentQueueBuilder.addSubQueue(queue);
+      return parentQueueBuilder;
+    } else {
+      throw new IllegalStateException(
+          "parentQueueBuilder field has to be set on a " + getClass());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileWriter.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileWriter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileWriter.java
new file mode 100644
index 0000000..df1cc53
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/AllocationFileWriter.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Supplier;
+
+/**
+ * This class is capable of serializing allocation file data to a file
+ * in XML format.
+ * See {@link #writeToFile(String)} method for the implementation.
+ */
+public final class AllocationFileWriter {
+  private Integer queueMaxAppsDefault;
+  private String queueMaxResourcesDefault;
+  private Integer userMaxAppsDefault;
+  private Double queueMaxAMShareDefault;
+  private Integer defaultMinSharePreemptionTimeout;
+  private Integer defaultFairSharePreemptionTimeout;
+  private Double defaultFairSharePreemptionThreshold;
+  private String defaultQueueSchedulingPolicy;
+  private List<AllocationFileQueue> queues = new ArrayList<>();
+  private UserSettings userSettings;
+
+  private AllocationFileWriter() {
+  }
+
+  public static AllocationFileWriter create() {
+    return new AllocationFileWriter();
+  }
+
+  public AllocationFileSimpleQueueBuilder queue(String queueName) {
+    return new AllocationFileSimpleQueueBuilder(this, queueName);
+  }
+
+  public AllocationFileWriter queueMaxAppsDefault(int value) {
+    this.queueMaxAppsDefault = value;
+    return this;
+  }
+
+  public AllocationFileWriter queueMaxResourcesDefault(String value) {
+    this.queueMaxResourcesDefault = value;
+    return this;
+  }
+
+  public AllocationFileWriter userMaxAppsDefault(int value) {
+    this.userMaxAppsDefault = value;
+    return this;
+  }
+
+  public AllocationFileWriter queueMaxAMShareDefault(double value) {
+    this.queueMaxAMShareDefault = value;
+    return this;
+  }
+
+  public AllocationFileWriter defaultMinSharePreemptionTimeout(int value) {
+    this.defaultMinSharePreemptionTimeout = value;
+    return this;
+  }
+
+  public AllocationFileWriter defaultFairSharePreemptionTimeout(int value) {
+    this.defaultFairSharePreemptionTimeout = value;
+    return this;
+  }
+
+  public AllocationFileWriter defaultFairSharePreemptionThreshold(
+      double value) {
+    this.defaultFairSharePreemptionThreshold = value;
+    return this;
+  }
+
+  public AllocationFileWriter defaultQueueSchedulingPolicy(String value) {
+    this.defaultQueueSchedulingPolicy = value;
+    return this;
+  }
+
+  public UserSettings.Builder userSettings(String username) {
+    return new UserSettings.Builder(this, username);
+  }
+
+  void addQueue(AllocationFileQueue queue) {
+    this.queues.add(queue);
+  }
+
+  void setUserSettings(UserSettings userSettings) {
+    this.userSettings = userSettings;
+  }
+
+  static void printQueues(PrintWriter pw, List<AllocationFileQueue> queues) {
+    for (AllocationFileQueue queue : queues) {
+      pw.println(queue.render());
+    }
+  }
+
+  private void printUserSettings(PrintWriter pw) {
+    pw.println(userSettings.render());
+  }
+
+  static void addIfPresent(PrintWriter pw, String tag,
+      Supplier<String> supplier) {
+    if (supplier.get() != null) {
+      pw.println("<" + tag + ">" + supplier.get() + "</" + tag + ">");
+    }
+  }
+
+  static String createNumberSupplier(Object number) {
+    if (number != null) {
+      return number.toString();
+    }
+    return null;
+  }
+
+  private void writeHeader(PrintWriter pw) {
+    pw.println("<?xml version=\"1.0\"?>");
+    pw.println("<allocations>");
+  }
+
+  private void writeFooter(PrintWriter pw) {
+    pw.println("</allocations>");
+  }
+
+  public void writeToFile(String filename) {
+    PrintWriter pw;
+    try {
+      pw = new PrintWriter(new FileWriter(filename));
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    writeHeader(pw);
+    if (!queues.isEmpty()) {
+      printQueues(pw, queues);
+    }
+    if (userSettings != null) {
+      printUserSettings(pw);
+    }
+
+    addIfPresent(pw, "queueMaxAppsDefault",
+        () -> createNumberSupplier(queueMaxAppsDefault));
+    addIfPresent(pw, "queueMaxResourcesDefault",
+        () -> queueMaxResourcesDefault);
+    addIfPresent(pw, "userMaxAppsDefault",
+        () -> createNumberSupplier(userMaxAppsDefault));
+    addIfPresent(pw, "queueMaxAMShareDefault",
+        () -> createNumberSupplier(queueMaxAMShareDefault));
+    addIfPresent(pw, "defaultMinSharePreemptionTimeout",
+        () -> createNumberSupplier(defaultMinSharePreemptionTimeout));
+    addIfPresent(pw, "defaultFairSharePreemptionTimeout",
+        () -> createNumberSupplier(defaultFairSharePreemptionTimeout));
+    addIfPresent(pw, "defaultFairSharePreemptionThreshold",
+        () -> createNumberSupplier(defaultFairSharePreemptionThreshold));
+    addIfPresent(pw, "defaultQueueSchedulingPolicy",
+        () -> defaultQueueSchedulingPolicy);
+    writeFooter(pw);
+    pw.close();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/814d701d/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/UserSettings.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/UserSettings.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/UserSettings.java
new file mode 100644
index 0000000..7a5656e
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/allocationfile/UserSettings.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.allocationfile;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * Value class that stores user settings and can render data in XML format,
+ * see {@link #render()}.
+ */
+class UserSettings {
+  private final String username;
+  private final Integer maxRunningApps;
+
+  UserSettings(Builder builder) {
+    this.username = builder.username;
+    this.maxRunningApps = builder.maxRunningApps;
+  }
+
+  public String render() {
+    StringWriter sw = new StringWriter();
+    PrintWriter pw = new PrintWriter(sw);
+    addStartTag(pw);
+    AllocationFileWriter.addIfPresent(pw, "maxRunningApps",
+        () -> AllocationFileWriter.createNumberSupplier(maxRunningApps));
+    addEndTag(pw);
+    pw.close();
+
+    return sw.toString();
+  }
+
+  private void addStartTag(PrintWriter pw) {
+    pw.println("<user name=\"" + username + "\">");
+  }
+
+  private void addEndTag(PrintWriter pw) {
+    pw.println("</user>");
+  }
+
+  /**
+   * Builder class for {@link UserSettings}
+   */
+  public static class Builder {
+    private final AllocationFileWriter allocationFileWriter;
+    private final String username;
+    private Integer maxRunningApps;
+
+    Builder(AllocationFileWriter allocationFileWriter, String username) {
+      this.allocationFileWriter = allocationFileWriter;
+      this.username = username;
+    }
+
+    public Builder maxRunningApps(int value) {
+      this.maxRunningApps = value;
+      return this;
+    }
+
+    public AllocationFileWriter build() {
+      UserSettings userSettings = new UserSettings(this);
+      allocationFileWriter.setUserSettings(userSettings);
+
+      return allocationFileWriter;
+    }
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message