Search in sources :

Example 21 with TaskId

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

the class TaskLauncherTest method scratchDirDeletedAfterTaskCompleted.

@Test
public void scratchDirDeletedAfterTaskCompleted() throws Throwable {
    ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    final TaskDataspaces dataspacesMock = mock(TaskDataspaces.class);
    when(dataspacesMock.getScratchFolder()).thenReturn(tmpFolder.newFolder());
    runTaskLauncher(createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory() {

        @Override
        public TaskDataspaces createTaskDataspaces(TaskId taskId, NamingService namingService, boolean isRunAsUser) {
            return dataspacesMock;
        }
    }), executableContainer);
    verify(dataspacesMock).close();
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskDataspaces(org.ow2.proactive.scheduler.task.data.TaskDataspaces) NamingService(org.objectweb.proactive.extensions.dataspaces.core.naming.NamingService) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Test(org.junit.Test)

Example 22 with TaskId

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

the class TaskLoggerTest method logPattern.

@Test
public void logPattern() throws Exception {
    TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L);
    taskLogger = new TaskLogger(taskId, "myhost");
    assertEquals("", taskLogger.getLogs().getAllLogs(false));
    taskLogger.getOutputSink().println("hello");
    String quotedStringTaskId = Pattern.quote(taskId.toString());
    assertTrue(taskLogger.getLogs().getAllLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] hello \r?\n"));
    taskLogger.getErrorSink().println("error");
    assertTrue(taskLogger.getLogs().getStderrLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] error \r?\n"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 23 with TaskId

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

the class ForkedProcessBuilderCreatorTest method createTaskLauncherInitializer.

private TaskLauncherInitializer createTaskLauncherInitializer() {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    TaskId taskId = createTaskId();
    taskLauncherInitializer.setTaskId(taskId);
    taskLauncherInitializer.setIterationIndex(iterationIndexValue);
    taskLauncherInitializer.setJobOwner(jobOwnerValue);
    taskLauncherInitializer.setReplicationIndex(taskReplicationValue);
    return taskLauncherInitializer;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer)

Example 24 with TaskId

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

the class ForkedJvmTaskExecutionCommandCreatorTest method createTaskLauncherInitializer.

private TaskLauncherInitializer createTaskLauncherInitializer() {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    TaskId taskId = createTaskId();
    taskLauncherInitializer.setTaskId(taskId);
    taskLauncherInitializer.setIterationIndex(iterationIndexValue);
    taskLauncherInitializer.setJobOwner(jobOwnerValue);
    taskLauncherInitializer.setReplicationIndex(taskReplicationValue);
    return taskLauncherInitializer;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer)

Example 25 with TaskId

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

the class LiveJobs method taskTerminatedWithResult.

public TerminationData taskTerminatedWithResult(TaskId taskId, TaskResultImpl result) {
    JobData jobData = lockJob(taskId.getJobId());
    if (jobData == null) {
        return emptyResult(taskId);
    }
    try {
        InternalTask task;
        try {
            task = jobData.job.getTask(taskId);
        } catch (UnknownTaskException e) {
            logger.error("Unexpected exception", e);
            return emptyResult(taskId);
        }
        if (task.getStatus() != TaskStatus.RUNNING) {
            tlogger.info(taskId, "task isn't running anymore");
            return emptyResult(taskId);
        }
        TaskIdWrapper taskIdWrapper = TaskIdWrapper.wrap(taskId);
        RunningTaskData taskData = runningTasksData.remove(taskIdWrapper);
        if (taskData == null) {
            tlogger.info(taskId, "Task " + taskId + " terminates after a recovery of the scheduler");
            taskData = new RunningTaskData(task, jobData.job.getOwner(), jobData.job.getCredentials(), task.getExecuterInformation().getLauncher());
        }
        TerminationData terminationData = createAndFillTerminationData(result, taskData, jobData.job, TerminationData.TerminationStatus.NORMAL);
        boolean errorOccurred = result.hadException();
        tlogger.info(taskId, "finished with" + (errorOccurred ? "" : "out") + " errors");
        if (errorOccurred) {
            tlogger.error(taskId, "task has terminated with an error", result.getException());
            task.decreaseNumberOfExecutionLeft();
            boolean requiresPauseJobOnError = onErrorPolicyInterpreter.requiresPauseJobOnError(task);
            int numberOfExecutionLeft = task.getNumberOfExecutionLeft();
            if (numberOfExecutionLeft <= 0 && onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
                tlogger.info(taskId, "no retry left and task is tagged with cancel job on error");
                jobData.job.increaseNumberOfFaultyTasks(taskId);
                endJob(jobData, terminationData, task, result, "An error occurred in your task and the maximum number of executions has been reached. " + "You also ask to cancel the job in such a situation!", JobStatus.CANCELED);
                jlogger.info(taskId.getJobId(), "job has been canceled");
                return terminationData;
            } else if (numberOfExecutionLeft > 0) {
                tlogger.info(taskId, "number of execution left is " + numberOfExecutionLeft);
                if (onErrorPolicyInterpreter.requiresPauseTaskOnError(task) || requiresPauseJobOnError) {
                    long waitTime = jobData.job.getNextWaitingTime(task.getMaxNumberOfExecution() - numberOfExecutionLeft);
                    restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, result, waitTime, terminationData);
                    tlogger.info(taskId, "new restart is scheduled");
                    return terminationData;
                } else {
                    jobData.job.increaseNumberOfFaultyTasks(taskId);
                    long waitTime = jobData.job.getNextWaitingTime(task.getMaxNumberOfExecution() - numberOfExecutionLeft);
                    restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, result, waitTime, terminationData);
                    tlogger.info(taskId, "new restart is scheduled");
                    return terminationData;
                }
            } else if (numberOfExecutionLeft <= 0) {
                if (!onErrorPolicyInterpreter.requiresPauseTaskOnError(task) && !onErrorPolicyInterpreter.requiresPauseJobOnError(task) && !onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
                    jobData.job.increaseNumberOfFaultyTasks(taskId);
                    // remove the parent tasks results if task fails and job is canceled
                    task.removeParentTasksResults();
                } else if (onErrorPolicyInterpreter.requiresPauseTaskOnError(task)) {
                    suspendTaskOnError(jobData, task, result.getTaskDuration());
                    tlogger.info(taskId, "Task always contains errors after automatic restart, so it stays in In_Error state");
                    return terminationData;
                } else if (requiresPauseJobOnError) {
                    suspendTaskOnError(jobData, task, result.getTaskDuration());
                    pauseJob(task.getJobId());
                    logger.info("Task always contains errors after automatic restart, so Job is always paused on error");
                    return terminationData;
                }
                if (requiresPauseJobOnError) {
                    pauseJob(task.getJobId());
                }
            }
        } else {
            // remove the parent tasks results if task finished with no error
            task.removeParentTasksResults();
        }
        terminateTask(jobData, task, errorOccurred, result, terminationData);
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

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