use of org.ow2.proactive.scripting.SimpleScript 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"));
}
use of org.ow2.proactive.scripting.SimpleScript 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());
}
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class TestJobRemove method setAttributes.
private void setAttributes(Task task) throws Exception {
task.addGenericInformation("k1", "v1");
task.addGenericInformation("k2", "v2");
SimpleScript script = new SimpleScript(task.getName() + "selection script", "javascript", new String[] { "param1", "param2" });
SelectionScript ss1 = new SelectionScript(script, true);
SelectionScript ss2 = new SelectionScript(script, false);
task.addSelectionScript(ss1);
task.addSelectionScript(ss2);
task.setPreScript(new SimpleScript(task.getName() + "pre script", "javascript", new String[] { "param1", "param2" }));
task.setPostScript(new SimpleScript(task.getName() + "post script", "javascript", new String[] { "param1", "param2" }));
task.setCleaningScript(new SimpleScript(task.getName() + "clean script", "javascript", new String[] { "param1", "param2" }));
task.setFlowScript(FlowScript.createContinueFlowScript());
task.addInputFiles("f1", InputAccessMode.TransferFromGlobalSpace);
task.addInputFiles("f2", InputAccessMode.TransferFromInputSpace);
task.addInputFiles("f3", InputAccessMode.TransferFromUserSpace);
task.addOutputFiles("f1", OutputAccessMode.TransferToGlobalSpace);
task.addOutputFiles("f2", OutputAccessMode.TransferToOutputSpace);
task.addOutputFiles("f3", OutputAccessMode.TransferToUserSpace);
}
use of org.ow2.proactive.scripting.SimpleScript 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;
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs method createJobWithAllKindOfScripts.
private TaskFlowJob createJobWithAllKindOfScripts() throws InvalidScriptException, UserException {
TaskFlowJob jobDef = new TaskFlowJob();
JavaTask t = task("T");
ForkEnvironment forkEnvironment = new ForkEnvironment();
SimpleScript aScript = new SimpleScript("", "");
forkEnvironment.setEnvScript(aScript);
t.setPreScript(aScript);
t.setPostScript(aScript);
t.setCleaningScript(aScript);
t.setSelectionScript(new SelectionScript("", ""));
t.setFlowScript(FlowScript.createContinueFlowScript());
t.setForkEnvironment(forkEnvironment);
jobDef.addTask(t);
return jobDef;
}
Aggregations