List of usage examples for org.apache.commons.exec PumpStreamHandler PumpStreamHandler
public PumpStreamHandler(final OutputStream out, final OutputStream err, final InputStream input)
PumpStreamHandler
. From source file:org.apache.zeppelin.interpreter.launcher.Kubectl.java
public int execute(String[] args, InputStream stdin, OutputStream stdout, OutputStream stderr) throws IOException { DefaultExecutor executor = new DefaultExecutor(); CommandLine cmd = new CommandLine(kubectlCmd); cmd.addArguments(args);// w w w . j av a 2s.co m ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); executor.setWatchdog(watchdog); PumpStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr, stdin); executor.setStreamHandler(streamHandler); return executor.execute(cmd); }
From source file:org.apache.zeppelin.spark.PySparkInterpreter.java
private void createGatewayServerAndStartScript() { // create python script createPythonScript();//from w w w . jav a2 s . co m port = findRandomOpenPortOnAllLocalInterfaces(); gatewayServer = new GatewayServer(this, port); gatewayServer.start(); // Run python shell CommandLine cmd = CommandLine.parse(getProperty("zeppelin.pyspark.python")); cmd.addArgument(scriptPath, false); cmd.addArgument(Integer.toString(port), false); cmd.addArgument(Integer.toString(getSparkInterpreter().getSparkVersion().toNumber()), false); executor = new DefaultExecutor(); outputStream = new ByteArrayOutputStream(); PipedOutputStream ps = new PipedOutputStream(); in = null; try { in = new PipedInputStream(ps); } catch (IOException e1) { throw new InterpreterException(e1); } ins = new BufferedWriter(new OutputStreamWriter(ps)); input = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, outputStream, in); executor.setStreamHandler(streamHandler); executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT)); try { Map env = EnvironmentUtils.getProcEnvironment(); executor.execute(cmd, env, this); pythonscriptRunning = true; } catch (IOException e) { throw new InterpreterException(e); } try { input.write("import sys, getopt\n".getBytes()); ins.flush(); } catch (IOException e) { throw new InterpreterException(e); } }
From source file:org.apache.zeppelin.spark.SparkRInterpreter.java
@Override public void open() { // create R script createRScript();/*from www . j a va2s. co m*/ int backendTimeout = Integer.parseInt(System.getenv().getOrDefault("SPARKR_BACKEND_TIMEOUT", "120")); // Launch a SparkR backend server for the R process to connect to; this will let it see our // Java system properties etc. ZeppelinRBackend sparkRBackend = new ZeppelinRBackend(); Semaphore initialized = new Semaphore(0); Thread sparkRBackendThread = new Thread("SparkR backend") { @Override public void run() { sparkRBackendPort = sparkRBackend.init(); initialized.release(); sparkRBackend.run(); } }; sparkRBackendThread.start(); // Wait for RBackend initialization to finish try { if (initialized.tryAcquire(backendTimeout, TimeUnit.SECONDS)) { // Launch R CommandLine cmd = CommandLine.parse(getProperty("zeppelin.sparkr.r")); cmd.addArgument(scriptPath, false); cmd.addArgument("--no-save", false); // cmd.addArgument(getJavaSparkContext().version(), false); executor = new DefaultExecutor(); outputStream = new ByteArrayOutputStream(); PipedOutputStream ps = new PipedOutputStream(); in = null; try { in = new PipedInputStream(ps); } catch (IOException e1) { throw new InterpreterException(e1); } ins = new BufferedWriter(new OutputStreamWriter(ps)); input = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, outputStream, in); executor.setStreamHandler(streamHandler); executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT)); Map env = EnvironmentUtils.getProcEnvironment(); String sparkRInterpreterObjId = sparkRBackend.put(this); String uberdataContextObjId = sparkRBackend.put(getUberdataContext()); env.put("R_PROFILE_USER", scriptPath); env.put("SPARK_HOME", getSparkHome()); env.put("EXISTING_SPARKR_BACKEND_PORT", String.valueOf(sparkRBackendPort)); env.put("SPARKR_INTERPRETER_ID", sparkRInterpreterObjId); env.put("UBERDATA_CONTEXT_ID", uberdataContextObjId); logger.info("executing {} {}", env, cmd.toString()); executor.execute(cmd, env, this); logger.info("executed"); rScriptRunning = true; } else { System.err.println("SparkR backend did not initialize in " + backendTimeout + " seconds"); System.exit(-1); } } catch (InterruptedException e) { new InterpreterException((e)); } catch (IOException e) { new InterpreterException((e)); } }
From source file:org.apache.zeppelin.spark.ZeppelinR.java
/** * Start R repl//www. j a v a 2 s. c om * @throws IOException */ public void open() throws IOException { createRScript(); zeppelinR.put(hashCode(), this); CommandLine cmd = CommandLine.parse(rCmdPath); cmd.addArgument("--no-save"); cmd.addArgument("--no-restore"); cmd.addArgument("-f"); cmd.addArgument(scriptPath); cmd.addArgument("--args"); cmd.addArgument(Integer.toString(hashCode())); cmd.addArgument(Integer.toString(port)); cmd.addArgument(libPath); cmd.addArgument(Integer.toString(sparkVersion.toNumber())); // dump out the R command to facilitate manually running it, e.g. for fault diagnosis purposes logger.debug(cmd.toString()); executor = new DefaultExecutor(); outputStream = new InterpreterOutputStream(logger); input = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(input); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, outputStream, in); executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT)); executor.setStreamHandler(streamHandler); Map env = EnvironmentUtils.getProcEnvironment(); initialOutput = new InterpreterOutput(null); outputStream.setInterpreterOutput(initialOutput); executor.execute(cmd, env, this); rScriptRunning = true; // flush output eval("cat('')"); }
From source file:org.bonitasoft.platform.setup.PlatformSetupTestUtils.java
public static PumpStreamHandler getExecuteStreamHandler(String answer) { return new PumpStreamHandler(System.out, System.err, new ByteArrayInputStream(answer.getBytes())); }
From source file:org.codehaus.mojo.AbstractLaunchMojo.java
protected int executeCommandLine(Executor exec, CommandLine commandLine, Map enviro, OutputStream out, OutputStream err, InputStream in) throws ExecuteException, IOException { exec.setStreamHandler(new PumpStreamHandler(out, err, in)); return exec.execute(commandLine, enviro); }
From source file:org.codehaus.mojo.cassandra.CleanupCassandraMojo.java
/** * {@inheritDoc}//from ww w .j av a 2s . co m */ public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("Skipping cassandra: cassandra.skip==true"); return; } try { Map environment = createEnvironmentVars(); CommandLine commandLine = newNodetoolCommandLine("cleanup"); Executor exec = new DefaultExecutor(); exec.setWorkingDirectory(cassandraDir); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); LogOutputStream stdout = new MavenLogOutputStream(getLog()); LogOutputStream stderr = new MavenLogOutputStream(getLog()); try { getLog().debug("Executing command line: " + commandLine); exec.setStreamHandler(new PumpStreamHandler(stdout, stderr, System.in)); exec.execute(commandLine, environment); getLog().info("Cleanup triggered."); } catch (ExecuteException e) { throw new MojoExecutionException("Command execution failed.", e); } catch (IOException e) { throw new MojoExecutionException("Command execution failed.", e); } } catch (IOException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }
From source file:org.codehaus.mojo.cassandra.CompactCassandraMojo.java
/** * {@inheritDoc}//from w ww. j a v a2s.co m */ public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("Skipping cassandra: cassandra.skip==true"); return; } try { Map environment = createEnvironmentVars(); CommandLine commandLine = newNodetoolCommandLine("compact"); Executor exec = new DefaultExecutor(); exec.setWorkingDirectory(cassandraDir); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); LogOutputStream stdout = new MavenLogOutputStream(getLog()); LogOutputStream stderr = new MavenLogOutputStream(getLog()); try { getLog().debug("Executing command line: " + commandLine); exec.setStreamHandler(new PumpStreamHandler(stdout, stderr, System.in)); exec.execute(commandLine, environment); getLog().info("Compact triggered."); } catch (ExecuteException e) { throw new MojoExecutionException("Command execution failed.", e); } catch (IOException e) { throw new MojoExecutionException("Command execution failed.", e); } } catch (IOException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }
From source file:org.codehaus.mojo.cassandra.FlushCassandraMojo.java
/** * {@inheritDoc}//w w w . j a v a2s . com */ public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("Skipping cassandra: cassandra.skip==true"); return; } try { Map environment = createEnvironmentVars(); CommandLine commandLine = newNodetoolCommandLine("flush"); Executor exec = new DefaultExecutor(); exec.setWorkingDirectory(cassandraDir); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); LogOutputStream stdout = new MavenLogOutputStream(getLog()); LogOutputStream stderr = new MavenLogOutputStream(getLog()); try { getLog().debug("Executing command line: " + commandLine); exec.setStreamHandler(new PumpStreamHandler(stdout, stderr, System.in)); exec.execute(commandLine, environment); getLog().info("Flush triggered."); } catch (ExecuteException e) { throw new MojoExecutionException("Command execution failed.", e); } catch (IOException e) { throw new MojoExecutionException("Command execution failed.", e); } } catch (IOException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }
From source file:org.codehaus.mojo.cassandra.RepairCassandraMojo.java
/** * {@inheritDoc}/*from w ww .j a v a 2 s . com*/ */ public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("Skipping cassandra: cassandra.skip==true"); return; } try { Map environment = createEnvironmentVars(); CommandLine commandLine = newNodetoolCommandLine("repair"); Executor exec = new DefaultExecutor(); exec.setWorkingDirectory(cassandraDir); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); LogOutputStream stdout = new MavenLogOutputStream(getLog()); LogOutputStream stderr = new MavenLogOutputStream(getLog()); try { getLog().debug("Executing command line: " + commandLine); exec.setStreamHandler(new PumpStreamHandler(stdout, stderr, System.in)); exec.execute(commandLine, environment); getLog().info("Repair triggered."); } catch (ExecuteException e) { throw new MojoExecutionException("Command execution failed.", e); } catch (IOException e) { throw new MojoExecutionException("Command execution failed.", e); } } catch (IOException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }