@Override public void onCoordinatorStop() { synchronized (lock) { LOGGER.info("Shutting down the executor service of the stream processor: {}.", processorId); boolean hasContainerShutdown = stopSamzaContainer(); // we only want to interrupt when container shutdown times out. if (!hasContainerShutdown) { containerExcecutorService.shutdownNow(); } state = State.STOPPED; } if (containerException != null) processorListener.afterFailure(containerException); else processorListener.afterStop(); }
@Override public void afterStart() { LOGGER.warn("Received container start notification for container: {} in stream processor: {}.", container, processorId); if (!processorOnStartCalled) { processorListener.afterStart(); processorOnStartCalled = true; } state = State.RUNNING; }
@Override public void beforeStart() { userDefinedProcessorLifecycleListener.beforeStart(); }
@Test public void testRunStreamTaskWithoutExternalContext() { final Map<String, String> cfgs = new HashMap<>(); cfgs.put(ApplicationConfig.APP_PROCESSOR_ID_GENERATOR_CLASS, UUIDGenerator.class.getName()); cfgs.put(JobConfig.JOB_NAME(), "test-task-job"); cfgs.put(JobConfig.JOB_ID(), "jobId"); config = new MapConfig(cfgs); mockApp = new LegacyTaskApplication(IdentityStreamTask.class.getName()); prepareTest(); StreamProcessor sp = mock(StreamProcessor.class); ArgumentCaptor<StreamProcessor.StreamProcessorLifecycleListenerFactory> captor = ArgumentCaptor.forClass(StreamProcessor.StreamProcessorLifecycleListenerFactory.class); doAnswer(i -> { ProcessorLifecycleListener listener = captor.getValue().createInstance(sp); listener.afterStart(); listener.afterStop(); return null; }).when(sp).start(); doReturn(sp).when(runner).createStreamProcessor(anyObject(), anyObject(), captor.capture(), eq(Optional.empty())); doReturn(ApplicationStatus.SuccessfulFinish).when(runner).status(); runner.run(); assertEquals(ApplicationStatus.SuccessfulFinish, runner.status()); }
@Override public void afterFailure(Throwable t) { log.info("Container Failed"); containerRunnerException = t; listener.afterFailure(t); } });
@Override public void afterStop() { log.info("Container Stopped"); listener.afterStop(); }
@Test public void testRunStreamTask() { final Map<String, String> cfgs = new HashMap<>(); cfgs.put(ApplicationConfig.APP_PROCESSOR_ID_GENERATOR_CLASS, UUIDGenerator.class.getName()); cfgs.put(JobConfig.JOB_NAME(), "test-task-job"); cfgs.put(JobConfig.JOB_ID(), "jobId"); config = new MapConfig(cfgs); mockApp = new LegacyTaskApplication(IdentityStreamTask.class.getName()); prepareTest(); StreamProcessor sp = mock(StreamProcessor.class); ArgumentCaptor<StreamProcessor.StreamProcessorLifecycleListenerFactory> captor = ArgumentCaptor.forClass(StreamProcessor.StreamProcessorLifecycleListenerFactory.class); doAnswer(i -> { ProcessorLifecycleListener listener = captor.getValue().createInstance(sp); listener.afterStart(); listener.afterStop(); return null; }).when(sp).start(); ExternalContext externalContext = mock(ExternalContext.class); doReturn(sp).when(runner) .createStreamProcessor(anyObject(), anyObject(), captor.capture(), eq(Optional.of(externalContext))); doReturn(ApplicationStatus.SuccessfulFinish).when(runner).status(); runner.run(externalContext); assertEquals(ApplicationStatus.SuccessfulFinish, runner.status()); }
@Override public void afterFailure(Throwable t) { log.info("Container Failed"); containerRunnerException = t; listener.afterFailure(t); } });
@Override public void afterStop() { log.info("Container Stopped"); listener.afterStop(); }
@Override public void onCoordinatorStop() { synchronized (lock) { LOGGER.info("Shutting down the executor service of the stream processor: {}.", processorId); boolean hasContainerShutdown = stopSamzaContainer(); // we only want to interrupt when container shutdown times out. if (!hasContainerShutdown) { containerExcecutorService.shutdownNow(); } state = State.STOPPED; } if (containerException != null) processorListener.afterFailure(containerException); else processorListener.afterStop(); }
@Override public void afterStart() { log.info("Container Started"); listener.afterStart(); }
@Test public void testRunComplete() { Map<String, String> cfgs = new HashMap<>(); cfgs.put(ApplicationConfig.APP_PROCESSOR_ID_GENERATOR_CLASS, UUIDGenerator.class.getName()); config = new MapConfig(cfgs); ProcessorLifecycleListenerFactory mockFactory = (pContext, cfg) -> mock(ProcessorLifecycleListener.class); mockApp = (StreamApplication) appDesc -> { appDesc.withProcessorLifecycleListenerFactory(mockFactory); }; prepareTest(); // return the jobConfigs from the planner doReturn(Collections.singletonList(new JobConfig(new MapConfig(config)))).when(localPlanner).prepareJobs(); StreamProcessor sp = mock(StreamProcessor.class); ArgumentCaptor<StreamProcessor.StreamProcessorLifecycleListenerFactory> captor = ArgumentCaptor.forClass(StreamProcessor.StreamProcessorLifecycleListenerFactory.class); doAnswer(i -> { ProcessorLifecycleListener listener = captor.getValue().createInstance(sp); listener.afterStart(); listener.afterStop(); return null; }).when(sp).start(); ExternalContext externalContext = mock(ExternalContext.class); doReturn(sp).when(runner) .createStreamProcessor(anyObject(), anyObject(), captor.capture(), eq(Optional.of(externalContext))); runner.run(externalContext); runner.waitForFinish(); assertEquals(runner.status(), ApplicationStatus.SuccessfulFinish); }
@Override public void afterFailure(Throwable t) { log.info("Container Failed"); containerRunnerException = t; listener.afterFailure(t); } });
@Override public void beforeStart() { userDefinedProcessorLifecycleListener.beforeStart(); }
@Override public void afterStop() { log.info("Container Stopped"); listener.afterStop(); }
@Override public void onCoordinatorStop() { synchronized (lock) { LOGGER.info("Shutting down the executor service of the stream processor: {}.", processorId); boolean hasContainerShutdown = stopSamzaContainer(); // we only want to interrupt when container shutdown times out. if (!hasContainerShutdown) { containerExcecutorService.shutdownNow(); } state = State.STOPPED; } if (containerException != null) processorListener.afterFailure(containerException); else processorListener.afterStop(); }
@Override public void afterStart() { if (numProcessorsToStart.decrementAndGet() == 0) { appStatus = ApplicationStatus.Running; } userDefinedProcessorLifecycleListener.afterStart(); }
@Override public void afterFailure(Throwable t) { log.info("Container Failed"); containerRunnerException = t; listener.afterFailure(t); } });
@Override public void beforeStart() { userDefinedProcessorLifecycleListener.beforeStart(); }
@Override public void afterStop() { log.info("Container Stopped"); listener.afterStop(); }