Search in sources :

Example 11 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class AbstractSmartProxy method syncAwaitedJob.

/**
 * This method will synchronize this proxy with a remote Scheduler for the
 * given job
 *
 * @param id job ID
 */
private void syncAwaitedJob(String id) {
    AwaitedJob awaitedJob = jobTracker.getAwaitedJob(id);
    try {
        JobState js = getJobState(id);
        for (TaskState ts : js.getTasks()) {
            String tname = ts.getName();
            AwaitedTask at = awaitedJob.getAwaitedTask(tname);
            if ((at != null) && (!at.isTransferring())) {
                TaskResult tres = null;
                try {
                    tres = getTaskResult(id, tname);
                    if (tres != null) {
                        log.debug("Synchonizing task " + tname + " of job " + id);
                        taskStateUpdatedEvent(new NotificationData<>(SchedulerEvent.TASK_RUNNING_TO_FINISHED, ts.getTaskInfo()));
                    }
                } catch (NotConnectedException e) {
                    e.printStackTrace();
                } catch (UnknownJobException e) {
                    log.error("Could not retrieve output data for job " + id + " because this job is not known by the Scheduler. \n ", e);
                } catch (UnknownTaskException e) {
                    log.error("Could not retrieve output data for task " + tname + " of job " + id + " because this task is not known by the Scheduler. \n ", e);
                } catch (Exception e) {
                    log.error("Unexpected error while getting the output data for task " + tname + " of job " + id, e);
                }
            }
        }
        if (js.isFinished()) {
            jobStateUpdatedEvent(new NotificationData<>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, js.getJobInfo()));
        }
    } catch (NotConnectedException e) {
        log.error("A connection error occured while trying to download output data of Job " + id + ". This job will remain in the list of awaited jobs. Another attempt to dowload the output data will be made next time the application is initialized. ", e);
    } catch (UnknownJobException e) {
        log.error("Could not retrieve output data for job " + id + " because this job is not known by the Scheduler. \n ", e);
        log.warn("Job  " + id + " will be removed from the known job list. The system will not attempt again to retrieve data for this job. You could try to manually copy the data from the location  " + awaitedJob.getPullURL());
        jobTracker.removeAwaitedJob(id);
    } catch (PermissionException e) {
        log.error("Could not retrieve output data for job " + id + " because you don't have permmission to access this job. You need to use the same connection credentials you used for submitting the job.  \n Another attempt to dowload the output data for this job will be made next time the application is initialized. ", e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) LoginException(javax.security.auth.login.LoginException) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException)

Example 12 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class SchedulerJMXTest method action.

