use of org.zeroturnaround.exec.ProcessExecutor in project mongo-hadoop by mongodb.
the class BaseHadoopTest method mongoImport.
public void mongoImport(final String collection, final File file) {
try {
final List<String> command = new ArrayList<String>();
command.addAll(asList(MONGO_IMPORT, "--drop", "--db", "mongo_hadoop", "--collection", collection, "--file", file.getAbsolutePath()));
if (isAuthEnabled()) {
final List<String> list = new ArrayList<String>(asList("-u", "bob", "-p", "pwd123"));
if (!System.getProperty("mongodb_server", "").equals("22-release")) {
list.addAll(asList("--authenticationDatabase", "admin"));
}
command.addAll(list);
}
final StringBuilder output = new StringBuilder();
final Iterator<String> iterator = command.iterator();
while (iterator.hasNext()) {
final String s = iterator.next();
if (output.length() != 0) {
output.append("\t");
} else {
output.append("\n");
}
output.append(s);
if (iterator.hasNext()) {
output.append(" \\");
}
output.append("\n");
}
LOG.info(output.toString());
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
final ByteArrayOutputStream errStream = new ByteArrayOutputStream();
final ProcessExecutor executor = new ProcessExecutor().command(command).readOutput(true).redirectOutput(outStream).redirectError(errStream);
final ProcessResult result = executor.execute();
if (result.getExitValue() != 0) {
LOG.error(result.getOutput().getString());
throw new RuntimeException(String.format("mongoimport failed with exit code %d: %s", result.getExitValue(), result.getOutput().getString()));
}
} catch (final IOException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (final InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (final TimeoutException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.zeroturnaround.exec.ProcessExecutor in project morphia by mongodb.
the class ZipCodeDataSetTest method installSampleData.
public void installSampleData() throws IOException, TimeoutException, InterruptedException {
File file = new File("zips.json");
if (!file.exists()) {
file = new File(System.getProperty("java.io.tmpdir"), "zips.json");
if (!file.exists()) {
download(new URL("http://media.mongodb.org/zips.json"), file);
}
}
DBCollection zips = getDb().getCollection("zips");
if (zips.count() == 0) {
new ProcessExecutor().command(MONGO_IMPORT, "--db", getDb().getName(), "--collection", "zipcodes", "--file", file.getAbsolutePath()).redirectError(System.err).execute();
}
}
use of org.zeroturnaround.exec.ProcessExecutor in project ninja by ninjaframework.
the class RunClassInSeparateJvmMachine method buildProcessExecutor.
ProcessExecutor buildProcessExecutor() {
List<String> commandLine = new ArrayList<>();
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
commandLine.add(javaBin);
commandLine.addAll(jvmArguments);
commandLine.add("-cp");
commandLine.add(classpath);
commandLine.add(classNameWithMainToRun);
// not redirecting error stream used for unit tests
return new ProcessExecutor(commandLine).directory(mavenBaseDir).destroyOnExit().addListener(new ProcessListener() {
@Override
public void afterStop(Process process) {
if (!restarting.get()) {
log.error("JVM process for {} terminated (next file change will attempt to restart it)", name);
}
}
}).redirectErrorStream(true).redirectOutput(this.output);
}
use of org.zeroturnaround.exec.ProcessExecutor in project mongo-hadoop by mongodb.
the class HiveTest method loadIntoHDFS.
protected void loadIntoHDFS(final String localPath, final String hdfsPath) {
try {
new ProcessExecutor(HADOOP_HOME + "/bin/hadoop", "fs", "-mkdir", "-p", hdfsPath).redirectOutput(System.out).execute();
new ProcessExecutor(HADOOP_HOME + "/bin/hadoop", "fs", "-put", localPath, hdfsPath).directory(PROJECT_HOME).redirectOutput(System.out).execute();
} catch (final Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations