Search in sources :

Example 91 with TaskResultImpl

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

the class TestReadSchedulerAccount method finishTask.

private long finishTask(InternalJob job, String taskName) throws Exception {
    Thread.sleep(100);
    InternalTask task = job.getTask(taskName);
    TaskResultImpl res = new TaskResultImpl(null, "ok", null, 0);
    job.terminateTask(false, task.getId(), null, null, res);
    if (job.isFinished()) {
        job.terminate();
    }
    dbManager.updateAfterTaskFinished(job, task, res);
    return task.getFinishedTime() - task.getStartTime();
}
Also used : TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 92 with TaskResultImpl

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

the class TestRestoreWorkflowJobs method finishedJobWithScriptsCanBeRecoveredAndLoaded.

@Test
public void finishedJobWithScriptsCanBeRecoveredAndLoaded() throws Exception {
    InternalJob job = defaultSubmitJobAndLoadInternal(true, createJobWithAllKindOfScripts());
    job.start();
    InternalTask mainTask = job.getTask("T");
    startTask(job, mainTask);
    dbManager.jobTaskStarted(job, mainTask, true);
    TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
    ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, null, result);
    job.setStatus(JobStatus.FINISHED);
    dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    JobStateMatcher expectedJob = job(job.getId(), JobStatus.FINISHED).withFinished(task("T", TaskStatus.FINISHED).checkFinished(), true);
    checkRecoveredState(recoverHelper.recover(-1), state().withFinished(expectedJob));
    List<InternalJob> finishedJobs = dbManager.loadFinishedJobs(true, -1);
    assertEquals(1, finishedJobs.size());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) ChangedTasksInfo(org.ow2.proactive.scheduler.job.ChangedTasksInfo) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) Test(org.junit.Test)

Example 93 with TaskResultImpl

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

the class TestTaskResultData method testResult.

@Test
public void testResult() throws Throwable {
    Map<String, String> metadata = ImmutableMap.of("key1", "value1", "key2", "value2");
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    TaskResultImpl result = new TaskResultImpl(null, new TestResult(10, "12345"), null, 0);
    String previewer = "org.ow2.proactive.scheduler.common.org.ow2.proactive.scheduler.common.ClassName";
    result.setPreviewerClassName(previewer);
    result.setMetadata(metadata);
    InternalTask task = (InternalTask) job.getTasks().get(0);
    System.out.println("Add task result");
    dbManager.updateAfterTaskFinished(job, task, result);
    System.out.println("Get last task result");
    TaskResultImpl restoredResult = (TaskResultImpl) dbManager.loadLastTaskResult(task.getId());
    Assert.assertEquals(task.getId(), restoredResult.getTaskId());
    Assert.assertNull(restoredResult.getException());
    Assert.assertNull(restoredResult.getOutput());
    TestResult value = (TestResult) restoredResult.value();
    Assert.assertNotNull(value);
    Assert.assertEquals(10, value.getA());
    Assert.assertEquals("12345", value.getB());
    Assert.assertEquals(previewer, restoredResult.getPreviewerClassName());
    Assert.assertNull(restoredResult.getAction());
    Assert.assertEquals(metadata, restoredResult.getMetadata());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 94 with TaskResultImpl

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

the class TestTaskResultData method testSimpleLogs.

@Test
public void testSimpleLogs() throws Exception {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    InternalTask task = (InternalTask) job.getTasks().get(0);
    TaskResultImpl result = new TaskResultImpl(null, "result", new SimpleTaskLogs("stdLogs", "errorLogs"), 0);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
    TaskLogs logs = restoredResult.getOutput();
    Assert.assertNotNull(logs);
    Assert.assertEquals("stdLogs", logs.getStdoutLogs(false));
    Assert.assertEquals("errorLogs", logs.getStderrLogs(false));
}
Also used : TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 95 with TaskResultImpl

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

the class LiveJobs method restartTask.

TerminationData restartTask(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(), "restarting task " + task.getId());
        if (!task.getStatus().isTaskAlive()) {
            tlogger.warn(task.getId(), "task isn't alive: " + task.getStatus());
            return emptyResult(task.getId());
        }
        TaskIdWrapper taskIdWrapper = TaskIdWrapper.wrap(task.getId());
        RunningTaskData taskData = runningTasksData.remove(taskIdWrapper);
        if (taskData == null) {
            throw new IllegalStateException("Task " + task.getId() + " is not running.");
        }
        TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, jobData.job, task, new TaskRestartedException("Aborted by user"), new SimpleTaskLogs("", "Aborted by user"));
        TerminationData terminationData = createAndFillTerminationData(taskResult, taskData, jobData.job, TerminationData.TerminationStatus.ABORTED);
        task.decreaseNumberOfExecutionLeft();
        if (task.getNumberOfExecutionLeft() <= 0 && onErrorPolicyInterpreter.requiresCancelJobOnError(task)) {
            endJob(jobData, terminationData, task, taskResult, "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);
            return terminationData;
        } else if (task.getNumberOfExecutionLeft() > 0) {
            long waitTime = restartDelay * 1000l;
            restartTaskOnError(jobData, task, TaskStatus.WAITING_ON_ERROR, taskResult, waitTime, terminationData);
            return terminationData;
        }
        terminateTask(jobData, task, true, taskResult, terminationData);
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException)

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