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());
}
}
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);
}
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"));
}
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;
}
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;
}
Aggregations