Search in sources :

Example 6 with Task

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

the class SchedulingTaskComparator method computeHashForSelectionScripts.

private void computeHashForSelectionScripts(InternalTask task, InternalJob job) {
    List<SelectionScript> scriptList = SchedulingMethodImpl.resolveScriptVariables(task.getSelectionScripts(), task.getRuntimeVariables());
    for (SelectionScript script : scriptList) {
        SelectionScript modifiedScript = script;
        try {
            Map<String, Serializable> bindings = SchedulingMethodImpl.createBindingsForSelectionScripts(job, task);
            modifiedScript = SchedulingMethodImpl.replaceBindingsInsideScript(script, bindings);
        } catch (Exception e) {
            logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
        }
        try {
            digests.add(new String(modifiedScript.digest()));
        } catch (Exception e) {
            logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
        }
    }
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) Serializable(java.io.Serializable)

Example 7 with Task

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

the class TerminationData method terminateRunningTask.

private void terminateRunningTask(SchedulingService service, TaskTerminationData taskToTerminate, RunningTaskData taskData) {
    Map<String, String> genericInformation = new HashMap<>();
    VariablesMap variables = null;
    if (taskToTerminate.internalJob != null) {
        genericInformation = taskData.getTask().getRuntimeGenericInformation();
    }
    try {
        variables = getStringSerializableMap(service, taskToTerminate);
    } catch (Exception e) {
        logger.error("Exception occurred, fail to get variables into the cleaning script: ", e);
    }
    try {
        if (taskToTerminate.terminationStatus == ABORTED) {
            taskData.getLauncher().kill();
        }
    } catch (Throwable t) {
        logger.info("Cannot terminate task launcher for task '" + taskData.getTask().getId() + "'", t);
        try {
            logger.info("Task launcher that cannot be terminated is identified by " + taskData.getLauncher().toString());
        } catch (Throwable ignore) {
            logger.info("Getting information about Task launcher failed (remote object not accessible?)");
        }
    }
    try {
        logger.debug("Releasing nodes for task '" + taskData.getTask().getId() + "'");
        RMProxiesManager proxiesManager = service.getInfrastructure().getRMProxiesManager();
        proxiesManager.getUserRMProxy(taskData.getUser(), taskData.getCredentials()).releaseNodes(taskData.getNodes(), taskToTerminate.terminationStatus != NODEFAILED ? taskData.getTask().getCleaningScript() : null, variables, genericInformation, taskToTerminate.taskData.getTask().getId(), service.addThirdPartyCredentials(taskData.getCredentials()));
    } catch (Throwable t) {
        logger.info("Failed to release nodes for task '" + taskData.getTask().getId() + "'", t);
    }
}
Also used : HashMap(java.util.HashMap) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) IOException(java.io.IOException) RMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.RMProxiesManager)

Example 8 with Task

use of org.ow2.proactive.scheduler.common.task.Task 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 9 with Task

use of org.ow2.proactive.scheduler.common.task.Task 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 10 with Task

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

the class SchedulerStateRecoverHelper method runningTaskMustBeResetToPending.

private boolean runningTaskMustBeResetToPending(InternalTask task, RMProxy rmProxy) {
    boolean resetToPending;
    if (rmProxy != null) {
        NodeSet nodes = task.getExecuterInformation().getNodes();
        boolean taskNodesKnownByRM = rmProxy.areNodesKnown(nodes);
        if (taskNodesKnownByRM) {
            TaskLauncher launcher = task.getExecuterInformation().getLauncher();
            logger.debug("Checking whether task launcher has called its doTask method: " + launcher.isTaskStarted());
            if (launcher.isTaskStarted()) {
                logger.info("Recover running task " + task.getId() + " (" + task.getName() + ") successfully with task launcher " + launcher);
                resetToPending = false;
            } else {
                logger.info(FAIL_TO_RECOVER_RUNNING_TASK_STRING + task.getId() + " (" + task.getName() + ") because its task launcher has not started to execute the task");
                resetToPending = true;
            }
        } else {
            logger.info(FAIL_TO_RECOVER_RUNNING_TASK_STRING + task.getId() + " (" + task.getName() + ") because the task's node is not known by the resource manager");
            resetToPending = true;
        }
    } else {
        logger.info(FAIL_TO_RECOVER_RUNNING_TASK_STRING + task.getId() + " (" + task.getName() + ") because the resource manager is not reachable");
        resetToPending = true;
    }
    return resetToPending;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher)

Aggregations

Test (org.junit.Test)152 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)112 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)100 JobId (org.ow2.proactive.scheduler.common.job.JobId)73 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)69 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)68 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)60 ArrayList (java.util.ArrayList)49 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)48 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)43 Task (org.ow2.proactive.scheduler.common.task.Task)41 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)41 File (java.io.File)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)34 HashMap (java.util.HashMap)33 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)33 SimpleScript (org.ow2.proactive.scripting.SimpleScript)33 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)27 TaskScript (org.ow2.proactive.scripting.TaskScript)27 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)26