Search in sources :

Example 16 with JobInfoImpl

use of org.ow2.proactive.scheduler.job.JobInfoImpl in project scheduling by ow2-proactive.

the class TerminateIfTaskHandler method terminateIfTask.

public boolean terminateIfTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, InternalTask descriptor, TaskId taskId) {
    InternalTask[] targets = searchIfElseJoinTasks(action, initiator);
    // the targetIf from action getTarget is the selected branch
    // the IF condition has already been evaluated prior to being put in a
    // FlowAction
    // the targetElse from action getTargetElse is the branch that was NOT
    // selected
    InternalTask targetIf = targets[0];
    InternalTask targetElse = targets[1];
    InternalTask targetJoin = targets[2];
    LOGGER.info("Control Flow Action IF: " + targetIf.getId() + " join: " + ((targetJoin == null) ? "null" : targetJoin.getId()));
    // these 2 tasks delimit the Task Block formed by the IF branch
    InternalTask branchStart = targetIf;
    InternalTask branchEnd = null;
    String match = targetIf.getMatchingBlock();
    if (match != null) {
        for (InternalTask t : internalJob.getIHMTasks().values()) {
            if (match.equals(t.getName()) && !(t.getStatus().equals(TaskStatus.FINISHED) || t.getStatus().equals(TaskStatus.SKIPPED))) {
                branchEnd = t;
            }
        }
    }
    // no matching block: there is no block, the branch is a single task
    if (branchEnd == null) {
        branchEnd = targetIf;
    }
    // plug the branch
    branchStart.addDependence(initiator);
    changesInfo.taskUpdated(branchStart);
    if (targetJoin != null) {
        targetJoin.addDependence(branchEnd);
        changesInfo.taskUpdated(targetJoin);
    }
    // the other branch will not be executed
    // first, find the concerned tasks
    List<InternalTask> elseTasks = new ArrayList<>();
    // elseTasks.add(targetElse);
    for (InternalTask t : internalJob.getIHMTasks().values()) {
        if (t.dependsOn(targetElse)) {
            elseTasks.add(t);
        }
    }
    // even though the targetElse is not going to be executed, a
    // dependency on initiator still makes sense and would help
    // reconstruct the job graph on the client
    targetElse.addDependence(initiator);
    changesInfo.taskUpdated(targetElse);
    for (InternalTask it : elseTasks) {
        it.setFinishedTime(descriptor.getFinishedTime() + 1);
        it.setStatus(TaskStatus.SKIPPED);
        it.setExecutionDuration(0);
        changesInfo.taskSkipped(it);
        internalJob.setNumberOfPendingTasks(internalJob.getNumberOfPendingTasks() - 1);
        internalJob.setNumberOfFinishedTasks(internalJob.getNumberOfFinishedTasks() + 1);
        LOGGER.info("Task " + it.getId() + " will not be executed");
    }
    // plug the branch in the descriptor
    TaskId joinId = null;
    if (targetJoin != null) {
        joinId = targetJoin.getId();
    }
    internalJob.getJobDescriptor().doIf(initiator.getId(), branchStart.getId(), branchEnd.getId(), joinId, targetElse.getId(), elseTasks);
    ((JobInfoImpl) internalJob.getJobInfo()).setTasksChanges(changesInfo, internalJob);
    // notify frontend that tasks were modified
    if (frontend != null) {
        frontend.jobStateUpdated(internalJob.getOwner(), new NotificationData<>(SchedulerEvent.TASK_SKIPPED, internalJob.getJobInfo()));
        frontend.jobUpdatedFullData(internalJob);
    }
    ((JobInfoImpl) internalJob.getJobInfo()).clearTasksChanges();
    // no jump is performed ; now that the tasks have been plugged
    // the flow can continue its normal operation
    internalJob.getJobDescriptor().terminate(taskId);
    return true;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Example 17 with JobInfoImpl

use of org.ow2.proactive.scheduler.job.JobInfoImpl in project scheduling by ow2-proactive.

the class JobRemoveHandler method call.

@Override
public Boolean call() {
    long start = 0;
    if (logger.isInfoEnabled()) {
        start = System.currentTimeMillis();
        logger.info("Removing job " + jobId);
    }
    SchedulerDBManager dbManager = service.getInfrastructure().getDBManager();
    List<InternalJob> jobs = dbManager.loadJobWithTasksIfNotRemoved(jobId);
    TerminationData terminationData;
    // if the context is not in sync with the database
    if (jobs.size() != 1) {
        terminationData = service.getJobs().removeJob(jobId);
    } else {
        // if the job was already finished we just remove it from the context
        if (isInFinishedState(jobs.get(0))) {
            terminationData = service.getJobs().removeJob(jobId);
        } else {
            terminationData = service.getJobs().killJob(jobId);
        }
    }
    service.submitTerminationDataHandler(terminationData);
    // if the job doesn't exist in the DB anymore we can stop here
    if (jobs.size() != 1) {
        return false;
    }
    jobs.get(0).setRemovedTime(System.currentTimeMillis());
    boolean removeFromDb = PASchedulerProperties.JOB_REMOVE_FROM_DB.getValueAsBoolean();
    dbManager.removeJob(jobId, jobs.get(0).getRemovedTime(), removeFromDb);
    ServerJobAndTaskLogs.remove(jobId);
    if (logger.isInfoEnabled()) {
        logger.info("Job " + jobId + " removed in " + (System.currentTimeMillis() - start) + "ms");
    }
    // send event to front-end
    service.getListener().jobStateUpdated(jobs.get(0).getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_REMOVE_FINISHED, new JobInfoImpl((JobInfoImpl) jobs.get(0).getJobInfo())));
    service.wakeUpSchedulingThread();
    return true;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Example 18 with JobInfoImpl

use of org.ow2.proactive.scheduler.job.JobInfoImpl in project scheduling by ow2-proactive.

the class LiveJobs method finishInErrorTask.

TerminationData finishInErrorTask(JobId jobId, String taskName) throws UnknownTaskException, UnknownJobException {
    JobData jobData = lockJob(jobId);
    if (jobData == null) {
        throw new UnknownJobException(jobId);
    }
    InternalJob job = jobData.job;
    try {
        InternalTask task = job.getTask(taskName);
        if (task == null) {
            throw new UnknownTaskException(taskName);
        }
        TaskId taskId = task.getId();
        if (task.getStatus() != TaskStatus.IN_ERROR) {
            tlogger.info(task.getId(), "Task must be in state IN_ERROR: " + task.getStatus());
            return emptyResult(task.getId());
        }
        TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, job, task);
        RunningTaskData data = new RunningTaskData(task, job.getOwner(), job.getCredentials(), task.getExecuterInformation().getLauncher());
        TerminationData terminationData = TerminationData.newTerminationData();
        terminationData.addTaskData(job, data, TerminationData.TerminationStatus.ABORTED, taskResult);
        tlogger.debug(taskId, "result added to job " + job.getId());
        // to be done before terminating the task, once terminated it is not
        // running anymore..
        ChangedTasksInfo changesInfo = job.finishInErrorTask(taskId, taskResult, listener);
        boolean jobFinished = job.isFinished();
        // update job info if it is terminated
        if (jobFinished) {
            // terminating job
            job.terminate();
            jlogger.debug(job.getId(), "terminated");
            jobs.remove(job.getId());
            terminationData.addJobToTerminate(job.getId());
        }
        // Update database
        if (taskResult.getAction() != null) {
            dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, taskResult);
        } else {
            dbManager.updateAfterTaskFinished(job, task, taskResult);
        }
        // send event
        listener.taskStateUpdated(job.getOwner(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_IN_ERROR_TO_FINISHED, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
        // if this job is finished (every task have finished)
        jlogger.info(job.getId(), "finished tasks " + job.getNumberOfFinishedTasks() + ", total tasks " + job.getTotalNumberOfTasks() + ", finished " + jobFinished);
        if (jobFinished) {
            // send event to client
            listener.jobStateUpdated(job.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
            listener.jobUpdatedFullData(job);
        }
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Example 19 with JobInfoImpl

use of org.ow2.proactive.scheduler.job.JobInfoImpl in project scheduling by ow2-proactive.

the class LiveJobs method terminateTask.

private void terminateTask(JobData jobData, InternalTask task, boolean errorOccurred, TaskResultImpl result, TerminationData terminationData) {
    InternalJob job = jobData.job;
    TaskId taskId = task.getId();
    tlogger.debug(taskId, "result added to job " + job.getId());
    // to be done before terminating the task, once terminated it is not
    // running anymore..
    job.getRunningTaskDescriptor(taskId);
    ChangedTasksInfo changesInfo = job.terminateTask(errorOccurred, taskId, listener, result.getAction(), result);
    boolean jobFinished = job.isFinished();
    // update job info if it is terminated
    if (jobFinished) {
        // terminating job
        job.terminate();
        jlogger.debug(job.getId(), "terminated");
        terminationData.addJobToTerminate(job.getId());
    }
    // Update database
    if (result.getAction() != null) {
        dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
    } else {
        dbManager.updateAfterTaskFinished(job, task, result);
    }
    // send event
    listener.taskStateUpdated(job.getOwner(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_RUNNING_TO_FINISHED, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
    // if this job is finished (every task have finished)
    jlogger.info(job.getId(), "finished tasks " + job.getNumberOfFinishedTasks() + ", total tasks " + job.getTotalNumberOfTasks() + ", finished " + jobFinished);
    if (jobFinished) {
        // send event to client
        listener.jobStateUpdated(job.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
        listener.jobUpdatedFullData(job);
    }
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Aggregations

JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)11 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)9 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)8 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)6 ArrayList (java.util.ArrayList)5 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)4 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)4 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)4 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)4 JobId (org.ow2.proactive.scheduler.common.job.JobId)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)2 JobState (org.ow2.proactive.scheduler.common.job.JobState)2 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)2 ChangedTasksInfo (org.ow2.proactive.scheduler.job.ChangedTasksInfo)2 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)2 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1