Search in sources :

Example 41 with NodeSet

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

the class TestNodesStates method testManyStatesChanges.

@Test
public void testManyStatesChanges() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    int totalNodeNumber = 5;
    rmHelper.createNodeSource("TestNodesStates", totalNodeNumber);
    // ----------------------------------------------------------
    // Book all nodes deployed by descriptor (user action)
    // verify that there are no free nodes left,
    // and give back to RM
    log("Test 1");
    NodeSet nodes = resourceManager.getAtMostNodes(totalNodeNumber, null);
    PAFuture.waitFor(nodes);
    assertEquals(totalNodeNumber, nodes.size());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    for (int i = 0; i < totalNodeNumber; i++) {
        RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodes.get(i).getNodeInformation().getURL());
        assertEquals(NodeState.BUSY, evt.getNodeState());
        checkEvent(evt, nodes.get(i));
    }
    // for next test
    Node n = nodes.get(0);
    resourceManager.releaseNodes(nodes);
    for (int i = 0; i < totalNodeNumber; i++) {
        RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodes.get(i).getNodeInformation().getURL());
        assertEquals(NodeState.FREE, evt.getNodeState());
        checkEvent(evt, nodes.get(i));
    }
    // ----------------------------------------------------------
    // give back a node already given back (i.e; node already free)
    // this action causes nothing(nor increasing free nodes number, nor generation of any event)
    log("Test 2");
    resourceManager.releaseNode(n);
    boolean timeouted = false;
    try {
        rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL(), 4000);
    } catch (ProActiveTimeoutException e) {
        timeouted = true;
    }
    assertTrue(timeouted);
    assertEquals(totalNodeNumber, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // Book all nodes deployed by descriptor
    // Test admin action : Remove a node from the RM (non preemptively),
    // node is busy, so becomes in "toRelease" state
    // user give back to RM the "toRelease" node, node is now removed
    log("Test 3");
    nodes = resourceManager.getAtMostNodes(totalNodeNumber, null);
    PAFuture.waitFor(nodes);
    for (int i = 0; i < totalNodeNumber; i++) {
        RMNodeEvent evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.BUSY, evt.getNodeState());
    }
    n = nodes.remove(0);
    // put node in "To Release" state
    resourceManager.removeNode(n.getNodeInformation().getURL(), false);
    // check that node toRelease event has been thrown
    RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.TO_BE_REMOVED, evt.getNodeState());
    // node is in "ToRelease" state, so always handled by RM
    assertEquals(totalNodeNumber, resourceManager.getState().getTotalNodesNumber());
    // user give back the node, so node is now removed
    resourceManager.releaseNode(n);
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL());
    // ----------------------------------------------------------
    // nodes are always in busy state
    // kill JVM of a node (simulate a fallen JVM or broken connection, i.e down node)
    // node must detected down by RM
    log("Test 4");
    n = nodes.get(0);
    // for next test
    Node n2 = nodes.get(1);
    try {
        n.getProActiveRuntime().killNode(n.getNodeInformation().getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.DOWN, evt.getNodeState());
    checkEvent(evt, n);
    resourceManager.releaseNodes(nodes);
    for (int i = 0; i < totalNodeNumber - 2; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    // two nodes killed, but the detected down is in RM down nodes list
    // ( down nodes are in total nodes count)
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 2, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // nodes left are in free state
    // kill JVM of a free node
    // node must detected down by RM
    log("Test 5");
    try {
        n2.getProActiveRuntime().killNode(n2.getNodeInformation().getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n2.getNodeInformation().getURL());
    assertEquals(NodeState.DOWN, evt.getNodeState());
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 3, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // book nodes, put one node in "toRelease" state,
    // then kill its JVM,
    // node must detected down by RM
    log("Test 6");
    nodes = resourceManager.getAtMostNodes(totalNodeNumber - 3, null);
    PAFuture.waitFor(nodes);
    for (int i = 0; i < totalNodeNumber - 3; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.BUSY, evt.getNodeState());
    }
    n = nodes.get(0);
    // for next test
    n2 = nodes.get(1);
    // put node in "To Release" state
    resourceManager.removeNode(n.getNodeInformation().getURL(), false);
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.TO_BE_REMOVED, evt.getNodeState());
    log("Test 6 Bis");
    // kill the node
    try {
        n.getProActiveRuntime().killNode(n.getNodeInformation().getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.DOWN, evt.getNodeState());
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    for (Node node : nodes) {
        log("Taken node: " + node.getNodeInformation().getURL());
    }
    // we have 2 nodes: 11 busy and one still down
    resourceManager.releaseNodes(nodes);
    for (int i = 0; i < 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 4, resourceManager.getState().getFreeNodesNumber());
    // admin removes again the node, ok he already asked this removal when node n was busy
    // choice here is advert admin that node has fallen (not hiding the down node event),
    // rather than automatically remove it
    resourceManager.removeNode(n.getNodeInformation().getURL(), false);
    // check that node removed event has been received
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL());
    assertEquals(totalNodeNumber - 2, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 4, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // Remove a free node,
    // 
    log("Test 7");
    resourceManager.removeNode(n2.getNodeInformation().getURL(), false);
    // check that node removed event has been received
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n2.getNodeInformation().getURL());
    assertEquals(totalNodeNumber - 3, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 5, resourceManager.getState().getFreeNodesNumber());
    log("End of test");
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) Node(org.objectweb.proactive.core.node.Node) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 42 with NodeSet

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

