Search in sources :

Example 1 with DataAccessId

use of es.bsc.compss.types.data.DataAccessId in project compss by bsc-wdc.

the class NIOJob method addParams.

private LinkedList<NIOParam> addParams() {
    LinkedList<NIOParam> params = new LinkedList<>();
    for (Parameter param : taskParams.getParameters()) {
        DataType type = param.getType();
        NIOParam np;
        switch(type) {
            case FILE_T:
            case OBJECT_T:
            case PSCO_T:
            case EXTERNAL_OBJECT_T:
                DependencyParameter dPar = (DependencyParameter) param;
                DataAccessId dAccId = dPar.getDataAccessId();
                Object value = dPar.getDataTarget();
                boolean preserveSourceData = true;
                if (dAccId instanceof RAccessId) {
                    // Parameter is a R, has sources
                    preserveSourceData = ((RAccessId) dAccId).isPreserveSourceData();
                } else if (dAccId instanceof RWAccessId) {
                    // Parameter is a RW, has sources
                    preserveSourceData = ((RWAccessId) dAccId).isPreserveSourceData();
                } else {
                    // Parameter is a W, it has no sources
                    preserveSourceData = false;
                }
                // Workaround for Python PSCOs in return
                // Check if the parameter has a valid PSCO and change its type
                String renaming;
                DataAccessId faId = dPar.getDataAccessId();
                if (faId instanceof WAccessId) {
                    // Write mode
                    WAccessId waId = (WAccessId) faId;
                    renaming = waId.getWrittenDataInstance().getRenaming();
                } else if (faId instanceof RWAccessId) {
                    // Read write mode
                    RWAccessId rwaId = (RWAccessId) faId;
                    renaming = rwaId.getWrittenDataInstance().getRenaming();
                } else {
                    // Read only mode
                    RAccessId raId = (RAccessId) faId;
                    renaming = raId.getReadDataInstance().getRenaming();
                }
                String pscoId = Comm.getData(renaming).getId();
                if (pscoId != null && type.equals(DataType.FILE_T)) {
                    param.setType(DataType.EXTERNAL_OBJECT_T);
                    type = param.getType();
                }
                // Create the NIO Param
                // Only store W and RW
                boolean writeFinalValue = !(dAccId instanceof RAccessId);
                np = new NIOParam(type, param.getStream(), param.getPrefix(), preserveSourceData, writeFinalValue, value, (Data) dPar.getDataSource(), dPar.getOriginalName());
                break;
            default:
                BasicTypeParameter btParB = (BasicTypeParameter) param;
                value = btParB.getValue();
                // Basic parameters are not preserved on Worker
                preserveSourceData = false;
                // Basic parameters are not stored on Worker
                writeFinalValue = false;
                np = new NIOParam(type, param.getStream(), param.getPrefix(), preserveSourceData, writeFinalValue, value, null, DependencyParameter.NO_NAME);
                break;
        }
        params.add(np);
    }
    return params;
}
Also used : RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) Data(es.bsc.compss.nio.commands.Data) LinkedList(java.util.LinkedList) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType) WAccessId(es.bsc.compss.types.data.DataAccessId.WAccessId) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) DataAccessId(es.bsc.compss.types.data.DataAccessId) NIOParam(es.bsc.compss.nio.NIOParam)

Example 2 with DataAccessId

use of es.bsc.compss.types.data.DataAccessId in project compss by bsc-wdc.

the class TaskAnalyser method endTask.

/**
 * Registers the end of execution of task @task
 *
 * @param task
 */
public void endTask(Task task) {
    int taskId = task.getId();
    boolean isFree = task.isFree();
    TaskState taskState = task.getStatus();
    LOGGER.info("Notification received for task " + taskId + " with end status " + taskState);
    // Check status
    if (!isFree) {
        LOGGER.debug("Task " + taskId + " is not registered as free. Waiting for other executions to end");
        return;
    }
    if (taskState == TaskState.FAILED) {
        ErrorManager.error(TASK_FAILED + task);
        return;
    }
    /*
         * Treat end of task
         */
    LOGGER.debug("Ending task " + taskId);
    // Free dependencies
    Long appId = task.getAppId();
    Integer taskCount = appIdToTaskCount.get(appId) - 1;
    appIdToTaskCount.put(appId, taskCount);
    if (taskCount == 0) {
        // Remove the appId from the barrier flags (if existant, otherwise do nothing)
        appIdBarrierFlags.remove(appId);
        Semaphore sem = appIdToSemaphore.remove(appId);
        if (sem != null) {
            // App was synchornized on a barrier flag or a no more tasks
            // Release the application semaphore
            appIdToTaskCount.remove(appId);
            sem.release();
        }
    }
    // Check if task is being waited
    List<Semaphore> sems = waitedTasks.remove(task);
    if (sems != null) {
        for (Semaphore sem : sems) {
            sem.release();
        }
    }
    for (Parameter param : task.getTaskDescription().getParameters()) {
        DataType type = param.getType();
        if (type == DataType.FILE_T || type == DataType.OBJECT_T || type == DataType.PSCO_T || type == DataType.EXTERNAL_OBJECT_T) {
            DependencyParameter dPar = (DependencyParameter) param;
            DataAccessId dAccId = dPar.getDataAccessId();
            LOGGER.debug("Treating that data " + dAccId + " has been accessed at " + dPar.getDataTarget());
            DIP.dataHasBeenAccessed(dAccId);
        }
    }
    // Task generation is finished if we are on noMoreTasks but we are not on a barrier
    if (appIdToSemaphore.get(appId) != null && !appIdBarrierFlags.contains(appId)) {
        checkResultFileTransfer(task);
    }
    // Release data dependent tasks
    task.releaseDataDependents();
}
Also used : ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) Semaphore(java.util.concurrent.Semaphore) TaskState(es.bsc.compss.types.Task.TaskState) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 3 with DataAccessId

