Search in sources :

Example 11 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager 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 12 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class TestNSProviderPermissions method testNodeProviderMe.

@Test
public void testNodeProviderMe() throws Exception {
    RMTHelper.log("Test1 - node providers = ME");
    ResourceManager nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
    nsadmin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ME" }, NODES_NOT_RECOVERABLE);
    List<TestNode> nodePool = rmHelper.createNodes("node", 2);
    testNode = nodePool.get(0);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    Node node1 = nodePool.remove(0).getNode();
    Node node2 = nodePool.remove(0).getNode();
    nsadmin.addNode(node1.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    ResourceManager user = rmHelper.getResourceManager(TestUsers.RADMIN);
    try {
        // user does not allow to add nodes
        user.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    try {
        // user does not allow to remove nodes
        user.removeNode(node1.getNodeInformation().getURL(), true).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    // AllPermission user
    ResourceManager admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    // user does not allow to add nodes
    admin.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    // user does not allow to remove nodes
    admin.removeNode(node1.getNodeInformation().getURL(), true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    // user does not allow to remove nodes
    admin.removeNodeSource(nsName, true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
}
Also used : DefaultInfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) TestNode(functionaltests.utils.TestNode) Node(org.objectweb.proactive.core.node.Node) TestNode(functionaltests.utils.TestNode) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 13 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class DynamicSelectionScriptTest method action.

@Test
public void action() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    int nsSize = rmHelper.createNodeSource("DynamicSelectionScriptTest");
    String node1Name = "node1";
    String node2Name = "node2";
    HashMap<String, String> vmProperties = new HashMap<>();
    String vmPropKey = "myProperty";
    String vmPropValue = "myValue";
    vmProperties.put(vmPropKey, vmPropValue);
    TestNode node1 = rmHelper.createNode(node1Name, vmProperties);
    testNodes.add(node1);
    String node1URL = node1.getNode().getNodeInformation().getURL();
    resourceManager.addNode(node1URL);
    // wait node adding event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
    // wait for the node to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // create the dynamic selection script object
    SelectionScript sScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, true);
    log("Test 1");
    NodeSet nodes = resourceManager.getAtMostNodes(1, sScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(1, nodes.size());
    assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
    assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
    RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    resourceManager.releaseNode(nodes.get(0));
    // wait for node free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    log("Test 2");
    nodes = resourceManager.getAtMostNodes(3, sScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(1, nodes.size());
    assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
    assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
    // wait for node busy event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    resourceManager.releaseNode(nodes.get(0));
    // wait for node free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    log("Test 3");
    // add a second with JVM env var
    TestNode node2 = rmHelper.createNode(node2Name, vmProperties);
    testNodes.add(node2);
    String node2URL = node2.getNode().getNodeInformation().getURL();
    resourceManager.addNode(node2URL);
    // wait node adding event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the node to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    nodes = resourceManager.getAtMostNodes(3, sScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(2, nodes.size());
    assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
    // wait for nodes busy event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    resourceManager.releaseNodes(nodes);
    // wait for node free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    log("Test 4");
    resourceManager.removeNode(node1URL, true);
    resourceManager.removeNode(node2URL, true);
    // wait for node removed event
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node2URL);
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node1URL);
    nodes = resourceManager.getAtMostNodes(3, sScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
    log("Test 5");
    // create the bad dynamic selection script object
    SelectionScript badScript = new SelectionScript(new File(badSelectionScriptpath.toURI()), new String[] {}, true);
    nodes = resourceManager.getAtMostNodes(3, badScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
    log("Test 6");
    // create the dynamic selection script object that doesn't define 'selected'
    SelectionScript noSelectedScript = new SelectionScript(new File(withoutSelectedSelectionScriptpath.toURI()), new String[] {}, true);
    nodes = resourceManager.getAtMostNodes(3, noSelectedScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(nsSize, resourceManager.getState().getFreeNodesNumber());
    log("Test 7");
    // Checking the dynamicity of the node (period during which the dynamic characteristics do not change).
    // It sets to 10 secs for testing configuration.
    // So first run the dynamic script that fails checking if the file exist
    // Then create a file and call getNodes again. It must return 0 nodes.
    // Wait for 10 secs and call getNodes again. The script must be executed now
    // and we should get some nodes.
    final String FILE_NAME = System.getProperty("java.io.tmpdir") + "/dynamicity.selection";
    if (new File(FILE_NAME).exists()) {
        new File(FILE_NAME).delete();
    }
    SelectionScript fileCheck = new SelectionScript(new File(fileCheckScriptPath.toURI()), new String[] { FILE_NAME }, true);
    log("The dynamic script checking is file exists must fail " + FILE_NAME);
    nodes = resourceManager.getAtMostNodes(1, fileCheck);
    assertEquals(0, nodes.size());
    log("Creating the file " + FILE_NAME);
    new File(FILE_NAME).createNewFile();
    log("The dynamic script checking is file exists must not be executed " + FILE_NAME);
    nodes = resourceManager.getAtMostNodes(1, fileCheck);
    assertEquals(0, nodes.size());
    Thread.sleep(10000);
    log("The dynamic script checking is file exists must pass " + FILE_NAME);
    nodes = resourceManager.getAtMostNodes(1, fileCheck);
    assertEquals(1, nodes.size());
    new File(FILE_NAME).delete();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) SelectionScript(org.ow2.proactive.scripting.SelectionScript) HashMap(java.util.HashMap) TestNode(functionaltests.utils.TestNode) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) File(java.io.File) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 14 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class SelectionWithSeveralScriptsTest method action.

@Test
public void action() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    String nodeSourceName = "selection-several-ns";
    resourceManager.createNodeSource(nodeSourceName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nodeSourceName);
    String node1Name = "node-sel-1";
    String node2Name = "node-sel-2";
    String node3Name = "node-sel-3";
    // ---------------------------------------------------
    // create a first node with the two VM properties
    // ---------------------------------------------------
    HashMap<String, String> vmTwoProperties = new HashMap<>();
    String vmPropKey1 = "myProperty1";
    String vmPropValue1 = "myValue1";
    vmTwoProperties.put(vmPropKey1, vmPropValue1);
    String vmPropKey2 = "myProperty2";
    String vmPropValue2 = "myValue2";
    vmTwoProperties.put(vmPropKey2, vmPropValue2);
    TestNode node1 = rmHelper.createNode(node1Name, vmTwoProperties);
    testNodes.add(node1);
    String node1URL = node1.getNode().getNodeInformation().getURL();
    resourceManager.addNode(node1URL, nodeSourceName);
    // wait node adding event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
    // wait for the nodes to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    Assert.assertEquals(1, resourceManager.listAliveNodeUrls().size());
    // --------------------------------------------------
    // create a second node with only the first VM property
    // ---------------------------------------------------
    HashMap<String, String> vmProp1 = new HashMap<>();
    vmProp1.put(vmPropKey1, vmPropValue1);
    TestNode node2 = rmHelper.createNode(node2Name, vmProp1);
    testNodes.add(node2);
    String node2URL = node2.getNode().getNodeInformation().getURL();
    resourceManager.addNode(node2URL, nodeSourceName);
    // wait node adding event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the nodes to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    Assert.assertEquals(2, resourceManager.listAliveNodeUrls().size());
    // --------------------------------------------------
    // create a third node with only the second VM property
    // ---------------------------------------------------
    HashMap<String, String> vmProp2 = new HashMap<>();
    vmProp1.put(vmPropKey2, vmPropValue2);
    TestNode node3 = rmHelper.createNode(node3Name, vmProp2);
    testNodes.add(node3);
    String node3URL = node3.getNode().getNodeInformation().getURL();
    resourceManager.addNode(node3URL, nodeSourceName);
    // wait node adding event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node3URL);
    // wait for the nodes to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    Assert.assertEquals(3, resourceManager.listAliveNodeUrls().size());
    // create the static selection script object that check vm prop1
    SelectionScript sScript1 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey1, vmPropValue1 }, true);
    // create the static selection script object prop2
    SelectionScript sScript2 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey2, vmPropValue2 }, false);
    log("Test 1");
    ArrayList<SelectionScript> scriptsList = new ArrayList<>();
    scriptsList.add(sScript1);
    scriptsList.add(sScript2);
    NodeSet nodes = resourceManager.getAtMostNodes(1, scriptsList, null);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(1, nodes.size());
    assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
    // wait for node busy event
    RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    assertEquals(2, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(nodes);
    // wait for node free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    assertEquals(3, resourceManager.getState().getFreeNodesNumber());
    log("Test 2");
    nodes = resourceManager.getAtMostNodes(3, scriptsList, nodes);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(3, resourceManager.getState().getFreeNodesNumber());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) SelectionScript(org.ow2.proactive.scripting.SelectionScript) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TestNode(functionaltests.utils.TestNode) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) File(java.io.File) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 15 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager 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)

Aggregations

ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)45 NodeSet (org.ow2.proactive.utils.NodeSet)26 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)25 Test (org.junit.Test)25 Node (org.objectweb.proactive.core.node.Node)16 File (java.io.File)14 Credentials (org.ow2.proactive.authentication.crypto.Credentials)14 Criteria (org.ow2.proactive.utils.Criteria)13 HashMap (java.util.HashMap)11 CredData (org.ow2.proactive.authentication.crypto.CredData)11 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)11 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)10 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)10 TestNode (functionaltests.utils.TestNode)9 SelectionScript (org.ow2.proactive.scripting.SelectionScript)9 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)5 PublicKey (java.security.PublicKey)4