Search in sources :

Example 6 with DataLocation

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

the class COMPSsRuntimeImpl method getFile.

/*
     * ********************************************************************************************************
     * LoaderAPI INTERFACE IMPLEMENTATION
     * ********************************************************************************************************
     */
/**
 * Returns a copy of the last file version
 */
@Override
public String getFile(String fileName, String destDir) {
    if (Tracer.isActivated()) {
        Tracer.emitEvent(Tracer.Event.GET_FILE.getId(), Tracer.Event.GET_FILE.getType());
    }
    // Parse the destination path
    if (!destDir.endsWith(File.separator)) {
        destDir += File.separator;
    }
    // Parse the file name
    DataLocation sourceLocation;
    try {
        sourceLocation = createLocation(fileName);
    } catch (IOException ioe) {
        ErrorManager.fatal(ERROR_FILE_NAME, ioe);
        return null;
    }
    if (sourceLocation == null) {
        ErrorManager.fatal(ERROR_FILE_NAME);
        return null;
    }
    // Ask the AP to
    String finalPath = mainAccessToFile(fileName, sourceLocation, AccessMode.R, destDir);
    if (Tracer.isActivated()) {
        Tracer.emitEvent(Tracer.EVENT_END, Tracer.getRuntimeEventsType());
    }
    return finalPath;
}
Also used : DataLocation(es.bsc.compss.types.data.location.DataLocation) IOException(java.io.IOException)

Example 7 with DataLocation

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

the class COMPSsRuntimeImpl method processParameters.

/*
     * ************************************************************************************************************
     * PRIVATE HELPER METHODS
     * ********************************************************************************************************
     */
private Parameter[] processParameters(int parameterCount, Object[] parameters) {
    Parameter[] pars = new Parameter[parameterCount];
    // Parameter parsing needed, object is not serializable
    int i = 0;
    for (int npar = 0; npar < parameterCount; ++npar) {
        DataType type = (DataType) parameters[i + 1];
        Direction direction = (Direction) parameters[i + 2];
        Stream stream = (Stream) parameters[i + 3];
        String prefix = (String) parameters[i + 4];
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("  Parameter " + (npar + 1) + " has type " + type.name());
        }
        switch(type) {
            case FILE_T:
                try {
                    String fileName = (String) parameters[i];
                    String originalName = new File(fileName).getName();
                    DataLocation location = createLocation((String) parameters[i]);
                    pars[npar] = new FileParameter(direction, stream, prefix, location, originalName);
                } catch (Exception e) {
                    LOGGER.error(ERROR_FILE_NAME, e);
                    ErrorManager.fatal(ERROR_FILE_NAME, e);
                }
                break;
            case PSCO_T:
            case OBJECT_T:
                pars[npar] = new ObjectParameter(direction, stream, prefix, parameters[i], oReg.newObjectParameter(parameters[i]));
                break;
            case EXTERNAL_OBJECT_T:
                String id = (String) parameters[i];
                pars[npar] = new ExternalObjectParameter(direction, stream, prefix, id, externalObjectHashcode(id));
                break;
            default:
                /*
                     * Basic types (including String). The only possible direction is IN, warn otherwise
                     */
                if (direction != Direction.IN) {
                    LOGGER.warn(WARN_WRONG_DIRECTION + "Parameter " + npar + " is a basic type, therefore it must have IN direction");
                }
                pars[npar] = new BasicTypeParameter(type, Direction.IN, stream, prefix, parameters[i]);
                break;
        }
        i += 5;
    }
    return pars;
}
Also used : DataLocation(es.bsc.compss.types.data.location.DataLocation) Direction(es.bsc.compss.types.annotations.parameter.Direction) IOException(java.io.IOException) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) Parameter(es.bsc.compss.types.parameter.Parameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType) Stream(es.bsc.compss.types.annotations.parameter.Stream) InputStream(java.io.InputStream) FileParameter(es.bsc.compss.types.parameter.FileParameter) File(java.io.File)

Example 8 with DataLocation

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

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

the class LogicalData method removeHostAndCheckLocationToSave.

/**
 * Removes all the locations assigned to a given host and returns a valid location if the file is unique
 *
 * @param host
 * @param sharedMountPoints
 * @return a valid location if the file is unique
 */
public synchronized DataLocation removeHostAndCheckLocationToSave(Resource host, Map<String, String> sharedMountPoints) {
    // and there is no unique file to save
    if (isBeingSaved) {
        return null;
    }
    // Otherwise, we must remove all the host locations and store a unique
    // location if needed. We only store the "best" location if any (by
    // choosing
    // any private location found or the first shared location)
    lockHostRemoval_private();
    DataLocation uniqueHostLocation = null;
    Iterator<DataLocation> it = this.locations.iterator();
    while (it.hasNext()) {
        DataLocation loc = it.next();
        switch(loc.getType()) {
            case PRIVATE:
                if (loc.getURIInHost(host) != null) {
                    this.isBeingSaved = true;
                    uniqueHostLocation = loc;
                    it.remove();
                }
                break;
            case SHARED:
                // is unique and must be saved
                if (loc.getHosts().isEmpty()) {
                    String sharedDisk = loc.getSharedDisk();
                    if (sharedDisk != null) {
                        String mountPoint = sharedMountPoints.get(sharedDisk);
                        if (mountPoint != null) {
                            if (uniqueHostLocation == null) {
                                this.isBeingSaved = true;
                                String targetPath = Protocol.FILE_URI.getSchema() + loc.getPath();
                                try {
                                    SimpleURI uri = new SimpleURI(targetPath);
                                    uniqueHostLocation = DataLocation.createLocation(host, uri);
                                } catch (Exception e) {
                                    ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, e);
                                }
                            }
                        }
                    }
                }
                break;
            case PERSISTENT:
                // Persistent location must never be saved
                break;
        }
    }
    releaseHostRemoval_private();
    return uniqueHostLocation;
}
Also used : SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) StorageException(storage.StorageException) UnstartedNodeException(es.bsc.compss.exceptions.UnstartedNodeException) IOException(java.io.IOException) CannotLoadException(es.bsc.compss.exceptions.CannotLoadException)

Example 10 with DataLocation

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

the class LogicalData method toString.

@Override
public synchronized String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Logical Data name: ").append(this.name).append("\n");
    sb.append("\t Value: ").append(value).append("\n");
    sb.append("\t Id: ").append(id).append("\n");
    sb.append("\t Locations:\n");
    synchronized (locations) {
        for (DataLocation dl : locations) {
            sb.append("\t\t * ").append(dl).append("\n");
        }
    }
    return sb.toString();
}
Also used : DataLocation(es.bsc.compss.types.data.location.DataLocation)

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