use of org.ow2.proactive.topology.descriptor.TopologyDescriptor 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.topology.descriptor.TopologyDescriptor 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.topology.descriptor.TopologyDescriptor in project scheduling by ow2-proactive.
the class LocalSelectionTest method getNodesAndReleaseThem.
private void getNodesAndReleaseThem(int number, TopologyDescriptor descriptor, int expectedReceived, int expectedExtraNodesSize) {
Criteria c = new Criteria(number);
c.setTopology(descriptor);
NodeSet ns = resourceManager.getNodes(c);
Assert.assertEquals(expectedReceived, ns.size());
Collection<Node> extra = ns.getExtraNodes();
if (expectedExtraNodesSize == 0) {
Assert.assertNull(extra);
} else {
Assert.assertEquals(expectedExtraNodesSize, extra.size());
}
resourceManager.releaseNodes(ns).getBooleanValue();
}
use of org.ow2.proactive.topology.descriptor.TopologyDescriptor in project scheduling by ow2-proactive.
the class TestTaskAttributes method testParallelEnv.
@Test
public void testParallelEnv() throws Exception {
JavaTask task = createDefaultTask("task");
ParallelEnvironment env = new ParallelEnvironment(5);
task.setParallelEnvironment(env);
InternalTask taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(5, taskData.getParallelEnvironment().getNodesNumber());
Assert.assertNull(taskData.getParallelEnvironment().getTopologyDescriptor());
TopologyDescriptor[] descs = { TopologyDescriptor.ARBITRARY, TopologyDescriptor.BEST_PROXIMITY, TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, TopologyDescriptor.SINGLE_HOST, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, new ThresholdProximityDescriptor(123) };
for (TopologyDescriptor desc : descs) {
task = createDefaultTask("task");
env = new ParallelEnvironment(10, desc);
task.setParallelEnvironment(env);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(10, taskData.getParallelEnvironment().getNodesNumber());
Assert.assertEquals(taskData.getParallelEnvironment().getTopologyDescriptor().getClass(), desc.getClass());
if (desc instanceof ThresholdProximityDescriptor) {
Assert.assertEquals(((ThresholdProximityDescriptor) taskData.getParallelEnvironment().getTopologyDescriptor()).getThreshold(), 123);
}
}
}
use of org.ow2.proactive.topology.descriptor.TopologyDescriptor 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