Search in sources :

Example 1 with ResourceSpecification

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

the class FailureRestartTestRun method testFailureRestart.

@Test
public void testFailureRestart() throws Exception {
    WeaveRunner runner = YarnTestSuite.getWeaveRunner();
    ResourceSpecification resource = ResourceSpecification.Builder.with().setVirtualCores(1).setMemory(512, ResourceSpecification.SizeUnit.MEGA).setInstances(2).build();
    WeaveController controller = runner.prepare(new FailureRunnable(), resource).withApplicationArguments("failure").withArguments(FailureRunnable.class.getSimpleName(), "failure2").addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).start();
    Iterable<Discoverable> discoverables = controller.discoverService("failure");
    Assert.assertTrue(YarnTestSuite.waitForSize(discoverables, 2, 60));
    // Make sure we see the right instance IDs
    Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));
    // Kill server with instanceId = 0
    controller.sendCommand(FailureRunnable.class.getSimpleName(), Command.Builder.of("kill0").build());
    // Do a shot sleep, make sure the runnable is killed.
    TimeUnit.SECONDS.sleep(5);
    Assert.assertTrue(YarnTestSuite.waitForSize(discoverables, 2, 60));
    // Make sure we see the right instance IDs
    Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));
    controller.stopAndWait();
}
Also used : WeaveRunner(com.continuuity.weave.api.WeaveRunner) Discoverable(com.continuuity.weave.discovery.Discoverable) PrinterLogHandler(com.continuuity.weave.api.logging.PrinterLogHandler) WeaveController(com.continuuity.weave.api.WeaveController) ResourceSpecification(com.continuuity.weave.api.ResourceSpecification) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with ResourceSpecification

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

the class RuntimeSpecificationCodec method deserialize.

@Override
public RuntimeSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String name = jsonObj.get("name").getAsString();
    WeaveRunnableSpecification runnable = context.deserialize(jsonObj.get("runnable"), WeaveRunnableSpecification.class);
    ResourceSpecification resources = context.deserialize(jsonObj.get("resources"), ResourceSpecification.class);
    Collection<LocalFile> files = context.deserialize(jsonObj.get("files"), new TypeToken<Collection<LocalFile>>() {
    }.getType());
    return new DefaultRuntimeSpecification(name, runnable, resources, files);
}
Also used : LocalFile(com.continuuity.weave.api.LocalFile) DefaultRuntimeSpecification(com.continuuity.weave.internal.DefaultRuntimeSpecification) TypeToken(com.google.common.reflect.TypeToken) JsonObject(com.google.gson.JsonObject) ResourceSpecification(com.continuuity.weave.api.ResourceSpecification) WeaveRunnableSpecification(com.continuuity.weave.api.WeaveRunnableSpecification)

Example 3 with ResourceSpecification

use of com.continuuity.weave.api.ResourceSpecification 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 4 with ResourceSpecification

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

the class ResourceReportTestRun method testRunnablesGetAllowedResourcesInEnv.

@Test
public void testRunnablesGetAllowedResourcesInEnv() throws InterruptedException, IOException, TimeoutException, ExecutionException {
    WeaveRunner runner = YarnTestSuite.getWeaveRunner();
    ResourceSpecification resourceSpec = ResourceSpecification.Builder.with().setVirtualCores(1).setMemory(2048, ResourceSpecification.SizeUnit.MEGA).setInstances(1).build();
    WeaveController controller = runner.prepare(new EnvironmentEchoServer(), resourceSpec).addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).withApplicationArguments("envecho").withArguments("EnvironmentEchoServer", "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> envEchoServices = controller.discoverService("envecho");
    Assert.assertTrue(YarnTestSuite.waitForSize(envEchoServices, 1, 30));
    // TODO: check virtual cores once yarn adds the ability
    Map<String, String> expectedValues = Maps.newHashMap();
    expectedValues.put(EnvKeys.YARN_CONTAINER_MEMORY_MB, "2048");
    expectedValues.put(EnvKeys.WEAVE_INSTANCE_COUNT, "1");
    // check environment of the runnable.
    Discoverable discoverable = envEchoServices.iterator().next();
    for (Map.Entry<String, String> expected : expectedValues.entrySet()) {
        Socket socket = new Socket(discoverable.getSocketAddress().getHostName(), discoverable.getSocketAddress().getPort());
        try {
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
            LineReader reader = new LineReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
            writer.println(expected.getKey());
            Assert.assertEquals(expected.getValue(), reader.readLine());
        } finally {
            socket.close();
        }
    }
    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) InputStreamReader(java.io.InputStreamReader) ServiceListenerAdapter(com.continuuity.weave.common.ServiceListenerAdapter) ResourceSpecification(com.continuuity.weave.api.ResourceSpecification) CountDownLatch(java.util.concurrent.CountDownLatch) LineReader(com.google.common.io.LineReader) PrinterLogHandler(com.continuuity.weave.api.logging.PrinterLogHandler) WeaveController(com.continuuity.weave.api.WeaveController) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map) Socket(java.net.Socket) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ResourceSpecification (com.continuuity.weave.api.ResourceSpecification)4 WeaveController (com.continuuity.weave.api.WeaveController)3 WeaveRunner (com.continuuity.weave.api.WeaveRunner)3 PrinterLogHandler (com.continuuity.weave.api.logging.PrinterLogHandler)3 Discoverable (com.continuuity.weave.discovery.Discoverable)3 PrintWriter (java.io.PrintWriter)3 Test (org.junit.Test)3 ServiceListenerAdapter (com.continuuity.weave.common.ServiceListenerAdapter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Socket (java.net.Socket)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LocalFile (com.continuuity.weave.api.LocalFile)1 ResourceReport (com.continuuity.weave.api.ResourceReport)1 WeaveRunnableSpecification (com.continuuity.weave.api.WeaveRunnableSpecification)1 DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)1 LineReader (com.google.common.io.LineReader)1 TypeToken (com.google.common.reflect.TypeToken)1 JsonObject (com.google.gson.JsonObject)1 InputStreamReader (java.io.InputStreamReader)1 Map (java.util.Map)1