Search in sources :

Example 26 with DataLocation

use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.

the class COMPSsRuntimeImpl method deleteFile.

/**
 * Deletes the specified version of a file
 */
@Override
public boolean deleteFile(String fileName) {
    // Check parameters
    if (fileName == null || fileName.isEmpty()) {
        return false;
    }
    LOGGER.info("Deleting File " + fileName);
    // Emit event
    if (Tracer.isActivated()) {
        Tracer.emitEvent(Tracer.Event.DELETE.getId(), Tracer.Event.DELETE.getType());
    }
    // Parse the file name and translate the access mode
    try {
        DataLocation loc = createLocation(fileName);
        ap.markForDeletion(loc);
    } catch (IOException ioe) {
        ErrorManager.fatal(ERROR_FILE_NAME, ioe);
    } finally {
        if (Tracer.isActivated()) {
            Tracer.emitEvent(Tracer.EVENT_END, Tracer.getRuntimeEventsType());
        }
    }
    // Return deletion was successful
    return true;
}
Also used : DataLocation(es.bsc.compss.types.data.location.DataLocation) IOException(java.io.IOException)

Example 27 with DataLocation

use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.

the class COMPSsRuntimeImpl method mainAccessToFile.

private String mainAccessToFile(String fileName, DataLocation loc, AccessMode am, String destDir) {
    // Tell the AP that the application wants to access a file.
    FileAccessParams fap = new FileAccessParams(am, loc);
    DataLocation targetLocation = ap.mainAccessToFile(loc, fap, destDir);
    // Checks on target
    String path = (targetLocation == null) ? fileName : targetLocation.getPath();
    DataLocation finalLocation = (targetLocation == null) ? loc : targetLocation;
    if (finalLocation == null) {
        ErrorManager.fatal(ERROR_FILE_NAME);
        return null;
    }
    // Return the final target path
    String finalPath;
    MultiURI u = finalLocation.getURIInHost(Comm.getAppHost());
    if (u != null) {
        finalPath = u.getPath();
    } else {
        finalPath = path;
    }
    return finalPath;
}
Also used : MultiURI(es.bsc.compss.types.uri.MultiURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) FileAccessParams(es.bsc.compss.types.data.AccessParams.FileAccessParams)

Example 28 with DataLocation

use of es.bsc.compss.types.data.location.DataLocation 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)

Example 29 with DataLocation

use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.

the class DataInfoProvider method blockDataAndGetResultFile.

/**
 * Blocks dataId and retrieves its result file
 *
 * @param dataId
 * @param listener
 * @return
 */
public ResultFile blockDataAndGetResultFile(int dataId, ResultListener listener) {
    DataInstanceId lastVersion;
    FileInfo fileInfo = (FileInfo) idToData.get(dataId);
    if (fileInfo != null && !fileInfo.isCurrentVersionToDelete()) {
        // If current version is to delete do not
        // transfer
        String[] splitPath = fileInfo.getOriginalLocation().getPath().split(File.separator);
        String origName = splitPath[splitPath.length - 1];
        if (origName.startsWith("compss-serialized-obj_")) {
            // Do not transfer objects serialized by the bindings
            if (DEBUG) {
                LOGGER.debug("Discarding file " + origName + " as a result");
            }
            return null;
        }
        fileInfo.blockDeletions();
        lastVersion = fileInfo.getCurrentDataVersion().getDataInstanceId();
        ResultFile rf = new ResultFile(lastVersion, fileInfo.getOriginalLocation());
        DataInstanceId fId = rf.getFileInstanceId();
        String renaming = fId.getRenaming();
        // Look for the last available version
        while (renaming != null && !Comm.existsData(renaming)) {
            renaming = DataInstanceId.previousVersionRenaming(renaming);
        }
        if (renaming == null) {
            LOGGER.error(RES_FILE_TRANSFER_ERR + ": Cannot transfer file " + fId.getRenaming() + " nor any of its previous versions");
            return null;
        }
        // Check if data is a PSCO and must be consolidated
        for (DataLocation loc : Comm.getData(renaming).getLocations()) {
            if (loc instanceof PersistentLocation) {
                String pscoId = ((PersistentLocation) loc).getId();
                if (Tracer.isActivated()) {
                    Tracer.emitEvent(Tracer.Event.STORAGE_CONSOLIDATE.getId(), Tracer.Event.STORAGE_CONSOLIDATE.getType());
                }
                try {
                    StorageItf.consolidateVersion(pscoId);
                } catch (StorageException e) {
                    LOGGER.error("Cannot consolidate PSCO " + pscoId, e);
                } finally {
                    if (Tracer.isActivated()) {
                        Tracer.emitEvent(Tracer.EVENT_END, Tracer.Event.STORAGE_CONSOLIDATE.getType());
                    }
                }
                LOGGER.debug("Returned because persistent object");
                return rf;
            }
        }
        // If no PSCO location is found, perform normal getData
        listener.addOperation();
        Comm.getAppHost().getData(renaming, rf.getOriginalLocation(), new FileTransferable(), listener);
        return rf;
    } else if (fileInfo != null && fileInfo.isCurrentVersionToDelete()) {
        if (DEBUG) {
            String[] splitPath = fileInfo.getOriginalLocation().getPath().split(File.separator);
            String origName = splitPath[splitPath.length - 1];
            LOGGER.debug("Trying to delete file " + origName);
        }
        if (fileInfo.delete()) {
        // idToData.remove(dataId);
        }
    }
    return null;
}
Also used : FileTransferable(es.bsc.compss.types.data.operation.FileTransferable) PersistentLocation(es.bsc.compss.types.data.location.PersistentLocation) DataLocation(es.bsc.compss.types.data.location.DataLocation) StorageException(storage.StorageException)

