当前位置: 首页>>代码示例>>Java>>正文


Java TwillController.awaitTerminated方法代码示例

本文整理汇总了Java中org.apache.twill.api.TwillController.awaitTerminated方法的典型用法代码示例。如果您正苦于以下问题:Java TwillController.awaitTerminated方法的具体用法?Java TwillController.awaitTerminated怎么用?Java TwillController.awaitTerminated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.twill.api.TwillController的用法示例。


在下文中一共展示了TwillController.awaitTerminated方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTaskCompleted

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testTaskCompleted() throws InterruptedException, TimeoutException, ExecutionException {
  TwillRunner twillRunner = getTwillRunner();
  TwillController controller = twillRunner.prepare(new SleepTask(),
                                              ResourceSpecification.Builder.with()
                                                .setVirtualCores(1)
                                                .setMemory(512, ResourceSpecification.SizeUnit.MEGA)
                                                .setInstances(3).build())
                                          .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                          .start();

  final CountDownLatch runLatch = new CountDownLatch(1);
  controller.onRunning(new Runnable() {
    @Override
    public void run() {
      runLatch.countDown();
    }
  }, Threads.SAME_THREAD_EXECUTOR);

  Assert.assertTrue(runLatch.await(1, TimeUnit.MINUTES));
  controller.awaitTerminated(1, TimeUnit.MINUTES);
  Assert.assertEquals(ServiceController.TerminationStatus.SUCCEEDED, controller.getTerminationStatus());
}
 
开发者ID:apache,项目名称:twill,代码行数:24,代码来源:TaskCompletedTestRun.java

示例2: testInitFail

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testInitFail() throws InterruptedException, ExecutionException, TimeoutException {
  TwillRunner runner = getTwillRunner();
  final CountDownLatch logLatch = new CountDownLatch(1);

  // Verify that it receives the exception log entry that thrown when runnable initialize
  LogHandler logVerifyHandler = new LogHandler() {
    @Override
    public void onLog(LogEntry logEntry) {
      if (logEntry.getMessage().endsWith("exited abnormally with state COMPLETE, exit code 10.")) {
        logLatch.countDown();
      }
    }
  };

  TwillController controller = runner
    .prepare(new InitFailRunnable())
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
    .addLogHandler(logVerifyHandler)
    .start();

  controller.awaitTerminated(2, TimeUnit.MINUTES);
  Assert.assertTrue(logLatch.await(10, TimeUnit.SECONDS));
}
 
开发者ID:apache,项目名称:twill,代码行数:25,代码来源:InitializeFailTestRun.java

示例3: testKilled

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testKilled() throws IOException, InterruptedException, TimeoutException, ExecutionException {
  // Create a parent folder to be written by EventHandler
  File parentFolder = TMP_FOLDER.newFolder();
  parentFolder.setWritable(true, false);
  TwillController controller = getTwillRunner().prepare(new SleepApplication(parentFolder.getAbsolutePath()))
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .start();
  // Wait for the runnable to run and create runFile within 120 secs
  File runFile = new File(parentFolder, RUN_FILE);
  Stopwatch stopwatch = new Stopwatch().start();
  while (!runFile.exists() && stopwatch.elapsedTime(TimeUnit.SECONDS) < 120) {
    TimeUnit.SECONDS.sleep(1);
  }
  Assert.assertTrue(runFile.exists());
  // Terminate the app once the runnable runs
  controller.terminate();
  controller.awaitTerminated(120, TimeUnit.SECONDS);
  // EventHandler#killed() method should be called to create a file
  Assert.assertTrue(new File(parentFolder.getAbsolutePath(), KILLED_FILE).exists());
  // EventHandler#completed() method should not be called
  Assert.assertFalse(new File(parentFolder.getAbsolutePath(), COMPLETED_FILE).exists());
  // EventHandler#aborted() method should not be called
  Assert.assertFalse(new File(parentFolder.getAbsolutePath(), ABORTED_FILE).exists());
}
 
