Search in sources :

Example 11 with NativeTask

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

the class TestReportingQueries method doTest.

@Test
public void doTest() throws Exception {
    checkInvalidIds();
    checkJobAndTasksNumbers(0, 0, 0, 0, 0, 0, 0, 0);
    checkMeanPendingTime();
    checkMeanExecutionTime();
    checkMeanSubmittingPeriod();
    TaskFlowJob jobDef1 = new TaskFlowJob();
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(TestDummyExecutable.class.getName());
    javaTask.setName("task1");
    jobDef1.addTask(javaTask);
    JavaTask forkJavaTask = createDefaultTask("task2");
    forkJavaTask.setExecutableClassName(TestDummyExecutable.class.getName());
    forkJavaTask.setForkEnvironment(new ForkEnvironment());
    jobDef1.addTask(forkJavaTask);
    NativeTask nativeTask = new NativeTask();
    nativeTask.setName("task3");
    nativeTask.setCommandLine("command");
    jobDef1.addTask(nativeTask);
    InternalJob job1 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    try {
        dbManager.getJobPendingTime(job1.getJobInfo().getJobId().value());
        Assert.fail();
    } catch (RuntimeException e) {
    }
    try {
        dbManager.getJobRunningTime(job1.getJobInfo().getJobId().value());
        Assert.fail();
    } catch (RuntimeException e) {
    }
    checkJobAndTasksNumbers(1, 0, 0, 1, 3, 0, 0, 3);
    checkMeanSubmittingPeriod(job1);
    checkMeanTaskPendingTime(job1);
    checkMeanTaskRunningTime(job1);
    checkNumberOfHosts(job1, 0);
    Thread.sleep(100);
    InternalJob job2 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    checkMeanSubmittingPeriod(job1, job2);
    checkJobAndTasksNumbers(2, 0, 0, 2, 6, 0, 0, 6);
    // job1: task1 started
    job1.start();
    startTask(job1, job1.getTask("task1"));
    dbManager.jobTaskStarted(job1, job1.getTask("task1"), true);
    checkNumberOfHosts(job1, 1);
    checkJobPendingTime(job1);
    checkMeanPendingTime(job1);
    checkMeanTaskPendingTime(job1);
    checkMeanTaskRunningTime(job1);
    checkJobAndTasksNumbers(1, 1, 0, 2, 5, 1, 0, 6);
    // job1: task1 finished
    finishTask(job1, "task1");
    checkJobAndTasksNumbers(1, 1, 0, 2, 5, 0, 1, 6);
    checkMeanTaskRunningTime(job1);
    checkNumberOfHosts(job1, 1);
    // job2: task1 started
    job2.start();
    startTask(job2, job2.getTask("task1"));
    dbManager.jobTaskStarted(job2, job2.getTask("task1"), true);
    checkMeanPendingTime(job1, job2);
    checkMeanTaskRunningTime(job2);
    checkJobAndTasksNumbers(0, 2, 0, 2, 4, 1, 1, 6);
    // job1: task2 and task3 started
    startTask(job1, job1.getTask("task2"));
    dbManager.jobTaskStarted(job1, job1.getTask("task2"), false);
    startTask(job1, job1.getTask("task3"));
    dbManager.jobTaskStarted(job1, job1.getTask("task3"), false);
    checkMeanTaskPendingTime(job1);
    checkMeanTaskRunningTime(job1);
    checkJobAndTasksNumbers(0, 2, 0, 2, 2, 3, 1, 6);
    // job1: task2 and task3 finished, job1 finished
    finishTask(job1, "task2");
    finishTask(job1, "task3");
    checkJobRunningTime(job1);
    checkMeanExecutionTime(job1);
    checkMeanTaskRunningTime(job1);
    checkJobAndTasksNumbers(0, 1, 1, 2, 2, 1, 3, 6);
    checkNumberOfHosts(job1, 1);
    // job2: task1, task2 and task3 finished, job2 finished
    finishTask(job2, "task1");
    finishTask(job2, "task2");
    finishTask(job2, "task3");
    checkJobRunningTime(job2);
    checkMeanExecutionTime(job1, job2);
    checkMeanTaskRunningTime(job2);
    checkJobAndTasksNumbers(0, 0, 2, 2, 0, 0, 6, 6);
    // remove job2
    dbManager.removeJob(job2.getId(), System.currentTimeMillis(), false);
    checkJobAndTasksNumbers(0, 0, 1, 1, 0, 0, 3, 3);
    checkMeanPendingTime(job1, job2);
    checkMeanExecutionTime(job1, job2);
    checkMeanSubmittingPeriod(job1, job2);
    InternalJob job3 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    checkMeanSubmittingPeriod(job1, job2, job3);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) Test(org.junit.Test)

