use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class TestConcurrentUsers method testConcurrency.
@Test
public void testConcurrency() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
String nsName = "TestConcurrentUsers";
String node1Name = "node1";
testNode = rmHelper.createNode(node1Name);
String node1URL = testNode.getNode().getNodeInformation().getURL();
resourceManager.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
resourceManager.addNode(node1URL, nsName);
// waiting for node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// waiting for the node to be free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
assertTrue(resourceManager.getState().getFreeNodesNumber() == 1);
log("Test 1 - releasing of the foreign node");
// acquiring a node
final NodeSet ns = resourceManager.getAtMostNodes(1, null);
// waiting for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(evt.getNodeState(), NodeState.BUSY);
assertEquals(ns.size(), 1);
assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
assertTrue(resourceManager.getState().getFreeNodesNumber() == 0);
Thread t = new Thread() {
@Override
public void run() {
try {
Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin("user"), CredData.parseDomain("user"), "pwd"), TestConcurrentUsers.this.rmHelper.getRMAuth().getPublicKey());
ResourceManager rm2 = TestConcurrentUsers.this.rmHelper.getRMAuth().login(cred);
rm2.releaseNode(ns.get(0)).getBooleanValue();
Assert.assertTrue("Should not be able to release foreign node", false);
} catch (Exception e) {
log(e.getMessage());
}
}
};
t.start();
t.join();
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(ns);
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(evt.getNodeState(), NodeState.FREE);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 2 - releasing node twice");
resourceManager.releaseNodes(ns);
// to make sure everything has been processed
Thread.sleep(1000);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 3 - client crash detection");
JVMProcessImpl nodeProcess = new JVMProcessImpl(new org.objectweb.proactive.core.process.AbstractExternalProcess.StandardOutputMessageLogger());
nodeProcess.setJvmOptions(Collections.singletonList(PAResourceManagerProperties.RM_HOME.getCmdLine() + PAResourceManagerProperties.RM_HOME.getValueAsString()));
nodeProcess.setClassname(GetAllNodes.class.getName());
nodeProcess.startProcess();
// node busy event
for (int i = 0; i < 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
// client does not exist anymore
log("Client does not exist anymore. Waiting for client crash detection.");
// waiting for node free event
for (int i = 0; i < 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.FREE, evt.getNodeState());
}
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 4 - disconnecting");
NodeSet ns2 = resourceManager.getAtMostNodes(1, null);
RMNodeEvent event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
Assert.assertTrue(event.getNodeState() == NodeState.BUSY);
PAFuture.waitFor(ns2);
log("Number of found nodes " + ns2.size());
assertEquals(1, ns2.size());
t = new Thread() {
public void run() {
try {
RMAuthentication auth = rmHelper.getRMAuth();
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), auth.getPublicKey());
ResourceManager rm = auth.login(cred);
rm.disconnect().getBooleanValue();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
t.join();
try {
event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
fail("Unexpected event: " + event);
} catch (ProActiveTimeoutException e) {
}
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent 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.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class TestLocalInfrastructureRestartDownNodesPolicy method testRestartDownNodesPolicy.
@Test
public void testRestartDownNodesPolicy() throws Exception {
nodeSourceName = "Node_source_1";
RMTHelper.log("Test 1 - restart down nodes policy");
createNodeSourceWithNodes(nodeSourceName, new Object[] { "ALL", "ALL", "10000" });
RMState stateTest1 = resourceManager.getState();
assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
assertEquals(defaultDescriptorNodesNb, stateTest1.getFreeNodesNumber());
NodeSet ns = resourceManager.getNodes(new Criteria(defaultDescriptorNodesNb));
for (Node n : ns) {
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
}
String nodeUrl = ns.get(0).getNodeInformation().getURL();
// Nodes will be redeployed only if we kill the whole runtime
rmHelper.killRuntime(nodeUrl);
RMNodeEvent ev = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeUrl);
assertEquals(NodeState.DOWN, ev.getNodeState());
// one node is down - the policy should detect it and redeploy
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalAliveNodesNumber());
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class TestNodeSourceThreadPool method testDownNodesCanStillBeDetectedWhenDeploymentThreadsAreExhausted.
@Test
public void testDownNodesCanStillBeDetectedWhenDeploymentThreadsAreExhausted() throws Exception {
String rmConfig = new File(RMTHelper.class.getResource(TWO_THREADS_CONFIG_FILE_PATH).toURI()).getAbsolutePath();
this.rmHelper.startRM(rmConfig);
this.resourceManager = this.rmHelper.getResourceManager();
this.resourceManager.defineNodeSource(NODE_SOURCE_NAME, SSHInfrastructureV2.class.getName(), getInfiniteRetryInfrastructureParameters(), StaticPolicy.class.getName(), getStaticPolicyParameters(), NODES_NOT_RECOVERABLE);
this.resourceManager.deployNodeSource(NODE_SOURCE_NAME);
RMTHelper.log("Waiting for the RM to have one free node");
while (this.resourceManager.getState().getFreeNodesNumber() != ONE_NODE_PER_HOST) {
Thread.sleep(ACTIVE_WAITING_PERIOD);
}
RMTHelper.log("The RM has one free node");
RMTHelper.log("Killing the free node");
String freeNodeUrl = this.resourceManager.getState().getFreeNodes().iterator().next();
RMTHelper.killRuntime(freeNodeUrl);
RMMonitorsHandler monitor = this.rmHelper.getMonitorsHandler();
monitor.flushEvents();
RMTHelper.log("Waiting for the RM to detect the node down");
RMNodeEvent nodeEvent = RMTHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, freeNodeUrl, NODE_STATE_CHANGED_TIMEOUT, monitor);
assertEquals(NodeState.DOWN, nodeEvent.getNodeState());
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class RMCore method getRMInitialState.
/**
* Builds and returns a snapshot of RMCore's current state. Initial state
* must be understood as a new Monitor point of view. A new monitor start to
* receive RMCore events, so must be informed of the current state of the
* Core at the beginning of monitoring. The monitor is built in three parts
* first with all the nodes knows by the RMCore, then with all deploying
* nodes known by the deployed node sources and then with all the defined
* node sources.
*
* @return RMInitialState containing nodes and nodeSources of the RMCore.
*/
public RMInitialState getRMInitialState() {
final Map<String, RMNodeEvent> nodeEvents = this.allNodes.values().stream().map(RMNode::createNodeEvent).collect(Collectors.toMap(RMNodeEvent::getNodeUrl, event -> event));
for (NodeSource source : this.deployedNodeSources.values()) {
for (RMDeployingNode node : source.getDeployingAndLostNodes()) {
final RMNodeEvent nodeEvent = node.createNodeEvent();
nodeEvents.put(nodeEvent.getNodeUrl(), nodeEvent);
}
}
final List<RMNodeSourceEvent> nodeSourceEvents = new ArrayList<>(this.definedNodeSources.values().stream().map(ns -> {
if (deployedNodeSources.containsKey(ns.getName())) {
return PAFuture.getFutureValue(deployedNodeSources.get(ns.getName()).createNodeSourceEvent());
} else {
return ns.createNodeSourceEvent();
}
}).collect(Collectors.toList()));
long eventCounter = 0;
for (RMNodeSourceEvent nodeSourceEvent : nodeSourceEvents) {
nodeSourceEvent.setCounter(eventCounter++);
}
for (RMNodeEvent nodeEvent : nodeEvents.values()) {
nodeEvent.setCounter(eventCounter++);
}
final RMInitialState rmInitialState = new RMInitialState();
rmInitialState.addAll(nodeEvents.values());
rmInitialState.addAll(nodeSourceEvents);
return rmInitialState;
}
Aggregations