Search in sources :

Example 1 with NIOURI

use of es.bsc.compss.nio.NIOURI in project compss by bsc-wdc.

the class NIOWorkerNode method sendData.

@Override
public void sendData(LogicalData ld, DataLocation source, DataLocation target, LogicalData tgtData, Transferable reason, EventListener listener) {
    if (target.getHosts().contains(Comm.getAppHost())) {
        // Order petition directly
        if (tgtData != null) {
            MultiURI u = ld.alreadyAvailable(Comm.getAppHost());
            if (u != null) {
                // Already present at the master
                reason.setDataTarget(u.getPath());
                listener.notifyEnd(null);
                return;
            }
        }
        Copy c = new DeferredCopy(ld, null, target, tgtData, reason, listener);
        Data d = new Data(ld);
        if (source != null) {
            for (MultiURI uri : source.getURIs()) {
                try {
                    NIOURI nURI = (NIOURI) uri.getInternalURI(NIOAdaptor.ID);
                    if (nURI != null) {
                        d.getSources().add(nURI);
                    }
                } catch (UnstartedNodeException une) {
                // Ignore internal URI
                }
            }
        }
        String path = target.getURIInHost(Comm.getAppHost()).getPath();
        c.setFinalTarget(path);
        ld.startCopy(c, c.getTargetLoc());
        DataRequest dr = new MasterDataRequest(c, reason.getType(), d, path);
        commManager.addTransferRequest(dr);
        commManager.requestTransfers();
    } else {
        // Request to any other
        orderCopy(new DeferredCopy(ld, source, target, tgtData, reason, listener));
    }
}
Also used : DeferredCopy(es.bsc.compss.types.data.operation.copy.DeferredCopy) MultiURI(es.bsc.compss.types.uri.MultiURI) DeferredCopy(es.bsc.compss.types.data.operation.copy.DeferredCopy) Copy(es.bsc.compss.types.data.operation.copy.Copy) StorageCopy(es.bsc.compss.types.data.operation.copy.StorageCopy) UnstartedNodeException(es.bsc.compss.exceptions.UnstartedNodeException) LogicalData(es.bsc.compss.types.data.LogicalData) Data(es.bsc.compss.nio.commands.Data) MasterDataRequest(es.bsc.compss.nio.dataRequest.MasterDataRequest) DataRequest(es.bsc.compss.nio.dataRequest.DataRequest) MasterDataRequest(es.bsc.compss.nio.dataRequest.MasterDataRequest) NIOURI(es.bsc.compss.nio.NIOURI)

Example 2 with NIOURI

use of es.bsc.compss.nio.NIOURI in project compss by bsc-wdc.

the class NIOWorker method askForObject.

