Search in sources :

Example 26 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData 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 27 with TaskData

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

the class SchedulerDBManager method saveTaskDependencies.

private void saveTaskDependencies(Session session, List<InternalTask> tasks, List<TaskData> taskRuntimeDataList) {
    for (int i = 0; i < tasks.size(); i++) {
        InternalTask task = tasks.get(i);
        TaskData taskRuntimeData = taskRuntimeDataList.get(i);
        saveSingleTaskDependencies(session, task, taskRuntimeData);
    }
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 28 with TaskData

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

the class TaskDBUtils method getTotalNumberOfTasks.

public static SessionWork<Integer> getTotalNumberOfTasks(final DBTaskDataParameters params) {
    return new SessionWork<Integer>() {

        @Override
        public Integer doInTransaction(Session session) {
            Set<TaskStatus> taskStatuses = params.getStatuses();
            if (taskStatuses.isEmpty()) {
                return 0;
            }
            boolean hasUser = params.hasUser();
            boolean hasTag = params.hasTag();
            boolean hasDateFrom = params.hasDateFrom();
            boolean hasDateTo = params.hasDateTo();
            String queryPrefix = "select count(*) from TaskData T where ";
            Query query = getQuery(session, params, taskStatuses, hasUser, hasTag, hasDateFrom, hasDateTo, SortSpecifierContainer.EMPTY_CONTAINER, queryPrefix);
            Long count = (Long) query.uniqueResult();
            return count.intValue();
        }
    };
}
Also used : SessionWork(org.ow2.proactive.db.SessionWork) Query(org.hibernate.Query) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) Session(org.hibernate.Session)

Example 29 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData 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)

Example 30 with TaskData

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

the class TestTaskAttributes method testEmptyAttributes.

@Test
public void testEmptyAttributes() throws Exception {
    JavaTask javaTask = createDefaultTask("task1");
    InternalTask taskData = saveSingleTask(javaTask).getTask("task1");
    Assert.assertNotNull(taskData.getId());
    NativeTask nativeTask = new NativeTask();
    nativeTask.setName("task1");
    nativeTask.setCommandLine("commandline");
    taskData = saveSingleTask(nativeTask).getTask("task1");
    Assert.assertNotNull(taskData.getId());
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)20 Test (org.junit.Test)12 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)7 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)7 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)5 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)5 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)4 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)4 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)4 Query (org.hibernate.Query)3 DBTaskId (org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)3 List (java.util.List)2 TaskAbortedException (org.ow2.proactive.scheduler.common.exception.TaskAbortedException)2 TaskPreemptedException (org.ow2.proactive.scheduler.common.exception.TaskPreemptedException)2 TaskRestartedException (org.ow2.proactive.scheduler.common.exception.TaskRestartedException)2