use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class ProbablisticSelectionManager method arrangeNodesForScriptExecution.
/**
* Find appropriate candidates nodes for script execution, taking into
* account "free" and "exclusion" nodes lists.
*
* @param scripts set of scripts to execute
* @param nodes free nodes list provided by resource manager
* @return candidates node list for script execution
*/
@Override
public List<RMNode> arrangeNodesForScriptExecution(final List<RMNode> nodes, List<SelectionScript> scripts, Map<String, Serializable> bindings) {
long startTime = System.currentTimeMillis();
boolean scriptSpecified = scripts != null && scripts.size() > 0;
// if no scripts are specified return filtered free nodes
if (!scriptSpecified) {
return nodes;
}
try {
// finding intersection
HashMap<RMNode, Probability> intersectionMap = new LinkedHashMap<>();
for (RMNode rmnode : nodes) {
boolean intersection = true;
double intersectionProbability = 1;
for (SelectionScript script : scripts) {
SelectionScript scriptWithReplacedBindings = replaceBindings(script, bindings);
String digest = new String(scriptWithReplacedBindings.digest());
if (probabilities.containsKey(digest) && probabilities.get(digest).containsKey(rmnode.getNodeURL())) {
double probability = probabilities.get(digest).get(rmnode.getNodeURL()).value();
if (probability == 0) {
intersection = false;
break;
} else {
intersectionProbability *= probability;
}
} else {
intersectionProbability *= Probability.defaultValue();
}
}
if (intersection) {
intersectionMap.put(rmnode, new Probability(intersectionProbability));
}
}
// sorting results based on calculated probability
Set<RMNode> nodeSet = intersectionMap.keySet();
List<RMNode> res = new ArrayList<>(nodeSet.size());
res.addAll(nodeSet);
Collections.sort(res, new NodeProbabilityComparator(intersectionMap));
if (logger.isDebugEnabled()) {
logger.debug("The following nodes are selected for scripts execution (time is " + (System.currentTimeMillis() - startTime) + " ms) :");
if (res.size() > 0) {
for (RMNode rmnode : res) {
logger.debug(rmnode.getNodeURL() + " : probability " + intersectionMap.get(rmnode));
}
} else {
logger.debug("None");
}
}
return res;
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage(), e);
return new ArrayList<>(0);
}
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class NonBlockingCoreTest method action.
@Test
public void action() throws Exception {
String rmconf = new File(PAResourceManagerProperties.getAbsolutePath(getClass().getResource("/functionaltests/config/functionalTRMProperties-long-selection-script-timeout.ini").getFile())).getAbsolutePath();
rmHelper.startRM(rmconf);
ResourceManager resourceManager = rmHelper.getResourceManager();
int initialNodeNumber = 2;
rmHelper.createNodeSource("NonBlockingCoreTest1", initialNodeNumber);
long coreScriptExecutionTimeout = PAResourceManagerProperties.RM_SELECT_SCRIPT_TIMEOUT.getValueAsLong();
long scriptSleepingTime = coreScriptExecutionTimeout * 2;
log("Selecting node with timeout script");
// create the static selection script object
final SelectionScript sScript = new SelectionScript(new File(selectionScriptWithtimeOutPath.toURI()), new String[] { Long.toString(scriptSleepingTime) }, false);
// mandatory to use RMUser AO, otherwise, getAtMostNode we be send in
// RMAdmin request queue
final RMAuthentication auth = rmHelper.getRMAuth();
final Credentials cred = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), auth.getPublicKey());
// cannot connect twice from the same active object
// so creating another thread
Thread t = new Thread() {
public void run() {
ResourceManager rm2;
try {
rm2 = auth.login(cred);
nodes = rm2.getAtMostNodes(2, sScript);
} catch (LoginException e) {
}
}
};
t.start();
String nodeName = "node_non_blocking_test";
testNode = RMTHelper.createNode(nodeName);
String nodeUrl = testNode.getNode().getNodeInformation().getURL();
log("Adding node " + nodeUrl);
resourceManager.addNode(nodeUrl);
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeUrl);
// waiting for node to be in free state, it is in configuring state when
// added...
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(resourceManager.getState().getTotalNodesNumber(), initialNodeNumber + 1);
assertEquals(resourceManager.getState().getFreeNodesNumber(), initialNodeNumber + 1);
// preemptive removal is useless for this case, because node is free
log("Removing node " + nodeUrl);
resourceManager.removeNode(nodeUrl, false);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, nodeUrl);
assertEquals(resourceManager.getState().getTotalNodesNumber(), initialNodeNumber);
assertEquals(resourceManager.getState().getFreeNodesNumber(), initialNodeNumber);
String nsName = "NonBlockingCoreTest";
log("Creating a node source " + nsName);
int nsNodesNumber = 1;
rmHelper.createNodeSource(nsName, nsNodesNumber);
assertEquals(resourceManager.getState().getTotalNodesNumber(), nsNodesNumber + initialNodeNumber);
assertEquals(resourceManager.getState().getFreeNodesNumber(), nsNodesNumber + initialNodeNumber);
log("Removing node source " + nsName);
resourceManager.removeNodeSource(nsName, true);
boolean selectionInProgress = PAFuture.isAwaited(nodes);
if (!selectionInProgress) {
// normally we are looking for 2 nodes with timeout script,
// so the selection procedure has to finish not earlier than
// coreScriptExecutionTimeout * nodesNumber
// it should be sufficient to perform all admin operations
// concurrently
//
// if the core is blocked admin operations will be performed after
// selection
fail("Blocked inside RMCore");
} else {
log("No blocking inside RMCore");
}
t.interrupt();
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class SelectionScriptTimeOutTest method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
rmHelper.createNodeSource();
int nodesNumber = resourceManager.getState().getTotalNodesNumber();
int scriptSleepingTime = 40 * 1000;
log("Test 1 - selecting nodes with timeout script");
// create the static selection script object
SelectionScript script = new SelectionScript(new File(selectionScriptWithtimeOutPath.toURI()), new String[] { Integer.toString(scriptSleepingTime) }, false);
NodeSet nodes = resourceManager.getAtMostNodes(2, script);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodesNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 2 - selecting nodes with script which is timed out only on some hosts");
String nodeName = "timeoutNode";
HashMap<String, String> vmProperties = new HashMap<>();
vmProperties.put(nodeName, "dummy");
testNode = rmHelper.createNode(nodeName, vmProperties);
String nodeURL = testNode.getNode().getNodeInformation().getURL();
resourceManager.addNode(nodeURL);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// now we have nodesNumber + 1 nodes
script = new SelectionScript(new File(selectionScriptWithtimeOutPath.toURI()), new String[] { Integer.toString(scriptSleepingTime), nodeName }, false);
// selecting all nodes
nodes = resourceManager.getAtMostNodes(nodesNumber + 1, script);
// have to get nodesNumber due to the script timeout on one node
assertEquals(nodesNumber, nodes.size());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
// waiting until selection manager finishes script execution for node "timeout"
// as we don't know how long should we wait roughly estimate it as scriptSleepingTime/2
Thread.sleep(scriptSleepingTime / 2);
NodeSet nodes2 = resourceManager.getAtMostNodes(1, null);
assertEquals(1, nodes2.size());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes).getBooleanValue();
resourceManager.releaseNodes(nodes2).getBooleanValue();
nodes = resourceManager.getAtMostNodes(2, script);
assertEquals(2, nodes.size());
assertEquals(nodesNumber - 1, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class SelectionWithNodesExclusionTest method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
final int initialNodesNumber = rmHelper.createNodeSource("SelectionWithNodesExclusionTest");
log("Test 1");
NodeSet nodeSetWithNodeToExclude = resourceManager.getAtMostNodes(1, null);
// wait for node selection
PAFuture.waitFor(nodeSetWithNodeToExclude);
assertEquals(1, nodeSetWithNodeToExclude.size());
assertEquals(initialNodesNumber - 1, resourceManager.getState().getFreeNodesNumber());
// wait for node busy event
RMNodeEvent evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNodes(nodeSetWithNodeToExclude);
// wait for node free event
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
Assert.assertEquals(NodeState.FREE, evt.getNodeState());
assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
// get nodes with the previous node excluded
NodeSet nodes = resourceManager.getAtMostNodes(initialNodesNumber, new ArrayList<SelectionScript>(), nodeSetWithNodeToExclude);
// wait for node selection
PAFuture.waitFor(nodes);
for (int i = 0; i < initialNodesNumber - 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
Assert.assertEquals(evt.getNodeState(), NodeState.BUSY);
}
// booked all nodes minus the node to exclude
assertEquals(initialNodesNumber - 1, nodes.size());
// excluded node stays in free state
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
// wait for nodes freed event
for (int i = 0; i < initialNodesNumber - 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.FREE, evt.getNodeState());
}
assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 2");
// create the dynamic selection script object
SelectionScript dummyDynamicScript = new SelectionScript(new File(dummySelectionScriptPath.toURI()), new String[] {}, true);
// get nodes with the previous node excluded
nodes = resourceManager.getAtMostNodes(initialNodesNumber, dummyDynamicScript, nodeSetWithNodeToExclude);
// wait for node selection
PAFuture.waitFor(nodes);
// wait for nodes busy event
for (int i = 0; i < initialNodesNumber - 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.BUSY, evt.getNodeState());
}
// booked all nodes minus the node to exclude
assertEquals(initialNodesNumber - 1, nodes.size());
// excluded node stays in free state
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
// wait for nodes freed event
for (int i = 0; i < initialNodesNumber - 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.FREE, evt.getNodeState());
}
assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 3");
// create the static selection script object
SelectionScript dummyStaticScript = new SelectionScript(new File(dummySelectionScriptPath.toURI()), new String[] {}, false);
// get nodes with the previous node excluded
nodes = resourceManager.getAtMostNodes(initialNodesNumber, dummyStaticScript, nodeSetWithNodeToExclude);
// wait for node selection
PAFuture.waitFor(nodes);
// wait for nodes busy event
for (int i = 0; i < initialNodesNumber - 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
// booked all nodes minus the node to exclude
assertEquals(initialNodesNumber - 1, nodes.size());
// excluded node stays in free state
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
// wait for node free event
for (int i = 0; i < initialNodesNumber - 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.FREE, evt.getNodeState());
}
assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 4");
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);
TestNode node2 = rmHelper.createNode(node2Name, vmProperties);
testNodes.add(node2);
String node2URL = node2.getNode().getNodeInformation().getURL();
resourceManager.addNode(node2URL);
Thread.sleep(5000);
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// wait for nodes added events
assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
// create the dynamic selection script object
SelectionScript checkPropDynamicSScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, true);
Node node1ToExclude = NodeFactory.getNode(node1URL);
nodeSetWithNodeToExclude = new NodeSet();
nodeSetWithNodeToExclude.add(node1ToExclude);
// get nodes with the previous node1 excluded
nodes = resourceManager.getAtMostNodes(initialNodesNumber, checkPropDynamicSScript, nodeSetWithNodeToExclude);
// wait for node selection
PAFuture.waitFor(nodes);
// wait for nodes busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
// booked all nodes minus the node to exclude
assertEquals(1, nodes.size());
// excluded node stays in free state
assertEquals(initialNodesNumber + 1, resourceManager.getState().getFreeNodesNumber());
// unique node got is node2
assertEquals(node2URL, nodes.get(0).getNodeInformation().getURL());
resourceManager.releaseNodes(nodes);
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.FREE, evt.getNodeState());
assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
log("Test 5");
// create the static selection script object
SelectionScript checkPropStaticSScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, false);
Node node2ToExclude = NodeFactory.getNode(node2URL);
nodeSetWithNodeToExclude = new NodeSet();
nodeSetWithNodeToExclude.add(node2ToExclude);
// get nodes with the previous node1 excluded
nodes = resourceManager.getAtMostNodes(initialNodesNumber, checkPropStaticSScript, nodeSetWithNodeToExclude);
// wait for node selection
PAFuture.waitFor(nodes);
// wait for nodes busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
// booked all nodes minus the node to exclude
assertEquals(1, nodes.size());
// excluded node stays in free state
assertEquals(initialNodesNumber + 1, resourceManager.getState().getFreeNodesNumber());
// unique node got is node2
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
resourceManager.releaseNodes(nodes);
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
log("Test 6");
nodeSetWithNodeToExclude.add(node1ToExclude);
// get nodes with the previous node1 excluded
nodes = resourceManager.getAtMostNodes(initialNodesNumber, checkPropStaticSScript, nodeSetWithNodeToExclude);
// wait for node selection
PAFuture.waitFor(nodes);
assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
}
use of org.ow2.proactive.scripting.SelectionScript in project scheduling by ow2-proactive.
the class SelectionWithSeveralScriptsTest2 method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
String nodeSourceName = "SelectionWithSeveralScriptsTest2";
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-sel2-1";
String node2Name = "node-sel2-2";
// ---------------------------------------------------
// create a first node with one VM property
// ---------------------------------------------------
HashMap<String, String> vmProp1 = new HashMap<>();
String vmPropKey1 = "myProperty1";
String vmPropValue1 = "myValue1";
vmProp1.put(vmPropKey1, vmPropValue1);
TestNode node1 = rmHelper.createNode(node1Name, vmProp1);
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 node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// --------------------------------------------------
// create a second node with two VM properties
// ---------------------------------------------------
HashMap<String, String> vmTwoProperties = new HashMap<>();
vmTwoProperties.put(vmPropKey1, vmPropValue1);
String vmPropKey2 = "myProperty2";
String vmPropValue2 = "myValue2";
vmTwoProperties.put(vmPropKey2, vmPropValue2);
TestNode node2 = rmHelper.createNode(node2Name, vmTwoProperties);
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 node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// 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(node2URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.FREE, evt.getNodeState());
assertEquals(2, resourceManager.getState().getFreeNodesNumber());
}
Aggregations