public ForkedProcessService buildProcess(String name, Map<String, String> env, List<String> commands) throws IOException, SliderException { ForkedProcessService process; process = new ForkedProcessService(name); process.init(getConfig()); process.build(env, commands); return process; }
/** * Get the final output. includes a quick sleep for the tail output * @return the last output */ private List<String> getFinalOutput() { return process.getRecentOutput(true, RECENT_OUTPUT_SLEEP_DURATION); }
@Override // notification from executed process public void onProcessExited(LongLivedProcess process, int uncorrected, int code) { try { synchronized (this) { completed(); //note whether or not the service had already stopped LOG.debug("Process has exited with exit code {}", code); if (code != 0) { reportFailure(code, getName() + " failed with code " + code); } } } finally { stop(); } }
@Override //AbstractService protected void serviceStop() throws Exception { completed(); stopForkedProcess(); }
process = new ForkedProcessService( name, new HashMap<String, String>(), Arrays.asList(commands)); process.setProcessLog(logger); process.init(new Configuration()); String errorText = null; process.start(); try { if (!process.waitForServiceToStop(timeoutMillis)) { throw new TimeoutException( "Process did not stop in " + timeoutMillis + "mS"); int exitCode = process.getExitCode(); List<String> recentOutput = process.getRecentOutput(); if (status != exitCode) { List<String> recentOutput = process.getRecentOutput(); for (String line : recentOutput) { log.info(line);
private ForkedProcessService initProcess(List<String> commands) throws IOException { process = new ForkedProcessService(name.getMethodName(), env, commands); process.init(new Configuration()); // increase the line limit to accommodate containers with long list of envs process.setRecentLineLimit(640); return process; }
@Test public void testExitCodes() throws Throwable { SliderTestUtils.skipOnWindows(); initProcess(commandFactory.exitFalse()); exec(); assertFalse(process.isProcessRunning()); Integer exitCode = process.getExitCode(); assertNotNull("null exit code", exitCode); assertTrue(exitCode != 0); int corrected = process.getExitCodeSignCorrected(); assertEquals(1, corrected); // assert that the exit code was uprated to a service failure assertNotNull(process.getFailureCause()); }
@Test public void testLs() throws Throwable { initProcess(commandFactory.ls(testDir)); exec(); assertFalse(process.isProcessRunning()); Integer exitCode = process.getExitCode(); assertNotNull("null exit code", exitCode); assertEquals(0, exitCode.intValue()); // assert that the service did not fail assertNull(process.getFailureCause()); }
public void exec() throws InterruptedException, TimeoutException { assertNotNull(process); process.start(); assert process.waitForServiceToStop(5000); }
@Override // notification from executed process public synchronized void onProcessStarted(LongLivedProcess process) { LOG.debug("Process has started"); processStarted = true; if (executionTimeout > 0) { setExecutor(ServiceThreadFactory.singleThreadExecutor(getName(), true)); execute(this); } }
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override // ExitCodeProvider public int getExitCode() { Throwable cause = getFailureCause(); if (cause != null) { //failed for some reason if (cause instanceof ExitCodeProvider) { return ((ExitCodeProvider) cause).getExitCode(); } } ForkedProcessService lastProc = latestProcess(); if (lastProc == null || !lastProc.isProcessTerminated()) { return 0; } else { return lastProc.getExitCode(); } }
@Test public void testSetenv() throws Throwable { String var = "TEST_RUN"; String val = "TEST-RUN-ENV-VALUE"; env.put(var, val); initProcess(commandFactory.env()); exec(); Integer exitCode = process.getExitCode(); assertNotNull("null exit code", exitCode); assertEquals(0, exitCode.intValue()); assertStringInOutput(val, getFinalOutput()); }
/** * Create an instance of the service, set up the process * @param name a name * @param commandList list of commands is inserted on the front * @param env environment variables above those generated by * @throws IOException IO problems */ public ForkedProcessService(String name, Map<String, String> env, List<String> commandList) throws IOException { super(name); build(env, commandList); }
process = new ForkedProcessService( name, new HashMap<String, String>(), Arrays.asList(commands)); process.setProcessLog(logger); process.init(new Configuration()); String errorText = null; process.start(); try { if (!process.waitForServiceToStop(timeoutMillis)) { throw new TimeoutException( "Process did not stop in " + timeoutMillis + "mS"); int exitCode = process.getExitCode(); List<String> recentOutput = process.getRecentOutput(); if (status != exitCode) { List<String> recentOutput = process.getRecentOutput(); for (String line : recentOutput) { log.info(line);
private ForkedProcessService initProcess(List<String> commands) throws IOException { process = new ForkedProcessService(name.getMethodName(), env, commands); process.init(new Configuration()); // increase the line limit to accommodate containers with long list of envs process.setRecentLineLimit(640); return process; }
@Test public void testExitCodes() throws Throwable { SliderTestUtils.skipOnWindows(); initProcess(commandFactory.exitFalse()); exec(); assertFalse(process.isProcessRunning()); Integer exitCode = process.getExitCode(); assertNotNull("null exit code", exitCode); assertTrue(exitCode != 0); int corrected = process.getExitCodeSignCorrected(); assertEquals(1, corrected); // assert that the exit code was uprated to a service failure assertNotNull(process.getFailureCause()); }
@Test public void testLs() throws Throwable { initProcess(commandFactory.ls(testDir)); exec(); assertFalse(process.isProcessRunning()); Integer exitCode = process.getExitCode(); assertNotNull("null exit code", exitCode); assertEquals(0, exitCode.intValue()); // assert that the service did not fail assertNull(process.getFailureCause()); }
public void exec() throws InterruptedException, TimeoutException { assertNotNull(process); process.start(); assert process.waitForServiceToStop(5000); }
@Override // notification from executed process public synchronized void onProcessStarted(LongLivedProcess process) { LOG.debug("Process has started"); processStarted = true; if (executionTimeout > 0) { setExecutor(ServiceThreadFactory.singleThreadExecutor(getName(), true)); execute(this); } }
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override // ExitCodeProvider public int getExitCode() { Throwable cause = getFailureCause(); if (cause != null) { //failed for some reason if (cause instanceof ExitCodeProvider) { return ((ExitCodeProvider) cause).getExitCode(); } } ForkedProcessService lastProc = latestProcess(); if (lastProc == null || !lastProc.isProcessTerminated()) { return 0; } else { return lastProc.getExitCode(); } }