Search in sources :

Example 6 with Resource

use of es.bsc.compss.types.resources.Resource 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 Resource

use of es.bsc.compss.types.resources.Resource 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 Resource

use of es.bsc.compss.types.resources.Resource in project compss by bsc-wdc.

the class Score method calculateDataLocalityScore.

/**
 * Calculates the number of Parameters in @params located in a given worker
 *
 * @w.
 *
 * @param params
 * @param w
 * @return
 */
public static long calculateDataLocalityScore(TaskDescription params, Worker<?> w) {
    long resourceScore = 0;
    if (params != null) {
        Parameter[] parameters = params.getParameters();
        // are located in the host
        for (Parameter p : parameters) {
            if (p instanceof DependencyParameter && p.getDirection() != Direction.OUT) {
                DependencyParameter dp = (DependencyParameter) p;
                DataInstanceId dId = null;
                switch(dp.getDirection()) {
                    case IN:
                        DataAccessId.RAccessId raId = (DataAccessId.RAccessId) dp.getDataAccessId();
                        dId = raId.getReadDataInstance();
                        break;
                    case INOUT:
                        DataAccessId.RWAccessId rwaId = (DataAccessId.RWAccessId) dp.getDataAccessId();
                        dId = rwaId.getReadDataInstance();
                        break;
                    case OUT:
                        // Cannot happen because of previous if
                        break;
                }
                // Get hosts for resource score
                if (dId != null) {
                    LogicalData dataLD = Comm.getData(dId.getRenaming());
                    if (dataLD != null) {
                        Set<Resource> hosts = dataLD.getAllHosts();
                        for (Resource host : hosts) {
                            if (host == w) {
                                resourceScore++;
                            }
                        }
                    }
                }
            }
        }
    }
    return resourceScore;
}
Also used : Resource(es.bsc.compss.types.resources.Resource) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) DataInstanceId(es.bsc.compss.types.data.DataInstanceId) LogicalData(es.bsc.compss.types.data.LogicalData) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) Parameter(es.bsc.compss.types.parameter.Parameter) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 9 with Resource

use of es.bsc.compss.types.resources.Resource in project compss by bsc-wdc.

the class LogicalData method writeToStorage.

/**
 * Writes memory value to file
 *
 * @throws Exception
 */
public synchronized void writeToStorage() throws IOException {
    if (this.id != null) {
    // It is a persistent object that is already persisted
    // Nothing to do
    // If the PSCO is not persisted we treat it as a normal object
    } else {
        // The object must be written to file
        String targetPath = Comm.getAppHost().getWorkingDirectory() + this.name;
        Serializer.serialize(value, targetPath);
        String targetPathWithSchema = Protocol.FILE_URI.getSchema() + targetPath;
        SimpleURI targetURI = new SimpleURI(targetPathWithSchema);
        DataLocation loc = DataLocation.createLocation(Comm.getAppHost(), targetURI);
        this.isBeingSaved = false;
        this.locations.add(loc);
        for (Resource r : loc.getHosts()) {
            switch(loc.getType()) {
                case PRIVATE:
                    r.addLogicalData(this);
                    break;
                case SHARED:
                    SharedDiskManager.addLogicalData(loc.getSharedDisk(), this);
                    break;
                case PERSISTENT:
                    // Nothing to do
                    break;
            }
        }
    }
}
Also used : SimpleURI(es.bsc.compss.types.uri.SimpleURI) Resource(es.bsc.compss.types.resources.Resource) DataLocation(es.bsc.compss.types.data.location.DataLocation)

Example 10 with Resource

use of es.bsc.compss.types.resources.Resource in project compss by bsc-wdc.

the class LogicalData method addLocation.

/*
     * Setters
     */
/**
 * Adds a new location
 *
 * @param loc
 */
public synchronized void addLocation(DataLocation loc) {
    this.isBeingSaved = false;
    this.locations.add(loc);
    for (Resource r : loc.getHosts()) {
        switch(loc.getType()) {
            case PRIVATE:
                r.addLogicalData(this);
                break;
            case SHARED:
                SharedDiskManager.addLogicalData(loc.getSharedDisk(), this);
                break;
            case PERSISTENT:
                this.id = ((PersistentLocation) loc).getId();
                break;
        }
    }
}
Also used : Resource(es.bsc.compss.types.resources.Resource)

Aggregations

Resource (es.bsc.compss.types.resources.Resource)12 LinkedList (java.util.LinkedList)6 MultiURI (es.bsc.compss.types.uri.MultiURI)5 LogicalData (es.bsc.compss.types.data.LogicalData)3 DataLocation (es.bsc.compss.types.data.location.DataLocation)3 SimpleURI (es.bsc.compss.types.uri.SimpleURI)2 File (java.io.File)2 StorageException (storage.StorageException)2 CopyException (es.bsc.compss.exceptions.CopyException)1 Data (es.bsc.compss.nio.commands.Data)1 CloudProvider (es.bsc.compss.types.CloudProvider)1 DataAccessId (es.bsc.compss.types.data.DataAccessId)1 DataInstanceId (es.bsc.compss.types.data.DataInstanceId)1 Copy (es.bsc.compss.types.data.operation.copy.Copy)1 DependencyParameter (es.bsc.compss.types.parameter.DependencyParameter)1 Parameter (es.bsc.compss.types.parameter.Parameter)1 CloudMethodWorker (es.bsc.compss.types.resources.CloudMethodWorker)1 CloudInstanceTypeDescription (es.bsc.compss.types.resources.description.CloudInstanceTypeDescription)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1