use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class TestSmartProxy method createTestJob.
protected TaskFlowJob createTestJob(boolean isolateOutputs) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.addAdditionalClasspath(getClasspath(job));
for (int i = 0; i < NB_TASKS; i++) {
JavaTask testTask = new JavaTask();
testTask.setName(TASK_NAME + i);
testTask.setExecutableClassName(SimpleJavaExecutable.class.getName());
testTask.setForkEnvironment(forkEnvironment);
// testTask.
// ------------- create an input File ------------
File inputFile = new File(inputLocalFolder, inputFileBaseName + "_" + i + inputFileExt);
String outputFileName = outputFileBaseName + "_" + i + outputFileExt;
// delete files after the test is finished
File outputFile = new File(outputLocalFolder, outputFileName);
outputFile.deleteOnExit();
inputFile.deleteOnExit();
FileWriter fw = new FileWriter(inputFile);
for (int j = 0; j <= Math.round(Math.random() * 100) + 1; j++) fw.write("Some random input");
fw.close();
// Add dummy input files, make sure no error happen
testTask.addInputFiles("DUMMY", InputAccessMode.TransferFromInputSpace);
testTask.addInputFiles(inputFile.getName(), InputAccessMode.TransferFromInputSpace);
if (isolateOutputs) {
testTask.addOutputFiles("*" + outputFileExt, OutputAccessMode.TransferToOutputSpace);
} else {
testTask.addOutputFiles(outputFileName, OutputAccessMode.TransferToOutputSpace);
}
job.addTask(testTask);
}
job.setInputSpace(dataServerURI);
job.setOutputSpace(dataServerURI);
return job;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class TestProcessTreeKiller method createJavaExecutableJob.
public static TaskFlowJob createJavaExecutableJob(String name, boolean forked) throws UserException {
TaskFlowJob job = new TaskFlowJob();
job.setName(name);
job.setDescription("A command that spawns processes");
JavaTask task = new JavaTask();
if (forked) {
task.setForkEnvironment(new ForkEnvironment());
}
task.addArgument("sleep", 3);
task.addArgument("tname", name);
task.addArgument("home", PASchedulerProperties.SCHEDULER_HOME.getValueAsString());
task.setName(name);
task.setExecutableClassName(JavaSpawnExecutable.class.getName());
job.addTask(task);
return job;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class TestForkedTaskWorkingDir method createFileInLocalSpaceJob.
private TaskFlowJob createFileInLocalSpaceJob(String blockTaskFromTestUrl, String blockTestBeforeKillingNodeUrl) throws Exception {
TaskFlowJob job = new TaskFlowJob();
JavaTask task1 = new JavaTask();
task1.setForkEnvironment(new ForkEnvironment());
task1.setName("task1");
task1.setExecutableClassName(CreateFileInLocalSpaceTask.class.getName());
task1.addArgument("blockTaskFromTestUrl", blockTaskFromTestUrl);
task1.addArgument("blockTestBeforeKillingNodeUrl", blockTestBeforeKillingNodeUrl);
task1.addOutputFiles("output_file.txt", OutputAccessMode.TransferToUserSpace);
job.addTask(task1);
return job;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment 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.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class TestNativeTaskPaths method testNativeTaskPaths.
@Test
public void testNativeTaskPaths() throws Throwable {
File in = File.createTempFile("input", "space");
in.delete();
in.mkdir();
String inPath = in.getAbsolutePath();
File out = File.createTempFile("output", "space");
out.delete();
out.mkdir();
File outc = new File(out, OutVarsFileC);
File outd = new File(out, OutVarsFileD);
if (outc.exists()) {
outc.delete();
}
if (outd.exists()) {
outd.delete();
}
File scriptTestEnv = null;
if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
scriptTestEnv = new File(inPath + File.separator + scriptCLinux);
scriptTestEnv.createNewFile();
PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
out3.print(scriptCLinuxContent);
out3.close();
} else {
scriptTestEnv = new File(inPath + File.separator + scriptCWindows);
scriptTestEnv.createNewFile();
PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
out3.print(scriptCWindowsContent);
out3.close();
}
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
job.setInputSpace(in.toURI().toURL().toString());
job.setOutputSpace(out.toURI().toURL().toString());
// // testing paths pattern
// NativeTask C = new NativeTask();
// C.setName("C");
// C.addOutputFiles(OutVarsFileC, OutputAccessMode.TransferToOutputSpace);
// switch (OperatingSystem.getOperatingSystem()) {
// case windows:
// C.setCommandLine(new String[] { "cmd", "/C",
// "echo \"$JAVA\" \"$PROACTIVE_HOME\" > $LOCALSPACE\\" + OutVarsFileC });
// break;
// case unix:
// C.setCommandLine(new String[] { "/bin/bash", "-c",
// "echo \\\"$JAVA\\\" \\\"$PROACTIVE_HOME\\\" > $LOCALSPACE/" + OutVarsFileC });
// break;
// default:
// throw new IllegalStateException("Unsupported operating system");
// }
// job.addTask(C);
// testing $USERSPACE environment variable
NativeTask D = new NativeTask();
D.setName("D");
if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
D.addInputFiles(scriptCLinux, InputAccessMode.TransferFromInputSpace);
} else {
D.addInputFiles(scriptCWindows, InputAccessMode.TransferFromInputSpace);
}
D.addOutputFiles(OutVarsFileD, OutputAccessMode.TransferToOutputSpace);
switch(OperatingSystem.getOperatingSystem()) {
case windows:
D.setCommandLine(new String[] { "cmd", "/C", scriptCWindows });
break;
case unix:
D.setCommandLine(new String[] { "/bin/bash", "-c", "chmod u+x $localspace/" + scriptCLinux + "; $localspace/" + scriptCLinux });
break;
default:
throw new IllegalStateException("Unsupported operating system");
}
D.setForkEnvironment(new ForkEnvironment("$LOCALSPACE"));
job.addTask(D);
Scheduler sched = schedulerHelper.getSchedulerInterface();
JobId id = sched.submit(job);
schedulerHelper.waitForEventJobFinished(id);
String contentExpected = "foo";
JobResult jr = schedulerHelper.getJobResult(id);
Assert.assertFalse(jr.hadException());
logger.info("Expected : '" + contentExpected + "'");
// logger.info(jr.getAllResults().get("C").getOutput().getAllLogs(true));
// String receivedc = IOUtils.toString(outc.toURI()).trim();
// logger.info("Received C : '" + receivedc + "'");
// Assert.assertEquals(contentExpected.toLowerCase(), receivedc.toLowerCase());
logger.info(jr.getAllResults().get("D").getOutput().getAllLogs(true));
String receivedd = IOUtils.toString(outd.toURI()).trim();
logger.info("Received D : '" + receivedd + "'");
Assert.assertEquals(contentExpected.toLowerCase(), receivedd.toLowerCase());
}
Aggregations