private void askForObject(NIOParam param, int index, TransferringTask tt) {
    WORKER_LOGGER.debug("   - " + (String) param.getValue() + " registered as object.");
    boolean askTransfer = false;
    // Try if parameter is in cache
    WORKER_LOGGER.debug("   - Checking if " + (String) param.getValue() + " is in cache.");
    boolean catched = dataManager.checkPresence((String) param.getValue());
    if (!catched) {
        // Try if any of the object locations is in cache
        boolean locationsInCache = false;
        WORKER_LOGGER.debug("   - Checking if " + (String) param.getValue() + " locations are catched");
        for (NIOURI loc : param.getData().getSources()) {
            if (dataManager.checkPresence(loc.getPath())) {
                // Object found
                WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") location found in cache.");
                try {
                    if (param.isPreserveSourceData()) {
                        WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") preserves sources. CACHE-COPYING");
                        Object o = Serializer.deserialize(loc.getPath());
                        storeObject((String) param.getValue(), o);
                    } else {
                        WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") erases sources. CACHE-MOVING");
                        Object o = dataManager.getObject(loc.getPath());
                        dataManager.remove(loc.getPath());
                        storeObject((String) param.getValue(), o);
                    }
                    locationsInCache = true;
                } catch (IOException ioe) {
                    // If exception is raised, locationsInCache remains false. We log the exception
                    // and try host files
                    WORKER_LOGGER.error("IOException", ioe);
                } catch (ClassNotFoundException e) {
                    // If exception is raised, locationsInCache remains false. We log the exception
                    // and try host files
                    WORKER_LOGGER.error("ClassNotFoundException", e);
                }
                // Stop looking for locations
                break;
            }
        }
        if (!locationsInCache) {
            // Try if any of the object locations is in the host
            boolean existInHost = false;
            WORKER_LOGGER.debug("   - Checking if " + (String) param.getValue() + " locations are in host");
            NIOURI loc = param.getData().getURIinHost(host);
            if (loc != null) {
                WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") found at host.");
                try {
                    File source = new File(workingDir + File.separator + loc.getPath());
                    File target = new File(workingDir + File.separator + param.getValue().toString());
                    if (param.isPreserveSourceData()) {
                        WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") preserves sources. COPYING");
                        WORKER_LOGGER.debug("         Source: " + source);
                        WORKER_LOGGER.debug("         Target: " + target);
                        Files.copy(source.toPath(), target.toPath());
                    } else {
                        WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") erases sources. MOVING");
                        WORKER_LOGGER.debug("         Source: " + source);
                        WORKER_LOGGER.debug("         Target: " + target);
                        if (!source.renameTo(target)) {
                            WORKER_LOGGER.error("Error renaming file from " + source.getAbsolutePath() + " to " + target.getAbsolutePath());
                        }
                    }
                    // Move object to cache
                    Object o = Serializer.deserialize((String) param.getValue());
                    storeObject((String) param.getValue(), o);
                    existInHost = true;
                } catch (IOException ioe) {
                    // If exception is raised, locationsInCache remains false. We log the exception
                    // and try host files
                    WORKER_LOGGER.error("IOException", ioe);
                } catch (ClassNotFoundException e) {
                    // If exception is raised, locationsInCache remains false. We log the exception
                    // and try host files
                    WORKER_LOGGER.error("ClassNotFoundException", e);
                }
            }
            if (!existInHost) {
                // We must transfer the file
                askTransfer = true;
            }
        }
    }
    // Request the transfer if needed
    askForTransfer(askTransfer, param, index, tt);
}
Also used : NIOURI(es.bsc.compss.nio.NIOURI) IOException(java.io.IOException) File(java.io.File)

Example 3 with NIOURI

use of es.bsc.compss.nio.NIOURI in project compss by bsc-wdc.

the class Data method getURIinHost.

// Returns a URI inside the same host or null if the data is not available
public NIOURI getURIinHost(String hostname) {
    for (NIOURI loc : sources) {
        String hostAndPort = loc.getHost().toString();
        String host = hostAndPort.substring(0, hostAndPort.indexOf(":"));
        if (host.equals(hostname)) {
            return loc;
        }
    }
    return null;
}
Also used : NIOURI(es.bsc.compss.nio.NIOURI)

Example 4 with NIOURI

use of es.bsc.compss.nio.NIOURI in project compss by bsc-wdc.

the class NIOWorkerNode method setInternalURI.

@Override
public void setInternalURI(MultiURI uri) throws UnstartedNodeException {
    if (node == null) {
        throw new UnstartedNodeException();
    }
    NIOURI nio = new NIOURI(node, uri.getPath());
    uri.setInternalURI(NIOAdaptor.ID, nio);
}
Also used : UnstartedNodeException(es.bsc.compss.exceptions.UnstartedNodeException) NIOURI(es.bsc.compss.nio.NIOURI)

Example 5 with NIOURI

use of es.bsc.compss.nio.NIOURI in project compss by bsc-wdc.

the class NIOWorker method askForFile.

