Search in sources :

Example 26 with TaskInfo

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

the class SchedulerClientTest method testKillTask.

@Test(timeout = MAX_WAIT_TIME)
public void testKillTask() throws Exception {
    ISchedulerClient client = clientInstance();
    Job job = createJob(NonTerminatingJob.class);
    SchedulerEventListenerImpl listener = new SchedulerEventListenerImpl();
    client.addEventListener(listener, true, SchedulerEvent.TASK_PENDING_TO_RUNNING);
    JobId jobId = submitJob(job, client);
    TaskInfo startedTask = listener.getStartedTask();
    while (!startedTask.getJobId().value().equals(jobId.value())) {
        startedTask = listener.getStartedTask();
    }
    client.killTask(jobId, getTaskNameForClass(NonTerminatingJob.class));
    client.removeEventListener();
    // should return immediately
    JobResult result = client.waitForJob(jobId, TimeUnit.MINUTES.toMillis(3));
    TaskResult tresult = result.getResult(getTaskName(NonTerminatingJob.class));
    Assert.assertTrue(tresult.hadException());
    Assert.assertTrue(tresult.getException() instanceof TaskAbortedException);
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleJob(functionaltests.jobs.SimpleJob) Job(org.ow2.proactive.scheduler.common.job.Job) NonTerminatingJob(functionaltests.jobs.NonTerminatingJob) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException) JobId(org.ow2.proactive.scheduler.common.job.JobId) NonTerminatingJob(functionaltests.jobs.NonTerminatingJob) Test(org.junit.Test)

Example 27 with TaskInfo

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

the class StringUtility method taskStatesAsString.

public static String taskStatesAsString(Collection<TaskStateData> tasks, boolean displayTags) {
    // create formatter
    ObjectArrayFormatter formatter = new ObjectArrayFormatter();
    formatter.setMaxColumnLength(80);
    // space between column
    formatter.setSpace(4);
    // title line
    List<String> list = new ArrayList<>();
    list.add("ID");
    list.add("NAME");
    if (displayTags) {
        list.add("TAG");
    }
    list.add("ITER");
    list.add("DUP");
    list.add("STATUS");
    list.add("HOSTNAME");
    list.add("EXEC DURATION");
    list.add("TOT DURATION");
    list.add("#NODES USED");
    list.add("#EXECUTIONS");
    list.add("#NODES KILLED");
    formatter.setTitle(list);
    formatter.addEmptyLine();
    for (TaskStateData taskState : tasks) {
        list = new ArrayList<>();
        TaskInfoData taskInfo = taskState.getTaskInfo();
        TaskIdData taskId = taskInfo.getTaskId();
        list.add(String.valueOf(taskId.getId()));
        list.add(taskId.getReadableName());
        if (displayTags) {
            list.add(toStringNullable(taskState.getTag()));
        }
        list.add((taskState.getIterationIndex() > 0) ? "" + taskState.getIterationIndex() : "");
        list.add((taskState.getReplicationIndex() > 0) ? "" + taskState.getReplicationIndex() : "");
        list.add(taskInfo.getTaskStatus().toString());
        list.add(toStringNullable(taskInfo.getExecutionHostName(), "unknown"));
        if (taskInfo.getTaskStatus() == TaskStatusData.IN_ERROR) {
            list.add(Tools.getFormattedDuration(taskInfo.getInErrorTime(), taskInfo.getStartTime()));
        } else {
            list.add(Tools.getFormattedDuration(0, taskInfo.getExecutionDuration()));
        }
        list.add(Tools.getFormattedDuration(taskInfo.getFinishedTime(), taskInfo.getStartTime()));
        list.add("" + taskState.getNumberOfNodesNeeded());
        list.add((taskState.getMaxNumberOfExecution() - taskInfo.getNumberOfExecutionLeft()) + "/" + taskState.getMaxNumberOfExecution());
        list.add((taskState.getMaxNumberOfExecutionOnFailure() - taskInfo.getNumberOfExecutionOnFailureLeft()) + "/" + taskState.getMaxNumberOfExecutionOnFailure());
        formatter.addLine(list);
    }
    return Tools.getStringAsArray(formatter);
}
Also used : TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) TaskInfoData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskInfoData) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData) ArrayList(java.util.ArrayList) ObjectArrayFormatter(org.ow2.proactive.utils.ObjectArrayFormatter)

