Search in sources :

Example 31 with JobResult

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

the class TRepJobs method testJobs.

public void testJobs(TRepCase... testCases) throws Throwable {
    for (TRepCase tcase : testCases) {
        String path = new File(TWorkflowJobs.class.getResource(tcase.jobPath).toURI()).getAbsolutePath();
        Job job = JobFactory.getFactory().createJob(path);
        JobId id = schedulerHelper.submitJob(job);
        SchedulerTHelper.log("Job submitted, id " + id.toString());
        JobState receivedstate = schedulerHelper.waitForEventJobSubmitted(id);
        Assert.assertEquals(id, receivedstate.getId());
        JobInfo jInfo = schedulerHelper.waitForEventJobRunning(id);
        Assert.assertEquals(jInfo.getJobId(), id);
        Assert.assertEquals(JobStatus.RUNNING, jInfo.getStatus());
        jInfo = schedulerHelper.waitForEventJobFinished(id);
        Assert.assertEquals(JobStatus.FINISHED, jInfo.getStatus());
        SchedulerTHelper.log("Job finished");
        JobResult res = schedulerHelper.getJobResult(id);
        Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
        JobState js = schedulerHelper.getSchedulerInterface().getJobState(id);
        // final number of tasks
        Assert.assertEquals(tcase.total, js.getTasks().size());
        // to be checked against this.tasks
        HashMap<String, Long> finalTaskCount = new HashMap<>();
        // to be checked against this.results
        HashMap<String, Long> finalResSum = new HashMap<>();
        for (TaskState ts : js.getTasks()) {
            String baseName = InternalTask.getInitialName(ts.getName());
            long count = 0;
            long sum = 0;
            if (finalTaskCount.containsKey(baseName)) {
                count = finalTaskCount.get(baseName);
                sum = finalResSum.get(baseName);
            }
            finalTaskCount.put(baseName, count + 1);
            long tr = 0;
            if (ts.getStatus().equals(TaskStatus.SKIPPED)) {
                tr = -1;
            } else {
                Serializable sr = res.getAllResults().get(ts.getName()).value();
                if (sr instanceof Long) {
                    tr = ((Long) sr).longValue();
                }
            }
            finalResSum.put(baseName, sum + tr);
        }
        Assert.assertEquals(tcase.tasks.size(), finalTaskCount.size());
        Assert.assertEquals(tcase.results.size(), finalResSum.size());
        Assert.assertEquals(finalTaskCount.size(), finalResSum.size());
        for (Entry<String, Long> entry : finalTaskCount.entrySet()) {
            Assert.assertTrue(tcase.tasks.containsKey(entry.getKey()));
            long val = tcase.tasks.get(entry.getKey());
            Assert.assertEquals(val, entry.getValue().longValue());
        }
        for (Entry<String, Long> entry : finalResSum.entrySet()) {
            Assert.assertTrue(tcase.results.containsKey(entry.getKey()));
            long val = tcase.results.get(entry.getKey());
            Assert.assertEquals(val, entry.getValue().longValue());
        }
        schedulerHelper.removeJob(id);
        schedulerHelper.waitForEventJobRemoved(id);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) File(java.io.File) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 32 with JobResult

use of org.ow2.proactive.scheduler.common.job.JobResult 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 33 with JobResult

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

the class TestWorkflowFailedScript method testIf.

/**
 * Creates  a job with 3 tasks : A B C
 * Workflow : A  -> if (B) else (C)
 * Flowscript on A throws an Exception
 * B is supposed to be executed as cancelJobOnError==false
 * C is supposed to be skipped as it is the default ELSE branch
 * A is supposed to provide a task result value containing an exception
 */
private void testIf() throws Throwable {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    job.setMaxNumberOfExecution(1);
    job.setOnTaskError(OnTaskError.CONTINUE_JOB_EXECUTION);
    JavaTask A = new JavaTask();
    A.setOnTaskError(OnTaskError.NONE);
    A.setMaxNumberOfExecution(1);
    A.setName("A");
    A.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    FlowScript ifScript = FlowScript.createIfFlowScript(ifScriptContent, "B", "C", null);
    A.setFlowScript(ifScript);
    job.addTask(A);
    JavaTask B = new JavaTask();
    B.setName("B");
    B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    job.addTask(B);
    JavaTask C = new JavaTask();
    C.setName("C");
    C.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    job.addTask(C);
    JobId id = schedulerHelper.submitJob(job);
    schedulerHelper.waitForEventJobFinished(id);
    JobResult res = schedulerHelper.getJobResult(id);
    Map<String, TaskResult> results = res.getAllResults();
    // tasks A and B should produce a result, C should be SKIPPED
    Assert.assertTrue("Expected 2 results, got " + results.size(), results.size() == 2);
    for (Entry<String, TaskResult> result : results.entrySet()) {
        if (result.getKey().equals("A")) {
            // A should produce an exception
            Assert.assertTrue("Task " + result.getKey() + " should have had an exception!", result.getValue().hadException());
        } else {
            // task should be B and not C
            Assert.assertTrue("Expected result for task B, got task " + result.getKey(), result.getKey().equals("B"));
            // Task B should run without exception
            Assert.assertFalse("Task " + result.getKey() + " had an exception!", result.getValue().hadException());
        }
    }
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) JobId(org.ow2.proactive.scheduler.common.job.JobId) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript)

