Search in sources :

Example 6 with NIOParam

use of es.bsc.compss.nio.NIOParam 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 7 with NIOParam

use of es.bsc.compss.nio.NIOParam in project compss by bsc-wdc.

the class Executor method bindOriginalFilenamesToRenames.

/**
 * Create symbolic links from files with the original name in task sandbox to the renamed file
 *
 * @param nt
 *            task description
 * @param sandbox
 *            created sandbox
 * @throws IOException
 * @throws Exception
 *             returns exception is a problem occurs during creation
 */
private void bindOriginalFilenamesToRenames(NIOTask nt, File sandbox) throws IOException {
    for (NIOParam param : nt.getParams()) {
        if (param.getType().equals(DataType.FILE_T)) {
            String renamedFilePath = (String) param.getValue();
            File renamedFile = new File(renamedFilePath);
            if (renamedFile.getName().equals(param.getOriginalName())) {
                param.setOriginalName(renamedFilePath);
            } else {
                String newOrigFilePath = sandbox.getAbsolutePath() + File.separator + param.getOriginalName();
                LOGGER.debug("Setting Original Name to " + newOrigFilePath);
                param.setOriginalName(newOrigFilePath);
                File newOrigFile = new File(newOrigFilePath);
                if (renamedFile.exists()) {
                    // IN or INOUT File creating a symbolic link
                    if (!newOrigFile.exists()) {
                        LOGGER.debug("Creating symlink " + newOrigFile.toPath() + " pointing to " + renamedFile.toPath());
                        Files.createSymbolicLink(newOrigFile.toPath(), renamedFile.toPath());
                    } else {
                        if (Files.isSymbolicLink(newOrigFile.toPath())) {
                            Path oldRenamed = Files.readSymbolicLink(newOrigFile.toPath());
                            LOGGER.debug("Checking if " + renamedFile.getName() + " is equal to " + oldRenamed.getFileName().toString());
                            if (isMajorVersion(renamedFile.getName(), oldRenamed.getFileName().toString())) {
                                Files.delete(newOrigFile.toPath());
                                Files.createSymbolicLink(newOrigFile.toPath(), renamedFile.toPath());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) File(java.io.File) NIOParam(es.bsc.compss.nio.NIOParam)

Example 8 with NIOParam

use of es.bsc.compss.nio.NIOParam 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)

Aggregations

NIOParam (es.bsc.compss.nio.NIOParam)8 JobExecutionException (es.bsc.compss.nio.exceptions.JobExecutionException)4 File (java.io.File)4 DataType (es.bsc.compss.types.annotations.parameter.DataType)2 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)2 NIOTask (es.bsc.compss.nio.NIOTask)1 Data (es.bsc.compss.nio.commands.Data)1 TransferringTask (es.bsc.compss.nio.dataRequest.WorkerDataRequest.TransferringTask)1 DataAccessId (es.bsc.compss.types.data.DataAccessId)1 RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)1 RWAccessId (es.bsc.compss.types.data.DataAccessId.RWAccessId)1 WAccessId (es.bsc.compss.types.data.DataAccessId.WAccessId)1 AbstractMethodImplementation (es.bsc.compss.types.implementations.AbstractMethodImplementation)1 BasicTypeParameter (es.bsc.compss.types.parameter.BasicTypeParameter)1 DependencyParameter (es.bsc.compss.types.parameter.DependencyParameter)1 Parameter (es.bsc.compss.types.parameter.Parameter)1 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1