use of es.bsc.compss.nio.master.handlers.ProcessOut in project compss by bsc-wdc.
the class WorkerStarter method killPreviousWorker.
private void killPreviousWorker(String user, String name, int pid) throws InitNodeException {
if (pid != -1) {
// Command was started but it is not possible to contact to the worker
String[] command = getStopCommand(pid);
ProcessOut po = executeCommand(user, name, command);
if (po == null) {
// Queue System managed worker starter
LOGGER.error("[START_CMD_ERROR]: An Error has occurred when queue system started NIO worker in resource " + name + ". Retries not available in this option.");
throw new InitNodeException("[START_CMD_ERROR]: An Error has occurred when queue system started NIO worker in resource " + name + ". Retries not available in this option.");
} else if (po.getExitValue() != 0) {
// Normal starting process
LOGGER.error(ERROR_SHUTTING_DOWN_RETRY);
}
}
}
use of es.bsc.compss.nio.master.handlers.ProcessOut in project compss by bsc-wdc.
the class WorkerStarter method executeCommand.
private ProcessOut executeCommand(String user, String resource, String[] command) {
ProcessOut processOut = new ProcessOut();
String[] cmd = this.nw.getConfiguration().getRemoteExecutionCommand(user, resource, command);
if (cmd == null) {
LOGGER.warn("Worker configured to be sarted by queue system.");
return null;
}
// Log command
StringBuilder sb = new StringBuilder("");
for (String param : cmd) {
sb.append(param).append(" ");
}
LOGGER.debug("COMM CMD: " + sb.toString());
// Execute command
try {
ProcessBuilder pb = new ProcessBuilder();
pb.environment().remove(Tracer.LD_PRELOAD);
pb.command(cmd);
Process process = pb.start();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
process.getOutputStream().close();
process.waitFor();
processOut.setExitValue(process.exitValue());
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
String line;
while ((line = reader.readLine()) != null) {
processOut.appendOutput(line);
LOGGER.debug("COMM CMD OUT: " + line);
}
reader = new BufferedReader(new InputStreamReader(stderr));
while ((line = reader.readLine()) != null) {
processOut.appendError(line);
LOGGER.debug("COMM CMD ERR: " + line);
}
} catch (Exception e) {
LOGGER.error("Exception initializing worker ", e);
}
return processOut;
}
use of es.bsc.compss.nio.master.handlers.ProcessOut in project compss by bsc-wdc.
the class WorkerStarter method startWorker.
private int startWorker(String user, String name, int port) throws InitNodeException {
// Initial wait
try {
Thread.sleep(START_WORKER_INITIAL_WAIT);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
long timer = START_WORKER_INITIAL_WAIT;
// Try to launch the worker until we receive the PID or we timeout
int pid = -1;
String[] command = getStartCommand(port);
do {
ProcessOut po = executeCommand(user, name, command);
if (po == null) {
// Queue System managed worker starter
LOGGER.debug("Worker process started in resource " + name + " by queue system.");
pid = 0;
} else if (po.getExitValue() == 0) {
// Success
String output = po.getOutput();
String[] lines = output.split("\n");
pid = Integer.parseInt(lines[lines.length - 1]);
} else {
if (timer > MAX_WAIT_FOR_SSH) {
// Timeout
throw new InitNodeException("[START_CMD_ERROR]: Could not start the NIO worker in resource " + name + " through user " + user + ".\n" + "OUTPUT:" + po.getOutput() + "\n" + "ERROR:" + po.getError() + "\n");
}
LOGGER.warn(" Worker process failed to start in resource " + name + ". Retrying...");
}
// Sleep between retries
try {
Thread.sleep(4 * WAIT_TIME_UNIT);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
timer = timer + (4 * WAIT_TIME_UNIT);
} while (pid < 0);
return pid;
}
Aggregations