use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class Executor method removeOriginalFilenames.
/**
* Undo symbolic links and renames done with the original names in task sandbox to the renamed file
*
* @param nt
* task description
* @throws IOException
* @throws JobExecutionException
* @throws Exception
* returns exception is an unexpected case is found.
*/
private void removeOriginalFilenames(NIOTask nt) throws IOException, JobExecutionException {
for (NIOParam param : nt.getParams()) {
if (param.getType().equals(DataType.FILE_T)) {
String renamedFilePath = (String) param.getValue();
String newOriginalFilePath = param.getOriginalName();
LOGGER.debug("Treating file " + renamedFilePath);
if (!renamedFilePath.equals(newOriginalFilePath)) {
File newOrigFile = new File(newOriginalFilePath);
File renamedFile = new File(renamedFilePath);
if (renamedFile.exists()) {
// IN, INOUT
if (newOrigFile.exists()) {
if (Files.isSymbolicLink(newOrigFile.toPath())) {
// If a symbolic link is created remove it
LOGGER.debug("Deleting symlink " + newOrigFile.toPath());
Files.delete(newOrigFile.toPath());
} else {
// Rewrite inout param by moving the new file to the renaming
move(newOrigFile.toPath(), renamedFile.toPath());
}
} else {
// Both files exist and are updated
LOGGER.debug("Repeated data for " + renamedFilePath + ". Nothing to do");
}
} else {
// OUT
if (newOrigFile.exists()) {
if (Files.isSymbolicLink(newOrigFile.toPath())) {
// Unexpected case
String msg = "ERROR: Unexpected case. A Problem occurred with File " + renamedFilePath + ". Either this file or the original name " + newOriginalFilePath + " do not exist.";
LOGGER.error(msg);
System.err.println(msg);
throw new JobExecutionException(msg);
} else {
// If an output file is created move to the renamed path (OUT Case)
move(newOrigFile.toPath(), renamedFile.toPath());
}
} else {
// Error output file does not exist
String msg = "ERROR: Output file " + newOriginalFilePath + " does not exist";
// Unexpected case (except for C binding when not serializing outputs)
if (Lang.valueOf(nt.getLang().toUpperCase()) != Lang.C) {
LOGGER.error(msg);
System.err.println(msg);
throw new JobExecutionException(msg);
}
}
}
}
}
}
}
use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class JavaExecutor method executeTask.
@Override
public void executeTask(NIOWorker nw, NIOTask nt, String outputsBasename, File taskSandboxWorkingDir, int[] assignedCoreUnits, int[] assignedGPUs) throws JobExecutionException {
/* Register outputs **************************************** */
NIOWorker.registerOutputs(outputsBasename);
/* TRY TO PROCESS THE TASK ******************************** */
System.out.println("[JAVA EXECUTOR] executeTask - Begin task execution");
try {
MethodType methodType = nt.getMethodType();
Invoker invoker = null;
switch(methodType) {
case METHOD:
invoker = new JavaInvoker(nw, nt, taskSandboxWorkingDir, assignedCoreUnits);
break;
case MPI:
invoker = new MPIInvoker(nw, nt, taskSandboxWorkingDir, assignedCoreUnits);
break;
case DECAF:
invoker = new DecafInvoker(nw, nt, taskSandboxWorkingDir, assignedCoreUnits);
break;
case OMPSS:
invoker = new OmpSsInvoker(nw, nt, taskSandboxWorkingDir, assignedCoreUnits);
break;
case OPENCL:
invoker = new OpenCLInvoker(nw, nt, taskSandboxWorkingDir, assignedCoreUnits);
break;
case BINARY:
invoker = new BinaryInvoker(nw, nt, taskSandboxWorkingDir, assignedCoreUnits);
break;
default:
throw new JobExecutionException("Unrecognised method type");
}
invoker.processTask();
} catch (JobExecutionException jee) {
System.out.println("[JAVA EXECUTOR] executeTask - Error in task execution");
System.err.println("[JAVA EXECUTOR] executeTask - Error in task execution");
jee.printStackTrace();
throw jee;
} finally {
System.out.println("[JAVA EXECUTOR] executeTask - End task execution");
NIOWorker.unregisterOutputs();
}
}
use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class Invoker method serializeBinaryExitValue.
public void serializeBinaryExitValue() throws JobExecutionException {
LOGGER.debug("Checking binary exit value serialization");
NIOParam lastParam = nt.getParams().getLast();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("- Param Type: " + lastParam.getType().name());
LOGGER.debug("- Preserve source data: " + lastParam.isPreserveSourceData());
LOGGER.debug("- Write final value: " + lastParam.isWriteFinalValue());
LOGGER.debug("- Prefix: " + lastParam.getPrefix());
}
// Last parameter is a FILE, direction OUT, with skip prefix => return in Python
if (lastParam.getType().equals(DataType.FILE_T) && !lastParam.isPreserveSourceData() && lastParam.isWriteFinalValue() && lastParam.getPrefix().equals(Constants.PREFIX_SKIP)) {
// Write exit value to the file
String renaming = lastParam.getOriginalName();
LOGGER.info("Writing Binary Exit Value (" + this.retValue.toString() + ") to " + renaming);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(renaming))) {
String value = "I" + this.retValue.toString() + "\n.\n";
writer.write(value);
writer.flush();
} catch (IOException ioe) {
throw new JobExecutionException("ERROR: Cannot serialize binary exit value for bindings", ioe);
}
}
}
use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class Invoker method processParameter.
private void processParameter(NIOParam np, int i) throws JobExecutionException {
// We need to use wrapper classes for basic types, reflection will unwrap automatically
this.streams[i] = np.getStream();
this.prefixes[i] = np.getPrefix();
switch(np.getType()) {
case BOOLEAN_T:
this.types[i] = boolean.class;
this.values[i] = np.getValue();
break;
case CHAR_T:
this.types[i] = char.class;
this.values[i] = np.getValue();
break;
case BYTE_T:
this.types[i] = byte.class;
this.values[i] = np.getValue();
break;
case SHORT_T:
this.types[i] = short.class;
this.values[i] = np.getValue();
break;
case INT_T:
this.types[i] = int.class;
this.values[i] = np.getValue();
break;
case LONG_T:
this.types[i] = long.class;
this.values[i] = np.getValue();
break;
case FLOAT_T:
this.types[i] = float.class;
this.values[i] = np.getValue();
break;
case DOUBLE_T:
this.types[i] = double.class;
this.values[i] = np.getValue();
break;
case STRING_T:
this.types[i] = String.class;
this.values[i] = np.getValue();
break;
case FILE_T:
this.types[i] = String.class;
this.values[i] = np.getOriginalName();
this.writeFinalValue[i] = np.isWriteFinalValue();
break;
case OBJECT_T:
this.renamings[i] = np.getValue().toString();
this.writeFinalValue[i] = np.isWriteFinalValue();
// Get object
Object obj;
try {
obj = this.nw.getObject(this.renamings[i]);
} catch (SerializedObjectException soe) {
throw new JobExecutionException(ERROR_SERIALIZED_OBJ, soe);
}
// Check if object is null
if (obj == null) {
// This happens when 2 tasks have an INOUT PSCO that is persisted within the 1st task
try {
obj = this.nw.getPersistentObject(renamings[i]);
} catch (StorageException se) {
throw new JobExecutionException(ERROR_SERIALIZED_OBJ, se);
}
}
// Check if object is still null
if (obj == null) {
StringBuilder sb = new StringBuilder();
if (this.hasTarget && i == this.numParams - 1) {
sb.append("Target object");
} else {
sb.append("Object parameter ").append(i);
}
sb.append(" with renaming ").append(this.renamings[i]);
sb.append(" in MethodDefinition ").append(this.impl.getMethodDefinition());
sb.append(" is null!").append("\n");
throw new JobExecutionException(sb.toString());
}
// Store information as target or as normal parameter
if (this.hasTarget && i == this.numParams - 1) {
// Last parameter is the target object
this.target.setValue(obj);
} else {
// Any other parameter
this.types[i] = obj.getClass();
this.values[i] = obj;
}
break;
case PSCO_T:
this.renamings[i] = np.getValue().toString();
this.writeFinalValue[i] = np.isWriteFinalValue();
// Get ID
String id = this.renamings[i];
// Get Object
try {
obj = this.nw.getPersistentObject(id);
} catch (StorageException e) {
throw new JobExecutionException(ERROR_PERSISTENT_OBJ + " with id " + id, e);
}
// Check if object is null
if (obj == null) {
StringBuilder sb = new StringBuilder();
if (this.hasTarget && i == this.numParams - 1) {
sb.append("Target PSCO");
} else {
sb.append("PSCO parameter ").append(i);
}
sb.append(" with renaming ").append(this.renamings[i]);
sb.append(" in MethodDefinition ").append(this.impl.getMethodDefinition());
sb.append(" is null!").append("\n");
throw new JobExecutionException(sb.toString());
}
// Store information as target or as normal parameter
if (this.hasTarget && i == this.numParams - 1) {
// Last parameter is the target object
this.target.setValue(obj);
} else {
// Any other parameter
this.types[i] = obj.getClass();
this.values[i] = obj;
}
break;
case EXTERNAL_OBJECT_T:
this.types[i] = String.class;
this.values[i] = np.getValue();
this.writeFinalValue[i] = np.isWriteFinalValue();
break;
}
this.isFile[i] = (np.getType().equals(DataType.FILE_T));
this.canBePSCO[i] = (np.getType().equals(DataType.OBJECT_T)) || (np.getType().equals(DataType.PSCO_T));
}
use of es.bsc.compss.nio.exceptions.JobExecutionException in project compss by bsc-wdc.
the class JavaInvoker method getMethod.
private Method getMethod() throws JobExecutionException {
Class<?> methodClass = null;
Method method = null;
try {
methodClass = Class.forName(this.className);
} catch (Exception e) {
throw new JobExecutionException(ERROR_CLASS_REFLECTION, e);
}
try {
method = methodClass.getMethod(this.methodName, this.types);
} catch (Exception e) {
throw new JobExecutionException(ERROR_METHOD_REFLECTION, e);
}
return method;
}
Aggregations