Search in sources :

Example 16 with SimpleURI

use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.

the class LogicalData method loadFromStorage.

/**
 * Loads the value of the LogicalData from a file
 *
 * @throws CannotLoadException
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws StorageException
 * @throws UnstartedNodeException
 *
 * @throws Exception
 */
public synchronized void loadFromStorage() throws CannotLoadException {
    if (value != null) {
        // Value is already loaded in memory
        return;
    }
    for (DataLocation loc : this.locations) {
        switch(loc.getType()) {
            case PRIVATE:
            case SHARED:
                // Get URI and deserialize object if possible
                MultiURI u = loc.getURIInHost(Comm.getAppHost());
                if (u == null) {
                    continue;
                }
                String path = u.getPath();
                if (path.startsWith(File.separator)) {
                    try {
                        this.value = Serializer.deserialize(path);
                    } catch (ClassNotFoundException | IOException e) {
                        // Check next location since deserialization was invalid
                        this.value = null;
                        continue;
                    }
                    String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
                    SimpleURI uri = new SimpleURI(targetPath);
                    try {
                        DataLocation tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
                        addLocation(tgtLoc);
                    } catch (IOException e) {
                        // Check next location since location was invalid
                        this.value = null;
                        continue;
                    }
                }
                return;
            case PERSISTENT:
                PersistentLocation pLoc = (PersistentLocation) loc;
                if (Tracer.isActivated()) {
                    Tracer.emitEvent(Tracer.Event.STORAGE_GETBYID.getId(), Tracer.Event.STORAGE_GETBYID.getType());
                }
                try {
                    this.value = StorageItf.getByID(pLoc.getId());
                    this.id = pLoc.getId();
                } catch (StorageException se) {
                    // Check next location since cannot retrieve the object from the storage Back-end
                    continue;
                } finally {
                    if (Tracer.isActivated()) {
                        Tracer.emitEvent(Tracer.EVENT_END, Tracer.Event.STORAGE_GETBYID.getType());
                    }
                }
                String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
                SimpleURI uri = new SimpleURI(targetPath);
                try {
                    DataLocation tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
                    addLocation(tgtLoc);
                } catch (IOException e) {
                    // Check next location since location was invalid
                    this.value = null;
                    continue;
                }
                return;
        }
    }
    // Any location has been able to load the value
    throw new CannotLoadException("Object has not any valid location available in the master");
}
Also used : MultiURI(es.bsc.compss.types.uri.MultiURI) PersistentLocation(es.bsc.compss.types.data.location.PersistentLocation) CannotLoadException(es.bsc.compss.exceptions.CannotLoadException) SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) IOException(java.io.IOException) StorageException(storage.StorageException)

Example 17 with SimpleURI

use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.

the class LogicalData method removeValue.

/**
 * Removes the object from master main memory and removes its location
 *
 * @return
 */
public synchronized Object removeValue() {
    DataLocation loc = null;
    String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
    try {
        SimpleURI uri = new SimpleURI(targetPath);
        loc = DataLocation.createLocation(Comm.getAppHost(), uri);
    } catch (Exception e) {
        ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, e);
    }
    Object val = this.value;
    this.value = null;
    // Removes only the memory location (no need to check private, shared,
    // persistent)
    this.locations.remove(loc);
    return val;
}
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 18 with SimpleURI

use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.

the class Resource method getWorkersDebugInfo.

