Search in sources :

Example 51 with TaskResultImpl

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

the class InProcessTaskExecutorTest method simpleScriptTask.

@Test
public void simpleScriptTask() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setPreScript(new SimpleScript("println('pre')", "groovy"));
    initializer.setPostScript(new SimpleScript("println('post')", "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println('hello'); java.lang.Thread.sleep(5); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(String.format("pre%nhello%npost%n"), taskOutput.output());
    assertEquals("hello", result.value());
    assertTrue("Task duration should be at least 5", result.getTaskDuration() >= 5);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 52 with TaskResultImpl

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

the class InProcessTaskExecutorTest method contextVariables_index.

@Test
public void contextVariables_index() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setReplicationIndex(7);
    initializer.setIterationIndex(6);
    String script = "result = variables.get('PA_TASK_ITERATION') * variables.get('PA_TASK_REPLICATION')";
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(script, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(42, result.value());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 53 with TaskResultImpl

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

the class InProcessTaskExecutorTest method taskWithFlowScript.

@Test
public void taskWithFlowScript() throws Exception {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setControlFlowScript(FlowScript.createReplicateFlowScript("print('flow'); runs=5", "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(FlowActionType.REPLICATE, result.getAction().getType());
    assertEquals("helloflow", taskOutput.output());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 54 with TaskResultImpl

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

the class LiveJobs method preemptTask.

TerminationData preemptTask(JobId jobId, String taskName, int restartDelay) throws UnknownJobException, UnknownTaskException {
    JobData jobData = lockJob(jobId);
    if (jobData == null) {
        throw new UnknownJobException(jobId);
    }
    try {
        InternalTask task = jobData.job.getTask(taskName);
        tlogger.info(task.getId(), "preempting task " + task.getId());
        if (!task.getStatus().isTaskAlive()) {
            tlogger.info(task.getId(), "task isn't alive: " + task.getStatus());
            return emptyResult(task.getId());
        }
        RunningTaskData taskData = runningTasksData.remove(TaskIdWrapper.wrap(task.getId()));
        if (taskData == null) {
            throw new IllegalStateException("Task " + task.getId() + " is not running.");
        }
        TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, jobData.job, task, new TaskPreemptedException("Preempted by admin"), new SimpleTaskLogs("", "Preempted by admin"));
        TerminationData terminationData = createAndFillTerminationData(taskResult, taskData, jobData.job, TerminationData.TerminationStatus.ABORTED);
        long waitTime = restartDelay * 1000L;
        restartTaskOnError(jobData, task, TaskStatus.PENDING, taskResult, waitTime, terminationData);
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 55 with TaskResultImpl

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

TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)73 Test (org.junit.Test)70 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)32 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)30 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)26 SimpleScript (org.ow2.proactive.scripting.SimpleScript)26 TaskScript (org.ow2.proactive.scripting.TaskScript)26 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)25 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)25 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)22 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 JobId (org.ow2.proactive.scheduler.common.job.JobId)16 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)16 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)15 HashMap (java.util.HashMap)13 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)13 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)12 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)11 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)10