Search in sources :

Example 1 with OneOpWithSemListener

use of es.bsc.compss.types.data.operation.OneOpWithSemListener 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 2 with OneOpWithSemListener

use of es.bsc.compss.types.data.operation.OneOpWithSemListener in project compss by bsc-wdc.

the class TransferRawFileRequest method process.

@Override
public void process(AccessProcessor ap, TaskAnalyser ta, DataInfoProvider dip, TaskDispatcher td) {
    // Make a copy of the original logical file, we don't want to leave track
    String sourceName = faId.getReadDataInstance().getRenaming();
    Comm.getAppHost().getData(sourceName, location, (LogicalData) null, new FileTransferable(), new OneOpWithSemListener(sem));
}
Also used : FileTransferable(es.bsc.compss.types.data.operation.FileTransferable) OneOpWithSemListener(es.bsc.compss.types.data.operation.OneOpWithSemListener)

Example 3 with OneOpWithSemListener

use of es.bsc.compss.types.data.operation.OneOpWithSemListener in project compss by bsc-wdc.

the class DataInfoProvider method transferObjectValue.

/**
 * Transfers the value of an object
 *
 * @param toRequest
 * @return
 */
public LogicalData transferObjectValue(TransferObjectRequest toRequest) {
    Semaphore sem = toRequest.getSemaphore();
    DataAccessId daId = toRequest.getDaId();
    RWAccessId rwaId = (RWAccessId) daId;
    String sourceName = rwaId.getReadDataInstance().getRenaming();
    // String targetName = rwaId.getWrittenDataInstance().getRenaming();
    if (DEBUG) {
        LOGGER.debug("Requesting getting object " + sourceName);
    }
    LogicalData ld = Comm.getData(sourceName);
    if (ld == null) {
        ErrorManager.error("Unregistered data " + sourceName);
        return null;
    }
    if (ld.isInMemory()) {
        // Write to storage (if needed)
        try {
            ld.writeToStorage();
        } catch (IOException e) {
            ErrorManager.error("Exception writing object to file.", e);
        }
        // Clear value
        ld.removeValue();
        // Set response
        toRequest.setResponse(ld.getValue());
        toRequest.setTargetData(ld);
        toRequest.getSemaphore().release();
    } else {
        if (DEBUG) {
            LOGGER.debug("Object " + sourceName + " not in memory. Requesting tranfers to " + Comm.getAppHost().getName());
        }
        DataLocation targetLocation = null;
        String path = DataLocation.Protocol.FILE_URI.getSchema() + Comm.getAppHost().getTempDirPath() + sourceName;
        try {
            SimpleURI uri = new SimpleURI(path);
            targetLocation = DataLocation.createLocation(Comm.getAppHost(), uri);
        } catch (Exception e) {
            ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
        }
        Comm.getAppHost().getData(sourceName, targetLocation, new ObjectTransferable(), new OneOpWithSemListener(sem));
    }
    return ld;
}
Also used : ObjectTransferable(es.bsc.compss.types.data.operation.ObjectTransferable) SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) OneOpWithSemListener(es.bsc.compss.types.data.operation.OneOpWithSemListener) DataAccessId(es.bsc.compss.types.data.DataAccessId) StorageException(storage.StorageException) IOException(java.io.IOException)

Aggregations

OneOpWithSemListener (es.bsc.compss.types.data.operation.OneOpWithSemListener)3 DataLocation (es.bsc.compss.types.data.location.DataLocation)2 FileTransferable (es.bsc.compss.types.data.operation.FileTransferable)2 SimpleURI (es.bsc.compss.types.uri.SimpleURI)2 IOException (java.io.IOException)2 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 DataInstanceId (es.bsc.compss.types.data.DataInstanceId)1 ObjectTransferable (es.bsc.compss.types.data.operation.ObjectTransferable)1 Semaphore (java.util.concurrent.Semaphore)1 StorageException (storage.StorageException)1