use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class ScoresTest method testResourceScores.
@SuppressWarnings("unchecked")
@Test
public void testResourceScores() throws BlockedActionException, UnassignedActionException, Exception {
drs1.clear();
FakeAllocatableAction action1 = new FakeAllocatableAction(fao, 1, 0, CoreManager.getCoreImplementations(0));
DataInstanceId d1v1 = new DataInstanceId(1, 1);
Comm.registerData(d1v1.getRenaming());
DataInstanceId d2v2 = new DataInstanceId(2, 2);
Comm.registerData(d2v2.getRenaming());
DependencyParameter dpD1V1 = new DependencyParameter(DataType.FILE_T, Direction.IN, Stream.UNSPECIFIED, Constants.PREFIX_EMTPY);
dpD1V1.setDataAccessId(new RAccessId(1, 1));
DependencyParameter dpD2V2 = new DependencyParameter(DataType.FILE_T, Direction.IN, Stream.UNSPECIFIED, Constants.PREFIX_EMTPY);
dpD2V2.setDataAccessId(new RAccessId(2, 2));
TaskDescription params = new TaskDescription("task", false, Constants.SINGLE_NODE, false, false, false, false, new Parameter[] { dpD1V1, dpD2V2 });
FullGraphScore<FakeProfile, FakeResourceDescription, FakeImplementation> actionScore = (FullGraphScore<FakeProfile, FakeResourceDescription, FakeImplementation>) ds.generateActionScore(action1);
FullGraphScore<FakeProfile, FakeResourceDescription, FakeImplementation> score1 = (FullGraphScore<FakeProfile, FakeResourceDescription, FakeImplementation>) drs1.generateResourceScore(action1, params, actionScore);
Verifiers.verifyScore(score1, 0, 2 * FullGraphResourceScheduler.DATA_TRANSFER_DELAY, 0, 0, 2 * FullGraphResourceScheduler.DATA_TRANSFER_DELAY);
Comm.registerLocation(d1v1.getRenaming(), DataLocation.createLocation(drs1.getResource(), new SimpleURI("/home/test/a")));
score1 = (FullGraphScore<FakeProfile, FakeResourceDescription, FakeImplementation>) drs1.generateResourceScore(action1, params, actionScore);
Verifiers.verifyScore(score1, 0, 1 * FullGraphResourceScheduler.DATA_TRANSFER_DELAY, 0, 0, 1 * FullGraphResourceScheduler.DATA_TRANSFER_DELAY);
Comm.registerLocation(d2v2.getRenaming(), DataLocation.createLocation(drs1.getResource(), new SimpleURI("/home/test/b")));
score1 = (FullGraphScore<FakeProfile, FakeResourceDescription, FakeImplementation>) drs1.generateResourceScore(action1, params, actionScore);
Verifiers.verifyScore(score1, 0, 0 * FullGraphResourceScheduler.DATA_TRANSFER_DELAY, 0, 0, 0 * FullGraphResourceScheduler.DATA_TRANSFER_DELAY);
Comm.removeData(d1v1.getRenaming());
Comm.removeData(d2v2.getRenaming());
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class Comm method registerValue.
/**
* Registers a new value @value for the data with id @dataId dataId must exist
*
* @param dataId
* @param value
* @return
*/
public static synchronized LogicalData registerValue(String dataId, Object value) {
LOGGER.debug("Register value " + value + " for data " + dataId);
String targetPath = Protocol.OBJECT_URI.getSchema() + dataId;
DataLocation location = null;
try {
SimpleURI uri = new SimpleURI(targetPath);
location = DataLocation.createLocation(appHost, uri);
} catch (IOException e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, e);
}
LogicalData logicalData = data.get(dataId);
logicalData.addLocation(location);
logicalData.setValue(value);
// Register PSCO Location if needed it's PSCO and it's persisted
if (value instanceof StubItf) {
String id = ((StubItf) value).getID();
if (id != null) {
Comm.registerPSCO(dataId, id);
}
}
return logicalData;
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class Comm method registerPSCO.
/**
* Registers a new PSCO id @id for the data with id @dataId dataId must exist
*
* @param dataId
* @param id
* @return
*/
public static synchronized LogicalData registerPSCO(String dataId, String id) {
String targetPath = Protocol.PERSISTENT_URI.getSchema() + id;
DataLocation location = null;
try {
SimpleURI uri = new SimpleURI(targetPath);
location = DataLocation.createLocation(appHost, uri);
} catch (IOException ioe) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + targetPath, ioe);
}
LogicalData logicalData = data.get(dataId);
logicalData.addLocation(location);
return logicalData;
}
use of es.bsc.compss.types.uri.SimpleURI in project compss by bsc-wdc.
the class COMPSsRuntimeImpl method createLocation.
private DataLocation createLocation(String fileName) throws IOException {
// Check if fileName contains schema
SimpleURI uri = new SimpleURI(fileName);
if (uri.getSchema().isEmpty()) {
// Add default File scheme and wrap local paths
String canonicalPath = new File(fileName).getCanonicalPath();
uri = new SimpleURI(Protocol.FILE_URI.getSchema() + canonicalPath);
}
// Check host
Resource host = Comm.getAppHost();
String hostName = uri.getHost();
if (hostName != null && !hostName.isEmpty()) {
host = Resource.getResource(hostName);
if (host == null) {
ErrorManager.error("Host " + hostName + " not found when creating data location.");
}
}
// Create location
return DataLocation.createLocation(host, uri);
}
use of es.bsc.compss.types.uri.SimpleURI 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));
}
}
Aggregations