public ProgramControllerServiceAdapter(Service service, ProgramRunId programRunId, @Nullable String componentName) { super(programRunId, componentName); this.service = service; this.serviceStoppedLatch = new CountDownLatch(1); listenToRuntimeState(service); }
@Override public void running() { started(); }
@Override public void failed(Service.State from, Throwable failure) { Throwable rootCause = Throwables.getRootCause(failure); LOG.error("{} Program '{}' failed.", getProgramRunId().getType(), getProgramRunId().getProgram(), failure); USERLOG.error("{} program '{}' failed with error: {}. Please check the system logs for more details.", getProgramRunId().getType(), getProgramRunId().getProgram(), rootCause.getMessage(), rootCause); serviceStoppedLatch.countDown(); error(failure); }
@Override protected void doCommand(String name, Object value) throws Exception { super.doCommand(name, value); if (!ProgramOptionConstants.INSTANCES.equals(name) || !(value instanceof Integer)) { return; } service.setInstanceCount((Integer) value); } }
private ProgramRuntimeService.RuntimeInfo createRuntimeInfo(Service service, final ProgramRunId programRunId) { final ProgramControllerServiceAdapter controller = new ProgramControllerServiceAdapter(service, programRunId); return new ProgramRuntimeService.RuntimeInfo() { @Override public ProgramController getController() { return controller; } @Override public ProgramType getType() { return programRunId.getType(); } @Override public ProgramId getProgramId() { return programRunId.getParent(); } @Nullable @Override public RunId getTwillRunId() { return null; } }; }
@Override protected void doStop() throws Exception { if (service.state() != Service.State.TERMINATED && service.state() != Service.State.FAILED) { LOG.debug("stopping controller service for program {}.", getProgramRunId()); service.stopAndWait(); LOG.debug("stopped controller service for program {}, waiting for it to finish running listener hooks.", getProgramRunId()); serviceStoppedLatch.await(30, TimeUnit.SECONDS); LOG.debug("controller service for program {} finished running listener hooks.", getProgramRunId()); } }
@Override public void failed(Service.State from, Throwable failure) { Throwable rootCause = Throwables.getRootCause(failure); LOG.error("{} Program '{}' failed.", getProgramRunId().getType(), getProgramRunId().getProgram(), failure); USERLOG.error("{} program '{}' failed with error: {}. Please check the system logs for more details.", getProgramRunId().getType(), getProgramRunId().getProgram(), rootCause.getMessage(), rootCause); serviceStoppedLatch.countDown(); error(failure); }
@Override protected void doCommand(String name, Object value) throws Exception { super.doCommand(name, value); if (!ProgramOptionConstants.INSTANCES.equals(name) || !(value instanceof Integer)) { return; } workerDriver.setInstanceCount((Integer) value); } }
/** * Creates a {@link ProgramRunnerFactory} for creating {@link ProgramRunner} * that always run with a {@link FastService}. * * @param argumentsMap the map to be populated with the user arguments for each run. */ private ProgramRunnerFactory createProgramRunnerFactory(final Map<ProgramId, Arguments> argumentsMap) { return programType -> (program, options) -> { ProgramId programId = program.getId(); argumentsMap.put(programId, options.getUserArguments()); Service service = new FastService(); ProgramController controller = new ProgramControllerServiceAdapter(service, programId.run(RunIds.generate())); service.start(); return controller; }; }
@Override protected void doStop() throws Exception { if (service.state() != Service.State.TERMINATED && service.state() != Service.State.FAILED) { LOG.debug("stopping controller service for program {}.", getProgramRunId()); service.stopAndWait(); LOG.debug("stopped controller service for program {}, waiting for it to finish running listener hooks.", getProgramRunId()); serviceStoppedLatch.await(30, TimeUnit.SECONDS); LOG.debug("controller service for program {} finished running listener hooks.", getProgramRunId()); } }
@Override protected void doCommand(String name, Object value) throws Exception { super.doCommand(name, value); if (!ProgramOptionConstants.INSTANCES.equals(name) || !(value instanceof Integer)) { return; } workerDriver.setInstanceCount((Integer) value); } }
ProgramController controller = new ProgramControllerServiceAdapter(service, programId.run(RunIds.generate())); ListenableFuture<Service.State> startCompletion = service.start();
public ProgramControllerServiceAdapter(Service service, ProgramRunId programRunId, @Nullable String componentName) { super(programRunId, componentName); this.service = service; this.serviceStoppedLatch = new CountDownLatch(1); listenToRuntimeState(service); }
@Override public void running() { started(); }
@Override protected void doCommand(String name, Object value) throws Exception { super.doCommand(name, value); if (!ProgramOptionConstants.INSTANCES.equals(name) || !(value instanceof Integer)) { return; } service.setInstanceCount((Integer) value); } }