@Test
public void action() throws Exception {
    final String userLogin = TestUsers.DEMO.username;
    final String userPassword = TestUsers.DEMO.password;
    final String adminLogin = TestUsers.TEST.username;
    final String adminPassword = TestUsers.TEST.password;
    final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    final PublicKey pubKey = auth.getPublicKey();
    // final Credentials userCreds =
    // Credentials.createCredentials(userLogin, userPassword, pubKey);
    final Credentials adminCreds = Credentials.createCredentials(new CredData(adminLogin, adminPassword), pubKey);
    final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
    final JMXServiceURL jmxRoServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RO));
    final ObjectName allAccountsMBeanName = new ObjectName(SchedulerJMXHelper.ALLACCOUNTS_MBEAN_NAME);
    final ObjectName myAccountMBeanName = new ObjectName(SchedulerJMXHelper.MYACCOUNT_MBEAN_NAME);
    final ObjectName runtimeDataMBeanName = new ObjectName(SchedulerJMXHelper.RUNTIMEDATA_MBEAN_NAME);
    final ObjectName managementMBeanName = new ObjectName(SchedulerJMXHelper.MANAGEMENT_MBEAN_NAME);
    final String suffix = "/" + PASchedulerProperties.SCHEDULER_JMX_CONNECTOR_NAME.getValueAsString();
    {
        RMTHelper.log("Test jmxRmiServiceURL is well formed");
        assertTrue("The jmxRmiServiceURL protocol must be rmi", jmxRmiServiceURL.getProtocol().equals("rmi"));
        assertTrue("The jmxRmiServiceURL URLPath must end with " + suffix, jmxRmiServiceURL.getURLPath().endsWith(suffix));
    }
    {
        RMTHelper.log("Test jmxRoServiceURL is well formed");
        assertTrue("The jmxRoServiceURL protocol must be ro", jmxRoServiceURL.getProtocol().equals("ro"));
        assertTrue("The jmxRoServiceURL URLPath must end with " + suffix, jmxRoServiceURL.getURLPath().endsWith(suffix));
    }
    {
        log("Test jmxRmiServiceURL and jmxRoServiceURL are not equal");
        Assert.assertFalse("The jmxRmiServiceURL and jmxRoServiceURL must not be equal", jmxRmiServiceURL.equals(jmxRoServiceURL));
    }
    {
        log("Test invalid JMX auth without creds (expect SecurityException)");
        try {
            JMXConnectorFactory.connect(jmxRmiServiceURL, new HashMap<String, Object>(0));
        } catch (Exception e) {
            assertTrue("JMX auth must throw SecurityException if a client tries to connect without creds in the " + "env", e instanceof SecurityException);
        }
    }
    {
        log("Test invalid JMX auth with null login/password creds (expect SecurityException)");
        // Create the environment
        final HashMap<String, Object> env = new HashMap<String, Object>(1);
        env.put(JMXConnector.CREDENTIALS, new Object[] { null, null });
        try {
            JMXConnectorFactory.connect(jmxRmiServiceURL, env);
        } catch (Exception e) {
            assertTrue("JMX auth must throw SecurityException if a client tries to connect with null credentials" + " the env", e instanceof SecurityException);
        }
    }
    {
        log("Test invalid JMX auth with bad login/password creds");
        // Create the environment
        final HashMap<String, Object> env = new HashMap<>(1);
        env.put(JMXConnector.CREDENTIALS, new Object[] { "abra", "cadabra" });
        try {
            JMXConnectorFactory.connect(jmxRmiServiceURL, env);
        } catch (Exception e) {
            assertTrue("JMX auth must throw SecurityException if a client tries to connect with bad " + "login/password credentials the env", e instanceof SecurityException);
        }
    }
    // Tests as user over RMI
    {
        log("Test as user 1 - Auth with login/pass over RMI and check connection");
        // Create the environment
        final HashMap<String, Object> env = new HashMap<>(1);
        env.put(JMXConnector.CREDENTIALS, new Object[] { userLogin, userPassword });
        // Connect to the JMX RMI Connector Server
        final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
        final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
        // Check that the MBean Server connection is not null
        assertNotNull("Unable to obtain the MBean server connection over RMI", conn);
        log("Test as user 2 - Check all mbeans are registered in the server");
        assertTrue("AllAccountsMBean is not registered", conn.isRegistered(allAccountsMBeanName));
        assertTrue("MyAccountMBean is not registered", conn.isRegistered(myAccountMBeanName));
        assertTrue("RuntimeDataMBean is not registered", conn.isRegistered(runtimeDataMBeanName));
        assertTrue("ManagementMBean is not registered", conn.isRegistered(managementMBeanName));
        log("Test as user 3 - Check MyAccountMBean attributes do not throw exceptions");
        final MBeanInfo info = conn.getMBeanInfo(myAccountMBeanName);
        for (final MBeanAttributeInfo att : info.getAttributes()) {
            final String attName = att.getName();
            try {
                conn.getAttribute(myAccountMBeanName, attName);
            } catch (Exception e) {
                fail("The attribute " + attName + " of MyAccountMBean must not throw " + e);
            }
        }
        log("Test as user 4 - Check RuntimeDataMBeanName attributes are correct");
        final String[] attributesToCheck = new String[] { "Status", "TotalJobsCount", "FinishedJobsCount", "TotalTasksCount", "FinishedTasksCount" };
        // Get all attributes to test BEFORE JOB SUBMISSION
        AttributeList list = conn.getAttributes(runtimeDataMBeanName, attributesToCheck);
        // Status
        Attribute att = (Attribute) list.get(0);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", "Started", att.getValue());
        // TotalJobsCount
        att = (Attribute) list.get(1);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", 0, att.getValue());
        // FinishedJobsCount
        att = (Attribute) list.get(2);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", 0, att.getValue());
        // NumberOfTasksCount
        att = (Attribute) list.get(3);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", 0, att.getValue());
        // FinishedTasksCount
        att = (Attribute) list.get(4);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", 0, att.getValue());
        // Create a job then submit it to the scheduler
        final int taskPerJob = 2;
        final TaskFlowJob job = new TaskFlowJob();
        for (int i = 0; i < taskPerJob; i++) {
            JavaTask task = new JavaTask();
            task.setName("" + i);
            task.setExecutableClassName(WaitAndPrint.class.getName());
            task.addArgument("sleepTime", "1");
            job.addTask(task);
        }
        // log as admin since its creds are already available
        final JobId id = schedulerHelper.submitJob(job);
        schedulerHelper.waitForEventJobFinished(id);
        // Get all attributes to test AFTER JOB EXECUTION
        list = conn.getAttributes(runtimeDataMBeanName, attributesToCheck);
        // Check SchedulerStatus
        att = (Attribute) list.get(0);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", "Started", att.getValue());
        // Check TotalNumberOfJobs
        att = (Attribute) list.get(1);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", 1, att.getValue());
        // Check NumberOfFinishedJobs
        att = (Attribute) list.get(2);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", 1, att.getValue());
        // Check TotalNumberOfTasks
        att = (Attribute) list.get(3);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", taskPerJob, att.getValue());
        // Check NumberOfFinishedTasks
        att = (Attribute) list.get(4);
        Assert.assertEquals("Incorrect value of " + att.getName() + " attribute", taskPerJob, att.getValue());
        jmxConnector.close();
    }
    // Test as admin over RO
    {
        log("Test as admin 1, auth with login/creds over RO and check connection");
        // Create the environment
        final HashMap<String, Object> env = new HashMap<>(1);
        env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
        env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, JMXProviderUtils.RO_PROVIDER_PKGS);
        // Connect to the JMX RO Connector Server
        final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRoServiceURL, env);
        final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
        // Check that the MBean Server connection is not null
        assertNotNull("Unable to obtain the MBean server connection over RO", conn);
        log("Test as admin 2 - Check ManagementMBean is registered in the MBean server");
        assertTrue("ManagementMBean is not registered", conn.isRegistered(managementMBeanName));
        RMTHelper.log("Test as admin 3 - Check ManagementMBean attributes do not throw exception");
        final MBeanInfo mInfo = conn.getMBeanInfo(managementMBeanName);
        for (final MBeanAttributeInfo att : mInfo.getAttributes()) {
            final String attName = att.getName();
            try {
                conn.getAttribute(managementMBeanName, attName);
            } catch (Exception e) {
                fail("The attribute " + attName + " of ManagementMBean must not throw " + e);
            }
        }
        RMTHelper.log("Test as admin 4 - Check AllAccountsMBean Username attribute");
        final String username = "Username";
        try {
            conn.setAttribute(allAccountsMBeanName, new Attribute(username, adminLogin));
        } catch (Exception e) {
            fail("Setting Username attribute of the AllAccountsMBean must not throw " + e);
        }
        String res = "";
        try {
            res = (String) conn.getAttribute(allAccountsMBeanName, username);
        } catch (Exception e) {
            fail("The attribute " + username + " of AllAccountsMBean must not throw " + e);
        }
        assertTrue("The attribute " + username + " of returns incorrect value", res.equals(adminLogin));
        jmxConnector.close();
    }
    // Test simultaneous RMI and RO connections
    {
        log("Test simultaneous JMX-RMI and JMX-RO connections as admin");
        final HashMap<String, Object> env = new HashMap<>(1);
        env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
        // Connect to the JMX-RMI Connector Server
        final JMXConnector jmxRmiConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
        final MBeanServerConnection conRmi = jmxRmiConnector.getMBeanServerConnection();
        // Connect to the JMX-RO Connector Server
        env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, JMXProviderUtils.RO_PROVIDER_PKGS);
        final JMXConnector jmxRoConnector1 = JMXConnectorFactory.connect(jmxRoServiceURL, env);
        final MBeanServerConnection conRo = jmxRoConnector1.getMBeanServerConnection();
        Assert.assertFalse("In case of simultaneous RMI and RO JMX connections they must not be equal", conRmi.equals(conRo));
        Assert.assertFalse("In case of simultaneous RMI and RO JMX connections the connectors must not provide the same connection ids", jmxRmiConnector.getConnectionId().equals(jmxRoConnector1.getConnectionId()));
        log("Test JMX-RO connection unicity (two connections over RO must not have the same id)");
        final JMXConnector jmxRoConnector2 = JMXConnectorFactory.connect(jmxRoServiceURL, env);
        Assert.assertFalse("In case of multiple RO JMX connections the connectors must not provide the same connection ids", jmxRoConnector1.getConnectionId().equals(jmxRoConnector2.getConnectionId()));
        // Close all connectors
        jmxRoConnector2.close();
        jmxRoConnector1.close();
        jmxRmiConnector.close();
    }
    // Test Helper class
    {
        log("Test JMXClientHelper as admin over RMI with connect() method");
        final JMXClientHelper client = new JMXClientHelper(auth, new Object[] { adminLogin, adminCreds });
        // default is over
        final boolean isConnected1 = client.connect();
        // RMI
        assertTrue("Unable to connect, exception is " + client.getLastException(), isConnected1);
        assertTrue("Incorrect default behavior of connect() method it must use RMI protocol", client.getConnector().getConnectionId().startsWith("rmi"));
        client.disconnect();
        Assert.assertFalse("The helper disconnect() must set the helper as disconnected", client.isConnected());
        final boolean isConnected2 = client.connect(JMXTransportProtocol.RO);
        assertTrue("Unable to connect, exception is " + client.getLastException(), isConnected2);
        assertTrue("The helper connect(JMXTransportProtocol.RO) method must use RO protocol", client.getConnector().getConnectionId().startsWith("ro"));
        client.disconnect();
        Assert.assertFalse("The helper disconnect() must set the helper as disconnected", client.isConnected());
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) JMXConnector(javax.management.remote.JMXConnector) JMXClientHelper(org.ow2.proactive.jmx.JMXClientHelper) Credentials(org.ow2.proactive.authentication.crypto.Credentials) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 13 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class RMProxyUserInterfaceTest method testGetNodeMBeanInfo_DisconnectionOfRemovedNodeSource.

