Search in sources :

Example 1 with FairSharePolicy

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy in project hadoop by apache.

the class TestSchedulingPolicy method testSchedulingPolicyViolation.

@Test
public void testSchedulingPolicyViolation() throws IOException {
    conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE);
    PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"root\">");
    out.println("<schedulingPolicy>fair</schedulingPolicy>");
    out.println("    <queue name=\"child1\">");
    out.println("    <schedulingPolicy>drf</schedulingPolicy>");
    out.println("    </queue>");
    out.println("    <queue name=\"child2\">");
    out.println("    <schedulingPolicy>fair</schedulingPolicy>");
    out.println("    </queue>");
    out.println("</queue>");
    out.println("<defaultQueueSchedulingPolicy>drf" + "</defaultQueueSchedulingPolicy>");
    out.println("</allocations>");
    out.close();
    scheduler.init(conf);
    FSQueue child1 = scheduler.getQueueManager().getQueue("child1");
    assertNull("Queue 'child1' should be null since its policy isn't allowed to" + " be 'drf' if its parent policy is 'fair'.", child1);
    // dynamic queue
    FSQueue dynamicQueue = scheduler.getQueueManager().getLeafQueue("dynamicQueue", true);
    assertNull("Dynamic queue should be null since it isn't allowed to be 'drf'" + " policy if its parent policy is 'fair'.", dynamicQueue);
    // Set child1 to 'fair' and child2 to 'drf', the reload the allocation file.
    out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"root\">");
    out.println("<schedulingPolicy>fair</schedulingPolicy>");
    out.println("    <queue name=\"child1\">");
    out.println("    <schedulingPolicy>fair</schedulingPolicy>");
    out.println("    </queue>");
    out.println("    <queue name=\"child2\">");
    out.println("    <schedulingPolicy>drf</schedulingPolicy>");
    out.println("    </queue>");
    out.println("</queue>");
    out.println("<defaultQueueSchedulingPolicy>drf" + "</defaultQueueSchedulingPolicy>");
    out.println("</allocations>");
    out.close();
    scheduler.reinitialize(conf, null);
    child1 = scheduler.getQueueManager().getQueue("child1");
    assertNotNull("Queue 'child1' should be not null since its policy is " + "allowed to be 'fair' if its parent policy is 'fair'.", child1);
    // Detect the policy violation of Child2, keep the original policy instead
    // of setting the new policy.
    FSQueue child2 = scheduler.getQueueManager().getQueue("child2");
    assertTrue("Queue 'child2' should be 'fair' since its new policy 'drf' " + "is not allowed.", child2.getPolicy() instanceof FairSharePolicy);
}
Also used : FairSharePolicy(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy) FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with FairSharePolicy

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy in project hadoop by apache.

the class TestSchedulingPolicy method testPolicyReinitilization.

@Test
public void testPolicyReinitilization() throws IOException {
    conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE);
    PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"root\">");
    out.println("<schedulingPolicy>fair</schedulingPolicy>");
    out.println("    <queue name=\"child1\">");
    out.println("    <schedulingPolicy>fair</schedulingPolicy>");
    out.println("    </queue>");
    out.println("    <queue name=\"child2\">");
    out.println("    <schedulingPolicy>fair</schedulingPolicy>");
    out.println("    </queue>");
    out.println("</queue>");
    out.println("</allocations>");
    out.close();
    scheduler.init(conf);
    // Set child1 to 'drf' which is not allowed, then reload the allocation file
    out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"root\">");
    out.println("<schedulingPolicy>fair</schedulingPolicy>");
    out.println("    <queue name=\"child1\">");
    out.println("    <schedulingPolicy>drf</schedulingPolicy>");
    out.println("    </queue>");
    out.println("    <queue name=\"child2\">");
    out.println("    <schedulingPolicy>fifo</schedulingPolicy>");
    out.println("    </queue>");
    out.println("</queue>");
    out.println("</allocations>");
    out.close();
    scheduler.reinitialize(conf, null);
    FSQueue child1 = scheduler.getQueueManager().getQueue("child1");
    assertTrue("Queue 'child1' should still be 'fair' since 'drf' isn't allowed" + " if its parent policy is 'fair'.", child1.getPolicy() instanceof FairSharePolicy);
    FSQueue child2 = scheduler.getQueueManager().getQueue("child2");
    assertTrue("Queue 'child2' should still be 'fair' there is a policy" + " violation while reinitialization.", child2.getPolicy() instanceof FairSharePolicy);
    // Set both child1 and root to 'drf', then reload the allocation file
    out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"root\">");
    out.println("<schedulingPolicy>drf</schedulingPolicy>");
    out.println("    <queue name=\"child1\">");
    out.println("    <schedulingPolicy>drf</schedulingPolicy>");
    out.println("    </queue>");
    out.println("    <queue name=\"child2\">");
    out.println("    <schedulingPolicy>fifo</schedulingPolicy>");
    out.println("    </queue>");
    out.println("</queue>");
    out.println("</allocations>");
    out.close();
    scheduler.reinitialize(conf, null);
    child1 = scheduler.getQueueManager().getQueue("child1");
    assertTrue("Queue 'child1' should be 'drf' since both 'root' and 'child1'" + " are 'drf'.", child1.getPolicy() instanceof DominantResourceFairnessPolicy);
    child2 = scheduler.getQueueManager().getQueue("child2");
    assertTrue("Queue 'child2' should still be 'fifo' there is no policy" + " violation while reinitialization.", child2.getPolicy() instanceof FifoPolicy);
}
Also used : FairSharePolicy(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy) FileWriter(java.io.FileWriter) FifoPolicy(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FifoPolicy) DominantResourceFairnessPolicy(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.DominantResourceFairnessPolicy) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with FairSharePolicy

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy in project hadoop by apache.

the class TestSchedulingPolicy method testFairShareComparatorTransitivity.

/**
   * Test whether {@link FairSharePolicy.FairShareComparator} is transitive.
   */
@Test
public void testFairShareComparatorTransitivity() {
    FairSharePolicy policy = new FairSharePolicy();
    Comparator<Schedulable> fairShareComparator = policy.getComparator();
    FairShareComparatorTester tester = new FairShareComparatorTester(fairShareComparator);
    tester.testTransitivity();
}
Also used : FairSharePolicy(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy) Test(org.junit.Test)

Aggregations

FairSharePolicy (org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FairSharePolicy)3 Test (org.junit.Test)3 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 DominantResourceFairnessPolicy (org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.DominantResourceFairnessPolicy)1 FifoPolicy (org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies.FifoPolicy)1