Search in sources :

Example 6 with DataInstanceId

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;
}
Also used : Resource(es.bsc.compss.types.resources.Resource) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) DataInstanceId(es.bsc.compss.types.data.DataInstanceId) LogicalData(es.bsc.compss.types.data.LogicalData) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) Parameter(es.bsc.compss.types.parameter.Parameter) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 7 with DataInstanceId

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;
}
Also used : DataInstanceId(es.bsc.compss.types.data.DataInstanceId) RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) WAccessId(es.bsc.compss.types.data.DataAccessId.WAccessId) DataAccessId(es.bsc.compss.types.data.DataAccessId) ShutdownException(es.bsc.compss.types.request.exceptions.ShutdownException) CannotLoadException(es.bsc.compss.exceptions.CannotLoadException)

Example 8 with DataInstanceId

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;
}
Also used : DataInstanceId(es.bsc.compss.types.data.DataInstanceId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) FileAccessParams(es.bsc.compss.types.data.AccessParams.FileAccessParams) AccessParams(es.bsc.compss.types.data.AccessParams) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 9 with DataInstanceId

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;
}
Also used : DataInstanceId(es.bsc.compss.types.data.DataInstanceId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) FileAccessParams(es.bsc.compss.types.data.AccessParams.FileAccessParams) AccessParams(es.bsc.compss.types.data.AccessParams) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 10 with DataInstanceId

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);
            }
        }
    }
}
Also used : DataInstanceId(es.bsc.compss.types.data.DataInstanceId) SimpleURI(es.bsc.compss.types.uri.SimpleURI) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) DataLocation(es.bsc.compss.types.data.location.DataLocation) DataAccessId(es.bsc.compss.types.data.DataAccessId) BlockedActionException(es.bsc.compss.scheduler.exceptions.BlockedActionException) UnassignedActionException(es.bsc.compss.scheduler.exceptions.UnassignedActionException) FailedActionException(es.bsc.compss.scheduler.exceptions.FailedActionException)

Aggregations

DataInstanceId (es.bsc.compss.types.data.DataInstanceId)10 DataAccessId (es.bsc.compss.types.data.DataAccessId)6 RWAccessId (es.bsc.compss.types.data.DataAccessId.RWAccessId)6 DependencyParameter (es.bsc.compss.types.parameter.DependencyParameter)5 Parameter (es.bsc.compss.types.parameter.Parameter)4 SimpleURI (es.bsc.compss.types.uri.SimpleURI)4 RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)3 DataLocation (es.bsc.compss.types.data.location.DataLocation)3 TaskDescription (es.bsc.compss.types.TaskDescription)2 AccessParams (es.bsc.compss.types.data.AccessParams)2 FileAccessParams (es.bsc.compss.types.data.AccessParams.FileAccessParams)2 WAccessId (es.bsc.compss.types.data.DataAccessId.WAccessId)2 ExternalObjectParameter (es.bsc.compss.types.parameter.ExternalObjectParameter)2 FileParameter (es.bsc.compss.types.parameter.FileParameter)2 ObjectParameter (es.bsc.compss.types.parameter.ObjectParameter)2 CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)1 BlockedActionException (es.bsc.compss.scheduler.exceptions.BlockedActionException)1 FailedActionException (es.bsc.compss.scheduler.exceptions.FailedActionException)1 UnassignedActionException (es.bsc.compss.scheduler.exceptions.UnassignedActionException)1 LogicalData (es.bsc.compss.types.data.LogicalData)1