Search in sources :

Example 1 with TestNode

use of functionaltests.utils.TestNode 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 2 with TestNode

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

the class TestNSProviderPermissions method testSpecificUsers.

@Test
public void testSpecificUsers() throws Exception {
    RMTHelper.log("Test5.1 - specific users");
    admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "users=nsadmin" }, 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);
    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);
    try {
        // user cannot add new nodes
        user.addNode(node3.getNodeInformation().getURL(), nsName).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    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);
    try {
        // user does not allow to remove nodes
        admin.removeNodeSource(nsName, true).getBooleanValue();
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
        rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
    } catch (Exception e) {
        fail();
    }
}
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 3 with TestNode

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

the class TestNSProviderPermissions method testAdminPriviledge.

@Test
public void testAdminPriviledge() throws Exception {
    RMTHelper.log("Test4 - admin priviledges");
    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", 2);
    testNode = nodePool.get(0);
    Node node1 = nodePool.remove(0).getNode();
    nsadmin.addNode(node1.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    // admin can remove anything
    admin.removeNode(node1.getNodeInformation().getURL(), true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    admin.removeNodeSource(nsName, true);
    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 4 with TestNode

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

the class TestNSProviderPermissions method testSpecificGroups.

@Test
public void testSpecificGroups() throws Exception {
    RMTHelper.log("Test5.2 - specific groups");
    admin = rmHelper.getResourceManager(TestUsers.ADMIN);
    admin.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "groups=nsadmins" }, NODES_NOT_RECOVERABLE).getBooleanValue();
    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);
    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);
    try {
        // user cannot add new nodes
        user.addNode(node3.getNodeInformation().getURL(), nsName).getBooleanValue();
        fail();
    } catch (Exception expected) {
    }
    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.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
}
Also used : TestNode(functionaltests.utils.TestNode) Node(org.objectweb.proactive.core.node.Node) TestNode(functionaltests.utils.TestNode) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 5 with TestNode

use of functionaltests.utils.TestNode 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)

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