Search in sources :

Example 1 with Topology

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

the class HAC method select.

/**
 * Selects a set of closest nodes from specified list.
 * The proximity between nodes is defined by distance function.
 *
 * @param number desired nodes number
 * @param from list of "free" nodes
 * @return list of nodes to be provided to the client
 */
public List<Node> select(int number, List<Node> from) {
    if (from.size() == 0) {
        // return empty list
        return new LinkedList<>();
    }
    // initializing cluster distances map
    // cluster is a group of nodes, initially each cluster consist of one node
    logger.debug("Initializing clusters map");
    HashMap<Cluster<Node>, HashMap<Cluster<Node>, Long>> clusterDistances = initClusterDistances(from);
    // no topology information for provided nodes
    if (from.size() > 0 && clusterDistances.size() == 0) {
        throw new TopologyException("Topology information is not available");
    }
    Cluster<Node> target = null;
    if (pivot.size() > 0) {
        // fixed orientation clustering
        Iterator<Node> it = pivot.iterator();
        Node pivotNode = it.next();
        target = new Cluster<>(getNodeId(pivotNode), pivotNode);
        // merging pivot nodes into one cluster and recalculating distances
        logger.debug("Merging pivot nodes into one cluster");
        while (it.hasNext()) {
            // merging clusters and recalculating distances between others
            pivotNode = it.next();
            Cluster<Node> pivotCluster = new Cluster<>(getNodeId(pivotNode), pivotNode);
            target = recalculateDistances(target, pivotCluster, clusterDistances);
        }
        // clustering centralized to the pivot
        logger.debug("Begin centralized hierarchical agglomerative clustering");
        while (clusterDistances.size() > 1 && target.size() < (number + pivot.size())) {
            Cluster<Node> closest = findClosestClustersTo(target, clusterDistances);
            if (closest == null) {
                // no clusters found => cannot merge anything => stop where we are
                break;
            }
            // merging clusters and recalculating distances between others
            target = recalculateDistances(target, closest, clusterDistances);
        }
        // removing pivot nodes from the result
        target.remove(pivot);
    } else {
        logger.debug("Begin hierarchical agglomerative clustering");
        target = (Cluster<Node>) clusterDistances.keySet().iterator().next();
        Cluster<Node> largest = target;
        // floating clustering
        while (clusterDistances.size() > 1) {
            // finding two clusters to merge according
            Cluster<Node>[] clustersToMerge = findClosestClusters(clusterDistances);
            if (clustersToMerge == null) {
                // stop the process
                break;
            }
            // merging clusters and recalculating distances between others
            target = recalculateDistances(clustersToMerge[0], clustersToMerge[1], clusterDistances);
            if (target.size() >= largest.size()) {
                largest = target;
            }
            if (target.size() == number) {
                // found all the nodes we need
                break;
            } else if (target.size() > number) {
                // found more nodes that we need,
                // target cluster contains all nodes from another cluster
                // largest is the target here
                logger.debug("Number of node in the cluster exceeded required node number " + target.size() + " vs " + number);
                Cluster<Node> anotherCluster = clustersToMerge[0] == target ? clustersToMerge[1] : clustersToMerge[0];
                target.removeLast(anotherCluster.size());
                final Cluster<Node> finalTarget = target;
                Comparator<Node> nodeDistanceComparator = new Comparator<Node>() {

                    public int compare(Node n1, Node n2) {
                        long res = getDistance(n1, finalTarget) - getDistance(n2, finalTarget);
                        if (res < 0) {
                            return -1;
                        } else if (res > 0) {
                            return 1;
                        } else {
                            return 0;
                        }
                    }
                };
                // sorting nodes in the smaller cluster according to their distances to target
                Collections.sort(anotherCluster.getElements(), nodeDistanceComparator);
                int neededNodesNumber = number - target.size();
                target.add(anotherCluster.getElements().subList(0, neededNodesNumber));
                break;
            }
        }
        target = largest;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + target.size() + " nodes out of " + number + ": " + target);
    }
    return target.getElements();
}
Also used : HashMap(java.util.HashMap) Node(org.objectweb.proactive.core.node.Node) LinkedList(java.util.LinkedList) TopologyException(org.ow2.proactive.resourcemanager.frontend.topology.TopologyException) Comparator(java.util.Comparator)

Example 2 with Topology

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

the class StaxJobFactory method createParallelEnvironment.

/**
 * Creates the parallel environment from the xml descriptor.
 */
