use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class ServiceInstance method obtainData.
@Override
public void obtainData(LogicalData ld, DataLocation source, DataLocation target, LogicalData tgtData, Transferable reason, EventListener listener) {
// Delegate on the master to obtain the data value
String path = target.getProtocol().getSchema() + target.getPath();
DataLocation tgtLoc = null;
try {
SimpleURI uri = new SimpleURI(path);
tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
}
COMPSsNode node = Comm.getAppHost().getNode();
node.obtainData(ld, source, tgtLoc, tgtData, reason, listener);
}
use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class Tracer method transferMasterPackage.
private static void transferMasterPackage() {
if (DEBUG) {
LOGGER.debug("Tracing: Transferring master package");
}
// Create source and target locations for tar.gz file
String filename = "master_compss_trace.tar.gz";
DataLocation source = null;
String sourcePath = DataLocation.Protocol.FILE_URI.getSchema() + filename;
try {
SimpleURI uri = new SimpleURI(sourcePath);
source = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + sourcePath, e);
}
DataLocation target = null;
String targetPath = DataLocation.Protocol.FILE_URI.getSchema() + traceDirPath + filename;
try {
SimpleURI uri = new SimpleURI(targetPath);
target = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, e);
}
// Ask for data
Semaphore sem = new Semaphore(0);
TracingCopyListener tracingListener = new TracingCopyListener(sem);
tracingListener.addOperation();
Comm.getAppHost().getNode().obtainData(new LogicalData("tracing master package"), source, target, new LogicalData("tracing master package"), new TracingCopyTransferable(), tracingListener);
// Wait for data
tracingListener.enable();
try {
sem.acquire();
} catch (InterruptedException ex) {
ErrorManager.warn("Error waiting for tracing files in master to get saved");
}
}
use of es.bsc.compss.types.data.location.DataLocation 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;
}
}
}
}
use of es.bsc.compss.types.data.location.DataLocation 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");
}
use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class LogicalData method finishedCopy.
/**
* Marks the end of a copy. Returns the location of the finished copy or null if not found
*
* @param c
* @return
*/
public synchronized DataLocation finishedCopy(Copy c) {
DataLocation loc = null;
Iterator<CopyInProgress> it = this.inProgress.iterator();
while (it.hasNext()) {
CopyInProgress cip = it.next();
if (cip.c == c) {
it.remove();
loc = cip.loc;
break;
}
}
return loc;
}
Aggregations