use of org.ow2.proactive.utils.NodeSet 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.utils.NodeSet in project scheduling by ow2-proactive.
the class TestLocalInfrastructureStaticPolicy method action.
@Test
public void action() throws Exception {
String source1 = "Node_source_1";
ResourceManager resourceManager = rmHelper.getResourceManager();
log("Test 1 - creation/removal of empty node source");
log("creation");
createEmptyNodeSource(source1);
log("removal");
resourceManager.removeNodeSource(source1, true);
log("ask to remove NS");
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
log("NS removed");
String source2 = "Node_source_2";
log("Test 2 - creation/removal of the node source with nodes");
createNodeSourceWithNodes(source1);
RMState s = resourceManager.getState();
assertEquals(defaultDescriptorNodesNb, s.getTotalNodesNumber());
assertEquals(defaultDescriptorNodesNb, s.getFreeNodesNumber());
// releasing some nodes
NodeSet ns = resourceManager.getAtMostNodes(defaultDescriptorNodesNb, null);
for (Node n : ns) {
// eat the freeToBusy event
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
resourceManager.removeNode(n.getNodeInformation().getURL(), true);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL());
}
assertEquals(0, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
log("removal");
resourceManager.removeNodeSource(source1, true);
log("ask to remove NS");
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
log("NS removed");
log("Test 3 - several node sources");
createNodeSourceWithNodes(source1);
createNodeSourceWithNodes(source2);
assertEquals(2 * defaultDescriptorNodesNb, resourceManager.getState().getTotalNodesNumber());
assertEquals(2 * defaultDescriptorNodesNb, resourceManager.getState().getFreeNodesNumber());
resourceManager.removeNodeSource(source1, true);
// wait the n events of the n nodes removals of the node source
for (int i = 0; i < defaultDescriptorNodesNb; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
// wait for the event of the node source removal
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
resourceManager.removeNodeSource(source2, true);
for (int i = 0; i < defaultDescriptorNodesNb; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
// wait for the event of the node source removal
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source2);
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class GetAllNodes method main.
public static void main(String[] args) {
RMAuthentication auth;
try {
auth = RMConnection.join(RMTHelper.getLocalUrl());
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
ResourceManager rm = auth.login(cred);
NodeSet nodes = rm.getNodes(new Criteria(rm.getState().getFreeNodesNumber()));
// use nodes to block until the future is available
System.out.println("Got " + nodes.size());
} catch (Exception e) {
e.printStackTrace();
}
System.exit(1);
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class TestAdminAddingNodes method testAddNodes.
@Test
public void testAddNodes() throws Exception {
final String NS_NAME = "TestAdminAddingNodes";
int pingFrequency = 6000;
ResourceManager resourceManager = rmHelper.getResourceManager();
resourceManager.createNodeSource(NS_NAME, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, NS_NAME);
resourceManager.setNodeSourcePingFrequency(pingFrequency, NS_NAME);
log("Test 1 : add a node");
String node1Name = "node1";
TestNode testNode1 = RMTHelper.createNode(node1Name);
testNodes.add(testNode1);
String node1URL = testNode1.getNodeURL();
resourceManager.addNode(node1URL, NS_NAME);
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 2 : remove an already deployed node");
// preemptive removal is useless for this case, because node is free
resourceManager.removeNode(node1URL, false);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node1URL);
assertEquals(0, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getTotalAliveNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
log("Test 3 : add a node, kill this node, node is detected down, and add a node that has the same URL");
// Test seems to have a race condition at this step
String node2Name = "node2";
TestNode testNode2 = RMTHelper.createNode(node2Name);
testNodes.add(testNode2);
String node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
// wait the node added event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
testNode2.kill();
testNodes.remove(testNode2);
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.DOWN);
// wait the node down event
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(0, resourceManager.getState().getTotalAliveNodesNumber());
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
// wait the node added event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
log("Test 4 : add a node, keep this node free, kill this node, and add a node that has the same URL");
// put a large ping frequency in order to avoid down nodes detection
resourceManager.setNodeSourcePingFrequency(Integer.MAX_VALUE, NS_NAME);
// wait the end of last ping sequence
Thread.sleep(pingFrequency * 2);
// node2 is free, kill the node
testNode2.kill();
testNodes.remove(testNode2);
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
NodeFactory.getNode(node2URL);
// wait the node added event, node added is configuring
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 5 : add a node, put this node busy, kill this node, and add a node that has the same URL");
// put the the node to busy state
NodeSet nodes = resourceManager.getAtMostNodes(1, null);
PAFuture.waitFor(nodes);
// wait the node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.BUSY);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
// node2 is busy, kill the node
testNode2.kill();
testNodes.remove(testNode2);
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
NodeFactory.getNode(node2URL);
// wait the node added event, node added is configuring
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 6 : add a node, put this node toRelease, kill this node, and add a node that has the same URL");
// put the the node to busy state
nodes = resourceManager.getAtMostNodes(1, null);
PAFuture.waitFor(nodes);
// wait the node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.BUSY);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
// put the node in to Release state
resourceManager.removeNode(node2URL, false);
// wait the node to release event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
testNode2.kill();
testNodes.remove(testNode2);
// create another node with the same URL, and add it to Resource manager
testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
testNodes.add(testNode2);
node2URL = testNode2.getNodeURL();
resourceManager.addNode(node2URL, NS_NAME);
NodeFactory.getNode(node2URL);
// wait the node added event, node added is configuring
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(evt.getNodeState(), NodeState.FREE);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 7");
// add the same node twice and check that RM will not kill the node. If it does
// second attempt will fail
BooleanWrapper result = resourceManager.addNode(node2URL, NS_NAME);
assertFalse(result.getBooleanValue());
try {
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL, 8000);
fail("Should timeout");
} catch (ProActiveTimeoutException expected) {
// expected
}
}
use of org.ow2.proactive.utils.NodeSet 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) {
}
}
Aggregations