Search in sources :

Example 6 with Topology

use of org.ow2.proactive.resourcemanager.frontend.topology.Topology in project scheduling by ow2-proactive.

the class SelectionTest method action.

@Test
public void action() throws Exception {
    String currentHost = System.getenv("HOSTNAME");
    // checking if properties distantHost and neighborHost are defined
    String distantHost = System.getProperty("distantHost");
    String neighborHost = System.getProperty("neighborHost");
    if (distantHost != null && !distantHost.equals("${distantHost}") && neighborHost != null && !neighborHost.equals("${neighborHost}")) {
        String rmHome = System.getProperty("pa.rm.home");
        String rmCredPath = rmHome + "/config/authentication/rm.cred";
        String javaExec = System.getenv("JAVA_HOME") + "/bin/java";
        // properties are defined, trying to deploy nodes to these hosts
        BooleanWrapper result = rmHelper.getResourceManager().createNodeSource("remote", SSHInfrastructure.class.getName(), new Object[] { // ssh options
        "", // java executable path
        javaExec, // rmHelper distrib path
        rmHome, // node lookup timeout
        "30000", // attempts
        "2", // os
        "Linux", // java options
        "", // rmHelper credential
        FileToBytesConverter.convertFileToByteArray(new File(rmCredPath)), (distantHost + " 2\n" + neighborHost).getBytes() }, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
        if (result.getBooleanValue()) {
            rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
            rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
            rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
            // wait for the nodes to be in free state
            rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
            rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
            rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        }
    // we are good - all remote nodes registered
    } else {
        // no parameters provided
        RMTHelper.log("Nothing to do. Set up distantHost & neighborHost parameters.");
        return;
    }
    // creating the selection script object
    SelectionScript script = new SelectionScript(new File(vmPropSelectionScriptpath), new String[] { this.vmPropKey1, this.vmPropValue1 }, true);
    List<SelectionScript> scriptList = new LinkedList<>();
    scriptList.add(script);
    ResourceManager resourceManager = rmHelper.getResourceManager();
    String node1 = "node1";
    // a node with the VM properties
    HashMap<String, String> vmProperties = new HashMap<>();
    vmProperties.put(this.vmPropKey1, this.vmPropValue1);
    testNode = rmHelper.createNode(node1, vmProperties);
    String node1URL = testNode.getNode().getNodeInformation().getURL();
    resourceManager.addNode(node1URL, NodeSource.DEFAULT);
    // wait node adding event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
    // wait for the nodes to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // so now we have 9 node in total
    // 6 local nodes (5 default, 1 marked with property)
    // 2 nodes on distant host
    // 1 node on neighbor host
    Assert.assertEquals(9, resourceManager.getState().getFreeNodesNumber());
    // checking TopologyDescriptor.ARBITRARY
    NodeSet ns = resourceManager.getAtMostNodes(1, TopologyDescriptor.ARBITRARY, null, null);
    Assert.assertEquals(1, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(8, TopologyDescriptor.ARBITRARY, null, null);
    Assert.assertEquals(8, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.ARBITRARY, null, null);
    Assert.assertEquals(9, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.ARBITRARY, scriptList, null);
    Assert.assertEquals(1, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    // checking TopologyDescriptor.BEST_PROXIMITY
    ns = resourceManager.getAtMostNodes(1, TopologyDescriptor.BEST_PROXIMITY, null, null);
    Assert.assertEquals(1, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(9, TopologyDescriptor.BEST_PROXIMITY, null, null);
    Assert.assertEquals(9, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.BEST_PROXIMITY, null, null);
    Assert.assertEquals(9, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    // Node pivotNode = null;
    ns = resourceManager.getAtMostNodes(6, TopologyDescriptor.BEST_PROXIMITY, null, null);
    Assert.assertEquals(6, ns.size());
    for (Node node : ns) {
        // pivotNode = node;
        if (!node.getNodeInformation().getURL().contains(currentHost)) {
            Assert.assertTrue("All nodes have to be from " + currentHost, false);
        }
    }
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(7, TopologyDescriptor.BEST_PROXIMITY, null, null);
    Assert.assertEquals(7, ns.size());
    for (Node node : ns) {
        if (node.getNodeInformation().getURL().contains(distantHost)) {
            Assert.assertTrue("Node from distant host selected", false);
        }
    }
    resourceManager.releaseNodes(ns).getBooleanValue();
    // pivot scenario
    // List<Node> pivot = new LinkedList<Node>();
    // pivot.add(pivotNode);
    // ns = resourceManager.getAtMostNodes(6,
    // new BestProximityDescriptor(BestProximityDescriptor.MAX, pivot), null, null);
    // Assert.assertEquals(6, ns.size());
    // for (Node node : ns) {
    // if (node.getNodeInformation().getURL().equals(pivotNode.getNodeInformation().getURL())) {
    // Assert.assertTrue("Pivot must not be in results", false);
    // }
    // if (node.getNodeInformation().getURL().contains(distantHost)) {
    // Assert.assertTrue("Node from distant host selected", false);
    // }
    // }
    // resourceManager.releaseNodes(ns).getBooleanValue();
    // 
    // ns = resourceManager.getAtMostNodes(7,
    // new BestProximityDescriptor(BestProximityDescriptor.MAX, pivot), null, null);
    // Assert.assertEquals(7, ns.size());
    // for (Node node : ns) {
    // if (node.getNodeInformation().getURL().equals(pivotNode.getNodeInformation().getURL())) {
    // Assert.assertTrue("Pivot must not be in results", false);
    // }
    // }
    // resourceManager.releaseNodes(ns).getBooleanValue();
    // checking TopologyDescriptor.ThresholdProximityDescriptor
    ns = resourceManager.getAtMostNodes(1, new ThresholdProximityDescriptor(Long.MAX_VALUE), null, null);
    Assert.assertEquals(1, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(9, new ThresholdProximityDescriptor(Long.MAX_VALUE), null, null);
    Assert.assertEquals(9, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, new ThresholdProximityDescriptor(Long.MAX_VALUE), null, null);
    Assert.assertEquals(9, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    // getting information about topology
    Topology topology = resourceManager.getTopology();
    Assert.assertEquals(3, topology.getHosts().size());
    // looking for distances consistency
    Long current2neighborDistance = topology.getDistance(currentHost, neighborHost);
    Long current2distantDistance = topology.getDistance(currentHost, distantHost);
    Long distant2neightborDistance = topology.getDistance(neighborHost, distantHost);
    if (current2neighborDistance == null || current2distantDistance == null) {
        Assert.assertTrue("Please put full host names to the parameters", false);
    }
    if (current2neighborDistance > current2distantDistance) {
        Assert.assertTrue("Distant host is close to current than neighbor according to the topology", false);
    }
    System.out.println("Distance between " + currentHost + " and " + neighborHost + " is " + current2neighborDistance);
    System.out.println("Distance between " + currentHost + " and " + distantHost + " is " + current2distantDistance);
    System.out.println("Distance between " + neighborHost + " and " + distantHost + " is " + distant2neightborDistance);
    long maxThreshold = Math.max(current2neighborDistance, Math.max(current2distantDistance, distant2neightborDistance));
    ns = resourceManager.getAtMostNodes(100, new ThresholdProximityDescriptor(current2neighborDistance - 1), null, null);
    Assert.assertEquals(6, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, new ThresholdProximityDescriptor(current2neighborDistance), null, null);
    Assert.assertEquals(7, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, new ThresholdProximityDescriptor(maxThreshold - 1), null, null);
    for (Node node : ns) {
        if (node.getNodeInformation().getURL().contains(distantHost)) {
            Assert.assertTrue("Node from distant host selected", false);
        }
    }
    Assert.assertEquals(7, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(10, new ThresholdProximityDescriptor(maxThreshold), null, null);
    Assert.assertEquals(9, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    // pivot scenario
    // ns = resourceManager.getAtMostNodes(1, new ThresholdProximityDescriptor(0, pivot), null, null);
    // Assert.assertEquals(1, ns.size());
    // for (Node node : ns) {
    // if (node.getNodeInformation().getURL().equals(pivotNode.getNodeInformation().getURL())) {
    // Assert.assertTrue("Pivot must not be in results", false);
    // }
    // if (node.getNodeInformation().getURL().contains(distantHost) ||
    // node.getNodeInformation().getURL().contains(neighborHost)) {
    // Assert.assertTrue("Incorrect node selected", false);
    // }
    // }
    // resourceManager.releaseNodes(ns).getBooleanValue();
    // 
    // ns = resourceManager.getAtMostNodes(6, new ThresholdProximityDescriptor(current2neighborDistance,
    // pivot), null, null);
    // Assert.assertEquals(6, ns.size());
    // for (Node node : ns) {
    // if (node.getNodeInformation().getURL().equals(pivotNode.getNodeInformation().getURL())) {
    // Assert.assertTrue("Pivot must not be in results", false);
    // }
    // if (node.getNodeInformation().getURL().contains(distantHost)) {
    // Assert.assertTrue("Node from distant host selected", false);
    // }
    // }
    // resourceManager.releaseNodes(ns).getBooleanValue();
    // checking TopologyDescriptor.SINGLE_HOST
    ns = resourceManager.getAtMostNodes(1, TopologyDescriptor.SINGLE_HOST, null, null);
    Assert.assertEquals(1, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(9, TopologyDescriptor.SINGLE_HOST, null, null);
    Assert.assertEquals(6, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.SINGLE_HOST, null, null);
    Assert.assertEquals(6, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.SINGLE_HOST, scriptList, null);
    Assert.assertEquals(1, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    // checking TopologyDescriptor.SINGLE_HOST_EXCLUSIVE
    ns = resourceManager.getAtMostNodes(1, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, null, null);
    Assert.assertEquals(1, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    if (!ns.get(0).getNodeInformation().getURL().contains(neighborHost)) {
        Assert.assertTrue("Neighbor host shold be selected", false);
    }
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(9, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, null, null);
    Assert.assertEquals(6, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(2, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, null, null);
    Assert.assertEquals(2, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(3, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, null, null);
    Assert.assertEquals(3, ns.size());
    Assert.assertEquals(3, ns.getExtraNodes().size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, scriptList, null);
    // no hosts matched selection script
    Assert.assertEquals(0, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, null, null);
    // return the host with max capacity
    Assert.assertEquals(6, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    // checking TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE
    ns = resourceManager.getAtMostNodes(1, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(1, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(2, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(2, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(3, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(3, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(9, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(9, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(8, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, null, null);
    // current + distant has to be selected
    Assert.assertEquals(8, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(7, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, null, null);
    // current + neighbor has to be selected
    Assert.assertEquals(7, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, scriptList, null);
    // selection script specified => no such set
    Assert.assertEquals(0, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(100, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, null, null);
    // get max possible capacity
    Assert.assertEquals(9, ns.size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    // checking TopologyDescriptor.ONE_NODE_PER_HOST_EXCLUSIVE
    ns = resourceManager.getAtMostNodes(1, TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(1, ns.size());
    Assert.assertEquals(null, ns.getExtraNodes());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(2, TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(2, ns.size());
    Assert.assertEquals(1, ns.getExtraNodes().size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(3, TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(3, ns.size());
    Assert.assertEquals(6, ns.getExtraNodes().size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    ns = resourceManager.getAtMostNodes(4, TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE, null, null);
    Assert.assertEquals(3, ns.size());
    Assert.assertEquals(6, ns.getExtraNodes().size());
    resourceManager.releaseNodes(ns).getBooleanValue();
    PAFuture.waitFor(resourceManager.removeNodeSource("remote", true));
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) SSHInfrastructure(org.ow2.proactive.resourcemanager.nodesource.infrastructure.SSHInfrastructure) HashMap(java.util.HashMap) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) Node(org.objectweb.proactive.core.node.Node) ThresholdProximityDescriptor(org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Topology(org.ow2.proactive.resourcemanager.frontend.topology.Topology) LinkedList(java.util.LinkedList) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) SelectionScript(org.ow2.proactive.scripting.SelectionScript) File(java.io.File) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 7 with Topology

use of org.ow2.proactive.resourcemanager.frontend.topology.Topology in project scheduling by ow2-proactive.

the class TopologyNodesFilterTest method unifedTestMethod.

private void unifedTestMethod(TopologyDescriptor topology, int requiredNodesNumber, Map<String, Integer> groupedNodeByHost, int outputNodesNumber) {
    Criteria crit = new Criteria(requiredNodesNumber);
    crit.setTopology(topology);
    crit.setScripts(null);
    crit.setBlackList(null);
    crit.setBestEffort(false);
    List<RMNode> arrangedNodes = new ArrayList<>();
    for (String host : groupedNodeByHost.keySet()) {
        for (int i = 0; i < groupedNodeByHost.get(host); i++) {
            arrangedNodes.add(createMockeNode(host));
        }
    }
    List<RMNode> arrangedFilteredNodes = new TopologyNodesFilter().filterNodes(crit, arrangedNodes);
    assertEquals(outputNodesNumber, arrangedFilteredNodes.size());
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) ArrayList(java.util.ArrayList) Criteria(org.ow2.proactive.utils.Criteria)

Example 8 with Topology

use of org.ow2.proactive.resourcemanager.frontend.topology.Topology in project scheduling by ow2-proactive.

the class Attribute method createParallelEnvironment.

/**
 * Creates the parallel environment element for the given task. Corresponds
 * to <define name="parallel">
 *
 * @return the {@link XMLTags#PARALLEL_ENV} element if the task has a
 *         parallel environment, null otherwise
 */
private Element createParallelEnvironment(Document doc, Task task) {
    ParallelEnvironment penv = task.getParallelEnvironment();
    if (penv == null)
        return null;
    Element parallelEnvE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.PARALLEL_ENV.getXMLName());
    setAttribute(parallelEnvE, XMLAttributes.TASK_NB_NODES, Integer.toString(penv.getNodesNumber()));
    // <ref name="topology"/>
    TopologyDescriptor topologyDescr = penv.getTopologyDescriptor();
    if (topologyDescr != null) {
        // <choice>
        // <ref name="arbitrary"/>
        // <ref name="bestProximity"/>
        // <ref name="thresholdProximity"/>
        // <ref name="singleHost"/>
        // <ref name="singleHostExclusive"/>
        // <ref name="multipleHostsExclusive"/>
        // <ref name="differentHostsExclusive"/>
        // </choice>
        Element topologyE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY.getXMLName());
        Element topologyDescrE = null;
        if (topologyDescr instanceof ArbitraryTopologyDescriptor) {
            topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_ARBITRARY.getXMLName());
        } else if (topologyDescr instanceof ThresholdProximityDescriptor) {
            topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_THRESHOLD_PROXIMITY.getXMLName());
            long threshold = ((ThresholdProximityDescriptor) topologyDescr).getThreshold();
            topologyDescrE.setAttribute(XMLAttributes.TOPOLOGY_THRESHOLD.getXMLName(), Long.toString(threshold));
        } else if (topologyDescr instanceof BestProximityDescriptor) {
            topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_BEST_PROXIMITY.getXMLName());
        } else if (topologyDescr instanceof SingleHostExclusiveDescriptor) {
            topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_SINGLE_HOST_EXCLUSIVE.getXMLName());
        } else if (topologyDescr instanceof SingleHostDescriptor) {
            topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_SINGLE_HOST.getXMLName());
        } else if (topologyDescr instanceof MultipleHostsExclusiveDescriptor) {
            topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_MULTIPLE_HOSTS_EXCLUSIVE.getXMLName());
        }
        if (topologyDescr instanceof DifferentHostsExclusiveDescriptor) {
            topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_DIFFERENT_HOSTS_EXCLUSIVE.getXMLName());
        }
        if (topologyDescrE != null) {
            topologyE.appendChild(topologyDescrE);
        }
        parallelEnvE.appendChild(topologyE);
    }
    return parallelEnvE;
}
Also used : DifferentHostsExclusiveDescriptor(org.ow2.proactive.topology.descriptor.DifferentHostsExclusiveDescriptor) ParallelEnvironment(org.ow2.proactive.scheduler.common.task.ParallelEnvironment) ArbitraryTopologyDescriptor(org.ow2.proactive.topology.descriptor.ArbitraryTopologyDescriptor) Element(org.w3c.dom.Element) ThresholdProximityDescriptor(org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor) BestProximityDescriptor(org.ow2.proactive.topology.descriptor.BestProximityDescriptor) SingleHostExclusiveDescriptor(org.ow2.proactive.topology.descriptor.SingleHostExclusiveDescriptor) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor) ArbitraryTopologyDescriptor(org.ow2.proactive.topology.descriptor.ArbitraryTopologyDescriptor) SingleHostDescriptor(org.ow2.proactive.topology.descriptor.SingleHostDescriptor) MultipleHostsExclusiveDescriptor(org.ow2.proactive.topology.descriptor.MultipleHostsExclusiveDescriptor)

Example 9 with Topology

use of org.ow2.proactive.resourcemanager.frontend.topology.Topology in project scheduling by ow2-proactive.

the class SelectionManager method doSelectNodes.

private NodeSet doSelectNodes(Criteria criteria, Client client) {
    boolean hasScripts = criteria.getScripts() != null && criteria.getScripts().size() > 0;
    boolean loggerIsDebugEnabled = logger.isDebugEnabled();
    if (loggerIsDebugEnabled) {
        logger.debug(client + " requested " + criteria.getSize() + " nodes with " + criteria.getTopology());
        if (hasScripts) {
            logger.debug("Selection scripts:");
            for (SelectionScript s : criteria.getScripts()) {
                logger.debug(s);
            }
        }
        if (criteria.getBlackList() != null && criteria.getBlackList().size() > 0) {
            logger.debug("Black list nodes:");
            for (Node n : criteria.getBlackList()) {
                logger.debug(n);
            }
        }
    }
    // can throw Exception if topology is disabled
    TopologyHandler handler = RMCore.topologyManager.getHandler(criteria.getTopology());
    int totalNumberOfAliveNodesRightNow = rmcore.getTotalAliveNodesNumber();
    List<RMNode> freeNodes = rmcore.getFreeNodes();
    // filtering out the "free node list"
    // removing exclusion and checking permissions
    List<RMNode> filteredNodes = filterOut(freeNodes, criteria, client);
    if (filteredNodes.size() == 0) {
        if (loggerIsDebugEnabled) {
            logger.debug(client + " will get 0 nodes");
        }
        return new NodeSet();
    }
    // arranging nodes according to the selection policy
    // if could be shuffling or node source priorities
    List<RMNode> afterPolicyNodes = selectionPolicy.arrangeNodes(criteria.getSize(), filteredNodes, client);
    List<Node> matchedNodes;
    if (hasScripts) {
        // checking if all scripts are authorized
        checkAuthorizedScripts(criteria.getScripts());
        // arranging nodes for script execution
        List<RMNode> arrangedNodes = arrangeNodesForScriptExecution(afterPolicyNodes, criteria.getScripts(), criteria.getBindings());
        List<RMNode> arrangedFilteredNodes = arrangedNodes;
        if (criteria.getTopology().isTopologyBased()) {
            arrangedFilteredNodes = topologyNodesFilter.filterNodes(criteria, arrangedNodes);
        }
        if (arrangedFilteredNodes.isEmpty()) {
            matchedNodes = new LinkedList<>();
        } else if (electedToRunOnAllNodes(criteria)) {
            // run scripts on all available nodes
            matchedNodes = runScripts(arrangedFilteredNodes, criteria);
        } else {
            // run scripts not on all nodes, but always on missing number of
            // nodes
            // until required node set is found
            matchedNodes = new LinkedList<>();
            while (matchedNodes.size() < criteria.getSize()) {
                int numberOfNodesForScriptExecution = criteria.getSize() - matchedNodes.size();
                if (numberOfNodesForScriptExecution < PAResourceManagerProperties.RM_SELECTION_MAX_THREAD_NUMBER.getValueAsInt()) {
                    // we can run
                    // "PAResourceManagerProperties.RM_SELECTION_MAX_THREAD_NUMBER.getValueAsInt()"
                    // scripts in parallel
                    // in case when we need less nodes it still useful to
                    // the full capacity of the thread pool to find nodes
                    // quicker
                    // it is not important if we find more nodes than needed
                    // subset will be selected later (topology handlers)
                    numberOfNodesForScriptExecution = PAResourceManagerProperties.RM_SELECTION_MAX_THREAD_NUMBER.getValueAsInt();
                }
                List<RMNode> subset = arrangedFilteredNodes.subList(0, Math.min(numberOfNodesForScriptExecution, arrangedFilteredNodes.size()));
                matchedNodes.addAll(runScripts(subset, criteria));
                // removing subset of arrangedNodes
                subset.clear();
                if (arrangedFilteredNodes.size() == 0) {
                    break;
                }
            }
            if (loggerIsDebugEnabled) {
                logger.debug(matchedNodes.size() + " nodes found after scripts execution for " + client);
            }
        }
    } else {
        matchedNodes = new LinkedList<>();
        for (RMNode node : afterPolicyNodes) {
            matchedNodes.add(node.getNode());
        }
    }
    if (criteria.getTopology().isTopologyBased() && loggerIsDebugEnabled) {
        logger.debug("Filtering nodes with topology " + criteria.getTopology());
    }
    NodeSet selectedNodes = handler.select(criteria.getSize(), matchedNodes);
    if (selectedNodes.size() < criteria.getSize() && !criteria.isBestEffort()) {
        selectedNodes.clear();
        if (selectedNodes.getExtraNodes() != null) {
            selectedNodes.getExtraNodes().clear();
        }
    }
    // the nodes are selected, now mark them as busy.
    for (Node node : selectedNodes) {
        try {
            // Synchronous call
            rmcore.setBusyNode(node.getNodeInformation().getURL(), client);
        } catch (NotConnectedException e) {
            // client has disconnected during getNodes request
            logger.warn(e.getMessage(), e);
            return null;
        }
    }
    // marking extra selected nodes as busy
    if (selectedNodes.size() > 0 && selectedNodes.getExtraNodes() != null) {
        for (Node node : new LinkedList<>(selectedNodes.getExtraNodes())) {
            try {
                // synchronous call
                rmcore.setBusyNode(node.getNodeInformation().getURL(), client);
            } catch (NotConnectedException e) {
                // client has disconnected during getNodes request
                logger.warn(e.getMessage(), e);
                return null;
            }
        }
    }
    if (logger.isInfoEnabled()) {
        String extraNodes = selectedNodes.getExtraNodes() != null && selectedNodes.getExtraNodes().size() > 0 ? " and " + selectedNodes.getExtraNodes().size() + " extra nodes" : "";
        logger.info(client + " requested " + criteria.getSize() + " nodes with " + criteria.getTopology() + " and will get " + selectedNodes.size() + " nodes " + extraNodes + " [totalNumberOfAliveNodesRightNow:" + totalNumberOfAliveNodesRightNow + ";freeNodes:" + freeNodes.size() + ";filteredNodes:" + filteredNodes.size() + ";reordered after policy:" + afterPolicyNodes.size() + ";selection script present:" + hasScripts + ";nodes filtered by selection script:" + matchedNodes.size() + ";selectedNodes:" + selectedNodes.size() + "]");
    }
    if (loggerIsDebugEnabled) {
        for (Node n : selectedNodes) {
            logger.debug(n.getNodeInformation().getURL());
        }
    }
    return selectedNodes;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Node(org.objectweb.proactive.core.node.Node) TopologyHandler(org.ow2.proactive.resourcemanager.selection.topology.TopologyHandler) LinkedList(java.util.LinkedList) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 10 with Topology

use of org.ow2.proactive.resourcemanager.frontend.topology.Topology in project scheduling by ow2-proactive.

the class TopologyManager method addNode.

/**
 * Updates the topology for new node. Executes the pinger on new node when this node belongs
 * to unknow host.
 */
public void addNode(Node node) {
    try {
        rwLock.writeLock().lock();
        if (!PAResourceManagerProperties.RM_TOPOLOGY_ENABLED.getValueAsBoolean()) {
            // do not do anything if topology disabled
            return;
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Adding Node " + node.getNodeInformation().getURL() + " to topology");
        }
        InetAddress host = node.getVMInformation().getInetAddress();
        if (topology.knownHost(host)) {
            // host topology is already known
            if (logger.isDebugEnabled()) {
                logger.debug("The topology information has been already added for node " + node.getNodeInformation().getURL());
            }
            nodesOnHost.get(host).add(node);
            return;
        }
        // unknown host => start pinging process
        NodeSet toPing = new NodeSet();
        HashMap<InetAddress, Long> hostsTopology = new HashMap<>();
        // adding one node from each host
        for (InetAddress h : nodesOnHost.keySet()) {
            // always have at least one node on each host
            if (nodesOnHost.get(h) != null && !nodesOnHost.get(h).isEmpty()) {
                toPing.add(nodesOnHost.get(h).iterator().next());
                hostsTopology.put(h, Long.MAX_VALUE);
            }
        }
        if (PAResourceManagerProperties.RM_TOPOLOGY_DISTANCE_ENABLED.getValueAsBoolean()) {
            hostsTopology = pingNode(node, toPing);
        }
        topology.addHostTopology(node.getVMInformation().getHostName(), host, hostsTopology);
        Set<Node> nodesList = new LinkedHashSet<>();
        nodesList.add(node);
        nodesOnHost.put(node.getVMInformation().getInetAddress(), nodesList);
    } finally {
        rwLock.writeLock().unlock();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Node " + node.getNodeInformation().getURL() + " added.");
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Node(org.objectweb.proactive.core.node.Node) InetAddress(java.net.InetAddress)

Aggregations

NodeSet (org.ow2.proactive.utils.NodeSet)6 TopologyDescriptor (org.ow2.proactive.topology.descriptor.TopologyDescriptor)5 ArrayList (java.util.ArrayList)4 Node (org.objectweb.proactive.core.node.Node)4 ThresholdProximityDescriptor (org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor)4 Criteria (org.ow2.proactive.utils.Criteria)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 IOException (java.io.IOException)2 TopologyDisabledException (org.ow2.proactive.resourcemanager.frontend.topology.TopologyDisabledException)2 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)2 ParallelEnvironment (org.ow2.proactive.scheduler.common.task.ParallelEnvironment)2 RMProxyCreationException (org.ow2.proactive.scheduler.core.rmproxies.RMProxyCreationException)2 SelectionScript (org.ow2.proactive.scripting.SelectionScript)2 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InetAddress (java.net.InetAddress)1 Comparator (java.util.Comparator)1 LinkedHashSet (java.util.LinkedHashSet)1