Search in sources :

Example 1 with DBTaskId

use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.

the class SchedulerDBManager method saveSingleTaskDependencies.

private void saveSingleTaskDependencies(Session session, InternalTask task, TaskData taskRuntimeData) {
    if (task.hasDependences()) {
        List<DBTaskId> dependencies = new ArrayList<>(task.getDependences().size());
        for (Task dependency : task.getDependences()) {
            dependencies.add(taskId((InternalTask) dependency));
        }
        taskRuntimeData.setDependentTasks(dependencies);
    } else {
        taskRuntimeData.setDependentTasks(Collections.<DBTaskId>emptyList());
    }
    if (task.getIfBranch() != null) {
        InternalTask ifBranch = task.getIfBranch();
        taskRuntimeData.setIfBranch(getTaskReference(session, ifBranch));
    } else {
        taskRuntimeData.setIfBranch(null);
    }
    if (task.getJoinedBranches() != null && !task.getJoinedBranches().isEmpty()) {
        List<DBTaskId> joinedBranches = new ArrayList<>(task.getJoinedBranches().size());
        for (InternalTask joinedBranch : task.getJoinedBranches()) {
            joinedBranches.add(taskId(joinedBranch));
        }
        taskRuntimeData.setJoinedBranches(joinedBranches);
    } else {
        taskRuntimeData.setJoinedBranches(Collections.<DBTaskId>emptyList());
    }
}
Also used : DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) Task(org.ow2.proactive.scheduler.common.task.Task) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList)

Example 2 with DBTaskId

use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.

the class SchedulerDBManager method toInternalTasks.

private Collection<InternalTask> toInternalTasks(boolean loadFullState, InternalJob internalJob, List<TaskData> taskRuntimeDataList) {
    Map<DBTaskId, InternalTask> tasks = new HashMap<>(taskRuntimeDataList.size());
    try {
        for (TaskData taskData : taskRuntimeDataList) {
            InternalTask internalTask = taskData.toInternalTask(internalJob, loadFullState);
            if (loadFullState) {
                internalTask.setParallelEnvironment(taskData.getParallelEnvironment());
                internalTask.setGenericInformation(taskData.getGenericInformation());
                for (SelectionScriptData scriptData : taskData.getSelectionScripts()) {
                    internalTask.addSelectionScript(scriptData.createSelectionScript());
                }
                if (taskData.getCleanScript() != null) {
                    internalTask.setCleaningScript(taskData.getCleanScript().createSimpleScript());
                }
                if (taskData.getPreScript() != null) {
                    internalTask.setPreScript(taskData.getPreScript().createSimpleScript());
                }
                if (taskData.getPostScript() != null) {
                    internalTask.setPostScript(taskData.getPostScript().createSimpleScript());
                }
                if (taskData.getFlowScript() != null) {
                    internalTask.setFlowScript(taskData.getFlowScript().createFlowScript());
                }
                for (SelectorData selectorData : taskData.getDataspaceSelectors()) {
                    if (selectorData.isInput()) {
                        InputSelector selector = selectorData.createInputSelector();
                        internalTask.addInputFiles(selector.getInputFiles(), selector.getMode());
                    } else {
                        OutputSelector selector = selectorData.createOutputSelector();
                        internalTask.addOutputFiles(selector.getOutputFiles(), selector.getMode());
                    }
                }
            }
            tasks.put(taskData.getId(), internalTask);
        }
    } catch (InvalidScriptException e) {
        throw new DatabaseManagerException("Failed to initialize loaded script", e);
    }
    for (TaskData taskData : taskRuntimeDataList) {
        InternalTask internalTask = tasks.get(taskData.getId());
        if (!taskData.getDependentTasks().isEmpty()) {
            for (DBTaskId dependent : taskData.getDependentTasks()) {
                internalTask.addDependence(tasks.get(dependent));
            }
        }
        if (loadFullState) {
            if (taskData.getIfBranch() != null) {
                internalTask.setIfBranch(tasks.get(taskData.getIfBranch().getId()));
            }
            if (!taskData.getJoinedBranches().isEmpty()) {
                List<InternalTask> branches = new ArrayList<>(taskData.getJoinedBranches().size());
                for (DBTaskId joinedBranch : taskData.getJoinedBranches()) {
                    branches.add(tasks.get(joinedBranch));
                }
                internalTask.setJoinedBranches(branches);
            }
            internalTask.setName(internalTask.getName());
        }
    }
    return tasks.values();
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) ArrayList(java.util.ArrayList) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)

