Search in sources :

Example 1 with ResourceReport

use of com.continuuity.weave.api.ResourceReport in project weave by continuuity.

the class ResourceReportTestRun method testResourceReportWithFailingContainers.

@Test
public void testResourceReportWithFailingContainers() throws InterruptedException, IOException, TimeoutException, ExecutionException {
    WeaveRunner runner = YarnTestSuite.getWeaveRunner();
    ResourceSpecification resourceSpec = ResourceSpecification.Builder.with().setVirtualCores(1).setMemory(128, ResourceSpecification.SizeUnit.MEGA).setInstances(2).build();
    WeaveController controller = runner.prepare(new BuggyServer(), resourceSpec).addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).withApplicationArguments("echo").withArguments("BuggyServer", "echo2").start();
    final CountDownLatch running = new CountDownLatch(1);
    controller.addListener(new ServiceListenerAdapter() {

        @Override
        public void running() {
            running.countDown();
        }
    }, Threads.SAME_THREAD_EXECUTOR);
    Assert.assertTrue(running.await(30, TimeUnit.SECONDS));
    Iterable<Discoverable> echoServices = controller.discoverService("echo");
    Assert.assertTrue(YarnTestSuite.waitForSize(echoServices, 2, 60));
    // check that we have 2 runnables.
    ResourceReport report = controller.getResourceReport();
    Assert.assertEquals(2, report.getRunnableResources("BuggyServer").size());
    // cause a divide by 0 in one server
    Discoverable discoverable = echoServices.iterator().next();
    Socket socket = new Socket(discoverable.getSocketAddress().getAddress(), discoverable.getSocketAddress().getPort());
    try {
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
        writer.println("0");
    } finally {
        socket.close();
    }
    // takes some time for app master to find out the container completed...
    TimeUnit.SECONDS.sleep(5);
    // check that we have 1 runnable, not 2.
    report = controller.getResourceReport();
    Assert.assertEquals(1, report.getRunnableResources("BuggyServer").size());
    controller.stop().get(30, TimeUnit.SECONDS);
    // Sleep a bit before exiting.
    TimeUnit.SECONDS.sleep(2);
}
Also used : WeaveRunner(com.continuuity.weave.api.WeaveRunner) Discoverable(com.continuuity.weave.discovery.Discoverable) ServiceListenerAdapter(com.continuuity.weave.common.ServiceListenerAdapter) ResourceSpecification(com.continuuity.weave.api.ResourceSpecification) CountDownLatch(java.util.concurrent.CountDownLatch) PrinterLogHandler(com.continuuity.weave.api.logging.PrinterLogHandler) WeaveController(com.continuuity.weave.api.WeaveController) ResourceReport(com.continuuity.weave.api.ResourceReport) OutputStreamWriter(java.io.OutputStreamWriter) Socket(java.net.Socket) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with ResourceReport

use of com.continuuity.weave.api.ResourceReport in project weave by continuuity.

the class ResourceReportTestRun method testResourceReport.

@Test
public void testResourceReport() throws InterruptedException, ExecutionException, IOException, URISyntaxException, TimeoutException {
    WeaveRunner runner = YarnTestSuite.getWeaveRunner();
    WeaveController controller = runner.prepare(new ResourceApplication()).addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).withApplicationArguments("echo").withArguments("echo1", "echo1").withArguments("echo2", "echo2").start();
    final CountDownLatch running = new CountDownLatch(1);
    controller.addListener(new ServiceListenerAdapter() {

        @Override
        public void running() {
            running.countDown();
        }
    }, Threads.SAME_THREAD_EXECUTOR);
    Assert.assertTrue(running.await(30, TimeUnit.SECONDS));
    // wait for 3 echo servers to come up
    Iterable<Discoverable> echoServices = controller.discoverService("echo");
    Assert.assertTrue(YarnTestSuite.waitForSize(echoServices, 3, 60));
    ResourceReport report = controller.getResourceReport();
    // make sure resources for echo1 and echo2 are there
    Map<String, Collection<WeaveRunResources>> usedResources = report.getResources();
    Assert.assertEquals(2, usedResources.keySet().size());
    Assert.assertTrue(usedResources.containsKey("echo1"));
    Assert.assertTrue(usedResources.containsKey("echo2"));
    Collection<WeaveRunResources> echo1Resources = usedResources.get("echo1");
    // 2 instances of echo1
    Assert.assertEquals(2, echo1Resources.size());
    // TODO: check cores after hadoop-2.1.0
    for (WeaveRunResources resources : echo1Resources) {
        Assert.assertEquals(128, resources.getMemoryMB());
    }
    Collection<WeaveRunResources> echo2Resources = usedResources.get("echo2");
    // 2 instances of echo1
    Assert.assertEquals(1, echo2Resources.size());
    // TODO: check cores after hadoop-2.1.0
    for (WeaveRunResources resources : echo2Resources) {
        Assert.assertEquals(256, resources.getMemoryMB());
    }
    // Decrease number of instances of echo1 from 2 to 1
    controller.changeInstances("echo1", 1);
    echoServices = controller.discoverService("echo1");
    Assert.assertTrue(YarnTestSuite.waitForSize(echoServices, 1, 60));
    report = controller.getResourceReport();
    // make sure resources for echo1 and echo2 are there
    usedResources = report.getResources();
    Assert.assertEquals(2, usedResources.keySet().size());
    Assert.assertTrue(usedResources.containsKey("echo1"));
    Assert.assertTrue(usedResources.containsKey("echo2"));
    echo1Resources = usedResources.get("echo1");
    // 1 instance of echo1 now
    Assert.assertEquals(1, echo1Resources.size());
    // TODO: check cores after hadoop-2.1.0
    for (WeaveRunResources resources : echo1Resources) {
        Assert.assertEquals(128, resources.getMemoryMB());
    }
    echo2Resources = usedResources.get("echo2");
    // 2 instances of echo1
    Assert.assertEquals(1, echo2Resources.size());
    // TODO: check cores after hadoop-2.1.0
    for (WeaveRunResources resources : echo2Resources) {
        Assert.assertEquals(256, resources.getMemoryMB());
    }
    controller.stop().get(30, TimeUnit.SECONDS);
    // Sleep a bit before exiting.
    TimeUnit.SECONDS.sleep(2);
}
Also used : WeaveRunner(com.continuuity.weave.api.WeaveRunner) Discoverable(com.continuuity.weave.discovery.Discoverable) ServiceListenerAdapter(com.continuuity.weave.common.ServiceListenerAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) WeaveRunResources(com.continuuity.weave.api.WeaveRunResources) PrinterLogHandler(com.continuuity.weave.api.logging.PrinterLogHandler) Collection(java.util.Collection) WeaveController(com.continuuity.weave.api.WeaveController) ResourceReport(com.continuuity.weave.api.ResourceReport) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ResourceReport (com.continuuity.weave.api.ResourceReport)2 WeaveController (com.continuuity.weave.api.WeaveController)2 WeaveRunner (com.continuuity.weave.api.WeaveRunner)2 PrinterLogHandler (com.continuuity.weave.api.logging.PrinterLogHandler)2 ServiceListenerAdapter (com.continuuity.weave.common.ServiceListenerAdapter)2 Discoverable (com.continuuity.weave.discovery.Discoverable)2 PrintWriter (java.io.PrintWriter)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 ResourceSpecification (com.continuuity.weave.api.ResourceSpecification)1 WeaveRunResources (com.continuuity.weave.api.WeaveRunResources)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Socket (java.net.Socket)1 Collection (java.util.Collection)1