@Override public Future<? extends ServiceController> call() throws Exception { return delegate.terminate(); } });
@Override public Future<? extends ServiceController> call() throws Exception { return delegate.terminate(); } });
@Override protected final void doStop() throws Exception { stopRequested = true; Futures.getUnchecked(twillController.terminate()); }
@Override protected final void doStop() throws Exception { stopRequested = true; Futures.getUnchecked(twillController.terminate()); }
@Override public void run() { if (executor.isShutdown()) { return; } Thread.interrupted(); try { finalController.terminate().get(); LOG.warn("{} was terminated", Constants.Service.MASTER_SERVICES); } catch (InterruptedException e) { // Should never happen } catch (ExecutionException e) { LOG.error("{} was terminated due to failure", Constants.Service.MASTER_SERVICES, e.getCause()); } LOG.warn("Restarting {} with back-off", Constants.Service.MASTER_SERVICES); backoffRun(); }
@Override public void run() { try { Futures.getUnchecked(controller.terminate()); } finally { twillRunner.stop(); } } });
@Override public void run() { try { Futures.getUnchecked(controller.terminate()); } finally { twillRunner.stop(); } } });
@Override public void run() { try { Futures.getUnchecked(controller.terminate()); } finally { twillRunner.stop(); } } });
/** * 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); }
public void stop(FluoConfiguration config) throws InterruptedException, ExecutionException { checkIfInitialized(config); String twillId = verifyTwillId(config); TwillController controller = getTwillRunner(config) .lookup(getYarnApplicationName(config.getApplicationName()), RunIds.fromString(twillId)); if ((controller != null) && isReady(controller)) { System.out.print("Stopping Fluo '" + config.getApplicationName() + "' application " + getAppInfo(config) + "..."); controller.terminate().get(); System.out.println("DONE"); } else { System.out.println("Fluo '" + config.getApplicationName() + "' application " + getAppInfo(config) + " is already stopped."); } }
public void stop(FluoConfiguration config) throws InterruptedException, ExecutionException { checkIfInitialized(config); String twillId = verifyTwillId(config); TwillController controller = getTwillRunner(config) .lookup(getYarnApplicationName(config.getApplicationName()), RunIds.fromString(twillId)); if ((controller != null) && isReady(controller)) { System.out.print("Stopping Fluo '" + config.getApplicationName() + "' application " + getAppInfo(config) + "..."); controller.terminate().get(); System.out.println("DONE"); } else { System.out.println("Fluo '" + config.getApplicationName() + "' application " + getAppInfo(config) + " is already stopped."); } }
public void stop(FluoConfiguration config) throws InterruptedException, ExecutionException { checkIfInitialized(config); String twillId = verifyTwillId(config); TwillController controller = getTwillRunner(config).lookup(getYarnApplicationName(config.getApplicationName()), RunIds.fromString(twillId)); if ((controller != null) && isReady(controller)) { System.out.print("Stopping Fluo '" + config.getApplicationName() + "' application " + getAppInfo(config) + "..."); controller.terminate().get(); System.out.println("DONE"); } else { System.out.println("Fluo '" + config.getApplicationName() + "' application " + getAppInfo(config) + " is already stopped."); } }
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; }
/** * Test to verify exception is thrown in case a non-existent runnable is specified in a placement policy. */ @Test(expected = IllegalArgumentException.class) public void testNonExistentRunnable() throws InterruptedException, ExecutionException, TimeoutException { TwillRunner runner = getTwillRunner(); TwillController controller = runner.prepare(new FaultyApplication()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); controller.terminate().get(120, TimeUnit.SECONDS); }
@After public final void cleanupTest() { // Make sure all applications are stopped after a test case is executed, even it failed. TwillRunner twillRunner = TWILL_TESTER.getTwillRunner(); for (TwillRunner.LiveInfo liveInfo : twillRunner.lookupLive()) { for (TwillController controller : liveInfo.getControllers()) { try { controller.terminate().get(); } catch (Throwable t) { LOG.error("Failed to stop application {}", liveInfo.getApplicationName(), t); } } } }
/** * Test to verify exception is thrown in case a runnable is mentioned in more than one placement policy. */ @Test(expected = IllegalArgumentException.class) public void testPlacementPolicySpecification() throws InterruptedException, ExecutionException, TimeoutException { TwillRunner runner = getTwillRunner(); TwillController controller = runner.prepare(new BadApplication()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); controller.terminate().get(120, TimeUnit.SECONDS); }
@Test public void testCustomClassLoader() throws Exception { TwillController controller = getTwillRunner().prepare(new CustomClassLoaderRunnable()) .setClassLoader(CustomClassLoader.class.getName()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .setJVMOptions("-Dservice.port=54321") .setJVMOptions(CustomClassLoaderRunnable.class.getSimpleName(), "-Dservice.name=custom") .start(); Assert.assertTrue(waitForSize(controller.discoverService("custom"), 1, 120)); controller.terminate().get(); } }
@Test public void testServiceDiscovery() throws InterruptedException, ExecutionException, TimeoutException { TwillRunner twillRunner = getTwillRunner(); TwillController controller = twillRunner .prepare(new ServiceApplication()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("echo") .start(); ServiceDiscovered discovered = controller.discoverService("discovered"); Assert.assertTrue(waitForSize(discovered, 1, 120)); controller.terminate().get(); }
/** * Test for requesting different container size in different order. * It specifically test for workaround for YARN-314. */ @Test public void testContainerSize() throws InterruptedException, TimeoutException, ExecutionException { TwillRunner runner = getTwillRunner(); TwillController controller = runner.prepare(new SleepApp()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); try { ServiceDiscovered discovered = controller.discoverService("sleep"); Assert.assertTrue(waitForSize(discovered, 2, 120)); } finally { controller.terminate().get(120, TimeUnit.SECONDS); } }
@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(); }