// SCHEDULING-1850
@Test
public void testGetNodeMBeanInfo_DisconnectionOfRemovedNodeSource() throws Exception {
    proxyUserInterface = createRMCachingProxyUserInterface();
    rmHelper.createNodeSource("NodeSource1", 1);
    RMInitialState state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
    String nodeSource1_NodeJmxUrl = state.getNodeEvents().get(0).getDefaultJMXUrl();
    Object mBeanFromNodeSource1 = proxyUserInterface.getNodeMBeanInfo(nodeSource1_NodeJmxUrl, EXISTING_OBJECT_NAME, Collections.<String>emptyList());
    assertNotNull(mBeanFromNodeSource1);
    // remove nodesource and try another jmx connection
    rmHelper.getResourceManager().removeNodeSource("NodeSource1", true);
    rmHelper.createNodeSource("NodeSource2", 1);
    state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
    String nodeSource2_NodeJmxUrl = state.getNodeEvents().get(0).getDefaultJMXUrl();
    Object mBeanFromNodeSource2 = proxyUserInterface.getNodeMBeanInfo(nodeSource2_NodeJmxUrl, EXISTING_OBJECT_NAME, Collections.<String>emptyList());
    assertNotNull(mBeanFromNodeSource2);
    // cleanup
    rmHelper.getResourceManager().removeNodeSource("NodeSource2", true);
}
Also used : RMInitialState(org.ow2.proactive.resourcemanager.common.event.RMInitialState) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 14 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class TestNodesStates method testManyStatesChanges.

