Search in sources :

Example 81 with FileWriter

use of java.io.FileWriter in project hadoop by apache.

the class TestFairSchedulerPreemption method writeAllocFile.

private void writeAllocFile() throws IOException {
    /*
     * Queue hierarchy:
     * root
     * |--- preemptable
     *      |--- child-1
     *      |--- child-2
     * |--- preemptable-sibling
     * |--- nonpreemptible
     *      |--- child-1
     *      |--- child-2
     */
    PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"preemptable\">");
    writePreemptionParams(out);
    // Child-1
    out.println("<queue name=\"child-1\">");
    writeResourceParams(out);
    out.println("</queue>");
    // Child-2
    out.println("<queue name=\"child-2\">");
    writeResourceParams(out);
    out.println("</queue>");
    // end of preemptable queue
    out.println("</queue>");
    out.println("<queue name=\"preemptable-sibling\">");
    writePreemptionParams(out);
    out.println("</queue>");
    // Queue with preemption disallowed
    out.println("<queue name=\"nonpreemptable\">");
    out.println("<allowPreemptionFrom>false" + "</allowPreemptionFrom>");
    writePreemptionParams(out);
    // Child-1
    out.println("<queue name=\"child-1\">");
    writeResourceParams(out);
    out.println("</queue>");
    // Child-2
    out.println("<queue name=\"child-2\">");
    writeResourceParams(out);
    out.println("</queue>");
    // end of nonpreemptable queue
    out.println("</queue>");
    if (drf) {
        out.println("<defaultQueueSchedulingPolicy>drf" + "</defaultQueueSchedulingPolicy>");
    }
    out.println("</allocations>");
    out.close();
    assertTrue("Allocation file does not exist, not running the test", ALLOC_FILE.exists());
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 82 with FileWriter

use of java.io.FileWriter in project hadoop by apache.

the class TestQueueManagerRealScheduler method writeAllocFile.

private void writeAllocFile(int defaultFairShareTimeout, int fairShareTimeout) throws IOException {
    PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"default\">");
    out.println("</queue>");
    out.println("<queue name=\"queueA\">");
    out.println("</queue>");
    out.println("<queue name=\"queueB\">");
    out.println("<queue name=\"queueB1\">");
    out.println("<minSharePreemptionTimeout>5</minSharePreemptionTimeout>");
    out.println("</queue>");
    out.println("<queue name=\"queueB2\">");
    out.println("</queue>");
    out.println("</queue>");
    out.println("<queue name=\"queueC\">");
    out.println("</queue>");
    out.println("<defaultMinSharePreemptionTimeout>15" + "</defaultMinSharePreemptionTimeout>");
    out.println("<defaultFairSharePreemptionTimeout>" + +defaultFairShareTimeout + "</defaultFairSharePreemptionTimeout>");
    out.println("<fairSharePreemptionTimeout>" + fairShareTimeout + "</fairSharePreemptionTimeout>");
    out.println("</allocations>");
    out.close();
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 83 with FileWriter

use of java.io.FileWriter 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 84 with FileWriter

use of java.io.FileWriter 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 85 with FileWriter

use of java.io.FileWriter in project hadoop by apache.

the class TestSchedulingPolicy method testFIFOPolicyOnlyForLeafQueues.

@Test
public void testFIFOPolicyOnlyForLeafQueues() 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("  <queue name=\"intermediate\">");
    out.println("    <schedulingPolicy>fifo</schedulingPolicy>");
    out.println("    <queue name=\"leaf\">");
    out.println("    <schedulingPolicy>fair</schedulingPolicy>");
    out.println("    </queue>");
    out.println("  </queue>");
    out.println("</queue>");
    out.println("</allocations>");
    out.close();
    scheduler.init(conf);
    FSQueue intermediate = scheduler.getQueueManager().getQueue("intermediate");
    assertNull("Queue 'intermediate' should be null since 'fifo' is only for " + "leaf queue.", intermediate);
    out = new PrintWriter(new FileWriter(ALLOC_FILE));
    out.println("<?xml version=\"1.0\"?>");
    out.println("<allocations>");
    out.println("<queue name=\"root\">");
    out.println("  <queue name=\"intermediate\">");
    out.println("    <schedulingPolicy>fair</schedulingPolicy>");
    out.println("    <queue name=\"leaf\">");
    out.println("    <schedulingPolicy>fifo</schedulingPolicy>");
    out.println("    </queue>");
    out.println("  </queue>");
    out.println("</queue>");
    out.println("</allocations>");
    out.close();
    scheduler.reinitialize(conf, null);
    assertNotNull(scheduler.getQueueManager().getQueue("intermediate"));
    FSQueue leaf = scheduler.getQueueManager().getQueue("intermediate.leaf");
    assertNotNull("Queue 'leaf' should be null since 'fifo' is only for " + "leaf queue.", leaf);
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

FileWriter (java.io.FileWriter)1776 File (java.io.File)1056 IOException (java.io.IOException)741 BufferedWriter (java.io.BufferedWriter)705 PrintWriter (java.io.PrintWriter)285 Test (org.junit.Test)222 Writer (java.io.Writer)162 FileReader (java.io.FileReader)121 BufferedReader (java.io.BufferedReader)107 ArrayList (java.util.ArrayList)101 FileNotFoundException (java.io.FileNotFoundException)68 Date (java.util.Date)61 Properties (java.util.Properties)61 FileOutputStream (java.io.FileOutputStream)58 HashMap (java.util.HashMap)53 StringWriter (java.io.StringWriter)50 Path (org.apache.hadoop.fs.Path)49 FileInputStream (java.io.FileInputStream)47 Map (java.util.Map)33 OutputStreamWriter (java.io.OutputStreamWriter)31