use of es.bsc.compss.types.annotations.parameter.DataType 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.types.annotations.parameter.DataType 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.types.annotations.parameter.DataType in project compss by bsc-wdc.
the class NIOTaskResult method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder("[TASK_RESULT ");
sb.append("[TASK ID= ").append(this.taskId).append("]");
sb.append("[PARAM_TYPES");
for (DataType param : this.paramTypes) {
sb.append(" ").append(param);
}
sb.append("]");
sb.append("[PARAM_VALUES");
for (Object param : this.paramValues) {
sb.append(" ").append(param);
}
sb.append("]");
sb.append("]");
return sb.toString();
}
use of es.bsc.compss.types.annotations.parameter.DataType in project compss by bsc-wdc.
the class COMPSsRuntimeImpl method hasReturn.
/**
* Returns whether the method parameters define a return or not
*
* @param parameters
* @return
*/
private boolean hasReturn(Parameter[] parameters) {
boolean hasReturn = false;
if (parameters.length != 0) {
Parameter lastParam = parameters[parameters.length - 1];
DataType type = lastParam.getType();
hasReturn = (lastParam.getDirection() == Direction.OUT && (type == DataType.OBJECT_T || type == DataType.PSCO_T || type == DataType.EXTERNAL_OBJECT_T));
}
return hasReturn;
}
Aggregations