Search in sources :

Example 46 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript 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 47 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class TestTaskAttributes method testScripts.

@Test
public void testScripts() throws Exception {
    TaskFlowJob jobDef = new TaskFlowJob();
    JavaTask task1 = createDefaultTask("task1");
    task1.addSelectionScript(new SelectionScript("selection1", "js", new String[] { "param1", "param2" }, true));
    task1.addSelectionScript(new SelectionScript("selection2", "js", new String[] { "param3" }, false));
    task1.addSelectionScript(new SelectionScript("selection3", "js"));
    task1.setCleaningScript(new SimpleScript("cleanscript", "js", new String[] { "p1", "p2" }));
    task1.setPreScript(new SimpleScript("prescript", "js", new String[] { "p1", "p2" }));
    task1.setPostScript(new SimpleScript("postscript", "js", new String[] { "p1", "p2" }));
    task1.setFlowScript(FlowScript.createContinueFlowScript());
    jobDef.addTask(task1);
    InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
    InternalTask task = job.getTask("task1");
    Assert.assertEquals("cleanscript", task.getCleaningScript().getScript());
    Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getCleaningScript().getParameters());
    Assert.assertEquals("prescript", task.getPreScript().getScript());
    Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getPreScript().getParameters());
    Assert.assertEquals("postscript", task.getPostScript().getScript());
    Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getPostScript().getParameters());
    Assert.assertEquals(FlowActionType.CONTINUE.toString(), task.getFlowScript().getActionType());
    Assert.assertEquals(3, task.getSelectionScripts().size());
    Set<String> scripts = new HashSet<>();
    for (SelectionScript script : task.getSelectionScripts()) {
        scripts.add(script.getScript());
        if (script.getScript().equals("selection1")) {
            Assert.assertArrayEquals(new String[] { "param1", "param2" }, script.getParameters());
        }
        if (script.getScript().equals("selection2")) {
            Assert.assertArrayEquals(new String[] { "param3" }, script.getParameters());
        }
        if (script.getScript().equals("selection3")) {
            Assert.assertArrayEquals(new String[] {}, script.getParameters());
        }
    }
    Set<String> expected = new HashSet<>();
    expected.add("selection1");
    expected.add("selection2");
    expected.add("selection3");
    Assert.assertEquals(expected, scripts);
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 48 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class TestTaskAttributes method testForkEnv.

@Test
public void testForkEnv() throws Exception {
    JavaTask task = createDefaultTask("task");
    ForkEnvironment env = new ForkEnvironment();
    task.setForkEnvironment(env);
    InternalTask taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertNotNull(taskData.getForkEnvironment());
    env = new ForkEnvironment();
    env.setEnvScript(new SimpleScript("forkenvscript", "js", new String[] { "p1", "p2" }));
    task.setForkEnvironment(env);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertNotNull(taskData.getForkEnvironment().getEnvScript());
    Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getForkEnvironment().getEnvScript().getParameters());
    env = new ForkEnvironment();
    env.setJavaHome("javahome");
    env.setWorkingDir("workingdir");
    env.addAdditionalClasspath("classpath");
    env.addJVMArgument("jvmargument");
    env.addSystemEnvironmentVariable("var1", "value1");
    StringBuilder longString = buildLongString();
    env.addSystemEnvironmentVariable("longvar", longString.toString());
    task.setForkEnvironment(env);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertEquals("javahome", taskData.getForkEnvironment().getJavaHome());
    Assert.assertEquals("workingdir", taskData.getForkEnvironment().getWorkingDir());
    Assert.assertEquals(1, taskData.getForkEnvironment().getAdditionalClasspath().size());
    Assert.assertEquals("classpath", taskData.getForkEnvironment().getAdditionalClasspath().get(0));
    Assert.assertEquals(1, taskData.getForkEnvironment().getJVMArguments().size());
    Assert.assertEquals("jvmargument", taskData.getForkEnvironment().getJVMArguments().get(0));
    Assert.assertEquals(2, taskData.getForkEnvironment().getSystemEnvironment().size());
    Assert.assertEquals("value1", taskData.getForkEnvironment().getSystemEnvironment().get("var1"));
    Assert.assertEquals(longString.toString(), taskData.getForkEnvironment().getSystemEnvironment().get("longvar"));
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Test(org.junit.Test)

Example 49 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class TestUnauthorizedScripts method createJob.

public Job createJob(String forkScriptContent, String cleanScriptContent) throws InvalidScriptException, UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_forkAndClean");
    ScriptTask taskWithFork = new ScriptTask();
    taskWithFork.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.setEnvScript(new SimpleScript(forkScriptContent, "groovy"));
    taskWithFork.setForkEnvironment(forkEnvironment);
    ScriptTask taskWithClean = new ScriptTask();
    taskWithClean.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    taskWithClean.setCleaningScript(new SimpleScript(cleanScriptContent, "groovy"));
    job.addTask(taskWithFork);
    job.addTask(taskWithClean);
    return job;
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 50 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class TestUnauthorizedScripts method createJobSelection.

public Job createJobSelection(String selectionScriptContent) throws InvalidScriptException, UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_selection");
    ScriptTask taskWithSelection = new ScriptTask();
    taskWithSelection.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    taskWithSelection.addSelectionScript(new SelectionScript(new SimpleScript(selectionScriptContent, "groovy"), true));
    job.addTask(taskWithSelection);
    return job;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript)

Aggregations

SimpleScript (org.ow2.proactive.scripting.SimpleScript)99 TaskScript (org.ow2.proactive.scripting.TaskScript)78 Test (org.junit.Test)68 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)64 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)31 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)31 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)19 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 File (java.io.File)16 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)13 Serializable (java.io.Serializable)12 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)8 HashMap (java.util.HashMap)7 JobId (org.ow2.proactive.scheduler.common.job.JobId)7