the class TestNSAdminPermissions method action.

@Test
public void action() throws Exception {
    String nsName = "TestNSAdminPermissions";
    ResourceManager adminRMAccess = rmHelper.getResourceManager(TestUsers.ADMIN);
    RMTHelper.log("Test1 - node source removal");
    adminRMAccess.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ME" }, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    // user does not have an access to change the node source
    ResourceManager userRMAccess = rmHelper.getResourceManager(TestUsers.RADMIN);
    try {
        userRMAccess.removeNodeSource(nsName, true).getBooleanValue();
        fail();
    } catch (Exception e) {
    }
    // admin and provider are in "nsadmins" group
    ResourceManager providerRMAccess = rmHelper.getResourceManager(TestUsers.NSADMIN);
    try {
        providerRMAccess.removeNodeSource(nsName, true).getBooleanValue();
        fail();
    } catch (Exception e) {
    }
    adminRMAccess = rmHelper.getResourceManager(TestUsers.ADMIN);
    adminRMAccess.removeNodeSource(nsName, true).getBooleanValue();
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
    RMTHelper.log("Test2 - ns admin can remove foreign nodes");
    userRMAccess = rmHelper.getResourceManager(TestUsers.RADMIN);
    userRMAccess.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "PROVIDER", "ALL" }, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    providerRMAccess = rmHelper.getResourceManager(TestUsers.NSADMIN);
    TestNode testNode1 = rmHelper.createNode("node1");
    testNodes.add(testNode1);
    Node node = testNode1.getNode();
    // adding the node as provider
    providerRMAccess.addNode(node.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    // node becomes free
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    userRMAccess = rmHelper.getResourceManager(TestUsers.RADMIN);
    // this is an administrator of the node source, so it can remove the foreign node
    userRMAccess.removeNode(node.getNodeInformation().getURL(), true).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    RMTHelper.log("Test3 - ns admin cannot get the foreign node");
    providerRMAccess = rmHelper.getResourceManager(TestUsers.NSADMIN);
    TestNode testNode2 = rmHelper.createNode("node2");
    testNodes.add(testNode2);
    Node node2 = testNode2.getNode();
    // adding the node as provider
    providerRMAccess.addNode(node2.getNodeInformation().getURL(), nsName).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    // node becomes free
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    userRMAccess = rmHelper.getResourceManager(TestUsers.RADMIN);
    // this is an administrator of the node source, so it can remove the foreign node
    NodeSet nodes = userRMAccess.getAtMostNodes(1, null);
    Assert.assertEquals("NS admin cannot get nodes as the get level is set to PROVIDER", 0, nodes.size());
    RMTHelper.log("Test4 - user with AllPermisssion can remove any node sources");
    adminRMAccess = rmHelper.getResourceManager(TestUsers.ADMIN);
    adminRMAccess.removeNodeSource(nsName, true).getBooleanValue();
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
    RMTHelper.log("Success");
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) DefaultInfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) Node(org.objectweb.proactive.core.node.Node) TestNode(functionaltests.utils.TestNode) TestNode(functionaltests.utils.TestNode) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 43 with NodeSet

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

the class SelectionScriptTimeOutTest method action.

