Search in sources :

Example 16 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class TimeSlotPolicy method activate.

/**
 * Activates the policy. Schedules acquire/release tasks with specified period.
 */
@Override
public BooleanWrapper activate() {
    try {
        if (period > 0) {
            info("Scheduling periodic nodes acquision");
            timer.scheduleAtFixedRate(new AcquireTask(), dateFormat.parse(acquireTime), period);
            timer.scheduleAtFixedRate(new ReleaseTask(), dateFormat.parse(releaseTime), period);
        } else {
            info("Scheduling non periodic nodes acquision");
            timer.schedule(new AcquireTask(), dateFormat.parse(acquireTime));
            timer.schedule(new ReleaseTask(), dateFormat.parse(releaseTime));
        }
    } catch (ParseException e) {
        return new BooleanWrapper(false);
    }
    return new BooleanWrapper(true);
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) ParseException(java.text.ParseException)

Example 17 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class TestRMMonitoring method action.

@Test
public void action() throws Exception {
    log("Deployment");
    RMMonitorEventReceiver resourceManager = (RMMonitorEventReceiver) rmHelper.getResourceManager();
    rmHelper.createNodeSource("TestRMMonitoring");
    Set<String> nodesUrls = rmHelper.listAliveNodesUrls();
    // we received all event as we are here
    log("Test 1 - subscribing only to 'node remove' event");
    resourceManager.removeRMEventListener();
    resourceManager.addRMEventListener(rmHelper.getEventReceiver(), RMEventType.NODE_REMOVED);
    String url = nodesUrls.iterator().next();
    BooleanWrapper status = resourceManager.removeNode(url, true);
    if (status.getBooleanValue()) {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED, 10000);
        log("Test 1 - success");
    }
    NodeSet ns = resourceManager.getAtMostNodes(5, null);
    log("Got " + ns.size() + " nodes");
    // must not receive "node busy" event
    try {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 2000);
        fail("Must not receive this type of event");
    } catch (ProActiveTimeoutException ex) {
        log("Test 2 - success");
    }
    resourceManager.releaseNodes(ns).getBooleanValue();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 18 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class NodesRecoveryPropertyTest method restartRmAndCheckFinalState.

private void restartRmAndCheckFinalState(String rmConfigPath, boolean nodesShouldBeRecreated) throws Exception {
    // restart RM
    rmHelper = new RMTHelper();
    startRmWithConfig(rmConfigPath);
    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
    if (PAResourceManagerProperties.RM_NODES_RECOVERY.getValueAsBoolean()) {
        assertThat(nodeSourceEvent.size()).isEqualTo(1);
    }
    assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
    // wait for nodes to be recreated if needed
    if (nodesShouldBeRecreated) {
        rmHelper.waitForAnyMultipleNodeEvent(RMEventType.NODE_STATE_CHANGED, NODE_NUMBER);
    }
    // the nodes should have been recovered too, and should be alive
    Set<String> allNodes = resourceManagerMonitor.getState().getAllNodes();
    assertThat(allNodes.size()).isEqualTo(NODE_NUMBER);
    Set<String> nodeSourceNames = new HashSet<>();
    nodeSourceNames.add(NODE_SOURCE_NAME);
    Set<String> aliveNodeUrls = resourceManager.listAliveNodeUrls(nodeSourceNames);
    assertThat(aliveNodeUrls.size()).isEqualTo(NODE_NUMBER);
    // 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 : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMTHelper(functionaltests.utils.RMTHelper) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet)

Example 19 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class RecoverSSHInfrastructureV2Test method restartRmAndCheckFinalState.

private void restartRmAndCheckFinalState(boolean nodesShouldBeRecreated) 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);
    // wait for nodes to be recreated if needed
    if (nodesShouldBeRecreated) {
        rmHelper.waitForAnyMultipleNodeEvent(RMEventType.NODE_STATE_CHANGED, TestSSHInfrastructureV2.NB_NODES);
    }
    // the nodes should have been recovered too, and should be alive
    Set<String> allNodes = resourceManagerMonitor.getState().getAllNodes();
    assertThat(allNodes.size()).isEqualTo(TestSSHInfrastructureV2.NB_NODES);
    Set<String> nodeSourceNames = new HashSet<>();
    nodeSourceNames.add(NODE_SOURCE_NAME);
    Set<String> aliveNodeUrls = resourceManager.listAliveNodeUrls(nodeSourceNames);
    assertThat(aliveNodeUrls.size()).isEqualTo(TestSSHInfrastructureV2.NB_NODES);
    // 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 : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMTHelper(functionaltests.utils.RMTHelper) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet)

Example 20 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper 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)

Aggregations

BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)36 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)10 Test (org.junit.Test)9 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)7 Matchers.anyString (org.mockito.Matchers.anyString)5 Node (org.objectweb.proactive.core.node.Node)5 HashSet (java.util.HashSet)4 Client (org.ow2.proactive.resourcemanager.authentication.Client)4 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)4 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)4 NodeSet (org.ow2.proactive.utils.NodeSet)4 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)3 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)3 RMProxyUserInterface (org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)3 RMTHelper (functionaltests.utils.RMTHelper)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 HttpResponse (org.apache.http.HttpResponse)2 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)2 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)2