Search in sources :

Example 26 with NativeTask

use of org.ow2.proactive.scheduler.common.task.NativeTask 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 27 with NativeTask

use of org.ow2.proactive.scheduler.common.task.NativeTask 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 28 with NativeTask

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

the class TestWorkingDirStaticCommand method testWorkingDirStaticCommand.

@Test
public void testWorkingDirStaticCommand() throws Throwable {
    String task1Name = "task1";
    JobId id = null;
    // set system Property for executable path
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            System.setProperty(executablePathPropertyName, new File(executablePathWindows.toURI()).getAbsolutePath());
            System.setProperty(WorkingDirPropertyName, new File(workingDirPath.toURI()).getAbsolutePath());
            // test submission and event reception
            TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
            List<String> command = new ArrayList<>();
            command.add("cmd");
            command.add("/C");
            String[] tabCommand = ((NativeTask) job.getTask("task1")).getCommandLine();
            for (int i = 0; i < tabCommand.length; i++) {
                if (i == 0)
                    command.add("\"\"" + tabCommand[i] + "\"");
                else if (i == tabCommand.length - 1)
                    command.add("\"" + tabCommand[i] + "\"\"");
                else
                    command.add("\"" + tabCommand[i] + "\"");
            }
            ((NativeTask) job.getTask("task1")).setCommandLine(command.toArray(new String[command.size()]));
            id = schedulerHelper.testJobSubmission(job);
            break;
        case unix:
            System.setProperty(executablePathPropertyName, new File(executablePath.toURI()).getAbsolutePath());
            System.setProperty(WorkingDirPropertyName, new File(workingDirPath.toURI()).getAbsolutePath());
            SchedulerTHelper.setExecutable(new File(executablePath.toURI()).getAbsolutePath());
            // test submission and event reception
            id = schedulerHelper.testJobSubmission(new File(jobDescriptor.toURI()).getAbsolutePath());
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    // remove job
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) ArrayList(java.util.ArrayList) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 29 with NativeTask

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

the class SchedulingServiceTest3 method createTestJob.

private TaskFlowJob createTestJob(boolean cancelJobOnError) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    JavaTask task1 = new JavaTask();
    task1.setName("javaTask");
    task1.setExecutableClassName("class");
    task1.setOnTaskError(cancelJobOnError ? OnTaskError.CANCEL_JOB : OnTaskError.NONE);
    job.addTask(task1);
    NativeTask task2 = new NativeTask();
    task2.setName("nativeTask");
    task2.setCommandLine("command line");
    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 30 with NativeTask

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

the class TestJobRemove method createJob.

private TaskFlowJob createJob(int tasksNumber) throws Exception {
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.addAdditionalClasspath("lib/ProActive/ProActive.jar", "compile/lib/ant.jar");
    TaskFlowJob jobDef = new TaskFlowJob();
    jobDef.addGenericInformation("k1", "v1");
    jobDef.addGenericInformation("k2", "v2");
    // add data with non-null ifBranch
    JavaTask A = createDefaultTask("A");
    A.setForkEnvironment(forkEnvironment);
    FlowScript ifScript = FlowScript.createIfFlowScript("branch = \"if\";", "B", "C", null);
    A.setFlowScript(ifScript);
    jobDef.addTask(A);
    JavaTask B = createDefaultTask("B");
    B.setForkEnvironment(forkEnvironment);
    jobDef.addTask(B);
    JavaTask C = createDefaultTask("C");
    C.setForkEnvironment(forkEnvironment);
    jobDef.addTask(C);
    for (int i = 0; i < tasksNumber; i++) {
        JavaTask task1 = new JavaTask();
        task1.setName("javaTask-" + i);
        task1.setExecutableClassName(TestDummyExecutable.class.getName());
        task1.addArgument("arg1", "arg1");
        task1.addArgument("arg2", "arg2");
        setAttributes(task1);
        JavaTask task2 = new JavaTask();
        task2.setName("forkedJavaTask-" + i);
        task2.setExecutableClassName(TestDummyExecutable.class.getName());
        ForkEnvironment forkEnv = new ForkEnvironment();
        forkEnv.addAdditionalClasspath("lib/ProActive/ProActive.jar");
        forkEnv.addAdditionalClasspath("compile/lib/ant.jar");
        forkEnv.addJVMArgument("jvmArg1");
        forkEnv.addJVMArgument("jvmArg2");
        forkEnv.addSystemEnvironmentVariable("e1", "v1");
        forkEnv.addSystemEnvironmentVariable("e2", "v2");
        forkEnv.setEnvScript(new SimpleScript("env script", "javascript", new String[] { "param1", "param2" }));
        task2.setForkEnvironment(forkEnv);
        task2.addArgument("arg1", "arg1");
        task2.addArgument("arg2", "arg2");
        setAttributes(task2);
        NativeTask task3 = new NativeTask();
        task3.setName("nativeTask-" + i);
        task3.setCommandLine("command1", "command2", "command3");
        setAttributes(task3);
        task1.addDependence(task2);
        task3.addDependence(task2);
        task1.setForkEnvironment(forkEnvironment);
        task2.setForkEnvironment(forkEnvironment);
        task3.setForkEnvironment(forkEnvironment);
        jobDef.addTask(task1);
        jobDef.addTask(task2);
        jobDef.addTask(task3);
    }
    return jobDef;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript)

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