@Test
public void testManyStatesChanges() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    int totalNodeNumber = 5;
    rmHelper.createNodeSource("TestNodesStates", totalNodeNumber);
    // ----------------------------------------------------------
    // Book all nodes deployed by descriptor (user action)
    // verify that there are no free nodes left,
    // and give back to RM
    log("Test 1");
    NodeSet nodes = resourceManager.getAtMostNodes(totalNodeNumber, null);
    PAFuture.waitFor(nodes);
    assertEquals(totalNodeNumber, nodes.size());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    for (int i = 0; i < totalNodeNumber; i++) {
        RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodes.get(i).getNodeInformation().getURL());
        assertEquals(NodeState.BUSY, evt.getNodeState());
        checkEvent(evt, nodes.get(i));
    }
    // for next test
    Node n = nodes.get(0);
    resourceManager.releaseNodes(nodes);
    for (int i = 0; i < totalNodeNumber; i++) {
        RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodes.get(i).getNodeInformation().getURL());
        assertEquals(NodeState.FREE, evt.getNodeState());
        checkEvent(evt, nodes.get(i));
    }
    // ----------------------------------------------------------
    // give back a node already given back (i.e; node already free)
    // this action causes nothing(nor increasing free nodes number, nor generation of any event)
    log("Test 2");
    resourceManager.releaseNode(n);
    boolean timeouted = false;
    try {
        rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL(), 4000);
    } catch (ProActiveTimeoutException e) {
        timeouted = true;
    }
    assertTrue(timeouted);
    assertEquals(totalNodeNumber, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // Book all nodes deployed by descriptor
    // Test admin action : Remove a node from the RM (non preemptively),
    // node is busy, so becomes in "toRelease" state
    // user give back to RM the "toRelease" node, node is now removed
    log("Test 3");
    nodes = resourceManager.getAtMostNodes(totalNodeNumber, null);
    PAFuture.waitFor(nodes);
    for (int i = 0; i < totalNodeNumber; i++) {
        RMNodeEvent evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.BUSY, evt.getNodeState());
    }
    n = nodes.remove(0);
    // put node in "To Release" state
    resourceManager.removeNode(n.getNodeInformation().getURL(), false);
    // check that node toRelease event has been thrown
    RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.TO_BE_REMOVED, evt.getNodeState());
    // node is in "ToRelease" state, so always handled by RM
    assertEquals(totalNodeNumber, resourceManager.getState().getTotalNodesNumber());
    // user give back the node, so node is now removed
    resourceManager.releaseNode(n);
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL());
    // ----------------------------------------------------------
    // nodes are always in busy state
    // kill JVM of a node (simulate a fallen JVM or broken connection, i.e down node)
    // node must detected down by RM
    log("Test 4");
    n = nodes.get(0);
    // for next test
    Node n2 = nodes.get(1);
    try {
        n.getProActiveRuntime().killNode(n.getNodeInformation().getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.DOWN, evt.getNodeState());
    checkEvent(evt, n);
    resourceManager.releaseNodes(nodes);
    for (int i = 0; i < totalNodeNumber - 2; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    // two nodes killed, but the detected down is in RM down nodes list
    // ( down nodes are in total nodes count)
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 2, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // nodes left are in free state
    // kill JVM of a free node
    // node must detected down by RM
    log("Test 5");
    try {
        n2.getProActiveRuntime().killNode(n2.getNodeInformation().getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n2.getNodeInformation().getURL());
    assertEquals(NodeState.DOWN, evt.getNodeState());
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 3, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // book nodes, put one node in "toRelease" state,
    // then kill its JVM,
    // node must detected down by RM
    log("Test 6");
    nodes = resourceManager.getAtMostNodes(totalNodeNumber - 3, null);
    PAFuture.waitFor(nodes);
    for (int i = 0; i < totalNodeNumber - 3; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.BUSY, evt.getNodeState());
    }
    n = nodes.get(0);
    // for next test
    n2 = nodes.get(1);
    // put node in "To Release" state
    resourceManager.removeNode(n.getNodeInformation().getURL(), false);
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.TO_BE_REMOVED, evt.getNodeState());
    log("Test 6 Bis");
    // kill the node
    try {
        n.getProActiveRuntime().killNode(n.getNodeInformation().getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    assertEquals(NodeState.DOWN, evt.getNodeState());
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    for (Node node : nodes) {
        log("Taken node: " + node.getNodeInformation().getURL());
    }
    // we have 2 nodes: 11 busy and one still down
    resourceManager.releaseNodes(nodes);
    for (int i = 0; i < 1; i++) {
        evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        assertEquals(NodeState.FREE, evt.getNodeState());
    }
    assertEquals(totalNodeNumber - 1, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 4, resourceManager.getState().getFreeNodesNumber());
    // admin removes again the node, ok he already asked this removal when node n was busy
    // choice here is advert admin that node has fallen (not hiding the down node event),
    // rather than automatically remove it
    resourceManager.removeNode(n.getNodeInformation().getURL(), false);
    // check that node removed event has been received
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL());
    assertEquals(totalNodeNumber - 2, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 4, resourceManager.getState().getFreeNodesNumber());
    // ----------------------------------------------------------
    // Remove a free node,
    // 
    log("Test 7");
    resourceManager.removeNode(n2.getNodeInformation().getURL(), false);
    // check that node removed event has been received
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n2.getNodeInformation().getURL());
    assertEquals(totalNodeNumber - 3, resourceManager.getState().getTotalNodesNumber());
    assertEquals(totalNodeNumber - 5, resourceManager.getState().getFreeNodesNumber());
    log("End of test");
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) Node(org.objectweb.proactive.core.node.Node) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 15 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class SchedulerAuthenticationGUIHelper method login.