private void askForFile(NIOParam param, int index, TransferringTask tt) {
    WORKER_LOGGER.debug("   - " + (String) param.getValue() + " registered as file.");
    boolean locationsInHost = false;
    boolean askTransfer = false;
    // Try if parameter is in the host
    WORKER_LOGGER.debug("   - Checking if file " + (String) param.getValue() + " exists.");
    File f = new File(param.getValue().toString());
    if (!f.exists()) {
        // Try if any of the locations is in the same host
        WORKER_LOGGER.debug("   - Checking if " + (String) param.getValue() + " exists in worker");
        NIOURI loc = param.getData().getURIinHost(host);
        if (loc != null) {
            // Data is already present at host
            WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") found at host.");
            try {
                File source = new File(loc.getPath());
                File target = new File(param.getValue().toString());
                if (param.isPreserveSourceData()) {
                    WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") preserves sources. COPYING");
                    WORKER_LOGGER.debug("         Source: " + source);
                    WORKER_LOGGER.debug("         Target: " + target);
                    // if (!source.exists() && (Lang.valueOf(getLang().toUpperCase()) != Lang.C)) {
                    if (!source.exists()) {
                        WORKER_LOGGER.debug("source does not exist, preserve data");
                        WORKER_LOGGER.debug("lang is " + getLang());
                        if (getLang().toUpperCase() != "C") {
                            WORKER_LOGGER.debug("[ERROR] File " + loc.getPath() + " does not exist but it could be an object in cache. Ignoring.");
                        }
                    // TODO The file to be copied needs to be serialized to a file from cache (or serialize from
                    // memory to memory
                    // if possible with a specific function
                    } else {
                        WORKER_LOGGER.debug("before copy");
                        Files.copy(source.toPath(), target.toPath());
                        WORKER_LOGGER.debug("after copy");
                    }
                } else {
                    WORKER_LOGGER.debug("   - Parameter " + index + "(" + (String) param.getValue() + ") erases sources. MOVING");
                    WORKER_LOGGER.debug("         Source: " + source);
                    WORKER_LOGGER.debug("         Target: " + target);
                    if (!source.exists()) {
                        WORKER_LOGGER.debug("source does not exist, no preserve data");
                        WORKER_LOGGER.debug("lang is " + getLang() + ", in uppercase is " + getLang().toUpperCase());
                        if (getLang().toUpperCase() != "C") {
                            WORKER_LOGGER.debug("File " + loc.getPath() + " does not exist but it could be an object in cache. Ignoring.");
                        }
                    } else {
                        try {
                            Files.move(source.toPath(), target.toPath(), StandardCopyOption.ATOMIC_MOVE);
                        } catch (AtomicMoveNotSupportedException amnse) {
                            WORKER_LOGGER.warn("WARN: AtomicMoveNotSupportedException. File cannot be atomically moved. Trying to move without atomic");
                            Files.move(source.toPath(), target.toPath());
                        }
                    }
                }
                locationsInHost = true;
            } catch (IOException ioe) {
                WORKER_LOGGER.error("IOException", ioe);
            }
        }
        if (!locationsInHost) {
            // We must transfer the file
            askTransfer = true;
        }
    } else {
        // Check if it is not currently transferred
        if (getDataRequests(param.getData().getName()) != null) {
            askTransfer = true;
        }
    }
    // Request the transfer if needed
    askForTransfer(askTransfer, param, index, tt);
}
Also used : NIOURI(es.bsc.compss.nio.NIOURI) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) IOException(java.io.IOException) File(java.io.File)

Aggregations

NIOURI (es.bsc.compss.nio.NIOURI)5 UnstartedNodeException (es.bsc.compss.exceptions.UnstartedNodeException)2 File (java.io.File)2 IOException (java.io.IOException)2 Data (es.bsc.compss.nio.commands.Data)1 DataRequest (es.bsc.compss.nio.dataRequest.DataRequest)1 MasterDataRequest (es.bsc.compss.nio.dataRequest.MasterDataRequest)1 LogicalData (es.bsc.compss.types.data.LogicalData)1 Copy (es.bsc.compss.types.data.operation.copy.Copy)1 DeferredCopy (es.bsc.compss.types.data.operation.copy.DeferredCopy)1 StorageCopy (es.bsc.compss.types.data.operation.copy.StorageCopy)1 MultiURI (es.bsc.compss.types.uri.MultiURI)1 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)1