Search in sources :

Example 1 with WAccessId

use of es.bsc.compss.types.data.DataAccessId.WAccessId in project compss by bsc-wdc.

the class NIOJob method addParams.

private LinkedList<NIOParam> addParams() {
    LinkedList<NIOParam> params = new LinkedList<>();
    for (Parameter param : taskParams.getParameters()) {
        DataType type = param.getType();
        NIOParam np;
        switch(type) {
            case FILE_T:
            case OBJECT_T:
            case PSCO_T:
            case EXTERNAL_OBJECT_T:
                DependencyParameter dPar = (DependencyParameter) param;
                DataAccessId dAccId = dPar.getDataAccessId();
                Object value = dPar.getDataTarget();
                boolean preserveSourceData = true;
                if (dAccId instanceof RAccessId) {
                    // Parameter is a R, has sources
                    preserveSourceData = ((RAccessId) dAccId).isPreserveSourceData();
                } else if (dAccId instanceof RWAccessId) {
                    // Parameter is a RW, has sources
                    preserveSourceData = ((RWAccessId) dAccId).isPreserveSourceData();
                } else {
                    // Parameter is a W, it has no sources
                    preserveSourceData = false;
                }
                // Workaround for Python PSCOs in return
                // Check if the parameter has a valid PSCO and change its type
                String renaming;
                DataAccessId faId = dPar.getDataAccessId();
                if (faId instanceof WAccessId) {
                    // Write mode
                    WAccessId waId = (WAccessId) faId;
                    renaming = waId.getWrittenDataInstance().getRenaming();
                } else if (faId instanceof RWAccessId) {
                    // Read write mode
                    RWAccessId rwaId = (RWAccessId) faId;
                    renaming = rwaId.getWrittenDataInstance().getRenaming();
                } else {
                    // Read only mode
                    RAccessId raId = (RAccessId) faId;
                    renaming = raId.getReadDataInstance().getRenaming();
                }
                String pscoId = Comm.getData(renaming).getId();
                if (pscoId != null && type.equals(DataType.FILE_T)) {
                    param.setType(DataType.EXTERNAL_OBJECT_T);
                    type = param.getType();
                }
                // Create the NIO Param
                // Only store W and RW
                boolean writeFinalValue = !(dAccId instanceof RAccessId);
                np = new NIOParam(type, param.getStream(), param.getPrefix(), preserveSourceData, writeFinalValue, value, (Data) dPar.getDataSource(), dPar.getOriginalName());
                break;
            default:
                BasicTypeParameter btParB = (BasicTypeParameter) param;
                value = btParB.getValue();
                // Basic parameters are not preserved on Worker
                preserveSourceData = false;
                // Basic parameters are not stored on Worker
                writeFinalValue = false;
                np = new NIOParam(type, param.getStream(), param.getPrefix(), preserveSourceData, writeFinalValue, value, null, DependencyParameter.NO_NAME);
                break;
        }
        params.add(np);
    }
    return params;
}
Also used : RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) Data(es.bsc.compss.nio.commands.Data) LinkedList(java.util.LinkedList) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType) WAccessId(es.bsc.compss.types.data.DataAccessId.WAccessId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) DataAccessId(es.bsc.compss.types.data.DataAccessId) NIOParam(es.bsc.compss.nio.NIOParam)

Example 2 with WAccessId

use of es.bsc.compss.types.data.DataAccessId.WAccessId in project compss by bsc-wdc.

the class TransferOpenFileRequest method process.

@Override
public void process(AccessProcessor ap, TaskAnalyser ta, DataInfoProvider dip, TaskDispatcher td) {
    LOGGER.debug("Process TransferOpenFileRequest");
    // Get target information
    String targetName;
    String targetPath;
    if (faId instanceof WAccessId) {
        // Write mode
        WAccessId waId = (WAccessId) faId;
        DataInstanceId targetFile = waId.getWrittenDataInstance();
        targetName = targetFile.getRenaming();
        targetPath = Comm.getAppHost().getTempDirPath() + targetName;
    } else if (faId instanceof RWAccessId) {
        // Read write mode
        RWAccessId rwaId = (RWAccessId) faId;
        targetName = rwaId.getWrittenDataInstance().getRenaming();
        targetPath = Comm.getAppHost().getTempDirPath() + targetName;
    } else {
        // Read only mode
        RAccessId raId = (RAccessId) faId;
        targetName = raId.getReadDataInstance().getRenaming();
        targetPath = Comm.getAppHost().getTempDirPath() + targetName;
    }
    LOGGER.debug("Openning file " + targetName + " at " + targetPath);
    // Create location
    DataLocation targetLocation = null;
    String pscoId = Comm.getData(targetName).getId();
    if (pscoId == null) {
        try {
            SimpleURI targetURI = new SimpleURI(DataLocation.Protocol.FILE_URI.getSchema() + targetPath);
            targetLocation = DataLocation.createLocation(Comm.getAppHost(), targetURI);
        } catch (IOException ioe) {
            ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, ioe);
        }
    } else {
        // It is an external object persisted inside the task
        try {
            SimpleURI targetURI = new SimpleURI(DataLocation.Protocol.PERSISTENT_URI.getSchema() + pscoId);
            targetLocation = DataLocation.createLocation(Comm.getAppHost(), targetURI);
        } catch (IOException ioe) {
            ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, ioe);
        }
    }
    // Register target location
    LOGGER.debug("Setting target location to " + targetLocation);
    setLocation(targetLocation);
    // Ask for transfer when required
    if (pscoId != null) {
        LOGGER.debug("External object detected. Auto-release");
        Comm.registerLocation(targetName, targetLocation);
        sem.release();
    } else if (faId instanceof WAccessId) {
        LOGGER.debug("Write only mode. Auto-release");
        Comm.registerLocation(targetName, targetLocation);
        sem.release();
    } else if (faId instanceof RWAccessId) {
        LOGGER.debug("RW mode. Asking for transfer");
        RWAccessId rwaId = (RWAccessId) faId;
        String srcName = rwaId.getReadDataInstance().getRenaming();
        Comm.getAppHost().getData(srcName, targetName, (LogicalData) null, new FileTransferable(), new OneOpWithSemListener(sem));
    } else {
        LOGGER.debug("Read only mode. Asking for transfer");
        RAccessId raId = (RAccessId) faId;
        String srcName = raId.getReadDataInstance().getRenaming();
        Comm.getAppHost().getData(srcName, srcName, new FileTransferable(), new OneOpWithSemListener(sem));
    }
}
Also used : FileTransferable(es.bsc.compss.types.data.operation.FileTransferable) DataInstanceId(es.bsc.compss.types.data.DataInstanceId) RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) WAccessId(es.bsc.compss.types.data.DataAccessId.WAccessId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) IOException(java.io.IOException) OneOpWithSemListener(es.bsc.compss.types.data.operation.OneOpWithSemListener)