private ParallelEnvironment createParallelEnvironment(XMLStreamReader cursorTask, Map<String, String> variables) throws JobCreationException {
    int event = -1;
    int nodesNumber = 0;
    TopologyDescriptor topologyDescriptor = null;
    // parallelEnvironment -> <topology>
    try {
        // cursor is parallelEnvironment
        for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
            String attrName = cursorTask.getAttributeLocalName(i);
            if (XMLAttributes.TASK_NB_NODES.matches(attrName)) {
                String value = replace(cursorTask.getAttributeValue(i), variables);
                nodesNumber = Integer.parseInt(value);
            }
        }
        while (cursorTask.hasNext()) {
            event = cursorTask.next();
            if (event == XMLEvent.START_ELEMENT) {
                break;
            } else if (event == XMLEvent.END_ELEMENT && XMLTags.PARALLEL_ENV.matches(cursorTask.getLocalName())) {
                return new ParallelEnvironment(nodesNumber, TopologyDescriptor.ARBITRARY);
            }
        }
        if (XMLTags.TOPOLOGY.matches(cursorTask.getLocalName())) {
            // topology element found
            while (cursorTask.hasNext()) {
                event = cursorTask.next();
                if (event == XMLEvent.START_ELEMENT) {
                    break;
                } else if (event == XMLEvent.END_ELEMENT && XMLTags.TOPOLOGY.matches(cursorTask.getLocalName())) {
                    throw new RuntimeException("Incorrect topology description");
                }
            }
            // arbitrary : no attributes
            if (XMLTags.TOPOLOGY_ARBITRARY.matches(cursorTask.getLocalName())) {
                topologyDescriptor = TopologyDescriptor.ARBITRARY;
            } else // bestProximity : no attributes
            if (XMLTags.TOPOLOGY_BEST_PROXIMITY.matches(cursorTask.getLocalName())) {
                topologyDescriptor = TopologyDescriptor.BEST_PROXIMITY;
            } else // thresholdProximity : elements threshold
            if (XMLTags.TOPOLOGY_THRESHOLD_PROXIMITY.matches(cursorTask.getLocalName())) {
                // attribute threshold
                for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
                    String attrName = cursorTask.getAttributeLocalName(i);
                    if (XMLAttributes.TOPOLOGY_THRESHOLD.matches(attrName)) {
                        String value = replace(cursorTask.getAttributeValue(i), variables);
                        long threshold = Long.parseLong(value);
                        topologyDescriptor = new ThresholdProximityDescriptor(threshold);
                    }
                }
            } else // singleHost : no attributes
            if (XMLTags.TOPOLOGY_SINGLE_HOST.matches(cursorTask.getLocalName())) {
                topologyDescriptor = TopologyDescriptor.SINGLE_HOST;
            } else // singleHostExclusive : no attributes
            if (XMLTags.TOPOLOGY_SINGLE_HOST_EXCLUSIVE.matches(cursorTask.getLocalName())) {
                topologyDescriptor = TopologyDescriptor.SINGLE_HOST_EXCLUSIVE;
            } else // multipleHostsExclusive : no attributes
            if (XMLTags.TOPOLOGY_MULTIPLE_HOSTS_EXCLUSIVE.matches(cursorTask.getLocalName())) {
                topologyDescriptor = TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE;
            } else // oneNodePerHostHostsExclusive : no attributes
            if (XMLTags.TOPOLOGY_DIFFERENT_HOSTS_EXCLUSIVE.matches(cursorTask.getLocalName())) {
                topologyDescriptor = TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE;
            }
        }
    } catch (Exception e) {
        throw new JobCreationException(XMLTags.TOPOLOGY.getXMLName(), null, e);
    }
    return new ParallelEnvironment(nodesNumber, topologyDescriptor);
}
Also used : ParallelEnvironment(org.ow2.proactive.scheduler.common.task.ParallelEnvironment) ThresholdProximityDescriptor(org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor) XMLStreamException(javax.xml.stream.XMLStreamException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) FileNotFoundException(java.io.FileNotFoundException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) IOException(java.io.IOException)

Example 3 with Topology

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

the class TopologyNodesTest method unifedTopologyTestMethod.

