Search in sources :

Example 41 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class TestKilledJobResult method test.

@Test
public void test() throws Throwable {
    TaskFlowJob job = new TaskFlowJob();
    JavaTask task1 = new JavaTask();
    task1.setName("task1");
    task1.setExecutableClassName(TestJavaTask1.class.getName());
    job.addTask(task1);
    JavaTask task2 = new JavaTask();
    task2.setName("task2");
    task2.setExecutableClassName(TestJavaTask2.class.getName());
    job.addTask(task2);
    task2.addDependence(task1);
    log("Submit job");
    JobId jobId = schedulerHelper.submitJob(job);
    log("Submitted job " + jobId);
    log("Waiting for task1 to finish");
    schedulerHelper.waitForEventTaskFinished(jobId, "task1");
    schedulerHelper.waitForEventTaskRunning(jobId, "task2");
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    log("Killing job");
    scheduler.killJob(jobId);
    log("Wait when job finishes");
    schedulerHelper.waitForEventJobFinished(jobId);
    JobResult jobResult = scheduler.getJobResult(jobId);
    printResult(jobResult);
    assertEquals(1, jobResult.getAllResults().size());
    assertEquals("OK", jobResult.getAllResults().get("task1").value().toString());
    JobInfo jobInfo = jobResult.getJobInfo();
    assertEquals(JobStatus.KILLED, jobInfo.getStatus());
    assertEquals(1, jobInfo.getNumberOfFinishedTasks());
    assertEquals(2, jobInfo.getTotalNumberOfTasks());
    assertEquals(0, jobInfo.getNumberOfPendingTasks());
    assertEquals(0, jobInfo.getNumberOfRunningTasks());
    JobState state = scheduler.getJobState(jobId);
    assertEquals(JobStatus.KILLED, state.getStatus());
    assertEquals(1, state.getNumberOfFinishedTasks());
    assertEquals(2, state.getTotalNumberOfTasks());
    assertEquals(0, state.getNumberOfPendingTasks());
    assertEquals(0, state.getNumberOfRunningTasks());
    assertEquals(2, state.getTasks().size());
    assertEquals(TaskStatus.FINISHED, findTask(state, "task1").getStatus());
    assertEquals(TaskStatus.ABORTED, findTask(state, "task2").getStatus());
    TaskState taskState0 = state.getTasks().get(0);
    TaskState taskState1 = state.getTasks().get(1);
    assertTrue(taskState0.getStartTime() > 0);
    assertTrue(taskState0.getFinishedTime() > 0);
    assertTrue(taskState0.getExecutionDuration() >= 0);
    assertTrue(taskState0.getExecutionDuration() <= taskState0.getFinishedTime() - taskState0.getStartTime());
    assertTrue(taskState1.getStartTime() > 0);
    assertTrue(taskState1.getFinishedTime() > 0);
    assertTrue(taskState1.getExecutionDuration() >= 0);
    assertTrue(taskState1.getExecutionDuration() <= taskState1.getFinishedTime() - taskState1.getStartTime());
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Test(org.junit.Test)

Example 42 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class TestProcessTreeKiller method testProcessTreeKiller.

@Test
public void testProcessTreeKiller() throws Throwable {
    schedulerHelper.addExtraNodes(2);
    Logger.getLogger(ProcessTree.class).setLevel(Level.DEBUG);
    Logger.getLogger(TaskLauncher.class).setLevel(Level.DEBUG);
    for (int i = 0; i < NB_ITERATIONS; i++) {
        log("***************************************************");
        log("************** Iteration " + i + " *************************");
        log("***************************************************");
        log("Creating job...");
        // create job 1 NativeExecutable
        TaskFlowJob job1 = new TaskFlowJob();
        job1.setName(this.getClass().getSimpleName() + "_1");
        job1.setDescription("a command that spawn processes");
        NativeTask task1 = new NativeTask();
        String task1Name = "TestPTK1";
        task1.setName(task1Name);
        String workingDir = new File(TestProcessTreeKiller.launchersDir.toURI()).getParentFile().getCanonicalPath();
        task1.setForkEnvironment(new ForkEnvironment(workingDir));
        JavaSpawnExecutable executable = new JavaSpawnExecutable();
        executable.home = PASchedulerProperties.SCHEDULER_HOME.getValueAsString();
        task1.setCommandLine(executable.getNativeExecLauncher(false));
        job1.addTask(task1);
        String task2Name = "TestTK2";
        TaskFlowJob job2 = createJavaExecutableJob(task2Name, true);
        log("************** Test with Job Killing *************");
        // submit three jobs
        JobId id1 = schedulerHelper.submitJob(job1);
        JobId id2 = schedulerHelper.submitJob(job2);
        schedulerHelper.waitForEventTaskRunning(id1, task1Name);
        schedulerHelper.waitForEventTaskRunning(id2, task2Name);
        log("************** All 2 tasks running *************");
        TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(detachedProcNumber * 2);
        // we should have 2 times (2 jobs) number of detached processes
        // kill the first job
        log("************** Waiting for the first job (NativeExecutable) to be killed *************");
        schedulerHelper.getSchedulerInterface().killJob(id1);
        schedulerHelper.waitForEventJobFinished(id1);
        log("************** First job killed *************");
        TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(detachedProcNumber);
        // kill the second job
        log("************** Waiting for the second job (JavaExecutable) to be killed *************");
        schedulerHelper.getSchedulerInterface().killJob(id2);
        schedulerHelper.waitForEventJobFinished(id2);
        log("************** Second job killed *************");
        TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(0);
        JobResult res = schedulerHelper.getJobResult(id1);
        assertEquals(JobStatus.KILLED, res.getJobInfo().getStatus());
        res = schedulerHelper.getJobResult(id2);
        assertEquals(JobStatus.KILLED, res.getJobInfo().getStatus());
        log("************** Test with Normal Job termination *************");
        // The test for normal termination in case of NativeExecutable is slightly different
        // we don't spawn here a native zombie process that will wait forever, because that would mean that the
        // NativeExecutable task will also wait forever !
        // This is related to the current implementation of NativeExecutable, as long as there are still some IO streamed
        // from the subprocesses of the main process, the task will wait
        // TODO improve the test by finding a way to run a detached process without IO redirection
        TaskFlowJob job4 = new TaskFlowJob();
        job4.setName(this.getClass().getSimpleName() + "_4");
        job4.setDescription("a command that spawn processes");
        NativeTask task4 = new NativeTask();
        String task4Name = "TestPTK4";
        task4.setName(task4Name);
        task4.setForkEnvironment(new ForkEnvironment(workingDir));
        task4.setCommandLine(executable.getNativeExecLauncher(true));
        job4.addTask(task4);
        // submit three jobs
        id1 = schedulerHelper.submitJob(job4);
        id2 = schedulerHelper.submitJob(job2);
        schedulerHelper.waitForEventTaskRunning(id1, task4Name);
        schedulerHelper.waitForEventTaskRunning(id2, task2Name);
        log("************** All 2 tasks running *************");
        TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(detachedProcNumber);
        // we should have 1 time (2 jobs) number of detached processes as the first job won't spawn any process
        log("************** Waiting for first job (NativeExecutable) to finish *************");
        // wait for the first job to finish normally
        schedulerHelper.waitForEventJobFinished(id1);
        log("************** First job finished *************");
        int runningDetachedProcNumber = countProcesses();
        log("************** number of processes : " + runningDetachedProcNumber);
        assertEquals(detachedProcNumber, runningDetachedProcNumber);
        log("************** Waiting for second job (JavaExecutable) to finish *************");
        // wait for the second job to finish normally
        schedulerHelper.waitForEventJobFinished(id2);
        log("************** Second job finished *************");
        runningDetachedProcNumber = countProcesses();
        log("************** number of processes : " + runningDetachedProcNumber);
        assertEquals(0, runningDetachedProcNumber);
        res = schedulerHelper.getJobResult(id1);
        assertEquals(JobStatus.FINISHED, res.getJobInfo().getStatus());
        res = schedulerHelper.getJobResult(id2);
        assertEquals(JobStatus.FINISHED, res.getJobInfo().getStatus());
    }
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) ProcessTree(org.ow2.proactive.process_tree_killer.ProcessTree) TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 43 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class TestRamPolicy method testRamPolicy.

@Test
public void testRamPolicy() throws Throwable {
    Map<String, String> variables = new HashMap<String, String>();
    variables.put("MERGE_RAM", getHalfLocalRam());
    JobId jobId = schedulerHelper.submitJob(new File(jobDescriptor.toURI()).getAbsolutePath(), variables);
    log("Waiting for job finished");
    JobInfo jInfo = schedulerHelper.waitForEventJobFinished(jobId);
    JobResult res = schedulerHelper.getJobResult(jobId);
    assertThat(res.hadException(), is(false));
}
Also used : HashMap(java.util.HashMap) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 44 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class RunningTaskRecoveryWithDownNodeTest method checkJobResult.

private void checkJobResult(JobId jobid, Scheduler scheduler) throws NotConnectedException, PermissionException, UnknownJobException {
    JobResult jobResult = scheduler.getJobResult(jobid);
    Assert.assertFalse(jobResult.hadException());
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult)

Example 45 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.

the class TestRMReconnectionWhileRunning method assertJobFinished.

private void assertJobFinished(JobId jobId) throws Exception {
    final JobResult result0 = schedulerHelper.getJobResult(jobId);
    assertNotNull(result0);
    final JobInfo jobInfo0 = result0.getJobInfo();
    final JobStatus status0 = jobInfo0.getStatus();
    assertFalse(status0.isJobAlive());
}
Also used : JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo)

Aggregations

JobResult (org.ow2.proactive.scheduler.common.job.JobResult)39 JobId (org.ow2.proactive.scheduler.common.job.JobId)26 Test (org.junit.Test)25 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)24 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)22 File (java.io.File)16 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)9 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)7 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)6 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)6 JobResultImpl (org.ow2.proactive.scheduler.job.JobResultImpl)6 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)6 Job (org.ow2.proactive.scheduler.common.job.Job)4 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)4 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)4 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)4 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)3 SimpleJob (functionaltests.jobs.SimpleJob)3 HashMap (java.util.HashMap)3 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)3