List of usage examples for org.apache.commons.exec DefaultExecutor DefaultExecutor
public DefaultExecutor()
From source file:org.apache.zeppelin.submarine.SubmarineShellInterpreter.java
public void createSecureConfiguration() throws InterpreterException { Properties properties = getProperties(); CommandLine cmdLine = CommandLine.parse(shell); cmdLine.addArgument("-c", false); String kinitCommand = String.format("kinit -k -t %s %s", properties.getProperty(SUBMARINE_HADOOP_KEYTAB), properties.getProperty(SUBMARINE_HADOOP_PRINCIPAL)); cmdLine.addArgument(kinitCommand, false); DefaultExecutor executor = new DefaultExecutor(); try {/*w w w. j ava 2 s . c o m*/ executor.execute(cmdLine); } catch (Exception e) { LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e); throw new InterpreterException(e); } }
From source file:org.apache.zeppelin.util.ProcessLauncher.java
public void launch() { DefaultExecutor executor = new DefaultExecutor(); this.processOutput = new ProcessLogOutputStream(); executor.setStreamHandler(new PumpStreamHandler(processOutput)); this.watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchdog);/*from w w w.j av a2s .com*/ 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(); } }
From source file:org.atmosphere.vibe.ProtocolTest.java
@Test public void protocol() throws Exception { final DefaultServer server = new DefaultServer(); server.onsocket(new Action<ServerSocket>() { @Override//from w w w . j a v a 2 s .c o m public void on(final ServerSocket socket) { socket.on("abort", new VoidAction() { @Override public void on() { socket.close(); } }).on("echo", new Action<Object>() { @Override public void on(Object data) { socket.send("echo", data); } }).on("/reply/inbound", new Action<Reply<Map<String, Object>>>() { @Override public void on(Reply<Map<String, Object>> reply) { Map<String, Object> data = reply.data(); switch ((String) data.get("type")) { case "resolved": reply.resolve(data.get("data")); break; case "rejected": reply.reject(data.get("data")); break; } } }).on("/reply/outbound", new Action<Map<String, Object>>() { @Override public void on(Map<String, Object> data) { switch ((String) data.get("type")) { case "resolved": socket.send("test", data.get("data"), new Action<Object>() { @Override public void on(Object data) { socket.send("done", data); } }); break; case "rejected": socket.send("test", data.get("data"), null, new Action<Object>() { @Override public void on(Object data) { socket.send("done", data); } }); break; } } }); } }); final HttpTransportServer httpTransportServer = new HttpTransportServer().ontransport(server); final WebSocketTransportServer wsTransportServer = new WebSocketTransportServer().ontransport(server); org.eclipse.jetty.server.Server jetty = new org.eclipse.jetty.server.Server(); ServerConnector connector = new ServerConnector(jetty); connector.setPort(8000); jetty.addConnector(connector); ServletContextHandler handler = new ServletContextHandler(); handler.addEventListener(new ServletContextListener() { @Override @SuppressWarnings("serial") public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); // /setup ServletRegistration regSetup = context.addServlet("/setup", new HttpServlet() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Map<String, String[]> params = req.getParameterMap(); if (params.containsKey("heartbeat")) { server.setHeartbeat(Integer.parseInt(params.get("heartbeat")[0])); } if (params.containsKey("_heartbeat")) { server.set_heartbeat(Integer.parseInt(params.get("_heartbeat")[0])); } } }); regSetup.addMapping("/setup"); // /vibe Servlet servlet = new VibeAtmosphereServlet().onhttp(httpTransportServer) .onwebsocket(wsTransportServer); ServletRegistration.Dynamic reg = context.addServlet(VibeAtmosphereServlet.class.getName(), servlet); reg.setAsyncSupported(true); reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString()); reg.addMapping("/vibe"); } @Override public void contextDestroyed(ServletContextEvent sce) { } }); jetty.setHandler(handler); jetty.start(); CommandLine cmdLine = CommandLine.parse("./src/test/resources/node/node") .addArgument("./src/test/resources/runner").addArgument("--vibe.transports") .addArgument("websocket,httpstream,httplongpoll"); DefaultExecutor executor = new DefaultExecutor(); // The exit value of mocha is the number of failed tests. executor.execute(cmdLine); jetty.stop(); }
From source file:org.benetech.secureapp.generator.SecureAppGeneratorApplication.java
static public int executeCommand(HttpSession session, String command, File initialDirectory) throws IOException, InterruptedException { /** TODO: This should not really be done synchronously for a number of reasons, commons-exec provides a * number of different ways to go about running async processes *//*from ww w . ja v a 2s .c o m*/ CommandLine cmdLine = CommandLine.parse(command); DefaultExecutor executor = new DefaultExecutor(); int exitStatus = executor.execute(cmdLine); return exitStatus; }
From source file:org.bonitasoft.platform.setup.PlatformSetupTestUtils.java
public static DefaultExecutor createExecutor(File distFolder) { DefaultExecutor oDefaultExecutor = new DefaultExecutor(); oDefaultExecutor.setWorkingDirectory(distFolder); return oDefaultExecutor; }
From source file:org.brailleblaster.util.ProgramCaller.java
public ProgramCaller(String command, String[] args, int returnValue) throws ExecuteException, IOException { cmdLine = new CommandLine(command + BBIni.getNativeCommandSuffix()); for (int i = 0; i < args.length; i++) cmdLine.addArgument(args[i]);// w w w . ja va2s. com resultHandler = new DefaultExecuteResultHandler(); ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); Executor executor = new DefaultExecutor(); executor.setExitValue(returnValue); executor.setWatchdog(watchdog); executor.execute(cmdLine, resultHandler); }
From source file:org.cloudifysource.dsl.context.utils.VolumeUtils.java
private static void executeCommandLine(final String commandLine, final long timeout) throws LocalStorageOperationException, TimeoutException { Executor executor = new DefaultExecutor(); executor.setExitValue(0);/* ww w .j a va 2 s. c o m*/ ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); ProcessOutputStream outAndErr = new ProcessOutputStream(); try { PumpStreamHandler streamHandler = new PumpStreamHandler(outAndErr); executor.setStreamHandler(streamHandler); logger.info("Executing commandLine : '" + commandLine + "'"); executor.execute(CommandLine.parse(commandLine)); logger.info("Execution completed successfully. Process output was : " + outAndErr.getOutput()); } catch (final Exception e) { if (watchdog.killedProcess()) { throw new TimeoutException("Timed out while executing commandLine : '" + commandLine + "'"); } throw new LocalStorageOperationException("Failed executing commandLine : '" + commandLine + ". Process output was : " + outAndErr.getOutput(), e); } }
From source file:org.cloudifysource.shell.commands.StartLocalCloud.java
private void startLocalAgent(Admin admin) throws ExecuteException, IOException { File binDir = new File(Environment.getHomeDirectory(), "bin"); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(binDir); CommandLine cmdLine = createCommandLine(); executor.setExitValue(0);/* w w w .j a v a 2 s .co m*/ executor.execute(cmdLine, new ExecuteResultHandler() { @Override public void onProcessFailed(ExecuteException e) { logger.log(Level.SEVERE, "Local Cloud Agent terminated unexpectedly", e); } @Override public void onProcessComplete(int arg0) { logger.fine("Local Cloud Agent terminated"); } }); boolean foundLus = admin.getLookupServices().waitFor(1, 1, TimeUnit.MINUTES); if (!foundLus) { throw new java.lang.IllegalStateException("Local Cloud Lookup Service did not start!"); } }
From source file:org.cloudifysource.shell.commands.TestRecipe.java
/** * Execute a command line in with a given map of environment settings. The execution outupt is filtered unless * verbose is set to true.//from w w w .ja va 2s .c o m * * @param cmdLine * The command to execute * @param env * Environment settings available for the command execution * @return the command's execution exit code, or -2 if the command failed to execute */ private int executeRecipe(final CommandLine cmdLine, final Map<Object, Object> env) { final DefaultExecutor executor = new DefaultExecutor(); // The watchdog will terminate the process if it does not end within the // specified timeout final int externalProcessTimeout = (this.timeout + EXTERNAL_PROCESS_WATCHDOG_ADDITIONAL_TIMEOUT) * 1000; final ExecuteWatchdog watchdog = new TestRecipeWatchdog(externalProcessTimeout); executor.setWatchdog(watchdog); executor.setExitValue(0); int result = -1; PipedInputStream in = null; PipedOutputStream out = null; BufferedReader reader = null; try { in = new PipedInputStream(); out = new PipedOutputStream(in); reader = new BufferedReader(new InputStreamReader(in)); final Thread thread = new Thread(new FilteredOutputHandler(reader, this.verbose)); thread.setDaemon(true); thread.start(); final PumpStreamHandler psh = new PumpStreamHandler(out, out); executor.setStreamHandler(psh); result = executor.execute(cmdLine, env); } catch (final ExecuteException e) { logger.log(Level.SEVERE, "A problem was encountered while executing the recipe: " + e.getMessage(), e); } catch (final IOException e) { logger.log(Level.SEVERE, "An IO Exception was encountered while executing the recipe: " + e.getMessage(), e); result = UNEXPECTED_ERROR_EXIT_CODE; } return result; }
From source file:org.cloudifysource.utilitydomain.context.blockstorage.VolumeUtils.java
private static void executeCommandLine(final String commandLine, final long timeout) throws LocalStorageOperationException, TimeoutException { Executor executor = new DefaultExecutor(); executor.setExitValue(0);/* w ww .j a v a 2s .c o m*/ ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); ProcessOutputStream outAndErr = new ProcessOutputStream(); try { PumpStreamHandler streamHandler = new PumpStreamHandler(outAndErr); executor.setStreamHandler(streamHandler); logger.info("Executing commandLine : '" + commandLine + "'"); executor.execute(CommandLine.parse(commandLine)); logger.info("Execution completed successfully. Process output was : " + outAndErr.getOutput()); } catch (final Exception e) { if (watchdog.killedProcess()) { throw new TimeoutException("Timed out while executing commandLine : '" + commandLine + "'"); } throw new LocalStorageOperationException("Failed executing commandLine : '" + commandLine + ". Process output was : " + outAndErr.getOutput(), e); } }