/**
 * This method will log a client to the scheduler by requesting his URL, username and password from a
 * graphical interface.
 *
 * @param schedulerURL The default URL of the scheduler to connect
 * @return The connection to the scheduler as a {@link Scheduler} if logging successful.
 * 			If the username is empty or if the user cancel the authentication, this method will return null.
 * @throws LoginException If a problem occurs while logging the user.
 * @throws SchedulerException If a problem occurs at scheduler level.
 */
public static Scheduler login(String schedulerURL) throws LoginException, SchedulerException {
    AuthResultContainer auth = connect(schedulerURL);
    if (auth == null) {
        return null;
    } else {
        SchedulerAuthenticationInterface schedAuth = auth.getAuth();
        Credentials cred = null;
        try {
            cred = Credentials.createCredentials(new CredData(CredData.parseLogin(auth.getUsername()), CredData.parseDomain(auth.getUsername()), auth.getPassword()), schedAuth.getPublicKey());
        } catch (LoginException e) {
            throw new LoginException("Could not retrieve public key from Scheduler " + schedulerURL + ", contact the administrator" + e);
        } catch (KeyException e) {
            throw new LoginException("Could not encrypt credentials " + e);
        }
        return schedAuth.login(cred);
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) KeyException(java.security.KeyException)

Aggregations

SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)9 KeyException (java.security.KeyException)6 LoginException (javax.security.auth.login.LoginException)6 Test (org.junit.Test)6 CredData (org.ow2.proactive.authentication.crypto.CredData)5 Credentials (org.ow2.proactive.authentication.crypto.Credentials)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)4 InternalSchedulerException (org.ow2.proactive.scheduler.common.exception.InternalSchedulerException)4 SchedulerException (org.ow2.proactive.scheduler.common.exception.SchedulerException)4 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)3 PublicKey (java.security.PublicKey)3 JMXConnector (javax.management.remote.JMXConnector)3 JMXServiceURL (javax.management.remote.JMXServiceURL)3 RMException (org.ow2.proactive.resourcemanager.exception.RMException)3 JobId (org.ow2.proactive.scheduler.common.job.JobId)3 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)2 File (java.io.File)2 MBeanServerConnection (javax.management.MBeanServerConnection)2