Search in sources :

Example 31 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.

the class TestTaskAttributes method testGenericInfo.

@Test
public void testGenericInfo() throws Exception {
    JavaTask task = createDefaultTask("task");
    Map<String, String> genericInfo;
    InternalTask taskData;
    genericInfo = new HashMap<>();
    task.setGenericInformation(genericInfo);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertNotNull(taskData.getGenericInformation());
    Assert.assertTrue(taskData.getGenericInformation().isEmpty());
    genericInfo = new HashMap<>();
    genericInfo.put("p1", "v1");
    genericInfo.put("p2", "v2");
    task.setGenericInformation(genericInfo);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertEquals(2, taskData.getGenericInformation().size());
    Assert.assertEquals("v1", taskData.getGenericInformation().get("p1"));
    Assert.assertEquals("v2", taskData.getGenericInformation().get("p2"));
    StringBuilder longString = buildLongString();
    genericInfo = new HashMap<>();
    genericInfo.put("longProperty", longString.toString());
    task.setGenericInformation(genericInfo);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertEquals(1, taskData.getGenericInformation().size());
    Assert.assertEquals(longString.toString(), taskData.getGenericInformation().get("longProperty"));
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 32 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.

the class TestTaskAttributes method testRestartMode.

@Test
public void testRestartMode() throws Exception {
    JavaTask task = createDefaultTask("task1");
    task.setRestartTaskOnError(RestartMode.ANYWHERE);
    InternalTask taskData = saveSingleTask(task).getTask("task1");
    Assert.assertSame(RestartMode.ANYWHERE, taskData.getRestartTaskOnError());
    task.setRestartTaskOnError(RestartMode.ELSEWHERE);
    taskData = saveSingleTask(task).getTask("task1");
    Assert.assertSame(RestartMode.ELSEWHERE, taskData.getRestartTaskOnError());
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 33 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData 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

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)20 Test (org.junit.Test)12 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)7 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)7 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)5 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)5 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)4 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)4 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)4 Query (org.hibernate.Query)3 DBTaskId (org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)3 List (java.util.List)2 TaskAbortedException (org.ow2.proactive.scheduler.common.exception.TaskAbortedException)2 TaskPreemptedException (org.ow2.proactive.scheduler.common.exception.TaskPreemptedException)2 TaskRestartedException (org.ow2.proactive.scheduler.common.exception.TaskRestartedException)2