use of es.bsc.compss.nio.worker.util.ExternalTaskStatus in project compss by bsc-wdc.
the class ExternalExecutor method executeExternal.
private void executeExternal(int jobId, String command, NIOTask nt, NIOWorker nw) throws JobExecutionException {
// Emit start task trace
// +1 Because Task ID can't be 0 (0 signals end task)
int taskType = nt.getTaskType() + 1;
int taskId = nt.getTaskId();
if (NIOTracer.isActivated()) {
emitStartTask(taskId, taskType);
}
LOGGER.debug("Starting job process ...");
// Send executeTask tag to pipe
boolean done = false;
int retries = 0;
while (!done && retries < MAX_RETRIES) {
// Send to pipe : task tID command(jobOut jobErr externalCMD) \n
String taskCMD = EXECUTE_TASK_TAG + TOKEN_SEP + jobId + TOKEN_SEP + command + TOKEN_NEW_LINE;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("EXECUTOR COMMAND: " + taskCMD);
}
try (FileOutputStream output = new FileOutputStream(writePipe, true)) {
output.write(taskCMD.getBytes());
output.flush();
output.close();
done = true;
} catch (Exception e) {
LOGGER.debug("Error on pipe write. Retry");
++retries;
}
}
if (!done) {
if (NIOTracer.isActivated()) {
emitEndTask();
}
LOGGER.error("ERROR: Could not execute job " + jobId + " because cannot write in pipe");
throw new JobExecutionException("Job " + jobId + " has failed. Cannot write in pipe");
}
// Retrieving job result
LOGGER.debug("Waiting for job " + jobId + " completion");
Semaphore sem = new Semaphore(0);
taskResultReader.askForTaskEnd(jobId, sem);
try {
sem.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
LOGGER.debug("Job " + jobId + " completed. Retrieving task result");
ExternalTaskStatus taskStatus = taskResultReader.getTaskStatus(jobId);
// Check task exit value
Integer exitValue = taskStatus.getExitValue();
if (exitValue != 0) {
if (NIOTracer.isActivated()) {
emitEndTask();
}
throw new JobExecutionException("Job " + jobId + " has failed. Exit values is " + exitValue);
}
// Update parameters
LOGGER.debug("Updating parameters for job " + jobId);
for (int i = 0; i < taskStatus.getNumParameters(); ++i) {
DataType paramType = taskStatus.getParameterType(i);
if (paramType.equals(DataType.EXTERNAL_OBJECT_T)) {
String paramValue = taskStatus.getParameterValue(i);
nt.getParams().get(i).setType(DataType.EXTERNAL_OBJECT_T);
nt.getParams().get(i).setValue(paramValue);
}
}
// Emit end task trace
if (NIOTracer.isActivated()) {
emitEndTask();
}
LOGGER.debug("Job " + jobId + " has finished with exit value 0");
}
Aggregations