Search in sources :

Example 1 with JVMProcessImpl

use of org.objectweb.proactive.core.process.JVMProcessImpl in project scheduling by ow2-proactive.

the class SchedulerTHelper method createRMNodeStarterNodes.

public List<TestNode> createRMNodeStarterNodes(String nodeName, int number) throws Exception {
    int pnpPort = RMTHelper.findFreePort();
    List<String> nodeUrls = new ArrayList<>(number);
    List<String> nodeNames = RMNodeStarter.getWorkersNodeNames(nodeName, number);
    for (int i = 0; i < number; i++) {
        nodeUrls.add("pnp://localhost:" + pnpPort + "/" + nodeNames.get(i));
    }
    String nodeUrl = "pnp://localhost:" + pnpPort + "/" + nodeName;
    Map<String, String> vmParameters = new HashMap<>();
    vmParameters.put(PNPConfig.PA_PNP_PORT.getName(), Integer.toString(pnpPort));
    JVMProcessImpl nodeProcess = RMTHelper.createJvmProcess(RMNodeStarter.class.getName(), Arrays.asList("-n", nodeName, "-r", getLocalUrl(), "-w", "" + number, "-Dproactive.net.nolocal=false"), vmParameters, null);
    ArrayList<TestNode> nodes = new ArrayList<>(number);
    // lookup all subsequent nodes remotely
    for (int i = 0; i < number; i++) {
        TestNode node0 = RMTHelper.createNode(nodeNames.get(i), nodeUrls.get(i), nodeProcess);
        nodes.add(node0);
    }
    return nodes;
}
Also used : RMNodeStarter(org.ow2.proactive.resourcemanager.utils.RMNodeStarter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JVMProcessImpl(org.objectweb.proactive.core.process.JVMProcessImpl)

Example 2 with JVMProcessImpl

use of org.objectweb.proactive.core.process.JVMProcessImpl in project scheduling by ow2-proactive.

the class SchedulerTHelper method createRMNodeStarterNode.

public TestNode createRMNodeStarterNode(String nodeName) throws Exception {
    int pnpPort = RMTHelper.findFreePort();
    String nodeUrl = "pnp://localhost:" + pnpPort + "/" + nodeName;
    Map<String, String> vmParameters = new HashMap<>();
    vmParameters.put(PNPConfig.PA_PNP_PORT.getName(), Integer.toString(pnpPort));
    JVMProcessImpl nodeProcess = RMTHelper.createJvmProcess(RMNodeStarter.class.getName(), Arrays.asList("-n", nodeName, "-r", getLocalUrl(), "-Dproactive.net.nolocal=false"), vmParameters, null);
    return RMTHelper.createNode(nodeName, nodeUrl, nodeProcess);
}
Also used : RMNodeStarter(org.ow2.proactive.resourcemanager.utils.RMNodeStarter) HashMap(java.util.HashMap) JVMProcessImpl(org.objectweb.proactive.core.process.JVMProcessImpl)

Example 3 with JVMProcessImpl

use of org.objectweb.proactive.core.process.JVMProcessImpl in project scheduling by ow2-proactive.

the class RMTHelper method createNode.

/**
 * Create a ProActive Node in a new JVM on the local host
 * with specific java parameters.
 * This method can be used to test adding nodes mechanism
 * with already deploy ProActive nodes.
 * @param nodeName node's name to create
 * @param vmParameters an HashMap containing key and value String
 * of type :-Dkey=value
 * @return created node URL
 * @throws IOException if the external JVM cannot be created
 * @throws NodeException if lookup of the new node fails.
 */
private static TestNode createNode(String nodeName, Map<String, String> vmParameters, List<String> vmOptions, int pnpPort) throws IOException, NodeException, InterruptedException {
    boolean exceptionOccurredWhileCreatingNode = false;
    NodeException lastException = null;
    int numberOfAttempts = 0;
    do {
        try {
            if (pnpPort <= 0) {
                pnpPort = findFreePort();
            }
            String nodeUrl = "pnp://localhost:" + pnpPort + "/" + nodeName;
            vmParameters.put(PNPConfig.PA_PNP_PORT.getName(), Integer.toString(pnpPort));
            JVMProcessImpl nodeProcess = createJvmProcess(StartNode.class.getName(), Collections.singletonList(nodeName), vmParameters, vmOptions);
            return createNode(nodeName, nodeUrl, nodeProcess);
        } catch (NodeException e) {
            exceptionOccurredWhileCreatingNode = true;
            lastException = e;
            numberOfAttempts++;
        }
    } while (exceptionOccurredWhileCreatingNode && numberOfAttempts < 20);
    throw lastException;
}
Also used : StartNode(org.objectweb.proactive.core.node.StartNode) JVMProcessImpl(org.objectweb.proactive.core.process.JVMProcessImpl) NodeException(org.objectweb.proactive.core.node.NodeException)

Example 4 with JVMProcessImpl

use of org.objectweb.proactive.core.process.JVMProcessImpl in project scheduling by ow2-proactive.

the class RMTHelper method createJvmProcess.

public static JVMProcessImpl createJvmProcess(String className, List<String> parameters, Map<String, String> vmParameters, List<String> vmOptions) throws IOException {
    JVMProcessImpl nodeProcess = new JVMProcessImpl(new org.objectweb.proactive.core.process.AbstractExternalProcess.StandardOutputMessageLogger());
    nodeProcess.setClassname(className);
    nodeProcess.setClasspath(testClasspath());
    ArrayList<String> jvmParameters = new ArrayList<>();
    if (vmParameters == null) {
        vmParameters = new HashMap<>();
    }
    vmParameters.put(CentralPAPropertyRepository.PA_COMMUNICATION_PROTOCOL.getName(), "pnp");
    if (!vmParameters.containsKey(CentralPAPropertyRepository.PA_HOME.getName())) {
        vmParameters.put(CentralPAPropertyRepository.PA_HOME.getName(), CentralPAPropertyRepository.PA_HOME.getValue());
    }
    if (!vmParameters.containsKey(PAResourceManagerProperties.RM_HOME.getKey())) {
        vmParameters.put(PAResourceManagerProperties.RM_HOME.getKey(), PAResourceManagerProperties.RM_HOME.getValueAsString());
    }
    if (!vmParameters.containsKey(CentralPAPropertyRepository.LOG4J.getName())) {
        try {
            File log4jFile = new File(CentralPAPropertyRepository.PA_HOME.getValue(), "config/log/node.properties");
            vmParameters.put(CentralPAPropertyRepository.LOG4J.getName(), log4jFile.toURI().toURL().toString());
        } catch (MalformedURLException ignore) {
        }
    }
    for (Entry<String, String> entry : vmParameters.entrySet()) {
        if (!entry.getKey().equals("") && !entry.getValue().equals("")) {
            jvmParameters.add("-D" + entry.getKey() + "=" + entry.getValue());
        }
    }
    if (vmOptions != null) {
        jvmParameters.addAll(vmOptions);
    }
    jvmParameters.addAll(setup.getJvmParametersAsList());
    jvmParameters.add("-Xmx256m");
    nodeProcess.setJvmOptions(jvmParameters);
    nodeProcess.setParameters(parameters);
    nodeProcess.startProcess();
    return nodeProcess;
}
Also used : MalformedURLException(java.net.MalformedURLException) JVMProcessImpl(org.objectweb.proactive.core.process.JVMProcessImpl) File(java.io.File)

Example 5 with JVMProcessImpl

use of org.objectweb.proactive.core.process.JVMProcessImpl 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

JVMProcessImpl (org.objectweb.proactive.core.process.JVMProcessImpl)6 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 NodeException (org.objectweb.proactive.core.node.NodeException)2 RMNodeStarter (org.ow2.proactive.resourcemanager.utils.RMNodeStarter)2 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 Test (org.junit.Test)1 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)1 StartNode (org.objectweb.proactive.core.node.StartNode)1 CredData (org.ow2.proactive.authentication.crypto.CredData)1 Credentials (org.ow2.proactive.authentication.crypto.Credentials)1 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)1 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)1 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)1 DefaultInfrastructureManager (org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager)1 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)1 NodeSet (org.ow2.proactive.utils.NodeSet)1