Example 12 with NativeTask

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

the class TestForkedTaskWorkingDir method nativeTask.

private void nativeTask() throws Exception {
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
        File input = createTempDirectory("test", ".input_native", null);
        File output = createTempDirectory("test", ".output_native", null);
        FileUtils.touch(new File(input, "inputFile_native.txt"));
        TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(TestForkedTaskWorkingDir.class.getResource("/functionaltests/descriptors/Job_forked_native_task_working_dir.xml").toURI()).getAbsolutePath());
        job.setInputSpace(input.toURI().toString());
        job.setOutputSpace(output.toURI().toString());
        schedulerHelper.testJobSubmission(job);
        assertTrue(new File(output, "outputFile_native.txt").exists());
    }
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) File(java.io.File)

Example 13 with NativeTask

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

the class SchedulingServiceTest2 method createTestJob.

private TaskFlowJob createTestJob() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    JavaTask task1 = new JavaTask();
    task1.setName("javaTask");
    task1.setExecutableClassName("class");
    task1.setOnTaskError(OnTaskError.CANCEL_JOB);
    job.addTask(task1);
    NativeTask task2 = new NativeTask();
    task2.setName("nativeTask");
    task2.setCommandLine("command line");
    task2.setOnTaskError(OnTaskError.CANCEL_JOB);
    job.addTask(task2);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask)

Example 14 with NativeTask

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

the class SchedulingServiceTest2 method testFailedTask.

private void testFailedTask(boolean failNativeTask) throws Exception {
    service.submitJob(createJob(createTestJob()));
    listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
    Map<JobId, JobDescriptor> jobsMap;
    JobDescriptor jobDesc;
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(2, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    if (failNativeTask) {
        InternalTask nativeTask = ((JobDescriptorImpl) jobDesc).getInternal().getTask("nativeTask");
        // native task terminates with code 1, flag 'cancelJobOnError' was
        // set so job should be cancelled
        service.taskTerminatedWithResult(nativeTask.getId(), new TaskResultImpl(nativeTask.getId(), new RuntimeException(), null, 0));
    } else {
        InternalTask javaTask = ((JobDescriptorImpl) jobDesc).getInternal().getTask("javaTask");
        // java task terminates with exception, flag 'cancelJobOnError' was
        // set so job should be cancelled
        service.taskTerminatedWithResult(javaTask.getId(), new TaskResultImpl(javaTask.getId(), new RuntimeException(), null, 0));
    }
    jobsMap = service.lockJobsToSchedule();
    assertEquals(0, jobsMap.size());
    listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
    infrastructure.assertRequests(2);
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 15 with NativeTask

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

the class SchedulingServiceTest3 method testTaskKill.

@Test
public void testTaskKill() throws Exception {
    service.submitJob(createJob(createTestJob(false)));
    listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
    Map<JobId, JobDescriptor> jobsMap;
    JobDescriptor jobDesc;
    jobsMap = service.lockJobsToSchedule();
    assertEquals(1, jobsMap.size());
    jobDesc = jobsMap.values().iterator().next();
    Assert.assertEquals(2, jobDesc.getEligibleTasks().size());
    for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
        taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
    }
    service.unlockJobsToSchedule(jobsMap.values());
    try {
        service.killTask(jobDesc.getJobId(), "invalid task name");
        Assert.fail();
    } catch (UnknownTaskException e) {
    }
    try {
        service.killTask(JobIdImpl.makeJobId("1234567"), "javaTask");
        Assert.fail();
    } catch (UnknownJobException e) {
    }
    Assert.assertTrue(service.killTask(jobDesc.getJobId(), "javaTask"));
    listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED);
    infrastructure.assertRequests(1);
    Assert.assertFalse(service.killTask(jobDesc.getJobId(), "javaTask"));
    TaskId nativeTaskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("nativeTask").getId();
    service.taskTerminatedWithResult(nativeTaskId, new TaskResultImpl(nativeTaskId, new Integer(0), null, 0));
    listener.assertEvents(SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
    infrastructure.assertRequests(1);
    try {
        service.killTask(jobDesc.getJobId(), "javaTask");
    } catch (UnknownJobException e) {
        Assert.fail("The job should still exist in the memory context as the auto Job removal feature isn't enabled");
    }
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)23 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)21 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)12 Test (org.junit.Test)11 File (java.io.File)10 JobId (org.ow2.proactive.scheduler.common.job.JobId)9 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)8 ArrayList (java.util.ArrayList)6 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)6 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)6 Task (org.ow2.proactive.scheduler.common.task.Task)6 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)6 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)4 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)4 FileNotFoundException (java.io.FileNotFoundException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)3 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)3 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)3