Search in sources :

Example 31 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.

the class SchedulerFrontendState method getTaskState.

synchronized TaskState getTaskState(JobId jobId, TaskId taskId) throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
    checkPermissions("getJobState", getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_STATE_OF_THIS_TASK);
    if (jobsMap.get(jobId) == null) {
        throw new UnknownJobException(jobId);
    }
    JobState jobState = jobsMap.get(jobId);
    synchronized (jobState) {
        TaskState ts = jobState.getHMTasks().get(taskId);
        if (ts == null) {
            throw new UnknownTaskException(taskId, jobId);
        }
        return ts;
    }
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobState(org.ow2.proactive.scheduler.common.job.JobState) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 32 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.

the class TerminationData method getStringSerializableMap.

public VariablesMap getStringSerializableMap(SchedulingService service, TaskTerminationData taskToTerminate) throws Exception {
    VariablesMap variablesMap = new VariablesMap();
    RunningTaskData taskData = taskToTerminate.taskData;
    TaskResultImpl taskResult = taskToTerminate.taskResult;
    InternalJob internalJob = taskToTerminate.internalJob;
    if (taskToTerminate.terminationStatus == ABORTED || taskResult == null) {
        List<InternalTask> iDependences = taskData.getTask().getIDependences();
        if (iDependences != null) {
            Set<TaskId> parentIds = new HashSet<>(iDependences.size());
            for (InternalTask parentTask : iDependences) {
                parentIds.addAll(InternalTaskParentFinder.getInstance().getFirstNotSkippedParentTaskIds(parentTask));
            }
            // Batch fetching of parent tasks results
            Map<TaskId, TaskResult> taskResults = new HashMap<>();
            for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds), PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
                taskResults.putAll(service.getInfrastructure().getDBManager().loadTasksResults(taskData.getTask().getJobId(), parentsSubList));
            }
            getResultsFromListOfTaskResults(variablesMap.getInheritedMap(), taskResults);
        } else {
            if (internalJob != null) {
                for (Map.Entry<String, JobVariable> jobVariableEntry : internalJob.getVariables().entrySet()) {
                    variablesMap.getInheritedMap().put(jobVariableEntry.getKey(), jobVariableEntry.getValue().getValue());
                }
            }
        }
        variablesMap.getInheritedMap().put(SchedulerVars.PA_TASK_SUCCESS.toString(), Boolean.toString(false));
    } else if (taskResult.hadException()) {
        variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, false));
    } else {
        variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, true));
    }
    variablesMap.setScopeMap(getNonInheritedScopeVariables(variablesMap.getInheritedMap(), taskData.getTask().getScopeVariables(), taskData.getTask().getVariables()));
    return variablesMap;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) HashMap(java.util.HashMap) Map(java.util.Map) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) HashSet(java.util.HashSet)

Example 33 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.

the class TimedDoTaskAction method call.

/**
 * {@inheritDoc}
 */
public Void call() throws Exception {
    try {
        // Set to empty array to emulate varargs behavior (i.e. not defined is
        // equivalent to empty array, not null.
        TaskResult[] params = new TaskResult[0];
        // if job is TASKSFLOW, preparing the list of parameters for this task.
        int resultSize = taskDescriptor.getParents().size();
        if ((job.getType() == JobType.TASKSFLOW) && (resultSize > 0) && task.handleResultsArguments()) {
            Set<TaskId> parentIds = new HashSet<>(resultSize);
            for (int i = 0; i < resultSize; i++) {
                parentIds.addAll(internalTaskParentFinder.getFirstNotSkippedParentTaskIds(((EligibleTaskDescriptorImpl) taskDescriptor.getParents().get(i)).getInternal()));
            }
            params = new TaskResult[parentIds.size()];
            // If parentTaskResults is null after a system failure (a very rare case)
            if (task.getParentTasksResults() == null) {
                Map<TaskId, TaskResult> taskResults = new HashMap<>();
                // Batch fetching of parent tasks results
                for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds), PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
                    taskResults.putAll(schedulingService.getInfrastructure().getDBManager().loadTasksResults(job.getId(), parentsSubList));
                }
                // store the parent tasks results in InternalTask for future executions.
                task.setParentTasksResults(taskResults);
            }
            int i = 0;
            for (TaskId taskId : parentIds) {
                params[i] = task.getParentTasksResults().get(taskId);
                i++;
            }
        }
        // activate loggers for this task if needed
        schedulingService.getListenJobLogsSupport().activeLogsIfNeeded(job.getId(), launcher);
        fillContainer();
        // try launch the task
        launcher.doTask(task.getExecutableContainer(), params, terminateNotification, taskRecoveryData.getTerminateNotificationNodeURL(), taskRecoveryData.isTaskRecoverable());
    } catch (Throwable e) {
        logger.warn("Failed to start task: " + e.getMessage(), e);
        restartTask();
    }
    return null;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) HashMap(java.util.HashMap) EligibleTaskDescriptorImpl(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) HashSet(java.util.HashSet)

Example 34 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.

the class SchedulerDBManager method taskId.

private static TaskData.DBTaskId taskId(TaskId taskId) {
    TaskData.DBTaskId id = new TaskData.DBTaskId();
    id.setJobId(jobId(taskId.getJobId()));
    id.setTaskId(taskId.longValue());
    return id;
}
Also used : DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)

Example 35 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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)

Aggregations

TaskId (org.ow2.proactive.scheduler.common.task.TaskId)100 Test (org.junit.Test)43 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)43 JobId (org.ow2.proactive.scheduler.common.job.JobId)33 ArrayList (java.util.ArrayList)27 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)25 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)22 HashMap (java.util.HashMap)18 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)18 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)15 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)12 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)12 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)11 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)11 List (java.util.List)10 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9