use of org.zeroturnaround.exec.ProcessResult 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.ProcessResult in project ninja by ninjaframework.
the class RunClassInSeparateJvmMachine method restart.
public synchronized void restart() {
restarting.set(true);
try {
if (this.activeProcess != null) {
log.debug("Attempting to destroy previous {} process", name);
this.activeProcess.getProcess().destroy();
log.debug("Waiting for previous {} process to terminate", name);
ProcessResult result = this.activeProcess.getFuture().get();
}
log.debug("Starting new {}", name);
this.activeProcess = startProcess();
} catch (ExecutionException | InterruptedException | IOException e) {
log.error("Something fishy happenend. Unable to cleanly restart {}!", name, e);
log.error("You'll probably need to restart maven?");
} finally {
restarting.set(false);
}
}
use of org.zeroturnaround.exec.ProcessResult in project ninja by ninjaframework.
the class RunClassInSeparateJvmMachineTest method startProcess.
@Test
public void startProcess() throws Exception {
RunClassInSeparateJvmMachine rcsjm = new RunClassInSeparateJvmMachine("FakeDaemon", FakeDaemonMain.class.getName(), getOurClassPath(), Collections.EMPTY_LIST, new File("."));
// override output so we can capture it
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
rcsjm.setOutput(baos);
StartedProcess startedProcess = rcsjm.startProcess();
assertTrue(isAlive(startedProcess.getProcess()));
waitOrTimeout(fakeDaemonCondition(baos), Timeout.timeout(Duration.millis(10000)));
startedProcess.getProcess().destroy();
ProcessResult processResult = startedProcess.getFuture().get();
}
Aggregations