Search in sources :

Example 21 with RMNodeEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.

the class TestNodeEncoding method createNodeSourceWithOneLocalNode.

protected String createNodeSourceWithOneLocalNode() throws Exception {
    byte[] credentials = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
    String javaProperty = "-D" + PAProperties.KEY_PA_FILE_ENCODING + "=" + FILE_ENCODING_NAME;
    rmHelper.getResourceManager(TestUsers.TEST, javaProperty).createNodeSource("testEncoding", LocalInfrastructure.class.getName(), new Object[] { credentials, 1, RMTHelper.DEFAULT_NODES_TIMEOUT, "" }, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceCreation("testEncoding");
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    RMNodeEvent rmNodeEvent = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    String nodeUrl = rmNodeEvent.getNodeUrl();
    logger.info("New node added " + nodeUrl);
    logger.info("Node has state '" + rmNodeEvent.getNodeState() + "'");
    return nodeUrl;
}
Also used : LocalInfrastructure(org.ow2.proactive.resourcemanager.nodesource.infrastructure.LocalInfrastructure) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) File(java.io.File) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)

Example 22 with RMNodeEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent 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 23 with RMNodeEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent 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 24 with RMNodeEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent 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)

Example 25 with RMNodeEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.

the class StaticSelectionScriptTest method action.

@Test
public void action() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    int nodeNumber = rmHelper.createNodeSource("StaticSelectionScriptTest");
    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 nodes to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // create the static selection script object
    SelectionScript sScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, false);
    log("Test 1");
    NodeSet nodes = resourceManager.getAtMostNodes(1, sScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(1, nodes.size());
    assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
    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());
    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(nodeNumber, 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 nodes 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(nodeNumber, resourceManager.getState().getFreeNodesNumber());
    // wait for node 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 nodes free event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(NodeState.FREE, evt.getNodeState());
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    Assert.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, node1URL);
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node2URL);
    nodes = resourceManager.getAtMostNodes(3, sScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
    log("Test 5");
    // create the bad static selection script object
    SelectionScript badScript = new SelectionScript(new File(badSelectionScriptpath.toURI()), new String[] {}, false);
    nodes = resourceManager.getAtMostNodes(3, badScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
    log("Test 6");
    // create the static selection script object that doesn't define 'selected'
    SelectionScript noSelectedScript = new SelectionScript(new File(withoutSelectedSelectionScriptpath.toURI()), new String[] {}, false);
    nodes = resourceManager.getAtMostNodes(3, noSelectedScript);
    // wait node selection
    PAFuture.waitFor(nodes);
    assertEquals(0, nodes.size());
    assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
}
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

RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)27 Test (org.junit.Test)14 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)13 NodeSet (org.ow2.proactive.utils.NodeSet)13 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)10 File (java.io.File)8 TestNode (functionaltests.utils.TestNode)7 Node (org.objectweb.proactive.core.node.Node)7 HashMap (java.util.HashMap)6 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)6 SelectionScript (org.ow2.proactive.scripting.SelectionScript)6 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)5 NodeState (org.ow2.proactive.resourcemanager.common.NodeState)4 RMState (org.ow2.proactive.resourcemanager.common.RMState)4 Criteria (org.ow2.proactive.utils.Criteria)4 ArrayList (java.util.ArrayList)3 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)3 DefaultInfrastructureManager (org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager)3 URI (java.net.URI)2 HashSet (java.util.HashSet)2