use of es.bsc.compss.types.uri.SimpleURI 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.uri.SimpleURI in project compss by bsc-wdc.
the class LogicalData method removeValue.
/**
* Removes the object from master main memory and removes its location
*
* @return
*/
public synchronized Object removeValue() {
DataLocation loc = null;
String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
try {
SimpleURI uri = new SimpleURI(targetPath);
loc = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, e);
}
Object val = this.value;
this.value = null;
// Removes only the memory location (no need to check private, shared,
// persistent)
this.locations.remove(loc);
return val;
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class Resource method getWorkersDebugInfo.
private void getWorkersDebugInfo() {
if (DEBUG) {
LOGGER.debug("Copying Workers Information");
}
COMPSsNode masterNode = Comm.getAppHost().getNode();
Semaphore sem = new Semaphore(0);
WorkersDebugInformationListener wdil = new WorkersDebugInformationListener(sem);
// Get Worker output
wdil.addOperation();
String outFileName = "worker_" + getName() + ".out";
SimpleURI outFileOrigin = node.getCompletePath(DataType.FILE_T, "log" + File.separator + "static_" + outFileName);
String outFileTarget = Protocol.FILE_URI.getSchema() + Comm.getAppHost().getWorkersDirPath() + File.separator + outFileName;
DataLocation outSource = null;
try {
outSource = DataLocation.createLocation(this, outFileOrigin);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + outFileOrigin.toString(), e);
}
DataLocation outTarget = null;
try {
SimpleURI uri = new SimpleURI(outFileTarget);
outTarget = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + outFileTarget);
}
LOGGER.debug("- Source: " + outFileOrigin);
LOGGER.debug("- Target: " + outFileTarget);
masterNode.obtainData(new LogicalData("workerOut" + this.getName()), outSource, outTarget, new LogicalData("workerOut" + this.getName()), new WorkersDebugInfoCopyTransferable(), wdil);
// Get Worker error
wdil.addOperation();
String errFileName = "worker_" + getName() + ".err";
SimpleURI errFileOrigin = node.getCompletePath(DataType.FILE_T, "log" + File.separator + "static_" + errFileName);
String errFileTarget = Protocol.FILE_URI.getSchema() + Comm.getAppHost().getWorkersDirPath() + File.separator + errFileName;
DataLocation errSource = null;
try {
errSource = DataLocation.createLocation(this, errFileOrigin);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + errFileOrigin.toString(), e);
}
DataLocation errTarget = null;
try {
SimpleURI uri = new SimpleURI(errFileTarget);
errTarget = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + errFileTarget);
}
LOGGER.debug("- Source: " + errFileOrigin);
LOGGER.debug("- Target: " + errFileTarget);
masterNode.obtainData(new LogicalData("workerErr" + this.getName()), errSource, errTarget, new LogicalData("workerErr" + this.getName()), new WorkersDebugInfoCopyTransferable(), wdil);
// Wait transfers
wdil.enable();
try {
sem.acquire();
} catch (InterruptedException ex) {
LOGGER.error("Error waiting for worker debug files in resource " + getName() + " to get saved");
}
LOGGER.debug("Worker files from resource " + getName() + "received");
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class Resource method getData.
/**
* Retrieves a given data
*
* @param ld
* @param newName
* @param tgtData
* @param reason
* @param listener
*/
public void getData(LogicalData ld, String newName, LogicalData tgtData, Transferable reason, EventListener listener) {
SimpleURI workingPath = node.getCompletePath(reason.getType(), newName);
DataLocation target = null;
try {
target = DataLocation.createLocation(this, workingPath);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + workingPath.toString(), e);
}
getData(ld, target, tgtData, reason, listener);
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class AccessProcessor method mainAccessToFile.
/**
* Notifies a main access to a given file @sourceLocation in mode @fap
*
* @param sourceLocation
* @param fap
* @param destDir
* @return
*/
public DataLocation mainAccessToFile(DataLocation sourceLocation, AccessParams.FileAccessParams fap, String destDir) {
boolean alreadyAccessed = alreadyAccessed(sourceLocation);
if (!alreadyAccessed) {
LOGGER.debug("File not accessed before, returning the same location");
return sourceLocation;
}
// Tell the DM that the application wants to access a file.
DataAccessId faId = registerDataAccess(fap);
DataLocation tgtLocation = sourceLocation;
if (fap.getMode() != AccessMode.W) {
// Wait until the last writer task for the file has finished
LOGGER.debug("File " + faId.getDataId() + " mode contains R, waiting until the last writer has finished");
waitForTask(faId.getDataId(), AccessMode.R);
if (destDir == null) {
tgtLocation = transferFileOpen(faId);
} else {
DataInstanceId daId;
if (fap.getMode() == AccessMode.R) {
RAccessId ra = (RAccessId) faId;
daId = ra.getReadDataInstance();
} else {
RWAccessId ra = (RWAccessId) faId;
daId = ra.getReadDataInstance();
}
String rename = daId.getRenaming();
String path = DataLocation.Protocol.FILE_URI.getSchema() + destDir + rename;
try {
SimpleURI uri = new SimpleURI(path);
tgtLocation = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
}
transferFileRaw(faId, tgtLocation);
}
}
if (fap.getMode() != AccessMode.R) {
// Mode contains W
LOGGER.debug("File " + faId.getDataId() + " mode contains W, register new writer");
DataInstanceId daId;
if (fap.getMode() == AccessMode.RW) {
RWAccessId ra = (RWAccessId) faId;
daId = ra.getWrittenDataInstance();
} else {
WAccessId ra = (WAccessId) faId;
daId = ra.getWrittenDataInstance();
}
String rename = daId.getRenaming();
String path = DataLocation.Protocol.FILE_URI.getSchema() + Comm.getAppHost().getTempDirPath() + rename;
try {
SimpleURI uri = new SimpleURI(path);
tgtLocation = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
}
Comm.registerLocation(rename, tgtLocation);
}
if (DEBUG) {
LOGGER.debug("File " + faId.getDataId() + " located on " + tgtLocation.toString());
}
return tgtLocation;
}
Aggregations