Search in sources :

Example 21 with SelectionScript

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

Example 22 with SelectionScript

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

the class ProbabilisticSelectionManagerTest method testIncreasingProbabilityDynamic.

@Test
public void testIncreasingProbabilityDynamic() throws Exception {
    int nbNodes = 10;
    SelectionScript script = new SelectionScript("test", "groovy", true);
    ManagerObjects managerObjects = new ManagerObjects(nbNodes).invoke();
    SelectionManager selectionManager = managerObjects.getSelectionManager();
    ArrayList<RMNode> freeNodes = managerObjects.getFreeNodes();
    for (int i = 0; i < nbNodes; i++) {
        // we increase the probability for each node, lowest node has the min number of true results
        for (int j = 0; j < i + 1; j++) {
            selectionManager.processScriptResult(script, Collections.EMPTY_MAP, new ScriptResult<>(true), freeNodes.get(i));
        }
    }
    List<RMNode> arrangedNodes = selectionManager.arrangeNodesForScriptExecution(freeNodes, Collections.singletonList(script), Collections.EMPTY_MAP);
    // nodes are expected to be sorted in reverse order
    for (int i = 0; i < nbNodes; i++) {
        Assert.assertEquals("mocked-node-" + (nbNodes - i), arrangedNodes.get(i).getNodeName());
        Assert.assertFalse(selectionManager.isPassed(script, Collections.EMPTY_MAP, arrangedNodes.get(i)));
    }
}
Also used : SelectionManager(org.ow2.proactive.resourcemanager.selection.SelectionManager) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) SelectionManagerTest(org.ow2.proactive.resourcemanager.selection.SelectionManagerTest) Test(org.junit.Test)

Example 23 with SelectionScript

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

the class ProbabilisticSelectionManagerTest method testDecreasingProbabilityErrorsDynamicScriptWithoutDynamicityStorage.

@Test
public void testDecreasingProbabilityErrorsDynamicScriptWithoutDynamicityStorage() throws Exception {
    int nbNodes = 10;
    PAResourceManagerProperties.RM_SELECT_SCRIPT_NODE_DYNAMICITY.updateProperty("0");
    try {
        SelectionScript script = new SelectionScript("test", "groovy", true);
        ManagerObjects managerObjects = new ManagerObjects(nbNodes).invoke();
        SelectionManager selectionManager = managerObjects.getSelectionManager();
        ArrayList<RMNode> freeNodes = managerObjects.getFreeNodes();
        for (int i = 0; i < nbNodes; i++) {
            // we decrease the probability for each node, lowest node has the max number of script exceptions
            for (int j = i; j < nbNodes; j++) {
                selectionManager.processScriptResult(script, Collections.EMPTY_MAP, new ScriptResult<Boolean>(new IllegalArgumentException("amistake")), freeNodes.get(i));
            }
        }
        List<RMNode> arrangedNodes = selectionManager.arrangeNodesForScriptExecution(freeNodes, Collections.singletonList(script), Collections.EMPTY_MAP);
        // list is supposed to contain all nodes because of dynamicity == 0
        Assert.assertEquals(freeNodes.size(), arrangedNodes.size());
        // nodes are expected to be sorted in reverse order
        for (int i = 0; i < nbNodes; i++) {
            Assert.assertEquals("mocked-node-" + (nbNodes - i), arrangedNodes.get(i).getNodeName());
            Assert.assertFalse(selectionManager.isPassed(script, Collections.EMPTY_MAP, arrangedNodes.get(i)));
        }
    } finally {
        PAResourceManagerProperties.RM_SELECT_SCRIPT_NODE_DYNAMICITY.updateProperty("300000");
    }
}
Also used : SelectionManager(org.ow2.proactive.resourcemanager.selection.SelectionManager) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) SelectionManagerTest(org.ow2.proactive.resourcemanager.selection.SelectionManagerTest) Test(org.junit.Test)

Example 24 with SelectionScript

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

the class ProbabilisticSelectionManagerTest method testVariableBindings.

@Test
public void testVariableBindings() throws Exception {
    SelectionScript script = new SelectionScript("variables.get(\"TOTO\")", "groovy", false);
    ManagerObjects managerObjects = new ManagerObjects(1).invoke();
    SelectionManager selectionManager = managerObjects.getSelectionManager();
    ArrayList<RMNode> freeNodes = managerObjects.getFreeNodes();
    Map<String, Serializable> bindings = Collections.singletonMap("TOTO", (Serializable) "value");
    selectionManager.processScriptResult(script, Collections.singletonMap("TOTO", (Serializable) "value"), new ScriptResult<>(true), freeNodes.get(0));
    Assert.assertTrue(selectionManager.isPassed(script, Collections.singletonMap("TOTO", (Serializable) "value"), freeNodes.get(0)));
    Assert.assertFalse(selectionManager.isPassed(script, Collections.singletonMap("TOTO", (Serializable) "differentValue"), freeNodes.get(0)));
    Assert.assertFalse(selectionManager.isPassed(script, Collections.<String, Serializable>emptyMap(), freeNodes.get(0)));
    selectionManager.processScriptResult(script, Collections.singletonMap("TOTO", (Serializable) "differentValue"), new ScriptResult<>(true), freeNodes.get(0));
    Assert.assertTrue(selectionManager.isPassed(script, Collections.singletonMap("TOTO", (Serializable) "differentValue"), freeNodes.get(0)));
    Assert.assertTrue(selectionManager.isPassed(script, Collections.singletonMap("TOTO", (Serializable) "value"), freeNodes.get(0)));
}
Also used : SelectionManager(org.ow2.proactive.resourcemanager.selection.SelectionManager) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Serializable(java.io.Serializable) SelectionManagerTest(org.ow2.proactive.resourcemanager.selection.SelectionManagerTest) Test(org.junit.Test)

Example 25 with SelectionScript

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

the class FlatJobFactory method createNativeTaskFromCommandString.

/**
 * Creates a native task from a string representing a native command to execute.
 * @param command a String representing a native command.
 * @param taskName an eventual name for the task.
 * @param selectionScriptPath path to an existing file containing a selection script code.
 * @return a NativeTask object that can be put in a Job Object.
 * @throws InvalidScriptException if an error occurs in definition of selection script
 * from file path specified.
 */
private NativeTask createNativeTaskFromCommandString(String command, String taskName, String selectionScriptPath) throws InvalidScriptException {
    NativeTask desc = new NativeTask();
    desc.setCommandLine(Tools.parseCommandLine(command));
    desc.setName(taskName);
    if (selectionScriptPath != null) {
        SelectionScript script = new SelectionScript(new SimpleScript(new File(selectionScriptPath), null), true);
        desc.addSelectionScript(script);
    }
    return desc;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) File(java.io.File)

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