Search in sources :

Example 36 with NodeSet

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

the class TestLocalInfrastructureRestartDownNodesPolicy method testRestartDownNodesPolicy.

@Test
public void testRestartDownNodesPolicy() throws Exception {
    nodeSourceName = "Node_source_1";
    RMTHelper.log("Test 1 - restart down nodes policy");
    createNodeSourceWithNodes(nodeSourceName, new Object[] { "ALL", "ALL", "10000" });
    RMState stateTest1 = resourceManager.getState();
    assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
    assertEquals(defaultDescriptorNodesNb, stateTest1.getFreeNodesNumber());
    NodeSet ns = resourceManager.getNodes(new Criteria(defaultDescriptorNodesNb));
    for (Node n : ns) {
        rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    }
    String nodeUrl = ns.get(0).getNodeInformation().getURL();
    // Nodes will be redeployed only if we kill the whole runtime
    rmHelper.killRuntime(nodeUrl);
    RMNodeEvent ev = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeUrl);
    assertEquals(NodeState.DOWN, ev.getNodeState());
    // one node is down - the policy should detect it and redeploy
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
    assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalAliveNodesNumber());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node) Criteria(org.ow2.proactive.utils.Criteria) RMState(org.ow2.proactive.resourcemanager.common.RMState) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 37 with NodeSet

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

the class TestLocalInfrastructureStaticPolicy method action.

@Test
public void action() throws Exception {
    String source1 = "Node_source_1";
    ResourceManager resourceManager = rmHelper.getResourceManager();
    log("Test 1 - creation/removal of empty node source");
    log("creation");
    createEmptyNodeSource(source1);
    log("removal");
    resourceManager.removeNodeSource(source1, true);
    log("ask to remove NS");
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
    log("NS removed");
    String source2 = "Node_source_2";
    log("Test 2 - creation/removal of the node source with nodes");
    createNodeSourceWithNodes(source1);
    RMState s = resourceManager.getState();
    assertEquals(defaultDescriptorNodesNb, s.getTotalNodesNumber());
    assertEquals(defaultDescriptorNodesNb, s.getFreeNodesNumber());
    // releasing some nodes
    NodeSet ns = resourceManager.getAtMostNodes(defaultDescriptorNodesNb, null);
    for (Node n : ns) {
        // eat the freeToBusy event
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        resourceManager.removeNode(n.getNodeInformation().getURL(), true);
        rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL());
    }
    assertEquals(0, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    log("removal");
    resourceManager.removeNodeSource(source1, true);
    log("ask to remove NS");
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
    log("NS removed");
    log("Test 3 - several node sources");
    createNodeSourceWithNodes(source1);
    createNodeSourceWithNodes(source2);
    assertEquals(2 * defaultDescriptorNodesNb, resourceManager.getState().getTotalNodesNumber());
    assertEquals(2 * defaultDescriptorNodesNb, resourceManager.getState().getFreeNodesNumber());
    resourceManager.removeNodeSource(source1, true);
    // wait the n events of the n nodes removals of the node source
    for (int i = 0; i < defaultDescriptorNodesNb; i++) {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    }
    // wait for the event of the node source removal
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
    resourceManager.removeNodeSource(source2, true);
    for (int i = 0; i < defaultDescriptorNodesNb; i++) {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    }
    // wait for the event of the node source removal
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source2);
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMState(org.ow2.proactive.resourcemanager.common.RMState) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 38 with NodeSet

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

the class GetAllNodes method main.

public static void main(String[] args) {
    RMAuthentication auth;
    try {
        auth = RMConnection.join(RMTHelper.getLocalUrl());
        Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
        ResourceManager rm = auth.login(cred);
        NodeSet nodes = rm.getNodes(new Criteria(rm.getState().getFreeNodesNumber()));
        // use nodes to block until the future is available
        System.out.println("Got " + nodes.size());
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.exit(1);
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Criteria(org.ow2.proactive.utils.Criteria) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 39 with NodeSet

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

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

the class TestConcurrentUsers method testConcurrency.

@Test
public void testConcurrency() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    String nsName = "TestConcurrentUsers";
    String node1Name = "node1";
    testNode = rmHelper.createNode(node1Name);
    String node1URL = testNode.getNode().getNodeInformation().getURL();
    resourceManager.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    resourceManager.addNode(node1URL, nsName);
    // waiting for node adding event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
    // waiting for the node to be free
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
    assertTrue(resourceManager.getState().getFreeNodesNumber() == 1);
    log("Test 1 - releasing of the foreign node");
    // acquiring a node
    final NodeSet ns = resourceManager.getAtMostNodes(1, null);
    // waiting for node busy event
    RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(evt.getNodeState(), NodeState.BUSY);
    assertEquals(ns.size(), 1);
    assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
    assertTrue(resourceManager.getState().getFreeNodesNumber() == 0);
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin("user"), CredData.parseDomain("user"), "pwd"), TestConcurrentUsers.this.rmHelper.getRMAuth().getPublicKey());
                ResourceManager rm2 = TestConcurrentUsers.this.rmHelper.getRMAuth().login(cred);
                rm2.releaseNode(ns.get(0)).getBooleanValue();
                Assert.assertTrue("Should not be able to release foreign node", false);
            } catch (Exception e) {
                log(e.getMessage());
            }
        }
    };
    t.start();
    t.join();
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    resourceManager.releaseNodes(ns);
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
    assertEquals(evt.getNodeState(), NodeState.FREE);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    log("Test 2 - releasing node twice");
    resourceManager.releaseNodes(ns);
    // to make sure everything has been processed
    Thread.sleep(1000);
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    log("Test 3 - client crash detection");
    JVMProcessImpl nodeProcess = new JVMProcessImpl(new org.objectweb.proactive.core.process.AbstractExternalProcess.StandardOutputMessageLogger());
    nodeProcess.setJvmOptions(Collections.singletonList(PAResourceManagerProperties.RM_HOME.getCmdLine() + PAResourceManagerProperties.RM_HOME.getValueAsString()));
    nodeProcess.setClassname(GetAllNodes.class.getName());
    nodeProcess.startProcess();
    // node busy event
    for (int i = 0; i < 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(evt.getNodeState(), NodeState.BUSY);
    }
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    // client does not exist anymore
    log("Client does not exist anymore. Waiting for client crash detection.");
    // waiting for node free event
    for (int i = 0; i < 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    assertEquals(1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(1, resourceManager.getState().getFreeNodesNumber());
    log("Test 4 - disconnecting");
    NodeSet ns2 = resourceManager.getAtMostNodes(1, null);
    RMNodeEvent event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
    Assert.assertTrue(event.getNodeState() == NodeState.BUSY);
    PAFuture.waitFor(ns2);
    log("Number of found nodes " + ns2.size());
    assertEquals(1, ns2.size());
    t = new Thread() {

        public void run() {
            try {
                RMAuthentication auth = rmHelper.getRMAuth();
                Credentials cred = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), auth.getPublicKey());
                ResourceManager rm = auth.login(cred);
                rm.disconnect().getBooleanValue();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    t.start();
    t.join();
    try {
        event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
        fail("Unexpected event: " + event);
    } catch (ProActiveTimeoutException e) {
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) DefaultInfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) CredData(org.ow2.proactive.authentication.crypto.CredData) JVMProcessImpl(org.objectweb.proactive.core.process.JVMProcessImpl) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) Credentials(org.ow2.proactive.authentication.crypto.Credentials) 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