use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class AddGetRemoveTest method action.
@Test
public void action() throws Exception {
final ResourceManager rm = rmHelper.getResourceManager();
// The username and thr password must be the same a used to connect to the RM
final String adminLogin = TestUsers.TEST.username;
final String adminPassword = TestUsers.TEST.password;
// All accounting values are checked through JMX
final RMAuthentication auth = rmHelper.getRMAuth();
final PublicKey pubKey = auth.getPublicKey();
final Credentials adminCreds = Credentials.createCredentials(new CredData(adminLogin, adminPassword), pubKey);
final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
final HashMap<String, Object> env = new HashMap<>(1);
env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
// Connect to the JMX RMI Connector Server
final ObjectName myAccountMBeanName = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
final ObjectName managementMBeanName = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
// ADD, GET, RELEASE
// 1) ADD
testNode = rmHelper.createNode("test");
Node node = testNode.getNode();
final String nodeURL = node.getNodeInformation().getURL();
rm.addNode(nodeURL).getBooleanValue();
// we eat the configuring to free
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// 2) GET
final long beforeGetTime = System.currentTimeMillis();
long originalUsedNodeTime = getUsedNodeTime(myAccountMBeanName, managementMBeanName, conn);
NodeSet nodes = rm.getNodes(new Criteria(1));
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
Thread.sleep(GR_DURATION);
rm.releaseNodes(nodes);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// Check account values validity
long usedNodeTime = getUsedNodeTime(myAccountMBeanName, managementMBeanName, conn) - originalUsedNodeTime;
// 3) REMOVE
rm.removeNode(nodeURL, true).getBooleanValue();
final long getRemoveMaxDuration = System.currentTimeMillis() - beforeGetTime;
assertThat("Invalid value of the usedNodeTime attribute", usedNodeTime, greaterThan(GR_DURATION));
assertThat("Invalid value of the usedNodeTime attribute", usedNodeTime, lessThan(getRemoveMaxDuration));
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class TestLocalInfrastructureRestartDownNodesPolicy method testRestartDownNodesPolicyWithRemoveNode.
/**
* This test ensures that when a node has been manually removed it is not redeployed by the policy
*/
@Test
public void testRestartDownNodesPolicyWithRemoveNode() throws Exception {
nodeSourceName = "Node_source_2";
RMTHelper.log("Test 2 - restart down nodes policy with a node removed");
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());
}
// remove the first node
Node nodeToRemove = ns.remove(0);
resourceManager.removeNode(nodeToRemove.getNodeInformation().getURL(), true);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, nodeToRemove.getNodeInformation().getURL());
RMTHelper.log("Node removed.");
stateTest1 = resourceManager.getState();
assertEquals(defaultDescriptorNodesNb - 1, stateTest1.getTotalNodesNumber());
String nodeUrl = ns.get(0).getNodeInformation().getURL();
// Nodes will be redeployed only if we kill the whole runtime
rmHelper.killRuntime(nodeUrl);
// one node is down - the policy should detect it and redeploy
for (int i = 0; i < defaultDescriptorNodesNb - 1; i++) {
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, ns.get(i).getNodeInformation().getURL());
}
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
for (int i = 0; i < defaultDescriptorNodesNb - 1; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
}
// now one node less should be deployed
assertEquals(defaultDescriptorNodesNb - 1, stateTest1.getTotalNodesNumber());
assertEquals(defaultDescriptorNodesNb - 1, stateTest1.getTotalAliveNodesNumber());
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class TestSSHInfrastructureV2RestartDownNodesPolicy method testSSHInfrastructureV2WithRestartDownNodes.
@Test
public void testSSHInfrastructureV2WithRestartDownNodes() throws Exception {
nsname = "testSSHInfraRestart";
resourceManager = this.rmHelper.getResourceManager();
RMTHelper.log("Test - Create SSH infrastructure with RestartDownNodes policy on ssh://localhost on port " + TestSSHInfrastructureV2.port);
resourceManager.createNodeSource(nsname, SSHInfrastructureV2.class.getName(), TestSSHInfrastructureV2.infraParams, RestartDownNodesPolicy.class.getName(), TestSSHInfrastructureV2.policyParameters, NODES_NOT_RECOVERABLE);
RMMonitorsHandler monitorsHandler = this.rmHelper.getMonitorsHandler();
this.rmHelper.waitForNodeSourceCreation(nsname, NB_NODES, monitorsHandler);
RMState s = resourceManager.getState();
assertEquals(NB_NODES, s.getTotalNodesNumber());
assertEquals(NB_NODES, s.getFreeNodesNumber());
NodeSet nodeset = resourceManager.getNodes(new Criteria(NB_NODES));
if (nodeset.size() != NB_NODES) {
RMTHelper.log("Illegal state : the infrastructure could not deploy nodes or they died immediately. Ending test");
throw new RuntimeException("Illegal state : the infrastructure could not deploy nodes or they died immediately. Ending test");
}
for (Node n : nodeset) {
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL(), 60000, monitorsHandler);
}
String nodeUrl = nodeset.get(0).getNodeInformation().getURL();
RMTHelper.log("Killing nodes");
// Nodes will be redeployed only if we kill the whole runtime
rmHelper.killRuntime(nodeUrl);
RMTHelper.log("Wait for down nodes detection by the rm");
for (Node n : nodeset) {
RMNodeEvent ev = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL(), 120000, monitorsHandler);
assertEquals(NodeState.DOWN, ev.getNodeState());
}
for (Node n : nodeset) {
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL(), 120000, monitorsHandler);
}
RMTHelper.log("Dumping events not consumed yet");
monitorsHandler.dumpEvents();
RMTHelper.log("Wait for nodes restart by the policy");
rmHelper.waitForAnyMultipleNodeEvent(RMEventType.NODE_ADDED, NB_NODES, monitorsHandler);
for (int i = 0; i < NB_NODES; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED, monitorsHandler);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED, monitorsHandler);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, monitorsHandler);
}
RMTHelper.log("Final checks on the scheduler state");
nodeset = resourceManager.getNodes(new Criteria(NB_NODES));
for (Node n : nodeset) {
System.out.println("NODE::" + n.getNodeInformation().getURL());
}
s = resourceManager.getState();
assertEquals(NB_NODES, s.getTotalNodesNumber());
// check amount of all nodes that are not down
assertEquals(NB_NODES, s.getTotalAliveNodesNumber());
}
use of org.ow2.proactive.utils.NodeSet 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.utils.NodeSet in project scheduling by ow2-proactive.
the class TestNSNodesPermissions method action.
@Test
public void action() throws Exception {
String nsName = "TestNSNodesPermissions";
RMTHelper.log("Test1 - node users = ME");
ResourceManager nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nsadmin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ME", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
List<Node> nodePool = createNodes("node", 2);
Node node = nodePool.remove(0);
Node node2 = nodePool.remove(0);
nsadmin.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
NodeSet nodes = nsadmin.getNodes(new Criteria(1));
// we eat free -> busy
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(1, nodes.size());
nsadmin.releaseNodes(nodes);
// busy -> free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
ResourceManager user = rmHelper.getResourceManager(TestUsers.RADMIN);
nodes = user.getNodes(new Criteria(1));
assertEquals("User cannot get foreign node", 0, nodes.size());
user.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2.getNodeInformation().getURL());
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nodes = nsadmin.getNodes(new Criteria(2));
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals("Did not get foreign node", 2, nodes.size());
nsadmin.releaseNodes(nodes);
// busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test2 - node users = MY_GROUPS");
ResourceManager admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "MY_GROUPS", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
node2 = nodePool.remove(0);
System.out.println(System.currentTimeMillis());
admin.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user = rmHelper.getResourceManager(TestUsers.RADMIN);
nodes = user.getNodes(new Criteria(1));
assertEquals("User cannot get foreign node", 0, nodes.size());
user.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2.getNodeInformation().getURL());
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nodes = nsadmin.getNodes(new Criteria(2));
assertEquals(2, nodes.size());
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.releaseNodes(nodes);
// busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test3 - node users = PROVIDER");
user = rmHelper.getResourceManager(TestUsers.RADMIN);
user.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "PROVIDER", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
node2 = nodePool.remove(0);
user.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// admin can get 2 nodes as it has AllPermissions
nodes = admin.getNodes(new Criteria(2));
assertEquals("Admin did not get foreign node", 2, nodes.size());
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin.releaseNodes(nodes);
// busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user = rmHelper.getResourceManager(TestUsers.RADMIN);
nodes = user.getNodes(new Criteria(2));
assertEquals(1, nodes.size());
// we eat free -> busy
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user.releaseNodes(nodes);
// busy -> free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nodes = nsadmin.getNodes(new Criteria(2));
assertEquals("Have got a foreign node", 0, nodes.size());
nsadmin.releaseNodes(nodes);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test4 - node users = PROVIDER_GROUPS");
user = rmHelper.getResourceManager(TestUsers.RADMIN);
user.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "PROVIDER_GROUPS", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
node2 = nodePool.remove(0);
user.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// admin can get 2 nodes as it has AllPermissions
nodes = admin.getNodes(new Criteria(2));
assertEquals("Admin did not get foreign node", 2, nodes.size());
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin.releaseNodes(nodes);
// we eat busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user = rmHelper.getResourceManager(TestUsers.RADMIN);
nodes = user.getNodes(new Criteria(2));
assertEquals(1, nodes.size());
// we eat free -> busy
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user.releaseNodes(nodes);
// we eat busy -> free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nodes = nsadmin.getNodes(new Criteria(2));
assertEquals("Have not get an admin node", 1, nodes.size());
// we eat free -> busy
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.releaseNodes(nodes);
// we eat busy -> free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test5 - node users = ALL");
user = rmHelper.getResourceManager(TestUsers.RADMIN);
user.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
user.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
Criteria criteria = new Criteria(1);
nodes = nsadmin.getNodes(criteria);
assertEquals("Have got a foreign node", 1, nodes.size());
// we eat the free to busy
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.releaseNodes(nodes);
// we eat the busy to free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
criteria.setNodeAccessToken("non_existing_token");
nodes = nsadmin.getNodes(criteria);
assertEquals("Got a regular node while requesting a node with token", 0, nodes.size());
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test6.1 - specific users");
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "users=nsadmin", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
node2 = nodePool.remove(0);
admin.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user = rmHelper.getResourceManager(TestUsers.RADMIN);
nodes = user.getNodes(new Criteria(1));
assertEquals("User cannot get foreign node", 0, nodes.size());
user.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2.getNodeInformation().getURL());
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nodes = user.getNodes(new Criteria(1));
assertEquals("User cannot even your own node", 0, nodes.size());
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nodes = nsadmin.getNodes(new Criteria(2));
assertEquals(2, nodes.size());
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.releaseNodes(nodes);
// busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test6.2 - specific groups");
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "groups=nsadmins", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
node2 = nodePool.remove(0);
admin.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user = rmHelper.getResourceManager(TestUsers.RADMIN);
nodes = user.getNodes(new Criteria(1));
assertEquals("User cannot get foreign node", 0, nodes.size());
user.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2.getNodeInformation().getURL());
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nodes = user.getNodes(new Criteria(1));
assertEquals("User cannot even your own node", 0, nodes.size());
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nodes = nsadmin.getNodes(new Criteria(2));
assertEquals(2, nodes.size());
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.releaseNodes(nodes);
// busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
nodes = admin.getNodes(new Criteria(2));
assertEquals(2, nodes.size());
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin.releaseNodes(nodes);
// busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test6.3 - specific tokens");
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "tokens=token1,token2", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
admin.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
criteria = new Criteria(1);
criteria.setNodeAccessToken("token1");
nodes = admin.getNodes(criteria);
assertEquals(1, nodes.size());
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin.releaseNodes(nodes);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
criteria.setNodeAccessToken("token2");
nodes = admin.getNodes(criteria);
assertEquals(1, nodes.size());
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
admin.releaseNodes(nodes);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// admin also does not have the right to get the node
criteria.setNodeAccessToken("token3");
nodes = admin.getNodes(criteria);
assertEquals(0, nodes.size());
user = rmHelper.getResourceManager(TestUsers.RADMIN);
criteria = new Criteria(1);
nodes = user.getNodes(criteria);
assertEquals(0, nodes.size());
criteria.setNodeAccessToken("token1");
nodes = user.getNodes(criteria);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user.releaseNodes(nodes);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test6.4 - specific users and groups");
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "users=radmin;groups=nsadmins", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
node2 = nodePool.remove(0);
admin.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user = rmHelper.getResourceManager(TestUsers.RADMIN);
nodes = user.getNodes(new Criteria(1));
assertEquals("User did not get a node but had a right to get it", 1, nodes.size());
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user.releaseNodes(nodes);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2.getNodeInformation().getURL());
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nodes = user.getNodes(new Criteria(2));
assertEquals("User did not get nodes but had a right to get them", 2, nodes.size());
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user.releaseNodes(nodes);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
nodes = nsadmin.getNodes(new Criteria(2));
assertEquals(2, nodes.size());
// we eat free -> busy * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.releaseNodes(nodes);
// busy -> free * 2
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
RMTHelper.log("Test6.5 - specific users and token");
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "users=radmin;tokens=token1", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
nodePool = createNodes("node", 2);
node = nodePool.remove(0);
admin.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// we eat the configuring to free nodeevent
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user = rmHelper.getResourceManager(TestUsers.RADMIN);
criteria = new Criteria(1);
criteria.setNodeAccessToken("token1");
nodes = user.getNodes(criteria);
assertEquals("User did not get a node but had a right to get it", 1, nodes.size());
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
user.releaseNodes(nodes);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// will not get a node as don't have the token "token2"
criteria.setNodeAccessToken("token2");
nodes = user.getNodes(criteria);
assertEquals(0, nodes.size());
nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
criteria.setNodeAccessToken("token1");
nodes = nsadmin.getNodes(criteria);
assertEquals(1, nodes.size());
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nsadmin.releaseNodes(nodes);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// removing the node source
admin = rmHelper.getResourceManager(TestUsers.ADMIN);
admin.removeNodeSource(nsName, true).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
}
Aggregations