use of es.bsc.compss.types.data.DataAccessId in project compss by bsc-wdc.

the class TaskAnalyser method processTask.

/**
 * Process the dependencies of a new task @currentTask
 *
 * @param currentTask
 */
public void processTask(Task currentTask) {
    TaskDescription params = currentTask.getTaskDescription();
    LOGGER.info("New " + (params.getType() == TaskType.METHOD ? "method" : "service") + " task(" + params.getName() + "), ID = " + currentTask.getId());
    if (drawGraph) {
        addNewTask(currentTask);
    }
    // Update task count
    Integer methodId = params.getId();
    Integer actualCount = currentTaskCount.get(methodId);
    if (actualCount == null) {
        actualCount = 0;
    }
    currentTaskCount.put(methodId, actualCount + 1);
    // Update app id task count
    Long appId = currentTask.getAppId();
    Integer taskCount = appIdToTaskCount.get(appId);
    if (taskCount == null) {
        taskCount = 0;
    }
    taskCount++;
    appIdToTaskCount.put(appId, taskCount);
    Integer totalTaskCount = appIdToTotalTaskCount.get(appId);
    if (totalTaskCount == null) {
        totalTaskCount = 0;
    }
    totalTaskCount++;
    appIdToTotalTaskCount.put(appId, totalTaskCount);
    // Check scheduling enforcing data
    int constrainingParam = -1;
    if (params.getType() == TaskType.SERVICE && params.hasTargetObject()) {
        if (params.hasReturnValue()) {
            constrainingParam = params.getParameters().length - 2;
        } else {
            constrainingParam = params.getParameters().length - 1;
        }
    }
    Parameter[] parameters = params.getParameters();
    for (int paramIdx = 0; paramIdx < parameters.length; paramIdx++) {
        Parameter p = parameters[paramIdx];
        if (DEBUG) {
            LOGGER.debug("* Parameter : " + p);
        }
        // Conversion: direction -> access mode
        AccessMode am = AccessMode.R;
        switch(p.getDirection()) {
            case IN:
                am = AccessMode.R;
                break;
            case OUT:
                am = AccessMode.W;
                break;
            case INOUT:
                am = AccessMode.RW;
                break;
        }
        // Inform the Data Manager about the new accesses
        DataAccessId daId;
        switch(p.getType()) {
            case FILE_T:
                FileParameter fp = (FileParameter) p;
                daId = DIP.registerFileAccess(am, fp.getLocation());
                break;
            case PSCO_T:
                ObjectParameter pscop = (ObjectParameter) p;
                // Check if its PSCO class and persisted to infer its type
                pscop.setType(DataType.PSCO_T);
                daId = DIP.registerObjectAccess(am, pscop.getValue(), pscop.getCode());
                break;
            case EXTERNAL_OBJECT_T:
                ExternalObjectParameter externalPSCOparam = (ExternalObjectParameter) p;
                // Check if its PSCO class and persisted to infer its type
                externalPSCOparam.setType(DataType.EXTERNAL_OBJECT_T);
                daId = DIP.registerExternalObjectAccess(am, externalPSCOparam.getId(), externalPSCOparam.getCode());
                break;
            case OBJECT_T:
                ObjectParameter op = (ObjectParameter) p;
                // Check if its PSCO class and persisted to infer its type
                if (op.getValue() instanceof StubItf && ((StubItf) op.getValue()).getID() != null) {
                    op.setType(DataType.PSCO_T);
                }
                daId = DIP.registerObjectAccess(am, op.getValue(), op.getCode());
                break;
            default:
                /*
                     * Basic types (including String). The only possible access mode is R (already checked by the API)
                     */
                continue;
        }
        // Add dependencies to the graph and register output values for future dependencies
        DependencyParameter dp = (DependencyParameter) p;
        dp.setDataAccessId(daId);
        switch(am) {
            case R:
                checkDependencyForRead(currentTask, dp);
                if (paramIdx == constrainingParam) {
                    DataAccessId.RAccessId raId = (DataAccessId.RAccessId) dp.getDataAccessId();
                    DataInstanceId dependingDataId = raId.getReadDataInstance();
                    if (dependingDataId != null) {
                        if (dependingDataId.getVersionId() > 1) {
                            currentTask.setEnforcingTask(writers.get(dependingDataId.getDataId()));
                        }
                    }
                }
                break;
            case RW:
                checkDependencyForRead(currentTask, dp);
                if (paramIdx == constrainingParam) {
                    DataAccessId.RWAccessId raId = (DataAccessId.RWAccessId) dp.getDataAccessId();
                    DataInstanceId dependingDataId = raId.getReadDataInstance();
                    if (dependingDataId != null) {
                        if (dependingDataId.getVersionId() > 1) {
                            currentTask.setEnforcingTask(writers.get(dependingDataId.getDataId()));
                        }
                    }
                }
                registerOutputValues(currentTask, dp);
                break;
            case W:
                registerOutputValues(currentTask, dp);
                break;
        }
    }
}
Also used : DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) DataInstanceId(es.bsc.compss.types.data.DataInstanceId) TaskDescription(es.bsc.compss.types.TaskDescription) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) StubItf(storage.StubItf) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 4 with DataAccessId

