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));
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations