use of es.bsc.compss.types.data.DataAccessId.WAccessId in project compss by bsc-wdc.
the class NIOJob method addParams.
private LinkedList<NIOParam> addParams() {
LinkedList<NIOParam> params = new LinkedList<>();
for (Parameter param : taskParams.getParameters()) {
DataType type = param.getType();
NIOParam np;
switch(type) {
case FILE_T:
case OBJECT_T:
case PSCO_T:
case EXTERNAL_OBJECT_T:
DependencyParameter dPar = (DependencyParameter) param;
DataAccessId dAccId = dPar.getDataAccessId();
Object value = dPar.getDataTarget();
boolean preserveSourceData = true;
if (dAccId instanceof RAccessId) {
// Parameter is a R, has sources
preserveSourceData = ((RAccessId) dAccId).isPreserveSourceData();
} else if (dAccId instanceof RWAccessId) {
// Parameter is a RW, has sources
preserveSourceData = ((RWAccessId) dAccId).isPreserveSourceData();
} else {
// Parameter is a W, it has no sources
preserveSourceData = false;
}
// Workaround for Python PSCOs in return
// Check if the parameter has a valid PSCO and change its type
String renaming;
DataAccessId faId = dPar.getDataAccessId();
if (faId instanceof WAccessId) {
// Write mode
WAccessId waId = (WAccessId) faId;
renaming = waId.getWrittenDataInstance().getRenaming();
} else if (faId instanceof RWAccessId) {
// Read write mode
RWAccessId rwaId = (RWAccessId) faId;
renaming = rwaId.getWrittenDataInstance().getRenaming();
} else {
// Read only mode
RAccessId raId = (RAccessId) faId;
renaming = raId.getReadDataInstance().getRenaming();
}
String pscoId = Comm.getData(renaming).getId();
if (pscoId != null && type.equals(DataType.FILE_T)) {
param.setType(DataType.EXTERNAL_OBJECT_T);
type = param.getType();
}
// Create the NIO Param
// Only store W and RW
boolean writeFinalValue = !(dAccId instanceof RAccessId);
np = new NIOParam(type, param.getStream(), param.getPrefix(), preserveSourceData, writeFinalValue, value, (Data) dPar.getDataSource(), dPar.getOriginalName());
break;
default:
BasicTypeParameter btParB = (BasicTypeParameter) param;
value = btParB.getValue();
// Basic parameters are not preserved on Worker
preserveSourceData = false;
// Basic parameters are not stored on Worker
writeFinalValue = false;
np = new NIOParam(type, param.getStream(), param.getPrefix(), preserveSourceData, writeFinalValue, value, null, DependencyParameter.NO_NAME);
break;
}
params.add(np);
}
return params;
}
use of es.bsc.compss.types.data.DataAccessId.WAccessId 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.DataAccessId.WAccessId 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