use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class JavaInvoker method externalExecution.
private Object externalExecution() throws JobExecutionException {
// Invoke the requested method from the external platform
// WARN: ExternalExecution is only supported for methods with PSCO as target object
int n = method.getParameterAnnotations().length;
ClassPool pool = ClassPool.getDefault();
Class<?>[] cParams = method.getParameterTypes();
CtClass[] ctParams = new CtClass[n];
for (int i = 0; i < n; i++) {
try {
ctParams[i] = pool.getCtClass(((Class<?>) cParams[i]).getName());
} catch (NotFoundException e) {
throw new JobExecutionException(ERROR_CLASS_NOT_FOUND + " " + cParams[i].getName(), e);
}
}
String descriptor;
try {
descriptor = method.getName() + Descriptor.ofMethod(pool.getCtClass(method.getReturnType().getName()), ctParams);
} catch (NotFoundException e) {
throw new JobExecutionException(ERROR_CLASS_NOT_FOUND + " " + method.getReturnType().getName(), e);
}
// Check and retrieve target PSCO Id
String id = null;
try {
id = ((StubItf) target.getValue()).getID();
} catch (Exception e) {
throw new JobExecutionException(ERROR_EXTERNAL_NO_PSCO, e);
}
if (id == null) {
throw new JobExecutionException(ERROR_EXTERNAL_NO_PSCO);
}
// Call Storage executeTask
if (LOGGER.isDebugEnabled()) {
LOGGER.info("External ExecuteTask " + method.getName() + " with target PSCO Id " + id + " in " + nw.getHostName());
} else {
LOGGER.info("External ExecuteTask " + method.getName());
}
if (NIOTracer.isActivated()) {
NIOTracer.emitEvent(NIOTracer.Event.STORAGE_EXECUTETASK.getId(), NIOTracer.Event.STORAGE_EXECUTETASK.getType());
}
PSCOCallbackHandler callback = new PSCOCallbackHandler();
try {
String call_result = StorageItf.executeTask(id, descriptor, values, nw.getHostName(), callback);
LOGGER.debug(call_result);
// Wait for execution
callback.waitForCompletion();
} catch (StorageException e) {
throw new JobExecutionException(ERROR_STORAGE_CALL, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new JobExecutionException(ERROR_CALLBACK_INTERRUPTED, e);
} finally {
if (NIOTracer.isActivated()) {
NIOTracer.emitEvent(NIOTracer.EVENT_END, NIOTracer.Event.STORAGE_EXECUTETASK.getType());
}
}
// Process the return status
CallbackEvent.EventType callStatus = callback.getStatus();
if (!callStatus.equals(CallbackEvent.EventType.SUCCESS)) {
throw new JobExecutionException(ERROR_EXTERNAL_EXECUTION);
}
// Process return value
Object retValue = null;
if (method.getReturnType().getName().compareTo(void.class.getName()) != 0) {
try {
retValue = callback.getResult();
} catch (StorageException e) {
LOGGER.warn(WARN_RET_VALUE_EXCEPTION, e);
retValue = null;
}
}
return retValue;
}
use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class Executor method checkJobFiles.
private void checkJobFiles(NIOTask nt) throws JobExecutionException {
// Check if all the output files have been actually created (in case user has forgotten)
// No need to distinguish between IN or OUT files, because IN files will exist, and
// if there's one or more missing, they will be necessarily out.
boolean allOutFilesCreated = true;
for (NIOParam param : nt.getParams()) {
if (param.getType().equals(DataType.FILE_T)) {
String filepath = (String) param.getValue();
File f = new File(filepath);
// If using C binding we ignore potential errors
if (!f.exists() && (Lang.valueOf(nt.getLang().toUpperCase()) != Lang.C)) {
StringBuilder errMsg = new StringBuilder();
errMsg.append("ERROR: File with path '").append(filepath);
errMsg.append("' not generated by task with Method Definition ").append(nt.getMethodImplementation().getMethodDefinition());
System.out.println(errMsg.toString());
System.err.println(errMsg.toString());
allOutFilesCreated = false;
}
}
}
if (!allOutFilesCreated) {
throw new JobExecutionException(ERROR_OUT_FILES + nt.getMethodImplementation().getMethodDefinition());
}
}
use of es.bsc.compss.nio.exceptions.JobExecutionException 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");
}
use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class ExternalExecutor method addArguments.
private static void addArguments(ArrayList<String> lArgs, NIOTask nt, NIOWorker nw) throws JobExecutionException, SerializedObjectException {
lArgs.add(Boolean.toString(NIOTracer.isActivated()));
lArgs.add(Integer.toString(nt.getTaskId()));
lArgs.add(Boolean.toString(nt.isWorkerDebug()));
lArgs.add(STORAGE_CONF);
// The implementation to execute externally can only be METHOD but we double check it
if (nt.getMethodType() != MethodType.METHOD) {
throw new JobExecutionException(ERROR_UNSUPPORTED_JOB_TYPE);
}
// Add method classname and methodname
MethodImplementation impl = (MethodImplementation) nt.getMethodImplementation();
lArgs.add(String.valueOf(impl.getMethodType()));
lArgs.add(impl.getDeclaringClass());
lArgs.add(impl.getAlternativeMethodName());
// Slave nodes and cus description
lArgs.add(String.valueOf(nt.getSlaveWorkersNodeNames().size()));
lArgs.addAll(nt.getSlaveWorkersNodeNames());
lArgs.add(String.valueOf(nt.getResourceDescription().getTotalCPUComputingUnits()));
// Add target
lArgs.add(Boolean.toString(nt.hasTarget()));
// Add return type
if (nt.hasReturn()) {
DataType returnType = nt.getParams().getLast().getType();
lArgs.add(Integer.toString(returnType.ordinal()));
} else {
lArgs.add("null");
}
// Add parameters
lArgs.add(Integer.toString(nt.getNumParams()));
for (NIOParam np : nt.getParams()) {
DataType type = np.getType();
lArgs.add(Integer.toString(type.ordinal()));
lArgs.add(Integer.toString(np.getStream().ordinal()));
lArgs.add(np.getPrefix());
switch(type) {
case FILE_T:
// Passing originalName link instead of renamed file
String originalFile = "";
if (np.getData() != null) {
originalFile = np.getData().getName();
}
String destFile = new File(np.getValue().toString()).getName();
if (!isRuntimeRenamed(destFile)) {
// Treat corner case: Destfile is original name. Parameter is INPUT with shared disk, so
// destfile should be the same as the input.
destFile = originalFile;
}
lArgs.add(originalFile + ":" + destFile + ":" + np.isPreserveSourceData() + ":" + np.isWriteFinalValue() + ":" + np.getOriginalName());
break;
case OBJECT_T:
case PSCO_T:
case EXTERNAL_OBJECT_T:
lArgs.add(np.getValue().toString());
lArgs.add(np.isWriteFinalValue() ? "W" : "R");
break;
case STRING_T:
String value = np.getValue().toString();
String[] vals = value.split(" ");
int numSubStrings = vals.length;
lArgs.add(Integer.toString(numSubStrings));
for (String v : vals) {
lArgs.add(v);
}
break;
default:
lArgs.add(np.getValue().toString());
}
}
}
use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class JavaInvoker method internalExecution.
private Object internalExecution() throws JobExecutionException {
Object retValue = null;
if (NIOTracer.isActivated()) {
NIOTracer.emitEvent(NIOTracer.Event.STORAGE_INVOKE.getId(), NIOTracer.Event.STORAGE_INVOKE.getType());
}
try {
LOGGER.info("Invoked " + method.getName() + " of " + target + " in " + nw.getHostName());
retValue = method.invoke(target.getValue(), values);
} catch (Exception e) {
throw new JobExecutionException(ERROR_TASK_EXECUTION, e);
} finally {
if (NIOTracer.isActivated()) {
NIOTracer.emitEvent(NIOTracer.EVENT_END, NIOTracer.Event.STORAGE_INVOKE.getType());
}
}
return retValue;
}
Aggregations