Java Code Examples for org.apache.commons.exec.Executor#setStreamHandler()

The following examples show how to use org.apache.commons.exec.Executor#setStreamHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: __platform-name__Loader.java    From ldbc_graphalytics with Apache License 2.0 6 votes vote down vote up
public int unload(String loadedInputPath) throws Exception {
	String unloaderDir = platformConfig.getUnloaderPath();
	commandLine = new CommandLine(Paths.get(unloaderDir).toFile());

	commandLine.addArgument("--graph-name");
	commandLine.addArgument(formattedGraph.getName());

	commandLine.addArgument("--output-path");
	commandLine.addArgument(loadedInputPath);

	String commandString = StringUtils.toString(commandLine.toStrings(), " ");
	LOG.info(String.format("Execute graph unloader with command-line: [%s]", commandString));

	Executor executor = new DefaultExecutor();
	executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
	executor.setExitValue(0);

	return executor.execute(commandLine);
}
 
Example 2
Source File: __platform-name__Loader.java    From ldbc_graphalytics with Apache License 2.0 5 votes vote down vote up
public int load(String loadedInputPath) throws Exception {
	String loaderDir = platformConfig.getLoaderPath();
	commandLine = new CommandLine(Paths.get(loaderDir).toFile());

	commandLine.addArgument("--graph-name");
	commandLine.addArgument(formattedGraph.getName());
	commandLine.addArgument("--input-vertex-path");
	commandLine.addArgument(formattedGraph.getVertexFilePath());
	commandLine.addArgument("--input-edge-path");
	commandLine.addArgument(formattedGraph.getEdgeFilePath());
	commandLine.addArgument("--output-path");
	commandLine.addArgument(loadedInputPath);
	commandLine.addArgument("--directed");
	commandLine.addArgument(formattedGraph.isDirected() ? "true" : "false");
	commandLine.addArgument("--weighted");
	commandLine.addArgument(formattedGraph.hasEdgeProperties() ? "true" : "false");


	String commandString = StringUtils.toString(commandLine.toStrings(), " ");
	LOG.info(String.format("Execute graph loader with command-line: [%s]", commandString));

	Executor executor = new DefaultExecutor();
	executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
	executor.setExitValue(0);

	return executor.execute(commandLine);
}
 
Example 3
Source File: __platform-name__Job.java    From ldbc_graphalytics with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the platform job with the pre-defined parameters.
 *
 * @return the exit code
 * @throws IOException if the platform failed to run
 */
public int execute() throws Exception {
	String executableDir = platformConfig.getExecutablePath();
	commandLine = new CommandLine(Paths.get(executableDir).toFile());

	// List of benchmark parameters.
	String jobId = getJobId();
	String logDir = getLogPath();

	// List of dataset parameters.
	String inputPath = getInputPath();
	String outputPath = getOutputPath();

	// List of platform parameters.
	int numMachines = platformConfig.getNumMachines();
	int numThreads = platformConfig.getNumThreads();
	String homeDir = platformConfig.getHomePath();

	appendBenchmarkParameters(jobId, logDir);
	appendAlgorithmParameters();
	appendDatasetParameters(inputPath, outputPath);
	appendPlatformConfigurations(homeDir, numMachines, numThreads);

	String commandString = StringUtils.toString(commandLine.toStrings(), " ");
	LOG.info(String.format("Execute benchmark job with command-line: [%s]", commandString));

	Executor executor = new DefaultExecutor();
	executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
	executor.setExitValue(0);
	return executor.execute(commandLine);
}
 
Example 4
Source File: TasksAutoConfiguration.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Get an {@link Executor} to use for executing processes from tasks.
 *
 * @return The executor to use
 */
// TODO: Remove once agent job runs complete
@Bean
@ConditionalOnMissingBean(Executor.class)
public Executor processExecutor() {
    final Executor executor = new DefaultExecutor();
    executor.setStreamHandler(new PumpStreamHandler(null, null));
    return executor;
}
 
Example 5
Source File: ExecutorFactory.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link Executor} implementation instance.
 *
 * @param detached Whether the streams for processes run on this executor should be detached (ignored) or not
 * @return A {@link Executor} instance
 */
public Executor newInstance(final boolean detached) {
    final Executor executor = new DefaultExecutor();
    if (detached) {
        executor.setStreamHandler(new PumpStreamHandler(null, null));
    }
    return executor;
}
 
Example 6
Source File: BenchmarkRunner.java    From trainbenchmark with Eclipse Public License 1.0 4 votes vote down vote up
public static int runPerformanceBenchmark(final BenchmarkConfig bc, final ExecutionConfig ec)
		throws IOException, InterruptedException {
	final Joiner joiner = Joiner.on(", ");
	System.out.println("Running benchmark.");
	System.out.println("Workload: " + bc.getConfigBase().getWorkload());
	System.out.println("Tool: " + bc.getToolName());
	System.out.println("Model: " + bc.getConfigBase().getModelPath());
	System.out.println("Description: " + bc.getDescription());
	System.out.println("Operations: [" + joiner.join(bc.getConfigBase().getOperations()) + "]");
	System.out.println("Execution configuration: " + ec);
	System.out.println("Runs: " + bc.getConfigBase().getRuns());

	final File configFile = File.createTempFile("trainbenchmark-benchmark-", ".conf");
	final String configPath = configFile.getAbsolutePath();
	bc.saveToFile(configPath);

	final String projectName = String.format("trainbenchmark-tool-%s", bc.getProjectName());
	final String jarPath = String.format("../%s/build/libs/%s-1.0.0-SNAPSHOT-fat.jar %s", projectName, projectName,
			configPath);

	final String javaCommand = String.format("java -Xms%s -Xmx%s -server -jar %s %s", ec.getXms(), ec.getXmx(),
			jarPath, configPath);
	final CommandLine cmdLine = CommandLine.parse(javaCommand);

	final long timeoutInSeconds = bc.getConfigBase().getTimeout();
	final long timeoutInMilliseconds = timeoutInSeconds * 1000;
	final ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutInMilliseconds);
	final Executor executor = new DefaultExecutor();
	executor.setWatchdog(watchdog);
	executor.setStreamHandler(new PumpStreamHandler());
	try {
		final int exitValue = executor.execute(cmdLine);
		System.out.println();
		return exitValue;
	} catch (final ExecuteException e) {
		if (watchdog.killedProcess()) {
			System.out.println("Process timed out.");
		} else {
			e.printStackTrace(System.out);
		}
		return e.getExitValue();
	}
}
 
Example 7
Source File: CommandExecutor.java    From ankush with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Exec.
 *
 * @param command the command
 * @param out the out
 * @param err the err
 * @return the int
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws InterruptedException the interrupted exception
 */
public static int exec(String command, OutputStream out, OutputStream err)
		throws IOException, InterruptedException {
	CommandLine cmdLine = CommandLine.parse(command);
	Executor executor = new DefaultExecutor();
	executor.setStreamHandler(new PumpStreamHandler(out, err, null));
	return executor.execute(cmdLine);
}