Search in sources :

Example 6 with JobExecutionException

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;
}
Also used : ClassPool(javassist.ClassPool) NotFoundException(javassist.NotFoundException) CallbackEvent(storage.CallbackEvent) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) StorageException(storage.StorageException) NotFoundException(javassist.NotFoundException) CtClass(javassist.CtClass) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) CtClass(javassist.CtClass) StorageException(storage.StorageException)

Example 7 with JobExecutionException

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

Example 8 with JobExecutionException

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");
}
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 9 with JobExecutionException

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());
        }
    }
}
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 10 with JobExecutionException

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;
}
Also used : JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) StorageException(storage.StorageException) NotFoundException(javassist.NotFoundException)

Aggregations

JobExecutionException (es.bsc.compss.nio.exceptions.JobExecutionException)10 NIOParam (es.bsc.compss.nio.NIOParam)4 StorageException (storage.StorageException)4 File (java.io.File)3 NotFoundException (javassist.NotFoundException)3 SerializedObjectException (es.bsc.compss.nio.exceptions.SerializedObjectException)2 DataType (es.bsc.compss.types.annotations.parameter.DataType)2 BinaryInvoker (es.bsc.compss.nio.worker.executors.util.BinaryInvoker)1 DecafInvoker (es.bsc.compss.nio.worker.executors.util.DecafInvoker)1 Invoker (es.bsc.compss.nio.worker.executors.util.Invoker)1 JavaInvoker (es.bsc.compss.nio.worker.executors.util.JavaInvoker)1 MPIInvoker (es.bsc.compss.nio.worker.executors.util.MPIInvoker)1 OmpSsInvoker (es.bsc.compss.nio.worker.executors.util.OmpSsInvoker)1 OpenCLInvoker (es.bsc.compss.nio.worker.executors.util.OpenCLInvoker)1 ExternalTaskStatus (es.bsc.compss.nio.worker.util.ExternalTaskStatus)1 MethodType (es.bsc.compss.types.implementations.AbstractMethodImplementation.MethodType)1 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)1 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1