Example 28 with TaskInfo

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

the class TestJobCoverage method testJobCoverage.

@Test
public void testJobCoverage() throws Throwable {
    JobState jstate;
    TaskInfo tinfo;
    JobInfo jinfo;
    // removing temp file if existing
    File w3File = new File(System.getProperty("java.io.tmpdir"), "WorkingAt3rdT2_13031984.tmp");
    if (w3File.exists()) {
        FileUtils.forceDelete(w3File);
    }
    // job submission
    log("Submitting job...");
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
    JobId id = schedulerHelper.submitJob(job);
    // checking all processes
    log("Checking all received events :");
    jstate = schedulerHelper.waitForEventJobSubmitted(id);
    assertEquals(JobStatus.PENDING, jstate.getStatus());
    // checking task 1
    log("Checking task1 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task1");
    jstate.update(tinfo);
    jstate.update(tinfo.getJobInfo());
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    assertEquals(JobStatus.RUNNING, jstate.getStatus());
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task1");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FINISHED, tinfo.getStatus());
    // checking task 2
    log("Checking task2 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
    // checking task 3
    log("Checking task3 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FINISHED, tinfo.getStatus());
    // checking task 4
    log("Checking task4 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task4");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task4");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
    // checking task 5
    log("Checking task5 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    String hostName = tinfo.getExecutionHostName();
    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    Assert.assertFalse(hostName.equals(tinfo.getExecutionHostName()));
    hostName = tinfo.getExecutionHostName();
    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    Assert.assertFalse(hostName.equals(tinfo.getExecutionHostName()));
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
    // checking task 6
    log("Checking task6 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task6");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task6");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FINISHED, tinfo.getStatus());
    // checking task 7
    log("Checking task7 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task7");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task7");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
    // checking task 8
    log("Checking task8 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
    // waiting for job termination
    log("Waiting for job to finish...");
    jinfo = schedulerHelper.waitForEventJobFinished(id);
    // checking results
    log("Checking results...");
    JobResult result = schedulerHelper.getJobResult(id);
    assertEquals(8, result.getAllResults().size());
    assertEquals(2, result.getPreciousResults().size());
    assertNotNull(result.getPreciousResults().get("task1"));
    assertNotNull(result.getPreciousResults().get("task6"));
    assertEquals("Working", result.getPreciousResults().get("task1").value());
    assertTrue(StackTraceUtil.getStackTrace(result.getResult("task2").getException()).contains("WorkingAt3rd - Status : Number is 1"));
    assertTrue(result.getResult("task3").value().toString().contains("WorkingAt3rd - Status : OK / File deleted :"));
    assertTrue(result.getResult("task4").getException().getCause().getMessage().contains("Throwing"));
    assertTrue(result.getResult("task5").getException().getCause().getMessage().contains("Throwing"));
    assertNotNull(result.getResult("task7").getException());
    assertNotNull(result.getResult("task8").getException());
    // checking end of the job...
    jstate.update(jinfo);
    assertEquals(0, jinfo.getNumberOfPendingTasks());
    assertEquals(0, jinfo.getNumberOfRunningTasks());
    assertEquals(8, jinfo.getNumberOfFinishedTasks());
    assertEquals(8, jinfo.getTotalNumberOfTasks());
    assertEquals(JobStatus.FINISHED, jinfo.getStatus());
    assertEquals(0, jstate.getNumberOfPendingTasks());
    assertEquals(0, jstate.getNumberOfRunningTasks());
    assertEquals(8, jstate.getNumberOfFinishedTasks());
    assertEquals(8, jstate.getTotalNumberOfTasks());
    assertEquals(JobStatus.FINISHED, jstate.getStatus());
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobState(org.ow2.proactive.scheduler.common.job.JobState) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 29 with TaskInfo

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

the class InternalTask method replicate.

/**
 * {@inheritDoc}
 */
@Override
public TaskState replicate() throws ExecutableCreationException {
    /*
         * this implementation deep copies everything using serialization. however the new
         * InternalTask cannot be strictly identical and we have to handle the following special
         * cases:
         *
         * - ExecutableContainer is transient and not copied during serialization. It needs to be
         * manually copied, and added to the InternalTask replica
         *
         * - Using the TaskInfo of _this_ gives us a FINISHED task, need to explicitely create a new
         * clean one.
         *
         * - InternalTask dependencies need to be nulled as they contain references to other
         * InternalTasks, and will be rewritten later anyway
         *
         * - Most of the objects down the object graph contain Hibernate @Id fields. If all those
         * fields are not set to 0 when inserting the object in DB, insertion will fail.
         *
         * - Collections are mapped to specific Hibernate internal collections at runtime, which
         * contain references to the @Id fields mentionned above. They need to be reset too.
         */
    InternalTask replicatedTask = null;
    // ExecutableContainer replicatedContainer = null;
    try {
        // Deep copy of the InternalTask using proactive serialization
        replicatedTask = (InternalTask) ProActiveMakeDeepCopy.WithProActiveObjectStream.makeDeepCopy(this);
    } catch (Throwable t) {
        throw new ExecutableCreationException("Failed to serialize task", t);
    }
    replicatedTask.internalJob = internalJob;
    // internalTasksDependencies contain references to other InternalTasks, it needs to be removed.
    // anyway, dependencies for the new task will not be the same as the original
    replicatedTask.internalTasksDependencies = null;
    // the taskinfo needs to be cleaned so that we don't tag this task as finished
    TaskId repId = replicatedTask.taskInfo.getTaskId();
    replicatedTask.taskInfo = new TaskInfoImpl();
    // we only need this id for the HashSet comparisons...
    replicatedTask.taskInfo.setTaskId(repId);
    replicatedTask.taskInfo.setNumberOfExecutionLeft(getMaxNumberOfExecution());
    replicatedTask.taskInfo.setNumberOfExecutionOnFailureLeft(getMaxNumberOfExecutionOnFailure());
    replicatedTask.setReplicatedFrom(this);
    // The next DB.update(InternalJob) will take care of it
    return replicatedTask;
}
Also used : ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl)

Example 30 with TaskInfo

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

the class SchedulingService method getProgressAndPingTaskNode.

void getProgressAndPingTaskNode(RunningTaskData taskData) {
    if (!jobs.canPingTask(taskData) || taskData.getPingAttempts() > PASchedulerProperties.SCHEDULER_NODE_PING_ATTEMPTS.getValueAsInt()) {
        return;
    }
    InternalTask task = taskData.getTask();
    try {
        // (2)
        int progress = taskData.getLauncher().getProgress();
        // get previous inside td
        if (progress != task.getProgress()) {
            // (1)
            task.setProgress(progress);
            // if progress != previously set progress (0 by default) -> update
            listener.taskStateUpdated(taskData.getUser(), new NotificationData<TaskInfo>(SchedulerEvent.TASK_PROGRESS, new TaskInfoImpl((TaskInfoImpl) task.getTaskInfo())));
        }
    } catch (Throwable t) {
        tlogger.debug(task.getId(), "TaskLauncher is not accessible, checking if the node can be reached.", t);
        pingTaskNodeAndInitiateRestart(task);
    }
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl)

Aggregations

TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)26 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)15 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)14 JobId (org.ow2.proactive.scheduler.common.job.JobId)10 Test (org.junit.Test)8 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)7 JobState (org.ow2.proactive.scheduler.common.job.JobState)7 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)6 ArrayList (java.util.ArrayList)5 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)5 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)4 TaskStatus (org.ow2.proactive.scheduler.common.task.TaskStatus)4 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)4 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)4 File (java.io.File)3 TaskAbortedException (org.ow2.proactive.scheduler.common.exception.TaskAbortedException)3 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)3 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)3 TaskInfoData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskInfoData)3 Page (org.ow2.proactive.scheduler.common.Page)2