Search in sources :

Example 1 with JobExecutionException

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

Example 2 with JobExecutionException

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();
    }
}
Also used : MethodType(es.bsc.compss.types.implementations.AbstractMethodImplementation.MethodType) OmpSsInvoker(es.bsc.compss.nio.worker.executors.util.OmpSsInvoker) JavaInvoker(es.bsc.compss.nio.worker.executors.util.JavaInvoker) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) Invoker(es.bsc.compss.nio.worker.executors.util.Invoker) BinaryInvoker(es.bsc.compss.nio.worker.executors.util.BinaryInvoker) OpenCLInvoker(es.bsc.compss.nio.worker.executors.util.OpenCLInvoker) OmpSsInvoker(es.bsc.compss.nio.worker.executors.util.OmpSsInvoker) DecafInvoker(es.bsc.compss.nio.worker.executors.util.DecafInvoker) MPIInvoker(es.bsc.compss.nio.worker.executors.util.MPIInvoker) JavaInvoker(es.bsc.compss.nio.worker.executors.util.JavaInvoker) DecafInvoker(es.bsc.compss.nio.worker.executors.util.DecafInvoker) OpenCLInvoker(es.bsc.compss.nio.worker.executors.util.OpenCLInvoker) MPIInvoker(es.bsc.compss.nio.worker.executors.util.MPIInvoker) BinaryInvoker(es.bsc.compss.nio.worker.executors.util.BinaryInvoker)

Example 3 with JobExecutionException

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

Example 4 with JobExecutionException

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

Example 5 with JobExecutionException

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;
}
Also used : JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) Method(java.lang.reflect.Method) 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