Example 34 with JobResult

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

the class TestWorkflowIterationAwareness method testNativeJob.

/**
 * native task through xml
 */
private void testNativeJob(String jobDescriptorPath) throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(jobDescriptorPath);
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            ((NativeTask) job.getTask("T1")).setPreScript(new SimpleScript(preScript, "groovy"));
            ((NativeTask) job.getTask("T1")).setPostScript(new SimpleScript(postScript, "groovy"));
            String[] tab = ((NativeTask) job.getTask("T1")).getCommandLine();
            tab[0] = "\"" + tab[0].replace("it.sh", "it.bat") + "\"";
            tab[1] = tmpFolder;
            ((NativeTask) job.getTask("T1")).setCommandLine(tab);
            break;
        case unix:
            job.getTask("T1").setPreScript(new SimpleScript(preScript, "groovy"));
            job.getTask("T1").setPostScript(new SimpleScript(postScript, "groovy"));
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    JobId id = TWorkflowJobs.testJobSubmission(schedulerHelper, job, null);
    JobResult res = schedulerHelper.getJobResult(id);
    Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
    int n = 4;
    for (Entry<String, TaskResult> result : res.getAllResults().entrySet()) {
        String path = "";
        switch(OperatingSystem.getOperatingSystem()) {
            case windows:
                File tmpdir = new File(tmpFolder, "native_result_");
                path = tmpdir.getAbsolutePath();
                break;
            case unix:
                path = System.getProperty("java.io.tmpdir") + "/native_result_";
                break;
            default:
                throw new IllegalStateException("Operating system not supported");
        }
        if (result.getKey().equals("T1")) {
            n--;
            File f = new File(path + "0_0");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1", "0", "0");
            in.close();
            f.delete();
        } else if (result.getKey().equals("T1*1")) {
            n--;
            File f = new File(path + "0_1");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1*1", "0", "1");
            in.close();
            f.delete();
        } else if (result.getKey().equals("T1#1")) {
            n--;
            File f = new File(path + "1_0");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1#1", "1", "0");
            in.close();
            f.delete();
        } else if (result.getKey().equals("T1#1*1")) {
            n--;
            File f = new File(path + "1_1");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1#1*1", "1", "1");
            in.close();
            f.delete();
        }
    }
    assertTrue("Expected 4 tasks, misses " + n, n == 0);
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) BufferedReader(java.io.BufferedReader) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) FileReader(java.io.FileReader) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 35 with JobResult

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

the class TestWorkflowIterationAwareness method testJavaJob.

/**
 * java task through xml
 */
private void testJavaJob(String jobDescriptorPath) throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(jobDescriptorPath);
    ((JavaTask) job.getTask("T1")).setPreScript(new SimpleScript(preScript, "groovy"));
    ((JavaTask) job.getTask("T1")).setPostScript(new SimpleScript(postScript, "groovy"));
    JobId id = TWorkflowJobs.testJobSubmission(schedulerHelper, job, null);
    JobResult res = schedulerHelper.getJobResult(id);
    Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
    int n = 4;
    for (Entry<String, TaskResult> result : res.getAllResults().entrySet()) {
        if (result.getKey().equals("T1")) {
            n--;
            checkResult(result.getValue().toString(), "T1", "0", "0");
        } else if (result.getKey().equals("T1*1")) {
            n--;
            checkResult(result.getValue().toString(), "T1*1", "0", "1");
        } else if (result.getKey().equals("T1#1")) {
            n--;
            checkResult(result.getValue().toString(), "T1#1", "1", "0");
        } else if (result.getKey().equals("T1#1*1")) {
            n--;
            checkResult(result.getValue().toString(), "T1#1*1", "1", "1");
        }
    }
    assertTrue("Expected 4 tasks, misses " + n, n == 0);
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) JobId(org.ow2.proactive.scheduler.common.job.JobId)

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