use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class TestNodeSourcesActions method testAddRemoveNodesPreemptively.
@Test
public void testAddRemoveNodesPreemptively() throws Exception {
String nodeSourceName = "TestNodeSourcesActions";
ResourceManager resourceManager = rmHelper.getResourceManager();
int nodeNumber = 5;
int pingFrequency = 5000;
byte[] creds = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
resourceManager.createNodeSource(nodeSourceName, LocalInfrastructure.class.getName(), new Object[] { creds, nodeNumber, RMTHelper.DEFAULT_NODES_TIMEOUT, "" }, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
// wait for creation of GCM Node Source event, and deployment of its nodes
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nodeSourceName);
resourceManager.setNodeSourcePingFrequency(pingFrequency, nodeSourceName);
RMTHelper.log("Test 1");
for (int i = 0; i < nodeNumber; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
}
assertEquals(nodeNumber, resourceManager.getState().getTotalNodesNumber());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
// book 3 nodes
NodeSet nodes = resourceManager.getAtMostNodes(3, null);
PAFuture.waitFor(nodes);
assertEquals(3, nodes.size());
assertEquals(nodeNumber - 3, resourceManager.getState().getFreeNodesNumber());
assertEquals(nodeNumber, resourceManager.getState().getTotalNodesNumber());
for (int i = 0; i < 3; i++) {
RMNodeEvent evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
// put one of the busy node in 'to release' state
Node n1 = nodes.remove(0);
resourceManager.removeNode(n1.getNodeInformation().getURL(), false);
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n1.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
// put one of the busy node in 'down' state
Node n2 = nodes.remove(0);
try {
n2.getProActiveRuntime().killNode(n2.getNodeInformation().getName());
} catch (Exception e) {
e.printStackTrace();
}
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n2.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.DOWN);
// kill preemptively the node source
resourceManager.removeNodeSource(nodeSourceName, true);
for (int i = 0; i < nodeNumber; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
// wait for the event of the node source removal
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nodeSourceName);
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(0, resourceManager.getState().getTotalNodesNumber());
// test the non preemptive node source removal
RMTHelper.log("Test 2");
String nodeSourceName2 = "TestNodeSourcesActions2";
// first im parameter is default rmHelper url
int expectedNodeNumber = 3;
rmHelper.createNodeSource(nodeSourceName2, expectedNodeNumber);
resourceManager.setNodeSourcePingFrequency(pingFrequency, nodeSourceName2);
assertEquals(expectedNodeNumber, resourceManager.getState().getTotalNodesNumber());
assertEquals(expectedNodeNumber, resourceManager.getState().getFreeNodesNumber());
// book 3 nodes
nodes = resourceManager.getAtMostNodes(3, null);
PAFuture.waitFor(nodes);
for (int i = 0; i < 3; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
assertEquals(3, nodes.size());
assertEquals(expectedNodeNumber - 3, resourceManager.getState().getFreeNodesNumber());
assertEquals(expectedNodeNumber, resourceManager.getState().getTotalNodesNumber());
// put one of the busy node in 'to release' state
n1 = nodes.remove(0);
resourceManager.removeNode(n1.getNodeInformation().getURL(), false);
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n1.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
// put one of the busy node in 'down' state
n2 = nodes.remove(0);
Node n3 = nodes.remove(0);
try {
n2.getProActiveRuntime().killNode(n2.getNodeInformation().getName());
} catch (Exception e) {
e.printStackTrace();
}
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n2.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.DOWN);
// kill non preemptively the node source
resourceManager.removeNodeSource(nodeSourceName2, false);
// the two free nodes and the down node (n2) are removed immediately
for (int i = 0; i < expectedNodeNumber - 2; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
// the 'to release' node (n1) keeps the same state
// the busy node (n3) becomes a 'to release' node
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n3.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(2, resourceManager.getState().getTotalNodesNumber());
// give back the two nodes in 'to release' state, they are directly removed
resourceManager.releaseNode(n1);
resourceManager.releaseNode(n3);
for (int i = 0; i < 2; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(0, resourceManager.getState().getTotalNodesNumber());
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent 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.resourcemanager.common.event.RMNodeEvent 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.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class RMCoreTest method configureNodeForStateChange.
private void configureNodeForStateChange(RMNode mockedRmNode, NodeState previousNodeState) {
RMNodeEvent rmNodeEvent = createRmNodeEvent(previousNodeState);
when(mockedRmNode.getLastEvent()).thenReturn(rmNodeEvent);
when(mockedRmNode.getOwner()).thenReturn(new Client(null, false));
RMCore.clients.put(mockedRmNode.getOwner().getId(), mockedRmNode.getOwner());
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class TestNonForkedScriptTask method nonForkedTasks_SystemExitScript_KillsANode.
@Ignore
@Test
public void nonForkedTasks_SystemExitScript_KillsANode() throws Throwable {
TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(nonForked_jobDescriptor.toURI()).getAbsolutePath());
schedulerHelper.submitJob(job);
// busy event when task is scheduler
schedulerHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// down event when node is killed
RMNodeEvent nodeKilledEvent = schedulerHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.DOWN, nodeKilledEvent.getNodeState());
}
Aggregations