Example 3 with WAccessId

use of es.bsc.compss.types.data.DataAccessId.WAccessId in project compss by bsc-wdc.

the class AccessProcessor method mainAccessToFile.

/**
 * Notifies a main access to a given file @sourceLocation in mode @fap
 *
 * @param sourceLocation
 * @param fap
 * @param destDir
 * @return
 */
public DataLocation mainAccessToFile(DataLocation sourceLocation, AccessParams.FileAccessParams fap, String destDir) {
    boolean alreadyAccessed = alreadyAccessed(sourceLocation);
    if (!alreadyAccessed) {
        LOGGER.debug("File not accessed before, returning the same location");
        return sourceLocation;
    }
    // Tell the DM that the application wants to access a file.
    DataAccessId faId = registerDataAccess(fap);
    DataLocation tgtLocation = sourceLocation;
    if (fap.getMode() != AccessMode.W) {
        // Wait until the last writer task for the file has finished
        LOGGER.debug("File " + faId.getDataId() + " mode contains R, waiting until the last writer has finished");
        waitForTask(faId.getDataId(), AccessMode.R);
        if (destDir == null) {
            tgtLocation = transferFileOpen(faId);
        } else {
            DataInstanceId daId;
            if (fap.getMode() == AccessMode.R) {
                RAccessId ra = (RAccessId) faId;
                daId = ra.getReadDataInstance();
            } else {
                RWAccessId ra = (RWAccessId) faId;
                daId = ra.getReadDataInstance();
            }
            String rename = daId.getRenaming();
            String path = DataLocation.Protocol.FILE_URI.getSchema() + destDir + rename;
            try {
                SimpleURI uri = new SimpleURI(path);
                tgtLocation = DataLocation.createLocation(Comm.getAppHost(), uri);
            } catch (Exception e) {
                ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
            }
            transferFileRaw(faId, tgtLocation);
        }
    }
    if (fap.getMode() != AccessMode.R) {
        // Mode contains W
        LOGGER.debug("File " + faId.getDataId() + " mode contains W, register new writer");
        DataInstanceId daId;
        if (fap.getMode() == AccessMode.RW) {
            RWAccessId ra = (RWAccessId) faId;
            daId = ra.getWrittenDataInstance();
        } else {
            WAccessId ra = (WAccessId) faId;
            daId = ra.getWrittenDataInstance();
        }
        String rename = daId.getRenaming();
        String path = DataLocation.Protocol.FILE_URI.getSchema() + Comm.getAppHost().getTempDirPath() + rename;
        try {
            SimpleURI uri = new SimpleURI(path);
            tgtLocation = DataLocation.createLocation(Comm.getAppHost(), uri);
        } catch (Exception e) {
            ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
        }
        Comm.registerLocation(rename, tgtLocation);
    }
    if (DEBUG) {
        LOGGER.debug("File " + faId.getDataId() + " located on " + tgtLocation.toString());
    }
    return tgtLocation;
}
Also used : DataInstanceId(es.bsc.compss.types.data.DataInstanceId) RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) WAccessId(es.bsc.compss.types.data.DataAccessId.WAccessId) DataAccessId(es.bsc.compss.types.data.DataAccessId) ShutdownException(es.bsc.compss.types.request.exceptions.ShutdownException) CannotLoadException(es.bsc.compss.exceptions.CannotLoadException)

Aggregations

RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)3 RWAccessId (es.bsc.compss.types.data.DataAccessId.RWAccessId)3 WAccessId (es.bsc.compss.types.data.DataAccessId.WAccessId)3 DataAccessId (es.bsc.compss.types.data.DataAccessId)2 DataInstanceId (es.bsc.compss.types.data.DataInstanceId)2 DataLocation (es.bsc.compss.types.data.location.DataLocation)2 SimpleURI (es.bsc.compss.types.uri.SimpleURI)2 CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)1 NIOParam (es.bsc.compss.nio.NIOParam)1 Data (es.bsc.compss.nio.commands.Data)1 DataType (es.bsc.compss.types.annotations.parameter.DataType)1 FileTransferable (es.bsc.compss.types.data.operation.FileTransferable)1 OneOpWithSemListener (es.bsc.compss.types.data.operation.OneOpWithSemListener)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 ShutdownException (es.bsc.compss.types.request.exceptions.ShutdownException)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1