@Override public void failure(Service service) { manager.stopAsync(); } });
public void run() { // Give the services 5 seconds to stop to ensure that we are responsive to shutdown // requests. try { manager.stopAsync().awaitStopped(5, TimeUnit.SECONDS); } catch (TimeoutException timeout) { // stopping timed out } } });
private void stopServices() { if (this.serviceManager != null) { try { // Give the services 5 minutes to stop to ensure that we are responsive to shutdown requests this.serviceManager.stopAsync().awaitStopped(5, TimeUnit.MINUTES); } catch (TimeoutException te) { logger.error("Timeout in stopping the service manager", te); } } }
private void shutdownServices() { logger.info("SingleTaskRunner shutting down services."); this.serviceManager.stopAsync(); try { this.serviceManager.awaitStopped(1, TimeUnit.MINUTES); } catch (final TimeoutException e) { logger.error("Timeout waiting for services to shutdown.", e); } }
@Override public void run() { manager.stopAsync().awaitStopped(); } };
/** * Stops the {@link ApplicationLauncher} by stopping all associated services. */ @Override public synchronized void stop() throws ApplicationException { if (!this.hasStarted) { LOG.warn("ApplicationLauncher was never started"); return; } if (this.hasStopped) { LOG.warn("ApplicationLauncher has already stopped"); return; } this.hasStopped = true; LOG.info("Shutting down the application"); try { this.serviceManager.stopAsync().awaitStopped(this.stopTime, TimeUnit.SECONDS); } catch (TimeoutException te) { LOG.error("Timeout in stopping the service manager", te); } }
@Override public void close() throws IOException { try { // Stop all dependent services this.serviceManager.stopAsync().awaitStopped(5, TimeUnit.SECONDS); } catch (TimeoutException te) { LOG.warn("Timed out while waiting for the service manager to be stopped", te); } finally { super.close(); } }
@Override public void execute() throws IOException { LOG.info("Starting the clean-up steps."); try { serviceManager.stopAsync().awaitStopped(5, TimeUnit.SECONDS); } catch (TimeoutException te) { // Ignored } finally { if (jobMetrics.isPresent()) { try { jobMetrics.get().stopMetricsReporting(); } catch (Throwable throwable) { LOG.error("Failed to stop job metrics reporting.", throwable); } finally { GobblinMetrics.remove(jobMetrics.get().getName()); } } } } };
@AfterClass public void tearDown() throws TimeoutException, IOException { if (jobConfigDir != null) { FileUtils.forceDelete(new File(jobConfigDir)); } this.serviceManager.stopAsync().awaitStopped(30, TimeUnit.SECONDS); } }
@Override protected void shutDown() throws Exception { getLog().info("Shutting down driver ..."); super.shutDown(); if (null != _subservices) { getLog().info("Shutting down subservices ..."); _subservices.stopAsync(); _subservices.awaitStopped(getInstanceCfg().getShutdownTimeoutMs(), TimeUnit.MILLISECONDS); getLog().info("All subservices have been shutdown."); } }
@Override public void run() { String msg = "SIGNAL received. Shutting down."; LOG.info(msg); activityWriter.write(new Activity(msg, Main.class)); auditEventSender.success(AuditActor.system(nodeId), NODE_SHUTDOWN_INITIATE); gracefulShutdown.runWithoutExit(); serviceManager.stopAsync().awaitStopped(); } }
/** * This test is for a case where two Service.Listener callbacks for the same service would call * transitionService in the wrong order due to a race. Due to the fact that it is a race this test * isn't guaranteed to expose the issue, but it is at least likely to become flaky if the race * sneaks back in, and in this case flaky means something is definitely wrong. * * <p>Before the bug was fixed this test would fail at least 30% of the time. */ public void testTransitionRace() throws TimeoutException { for (int k = 0; k < 1000; k++) { List<Service> services = Lists.newArrayList(); for (int i = 0; i < 5; i++) { services.add(new SnappyShutdownService(i)); } ServiceManager manager = new ServiceManager(services); manager.startAsync().awaitHealthy(); manager.stopAsync().awaitStopped(1, TimeUnit.SECONDS); } }
@AfterClass public void tearDown() throws IOException { cleanUpDir(TESTDIR); try { this.specCompiler.getServiceManager().stopAsync().awaitStopped(5, TimeUnit.SECONDS); } catch (Exception e) { log.warn("Could not stop Service Manager"); } }
public void testDoCancelStart() throws TimeoutException { Service a = new AbstractService() { @Override protected void doStart() { // Never starts! } @Override protected void doCancelStart() { assertThat(state()).isEqualTo(Service.State.STOPPING); notifyStopped(); } @Override protected void doStop() { throw new AssertionError(); // Should not be called. } }; final ServiceManager manager = new ServiceManager(asList(a)); manager.startAsync(); manager.stopAsync(); manager.awaitStopped(10, TimeUnit.MILLISECONDS); assertThat(manager.servicesByState().keySet()).containsExactly(Service.State.TERMINATED); }
public void testTimeouts() throws Exception { Service a = new NoOpDelayedService(50); ServiceManager manager = new ServiceManager(asList(a)); manager.startAsync(); try { manager.awaitHealthy(1, TimeUnit.MILLISECONDS); fail(); } catch (TimeoutException expected) { } manager.awaitHealthy(5, SECONDS); // no exception thrown manager.stopAsync(); try { manager.awaitStopped(1, TimeUnit.MILLISECONDS); fail(); } catch (TimeoutException expected) { } manager.awaitStopped(5, SECONDS); // no exception thrown }
public void testFailStop() throws Exception { Service a = new NoOpService(); Service b = new FailStopService(); Service c = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b, c)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); manager.startAsync().awaitHealthy(); assertTrue(listener.healthyCalled); assertFalse(listener.stoppedCalled); manager.stopAsync().awaitStopped(); assertTrue(listener.stoppedCalled); assertEquals(ImmutableSet.of(b), listener.failedServices); assertState(manager, Service.State.FAILED, b); assertState(manager, Service.State.TERMINATED, a, c); }
public void testFailRun() throws Exception { Service a = new NoOpService(); Service b = new FailRunService(); ServiceManager manager = new ServiceManager(asList(a, b)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b); try { manager.startAsync().awaitHealthy(); fail(); } catch (IllegalStateException expected) { } assertTrue(listener.healthyCalled); assertEquals(ImmutableSet.of(b), listener.failedServices); manager.stopAsync().awaitStopped(); assertState(manager, Service.State.FAILED, b); assertState(manager, Service.State.TERMINATED, a); assertTrue(listener.stoppedCalled); }
assertFalse(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); manager.stopAsync().awaitStopped(); assertFalse(manager.isHealthy()); assertTrue(listener.stoppedCalled);
public void testServiceStartStop() { Service a = new NoOpService(); Service b = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b); assertFalse(manager.isHealthy()); manager.startAsync().awaitHealthy(); assertState(manager, Service.State.RUNNING, a, b); assertTrue(manager.isHealthy()); assertTrue(listener.healthyCalled); assertFalse(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); manager.stopAsync().awaitStopped(); assertState(manager, Service.State.TERMINATED, a, b); assertFalse(manager.isHealthy()); assertTrue(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); }
public void testFailStart() throws Exception { Service a = new NoOpService(); Service b = new FailStartService(); Service c = new NoOpService(); Service d = new FailStartService(); Service e = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b, c, d, e)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b, c, d, e); try { manager.startAsync().awaitHealthy(); fail(); } catch (IllegalStateException expected) { } assertFalse(listener.healthyCalled); assertState(manager, Service.State.RUNNING, a, c, e); assertEquals(ImmutableSet.of(b, d), listener.failedServices); assertState(manager, Service.State.FAILED, b, d); assertFalse(manager.isHealthy()); manager.stopAsync().awaitStopped(); assertFalse(manager.isHealthy()); assertFalse(listener.healthyCalled); assertTrue(listener.stoppedCalled); }