use of es.bsc.compss.types.data.operation.FileTransferable 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.FileTransferable 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.FileTransferable in project compss by bsc-wdc.
the class DataInfoProvider method blockDataAndGetResultFile.
/**
* Blocks dataId and retrieves its result file
*
* @param dataId
* @param listener
* @return
*/
public ResultFile blockDataAndGetResultFile(int dataId, ResultListener listener) {
DataInstanceId lastVersion;
FileInfo fileInfo = (FileInfo) idToData.get(dataId);
if (fileInfo != null && !fileInfo.isCurrentVersionToDelete()) {
// If current version is to delete do not
// transfer
String[] splitPath = fileInfo.getOriginalLocation().getPath().split(File.separator);
String origName = splitPath[splitPath.length - 1];
if (origName.startsWith("compss-serialized-obj_")) {
// Do not transfer objects serialized by the bindings
if (DEBUG) {
LOGGER.debug("Discarding file " + origName + " as a result");
}
return null;
}
fileInfo.blockDeletions();
lastVersion = fileInfo.getCurrentDataVersion().getDataInstanceId();
ResultFile rf = new ResultFile(lastVersion, fileInfo.getOriginalLocation());
DataInstanceId fId = rf.getFileInstanceId();
String renaming = fId.getRenaming();
// Look for the last available version
while (renaming != null && !Comm.existsData(renaming)) {
renaming = DataInstanceId.previousVersionRenaming(renaming);
}
if (renaming == null) {
LOGGER.error(RES_FILE_TRANSFER_ERR + ": Cannot transfer file " + fId.getRenaming() + " nor any of its previous versions");
return null;
}
// Check if data is a PSCO and must be consolidated
for (DataLocation loc : Comm.getData(renaming).getLocations()) {
if (loc instanceof PersistentLocation) {
String pscoId = ((PersistentLocation) loc).getId();
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.Event.STORAGE_CONSOLIDATE.getId(), Tracer.Event.STORAGE_CONSOLIDATE.getType());
}
try {
StorageItf.consolidateVersion(pscoId);
} catch (StorageException e) {
LOGGER.error("Cannot consolidate PSCO " + pscoId, e);
} finally {
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.EVENT_END, Tracer.Event.STORAGE_CONSOLIDATE.getType());
}
}
LOGGER.debug("Returned because persistent object");
return rf;
}
}
// If no PSCO location is found, perform normal getData
listener.addOperation();
Comm.getAppHost().getData(renaming, rf.getOriginalLocation(), new FileTransferable(), listener);
return rf;
} else if (fileInfo != null && fileInfo.isCurrentVersionToDelete()) {
if (DEBUG) {
String[] splitPath = fileInfo.getOriginalLocation().getPath().split(File.separator);
String origName = splitPath[splitPath.length - 1];
LOGGER.debug("Trying to delete file " + origName);
}
if (fileInfo.delete()) {
// idToData.remove(dataId);
}
}
return null;
}
Aggregations