开发者ID:apache,项目名称:twill,代码行数:26,代码来源:EventHandlerTestRun.java

示例4: testProvisionTimeout

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testProvisionTimeout() throws InterruptedException, ExecutionException, TimeoutException, IOException {
  TwillRunner runner = getTwillRunner();
  // Create a parent folder to be written by EventHandler#aborted()
  File parentFolder = TMP_FOLDER.newFolder();
  parentFolder.setWritable(true, false);
  TwillController controller = runner.prepare(new TimeoutApplication(parentFolder.getAbsolutePath()))
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                     .start();

  // The provision should failed in 30 seconds after AM started, which AM could took a while to start.
  // Hence we give 90 seconds max time here.
  try {
    controller.awaitTerminated(90, TimeUnit.SECONDS);
    // EventHandler#aborted() method should be called to create a file
    Assert.assertTrue(new File(parentFolder.getAbsolutePath(), ABORTED_FILE).exists());
    String[] abortedFiles = parentFolder.list();
    Assert.assertNotNull(abortedFiles);
    Assert.assertEquals(1, abortedFiles.length);
  } finally {
    // If it timeout, kill the app as cleanup.
    controller.kill();
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:25,代码来源:ProvisionTimeoutTestRun.java

示例5: maxRetriesRun

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
private void maxRetriesRun(final int instances) throws TimeoutException, ExecutionException {
  TwillRunner runner = getTwillRunner();
  final int maxRetries = 3;
  final AtomicInteger retriesSeen = new AtomicInteger(0);

  ResourceSpecification resource = ResourceSpecification.Builder.with().setVirtualCores(1)
    .setMemory(512, ResourceSpecification.SizeUnit.MEGA).setInstances(instances).build();

  TwillController controller = runner.prepare(new FailingServer(), resource)
    .withMaxRetries(FailingServer.class.getSimpleName(), maxRetries)
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .addLogHandler(new LogHandler() {
      @Override
      public void onLog(LogEntry logEntry) {
        if (logEntry.getMessage().contains("retries for instance")) {
          retriesSeen.incrementAndGet();
        }
      }
    })
    .start();

  controller.awaitTerminated(2, TimeUnit.MINUTES);
  Assert.assertEquals(maxRetries * instances, retriesSeen.get());
}
 
开发者ID:apache,项目名称:twill,代码行数:25,代码来源:MaxRetriesTestRun.java

示例6: main

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
public static void main(String[] args) {
  if (args.length < 1) {
    System.err.println("Arguments format: <host:port of zookeeper server>");
    System.exit(1);
  }

  String zkStr = args[0];
  YarnConfiguration yarnConfiguration = new YarnConfiguration();
  final TwillRunnerService twillRunner = new YarnTwillRunnerService(yarnConfiguration, zkStr);
  twillRunner.start();

  String yarnClasspath =
    yarnConfiguration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH,
                          Joiner.on(",").join(YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
  List<String> applicationClassPaths = Lists.newArrayList();
  Iterables.addAll(applicationClassPaths, Splitter.on(",").split(yarnClasspath));
  final TwillController controller = twillRunner.prepare(new HelloWorldRunnable())
      .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
      .withApplicationClassPaths(applicationClassPaths)
      .withBundlerClassAcceptor(new HadoopClassExcluder())
      .start();

  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      try {
        Futures.getUnchecked(controller.terminate());
      } finally {
        twillRunner.stop();
      }
    }
  });

  try {
    controller.awaitTerminated();
  } catch (ExecutionException e) {
    e.printStackTrace();
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:40,代码来源:HelloWorld.java

示例7: testComplete

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testComplete() throws InterruptedException, ExecutionException, TimeoutException, IOException {
  // Create a parent folder to be written by EventHandler
  File parentFolder = TMP_FOLDER.newFolder();
  parentFolder.setWritable(true, false);
  TwillController controller = getTwillRunner().prepare(new CompleteApplication(parentFolder.getAbsolutePath()))
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .withApplicationArguments(parentFolder.getAbsolutePath())
    .start();

  // Wait for the app to complete within 120 seconds.
  controller.awaitTerminated(120, TimeUnit.SECONDS);
  // EventHandler#started() method should be called to create a file
  Assert.assertTrue(new File(parentFolder.getAbsolutePath(), STARTED_FILE).exists());
  // CompleteRunnable#run() method should be called to create a file after EventHandler#started() method is called
  Assert.assertTrue(new File(parentFolder.getAbsolutePath(), RUN_FILE).exists());
  // EventHandler#containerLaunched(String, int, String) method should be called to create a folder
  Assert.assertTrue(new File(parentFolder.getAbsolutePath(), CONTAINER_LAUNCHED_FOLDER).exists());
  // EventHandler#containerStopped(String, int, String, int) method should be called to create a folder
  Assert.assertTrue(new File(parentFolder.getAbsolutePath(), CONTAINER_STOPPED_FOLDER).exists());
  // EventHandler#completed() method should be called to create a file
  Assert.assertTrue(new File(parentFolder.getAbsolutePath(), COMPLETED_FILE).exists());
  // EventHandler#killed() method should not be called
  Assert.assertFalse(new File(parentFolder.getAbsolutePath(), KILLED_FILE).exists());
  // EventHandler#aborted() method should not be called
  Assert.assertFalse(new File(parentFolder.getAbsolutePath(), ABORTED_FILE).exists());
  // Assert that containerLaunched and containerStopped are called for the same containers
  // for the same number of times
  String[] containerLaunchedFiles = new File(parentFolder.getAbsolutePath(), CONTAINER_LAUNCHED_FOLDER).list();
  String[] containerStoppedFiles = new File(parentFolder.getAbsolutePath(), CONTAINER_STOPPED_FOLDER).list();
  Assert.assertEquals(containerLaunchedFiles.length, containerStoppedFiles.length);
  Assert.assertTrue(Arrays.asList(containerLaunchedFiles).containsAll(Arrays.asList(containerStoppedFiles)));
}
 
开发者ID:apache,项目名称:twill,代码行数:34,代码来源:EventHandlerTestRun.java

示例8: testAppSessionExpire

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testAppSessionExpire() throws InterruptedException, ExecutionException, TimeoutException {
  TwillRunner runner = getTwillRunner();
  TwillController controller = runner.prepare(new SleepRunnable(600))
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                     .start();

  final CountDownLatch runLatch = new CountDownLatch(1);
  controller.onRunning(new Runnable() {
    @Override
    public void run() {
      runLatch.countDown();
    }
  }, Threads.SAME_THREAD_EXECUTOR);

  // Wait for application running
  Assert.assertTrue(runLatch.await(60, TimeUnit.SECONDS));

  // Find the app master ZK session and expire it two times, 10 seconds apart.
  for (int i = 0; i < 2; i++) {
    Assert.assertTrue(expireAppMasterZKSession(controller, 10, TimeUnit.SECONDS));

    try {
      controller.awaitTerminated(10, TimeUnit.SECONDS);
      Assert.fail("Unexpected application termination.");
    } catch (TimeoutException e) {
      // OK, expected.
    }
  }

  controller.terminate().get(120, TimeUnit.SECONDS);
}
 
开发者ID:apache,项目名称:twill,代码行数:33,代码来源:SessionExpireTestRun.java

示例9: testControllerBefore

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testControllerBefore() throws InterruptedException, ExecutionException, TimeoutException {
  InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
  zkServer.startAndWait();

  LOG.info("ZKServer: " + zkServer.getConnectionStr());
  try {
    RunId runId = RunIds.generate();
    ZKClientService zkClientService = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClientService.startAndWait();

    final CountDownLatch runLatch = new CountDownLatch(1);
    TwillController controller = getController(zkClientService, "testControllerBefore", runId);
    controller.onRunning(new Runnable() {
      @Override
      public void run() {
        runLatch.countDown();
      }
    }, Threads.SAME_THREAD_EXECUTOR);

    Service service = createService(zkClientService, runId);
    service.start();

    Assert.assertTrue(runLatch.await(2, TimeUnit.SECONDS));

    try {
      controller.awaitTerminated(2, TimeUnit.SECONDS);
      Assert.fail("Service should not be terminated");
    } catch (TimeoutException e) {
      // Expected
    }

    service.stop();
    controller.awaitTerminated(120, TimeUnit.SECONDS);

  } finally {
    zkServer.stopAndWait();
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:40,代码来源:ControllerTest.java

示例10: startApp

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
/**
 * Start an instance of the {@link PeriodicNotificationTwillApp}.
 *
 * @param interactive - If true, this method will block until the user terminates this JVM, at which point the
 *            {@link PeriodicNotificationTwillApp} on the YARN cluster will also be terminated. If false, this
 *            method will return after startup.
 */
public void startApp(final boolean interactive) {
    final String yarnClasspath = yarnConfiguration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH,
            Joiner.on(",").join(YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
    final List<String> applicationClassPaths = Lists.newArrayList();
    Iterables.addAll(applicationClassPaths, Splitter.on(",").split(yarnClasspath));
    final TwillController controller = twillRunner
            .prepare(new PeriodicNotificationTwillApp(configFile))
            .addLogHandler(new PrinterLogHandler(new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true)))
            .withApplicationClassPaths(applicationClassPaths)
            //.withApplicationArguments(args)
            //.withArguments(runnableName, args)
            // .withBundlerClassAcceptor(new HadoopClassExcluder())
            .start();

    final ResourceReport r = getResourceReport(controller, 5, TimeUnit.MINUTES);
    LOG.info("Received ResourceReport: {}", r);
    LOG.info("{} started successfully!", PeriodicNotificationTwillApp.APPLICATION_NAME);

    if(interactive) {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                try {
                    Futures.getUnchecked(controller.terminate());
                } finally {
                    twillRunner.stop();
                }
            }
        });

        try {
            LOG.info("{} waiting termination by user.  Type ctrl-c to terminate.", PeriodicNotificationTwillApp.class.getSimpleName());
            controller.awaitTerminated();
        } catch (final ExecutionException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:46,代码来源:PeriodicNotificationTwillRunner.java

示例11: main

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
public static void main(String[] args) {
  if (args.length < 3) {
    System.err.println("Arguments format: <host:port of zookeeper server>"
                         + " <bundle jar path> <main class name> <extra args>");
    System.exit(1);
  }

  String zkStr = args[0];
  BundledJarRunner.Arguments arguments = new BundledJarRunner.Arguments(
          args[1], "/lib", args[2], Arrays.copyOfRange(args, 3, args.length));

  File jarFile = new File(arguments.getJarFileName());
  Preconditions.checkState(jarFile.exists());
  Preconditions.checkState(jarFile.canRead());

  final TwillRunnerService twillRunner = new YarnTwillRunnerService(new YarnConfiguration(), zkStr);
  twillRunner.start();


  final TwillController controller = twillRunner.prepare(
    new ExampleBundledJarApp(jarFile.getName(), jarFile.toURI()))
    .withArguments("BundledJarRunnable", arguments.toArray())
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .start();

  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      try {
        Futures.getUnchecked(controller.terminate());
      } finally {
        twillRunner.stop();
      }
    }
  });

  try {
    controller.awaitTerminated();
  } catch (ExecutionException e) {
    LOG.error("Error", e);
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:43,代码来源:BundledJarExample.java


注:本文中的org.apache.twill.api.TwillController.awaitTerminated方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。