use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class SchedulingTaskComparator method computeHashForSelectionScripts.
private void computeHashForSelectionScripts(InternalTask task, InternalJob job) {
List<SelectionScript> scriptList = SchedulingMethodImpl.resolveScriptVariables(task.getSelectionScripts(), task.getRuntimeVariables());
for (SelectionScript script : scriptList) {
SelectionScript modifiedScript = script;
try {
Map<String, Serializable> bindings = SchedulingMethodImpl.createBindingsForSelectionScripts(job, task);
modifiedScript = SchedulingMethodImpl.replaceBindingsInsideScript(script, bindings);
} catch (Exception e) {
logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
}
try {
digests.add(new String(modifiedScript.digest()));
} catch (Exception e) {
logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
}
}
}
use of org.ow2.proactive.scripting.SelectionScript 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.SelectionScript in project scheduling by ow2-proactive.
the class TestKillWhenInStoppedState method createPendingJob.
private TaskFlowJob createPendingJob() throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName("Test pending job");
job.setOnTaskError(OnTaskError.CONTINUE_JOB_EXECUTION);
JavaTask javaTask = new JavaTask();
javaTask.setExecutableClassName(TestJavaTask.class.getName());
javaTask.setName(TASK_NAME2);
javaTask.setSelectionScript(new SelectionScript("selected = false;", "JavaScript", false));
job.addTask(javaTask);
return job;
}
use of org.ow2.proactive.scripting.SelectionScript 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;
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class TestTaskNotStarted method createJob1.
/*
* Job with one task, task's selection script always returns 'false' so task can't start
*/
private TaskFlowJob createJob1() throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_1");
JavaTask javaTask = new JavaTask();
javaTask.setExecutableClassName(EmptyTask.class.getName());
javaTask.setName("task1");
SelectionScript selScript = new SelectionScript("selected = false;", "js");
javaTask.setSelectionScript(selScript);
job.addTask(javaTask);
return job;
}
Aggregations