private void unifedTopologyTestMethod(TopologyDescriptor topology, int requiredNodesNumber, Map<String, Integer> groupedNodeByHost, int outputNodesNumber) throws ClassNotFoundException {
    Criteria crit = new Criteria(requiredNodesNumber);
    crit.setTopology(topology);
    crit.setScripts(null);
    crit.setBlackList(null);
    crit.setBestEffort(false);
    List<Node> arrangedNodes = new ArrayList<>();
    for (String host : groupedNodeByHost.keySet()) {
        for (int i = 0; i < groupedNodeByHost.get(host); i++) {
            arrangedNodes.add(createMockeNode(host));
        }
    }
    // simulate what the selection manager is doing
    TopologyManager manager = new TopologyManager();
    for (Node node : arrangedNodes) {
        manager.addNode(node);
    }
    TopologyHandler handler = manager.getHandler(crit.getTopology());
    NodeSet selectedNodes = handler.select(crit.getSize(), arrangedNodes);
    if (selectedNodes.size() < crit.getSize() && !crit.isBestEffort()) {
        selectedNodes.clear();
        if (selectedNodes.getExtraNodes() != null) {
            selectedNodes.getExtraNodes().clear();
        }
    }
    Set<Node> allNodes = new HashSet<>(selectedNodes);
    if (selectedNodes.getExtraNodes() != null) {
        allNodes.addAll((selectedNodes.getExtraNodes()));
    }
    System.out.println("Selected nodes : " + allNodes);
    if (outputNodesNumber >= 0) {
        assertEquals(outputNodesNumber, allNodes.size());
    } else {
        // different host exclusive test
        Map<String, Integer> checkNodesByHost = new HashMap<>(groupedNodeByHost);
        for (Node node : allNodes) {
            String hostName = node.getVMInformation().getHostName();
            checkNodesByHost.put(hostName, checkNodesByHost.get(hostName) - 1);
        }
        System.out.println("Free nodes after selection : " + checkNodesByHost);
        Assert.assertEquals(requiredNodesNumber, checkNodesByHost.entrySet().stream().filter(entry -> entry.getValue() == 0).collect(Collectors.toList()).size());
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Criteria(org.ow2.proactive.utils.Criteria) BeforeClass(org.junit.BeforeClass) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) NodeSet(org.ow2.proactive.utils.NodeSet) ImmutableMap(com.google.common.collect.ImmutableMap) VMInformation(org.objectweb.proactive.core.runtime.VMInformation) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Node(org.objectweb.proactive.core.node.Node) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties) List(java.util.List) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor) NodeInformation(org.objectweb.proactive.core.node.NodeInformation) Map(java.util.Map) HostsPinger(org.ow2.proactive.resourcemanager.frontend.topology.pinging.HostsPinger) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Node(org.objectweb.proactive.core.node.Node) ArrayList(java.util.ArrayList) Criteria(org.ow2.proactive.utils.Criteria) HashSet(java.util.HashSet)

Example 4 with Topology

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

the class JobComparator method isEqualParallelEnvironment.

private boolean isEqualParallelEnvironment(ParallelEnvironment e1, ParallelEnvironment e2) {
    if ((e1 == null) && (e2 == null))
        return true;
    if ((e1 == null) ^ (e2 == null)) {
        stack.push("One value out of 2 is null");
        return false;
    }
    if (e1.getNodesNumber() != e2.getNodesNumber()) {
        stack.push("nodes number");
        return false;
    }
    // check same instance of topology decsriptor
    TopologyDescriptor topologyDescriptor1 = e1.getTopologyDescriptor();
    TopologyDescriptor topologyDescriptor2 = e2.getTopologyDescriptor();
    if (topologyDescriptor1 == null && topologyDescriptor2 == null) {
        return true;
    }
    if (topologyDescriptor1 == null ^ topologyDescriptor2 == null) {
        return isEqualClass(TopologyDescriptor.ARBITRARY.getClass(), (topologyDescriptor1 == null ? topologyDescriptor2.getClass() : topologyDescriptor1.getClass()));
    }
    if (!isEqualClass(topologyDescriptor1.getClass(), topologyDescriptor2.getClass())) {
        stack.push("topology descriptor type");
        return false;
    }
    if (topologyDescriptor1 instanceof ThresholdProximityDescriptor) {
        if (!(topologyDescriptor2 instanceof ThresholdProximityDescriptor)) {
            stack.push("Only one is ThresholdProximityDescriptor type.");
            return false;
        }
        if (((ThresholdProximityDescriptor) topologyDescriptor1).getThreshold() != ((ThresholdProximityDescriptor) topologyDescriptor2).getThreshold()) {
            stack.push("ThresholdProximityDescriptor.threshold");
            return false;
        }
    }
    return true;
}
Also used : ThresholdProximityDescriptor(org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor)

Example 5 with Topology

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

the class TestRMProxy method requestWithExtraNodes.

private void requestWithExtraNodes(RMProxy proxy, ResourceManager rm) throws Exception {
    log("Request NodeSet with extra nodes");
    TopologyDescriptor topology = TopologyDescriptor.SINGLE_HOST_EXCLUSIVE;
    Criteria criteria = new Criteria(1);
    criteria.setTopology(topology);
    NodeSet nodeSet = proxy.getNodes(criteria);
    PAFuture.waitFor(nodeSet);
    assertEquals(1, nodeSet.size());
    Assert.assertNotNull("Extra nodes are expected", nodeSet.getExtraNodes());
    assertEquals(NODES_NUMBER - 1, nodeSet.getExtraNodes().size());
    assertEquals(0, rm.getState().getFreeNodesNumber());
    proxy.releaseNodes(nodeSet);
    waitWhenNodesAreReleased(NODES_NUMBER);
    assertEquals(NODES_NUMBER, rm.getState().getFreeNodesNumber());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Criteria(org.ow2.proactive.utils.Criteria) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor)

Aggregations

NodeSet (org.ow2.proactive.utils.NodeSet)8 TopologyDescriptor (org.ow2.proactive.topology.descriptor.TopologyDescriptor)7 HashMap (java.util.HashMap)6 Node (org.objectweb.proactive.core.node.Node)6 Criteria (org.ow2.proactive.utils.Criteria)6 ArrayList (java.util.ArrayList)5 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)4 IOException (java.io.IOException)3 InetAddress (java.net.InetAddress)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Test (org.junit.Test)3 ThresholdProximityDescriptor (org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2