Search in sources :

Example 6 with Criteria

use of org.ow2.proactive.utils.Criteria 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());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node) Criteria(org.ow2.proactive.utils.Criteria) RMState(org.ow2.proactive.resourcemanager.common.RMState) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 7 with Criteria

use of org.ow2.proactive.utils.Criteria 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());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) RestartDownNodesPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.RestartDownNodesPolicy) Node(org.objectweb.proactive.core.node.Node) SSHInfrastructureV2(org.ow2.proactive.resourcemanager.nodesource.infrastructure.SSHInfrastructureV2) Criteria(org.ow2.proactive.utils.Criteria) RMState(org.ow2.proactive.resourcemanager.common.RMState) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMMonitorsHandler(functionaltests.monitor.RMMonitorsHandler) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 8 with Criteria

use of org.ow2.proactive.utils.Criteria 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);
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node) TestNode(functionaltests.utils.TestNode) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Criteria(org.ow2.proactive.utils.Criteria) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 9 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class UnauthorizedSelectionScriptTest method action.

@Test
public void action() throws Exception {
    String rmconf = new File(PAResourceManagerProperties.getAbsolutePath(getClass().getResource("/functionaltests/config/rm-authorized-selection-script.ini").getFile())).getAbsolutePath();
    rmHelper.startRM(rmconf);
    ResourceManager rm = this.rmHelper.getResourceManager();
    this.rmHelper.createNodeSource("Dummy", 1);
    log("Test 1 - unautorized script");
    Criteria criteria = new Criteria(1);
    URL vmPropSelectionScriptpath = this.getClass().getResource("dummySelectionScript.js");
    List<SelectionScript> scripts = new ArrayList<>();
    scripts.add(new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), null, true));
    criteria.setScripts(scripts);
    try {
        NodeSet ns = rm.getNodes(criteria);
        System.out.println("Number of nodes matched " + ns.size());
        fail("Executed unauthorized selection script");
    } catch (SecurityException ex) {
        log("Test 1 - passed");
    }
    log("Test 2 - authorized script");
    String authorizedScriptPath = PAResourceManagerProperties.RM_HOME.getValueAsString() + "/samples/scripts/selection/checkPhysicalFreeMem.js";
    scripts = new ArrayList<>();
    scripts.add(new SelectionScript(new File(authorizedScriptPath), new String[] { "1" }, true));
    criteria.setScripts(scripts);
    NodeSet ns = rm.getNodes(criteria);
    System.out.println("Number of nodes matched " + ns.size());
    assertEquals(1, ns.size());
    log("Test 2 - passed");
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) SelectionScript(org.ow2.proactive.scripting.SelectionScript) ArrayList(java.util.ArrayList) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Criteria(org.ow2.proactive.utils.Criteria) File(java.io.File) URL(java.net.URL) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 10 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class LocalSelectionTest method getNodesAndReleaseThem.

private void getNodesAndReleaseThem(int number, TopologyDescriptor descriptor, int expectedReceived, int expectedExtraNodesSize) {
    Criteria c = new Criteria(number);
    c.setTopology(descriptor);
    NodeSet ns = resourceManager.getNodes(c);
    Assert.assertEquals(expectedReceived, ns.size());
    Collection<Node> extra = ns.getExtraNodes();
    if (expectedExtraNodesSize == 0) {
        Assert.assertNull(extra);
    } else {
        Assert.assertEquals(expectedExtraNodesSize, extra.size());
    }
    resourceManager.releaseNodes(ns).getBooleanValue();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node) Criteria(org.ow2.proactive.utils.Criteria)

Aggregations

Criteria (org.ow2.proactive.utils.Criteria)25 NodeSet (org.ow2.proactive.utils.NodeSet)23 Test (org.junit.Test)16 Node (org.objectweb.proactive.core.node.Node)9 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)7 ArrayList (java.util.ArrayList)7 RMCore (org.ow2.proactive.resourcemanager.core.RMCore)6 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)6 CredData (org.ow2.proactive.authentication.crypto.CredData)5 Credentials (org.ow2.proactive.authentication.crypto.Credentials)5 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)5 Client (org.ow2.proactive.resourcemanager.authentication.Client)4 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)4 LinkedList (java.util.LinkedList)3 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)3 RMState (org.ow2.proactive.resourcemanager.common.RMState)3 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)3 PublicKey (java.security.PublicKey)2 HashMap (java.util.HashMap)2 List (java.util.List)2