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();
}
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);
}
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());
}
}
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;
}
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());
}
Aggregations