Search in sources :

Example 1 with CannotLoadException

use of es.bsc.compss.exceptions.CannotLoadException 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 2 with CannotLoadException

use of es.bsc.compss.exceptions.CannotLoadException in project compss by bsc-wdc.

the class AccessProcessor method obtainObject.

/**
 * Adds a request to obtain an object from a worker to the master
 *
 * @param oaId
 * @return
 */
private Object obtainObject(DataAccessId oaId) {
    LOGGER.debug("Obtain object with id " + oaId);
    // Ask for the object
    Semaphore sem = new Semaphore(0);
    TransferObjectRequest tor = new TransferObjectRequest(oaId, sem);
    if (!requestQueue.offer(tor)) {
        ErrorManager.error(ERROR_QUEUE_OFFER + "obtain object");
    }
    // Wait for response
    sem.acquireUninterruptibly();
    // Get response
    Object oUpdated = tor.getResponse();
    if (oUpdated == null) {
        /*
             * The Object didn't come from a WS but was transferred from a worker, we load it from its storage (file or
             * persistent)
             */
        LogicalData ld = tor.getLogicalDataTarget();
        try {
            ld.loadFromStorage();
            oUpdated = ld.getValue();
        } catch (CannotLoadException e) {
            LOGGER.fatal(ERROR_OBJECT_LOAD_FROM_STORAGE + ": " + ((ld == null) ? "null" : ld.getName()), e);
            ErrorManager.fatal(ERROR_OBJECT_LOAD_FROM_STORAGE + ": " + ((ld == null) ? "null" : ld.getName()), e);
        }
    }
    return oUpdated;
}
Also used : TransferObjectRequest(es.bsc.compss.types.request.ap.TransferObjectRequest) LogicalData(es.bsc.compss.types.data.LogicalData) CannotLoadException(es.bsc.compss.exceptions.CannotLoadException) Semaphore(java.util.concurrent.Semaphore)

Aggregations

CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)2 LogicalData (es.bsc.compss.types.data.LogicalData)1 DataLocation (es.bsc.compss.types.data.location.DataLocation)1 PersistentLocation (es.bsc.compss.types.data.location.PersistentLocation)1 TransferObjectRequest (es.bsc.compss.types.request.ap.TransferObjectRequest)1 MultiURI (es.bsc.compss.types.uri.MultiURI)1 SimpleURI (es.bsc.compss.types.uri.SimpleURI)1 IOException (java.io.IOException)1 Semaphore (java.util.concurrent.Semaphore)1 StorageException (storage.StorageException)1