Search in sources :

Example 16 with JavaTask

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

the class TestGlobalSpace method testGlobalSpace.

@Test
public void testGlobalSpace() throws Throwable {
    File in = tmpFolder.newFolder("input_space");
    String inPath = in.getAbsolutePath();
    File out = tmpFolder.newFolder("output_space");
    String outPath = out.getAbsolutePath();
    writeFiles(inFiles, inPath);
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    job.setInputSpace(in.toURI().toURL().toString());
    job.setOutputSpace(out.toURI().toURL().toString());
    JavaTask A = new JavaTask();
    A.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    A.setName("A");
    for (String[] file : inFiles) {
        A.addInputFiles(file[0], InputAccessMode.TransferFromInputSpace);
        A.addOutputFiles(file[0] + ".glob.A", OutputAccessMode.TransferToGlobalSpace);
    }
    A.setPreScript(new SimpleScript(scriptA, "groovy"));
    A.setForkEnvironment(new ForkEnvironment());
    job.addTask(A);
    JavaTask B = new JavaTask();
    B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    B.setName("B");
    B.addDependence(A);
    for (String[] file : inFiles) {
        B.addInputFiles(file[0] + ".glob.A", InputAccessMode.TransferFromGlobalSpace);
        B.addOutputFiles(file[0] + ".out", OutputAccessMode.TransferToOutputSpace);
    }
    B.setPreScript(new SimpleScript(scriptB, "groovy"));
    B.setForkEnvironment(new ForkEnvironment());
    job.addTask(B);
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    JobId id = scheduler.submit(job);
    schedulerHelper.waitForEventJobFinished(id);
    assertFalse(schedulerHelper.getJobResult(id).hadException());
    /**
     * check: inFiles > IN > LOCAL A > GLOBAL > LOCAL B > OUT
     */
    for (String[] inFile : inFiles) {
        File f = new File(outPath + File.separator + inFile[0] + ".out");
        assertTrue("File does not exist: " + f.getAbsolutePath(), f.exists());
        Assert.assertEquals("Original and copied files differ", inFile[1], FileUtils.readFileToString(f));
        f.delete();
        File inf = new File(inPath + File.separator + inFile[0]);
        inf.delete();
    }
    /**
     * check that the file produced is accessible in the global user space via the scheduler API
     */
    String globalURI = scheduler.getGlobalSpaceURIs().get(0);
    assertTrue(globalURI.startsWith("file:"));
    String globalPath = new File(new URI(globalURI)).getAbsolutePath();
    FileSystemManager fsManager = VFSFactory.createDefaultFileSystemManager();
    for (String[] file : inFiles) {
        FileObject outFile = fsManager.resolveFile(globalURI + "/" + file[0] + ".glob.A");
        log("Checking existence of " + outFile.getURL());
        assertTrue(outFile.getURL() + " exists", outFile.exists());
        File outFile2 = new File(globalPath, file[0] + ".glob.A");
        log("Checking existence of " + outFile2);
        assertTrue(outFile2 + " exists", outFile2.exists());
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) FileObject(org.apache.commons.vfs2.FileObject) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) URI(java.net.URI) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 17 with JavaTask

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

the class TestWorkflowDataspace method testJavaTask.

private void testJavaTask() throws Throwable {
    String tmpdir = System.getProperty("java.io.tmpdir");
    File inputSpace = new File(tmpdir + File.separator + "inputSpace." + System.currentTimeMillis());
    File outputSpace = new File(tmpdir + File.separator + "outputSpace." + System.currentTimeMillis());
    inputSpace.mkdir();
    outputSpace.mkdir();
    for (int it = 0; it < 3; it++) {
        for (int dup = 0; dup < 3; dup++) {
            File f = new File(inputSpace.getCanonicalPath() + File.separator + it + "_" + dup + ".in");
            f.createNewFile();
            BufferedWriter out = new BufferedWriter(new FileWriter(f));
            out.write("it " + it + " dup " + dup + "\n");
            out.close();
        }
    }
    TaskFlowJob job = new TaskFlowJob();
    job.setName(TestWorkflowDataspace.class.getSimpleName());
    job.setInputSpace(inputSpace.toURI().toURL().toString());
    job.setOutputSpace(outputSpace.toURI().toURL().toString());
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    JavaTask t = new JavaTask();
    t.setName("T");
    t.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    t.setFlowScript(FlowScript.createReplicateFlowScript("runs = 3;"));
    t.setFlowBlock(FlowBlock.START);
    t.setForkEnvironment(forkEnvironment);
    job.addTask(t);
    JavaTask t1 = new JavaTask();
    t1.setName("T1");
    t1.setForkEnvironment(forkEnvironment);
    t1.setExecutableClassName(JobWorkflowDataspace.class.getCanonicalName());
    t1.setForkEnvironment(new ForkEnvironment());
    t1.addDependence(t);
    t1.addInputFiles("$PA_TASK_ITERATION_$PA_TASK_REPLICATION.in", InputAccessMode.TransferFromInputSpace);
    t1.addOutputFiles("$PA_TASK_ITERATION_$PA_TASK_REPLICATION.out", OutputAccessMode.TransferToOutputSpace);
    job.addTask(t1);
    JavaTask t2 = new JavaTask();
    t2.setName("T2");
    t2.setForkEnvironment(forkEnvironment);
    t2.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    t2.addDependence(t1);
    t2.setFlowScript(// 
    FlowScript.createLoopFlowScript(// 
    "if (variables.get('PA_TASK_ITERATION') < 2) {" + // 
    "loop = true;" + // 
    "} else {" + // 
    "loop = false;" + "}", "T"));
    t2.setFlowBlock(FlowBlock.END);
    job.addTask(t2);
    JobId id = TWorkflowJobs.testJobSubmission(schedulerHelper, job, null);
    Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
    for (int it = 0; it < 3; it++) {
        for (int dup = 0; dup < 3; dup++) {
            File f = new File(outputSpace.getCanonicalPath() + File.separator + it + "_" + dup + ".out");
            Assert.assertTrue("Missing output file " + f.getName(), f.exists());
            BufferedReader in = new BufferedReader(new FileReader(f));
            String line = in.readLine();
            Assert.assertTrue("Wrong content for " + f.getCanonicalPath(), line.equals("it " + it + " dup " + dup));
        }
    }
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) JobWorkflowDataspace(functionaltests.workflow.JobWorkflowDataspace) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 18 with JavaTask

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

the class BaseSchedulerDBTest method createDefaultTask.

protected static JavaTask createDefaultTask(String taskName) {
    JavaTask task = new JavaTask();
    task.setName(taskName);
    task.setExecutableClassName(TestDummyExecutable.class.getName());
    return task;
}
Also used : JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 19 with JavaTask

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

the class SchedulerDbManagerConcurrencyTest method createAndInsertJob.

public InternalJob createAndInsertJob() throws Exception {
    TaskFlowJob jobDef = new TaskFlowJob();
    JavaTask javaTask = createDefaultTask("java task");
    javaTask.setExecutableClassName(TestDummyExecutable.class.getName());
    jobDef.addTask(javaTask);
    return defaultSubmitJob(jobDef);
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 20 with JavaTask

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

the class SchedulerTasksStateRecoverIntegrationTest method testRecover.

@Test
public void testRecover() throws Exception {
    SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
    RecoveredSchedulerState state = recoverHelper.recover(-1);
    Assert.assertEquals(0, state.getFinishedJobs().size());
    Assert.assertEquals(0, state.getRunningJobs().size());
    Assert.assertEquals(0, state.getPendingJobs().size());
    TaskFlowJob job1 = new TaskFlowJob();
    JavaTask task1 = createDefaultTask("task1");
    JavaTask task2 = createDefaultTask("task2");
    JavaTask task3 = createDefaultTask("task3");
    task1.addDependence(task2);
    task1.addDependence(task3);
    task2.addDependence(task3);
    job1.addTask(task1);
    job1.addTask(task2);
    job1.addTask(task3);
    InternalJob job = defaultSubmitJob(job1);
    JobStateMatcher expectedJob;
    expectedJob = job(job.getId(), JobStatus.PENDING).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
    state = checkRecoveredState(recoverHelper.recover(-1), state().withPending(expectedJob));
    job = state.getPendingJobs().get(0);
    TaskDescriptor task = job.getJobDescriptor().getEligibleTasks().iterator().next();
    Assert.assertEquals(2, task.getChildren().size());
    Assert.assertEquals(0, task.getParents().size());
    job.terminate();
    dbManager.updateAfterTaskFinished(job, null, null);
    expectedJob = job(job.getId(), JobStatus.FINISHED).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
    state = checkRecoveredState(recoverHelper.recover(-1), state().withFinished(expectedJob));
    job = state.getFinishedJobs().get(0);
    task = job.getJobDescriptor().getEligibleTasks().iterator().next();
    Assert.assertEquals(2, task.getChildren().size());
    Assert.assertEquals(0, task.getParents().size());
}
Also used : RecoveredSchedulerState(org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState) TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) Test(org.junit.Test)

Aggregations

JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)96 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)92 Test (org.junit.Test)40 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)22 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)18 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)17 JobId (org.ow2.proactive.scheduler.common.job.JobId)14 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)12 EmptyTask (org.ow2.proactive.scheduler.examples.EmptyTask)11 SelectionScript (org.ow2.proactive.scripting.SelectionScript)10 SimpleScript (org.ow2.proactive.scripting.SimpleScript)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)9 File (java.io.File)8 HashMap (java.util.HashMap)7 Task (org.ow2.proactive.scheduler.common.task.Task)7 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)6 EmptyExecutable (functionaltests.executables.EmptyExecutable)5 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)4