Search in sources :

Example 36 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class NodesCleaner method cleanAndRelease.

/**
 * Cleans nodes in parallel for the nodes specified.
 *
 * @param nodes to be cleaned
 * @return true if all the nodes were freed, false if error occurs on one of the node (it will be marked as down in this case)
 */
public BooleanWrapper cleanAndRelease(List<RMNode> nodes) {
    List<Callable<Boolean>> cleaners = new LinkedList<>();
    for (RMNode node : nodes) {
        logger.debug("Cleaning the node " + node.getNodeURL());
        cleaners.add(new NodeCleaner(node));
    }
    try {
        Collection<Future<Boolean>> cleanNodes = scriptExecutorThreadPool.invokeAll(cleaners);
        int index = 0;
        for (Future<Boolean> cleanNode : cleanNodes) {
            RMNode node = nodes.get(index);
            if (!cleanNode.isCancelled()) {
                Boolean isClean = null;
                try {
                    isClean = cleanNode.get();
                    if (!isClean.booleanValue()) {
                        logger.warn("Cannot clean the node " + node.getNodeURL());
                        rmcore.setDownNode(node.getNodeURL());
                    } else {
                        logger.debug("The node " + node.getNodeURL() + " has been successfully cleaned");
                    }
                } catch (ExecutionException e) {
                    logger.warn("Cannot clean the node " + node.getNodeURL(), e);
                    rmcore.setDownNode(node.getNodeURL());
                }
            } else {
                logger.warn("Cannot clean the node " + node.getNodeURL());
                rmcore.setDownNode(node.getNodeURL());
            }
            index++;
        }
        // in this case rmcore.setFreeNodes() will return false
        return rmcore.setFreeNodes(nodes);
    } catch (InterruptedException e) {
        logger.error("", e);
    }
    return new BooleanWrapper(false);
}
Also used : Callable(java.util.concurrent.Callable) LinkedList(java.util.LinkedList) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)36 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)10 Test (org.junit.Test)9 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)7 Matchers.anyString (org.mockito.Matchers.anyString)5 Node (org.objectweb.proactive.core.node.Node)5 HashSet (java.util.HashSet)4 Client (org.ow2.proactive.resourcemanager.authentication.Client)4 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)4 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)4 NodeSet (org.ow2.proactive.utils.NodeSet)4 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)3 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)3 RMProxyUserInterface (org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)3 RMTHelper (functionaltests.utils.RMTHelper)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 HttpResponse (org.apache.http.HttpResponse)2 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)2 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)2