use of es.bsc.compss.types.uri.SimpleURI 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.uri.SimpleURI in project compss by bsc-wdc.
the class DataLocation method createLocation.
/**
* Creates a new location in the host @host with path @uri. The URI must: - Contain a valid schema (file://,
* shared://, object://, storage://) - Contain a valid path - Any hostname (ignored since host is received from the
* other parameter)
*
* @param host
* @param uri
* @return
* @throws Exception
*/
public static DataLocation createLocation(Resource host, SimpleURI uri) throws IOException {
Protocol protocol = Protocol.getBySchema(uri.getSchema());
if (protocol == null) {
LOGGER.warn("WARN: Unrecognised protocol [ " + uri.getSchema() + " ] for createLocation. Switching to " + Protocol.ANY_URI.getSchema());
protocol = Protocol.ANY_URI;
}
DataLocation loc = null;
switch(protocol) {
case FILE_URI:
// Local file
String canonicalPath = null;
try {
canonicalPath = new URI(uri.getPath()).normalize().getPath();
if ('/' != canonicalPath.charAt(0)) {
canonicalPath = new File(uri.getPath()).getCanonicalPath();
}
} catch (URISyntaxException e) {
canonicalPath = new File(uri.getPath()).getCanonicalPath();
}
LOGGER.debug("Creating new FileLocation: " + protocol.getSchema() + host.getName() + "@" + canonicalPath);
loc = createLocation(Protocol.FILE_URI, host, canonicalPath);
break;
case SHARED_URI:
// Shared file of the form: shared://sharedDisk/path/file
// First slash occurrence
int splitIndex = uri.getPath().indexOf(File.separator);
String diskName = uri.getPath().substring(0, splitIndex);
String path = uri.getPath().substring(splitIndex + 1);
LOGGER.debug("Creating new SharedLocation: " + protocol.getSchema() + "@" + diskName + path);
loc = new SharedLocation(Protocol.SHARED_URI, diskName, path);
break;
case OBJECT_URI:
// Object
// The Object name is stored as path in the URI
String objectName = uri.getPath();
LOGGER.debug("Creating new ObjectLocation: " + protocol.getSchema() + host.getName() + "@" + objectName);
loc = createLocation(Protocol.OBJECT_URI, host, objectName);
break;
case PERSISTENT_URI:
// The PSCO Id is stored as path in the URI
String id = uri.getPath();
LOGGER.debug("Creating new PersistentLocation: " + id);
loc = new PersistentLocation(id);
break;
case ANY_URI:
LOGGER.debug("Creating new AnyLocation: " + Protocol.ANY_URI.getSchema() + host.getName() + "@" + uri.getPath());
loc = createLocation(Protocol.ANY_URI, host, uri.getPath());
break;
}
return loc;
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class Resource method getTracingPackageToMaster.
private void getTracingPackageToMaster() {
COMPSsNode masterNode = Comm.getAppHost().getNode();
Semaphore sem = new Semaphore(0);
String fileName = getName() + "_compss_trace.tar.gz";
SimpleURI fileOriginURI = node.getCompletePath(DataType.FILE_T, fileName);
if (DEBUG) {
LOGGER.debug("Copying tracing package from : " + fileOriginURI.getPath() + ",to : " + Comm.getAppHost().getAppLogDirPath() + "trace" + File.separator + fileName);
}
TracingCopyListener tracingListener = new TracingCopyListener(sem);
tracingListener.addOperation();
// Source data location
DataLocation source;
try {
source = DataLocation.createLocation(this, fileOriginURI);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + fileOriginURI.getPath(), e);
return;
}
// Target data location
DataLocation tgt;
String targetPath = Protocol.FILE_URI.getSchema() + Comm.getAppHost().getAppLogDirPath() + "trace" + File.separator + fileName;
try {
SimpleURI uri = new SimpleURI(targetPath);
tgt = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath);
return;
}
// Ask for data
masterNode.obtainData(new LogicalData("tracing" + this.getName()), source, tgt, new LogicalData("tracing" + this.getName()), new TracingCopyTransferable(), tracingListener);
tracingListener.enable();
try {
sem.acquire();
} catch (InterruptedException ex) {
LOGGER.error("Error waiting for tracing files in resource " + getName() + " to get saved");
}
if (DEBUG) {
LOGGER.debug("Removing " + this.getName() + " tracing temporary files");
}
File f = null;
try {
f = new File(source.getPath());
if (!f.delete()) {
LOGGER.error("Unable to remove tracing temporary files of node " + this.getName());
}
} catch (Exception e) {
LOGGER.error("Unable to remove tracing temporary files of node " + this.getName(), e);
}
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class Resource method retrieveData.
/**
* Retrieves all the data from the Resource
*
* @param saveUniqueData
*/
public void retrieveData(boolean saveUniqueData) {
if (DEBUG) {
LOGGER.debug("Retrieving data resource " + this.getName());
}
Semaphore sem = new Semaphore(0);
SafeCopyListener listener = new SafeCopyListener(sem);
Set<LogicalData> lds = getAllDataFromHost();
Map<String, String> disks = SharedDiskManager.terminate(this);
COMPSsNode masterNode = Comm.getAppHost().getNode();
for (LogicalData ld : lds) {
ld.notifyToInProgressCopiesEnd(listener);
DataLocation lastLoc = ld.removeHostAndCheckLocationToSave(this, disks);
if (lastLoc != null && saveUniqueData) {
listener.addOperation();
DataLocation safeLoc = null;
String safePath = Protocol.FILE_URI.getSchema() + Comm.getAppHost().getTempDirPath() + ld.getName();
try {
SimpleURI uri = new SimpleURI(safePath);
safeLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + safePath, e);
}
masterNode.obtainData(ld, lastLoc, safeLoc, ld, new SafeCopyTransferable(), listener);
}
}
if (DEBUG) {
LOGGER.debug("Waiting for finishing saving copies for " + this.getName());
}
listener.enable();
try {
sem.acquire();
} catch (InterruptedException ex) {
LOGGER.error("Error waiting for files in resource " + getName() + " to get saved");
}
if (DEBUG) {
LOGGER.debug("Unique files saved for " + this.getName());
}
if (this.getType() != Type.SERVICE) {
shutdownExecutionManager();
if (Tracer.isActivated()) {
if (node.generatePackage()) {
getTracingPackageToMaster();
if (DEBUG) {
LOGGER.debug("Tracing package obtained for " + this.getName());
}
}
}
if (DEBUG) {
if (node.generateWorkersDebugInfo()) {
getWorkersDebugInfo();
LOGGER.debug("Workers Debug files obtained for " + this.getName());
}
}
}
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class ServiceInstance method obtainData.
@Override
public void obtainData(LogicalData ld, DataLocation source, DataLocation target, LogicalData tgtData, Transferable reason, EventListener listener) {
// Delegate on the master to obtain the data value
String path = target.getProtocol().getSchema() + target.getPath();
DataLocation tgtLoc = null;
try {
SimpleURI uri = new SimpleURI(path);
tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
}
COMPSsNode node = Comm.getAppHost().getNode();
node.obtainData(ld, source, tgtLoc, tgtData, reason, listener);
}
Aggregations