use of org.ow2.proactive.resourcemanager.frontend.ResourceManager 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.resourcemanager.frontend.ResourceManager 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.resourcemanager.frontend.ResourceManager 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());
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class StaticSelectionScriptTest method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
int nodeNumber = rmHelper.createNodeSource("StaticSelectionScriptTest");
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 nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// create the static selection script object
SelectionScript sScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, false);
log("Test 1");
NodeSet nodes = resourceManager.getAtMostNodes(1, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
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());
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(nodeNumber, 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 nodes 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(nodeNumber, resourceManager.getState().getFreeNodesNumber());
// wait for node 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 nodes free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
Assert.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, node1URL);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node2URL);
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 5");
// create the bad static selection script object
SelectionScript badScript = new SelectionScript(new File(badSelectionScriptpath.toURI()), new String[] {}, false);
nodes = resourceManager.getAtMostNodes(3, badScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 6");
// create the static selection script object that doesn't define 'selected'
SelectionScript noSelectedScript = new SelectionScript(new File(withoutSelectedSelectionScriptpath.toURI()), new String[] {}, false);
nodes = resourceManager.getAtMostNodes(3, noSelectedScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class RMFunctionalTest method cleanState.
/**
* Remove all node sources and nodes in the RM
*
* @throws Exception
*/
private void cleanState() throws Exception {
if (rmHelper.isRMStarted()) {
// force reconnection
rmHelper.disconnect();
ResourceManager rm = rmHelper.getResourceManager();
int nodeNumber = rm.getState().getTotalNodesNumber();
RMInitialState state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
for (RMNodeSourceEvent sourceEvent : state.getNodeSourceEvents()) {
String nodeSource = sourceEvent.getSourceName();
rm.removeNodeSource(nodeSource, true);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nodeSource);
}
for (int i = 0; i < nodeNumber; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
}
}
Aggregations