use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class COMPSsRuntimeImpl method getFile.
/*
* ********************************************************************************************************
* LoaderAPI INTERFACE IMPLEMENTATION
* ********************************************************************************************************
*/
/**
* Returns a copy of the last file version
*/
@Override
public String getFile(String fileName, String destDir) {
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.Event.GET_FILE.getId(), Tracer.Event.GET_FILE.getType());
}
// Parse the destination path
if (!destDir.endsWith(File.separator)) {
destDir += File.separator;
}
// Parse the file name
DataLocation sourceLocation;
try {
sourceLocation = createLocation(fileName);
} catch (IOException ioe) {
ErrorManager.fatal(ERROR_FILE_NAME, ioe);
return null;
}
if (sourceLocation == null) {
ErrorManager.fatal(ERROR_FILE_NAME);
return null;
}
// Ask the AP to
String finalPath = mainAccessToFile(fileName, sourceLocation, AccessMode.R, destDir);
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.EVENT_END, Tracer.getRuntimeEventsType());
}
return finalPath;
}
use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class COMPSsRuntimeImpl method processParameters.
/*
* ************************************************************************************************************
* PRIVATE HELPER METHODS
* ********************************************************************************************************
*/
private Parameter[] processParameters(int parameterCount, Object[] parameters) {
Parameter[] pars = new Parameter[parameterCount];
// Parameter parsing needed, object is not serializable
int i = 0;
for (int npar = 0; npar < parameterCount; ++npar) {
DataType type = (DataType) parameters[i + 1];
Direction direction = (Direction) parameters[i + 2];
Stream stream = (Stream) parameters[i + 3];
String prefix = (String) parameters[i + 4];
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" Parameter " + (npar + 1) + " has type " + type.name());
}
switch(type) {
case FILE_T:
try {
String fileName = (String) parameters[i];
String originalName = new File(fileName).getName();
DataLocation location = createLocation((String) parameters[i]);
pars[npar] = new FileParameter(direction, stream, prefix, location, originalName);
} catch (Exception e) {
LOGGER.error(ERROR_FILE_NAME, e);
ErrorManager.fatal(ERROR_FILE_NAME, e);
}
break;
case PSCO_T:
case OBJECT_T:
pars[npar] = new ObjectParameter(direction, stream, prefix, parameters[i], oReg.newObjectParameter(parameters[i]));
break;
case EXTERNAL_OBJECT_T:
String id = (String) parameters[i];
pars[npar] = new ExternalObjectParameter(direction, stream, prefix, id, externalObjectHashcode(id));
break;
default:
/*
* Basic types (including String). The only possible direction is IN, warn otherwise
*/
if (direction != Direction.IN) {
LOGGER.warn(WARN_WRONG_DIRECTION + "Parameter " + npar + " is a basic type, therefore it must have IN direction");
}
pars[npar] = new BasicTypeParameter(type, Direction.IN, stream, prefix, parameters[i]);
break;
}
i += 5;
}
return pars;
}
use of es.bsc.compss.types.data.location.DataLocation 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.location.DataLocation in project compss by bsc-wdc.
the class LogicalData method removeHostAndCheckLocationToSave.
/**
* Removes all the locations assigned to a given host and returns a valid location if the file is unique
*
* @param host
* @param sharedMountPoints
* @return a valid location if the file is unique
*/
public synchronized DataLocation removeHostAndCheckLocationToSave(Resource host, Map<String, String> sharedMountPoints) {
// and there is no unique file to save
if (isBeingSaved) {
return null;
}
// Otherwise, we must remove all the host locations and store a unique
// location if needed. We only store the "best" location if any (by
// choosing
// any private location found or the first shared location)
lockHostRemoval_private();
DataLocation uniqueHostLocation = null;
Iterator<DataLocation> it = this.locations.iterator();
while (it.hasNext()) {
DataLocation loc = it.next();
switch(loc.getType()) {
case PRIVATE:
if (loc.getURIInHost(host) != null) {
this.isBeingSaved = true;
uniqueHostLocation = loc;
it.remove();
}
break;
case SHARED:
// is unique and must be saved
if (loc.getHosts().isEmpty()) {
String sharedDisk = loc.getSharedDisk();
if (sharedDisk != null) {
String mountPoint = sharedMountPoints.get(sharedDisk);
if (mountPoint != null) {
if (uniqueHostLocation == null) {
this.isBeingSaved = true;
String targetPath = Protocol.FILE_URI.getSchema() + loc.getPath();
try {
SimpleURI uri = new SimpleURI(targetPath);
uniqueHostLocation = DataLocation.createLocation(host, uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, e);
}
}
}
}
}
break;
case PERSISTENT:
// Persistent location must never be saved
break;
}
}
releaseHostRemoval_private();
return uniqueHostLocation;
}
use of es.bsc.compss.types.data.location.DataLocation in project compss by bsc-wdc.
the class LogicalData method toString.
@Override
public synchronized String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Logical Data name: ").append(this.name).append("\n");
sb.append("\t Value: ").append(value).append("\n");
sb.append("\t Id: ").append(id).append("\n");
sb.append("\t Locations:\n");
synchronized (locations) {
for (DataLocation dl : locations) {
sb.append("\t\t * ").append(dl).append("\n");
}
}
return sb.toString();
}
Aggregations