Search in sources :

Example 6 with TestNode

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

the class SelectionWithSeveralScriptsTest method action.

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

Example 7 with TestNode

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

the class TestTaskRestartOnNodeFailure method testTaskKillNode.

private void testTaskKillNode(FileLock fileLock, boolean waitBeforeKill) throws Exception {
    Path fileLockPath = fileLock.lock();
    TestNode nodeToKill = startNode();
    log("Submit job");
    final JobId jobId = schedulerHelper.submitJob(createJob(fileLockPath.toString()));
    log("Wait when node becomes busy");
    RMNodeEvent event;
    do {
        event = schedulerHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, TIMEOUT);
    } while (!event.getNodeState().equals(NodeState.BUSY));
    log("Wait when task starts");
    schedulerHelper.waitForEventTaskRunning(jobId, "Test task");
    /*
         * Want to test two cases (existed at the time of this writing): - if wait some time before
         * killing node then node failure is detected by the pinger thread - if kill node
         * immediately then node failure is detected by the thread calling TaskLauncher.doTask
         */
    if (waitBeforeKill) {
        log("Wait some time");
        Thread.sleep(5000);
    }
    log("Stop task node process (node " + nodeToKill.getNode().getNodeInformation().getURL() + ")");
    nodeToKill.kill();
    TestNode newNode = startNode();
    log("Let task finish");
    fileLock.unlock();
    log("Wait when job finish");
    schedulerHelper.waitForEventJobFinished(jobId, TIMEOUT);
    event = schedulerHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, newNode.getNode().getNodeInformation().getURL(), TIMEOUT);
    assertEquals(NodeState.BUSY, event.getNodeState());
    event = schedulerHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, newNode.getNode().getNodeInformation().getURL(), TIMEOUT);
    assertEquals(NodeState.FREE, event.getNodeState());
    log("Check job result");
    checkJobResult(schedulerHelper.getSchedulerInterface(), jobId);
    schedulerHelper.getResourceManager().removeNode(newNode.getNodeURL(), true);
    newNode.kill();
}
Also used : Path(java.nio.file.Path) TestNode(functionaltests.utils.TestNode) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 8 with TestNode

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

the class TestChildProcessOfNodeKilled method childProcessesForkedByTaskAreCleanedUpWhenRMNodeStarterIsKilled.

@Test
public void childProcessesForkedByTaskAreCleanedUpWhenRMNodeStarterIsKilled() throws Throwable {
    TestNode tNode = startSchedulerAndRMWithOneNode();
    startJobForkingProcesses();
    schedulerHelper.killNode(tNode.getNode().getNodeInformation().getURL());
    TestProcessTreeKiller.waitUntilAllForkedProcessesAreKilled();
}
Also used : TestNode(functionaltests.utils.TestNode) Test(org.junit.Test)

Example 9 with TestNode

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

the class TestAdminAddingNodes method testAddNodes.

