private void die(Throwable exception) { String processInfo = _process.getProcessInfoString() + _process.getProcessTerminationInfoString(); _exception = new RuntimeException(processInfo, exception); String message = String.format("Halting process: ShellBolt died. Command: %s, ProcessInfo %s", Arrays.toString(_command), processInfo); LOG.error(message, exception); _collector.reportError(exception); if (!_isLocalMode && (_running || (exception instanceof Error))) { //don't exit if not running, unless it is an Error System.exit(11); } }
public void open(Map<String, Object> topoConf, TopologyContext context, SpoutOutputCollector collector) { _collector = collector; _context = context; if (topoConf.containsKey(Config.TOPOLOGY_SUBPROCESS_TIMEOUT_SECS)) { workerTimeoutMills = 1000 * ObjectReader.getInt(topoConf.get(Config.TOPOLOGY_SUBPROCESS_TIMEOUT_SECS)); } else { workerTimeoutMills = 1000 * ObjectReader.getInt(topoConf.get(Config.SUPERVISOR_WORKER_TIMEOUT_SECS)); } _process = new ShellProcess(_command); if (!env.isEmpty()) { _process.setEnv(env); } Number subpid = _process.launch(topoConf, context, changeDirectory); LOG.info("Launched subprocess with pid " + subpid); _logHandler = ShellUtils.getLogHandler(topoConf); _logHandler.setUpContext(ShellSpout.class, _process, _context); heartBeatExecutorService = MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1)); }
public void close() { heartBeatExecutorService.shutdownNow(); _process.destroy(); _running = false; }
public String getProcessTerminationInfoString() { return String.format(" exitCode:%s, errorString:%s ", getExitCode(), getErrorsString()); } }
private void querySubprocess() { try { markWaitingSubprocess(); _process.writeSpoutMsg(_spoutMsg); ShellMsg shellMsg = _process.readShellMsg(); String command = shellMsg.getCommand(); if (command == null) { List<Integer> outtasks = _collector.emit(stream, tuple, messageId); if (shellMsg.areTaskIdsNeeded()) { _process.writeTaskIds(outtasks); String processInfo = _process.getProcessInfoString() + _process.getProcessTerminationInfoString(); throw new RuntimeException(processInfo, e); } finally {
public Number launch(Map<String, Object> conf, TopologyContext context, boolean changeDirectory) { ProcessBuilder builder = new ProcessBuilder(command); if (!env.isEmpty()) { Map<String, String> buildEnv = builder.environment(); modifyEnvironment(buildEnv); } if (changeDirectory) { builder.directory(new File(context.getCodeDir())); } ShellLogger = LoggerFactory.getLogger(context.getThisComponentId()); this.componentName = context.getThisComponentId(); this.serializer = getSerializer(conf); try { _subprocess = builder.start(); processErrorStream = _subprocess.getErrorStream(); serializer.initialize(_subprocess.getOutputStream(), _subprocess.getInputStream()); this.pid = serializer.connect(conf, context); } catch (IOException e) { throw new RuntimeException( "Error when launching multilang subprocess\n" + getErrorsString(), e); } catch (NoOutputException e) { throw new RuntimeException(e + getErrorsString() + "\n"); } return this.pid; }
private ShellProcess mockProcess() { ShellProcess process = mock(ShellProcess.class); when(process.getProcessInfoString()).thenReturn("info"); return process; }
public void writeBoltMsg(BoltMsg msg) throws IOException { serializer.writeBoltMsg(msg); // Log any info sent on the error stream logErrorStream(); }
public ShellMsg readShellMsg() throws IOException { try { return serializer.readShellMsg(); } catch (NoOutputException e) { throw new RuntimeException(e + getErrorsString() + "\n"); } }
public Number launch(Map<String, Object> conf, TopologyContext context) { return launch(conf, context, true); }
private void querySubprocess() { try { markWaitingSubprocess(); _process.writeSpoutMsg(_spoutMsg); ShellMsg shellMsg = _process.readShellMsg(); String command = shellMsg.getCommand(); if (command == null) { List<Integer> outtasks = _collector.emit(stream, tuple, messageId); if (shellMsg.areTaskIdsNeeded()) { _process.writeTaskIds(outtasks); String processInfo = _process.getProcessInfoString() + _process.getProcessTerminationInfoString(); throw new RuntimeException(processInfo, e); } finally {
public Number launch(Map conf, TopologyContext context, boolean changeDirectory) { ProcessBuilder builder = new ProcessBuilder(command); if (!env.isEmpty()) { Map<String, String> buildEnv = builder.environment(); modifyEnvironment(buildEnv); } if (changeDirectory) { builder.directory(new File(context.getCodeDir())); } ShellLogger = LoggerFactory.getLogger(context.getThisComponentId()); this.componentName = context.getThisComponentId(); this.serializer = getSerializer(conf); try { _subprocess = builder.start(); processErrorStream = _subprocess.getErrorStream(); serializer.initialize(_subprocess.getOutputStream(), _subprocess.getInputStream()); this.pid = serializer.connect(conf, context); } catch (IOException e) { throw new RuntimeException( "Error when launching multilang subprocess\n" + getErrorsString(), e); } catch (NoOutputException e) { throw new RuntimeException(e + getErrorsString() + "\n"); } return this.pid; }
msg = "ShellLog " + msg; } else { msg = "ShellLog " + process.getProcessInfoString() + " " + msg;
public String getProcessTerminationInfoString() { return String.format(" exitCode:%s, errorString:%s ", getExitCode(), getErrorsString()); } }
public void writeSpoutMsg(SpoutMsg msg) throws IOException { serializer.writeSpoutMsg(msg); // Log any info sent on the error stream logErrorStream(); }
public ShellMsg readShellMsg() throws IOException { try { return serializer.readShellMsg(); } catch (NoOutputException e) { throw new RuntimeException(e + getErrorsString() + "\n"); } }
public Number launch(Map conf, TopologyContext context) { return launch(conf, context, true); }
_process = new ShellProcess(_command); if (!env.isEmpty()) { _process.setEnv(env); Number subpid = _process.launch(topoConf, context, changeDirectory); LOG.info("Launched subprocess with pid " + subpid);
private void die(Throwable exception) { String processInfo = _process.getProcessInfoString() + _process.getProcessTerminationInfoString(); _exception = new RuntimeException(processInfo, exception); String message = String.format("Halting process: ShellSpout died. Command: %s, ProcessInfo %s", Arrays.toString(_command), processInfo); LOG.error(message, exception); _collector.reportError(exception); if (_running || (exception instanceof Error)) { //don't exit if not running, unless it is an Error System.exit(11); } }
/** * If both {@link ShellMsg} and {@link ShellProcess} are provided, both * will be used to build the log message. */ @Test public void handleLog_valid() { ShellMsg msg = mockMsg(); ShellProcess process = mockProcess(); logHandler.setUpContext(DefaultShellLogHandlerTest.class, process, null); logHandler.log(msg); verify(msg).getMsg(); verify(process).getProcessInfoString(); } }