use of es.bsc.compss.types.data.DataAccessId in project compss by bsc-wdc.

the class DataInfoProvider method willAccess.

private DataAccessId willAccess(AccessMode mode, DataInfo di) {
    // Version management
    DataAccessId daId = null;
    switch(mode) {
        case R:
            di.willBeRead();
            daId = new RAccessId(di.getCurrentDataVersion());
            if (DEBUG) {
                StringBuilder sb = new StringBuilder("");
                sb.append("Access:").append("\n");
                sb.append("  * Type: R").append("\n");
                sb.append("  * Read Datum: d").append(daId.getDataId()).append("v").append(((RAccessId) daId).getRVersionId()).append("\n");
                LOGGER.debug(sb.toString());
            }
            break;
        case W:
            di.willBeWritten();
            daId = new WAccessId(di.getCurrentDataVersion());
            if (DEBUG) {
                StringBuilder sb = new StringBuilder("");
                sb.append("Access:").append("\n");
                sb.append("  * Type: W").append("\n");
                sb.append("  * Write Datum: d").append(daId.getDataId()).append("v").append(((WAccessId) daId).getWVersionId()).append("\n");
                LOGGER.debug(sb.toString());
            }
            break;
        case RW:
            di.willBeRead();
            DataVersion readInstance = di.getCurrentDataVersion();
            di.willBeWritten();
            DataVersion writtenInstance = di.getCurrentDataVersion();
            daId = new RWAccessId(readInstance, writtenInstance);
            if (DEBUG) {
                StringBuilder sb = new StringBuilder("");
                sb.append("Access:").append("\n");
                sb.append("  * Type: RW").append("\n");
                sb.append("  * Read Datum: d").append(daId.getDataId()).append("v").append(((RWAccessId) daId).getRVersionId()).append("\n");
                sb.append("  * Write Datum: d").append(daId.getDataId()).append("v").append(((RWAccessId) daId).getWVersionId()).append("\n");
                LOGGER.debug(sb.toString());
            }
            break;
    }
    return daId;
}
Also used : DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 5 with DataAccessId

use of es.bsc.compss.types.data.DataAccessId in project compss by bsc-wdc.

the class DataInfoProvider method finishFileAccess.

public void finishFileAccess(AccessMode mode, DataLocation location) {
    DataInfo fileInfo;
    String locationKey = location.getLocationKey();
    Integer fileId = nameToId.get(locationKey);
    // First access to this file
    if (fileId == null) {
        LOGGER.warn("File " + location.getLocationKey() + " has not been accessed before");
        return;
    }
    fileInfo = idToData.get(fileId);
    DataAccessId daid = getAccess(mode, fileInfo);
    if (daid == null) {
        LOGGER.warn("File " + location.getLocationKey() + " has not been accessed before");
        return;
    }
    dataHasBeenAccessed(daid);
}
Also used : DataAccessId(es.bsc.compss.types.data.DataAccessId)

Aggregations

DataAccessId (es.bsc.compss.types.data.DataAccessId)14 RWAccessId (es.bsc.compss.types.data.DataAccessId.RWAccessId)5 DependencyParameter (es.bsc.compss.types.parameter.DependencyParameter)5 Parameter (es.bsc.compss.types.parameter.Parameter)5 DataType (es.bsc.compss.types.annotations.parameter.DataType)4 RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)4 DataInstanceId (es.bsc.compss.types.data.DataInstanceId)4 BasicTypeParameter (es.bsc.compss.types.parameter.BasicTypeParameter)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 DataLocation (es.bsc.compss.types.data.location.DataLocation)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 SimpleURI (es.bsc.compss.types.uri.SimpleURI)2 Semaphore (java.util.concurrent.Semaphore)2 File (org.gridlab.gat.io.File)2 CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)1