use of es.bsc.compss.types.data.operation.OneOpWithSemListener in project compss by bsc-wdc.
the class TransferOpenFileRequest method process.
@Override
public void process(AccessProcessor ap, TaskAnalyser ta, DataInfoProvider dip, TaskDispatcher td) {
LOGGER.debug("Process TransferOpenFileRequest");
// Get target information
String targetName;
String targetPath;
if (faId instanceof WAccessId) {
// Write mode
WAccessId waId = (WAccessId) faId;
DataInstanceId targetFile = waId.getWrittenDataInstance();
targetName = targetFile.getRenaming();
targetPath = Comm.getAppHost().getTempDirPath() + targetName;
} else if (faId instanceof RWAccessId) {
// Read write mode
RWAccessId rwaId = (RWAccessId) faId;
targetName = rwaId.getWrittenDataInstance().getRenaming();
targetPath = Comm.getAppHost().getTempDirPath() + targetName;
} else {
// Read only mode
RAccessId raId = (RAccessId) faId;
targetName = raId.getReadDataInstance().getRenaming();
targetPath = Comm.getAppHost().getTempDirPath() + targetName;
}
LOGGER.debug("Openning file " + targetName + " at " + targetPath);
// Create location
DataLocation targetLocation = null;
String pscoId = Comm.getData(targetName).getId();
if (pscoId == null) {
try {
SimpleURI targetURI = new SimpleURI(DataLocation.Protocol.FILE_URI.getSchema() + targetPath);
targetLocation = DataLocation.createLocation(Comm.getAppHost(), targetURI);
} catch (IOException ioe) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, ioe);
}
} else {
// It is an external object persisted inside the task
try {
SimpleURI targetURI = new SimpleURI(DataLocation.Protocol.PERSISTENT_URI.getSchema() + pscoId);
targetLocation = DataLocation.createLocation(Comm.getAppHost(), targetURI);
} catch (IOException ioe) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, ioe);
}
}
// Register target location
LOGGER.debug("Setting target location to " + targetLocation);
setLocation(targetLocation);
// Ask for transfer when required
if (pscoId != null) {
LOGGER.debug("External object detected. Auto-release");
Comm.registerLocation(targetName, targetLocation);
sem.release();
} else if (faId instanceof WAccessId) {
LOGGER.debug("Write only mode. Auto-release");
Comm.registerLocation(targetName, targetLocation);
sem.release();
} else if (faId instanceof RWAccessId) {
LOGGER.debug("RW mode. Asking for transfer");
RWAccessId rwaId = (RWAccessId) faId;
String srcName = rwaId.getReadDataInstance().getRenaming();
Comm.getAppHost().getData(srcName, targetName, (LogicalData) null, new FileTransferable(), new OneOpWithSemListener(sem));
} else {
LOGGER.debug("Read only mode. Asking for transfer");
RAccessId raId = (RAccessId) faId;
String srcName = raId.getReadDataInstance().getRenaming();
Comm.getAppHost().getData(srcName, srcName, new FileTransferable(), new OneOpWithSemListener(sem));
}
}
use of es.bsc.compss.types.data.operation.OneOpWithSemListener in project compss by bsc-wdc.
the class TransferRawFileRequest method process.
@Override
public void process(AccessProcessor ap, TaskAnalyser ta, DataInfoProvider dip, TaskDispatcher td) {
// Make a copy of the original logical file, we don't want to leave track
String sourceName = faId.getReadDataInstance().getRenaming();
Comm.getAppHost().getData(sourceName, location, (LogicalData) null, new FileTransferable(), new OneOpWithSemListener(sem));
}
use of es.bsc.compss.types.data.operation.OneOpWithSemListener in project compss by bsc-wdc.
the class DataInfoProvider method transferObjectValue.
/**
* Transfers the value of an object
*
* @param toRequest
* @return
*/
public LogicalData transferObjectValue(TransferObjectRequest toRequest) {
Semaphore sem = toRequest.getSemaphore();
DataAccessId daId = toRequest.getDaId();
RWAccessId rwaId = (RWAccessId) daId;
String sourceName = rwaId.getReadDataInstance().getRenaming();
// String targetName = rwaId.getWrittenDataInstance().getRenaming();
if (DEBUG) {
LOGGER.debug("Requesting getting object " + sourceName);
}
LogicalData ld = Comm.getData(sourceName);
if (ld == null) {
ErrorManager.error("Unregistered data " + sourceName);
return null;
}
if (ld.isInMemory()) {
// Write to storage (if needed)
try {
ld.writeToStorage();
} catch (IOException e) {
ErrorManager.error("Exception writing object to file.", e);
}
// Clear value
ld.removeValue();
// Set response
toRequest.setResponse(ld.getValue());
toRequest.setTargetData(ld);
toRequest.getSemaphore().release();
} else {
if (DEBUG) {
LOGGER.debug("Object " + sourceName + " not in memory. Requesting tranfers to " + Comm.getAppHost().getName());
}
DataLocation targetLocation = null;
String path = DataLocation.Protocol.FILE_URI.getSchema() + Comm.getAppHost().getTempDirPath() + sourceName;
try {
SimpleURI uri = new SimpleURI(path);
targetLocation = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
}
Comm.getAppHost().getData(sourceName, targetLocation, new ObjectTransferable(), new OneOpWithSemListener(sem));
}
return ld;
}
Aggregations