Search in sources :

Example 11 with DataType

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");
}
Also used : ExternalTaskStatus(es.bsc.compss.nio.worker.util.ExternalTaskStatus) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) FileOutputStream(java.io.FileOutputStream) DataType(es.bsc.compss.types.annotations.parameter.DataType) Semaphore(java.util.concurrent.Semaphore) SerializedObjectException(es.bsc.compss.nio.exceptions.SerializedObjectException) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException)

Example 12 with DataType

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());
        }
    }
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) DataType(es.bsc.compss.types.annotations.parameter.DataType) File(java.io.File) NIOParam(es.bsc.compss.nio.NIOParam)

Example 13 with DataType

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();
}
Also used : DataType(es.bsc.compss.types.annotations.parameter.DataType)

Example 14 with DataType

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;
}
Also used : ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) Parameter(es.bsc.compss.types.parameter.Parameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType)

Aggregations

DataType (es.bsc.compss.types.annotations.parameter.DataType)14 Parameter (es.bsc.compss.types.parameter.Parameter)6 BasicTypeParameter (es.bsc.compss.types.parameter.BasicTypeParameter)5 DependencyParameter (es.bsc.compss.types.parameter.DependencyParameter)5 DataAccessId (es.bsc.compss.types.data.DataAccessId)4 RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)3 ExternalObjectParameter (es.bsc.compss.types.parameter.ExternalObjectParameter)3 FileParameter (es.bsc.compss.types.parameter.FileParameter)3 ObjectParameter (es.bsc.compss.types.parameter.ObjectParameter)3 Semaphore (java.util.concurrent.Semaphore)3 NIOParam (es.bsc.compss.nio.NIOParam)2 JobExecutionException (es.bsc.compss.nio.exceptions.JobExecutionException)2 Stream (es.bsc.compss.types.annotations.parameter.Stream)2 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)2 File (java.io.File)2 File (org.gridlab.gat.io.File)2 Data (es.bsc.compss.nio.commands.Data)1 SerializedObjectException (es.bsc.compss.nio.exceptions.SerializedObjectException)1 ExternalTaskStatus (es.bsc.compss.nio.worker.util.ExternalTaskStatus)1 TaskState (es.bsc.compss.types.Task.TaskState)1