Search in sources :

Example 46 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class SelectionManager method filterOut.

/**
 * Removes exclusion nodes and nodes not accessible for the client
 */
private List<RMNode> filterOut(List<RMNode> freeNodes, Criteria criteria, Client client) {
    NodeSet exclusion = criteria.getBlackList();
    Set<String> inclusion = criteria.getAcceptableNodesUrls();
    boolean nodeWithTokenRequested = criteria.getNodeAccessToken() != null && criteria.getNodeAccessToken().length() > 0;
    TokenPrincipal tokenPrincipal = null;
    if (nodeWithTokenRequested) {
        logger.debug("Node access token specified " + criteria.getNodeAccessToken());
        tokenPrincipal = new TokenPrincipal(criteria.getNodeAccessToken());
        client.getSubject().getPrincipals().add(tokenPrincipal);
    }
    List<RMNode> filteredList = new ArrayList<>();
    HashSet<Permission> clientPermissions = new HashSet<>();
    for (RMNode node : freeNodes) {
        // checking the permission
        try {
            if (!clientPermissions.contains(node.getUserPermission())) {
                client.checkPermission(node.getUserPermission(), client + " is not authorized to get the node " + node.getNodeURL() + " from " + node.getNodeSource().getName());
                clientPermissions.add(node.getUserPermission());
            }
        } catch (SecurityException e) {
            // client does not have an access to this node
            logger.debug(e.getMessage());
            continue;
        }
        // with other tokens but must also filter out nodes without tokens
        if (nodeWithTokenRequested && !node.isProtectedByToken()) {
            continue;
        }
        // we will avoid it here
        if (nodeWithTokenRequested) {
            PrincipalPermission perm = (PrincipalPermission) node.getUserPermission();
            // checking explicitly that node has this token identity
            if (!perm.hasPrincipal(tokenPrincipal)) {
                if (logger.isDebugEnabled()) {
                    logger.debug(client + " does not have required token to get the node " + node.getNodeURL() + " from " + node.getNodeSource().getName());
                }
                continue;
            }
        }
        if (!contains(exclusion, node) && ((inclusion != null) ? inclusion.contains(node.getNodeURL()) : true)) {
            filteredList.add(node);
        }
    }
    return filteredList;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) ArrayList(java.util.ArrayList) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Permission(java.security.Permission) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) TokenPrincipal(org.ow2.proactive.authentication.principals.TokenPrincipal) HashSet(java.util.HashSet)

Example 47 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class SelectionManager method runScripts.

/**
 * Runs scripts on given set of nodes and returns matched nodes. It blocks
 * until all results are obtained.
 *
 * @param candidates
 *            nodes to execute scripts on
 * @param criteria
 *            contains a set of scripts to execute on each node
 * @return nodes matched to all scripts
 */
private List<Node> runScripts(List<RMNode> candidates, Criteria criteria) {
    List<Node> matched = new LinkedList<>();
    if (candidates.size() == 0) {
        return matched;
    }
    // creating script executors object to be run in dedicated thread pool
    List<Callable<Node>> scriptExecutors = new LinkedList<>();
    synchronized (inProgress) {
        if (inProgress.size() > 0) {
            logger.warn(inProgress.size() + " nodes are in process of script execution");
            for (String nodeName : inProgress) {
                logger.warn(nodeName);
            }
            logger.warn("Something is wrong on these nodes");
        }
        for (RMNode node : candidates) {
            if (!inProgress.contains(node.getNodeURL())) {
                inProgress.add(node.getNodeURL());
                scriptExecutors.add(new ScriptExecutor(node, criteria, this));
            }
        }
    }
    try {
        // launching
        Collection<Future<Node>> matchedNodes = scriptExecutorThreadPool.invokeAll(scriptExecutors);
        // waiting for the results
        for (Future<Node> futureNode : matchedNodes) {
            Node node;
            try {
                node = futureNode.get();
                if (node != null) {
                    matched.add(node);
                }
            } catch (InterruptedException e) {
                logger.warn("Interrupting the selection manager");
                return matched;
            } catch (ExecutionException e) {
                logger.warn("Ignoring exception in selection script: " + e.getMessage());
            }
        }
    } catch (InterruptedException e1) {
        logger.warn("Interrupting the selection manager");
    }
    return matched;
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Node(org.objectweb.proactive.core.node.Node) LinkedList(java.util.LinkedList) Callable(java.util.concurrent.Callable) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) PAFuture(org.objectweb.proactive.api.PAFuture) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 48 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode 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 49 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class ProbablisticSelectionManager method arrangeNodesForScriptExecution.