private void getWorkersDebugInfo() {
    if (DEBUG) {
        LOGGER.debug("Copying Workers Information");
    }
    COMPSsNode masterNode = Comm.getAppHost().getNode();
    Semaphore sem = new Semaphore(0);
    WorkersDebugInformationListener wdil = new WorkersDebugInformationListener(sem);
    // Get Worker output
    wdil.addOperation();
    String outFileName = "worker_" + getName() + ".out";
    SimpleURI outFileOrigin = node.getCompletePath(DataType.FILE_T, "log" + File.separator + "static_" + outFileName);
    String outFileTarget = Protocol.FILE_URI.getSchema() + Comm.getAppHost().getWorkersDirPath() + File.separator + outFileName;
    DataLocation outSource = null;
    try {
        outSource = DataLocation.createLocation(this, outFileOrigin);
    } catch (Exception e) {
        ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + outFileOrigin.toString(), e);
    }
    DataLocation outTarget = null;
    try {
        SimpleURI uri = new SimpleURI(outFileTarget);
        outTarget = DataLocation.createLocation(Comm.getAppHost(), uri);
    } catch (Exception e) {
        ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + outFileTarget);
    }
    LOGGER.debug("- Source: " + outFileOrigin);
    LOGGER.debug("- Target: " + outFileTarget);
    masterNode.obtainData(new LogicalData("workerOut" + this.getName()), outSource, outTarget, new LogicalData("workerOut" + this.getName()), new WorkersDebugInfoCopyTransferable(), wdil);
    // Get Worker error
    wdil.addOperation();
    String errFileName = "worker_" + getName() + ".err";
    SimpleURI errFileOrigin = node.getCompletePath(DataType.FILE_T, "log" + File.separator + "static_" + errFileName);
    String errFileTarget = Protocol.FILE_URI.getSchema() + Comm.getAppHost().getWorkersDirPath() + File.separator + errFileName;
    DataLocation errSource = null;
    try {
        errSource = DataLocation.createLocation(this, errFileOrigin);
    } catch (Exception e) {
        ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + errFileOrigin.toString(), e);
    }
    DataLocation errTarget = null;
    try {
        SimpleURI uri = new SimpleURI(errFileTarget);
        errTarget = DataLocation.createLocation(Comm.getAppHost(), uri);
    } catch (Exception e) {
        ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + errFileTarget);
    }
    LOGGER.debug("- Source: " + errFileOrigin);
    LOGGER.debug("- Target: " + errFileTarget);
    masterNode.obtainData(new LogicalData("workerErr" + this.getName()), errSource, errTarget, new LogicalData("workerErr" + this.getName()), new WorkersDebugInfoCopyTransferable(), wdil);
    // Wait transfers
    wdil.enable();
    try {
        sem.acquire();
    } catch (InterruptedException ex) {
        LOGGER.error("Error waiting for worker debug files in resource " + getName() + " to get saved");
    }
    LOGGER.debug("Worker files from resource " + getName() + "received");
}
Also used : WorkersDebugInformationListener(es.bsc.compss.types.data.listener.WorkersDebugInformationListener) LogicalData(es.bsc.compss.types.data.LogicalData) SimpleURI(es.bsc.compss.types.uri.SimpleURI) WorkersDebugInfoCopyTransferable(es.bsc.compss.types.data.transferable.WorkersDebugInfoCopyTransferable) DataLocation(es.bsc.compss.types.data.location.DataLocation) Semaphore(java.util.concurrent.Semaphore) COMPSsNode(es.bsc.compss.types.COMPSsNode) InitNodeException(es.bsc.compss.exceptions.InitNodeException) UnstartedNodeException(es.bsc.compss.exceptions.UnstartedNodeException)

Example 19 with SimpleURI

use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.

the class Resource method getData.

/**
 * Retrieves a given data
 *
 * @param ld
 * @param newName
 * @param tgtData
 * @param reason
 * @param listener
 */
public void getData(LogicalData ld, String newName, LogicalData tgtData, Transferable reason, EventListener listener) {
    SimpleURI workingPath = node.getCompletePath(reason.getType(), newName);
    DataLocation target = null;
    try {
        target = DataLocation.createLocation(this, workingPath);
    } catch (Exception e) {
        ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + workingPath.toString(), e);
    }
    getData(ld, target, tgtData, reason, listener);
}
Also used : SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) InitNodeException(es.bsc.compss.exceptions.InitNodeException) UnstartedNodeException(es.bsc.compss.exceptions.UnstartedNodeException)

Example 20 with SimpleURI

use of es.bsc.compss.types.uri.SimpleURI 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

SimpleURI (es.bsc.compss.types.uri.SimpleURI)22 DataLocation (es.bsc.compss.types.data.location.DataLocation)16 IOException (java.io.IOException)9 UnstartedNodeException (es.bsc.compss.exceptions.UnstartedNodeException)6 LogicalData (es.bsc.compss.types.data.LogicalData)6 InitNodeException (es.bsc.compss.exceptions.InitNodeException)5 Semaphore (java.util.concurrent.Semaphore)5 CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)4 COMPSsNode (es.bsc.compss.types.COMPSsNode)4 DataInstanceId (es.bsc.compss.types.data.DataInstanceId)4 File (java.io.File)4 StorageException (storage.StorageException)4 DataAccessId (es.bsc.compss.types.data.DataAccessId)3 RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)3 Test (org.junit.Test)3 RWAccessId (es.bsc.compss.types.data.DataAccessId.RWAccessId)2 WAccessId (es.bsc.compss.types.data.DataAccessId.WAccessId)2 TracingCopyListener (es.bsc.compss.types.data.listener.TracingCopyListener)2 OneOpWithSemListener (es.bsc.compss.types.data.operation.OneOpWithSemListener)2 TracingCopyTransferable (es.bsc.compss.types.data.transferable.TracingCopyTransferable)2