use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class COMPSsRuntimeImpl method deleteFile.
/**
* Deletes the specified version of a file
*/
@Override
public boolean deleteFile(String fileName) {
// Check parameters
if (fileName == null || fileName.isEmpty()) {
return false;
}
LOGGER.info("Deleting File " + fileName);
// Emit event
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.Event.DELETE.getId(), Tracer.Event.DELETE.getType());
}
// Parse the file name and translate the access mode
try {
DataLocation loc = createLocation(fileName);
ap.markForDeletion(loc);
} catch (IOException ioe) {
ErrorManager.fatal(ERROR_FILE_NAME, ioe);
} finally {
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.EVENT_END, Tracer.getRuntimeEventsType());
}
}
// Return deletion was successful
return true;
}
use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class COMPSsRuntimeImpl method mainAccessToFile.
private String mainAccessToFile(String fileName, DataLocation loc, AccessMode am, String destDir) {
// Tell the AP that the application wants to access a file.
FileAccessParams fap = new FileAccessParams(am, loc);
DataLocation targetLocation = ap.mainAccessToFile(loc, fap, destDir);
// Checks on target
String path = (targetLocation == null) ? fileName : targetLocation.getPath();
DataLocation finalLocation = (targetLocation == null) ? loc : targetLocation;
if (finalLocation == null) {
ErrorManager.fatal(ERROR_FILE_NAME);
return null;
}
// Return the final target path
String finalPath;
MultiURI u = finalLocation.getURIInHost(Comm.getAppHost());
if (u != null) {
finalPath = u.getPath();
} else {
finalPath = path;
}
return finalPath;
}
use of es.bsc.compss.types.data.location.DataLocation 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;
}
use of es.bsc.compss.types.data.location.DataLocation 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;
}
use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class ExecutionAction method doOutputTransfers.
private final void doOutputTransfers(Job<?> job) {
// Job finished, update info about the generated/updated data
Worker<? extends WorkerResourceDescription> w = this.getAssignedResource().getResource();
for (Parameter p : job.getTaskParams().getParameters()) {
if (p instanceof DependencyParameter) {
// OUT or INOUT: we must tell the FTM about the
// generated/updated datum
DataInstanceId dId = null;
DependencyParameter dp = (DependencyParameter) p;
switch(p.getDirection()) {
case IN:
// FTM already knows about this datum
continue;
case OUT:
dId = ((DataAccessId.WAccessId) dp.getDataAccessId()).getWrittenDataInstance();
break;
case INOUT:
dId = ((DataAccessId.RWAccessId) dp.getDataAccessId()).getWrittenDataInstance();
if (job.getType() == TaskType.SERVICE) {
continue;
}
break;
}
String name = dId.getRenaming();
if (job.getType() == TaskType.METHOD) {
String targetProtocol = null;
switch(dp.getType()) {
case FILE_T:
targetProtocol = DataLocation.Protocol.FILE_URI.getSchema();
break;
case OBJECT_T:
targetProtocol = DataLocation.Protocol.OBJECT_URI.getSchema();
break;
case PSCO_T:
targetProtocol = DataLocation.Protocol.PERSISTENT_URI.getSchema();
break;
case EXTERNAL_OBJECT_T:
// Its value is the PSCO Id
targetProtocol = DataLocation.Protocol.PERSISTENT_URI.getSchema();
break;
default:
// Should never reach this point because only
// DependencyParameter types are treated
// Ask for any_uri just in case
targetProtocol = DataLocation.Protocol.ANY_URI.getSchema();
break;
}
DataLocation outLoc = null;
try {
SimpleURI targetURI = new SimpleURI(targetProtocol + dp.getDataTarget());
outLoc = DataLocation.createLocation(w, targetURI);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + dp.getDataTarget(), e);
}
Comm.registerLocation(name, outLoc);
} else {
// Service
Object value = job.getReturnValue();
Comm.registerValue(name, value);
}
}
}
}
Aggregations