Example 3 with DBTaskId

use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.

the class SchedulerDBManager method loadTaskResult.

@SuppressWarnings("unchecked")
private TaskResult loadTaskResult(Session session, TaskId taskId, int resultIndex) {
    DBTaskId dbTaskId = taskId(taskId);
    TaskData task = session.load(TaskData.class, dbTaskId);
    Query query = session.getNamedQuery("loadTasksResultByTask").setParameter("task", task);
    query.setMaxResults(1);
    query.setFirstResult(resultIndex);
    List<TaskResultData> results = (List<TaskResultData>) query.list();
    if (results.isEmpty()) {
        return null;
    } else {
        return results.get(0).toTaskResult(taskId);
    }
}
Also used : DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) Query(org.hibernate.Query) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with DBTaskId

use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.

the class SchedulerDBManager method loadJobResult.

@SuppressWarnings("unchecked")
private JobResultImpl loadJobResult(Session session, Query query, JobData job, JobId jobId) {
    JobResultImpl jobResult = new JobResultImpl();
    jobResult.setJobInfo(job.createJobInfo(jobId));
    DBTaskId currentTaskId = null;
    List<Object[]> resultList = (List<Object[]>) query.list();
    if (resultList.isEmpty()) {
        return jobResult;
    }
    int counter = 0;
    for (Object[] result : resultList) {
        TaskResultData resultData = (TaskResultData) result[0];
        DBTaskId dbTaskId = (DBTaskId) result[1];
        String taskName = (String) result[2];
        Boolean preciousResult = (Boolean) result[3];
        boolean nextTask = !dbTaskId.equals(currentTaskId);
        if (nextTask) {
            TaskId taskId = TaskIdImpl.createTaskId(jobId, taskName, dbTaskId.getTaskId());
            jobResult.addTaskResult(taskName, resultData.toTaskResult(taskId), preciousResult);
            currentTaskId = dbTaskId;
        }
        if (++counter % 100 == 0) {
            session.clear();
        }
    }
    return jobResult;
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with DBTaskId

use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.

the class TaskData method createTaskData.

static TaskData createTaskData(JobData jobRuntimeData, InternalScriptTask task) {
    TaskData taskData = new TaskData();
    TaskData.DBTaskId taskId = new DBTaskId();
    taskId.setJobId(jobRuntimeData.getId());
    taskId.setTaskId(task.getTaskInfo().getTaskId().longValue());
    taskData.setId(taskId);
    taskData.setDescription(task.getDescription());
    taskData.setTag(task.getTag());
    taskData.setParallelEnvironment(task.getParallelEnvironment());
    taskData.setFlowBlock(task.getFlowBlock());
    taskData.setRestartMode(task.getRestartTaskOnError());
    taskData.setPreciousLogs(task.isPreciousLogs());
    taskData.setPreciousResult(task.isPreciousResult());
    taskData.setRunAsMe(task.isRunAsMe());
    taskData.setWallTime(task.getWallTime());
    taskData.setOnTaskErrorString(task.getOnTaskErrorProperty().getValue());
    taskData.setMaxNumberOfExecution(task.getMaxNumberOfExecution());
    taskData.setJobData(jobRuntimeData);
    taskData.setNumberOfExecutionOnFailureLeft(PASchedulerProperties.NUMBER_OF_EXECUTION_ON_FAILURE.getValueAsInt());
    taskData.setNumberOfExecutionLeft(task.getMaxNumberOfExecution());
    taskData.setGenericInformation(task.getGenericInformation());
    HashMap<String, TaskDataVariable> variables = new HashMap<>();
    for (Map.Entry<String, TaskVariable> entry : task.getVariables().entrySet()) {
        variables.put(entry.getKey(), TaskDataVariable.create(entry.getKey(), entry.getValue(), taskData));
    }
    taskData.setVariables(variables);
    // set the scheduledTime if the START_AT property exists
    Map<String, String> genericInfos = taskData.getGenericInformation();
    if (genericInfos != null && genericInfos.containsKey(CommonAttribute.GENERIC_INFO_START_AT_KEY)) {
        long scheduledTime = ISO8601DateUtil.toDate(genericInfos.get(CommonAttribute.GENERIC_INFO_START_AT_KEY)).getTime();
        taskData.setScheduledTime(scheduledTime);
        task.setScheduledTime(scheduledTime);
    }
    taskData.updateMutableAttributes(task);
    if (task.getSelectionScripts() != null) {
        List<SelectionScriptData> scripts = new ArrayList<>(task.getSelectionScripts().size());
        for (SelectionScript selectionScript : task.getSelectionScripts()) {
            scripts.add(SelectionScriptData.createForSelectionScript(selectionScript, taskData));
        }
        taskData.setSelectionScripts(scripts);
    }
    if (task.getExecutableContainer() != null) {
        taskData.setScript(ScriptData.createForScript(((ScriptExecutableContainer) task.getExecutableContainer()).getScript(), taskData));
    }
    if (task.getPreScript() != null) {
        taskData.setPreScript(ScriptData.createForScript(task.getPreScript(), taskData));
    }
    if (task.getPostScript() != null) {
        taskData.setPostScript(ScriptData.createForScript(task.getPostScript(), taskData));
    }
    if (task.getCleaningScript() != null) {
        taskData.setCleanScript(ScriptData.createForScript(task.getCleaningScript(), taskData));
    }
    if (task.getFlowScript() != null) {
        taskData.setFlowScript(ScriptData.createForFlowScript(task.getFlowScript(), taskData));
    }
    List<SelectorData> selectorsData = new ArrayList<>();
    if (task.getInputFilesList() != null) {
        for (InputSelector selector : task.getInputFilesList()) {
            selectorsData.add(SelectorData.createForInputSelector(selector, taskData));
        }
    }
    if (task.getOutputFilesList() != null) {
        for (OutputSelector selector : task.getOutputFilesList()) {
            selectorsData.add(SelectorData.createForOutputSelector(selector, taskData));
        }
    }
    taskData.setDataspaceSelectors(selectorsData);
    ForkEnvironment forkEnvironment = task.getForkEnvironment();
    if (forkEnvironment != null) {
        taskData.setAdditionalClasspath(forkEnvironment.getAdditionalClasspath());
        taskData.setJavaHome(forkEnvironment.getJavaHome());
        taskData.setJvmArguments(forkEnvironment.getJVMArguments());
        taskData.setWorkingDir(forkEnvironment.getWorkingDir());
        if (forkEnvironment.getEnvScript() != null) {
            taskData.setEnvScript(ScriptData.createForScript(forkEnvironment.getEnvScript(), taskData));
        }
        Map<String, String> systemEnvironment = forkEnvironment.getSystemEnvironment();
        if (systemEnvironment != null) {
            List<EnvironmentModifierData> envModifiers = new ArrayList<>(systemEnvironment.size());
            for (Map.Entry<String, String> entry : systemEnvironment.entrySet()) {
                envModifiers.add(EnvironmentModifierData.create(new PropertyModifier(entry.getKey(), entry.getValue()), taskData));
            }
            taskData.setEnvModifiers(envModifiers);
        }
    }
    taskData.initTaskType(task);
    return taskData;
}
Also used : PropertyModifier(org.ow2.proactive.scheduler.common.task.PropertyModifier) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) SelectionScript(org.ow2.proactive.scripting.SelectionScript) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector)

Aggregations

ArrayList (java.util.ArrayList)4 DBTaskId (org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)4 List (java.util.List)2 InputSelector (org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)2 OutputSelector (org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector)2 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)2 HashMap (java.util.HashMap)1 Query (org.hibernate.Query)1 DatabaseManagerException (org.ow2.proactive.db.DatabaseManagerException)1 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)1 PropertyModifier (org.ow2.proactive.scheduler.common.task.PropertyModifier)1 Task (org.ow2.proactive.scheduler.common.task.Task)1 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)1 TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)1 JobResultImpl (org.ow2.proactive.scheduler.job.JobResultImpl)1 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)1 InternalForkedScriptTask (org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask)1 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)1 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)1 SelectionScript (org.ow2.proactive.scripting.SelectionScript)1