use of es.bsc.compss.types.data.DataInstanceId in project compss by bsc-wdc.
the class Score method calculateDataLocalityScore.
/**
* Calculates the number of Parameters in @params located in a given worker
*
* @w.
*
* @param params
* @param w
* @return
*/
public static long calculateDataLocalityScore(TaskDescription params, Worker<?> w) {
long resourceScore = 0;
if (params != null) {
Parameter[] parameters = params.getParameters();
// are located in the host
for (Parameter p : parameters) {
if (p instanceof DependencyParameter && p.getDirection() != Direction.OUT) {
DependencyParameter dp = (DependencyParameter) p;
DataInstanceId dId = null;
switch(dp.getDirection()) {
case IN:
DataAccessId.RAccessId raId = (DataAccessId.RAccessId) dp.getDataAccessId();
dId = raId.getReadDataInstance();
break;
case INOUT:
DataAccessId.RWAccessId rwaId = (DataAccessId.RWAccessId) dp.getDataAccessId();
dId = rwaId.getReadDataInstance();
break;
case OUT:
// Cannot happen because of previous if
break;
}
// Get hosts for resource score
if (dId != null) {
LogicalData dataLD = Comm.getData(dId.getRenaming());
if (dataLD != null) {
Set<Resource> hosts = dataLD.getAllHosts();
for (Resource host : hosts) {
if (host == w) {
resourceScore++;
}
}
}
}
}
}
}
return resourceScore;
}
use of es.bsc.compss.types.data.DataInstanceId 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;
}
use of es.bsc.compss.types.data.DataInstanceId in project compss by bsc-wdc.
the class AccessProcessor method mainAcessToObject.
/**
* Notifies a main access to an object @obj
*
* @param obj
* @param hashCode
* @return
*/
public Object mainAcessToObject(Object obj, int hashCode) {
if (DEBUG) {
LOGGER.debug("Requesting main access to object with hash code " + hashCode);
}
// Tell the DIP that the application wants to access an object
AccessParams.ObjectAccessParams oap = new AccessParams.ObjectAccessParams(AccessMode.RW, obj, hashCode);
DataAccessId oaId = registerDataAccess(oap);
DataInstanceId wId = ((DataAccessId.RWAccessId) oaId).getWrittenDataInstance();
String wRename = wId.getRenaming();
// Wait until the last writer task for the object has finished
if (DEBUG) {
LOGGER.debug("Waiting for last writer of " + oaId.getDataId() + " with renaming " + wRename);
}
waitForTask(oaId.getDataId(), AccessMode.RW);
// Ask for the object
if (DEBUG) {
LOGGER.debug("Request object transfer " + oaId.getDataId() + " with renaming " + wRename);
}
Object oUpdated = obtainObject(oaId);
if (DEBUG) {
LOGGER.debug("Object retrieved. Set new version to: " + wRename);
}
setObjectVersionValue(wRename, oUpdated);
return oUpdated;
}
use of es.bsc.compss.types.data.DataInstanceId in project compss by bsc-wdc.
the class AccessProcessor method mainAcessToExternalObject.
/**
* Notifies a main access to an external object {@code id}
*
* @param fileName
* @param id
* @param hashCode
* @return
*/
public String mainAcessToExternalObject(String id, int hashCode) {
if (DEBUG) {
LOGGER.debug("Requesting main access to external object with hash code " + hashCode);
}
// Tell the DIP that the application wants to access an object
AccessParams.ObjectAccessParams oap = new AccessParams.ObjectAccessParams(AccessMode.RW, id, hashCode);
DataAccessId oaId = registerDataAccess(oap);
DataInstanceId wId = ((DataAccessId.RWAccessId) oaId).getWrittenDataInstance();
String wRename = wId.getRenaming();
// Wait until the last writer task for the object has finished
if (DEBUG) {
LOGGER.debug("Waiting for last writer of " + oaId.getDataId() + " with renaming " + wRename);
}
waitForTask(oaId.getDataId(), AccessMode.RW);
// TODO: Check if the object was already piggybacked in the task notification
String lastRenaming = ((DataAccessId.RWAccessId) oaId).getReadDataInstance().getRenaming();
String newId = Comm.getData(lastRenaming).getId();
return Protocol.PERSISTENT_URI.getSchema() + newId;
}
use of es.bsc.compss.types.data.DataInstanceId 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