Search in sources :

Example 11 with TestNode

use of functionaltests.utils.TestNode in project scheduling by ow2-proactive.

the class TestNSNodesPermissions method createNodes.

private List<Node> createNodes(String name, int number) throws Exception {
    List<TestNode> nodePool = rmHelper.createNodes("node", 17);
    testNodes.addAll(nodePool);
    ArrayList<Node> answer = new ArrayList<>(nodePool.size());
    for (TestNode tn : nodePool) {
        answer.add(tn.getNode());
    }
    return answer;
}
Also used : Node(org.objectweb.proactive.core.node.Node) TestNode(functionaltests.utils.TestNode) ArrayList(java.util.ArrayList) TestNode(functionaltests.utils.TestNode)

Example 12 with TestNode

use of functionaltests.utils.TestNode in project scheduling by ow2-proactive.

the class TestNSProviderPermissions method testNodeProviderMyGroups.

@Test
public void testNodeProviderMyGroups() throws Exception {
    RMTHelper.log("Test2 - node providers = MY_GROUPS");
    admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "MY_GROUPS" }, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    List<TestNode> nodePool = rmHelper.createNodes("node", 3);
    testNode = nodePool.get(0);
    Node node1 = nodePool.remove(0).getNode();
    Node node2 = nodePool.remove(0).getNode();
    Node node3 = nodePool.remove(0).getNode();
    admin.addNode(node1.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
    // nsadmin is in the same group as admin
    nsadmin.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    user = rmHelper.getResourceManager(TestUsers.RADMIN);
    try {
        // user does not allow to add nodes
        user.addNode(node3.getNodeInformation().getURL(), nsName).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    try {
        // user does not allow to remove nodes
        user.removeNode(node2.getNodeInformation().getURL(), true).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
    try {
        // nsadmin cannot remove foreign node
        nsadmin.removeNode(node1.getNodeInformation().getURL(), true).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    // but it can remove its own
    nsadmin.removeNode(node2.getNodeInformation().getURL(), true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    nsadmin.addNode(node3.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    // admin can remove foreign node
    admin.removeNode(node3.getNodeInformation().getURL(), true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    admin.removeNodeSource(nsName, true).getBooleanValue();
    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) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 13 with TestNode

use of functionaltests.utils.TestNode in project scheduling by ow2-proactive.

the class TestNSProviderPermissions method testSpecificUsersGroups.

@Test
public void testSpecificUsersGroups() throws Exception {
    RMTHelper.log("Test5.3 - specific users/groups");
    admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "users=radmin;groups=nsadmins" }, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    List<TestNode> nodePool = rmHelper.createNodes("node", 3);
    Node node1 = nodePool.remove(0).getNode();
    Node node2 = nodePool.remove(0).getNode();
    Node node3 = nodePool.remove(0).getNode();
    admin.addNode(node1.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
    try {
        // nsadmin cannot remove node as he is not a node owner
        nsadmin.removeNode(node1.getNodeInformation().getURL(), true).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    nsadmin.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    user = rmHelper.getResourceManager(TestUsers.RADMIN);
    // user can add new nodes
    user.addNode(node3.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    try {
        // user cannot remove node as he is not a node owner
        user.removeNode(node2.getNodeInformation().getURL(), true).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    // user does not allow to remove nodes
    admin.removeNodeSource(nsName, true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    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) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 14 with TestNode

use of functionaltests.utils.TestNode in project scheduling by ow2-proactive.

the class TestNSProviderPermissions method testNodeProviderAll.

@Test
public void testNodeProviderAll() throws Exception {
    RMTHelper.log("Test3 - node providers = ALL");
    nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
    nsadmin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ALL" }, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    List<TestNode> nodePool = rmHelper.createNodes("node", 3);
    testNode = nodePool.get(0);
    Node node1 = nodePool.remove(0).getNode();
    Node node2 = nodePool.remove(0).getNode();
    Node node3 = nodePool.remove(0).getNode();
    nsadmin.addNode(node1.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    user = rmHelper.getResourceManager(TestUsers.RADMIN);
    // user can add new nodes
    user.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    try {
        // but cannot remove a foreign node
        user.removeNode(node1.getNodeInformation().getURL(), true).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    // user can remove his own node
    user.removeNode(node2.getNodeInformation().getURL(), true).getBooleanValue();
    // adding node3
    user.addNode(node3.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    nsadmin = rmHelper.getResourceManager(TestUsers.NSADMIN);
    // nsadmin can remove node3 as ns admin
    nsadmin.removeNode(node3.getNodeInformation().getURL(), true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    nsadmin.removeNodeSource(nsName, true).getBooleanValue();
    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) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 15 with TestNode

use of functionaltests.utils.TestNode in project scheduling by ow2-proactive.

the class SelectionWithNodesExclusionTest method action.

@Test
public void action() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    final int initialNodesNumber = rmHelper.createNodeSource("SelectionWithNodesExclusionTest");
    log("Test 1");
    NodeSet nodeSetWithNodeToExclude = resourceManager.getAtMostNodes(1, null);
    // wait for node selection
    PAFuture.waitFor(nodeSetWithNodeToExclude);
    assertEquals(1, nodeSetWithNodeToExclude.size());
    assertEquals(initialNodesNumber - 1, resourceManager.getState().getFreeNodesNumber());
    // wait for node busy event
    RMNodeEvent evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    resourceManager.releaseNodes(nodeSetWithNodeToExclude);
    // wait for node free event
    evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    Assert.assertEquals(NodeState.FREE, evt.getNodeState());
    assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
    // get nodes with the previous node excluded
    NodeSet nodes = resourceManager.getAtMostNodes(initialNodesNumber, new ArrayList<SelectionScript>(), nodeSetWithNodeToExclude);
    // wait for node selection
    PAFuture.waitFor(nodes);
    for (int i = 0; i < initialNodesNumber - 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        Assert.assertEquals(evt.getNodeState(), NodeState.BUSY);
    }
    // booked all nodes minus the node to exclude
    assertEquals(initialNodesNumber - 1, nodes.size());
    // excluded node stays in free state
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(nodes);
    // wait for nodes freed event
    for (int i = 0; i < initialNodesNumber - 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
    log("Test 2");
    // create the dynamic selection script object
    SelectionScript dummyDynamicScript = new SelectionScript(new File(dummySelectionScriptPath.toURI()), new String[] {}, true);
    // get nodes with the previous node excluded
    nodes = resourceManager.getAtMostNodes(initialNodesNumber, dummyDynamicScript, nodeSetWithNodeToExclude);
    // wait for node selection
    PAFuture.waitFor(nodes);
    // wait for nodes busy event
    for (int i = 0; i < initialNodesNumber - 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.BUSY, evt.getNodeState());
    }
    // booked all nodes minus the node to exclude
    assertEquals(initialNodesNumber - 1, nodes.size());
    // excluded node stays in free state
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(nodes);
    // wait for nodes freed event
    for (int i = 0; i < initialNodesNumber - 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
    log("Test 3");
    // create the static selection script object
    SelectionScript dummyStaticScript = new SelectionScript(new File(dummySelectionScriptPath.toURI()), new String[] {}, false);
    // get nodes with the previous node excluded
    nodes = resourceManager.getAtMostNodes(initialNodesNumber, dummyStaticScript, nodeSetWithNodeToExclude);
    // wait for node selection
    PAFuture.waitFor(nodes);
    // wait for nodes busy event
    for (int i = 0; i < initialNodesNumber - 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(evt.getNodeState(), NodeState.BUSY);
    }
    // booked all nodes minus the node to exclude
    assertEquals(initialNodesNumber - 1, nodes.size());
    // excluded node stays in free state
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(nodes);
    // wait for node free event
    for (int i = 0; i < initialNodesNumber - 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    assertEquals(initialNodesNumber, resourceManager.getState().getFreeNodesNumber());
    log("Test 4");
    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);
    TestNode node2 = rmHelper.createNode(node2Name, vmProperties);
    testNodes.add(node2);
    String node2URL = node2.getNode().getNodeInformation().getURL();
    resourceManager.addNode(node2URL);
    Thread.sleep(5000);
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the nodes to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // wait for nodes added events
    assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
    // create the dynamic selection script object
    SelectionScript checkPropDynamicSScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, true);
    Node node1ToExclude = NodeFactory.getNode(node1URL);
    nodeSetWithNodeToExclude = new NodeSet();
    nodeSetWithNodeToExclude.add(node1ToExclude);
    // get nodes with the previous node1 excluded
    nodes = resourceManager.getAtMostNodes(initialNodesNumber, checkPropDynamicSScript, nodeSetWithNodeToExclude);
    // wait for node selection
    PAFuture.waitFor(nodes);
    // wait for nodes busy event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    // booked all nodes minus the node to exclude
    assertEquals(1, nodes.size());
    // excluded node stays in free state
    assertEquals(initialNodesNumber + 1, resourceManager.getState().getFreeNodesNumber());
    // unique node got is node2
    assertEquals(node2URL, nodes.get(0).getNodeInformation().getURL());
    resourceManager.releaseNodes(nodes);
    // wait for node free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
    log("Test 5");
    // create the static selection script object
    SelectionScript checkPropStaticSScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, false);
    Node node2ToExclude = NodeFactory.getNode(node2URL);
    nodeSetWithNodeToExclude = new NodeSet();
    nodeSetWithNodeToExclude.add(node2ToExclude);
    // get nodes with the previous node1 excluded
    nodes = resourceManager.getAtMostNodes(initialNodesNumber, checkPropStaticSScript, nodeSetWithNodeToExclude);
    // wait for node selection
    PAFuture.waitFor(nodes);
    // wait for nodes busy event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    // booked all nodes minus the node to exclude
    assertEquals(1, nodes.size());
    // excluded node stays in free state
    assertEquals(initialNodesNumber + 1, resourceManager.getState().getFreeNodesNumber());
    // unique node got is node2
    assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
    resourceManager.releaseNodes(nodes);
    // wait for node free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
    log("Test 6");
    nodeSetWithNodeToExclude.add(node1ToExclude);
    // get nodes with the previous node1 excluded
    nodes = resourceManager.getAtMostNodes(initialNodesNumber, checkPropStaticSScript, nodeSetWithNodeToExclude);
    // wait for node selection
    PAFuture.waitFor(nodes);
    assertEquals(initialNodesNumber + 2, resourceManager.getState().getFreeNodesNumber());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) SelectionScript(org.ow2.proactive.scripting.SelectionScript) HashMap(java.util.HashMap) Node(org.objectweb.proactive.core.node.Node) TestNode(functionaltests.utils.TestNode) TestNode(functionaltests.utils.TestNode) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) File(java.io.File) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Aggregations

TestNode (functionaltests.utils.TestNode)17 Test (org.junit.Test)15 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)14 Node (org.objectweb.proactive.core.node.Node)10 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)8 DefaultInfrastructureManager (org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager)8 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)8 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)7 NodeSet (org.ow2.proactive.utils.NodeSet)7 File (java.io.File)5 HashMap (java.util.HashMap)5 SelectionScript (org.ow2.proactive.scripting.SelectionScript)5 ArrayList (java.util.ArrayList)3 URI (java.net.URI)1 Path (java.nio.file.Path)1 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)1 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1