Search in sources :

Example 16 with SelectionScript

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

the class SelectionScriptEvaluator method evaluateScript.

private static void evaluateScript(String selectionScript) {
    try {
        final ScriptHandler localHandler = ScriptLoader.createLocalHandler();
        final ScriptResult<Boolean> result = localHandler.handle(new SelectionScript(new File(selectionScript), null));
        if (result.errorOccured()) {
            result.getException().printStackTrace(System.err);
            System.exit(3);
        }
    } catch (InvalidScriptException e) {
        System.exit(2);
    }
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) File(java.io.File) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 17 with SelectionScript

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);
        }
    }
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) Serializable(java.io.Serializable)

Example 18 with SelectionScript

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);
}
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 19 with SelectionScript

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;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 20 with SelectionScript

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;
}
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

SelectionScript (org.ow2.proactive.scripting.SelectionScript)42 Test (org.junit.Test)18 File (java.io.File)13 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)10 NodeSet (org.ow2.proactive.utils.NodeSet)10 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)9 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)9 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)9 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)6 SelectionManager (org.ow2.proactive.resourcemanager.selection.SelectionManager)6 SelectionManagerTest (org.ow2.proactive.resourcemanager.selection.SelectionManagerTest)6 SimpleScript (org.ow2.proactive.scripting.SimpleScript)6 TestNode (functionaltests.utils.TestNode)5 Criteria (org.ow2.proactive.utils.Criteria)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 HashSet (java.util.HashSet)3 Node (org.objectweb.proactive.core.node.Node)3