• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TwillController类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: stopClusterAsync

import org.apache.twill.api.TwillController; //导入依赖的package包/类
private void stopClusterAsync(Cluster cluster) throws YarnProvisioningHandlingException {
  TwillController controller = getTwillControllerHelper(cluster);
  if (cluster.getState() == ClusterState.STOPPED || cluster.getState() == ClusterState.FAILED) {
    // nothing to do - probably termination routine was called already
    return;
  }
  if (controller == null) {
    if (cluster.getState() != ClusterState.STOPPED && cluster.getState() != ClusterState.FAILED) {
      logger.warn("Either cluster is already stopped or YarnTwillRunnerService was not initialized yet. You may want to try again");
      cluster.setState(ClusterState.STOPPED);
    }
    return;
  }
  // async call
  cluster.setState(ClusterState.STOPPING);
  controller.terminate();
  return;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:19,代码来源:YarnService.java


示例2: getTwillControllerHelper

import org.apache.twill.api.TwillController; //导入依赖的package包/类
private TwillController getTwillControllerHelper(Cluster cluster) throws YarnProvisioningHandlingException {
  RunId runId = cluster.getRunId();
  if (runId == null) {
    return null;
  }

  TwillRunnerService twillService = getTwillService(cluster);
  if (twillService == null) {
    logger.error("YarnTwillRunnerService is null. Possibly was not instantiated yet");
    return null;
  }

  String applicationName = cluster.getClusterConfig().getName();
  if (applicationName == null) {
    applicationName = DacDaemonYarnApplication.YARN_APPLICATION_NAME_DEFAULT;
  }

  TwillController controller =  twillService.lookup(applicationName, RunIds.fromString(runId.getId()));
  initOnTerminatingThread(cluster,controller);

  return controller;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:YarnService.java


示例3: testStopCluster

import org.apache.twill.api.TwillController; //导入依赖的package包/类
@Test
public void testStopCluster() throws Exception {
  assumeNonMaprProfile();

  Cluster myCluster = createCluster();
  myCluster.setState(ClusterState.RUNNING);

  YarnController controller = Mockito.mock(YarnController.class);
  YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class));

  TwillController twillController = Mockito.mock(TwillController.class);
  RunId runId = RunIds.generate();

  when(controller.startCluster(any(YarnConfiguration.class), eq(myCluster.getClusterConfig().getSubPropertyList())))
    .thenReturn(twillController);
  when(twillController.getRunId()).thenReturn(runId);

  myCluster.setRunId(new com.dremio.provision.RunId(runId.getId()));
  yarnService.stopCluster(myCluster);

  assertEquals(ClusterState.STOPPED, myCluster.getState());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:TestYarnService.java


示例4: testDistributedShell

import org.apache.twill.api.TwillController; //导入依赖的package包/类
@Ignore
@Test
public void testDistributedShell() throws InterruptedException {
  TwillRunner twillRunner = getTwillRunner();

  TwillController controller = twillRunner.prepare(new DistributedShell("pwd", "ls -al"))
                                          .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
                                          .start();

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

  Assert.assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
}
 
开发者ID:apache,项目名称:twill,代码行数:20,代码来源:DistributeShellTestRun.java


示例5: waitForDebugPort

import org.apache.twill.api.TwillController; //导入依赖的package包/类
private boolean waitForDebugPort(TwillController controller, String runnable, int timeLimit)
  throws InterruptedException {
  long millis = 0;
  while (millis < 1000 * timeLimit) {
    ResourceReport report = controller.getResourceReport();
    if (report == null || report.getRunnableResources(runnable) == null) {
      continue;
    }
    for (TwillRunResources resources : report.getRunnableResources(runnable)) {
      if (resources.getDebugPort() != null) {
        return true;
      }
    }
    TimeUnit.MILLISECONDS.sleep(100);
    millis += 100;
  }
  return false;
}
 
开发者ID:apache,项目名称:twill,代码行数:19,代码来源:DebugTestRun.java


示例6: testDebugPortOneRunnable

import org.apache.twill.api.TwillController; //导入依赖的package包/类
@Test
public void testDebugPortOneRunnable() throws Exception {
  YarnTwillRunnerService runner = getTwillRunner();
  runner.start();

  TwillController controller = runner.prepare(new DummyApplication())
                                     .enableDebugging("r1")
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
                                     .start();
  final CountDownLatch running = new CountDownLatch(1);
  controller.onRunning(new Runnable() {
    @Override
    public void run() {
      running.countDown();
    }
  }, Threads.SAME_THREAD_EXECUTOR);

  Assert.assertTrue(running.await(120, TimeUnit.SECONDS));
  Assert.assertTrue(waitForDebugPort(controller, "r1", 30));
  controller.terminate().get(120, TimeUnit.SECONDS);
  // Sleep a bit before exiting.
  TimeUnit.SECONDS.sleep(2);
}
 
开发者ID:apache,项目名称:twill,代码行数:24,代码来源:DebugTestRun.java


示例7: testDebugPortAllRunnables

import org.apache.twill.api.TwillController; //导入依赖的package包/类
@Test
public void testDebugPortAllRunnables() throws Exception {
  YarnTwillRunnerService runner = getTwillRunner();
  runner.start();

  TwillController controller = runner.prepare(new DummyApplication())
                                     .enableDebugging()
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
                                     .start();
  final CountDownLatch running = new CountDownLatch(1);
  controller.onRunning(new Runnable() {
    @Override
    public void run() {
      running.countDown();
    }
  }, Threads.SAME_THREAD_EXECUTOR);

  Assert.assertTrue(running.await(120, TimeUnit.SECONDS));
  Assert.assertTrue(waitForDebugPort(controller, "r1", 30));
  Assert.assertTrue(waitForDebugPort(controller, "r2", 30));
  controller.terminate().get(120, TimeUnit.SECONDS);
  // Sleep a bit before exiting.
  TimeUnit.SECONDS.sleep(2);
}
 
开发者ID:apache,项目名称:twill,代码行数:25,代码来源:DebugTestRun.java


示例8: 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


示例9: testFailureComplete

import org.apache.twill.api.TwillController; //导入依赖的package包/类
@Test
public void testFailureComplete() throws TimeoutException, ExecutionException, InterruptedException {
  TwillRunner twillRunner = getTwillRunner();

  // Start the app with an invalid ClassLoader. This will cause the AM fails to start.
  TwillController controller = twillRunner.prepare(new SleepTask(),
                                                   ResourceSpecification.Builder.with()
                                                     .setVirtualCores(1)
                                                     .setMemory(512, ResourceSpecification.SizeUnit.MEGA)
                                                     .setInstances(1).build())
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .setClassLoader("InvalidClassLoader")
    .start();

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

  Assert.assertTrue(terminateLatch.await(2, TimeUnit.MINUTES));
  Assert.assertEquals(ServiceController.TerminationStatus.FAILED, controller.getTerminationStatus());
}
 
开发者ID:apache,项目名称:twill,代码行数:26,代码来源:TaskCompletedTestRun.java


示例10: 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


示例11: 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


示例12: testExtraOptions

import org.apache.twill.api.TwillController; //导入依赖的package包/类
@Test
public void testExtraOptions() throws InterruptedException, ExecutionException {
  // Start the testing app with jvm options at both global level as well as for the specific runnables.
  TwillController controller = getTwillRunner()
    .prepare(new JvmOptionsApplication())
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
    .setJVMOptions("-Dservice.name=default")
    .setJVMOptions("r2", "-Dservice.name=r2")
    .start();

  // For r1 and r3 will be using "default" as the service name.
  waitForSize(controller.discoverService("default"), 2, 120);
  // r2 will be use "r2" as the service name.
  waitForSize(controller.discoverService("r2"), 1, 120);

  controller.terminate().get();
}
 
开发者ID:apache,项目名称:twill,代码行数:18,代码来源:JvmOptionsTestRun.java


示例13: waitForLogLevel

import org.apache.twill.api.TwillController; //导入依赖的package包/类
private boolean waitForLogLevel(TwillController controller, String runnable, long timeout,
                                TimeUnit timeoutUnit, @Nullable LogEntry.Level expected) throws InterruptedException {

  Stopwatch stopwatch = new Stopwatch();
  stopwatch.start();
  do {
    ResourceReport report = controller.getResourceReport();
    if (report == null || report.getRunnableResources(runnable) == null) {
      continue;
    }
    for (TwillRunResources resources : report.getRunnableResources(runnable)) {
      LogEntry.Level level = resources.getLogLevels().get(Logger.ROOT_LOGGER_NAME);
      if (expected == level) {
         return true;
      }
    }
    TimeUnit.MILLISECONDS.sleep(100);
  } while (stopwatch.elapsedTime(timeoutUnit) < timeout);

  return false;
}
 
开发者ID:apache,项目名称:twill,代码行数:22,代码来源:LogLevelTestRun.java


示例14: waitForContainers

import org.apache.twill.api.TwillController; //导入依赖的package包/类
private void waitForContainers(TwillController controller, int count, long timeout, TimeUnit timeoutUnit)
  throws Exception {
  Stopwatch stopwatch = new Stopwatch();
  stopwatch.start();
  int yarnContainers = 0;
  int twillContainers = 0;
  do {
    if (controller.getResourceReport() != null) {
      yarnContainers =
        getApplicationResourceReport(controller.getResourceReport().getApplicationId()).getNumUsedContainers();
      twillContainers = getTwillContainersUsed(controller);
      if (yarnContainers == count && twillContainers == count) {
        return;
      }
    }
    TimeUnit.SECONDS.sleep(1);
  } while (stopwatch.elapsedTime(timeoutUnit) < timeout);

  throw new TimeoutException("Timeout reached while waiting for num containers to be " +  count +
                               ". Yarn containers = " + yarnContainers + ", Twill containers = " + twillContainers);
}
 
开发者ID:apache,项目名称:twill,代码行数:22,代码来源:RestartRunnableTestRun.java


示例15: waitForInstance

import org.apache.twill.api.TwillController; //导入依赖的package包/类
private void waitForInstance(TwillController controller, String runnable, String yarnInstanceId,
                             long timeout, TimeUnit timeoutUnit) throws InterruptedException, TimeoutException {
  Stopwatch stopwatch = new Stopwatch();
  stopwatch.start();
  do {
    ResourceReport report = controller.getResourceReport();
    if (report != null && report.getRunnableResources(runnable) != null) {
      for (TwillRunResources resources : report.getRunnableResources(runnable)) {
        if (resources.getContainerId().endsWith(yarnInstanceId)) {
          return;
        }
      }
    }
    TimeUnit.SECONDS.sleep(1);
  } while (stopwatch.elapsedTime(timeoutUnit) < timeout);

  throw new TimeoutException("Timeout reached while waiting for runnable " +
                               runnable + " instance " + yarnInstanceId);
}
 
开发者ID:apache,项目名称:twill,代码行数:20,代码来源:RestartRunnableTestRun.java


示例16: 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


示例17: 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


示例18: test

import org.apache.twill.api.TwillController; //导入依赖的package包/类
@Test
public void test() throws ExecutionException, InterruptedException, TimeoutException {
  TwillRunner runner = getTwillRunner();

  // Start the TestRunnable and make sure it is executed with the log message emitted.
  CountDownLatch logLatch = new CountDownLatch(1);
  TwillController controller = runner.prepare(new TestRunnable())
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .addLogHandler(logEntry -> {
      if ("Hello World".equals(logEntry.getMessage())) {
        logLatch.countDown();
      }
    })
    .start();

  Assert.assertTrue(logLatch.await(120, TimeUnit.SECONDS));
  controller.terminate().get(120, TimeUnit.SECONDS);
}
 
开发者ID:apache,项目名称:twill,代码行数:19,代码来源:Java8Test.java


示例19: stopApp

import org.apache.twill.api.TwillController; //导入依赖的package包/类
/**
 * Terminates all instances of the {@link PeriodicNotificationTwillApp} on the YARN cluster.
 */
public void stopApp() {
    LOG.info("Stopping any running instances...");

    int counter = 0;
    // It is possible that we have launched multiple instances of the app.  For now, stop them all, one at a time.
    for(final TwillController c : twillRunner.lookup(PeriodicNotificationTwillApp.APPLICATION_NAME)) {
        final ResourceReport report = c.getResourceReport();
        LOG.info("Attempting to stop {} with YARN ApplicationId: {} and Twill RunId: {}", PeriodicNotificationTwillApp.APPLICATION_NAME, report.getApplicationId(), c.getRunId());
        Futures.getUnchecked(c.terminate());
        LOG.info("Stopped {} with YARN ApplicationId: {} and Twill RunId: {}", PeriodicNotificationTwillApp.APPLICATION_NAME, report.getApplicationId(), c.getRunId());
        counter++;
    }

    LOG.info("Stopped {} instance(s) of {}", counter, PeriodicNotificationTwillApp.APPLICATION_NAME);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:19,代码来源:PeriodicNotificationTwillRunner.java


示例20: getResourceReport

import org.apache.twill.api.TwillController; //导入依赖的package包/类
/**
 * Blocks until a non-null Resource report is returned.
 * @param controller - The controller to interrogate.
 * @param timeout - The maximum time to poll {@controller}.  Use -1 for infinite polling.
 * @param timeoutUnits - The units of {@code timeout}.
 * @return The ResourceReport for the application.
 * @throws IllegalStateException If a timeout occurs before a ResourceReport is returned.
 */
private ResourceReport getResourceReport(final TwillController controller, final long timeout, final TimeUnit timeoutUnits) {
    Preconditions.checkArgument(timeout >= -1, "timeout cannot be less than -1");
    final long timeoutMillis = TimeUnit.MILLISECONDS.convert(timeout, timeoutUnits);
    final long sleepMillis = 1000; // how long to sleep between retrieval attempts.
    long totalElapsedMillis = 0;
    ResourceReport report = controller.getResourceReport();
    while (reportIsLoading(report)) {
        try {
            Thread.sleep(sleepMillis);
        } catch (final InterruptedException e) {
            throw new IllegalStateException(e);
        }
        totalElapsedMillis += sleepMillis;
        if ((timeout != -1) && (totalElapsedMillis >= timeoutMillis)) {
            final String errorMessage = "Timeout while waiting for the Twill Application to start on YARN.  Total elapsed time: " + TimeUnit.SECONDS.convert(totalElapsedMillis, TimeUnit.MILLISECONDS) + "s.";
            LOG.error(errorMessage);
            throw new IllegalStateException(errorMessage);
        }
        if ((totalElapsedMillis % 5000) == 0) {
            LOG.info("Waiting for the Twill Application to start on YARN... Total elapsed time: {}s.", TimeUnit.SECONDS.convert(totalElapsedMillis, TimeUnit.MILLISECONDS));
        }
        report = controller.getResourceReport();
    }
    return report;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:34,代码来源:PeriodicNotificationTwillRunner.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GraphViewDataInterface类代码示例发布时间:2022-05-22
下一篇:
Java DoubleSumAggregator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap