Search in sources :

Example 81 with JavaTask

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

the class SchedulerDbManagerRecoveryTest method testLoadNotFinishedForkEnvironment.

/**
 * Regression test related to issue #1849.
 * <p>
 * https://github.com/ow2-proactive/scheduling/issues/1849
 */
@Test
public void testLoadNotFinishedForkEnvironment() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    JavaTask task1 = new JavaTask();
    task1.setName("task1");
    task1.setExecutableClassName("MyClass");
    JavaTask task2 = new JavaTask();
    task2.setName("task2");
    task2.setExecutableClassName("MyClass");
    task2.addDependence(task1);
    job.addTask(task1);
    job.addTask(task2);
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.addAdditionalClasspath("$USERSPACE/test.jar");
    for (Task task : job.getTasks()) {
        task.setForkEnvironment(forkEnvironment);
    }
    dbManager.newJobSubmitted(Jobs.createJob(job));
    closeAndRestartDatabase();
    List<InternalJob> internalJobs = dbManager.loadNotFinishedJobs(true);
    assertThat(internalJobs).hasSize(1);
    for (InternalTask internalTask : internalJobs.get(0).getITasks()) {
        List<String> additionalClasspath = internalTask.getForkEnvironment().getAdditionalClasspath();
        assertThat(additionalClasspath).hasSize(1);
        assertThat(additionalClasspath.get(0)).isEqualTo("$USERSPACE/test.jar");
    }
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) Test(org.junit.Test) ProActiveTest(org.ow2.tests.ProActiveTest)

Example 82 with JavaTask

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

the class SchedulingServiceTest10 method createTestJob.

private TaskFlowJob createTestJob() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    JavaTask task1 = new JavaTask();
    task1.setExecutableClassName("class");
    task1.setName("task1");
    job.addTask(task1);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 83 with JavaTask

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

the class SchedulingServiceTest5 method createTestJob.

private TaskFlowJob createTestJob() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    JavaTask task1 = new JavaTask();
    task1.setName("task1");
    task1.setExecutableClassName("class");
    job.addTask(task1);
    JavaTask task2 = new JavaTask();
    task2.setName("task2");
    task2.setExecutableClassName("class");
    job.addTask(task2);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 84 with JavaTask

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

the class TestDataspaceScripts method testDataspaceScripts.

/**
 * Creates a task with a Pre/Post/Flow scripts that copy files from input files to output files
 */
@Test
public void testDataspaceScripts() throws Throwable {
    File input = tmpFolder.newFolder("input");
    File output = tmpFolder.newFolder("output");
    File global = tmpFolder.newFolder("global");
    File user = tmpFolder.newFolder("user");
    /**
     * creates the testfile in both input and output spaces
     */
    BufferedOutputStream inout = new BufferedOutputStream(new FileOutputStream(new File(input.getAbsolutePath() + File.separator + fileName + "_input")));
    BufferedOutputStream outout = new BufferedOutputStream(new FileOutputStream(new File(output.getAbsolutePath() + File.separator + fileName + "_output")));
    BufferedOutputStream globout = new BufferedOutputStream(new FileOutputStream(new File(global.getAbsolutePath() + File.separator + fileName + "_global")));
    BufferedOutputStream userout = new BufferedOutputStream(new FileOutputStream(new File(user.getAbsolutePath() + File.separator + fileName + "_user")));
    for (String line : fileContent) {
        inout.write((line + "\n").getBytes());
        outout.write((line + "\n").getBytes());
        globout.write((line + "\n").getBytes());
        userout.write((line + "\n").getBytes());
    }
    inout.close();
    outout.close();
    globout.close();
    userout.close();
    /**
     * single job with single empty task
     */
    TaskFlowJob job = new TaskFlowJob();
    job.setInputSpace(input.toURI().toString());
    job.setOutputSpace(output.toURI().toString());
    job.setGlobalSpace(global.toURI().toString());
    job.setUserSpace(user.toURI().toString());
    JavaTask t = new JavaTask();
    job.addTask(t);
    job.setName(this.getClass().getSimpleName());
    t.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    t.setName("T");
    t.addInputFiles(fileName + "_input", InputAccessMode.TransferFromInputSpace);
    t.addInputFiles(fileName + "_user", InputAccessMode.TransferFromUserSpace);
    t.addInputFiles(fileName + "_global", InputAccessMode.TransferFromGlobalSpace);
    t.addInputFiles(fileName + "_output", InputAccessMode.TransferFromOutputSpace);
    t.addOutputFiles("res_*", OutputAccessMode.TransferToOutputSpace);
    t.addOutputFiles("res_*", OutputAccessMode.TransferToUserSpace);
    t.addOutputFiles("res_*", OutputAccessMode.TransferToGlobalSpace);
    File results = org.ow2.proactive.utils.FileUtils.createTempDirectory("test", ".results", null);
    // for the JS engine on Windows
    String windowsReadyResultsPath = results.getAbsolutePath().replace("\\", "/");
    String scriptContentFiltered = scriptContent.replaceAll(folderMacro, windowsReadyResultsPath);
    t.setPreScript(new SimpleScript(scriptContentFiltered.replaceAll(typeMacro, "pre"), "groovy"));
    t.setPostScript(new SimpleScript(scriptContentFiltered.replaceAll(typeMacro, "post"), "groovy"));
    t.setFlowScript(FlowScript.createLoopFlowScript(scriptContentFiltered.replaceAll(typeMacro, "flow"), "groovy", "T"));
    t.setForkEnvironment(new ForkEnvironment());
    /**
     * job submission, wait on result, removal
     */
    JobId id = schedulerHelper.testJobSubmission(job);
    assertFalse(schedulerHelper.getJobResult(id).hadException());
    /**
     * check content of the files created by the script
     */
    checkFile(new File(output, "res_" + "pre" + fileName + "_user"));
    checkFile(new File(output, "res_" + "pre" + fileName + "_global"));
    checkFile(new File(output, "res_" + "pre" + fileName + "_input"));
    checkFile(new File(output, "res_" + "pre" + fileName + "_output"));
    checkFile(new File(output, "res_" + "post" + fileName + "_user"));
    checkFile(new File(output, "res_" + "post" + fileName + "_global"));
    checkFile(new File(output, "res_" + "post" + fileName + "_input"));
    checkFile(new File(output, "res_" + "post" + fileName + "_output"));
    checkFile(new File(output, "res_" + "flow" + fileName + "_user"));
    checkFile(new File(output, "res_" + "flow" + fileName + "_global"));
    checkFile(new File(output, "res_" + "flow" + fileName + "_input"));
    checkFile(new File(output, "res_" + "flow" + fileName + "_output"));
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 85 with JavaTask

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

the class TestUserSpace method testUserSpace.

@Test
public void testUserSpace() throws Throwable {
    File in = tmpFolder.newFolder("input_space");
    String inPath = in.getAbsolutePath();
    File out = tmpFolder.newFolder("output_space");
    String outPath = out.getAbsolutePath();
    FileSystemManager fsManager = VFSFactory.createDefaultFileSystemManager();
    Scheduler sched = schedulerHelper.getSchedulerInterface();
    String userURI = sched.getUserSpaceURIs().get(0);
    assertTrue(userURI.startsWith("file:"));
    log("User URI is " + userURI);
    String userPath = new File(new URI(userURI)).getAbsolutePath();
    FileObject pathReplaceFO = fsManager.resolveFile(userURI + "/" + pathReplaceFile);
    if (pathReplaceFO.exists()) {
        pathReplaceFO.delete();
    }
    /**
     * Writes inFiles in INPUT
     */
    writeFiles(inFiles, inPath);
    File testPathRepl = new File(inPath + File.separator + pathReplaceFile);
    testPathRepl.createNewFile();
    PrintWriter out2 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(testPathRepl))));
    out2.print(pathReplaceFile);
    out2.close();
    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.setForkEnvironment(new ForkEnvironment());
    A.setName("A");
    for (String[] file : inFiles) {
        A.addInputFiles(file[0], InputAccessMode.TransferFromInputSpace);
        A.addOutputFiles(file[0] + ".glob.A", OutputAccessMode.TransferToUserSpace);
    }
    A.setPreScript(new SimpleScript(scriptA, "groovy"));
    job.addTask(A);
    JavaTask B = new JavaTask();
    B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    B.setForkEnvironment(new ForkEnvironment());
    B.setName("B");
    B.addDependence(A);
    for (String[] file : inFiles) {
        B.addInputFiles(file[0] + ".glob.A", InputAccessMode.TransferFromUserSpace);
        B.addOutputFiles(file[0] + ".out", OutputAccessMode.TransferToOutputSpace);
    }
    B.setPreScript(new SimpleScript(scriptB, "groovy"));
    job.addTask(B);
    JobId id = sched.submit(job);
    schedulerHelper.waitForEventJobFinished(id);
    JobResult jr = schedulerHelper.getJobResult(id);
    Assert.assertFalse(jr.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));
        File inf = new File(inPath + File.separator + inFile[0]);
    }
    for (String[] file : inFiles) {
        FileObject outFile = fsManager.resolveFile(userURI + "/" + file[0] + ".glob.A");
        log("Checking existence of " + outFile.getURL());
        assertTrue(outFile.getURL() + " exists", outFile.exists());
        File outFile2 = new File(userPath, file[0] + ".glob.A");
        log("Checking existence of " + outFile2);
        assertTrue(outFile2 + " exists", outFile2.exists());
    }
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) 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) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) URI(java.net.URI) FileObject(org.apache.commons.vfs2.FileObject) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)104 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)104 Test (org.junit.Test)44 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)24 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)20 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)18 JobId (org.ow2.proactive.scheduler.common.job.JobId)14 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)14 EmptyTask (org.ow2.proactive.scheduler.examples.EmptyTask)13 SelectionScript (org.ow2.proactive.scripting.SelectionScript)12 SimpleScript (org.ow2.proactive.scripting.SimpleScript)12 File (java.io.File)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)11 HashMap (java.util.HashMap)10 Task (org.ow2.proactive.scheduler.common.task.Task)9 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)7 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)6 EmptyExecutable (functionaltests.executables.EmptyExecutable)5 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5