use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class DynamicSelectionScriptTest method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
int nsSize = rmHelper.createNodeSource("DynamicSelectionScriptTest");
String node1Name = "node1";
String node2Name = "node2";
HashMap<String, String> vmProperties = new HashMap<>();
String vmPropKey = "myProperty";
String vmPropValue = "myValue";
vmProperties.put(vmPropKey, vmPropValue);
TestNode node1 = rmHelper.createNode(node1Name, vmProperties);
testNodes.add(node1);
String node1URL = node1.getNode().getNodeInformation().getURL();
resourceManager.addNode(node1URL);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// create the dynamic selection script object
SelectionScript sScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, true);
log("Test 1");
NodeSet nodes = resourceManager.getAtMostNodes(1, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNode(nodes.get(0));
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 2");
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNode(nodes.get(0));
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 3");
// add a second with JVM env var
TestNode node2 = rmHelper.createNode(node2Name, vmProperties);
testNodes.add(node2);
String node2URL = node2.getNode().getNodeInformation().getURL();
resourceManager.addNode(node2URL);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(2, nodes.size());
assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
// wait for nodes busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNodes(nodes);
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 4");
resourceManager.removeNode(node1URL, true);
resourceManager.removeNode(node2URL, true);
// wait for node removed event
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node2URL);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node1URL);
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
log("Test 5");
// create the bad dynamic selection script object
SelectionScript badScript = new SelectionScript(new File(badSelectionScriptpath.toURI()), new String[] {}, true);
nodes = resourceManager.getAtMostNodes(3, badScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
log("Test 6");
// create the dynamic selection script object that doesn't define 'selected'
SelectionScript noSelectedScript = new SelectionScript(new File(withoutSelectedSelectionScriptpath.toURI()), new String[] {}, true);
nodes = resourceManager.getAtMostNodes(3, noSelectedScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
log("Test 7");
// Checking the dynamicity of the node (period during which the dynamic characteristics do not change).
// It sets to 10 secs for testing configuration.
// So first run the dynamic script that fails checking if the file exist
// Then create a file and call getNodes again. It must return 0 nodes.
// Wait for 10 secs and call getNodes again. The script must be executed now
// and we should get some nodes.
final String FILE_NAME = System.getProperty("java.io.tmpdir") + "/dynamicity.selection";
if (new File(FILE_NAME).exists()) {
new File(FILE_NAME).delete();
}
SelectionScript fileCheck = new SelectionScript(new File(fileCheckScriptPath.toURI()), new String[] { FILE_NAME }, true);
log("The dynamic script checking is file exists must fail " + FILE_NAME);
nodes = resourceManager.getAtMostNodes(1, fileCheck);
assertEquals(0, nodes.size());
log("Creating the file " + FILE_NAME);
new File(FILE_NAME).createNewFile();
log("The dynamic script checking is file exists must not be executed " + FILE_NAME);
nodes = resourceManager.getAtMostNodes(1, fileCheck);
assertEquals(0, nodes.size());
Thread.sleep(10000);
log("The dynamic script checking is file exists must pass " + FILE_NAME);
nodes = resourceManager.getAtMostNodes(1, fileCheck);
assertEquals(1, nodes.size());
new File(FILE_NAME).delete();
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class SelectionWithSeveralScriptsTest method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
String nodeSourceName = "selection-several-ns";
resourceManager.createNodeSource(nodeSourceName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nodeSourceName);
String node1Name = "node-sel-1";
String node2Name = "node-sel-2";
String node3Name = "node-sel-3";
// ---------------------------------------------------
// create a first node with the two VM properties
// ---------------------------------------------------
HashMap<String, String> vmTwoProperties = new HashMap<>();
String vmPropKey1 = "myProperty1";
String vmPropValue1 = "myValue1";
vmTwoProperties.put(vmPropKey1, vmPropValue1);
String vmPropKey2 = "myProperty2";
String vmPropValue2 = "myValue2";
vmTwoProperties.put(vmPropKey2, vmPropValue2);
TestNode node1 = rmHelper.createNode(node1Name, vmTwoProperties);
testNodes.add(node1);
String node1URL = node1.getNode().getNodeInformation().getURL();
resourceManager.addNode(node1URL, nodeSourceName);
// 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);
Assert.assertEquals(1, resourceManager.listAliveNodeUrls().size());
// --------------------------------------------------
// create a second node with only the first VM property
// ---------------------------------------------------
HashMap<String, String> vmProp1 = new HashMap<>();
vmProp1.put(vmPropKey1, vmPropValue1);
TestNode node2 = rmHelper.createNode(node2Name, vmProp1);
testNodes.add(node2);
String node2URL = node2.getNode().getNodeInformation().getURL();
resourceManager.addNode(node2URL, nodeSourceName);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
Assert.assertEquals(2, resourceManager.listAliveNodeUrls().size());
// --------------------------------------------------
// create a third node with only the second VM property
// ---------------------------------------------------
HashMap<String, String> vmProp2 = new HashMap<>();
vmProp1.put(vmPropKey2, vmPropValue2);
TestNode node3 = rmHelper.createNode(node3Name, vmProp2);
testNodes.add(node3);
String node3URL = node3.getNode().getNodeInformation().getURL();
resourceManager.addNode(node3URL, nodeSourceName);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node3URL);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
Assert.assertEquals(3, resourceManager.listAliveNodeUrls().size());
// create the static selection script object that check vm prop1
SelectionScript sScript1 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey1, vmPropValue1 }, true);
// create the static selection script object prop2
SelectionScript sScript2 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey2, vmPropValue2 }, false);
log("Test 1");
ArrayList<SelectionScript> scriptsList = new ArrayList<>();
scriptsList.add(sScript1);
scriptsList.add(sScript2);
NodeSet nodes = resourceManager.getAtMostNodes(1, scriptsList, null);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
assertEquals(2, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
assertEquals(3, resourceManager.getState().getFreeNodesNumber());
log("Test 2");
nodes = resourceManager.getAtMostNodes(3, scriptsList, nodes);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(3, resourceManager.getState().getFreeNodesNumber());
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class UnauthorizedSelectionScriptTest method action.
@Test
public void action() throws Exception {
String rmconf = new File(PAResourceManagerProperties.getAbsolutePath(getClass().getResource("/functionaltests/config/rm-authorized-selection-script.ini").getFile())).getAbsolutePath();
rmHelper.startRM(rmconf);
ResourceManager rm = this.rmHelper.getResourceManager();
this.rmHelper.createNodeSource("Dummy", 1);
log("Test 1 - unautorized script");
Criteria criteria = new Criteria(1);
URL vmPropSelectionScriptpath = this.getClass().getResource("dummySelectionScript.js");
List<SelectionScript> scripts = new ArrayList<>();
scripts.add(new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), null, true));
criteria.setScripts(scripts);
try {
NodeSet ns = rm.getNodes(criteria);
System.out.println("Number of nodes matched " + ns.size());
fail("Executed unauthorized selection script");
} catch (SecurityException ex) {
log("Test 1 - passed");
}
log("Test 2 - authorized script");
String authorizedScriptPath = PAResourceManagerProperties.RM_HOME.getValueAsString() + "/samples/scripts/selection/checkPhysicalFreeMem.js";
scripts = new ArrayList<>();
scripts.add(new SelectionScript(new File(authorizedScriptPath), new String[] { "1" }, true));
criteria.setScripts(scripts);
NodeSet ns = rm.getNodes(criteria);
System.out.println("Number of nodes matched " + ns.size());
assertEquals(1, ns.size());
log("Test 2 - passed");
}
use of org.ow2.proactive.scripting.SelectionScript 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));
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class ScriptUpdateUtil method resolveScripts.
/**
* Filters the scripts in the specified job.
*/
public static TaskFlowJob resolveScripts(TaskFlowJob job) {
ArrayList<Task> tasks = job.getTasks();
for (Task task : tasks) {
Map<String, String> variables = task.getVariablesOverriden(job);
List<SelectionScript> selectionScripts = task.getSelectionScripts();
if (selectionScripts != null) {
for (SelectionScript sscript : selectionScripts) {
resolveScript(sscript, variables);
}
}
resolveScript(task.getFlowScript(), variables);
resolveScript(task.getPreScript(), variables);
resolveScript(task.getPostScript(), variables);
resolveScript(task.getCleaningScript(), variables);
}
return job;
}
Aggregations