use of org.apache.commons.exec.DefaultExecutor in project yeoman-maven-plugin by trecloux.
the class YeomanMojo method executeCommand.
void executeCommand(String command) throws MojoExecutionException {
try {
if (isWindows()) {
command = "cmd /c " + command;
}
CommandLine cmdLine = CommandLine.parse(command);
DefaultExecutor executor = new DefaultExecutor();
executor.setWorkingDirectory(yeomanProjectDirectory);
executor.execute(cmdLine);
} catch (IOException e) {
throw new MojoExecutionException("Error during : " + command, e);
}
}
use of org.apache.commons.exec.DefaultExecutor in project zeppelin by apache.
the class ShellInterpreter method open.
@Override
public void open() {
super.open();
long timeoutThreshold = Long.parseLong(getProperty(TIMEOUT_PROPERTY, DEFAULT_TIMEOUT));
long timeoutCheckInterval = Long.parseLong(getProperty(TIMEOUT_CHECK_INTERVAL_PROPERTY, DEFAULT_CHECK_INTERVAL));
LOGGER.info("Command timeout property: {}", timeoutThreshold);
executorMap = new ConcurrentHashMap<>();
contextMap = new ConcurrentHashMap<>();
shellOutputCheckExecutor.scheduleAtFixedRate(() -> {
try {
for (Map.Entry<String, DefaultExecutor> entry : executorMap.entrySet()) {
String paragraphId = entry.getKey();
DefaultExecutor executor = entry.getValue();
InterpreterContext context = contextMap.get(paragraphId);
if (context == null) {
LOGGER.warn("No InterpreterContext associated with paragraph: {}", paragraphId);
continue;
}
if ((System.currentTimeMillis() - context.out.getLastWriteTimestamp()) > timeoutThreshold) {
LOGGER.info("No output for paragraph {} for the last {} milli-seconds, so kill it", paragraphId, timeoutThreshold);
executor.getWatchdog().destroyProcess();
}
}
} catch (Exception e) {
LOGGER.error("Error when checking shell command timeout", e);
}
}, timeoutCheckInterval, timeoutCheckInterval, TimeUnit.MILLISECONDS);
}
use of org.apache.commons.exec.DefaultExecutor in project zeppelin by apache.
the class SubmarineJobTest method defaultExecutorTest.
@Test
public void defaultExecutorTest() throws IOException {
DefaultExecutor executor = new DefaultExecutor();
CommandLine cmdLine = CommandLine.parse(shell);
URL urlTemplate = Resources.getResource(DEFAULT_EXECUTOR_TEST);
cmdLine.addArgument(urlTemplate.getFile(), false);
Map<String, String> env = new HashMap<>();
env.put("CLASSPATH", "`$HADOOP_HDFS_HOME/bin/hadoop classpath --glob`");
env.put("EVN", "test");
AtomicBoolean cmdLineRunning = new AtomicBoolean(true);
StringBuffer sbLogOutput = new StringBuffer();
executor.setStreamHandler(new PumpStreamHandler(new LogOutputStream() {
@Override
protected void processLine(String line, int level) {
// LOGGER.info(line);
sbLogOutput.append(line + "\n");
}
}));
executor.execute(cmdLine, env, new DefaultExecuteResultHandler() {
@Override
public void onProcessComplete(int exitValue) {
cmdLineRunning.set(false);
}
@Override
public void onProcessFailed(ExecuteException e) {
cmdLineRunning.set(false);
LOGGER.error(e.getMessage());
}
});
int loopCount = 100;
while ((loopCount-- > 0) && cmdLineRunning.get()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
LOGGER.info(sbLogOutput.toString());
}
use of org.apache.commons.exec.DefaultExecutor in project zeppelin by apache.
the class JupyterKernelInterpreter method activateCondaEnv.
private String activateCondaEnv(String envName) throws IOException {
LOGGER.info("Activating conda env: {}", envName);
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
PumpStreamHandler psh = new PumpStreamHandler(stdout);
if (!new File(envName).exists()) {
throw new IOException("Fail to activating conda env because no environment folder: " + envName);
}
File scriptFile = Files.createTempFile("zeppelin_jupyter_kernel_", ".sh").toFile();
try (FileWriter writer = new FileWriter(scriptFile)) {
IOUtils.write(String.format("chmod 777 -R %s \nsource %s/bin/activate \nconda-unpack", envName, envName), writer);
}
scriptFile.setExecutable(true, false);
scriptFile.setReadable(true, false);
CommandLine cmd = new CommandLine(scriptFile.getAbsolutePath());
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(psh);
int exitCode = executor.execute(cmd);
if (exitCode != 0) {
throw new IOException("Fail to activate conda env, " + stdout.toString());
} else {
LOGGER.info("Activate conda env successfully");
this.condaEnv = envName;
return envName + "/bin/python";
}
}
use of org.apache.commons.exec.DefaultExecutor in project zeppelin by apache.
the class ProcessLauncher method launch.
public void launch() {
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(processOutput));
this.watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
executor.setWatchdog(watchdog);
try {
executor.execute(commandLine, envs, this);
transition(State.LAUNCHED);
LOGGER.info("Process is launched: {}", commandLine);
} catch (IOException e) {
this.processOutput.stopCatchLaunchOutput();
LOGGER.error("Fail to launch process: {}", commandLine, e);
transition(State.TERMINATED);
errorMessage = e.getMessage();
}
}
Aggregations