@Test
public void action() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    rmHelper.createNodeSource();
    int nodesNumber = resourceManager.getState().getTotalNodesNumber();
    int scriptSleepingTime = 40 * 1000;
    log("Test 1 - selecting nodes with timeout script");
    // create the static selection script object
    SelectionScript script = new SelectionScript(new File(selectionScriptWithtimeOutPath.toURI()), new String[] { Integer.toString(scriptSleepingTime) }, false);
    NodeSet nodes = resourceManager.getAtMostNodes(2, script);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(nodesNumber, resourceManager.getState().getFreeNodesNumber());
    log("Test 2 - selecting nodes with script which is timed out only on some hosts");
    String nodeName = "timeoutNode";
    HashMap<String, String> vmProperties = new HashMap<>();
    vmProperties.put(nodeName, "dummy");
    testNode = rmHelper.createNode(nodeName, vmProperties);
    String nodeURL = testNode.getNode().getNodeInformation().getURL();
    resourceManager.addNode(nodeURL);
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    // wait for the nodes to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // now we have nodesNumber + 1 nodes
    script = new SelectionScript(new File(selectionScriptWithtimeOutPath.toURI()), new String[] { Integer.toString(scriptSleepingTime), nodeName }, false);
    // selecting all nodes
    nodes = resourceManager.getAtMostNodes(nodesNumber + 1, script);
    // have to get nodesNumber due to the script timeout on one node
    assertEquals(nodesNumber, nodes.size());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    // waiting until selection manager finishes script execution for node "timeout"
    // as we don't know how long should we wait roughly estimate it as scriptSleepingTime/2
    Thread.sleep(scriptSleepingTime / 2);
    NodeSet nodes2 = resourceManager.getAtMostNodes(1, null);
    assertEquals(1, nodes2.size());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(nodes).getBooleanValue();
    resourceManager.releaseNodes(nodes2).getBooleanValue();
    nodes = resourceManager.getAtMostNodes(2, script);
    assertEquals(2, nodes.size());
    assertEquals(nodesNumber - 1, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(nodes);
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) SelectionScript(org.ow2.proactive.scripting.SelectionScript) HashMap(java.util.HashMap) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) File(java.io.File) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 44 with NodeSet

use of org.ow2.proactive.utils.NodeSet 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)

Example 45 with NodeSet

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

the class SelectionWithSeveralScriptsTest2 method action.

@Test
public void action() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    String nodeSourceName = "SelectionWithSeveralScriptsTest2";
    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-sel2-1";
    String node2Name = "node-sel2-2";
    // ---------------------------------------------------
    // create a first node with one VM property
    // ---------------------------------------------------
    HashMap<String, String> vmProp1 = new HashMap<>();
    String vmPropKey1 = "myProperty1";
    String vmPropValue1 = "myValue1";
    vmProp1.put(vmPropKey1, vmPropValue1);
    TestNode node1 = rmHelper.createNode(node1Name, vmProp1);
    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 node to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // --------------------------------------------------
    // create a second node with two VM properties
    // ---------------------------------------------------
    HashMap<String, String> vmTwoProperties = new HashMap<>();
    vmTwoProperties.put(vmPropKey1, vmPropValue1);
    String vmPropKey2 = "myProperty2";
    String vmPropValue2 = "myValue2";
    vmTwoProperties.put(vmPropKey2, vmPropValue2);
    TestNode node2 = rmHelper.createNode(node2Name, vmTwoProperties);
    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 node to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // 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(node2URL, nodes.get(0).getNodeInformation().getURL());
    // wait for node busy event
    RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(NodeState.BUSY, evt.getNodeState());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(nodes);
    // wait for node free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    assertEquals(2, 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)

Aggregations

NodeSet (org.ow2.proactive.utils.NodeSet)51 Test (org.junit.Test)28 Criteria (org.ow2.proactive.utils.Criteria)23 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)20 Node (org.objectweb.proactive.core.node.Node)18 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)17 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 SelectionScript (org.ow2.proactive.scripting.SelectionScript)10 File (java.io.File)9 TestNode (functionaltests.utils.TestNode)8 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)7 RMCore (org.ow2.proactive.resourcemanager.core.RMCore)5 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)5 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)4 RMState (org.ow2.proactive.resourcemanager.common.RMState)4 IOException (java.io.IOException)3 Permission (java.security.Permission)3 HashSet (java.util.HashSet)3