Search in sources :

Example 31 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 32 with RMNodeEvent

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

the class RMCoreTest method createRmNodeEvent.

private RMNodeEvent createRmNodeEvent(NodeState previousNodeState) {
    RMNodeDescriptor rmNodeDescriptor = new RMNodeDescriptor();
    rmNodeDescriptor.setState(NodeState.DOWN);
    return new RMNodeEvent(rmNodeDescriptor, RMEventType.NODE_STATE_CHANGED, previousNodeState, "initiator");
}
Also used : RMNodeDescriptor(org.ow2.proactive.resourcemanager.common.event.RMNodeDescriptor) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)

Example 33 with RMNodeEvent

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

the class RMFunctionalTest method cleanState.

/**
 * Remove all node sources and nodes in the RM
 *
 * @throws Exception
 */
private void cleanState() throws Exception {
    if (rmHelper.isRMStarted()) {
        logger.info("Cleaning RM State");
        // force reconnection
        rmHelper.disconnect();
        ResourceManager rm = rmHelper.getResourceManager();
        RMInitialState state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
        List<RMNodeEvent> allNodes = state.getNodeEvents();
        for (RMNodeSourceEvent sourceEvent : state.getNodeSourceEvents()) {
            String nodeSource = sourceEvent.getSourceName();
            rm.removeNodeSource(nodeSource, true);
            for (RMNodeEvent nodeEvent : allNodes) {
                if (nodeSource.equals(nodeEvent.getNodeSource())) {
                    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, nodeEvent.getNodeUrl());
                }
            }
            rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nodeSource);
        }
        state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
        Assert.assertEquals(0, state.getNodeSourceEvents().size());
        if (state.getNodeEvents().size() > 0) {
            for (RMNodeEvent remainingNode : state.getNodeEvents()) {
                rm.removeNode(remainingNode.getNodeUrl(), true);
                rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, remainingNode.getNodeUrl());
            }
        }
        state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
        Assert.assertEquals(0, state.getNodeEvents().size());
        logger.info("RM State cleaned");
    }
}
Also used : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) RMInitialState(org.ow2.proactive.resourcemanager.common.event.RMInitialState) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver)

Example 34 with RMNodeEvent

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

the class TestExecuteScriptsOnBusyNode method testExecuteScriptOnBusyNode.

@Test
public void testExecuteScriptOnBusyNode() throws Exception {
    FileLock fileLock = new FileLock();
    Path fileLockPath = fileLock.lock();
    log("Submit job");
    final JobId jobId = schedulerHelper.submitJob(createJobWithLock(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");
    log("Wait some time until task launcher is started");
    Thread.sleep(5000);
    List<ScriptResult<Object>> results = schedulerHelper.getResourceManager().executeScript("println \"Executing Script\";", "groovy", TargetType.NODE_URL.name(), Sets.newSet(testNode.getNodeURL()));
    Assert.assertEquals(1, results.size());
    ScriptResult result = results.get(0);
    if (result.errorOccured()) {
        result.getException().printStackTrace();
        Assert.fail("Script execution failed");
    }
    log("Let task finish");
    fileLock.unlock();
    log("Wait when job finish");
    schedulerHelper.waitForEventJobFinished(jobId, TIMEOUT);
    schedulerHelper.waitUntilState(testNode.getNodeURL(), NodeState.FREE, TIMEOUT);
    log("Check job result");
    checkJobResult(schedulerHelper.getSchedulerInterface(), jobId);
    checkActiveObjects();
}
Also used : Path(java.nio.file.Path) ScriptResult(org.ow2.proactive.scripting.ScriptResult) FileLock(org.ow2.proactive.scheduler.util.FileLock) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 35 with RMNodeEvent

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

the class RecoverSSHInfrastructureV2Test method restartRmAndCheckFinalState.

private void restartRmAndCheckFinalState(int expectedNbAliveNodes, int expectedNbDownNodes) throws Exception {
    // restart RM
    rmHelper = new RMTHelper();
    startRmWithConfig(RESTART_CONFIG);
    assertThat(PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean()).isFalse();
    assertThat(rmHelper.isRMStarted()).isTrue();
    // re-snapshot the RM state
    RMMonitorEventReceiver resourceManagerMonitor = (RMMonitorEventReceiver) resourceManager;
    List<RMNodeSourceEvent> nodeSourceEvent = resourceManagerMonitor.getInitialState().getNodeSourceEvents();
    // the node source has been recovered on restart: we should have one node source with the same name
    assertThat(nodeSourceEvent.size()).isEqualTo(1);
    assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
    // the nodes should have been recovered too, and should be alive or down
    Set<String> allNodes = resourceManagerMonitor.getState().getAllNodes();
    assertThat(allNodes.size()).isEqualTo(TestSSHInfrastructureV2.NB_NODES);
    Set<String> nodeSourceNames = new HashSet<>();
    nodeSourceNames.add(NODE_SOURCE_NAME);
    List<RMNodeEvent> nodeEvents = resourceManagerMonitor.getInitialState().getNodeEvents();
    long nbFreeNodes = nodeEvents.stream().filter(nodeEvent -> nodeEvent.getNodeState().equals(NodeState.FREE)).count();
    assertThat(nbFreeNodes).isEqualTo(expectedNbAliveNodes);
    long nbDownNodes = nodeEvents.stream().filter(nodeEvent -> nodeEvent.getNodeState().equals(NodeState.DOWN)).count();
    assertThat(nbDownNodes).isEqualTo(expectedNbDownNodes);
    // the recovered nodes should be usable, try to lock/unlock them to see
    BooleanWrapper lockSucceeded = resourceManager.lockNodes(allNodes);
    assertThat(lockSucceeded).isEqualTo(new BooleanWrapper(true));
    BooleanWrapper unlockSucceeded = resourceManager.unlockNodes(allNodes);
    assertThat(unlockSucceeded).isEqualTo(new BooleanWrapper(true));
}
Also used : RestartDownNodesPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.RestartDownNodesPolicy) TestSSHInfrastructureV2(functionaltests.nodesource.TestSSHInfrastructureV2) SSHInfrastructureV2(org.ow2.proactive.resourcemanager.nodesource.infrastructure.SSHInfrastructureV2) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) Set(java.util.Set) Test(org.junit.Test) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) Truth.assertThat(com.google.common.truth.Truth.assertThat) NodeState(org.ow2.proactive.resourcemanager.common.NodeState) File(java.io.File) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) List(java.util.List) NODES_RECOVERABLE(functionaltests.nodesrecovery.RecoverInfrastructureTestHelper.NODES_RECOVERABLE) RMTHelper(functionaltests.utils.RMTHelper) After(org.junit.After) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) Before(org.junit.Before) RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMTHelper(functionaltests.utils.RMTHelper) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet)

Aggregations

RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)39 Test (org.junit.Test)24 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)19 NodeSet (org.ow2.proactive.utils.NodeSet)16 File (java.io.File)15 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)15 TestNode (functionaltests.utils.TestNode)8 HashMap (java.util.HashMap)8 NodeState (org.ow2.proactive.resourcemanager.common.NodeState)8 Node (org.objectweb.proactive.core.node.Node)7 SelectionScript (org.ow2.proactive.scripting.SelectionScript)7 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)6 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)6 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)6 Criteria (org.ow2.proactive.utils.Criteria)6 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)5 RMTHelper (functionaltests.utils.RMTHelper)5 HashSet (java.util.HashSet)5 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)5 ArrayList (java.util.ArrayList)4