Search in sources :

Example 21 with ScriptResult

use of org.ow2.proactive.scripting.ScriptResult 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 22 with ScriptResult

use of org.ow2.proactive.scripting.ScriptResult 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 23 with ScriptResult

use of org.ow2.proactive.scripting.ScriptResult 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 24 with ScriptResult

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

the class ProbablisticSelectionManager method processScriptResult.

/**
 * Processes script result and updates knowledge base of
 * selection manager at the same time.
 *
 * @param script - executed script
 * @param scriptResult - obtained script result
 * @param rmnode - node on which script has been executed
 * @return whether node is selected
 */
@Override
public synchronized boolean processScriptResult(SelectionScript script, Map<String, Serializable> bindings, ScriptResult<Boolean> scriptResult, RMNode rmnode) {
    boolean result = false;
    SelectionScript scriptWithReplacedBindings = replaceBindings(script, bindings);
    try {
        String digest = new String(scriptWithReplacedBindings.digest());
        Probability probability = new Probability(Probability.defaultValue());
        if (probabilities.containsKey(digest) && probabilities.get(digest).containsKey(rmnode.getNodeURL())) {
            probability = probabilities.get(digest).get(rmnode.getNodeURL());
            assert (probability.value() >= 0 && probability.value() <= 1);
        }
        if (scriptResult == null || scriptResult.errorOccured() || !scriptResult.getResult()) {
            // error during script execution or script returned false
            if (scriptWithReplacedBindings.isDynamic()) {
                probability.decrease();
            } else {
                probability = Probability.ZERO;
            }
        } else {
            // script passed
            result = true;
            if (scriptWithReplacedBindings.isDynamic()) {
                probability.increase();
            } else {
                probability = Probability.ONE;
            }
        }
        if (!probabilities.containsKey(digest)) {
            // checking if the number of selection script does not exceeded the maximum
            if (probabilities.size() >= PAResourceManagerProperties.RM_SELECT_SCRIPT_CACHE_SIZE.getValueAsInt()) {
                String oldest = digestQueue.poll();
                probabilities.remove(oldest);
                if (logger.isDebugEnabled()) {
                    logger.debug("Removing the script: " + scriptWithReplacedBindings.hashCode() + " from the data base because the limit is reached");
                }
            }
            // adding a new script record
            probabilities.put(digest, new HashMap<String, Probability>());
            logger.debug("Scripts cache size " + probabilities.size());
            digestQueue.offer(digest);
        }
        if (logger.isDebugEnabled()) {
            logger.debug(rmnode.getNodeURL() + " : script " + scriptWithReplacedBindings.hashCode() + ", probability " + probability);
        }
        probabilities.get(digest).put(rmnode.getNodeURL().intern(), probability);
    } catch (NoSuchAlgorithmException e) {
        logger.error(e.getMessage(), e);
    }
    return result;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 25 with ScriptResult

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

the class TestExecRemote method processBuilderScript.

private void processBuilderScript(String miscDir, boolean isLinux, String valueToEcho, HashSet<String> nodesUrls) throws Exception {
    File sFile = new File(miscDir + "processBuilder.groovy");
    RMTHelper.log("Test 4 - Test " + sFile);
    String[] cmd = (isLinux) ? new String[] { "/bin/bash", "-c", "echo " + valueToEcho } : new String[] { "cmd.exe", "/c", "@(echo " + valueToEcho + ")" };
    SimpleScript script = new SimpleScript(sFile, cmd);
    List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODE_URL.toString(), nodesUrls);
    assertFalse("The results must not be empty", results.size() == 0);
    for (ScriptResult<Object> res : results) {
        String output = res.getOutput();
        assertTrue("The script output must contains " + valueToEcho, output.contains(valueToEcho));
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript) File(java.io.File)

Aggregations

ScriptResult (org.ow2.proactive.scripting.ScriptResult)18 SelectionScript (org.ow2.proactive.scripting.SelectionScript)10 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)8 Test (org.junit.Test)7 SimpleScript (org.ow2.proactive.scripting.SimpleScript)7 SelectionManager (org.ow2.proactive.resourcemanager.selection.SelectionManager)6 SelectionManagerTest (org.ow2.proactive.resourcemanager.selection.SelectionManagerTest)6 File (java.io.File)5 Serializable (java.io.Serializable)4 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)4 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)4 IOException (java.io.IOException)3 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 LoginException (javax.security.auth.login.LoginException)2 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)2 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)2