Example 30 with DataLocation

use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.

the class ExecutionAction method doOutputTransfers.

private final void doOutputTransfers(Job<?> job) {
    // Job finished, update info about the generated/updated data
    Worker<? extends WorkerResourceDescription> w = this.getAssignedResource().getResource();
    for (Parameter p : job.getTaskParams().getParameters()) {
        if (p instanceof DependencyParameter) {
            // OUT or INOUT: we must tell the FTM about the
            // generated/updated datum
            DataInstanceId dId = null;
            DependencyParameter dp = (DependencyParameter) p;
            switch(p.getDirection()) {
                case IN:
                    // FTM already knows about this datum
                    continue;
                case OUT:
                    dId = ((DataAccessId.WAccessId) dp.getDataAccessId()).getWrittenDataInstance();
                    break;
                case INOUT:
                    dId = ((DataAccessId.RWAccessId) dp.getDataAccessId()).getWrittenDataInstance();
                    if (job.getType() == TaskType.SERVICE) {
                        continue;
                    }
                    break;
            }
            String name = dId.getRenaming();
            if (job.getType() == TaskType.METHOD) {
                String targetProtocol = null;
                switch(dp.getType()) {
                    case FILE_T:
                        targetProtocol = DataLocation.Protocol.FILE_URI.getSchema();
                        break;
                    case OBJECT_T:
                        targetProtocol = DataLocation.Protocol.OBJECT_URI.getSchema();
                        break;
                    case PSCO_T:
                        targetProtocol = DataLocation.Protocol.PERSISTENT_URI.getSchema();
                        break;
                    case EXTERNAL_OBJECT_T:
                        // Its value is the PSCO Id
                        targetProtocol = DataLocation.Protocol.PERSISTENT_URI.getSchema();
                        break;
                    default:
                        // Should never reach this point because only
                        // DependencyParameter types are treated
                        // Ask for any_uri just in case
                        targetProtocol = DataLocation.Protocol.ANY_URI.getSchema();
                        break;
                }
                DataLocation outLoc = null;
                try {
                    SimpleURI targetURI = new SimpleURI(targetProtocol + dp.getDataTarget());
                    outLoc = DataLocation.createLocation(w, targetURI);
                } catch (Exception e) {
                    ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + dp.getDataTarget(), e);
                }
                Comm.registerLocation(name, outLoc);
            } else {
                // Service
                Object value = job.getReturnValue();
                Comm.registerValue(name, value);
            }
        }
    }
}
Also used : DataInstanceId(es.bsc.compss.types.data.DataInstanceId) SimpleURI(es.bsc.compss.types.uri.SimpleURI) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) DataLocation(es.bsc.compss.types.data.location.DataLocation) DataAccessId(es.bsc.compss.types.data.DataAccessId) BlockedActionException(es.bsc.compss.scheduler.exceptions.BlockedActionException) UnassignedActionException(es.bsc.compss.scheduler.exceptions.UnassignedActionException) FailedActionException(es.bsc.compss.scheduler.exceptions.FailedActionException)

Aggregations

DataLocation (es.bsc.compss.types.data.location.DataLocation)30 SimpleURI (es.bsc.compss.types.uri.SimpleURI)16 IOException (java.io.IOException)14 LogicalData (es.bsc.compss.types.data.LogicalData)9 UnstartedNodeException (es.bsc.compss.exceptions.UnstartedNodeException)6 InitNodeException (es.bsc.compss.exceptions.InitNodeException)5 MultiURI (es.bsc.compss.types.uri.MultiURI)5 Semaphore (java.util.concurrent.Semaphore)5 StorageException (storage.StorageException)5 CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)4 COMPSsNode (es.bsc.compss.types.COMPSsNode)4 File (java.io.File)4 DataAccessId (es.bsc.compss.types.data.DataAccessId)3 DataInstanceId (es.bsc.compss.types.data.DataInstanceId)3 Copy (es.bsc.compss.types.data.operation.copy.Copy)3 Resource (es.bsc.compss.types.resources.Resource)3 AccessMode (es.bsc.compss.types.data.AccessParams.AccessMode)2 RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)2 RWAccessId (es.bsc.compss.types.data.DataAccessId.RWAccessId)2 WAccessId (es.bsc.compss.types.data.DataAccessId.WAccessId)2