Search in sources :

Example 31 with TaskResultImpl

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

the class TestTaskResultData method testTaskResultMultipleAttempts.

@Test
public void testTaskResultMultipleAttempts() throws Throwable {
    TaskFlowJob jobDef = new TaskFlowJob();
    jobDef.addTask(createDefaultTask("testTask"));
    InternalJob internalJob = defaultSubmitJobAndLoadInternal(true, jobDef);
    InternalTask task = internalJob.getTask("testTask");
    dbManager.updateAfterTaskFinished(internalJob, task, new TaskResultImpl(null, new TestResult(0, "1_1"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task, new TaskResultImpl(null, new TestResult(0, "1_2"), null, 0));
    TaskResult result1 = dbManager.loadTaskResult(jobDef.getId(), "testTask", 0);
    TaskResult result2 = dbManager.loadTaskResult(jobDef.getId(), "testTask", 0);
    // try to load individual task result attempts
    Assert.assertNotNull(result1);
    Assert.assertNotNull(result2);
    Assert.assertNull(dbManager.loadTaskResult(jobDef.getId(), "testTask", 2));
    List<TaskResult> results = dbManager.loadTaskResultAllAttempts(jobDef.getId(), "testTask");
    Assert.assertEquals(2, results.size());
    // list of results returned by loadTaskResultAllAttempts are in reverse order from individual index (list preserve the execution order, index starts from last execution)
    Assert.assertEquals(results.get(0), result2);
    Assert.assertEquals(results.get(1), result1);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 32 with TaskResultImpl

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

the class TestTaskResultData method testFlowAction.

@Test
public void testFlowAction() throws Exception {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    InternalTask task = (InternalTask) job.getTasks().get(0);
    TaskResultImpl result = new TaskResultImpl(null, new TestResult(10, "12345"), null, 0);
    FlowAction action = new FlowAction(FlowActionType.LOOP);
    action.setDupNumber(33);
    action.setTarget("t");
    action.setTargetContinuation("tc");
    action.setTargetElse("te");
    result.setAction(action);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResultImpl restoredResult = (TaskResultImpl) dbManager.loadLastTaskResult(task.getId());
    FlowAction restoredAction = restoredResult.getAction();
    Assert.assertNotNull(restoredAction);
    Assert.assertEquals(FlowActionType.LOOP, restoredAction.getType());
    Assert.assertEquals(33, restoredAction.getDupNumber());
    Assert.assertEquals("t", restoredAction.getTarget());
    Assert.assertEquals("tc", restoredAction.getTargetContinuation());
    Assert.assertEquals("te", restoredAction.getTargetElse());
    restoredResult = (TaskResultImpl) dbManager.loadTaskResult(job.getId(), "task", 0);
    restoredAction = restoredResult.getAction();
    Assert.assertEquals(FlowActionType.LOOP, restoredAction.getType());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 33 with TaskResultImpl

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

the class TestTaskResultData method testMultipleJobs.

@Test
public void testMultipleJobs() throws Throwable {
    // two jobs have tasks with the same name
    TaskFlowJob jobDef1 = new TaskFlowJob();
    jobDef1.addTask(createDefaultTask("task1"));
    TaskFlowJob jobDef2 = new TaskFlowJob();
    jobDef2.addTask(createDefaultTask("task1"));
    InternalJob job1 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    InternalJob job2 = defaultSubmitJobAndLoadInternal(true, jobDef2);
    dbManager.updateAfterTaskFinished(job1, job1.getTask("task1"), new TaskResultImpl(null, new TestResult(0, "job1Res"), null, 0));
    dbManager.updateAfterTaskFinished(job2, job2.getTask("task1"), new TaskResultImpl(null, new TestResult(0, "job2Res"), null, 0));
    TestResult result;
    result = (TestResult) dbManager.loadTaskResult(job1.getId(), "task1", 0).value();
    Assert.assertEquals("job1Res", result.getB());
    result = (TestResult) dbManager.loadTaskResult(job2.getId(), "task1", 0).value();
    Assert.assertEquals("job2Res", result.getB());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Test(org.junit.Test)

Example 34 with TaskResultImpl

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

the class TestTaskResultData method testMultipleResults.

@Test
public void testMultipleResults() throws Throwable {
    TaskFlowJob job = new TaskFlowJob();
    job.addTask(createDefaultTask("task1"));
    job.addTask(createDefaultTask("task2"));
    job.addTask(createDefaultTask("task3"));
    InternalJob internalJob = defaultSubmitJobAndLoadInternal(true, job);
    InternalTask task1 = internalJob.getTask("task1");
    InternalTask task2 = internalJob.getTask("task2");
    InternalTask task3 = internalJob.getTask("task3");
    dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_1"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_2"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_3"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_1"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_2"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_3"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_1"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_2"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_3"), null, 0));
    TestResult result;
    result = (TestResult) dbManager.loadLastTaskResult(task1.getId()).value();
    Assert.assertEquals("1_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task1.getName(), 0).value();
    Assert.assertEquals("1_3", result.getB());
    result = (TestResult) dbManager.loadLastTaskResult(task2.getId()).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadLastTaskResult(task3.getId()).value();
    Assert.assertEquals("3_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task3.getName(), 0).value();
    Assert.assertEquals("3_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(task2.getId(), 0).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(task2.getId(), 1).value();
    Assert.assertEquals("2_2", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 1).value();
    Assert.assertEquals("2_2", result.getB());
    result = (TestResult) dbManager.loadTaskResult(task2.getId(), 2).value();
    Assert.assertEquals("2_1", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 2).value();
    Assert.assertEquals("2_1", result.getB());
    Assert.assertNull(dbManager.loadTaskResult(task2.getId(), 3));
    Assert.assertNull(dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 3));
    List<TaskId> taskIds = Arrays.asList(task1.getId(), task2.getId(), task3.getId());
    System.out.println("Load results for 3 tasks");
    Map<TaskId, TaskResult> results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
    Assert.assertEquals(3, results.size());
    result = (TestResult) results.get(task1.getId()).value();
    Assert.assertEquals("1_3", result.getB());
    result = (TestResult) results.get(task2.getId()).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) results.get(task3.getId()).value();
    Assert.assertEquals("3_3", result.getB());
    taskIds = Arrays.asList(task2.getId(), task3.getId());
    System.out.println("Load results for 2 tasks");
    results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
    Assert.assertEquals(2, results.size());
    result = (TestResult) results.get(task2.getId()).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) results.get(task3.getId()).value();
    Assert.assertEquals("3_3", result.getB());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 35 with TaskResultImpl

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

the class TestTaskResultData method testLog4jLogs.

@Test
public void testLog4jLogs() throws Exception {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    InternalTask task = (InternalTask) job.getTasks().get(0);
    LinkedList<LoggingEvent> events = new LinkedList<>();
    for (int i = 0; i < 3; i++) {
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.INFO, "info" + i, null));
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.ERROR, "error" + i, null));
    }
    TaskResultImpl result = new TaskResultImpl(null, "result", new Log4JTaskLogs(events, "0"), 0);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
    TaskLogs logs = restoredResult.getOutput();
    Assert.assertNotNull(logs);
    String logsString = logs.getStdoutLogs(false);
    Assert.assertTrue(logsString.contains("info0"));
    Assert.assertTrue(logsString.contains("info1"));
    Assert.assertTrue(logsString.contains("info2"));
    logsString = logs.getStderrLogs(false);
    Assert.assertTrue(logsString.contains("error0"));
    Assert.assertTrue(logsString.contains("error1"));
    Assert.assertTrue(logsString.contains("error2"));
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) 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) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)79 Test (org.junit.Test)77 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)35 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)35 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)30 SimpleScript (org.ow2.proactive.scripting.SimpleScript)30 TaskScript (org.ow2.proactive.scripting.TaskScript)30 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)29 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)26 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)26 NodeInfo (org.ow2.proactive.scheduler.task.context.NodeInfo)26 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)22 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 HashMap (java.util.HashMap)17 JobId (org.ow2.proactive.scheduler.common.job.JobId)17 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)16 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)13 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)13 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)12