/**
 * Find appropriate candidates nodes for script execution, taking into
 * account "free" and "exclusion" nodes lists.
 *
 * @param scripts set of scripts to execute
 * @param nodes free nodes list provided by resource manager
 * @return candidates node list for script execution
 */
@Override
public List<RMNode> arrangeNodesForScriptExecution(final List<RMNode> nodes, List<SelectionScript> scripts, Map<String, Serializable> bindings) {
    long startTime = System.currentTimeMillis();
    boolean scriptSpecified = scripts != null && scripts.size() > 0;
    // if no scripts are specified return filtered free nodes
    if (!scriptSpecified) {
        return nodes;
    }
    try {
        // finding intersection
        HashMap<RMNode, Probability> intersectionMap = new LinkedHashMap<>();
        for (RMNode rmnode : nodes) {
            boolean intersection = true;
            double intersectionProbability = 1;
            for (SelectionScript script : scripts) {
                SelectionScript scriptWithReplacedBindings = replaceBindings(script, bindings);
                String digest = new String(scriptWithReplacedBindings.digest());
                if (probabilities.containsKey(digest) && probabilities.get(digest).containsKey(rmnode.getNodeURL())) {
                    double probability = probabilities.get(digest).get(rmnode.getNodeURL()).value();
                    if (probability == 0) {
                        intersection = false;
                        break;
                    } else {
                        intersectionProbability *= probability;
                    }
                } else {
                    intersectionProbability *= Probability.defaultValue();
                }
            }
            if (intersection) {
                intersectionMap.put(rmnode, new Probability(intersectionProbability));
            }
        }
        // sorting results based on calculated probability
        Set<RMNode> nodeSet = intersectionMap.keySet();
        List<RMNode> res = new ArrayList<>(nodeSet.size());
        res.addAll(nodeSet);
        Collections.sort(res, new NodeProbabilityComparator(intersectionMap));
        if (logger.isDebugEnabled()) {
            logger.debug("The following nodes are selected for scripts execution (time is " + (System.currentTimeMillis() - startTime) + " ms) :");
            if (res.size() > 0) {
                for (RMNode rmnode : res) {
                    logger.debug(rmnode.getNodeURL() + " : probability " + intersectionMap.get(rmnode));
                }
            } else {
                logger.debug("None");
            }
        }
        return res;
    } catch (NoSuchAlgorithmException e) {
        logger.error(e.getMessage(), e);
        return new ArrayList<>(0);
    }
}
Also used : ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LinkedHashMap(java.util.LinkedHashMap) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) SelectionScript(org.ow2.proactive.scripting.SelectionScript)

Example 50 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class NodesLockRestorationManagerTest method testLockNodeSucceeds.

@Test
public void testLockNodeSucceeds() {
    doReturn(new BooleanWrapper(true)).when(rmCore).lockNodes(anySetOf(String.class), eq(caller));
    verify(rmCore, never()).lockNodes(anySetOf(String.class), eq(caller));
    RMNode rmNode = RMNodeHelper.basicWithMockedInternals().getLeft();
    boolean lockResult = nodesLockRestorationManager.lockNode(rmNode, caller);
    assertThat(lockResult).isTrue();
    verify(rmCore).lockNodes(anySetOf(String.class), eq(caller));
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Test(org.junit.Test)

Aggregations

RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)55 Test (org.junit.Test)27 Node (org.objectweb.proactive.core.node.Node)12 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)12 Client (org.ow2.proactive.resourcemanager.authentication.Client)12 SelectionScript (org.ow2.proactive.scripting.SelectionScript)12 ArrayList (java.util.ArrayList)11 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)11 LinkedList (java.util.LinkedList)10 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)10 SelectionManager (org.ow2.proactive.resourcemanager.selection.SelectionManager)8 NodeState (org.ow2.proactive.resourcemanager.common.NodeState)7 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)7 Permission (java.security.Permission)6 SelectionManagerTest (org.ow2.proactive.resourcemanager.selection.SelectionManagerTest)6 NodeSet (org.ow2.proactive.utils.NodeSet)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 MutableInteger (org.objectweb.proactive.core.util.MutableInteger)5 PrincipalPermission (org.ow2.proactive.permissions.PrincipalPermission)5