@Test
public void testAddNodes() throws Exception {
    final String NS_NAME = "TestAdminAddingNodes";
    int pingFrequency = 6000;
    ResourceManager resourceManager = rmHelper.getResourceManager();
    resourceManager.createNodeSource(NS_NAME, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, NS_NAME);
    resourceManager.setNodeSourcePingFrequency(pingFrequency, NS_NAME);
    log("Test 1 : add a node");
    String node1Name = "node1";
    TestNode testNode1 = RMTHelper.createNode(node1Name);
    testNodes.add(testNode1);
    String node1URL = testNode1.getNodeURL();
    resourceManager.addNode(node1URL, NS_NAME);
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
    // wait for the node to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    log("Test 2 : remove an already deployed node");
    // preemptive removal is useless for this case, because node is free
    resourceManager.removeNode(node1URL, false);
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node1URL);
    assertEquals(0, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getTotalAliveNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    log("Test 3 : add a node, kill this node, node is detected down, and add a node that has the same URL");
    // Test seems to have a race condition at this step
    String node2Name = "node2";
    TestNode testNode2 = RMTHelper.createNode(node2Name);
    testNodes.add(testNode2);
    String node2URL = testNode2.getNodeURL();
    resourceManager.addNode(node2URL, NS_NAME);
    // wait the node added event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the node to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
    testNode2.kill();
    testNodes.remove(testNode2);
    RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(evt.getNodeState(), NodeState.DOWN);
    // wait the node down event
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    assertEquals(0, resourceManager.getState().getTotalAliveNodesNumber());
    // create another node with the same URL, and add it to Resource manager
    testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
    testNodes.add(testNode2);
    node2URL = testNode2.getNodeURL();
    resourceManager.addNode(node2URL, NS_NAME);
    // wait the node added event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the node to be in free state
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    assertEquals(1, resourceManager.getState().getTotalAliveNodesNumber());
    log("Test 4 : add a node, keep this node free, kill this node, and add a node that has the same URL");
    // put a large ping frequency in order to avoid down nodes detection
    resourceManager.setNodeSourcePingFrequency(Integer.MAX_VALUE, NS_NAME);
    // wait the end of last ping sequence
    Thread.sleep(pingFrequency * 2);
    // node2 is free, kill the node
    testNode2.kill();
    testNodes.remove(testNode2);
    // create another node with the same URL, and add it to Resource manager
    testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
    testNodes.add(testNode2);
    node2URL = testNode2.getNodeURL();
    resourceManager.addNode(node2URL, NS_NAME);
    NodeFactory.getNode(node2URL);
    // wait the node added event, node added is configuring
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the node to be in free state
    rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    log("Test 5 : add a node, put this node busy, kill this node, and add a node that has the same URL");
    // put the the node to busy state
    NodeSet nodes = resourceManager.getAtMostNodes(1, null);
    PAFuture.waitFor(nodes);
    // wait the node busy event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(evt.getNodeState(), NodeState.BUSY);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    // node2 is busy, kill the node
    testNode2.kill();
    testNodes.remove(testNode2);
    // create another node with the same URL, and add it to Resource manager
    testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
    testNodes.add(testNode2);
    node2URL = testNode2.getNodeURL();
    resourceManager.addNode(node2URL, NS_NAME);
    NodeFactory.getNode(node2URL);
    // wait the node added event, node added is configuring
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the node to be in free state
    rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    log("Test 6 : add a node, put this node toRelease, kill this node, and add a node that has the same URL");
    // put the the node to busy state
    nodes = resourceManager.getAtMostNodes(1, null);
    PAFuture.waitFor(nodes);
    // wait the node busy event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(evt.getNodeState(), NodeState.BUSY);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    // put the node in to Release state
    resourceManager.removeNode(node2URL, false);
    // wait the node to release event
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    testNode2.kill();
    testNodes.remove(testNode2);
    // create another node with the same URL, and add it to Resource manager
    testNode2 = RMTHelper.createNode(node2Name, new URI(node2URL).getPort());
    testNodes.add(testNode2);
    node2URL = testNode2.getNodeURL();
    resourceManager.addNode(node2URL, NS_NAME);
    NodeFactory.getNode(node2URL);
    // wait the node added event, node added is configuring
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
    // wait for the node to be in free state
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
    assertEquals(evt.getNodeState(), NodeState.FREE);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    log("Test 7");
    // add the same node twice and check that RM will not kill the node. If it does
    // second attempt will fail
    BooleanWrapper result = resourceManager.addNode(node2URL, NS_NAME);
    assertFalse(result.getBooleanValue());
    try {
        rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL, 8000);
        fail("Should timeout");
    } catch (ProActiveTimeoutException expected) {
    // expected
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) DefaultInfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) TestNode(functionaltests.utils.TestNode) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) URI(java.net.URI) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 10 with TestNode

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

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