Search in sources :

Example 6 with MultiURI

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

the class ImmediateCopy method perform.

public void perform() {
    Resource targetHost = ((LinkedList<Resource>) tgtLoc.getHosts()).getFirst();
    LOGGER.debug("THREAD " + Thread.currentThread().getName() + " - Copy file " + getName() + " to " + tgtLoc);
    synchronized (srcData) {
        if (tgtData != null) {
            MultiURI u;
            if ((u = srcData.alreadyAvailable(targetHost)) != null) {
                setFinalTarget(u.getPath());
                end(DataOperation.OpEndState.OP_OK);
                LOGGER.debug("THREAD " + Thread.currentThread().getName() + " - A copy of " + getName() + " is already present at " + targetHost + " on path " + u.getPath());
                return;
            }
            Copy copyInProgress = null;
            if ((copyInProgress = srcData.alreadyCopying(tgtLoc)) != null) {
                String path = copyInProgress.tgtLoc.getURIInHost(targetHost).getPath();
                setFinalTarget(path);
                // The same operation is already in progress - no need to repeat it
                end(DataOperation.OpEndState.OP_IN_PROGRESS);
                // This group must be notified as well when the operation finishes
                synchronized (copyInProgress.getEventListeners()) {
                    copyInProgress.addEventListeners(getEventListeners());
                }
                LOGGER.debug("THREAD " + Thread.currentThread().getName() + " - A copy to " + path + " is already in progress, skipping replication");
                return;
            }
        }
        srcData.startCopy(this, tgtLoc);
    }
    try {
        LOGGER.debug("[InmediateCopy] Performing Inmediate specific Copy for " + getName());
        specificCopy();
    } catch (CopyException e) {
        end(DataOperation.OpEndState.OP_FAILED, e);
        return;
    } finally {
        DataLocation actualLocation;
        synchronized (srcData) {
            actualLocation = srcData.finishedCopy(this);
        }
        if (tgtData != null) {
            synchronized (tgtData) {
                tgtData.addLocation(actualLocation);
            }
        }
    }
    String path = tgtLoc.getURIInHost(targetHost).getPath();
    setFinalTarget(path);
    synchronized (srcData) {
        end(DataOperation.OpEndState.OP_OK);
    }
    LOGGER.debug("[InmediateCopy] Inmediate Copy for " + getName() + " performed.");
}
Also used : MultiURI(es.bsc.compss.types.uri.MultiURI) CopyException(es.bsc.compss.exceptions.CopyException) Resource(es.bsc.compss.types.resources.Resource) DataLocation(es.bsc.compss.types.data.location.DataLocation) LinkedList(java.util.LinkedList)

Example 7 with MultiURI

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

the class NIOWorkerNode method orderCopy.

private void orderCopy(DeferredCopy c) {
    LOGGER.info("Order Copy for " + c.getSourceData());
    Resource tgtRes = ((LinkedList<Resource>) c.getTargetLoc().getHosts()).getFirst();
    LogicalData ld = c.getSourceData();
    String path;
    synchronized (ld) {
        if (c.getTargetData() != null) {
            MultiURI u = ld.alreadyAvailable(tgtRes);
            if (u != null) {
                path = u.getPath();
            } else {
                path = c.getTargetLoc().getURIInHost(tgtRes).getPath();
            }
        } else {
            path = c.getTargetLoc().getURIInHost(tgtRes).getPath();
        }
        c.setProposedSource(new Data(ld));
        LOGGER.debug("Setting final target in deferred copy " + path);
        c.setFinalTarget(path);
        // TODO: MISSING CHECK IF FILE IS ALREADY BEEN COPIED IN A SHARED LOCATION
        ld.startCopy(c, c.getTargetLoc());
        commManager.registerCopy(c);
    }
    c.end(DataOperation.OpEndState.OP_OK);
}
Also used : LogicalData(es.bsc.compss.types.data.LogicalData) MultiURI(es.bsc.compss.types.uri.MultiURI) Resource(es.bsc.compss.types.resources.Resource) LogicalData(es.bsc.compss.types.data.LogicalData) Data(es.bsc.compss.nio.commands.Data) LinkedList(java.util.LinkedList)

Example 8 with MultiURI

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

the class NIOAdaptor method getObject.

@Override
public Object getObject(String name) throws SerializedObjectException {
    LogicalData ld = Comm.getData(name);
    Object o = ld.getValue();
    // Check if the object has been serialized meanwhile
    if (o == null) {
        for (MultiURI loc : ld.getURIs()) {
            if (!loc.getProtocol().equals(Protocol.OBJECT_URI) && loc.getHost().equals(Comm.getAppHost())) {
                // The object is null because it has been serialized by the master, raise exception
                throw new SerializedObjectException(name);
            }
        }
    }
    // 2- The object is really null (no exception thrown)
    return o;
}
Also used : LogicalData(es.bsc.compss.types.data.LogicalData) MultiURI(es.bsc.compss.types.uri.MultiURI) SerializedObjectException(es.bsc.compss.nio.exceptions.SerializedObjectException)

Example 9 with MultiURI

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

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

the class Comm method dataDump.

/**
 * Dumps the stored data (only for testing)
 *
 * @return
 */
public static synchronized String dataDump() {
    StringBuilder sb = new StringBuilder("DATA DUMP\n");
    for (Entry<String, LogicalData> lde : data.entrySet()) {
        sb.append("\t *").append(lde.getKey()).append(":\n");
        LogicalData ld = lde.getValue();
        for (MultiURI u : ld.getURIs()) {
            sb.append("\t\t + ").append(u.toString()).append("\n");
            for (String adaptor : adaptors.keySet()) {
                Object internal = null;
                try {
                    internal = u.getInternalURI(adaptor);
                    if (internal != null) {
                        sb.append("\t\t\t - ").append(internal.toString()).append("\n");
                    }
                } catch (UnstartedNodeException une) {
                // Node was not started. Cannot print internal object.
                }
            }
        }
    }
    return sb.toString();
}
Also used : LogicalData(es.bsc.compss.types.data.LogicalData) MultiURI(es.bsc.compss.types.uri.MultiURI) UnstartedNodeException(es.bsc.compss.exceptions.UnstartedNodeException)

Aggregations

MultiURI (es.bsc.compss.types.uri.MultiURI)12 LogicalData (es.bsc.compss.types.data.LogicalData)5 DataLocation (es.bsc.compss.types.data.location.DataLocation)5 Resource (es.bsc.compss.types.resources.Resource)5 LinkedList (java.util.LinkedList)5 UnstartedNodeException (es.bsc.compss.exceptions.UnstartedNodeException)3 CopyException (es.bsc.compss.exceptions.CopyException)2 Data (es.bsc.compss.nio.commands.Data)2 Copy (es.bsc.compss.types.data.operation.copy.Copy)2 File (java.io.File)2 IOException (java.io.IOException)2 StorageException (storage.StorageException)2 CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)1 GATCopyException (es.bsc.compss.gat.master.exceptions.GATCopyException)1 NIOURI (es.bsc.compss.nio.NIOURI)1 DataRequest (es.bsc.compss.nio.dataRequest.DataRequest)1 MasterDataRequest (es.bsc.compss.nio.dataRequest.MasterDataRequest)1 SerializedObjectException (es.bsc.compss.nio.exceptions.SerializedObjectException)1 FileAccessParams (es.bsc.compss.types.data.AccessParams.FileAccessParams)1 PersistentLocation (es.bsc.compss.types.data.location.PersistentLocation)1