Search in sources :

Example 26 with Connection

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

the class AbstractCommand method execute.

protected HttpResponseWrapper execute(HttpUriRequest request, ApplicationContext currentContext) {
    String sessionId = currentContext.getSessionId();
    if (sessionId != null) {
        request.setHeader("sessionid", sessionId);
    }
    CommonHttpClientBuilder httpClientBuilder = new HttpClientBuilder().useSystemProperties();
    try {
        if ("https".equals(request.getURI().getScheme()) && currentContext.canInsecureAccess()) {
            httpClientBuilder.insecure(true);
        }
        HttpResponse response = httpClientBuilder.build().execute(request);
        return new HttpResponseWrapper(response);
    } catch (SSLPeerUnverifiedException sslException) {
        throw new CLIException(CLIException.REASON_OTHER, "SSL error. Perhaps HTTPS certificate could not be validated, " + "you can try with -k or insecure() for insecure SSL connection.", sslException);
    } catch (Exception e) {
        throw new CLIException(CLIException.REASON_OTHER, e.getMessage(), e);
    } finally {
        ((HttpRequestBase) request).releaseConnection();
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) HttpResponse(org.apache.http.HttpResponse) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) CommonHttpClientBuilder(org.ow2.proactive.http.CommonHttpClientBuilder) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) IOException(java.io.IOException) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) CommonHttpClientBuilder(org.ow2.proactive.http.CommonHttpClientBuilder)

Example 27 with Connection

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

the class TestGetUsage method testGetMyAccountUsage.

@Test
public void testGetMyAccountUsage() throws Exception {
    Date beforeJobExecution = new Date();
    // put some data in the database
    Scheduler firstUser = schedulerHelper.getSchedulerInterface();
    JobId jobId = firstUser.submit(createJob());
    schedulerHelper.waitForEventJobFinished(jobId, 30000);
    Date afterJobExecution = new Date();
    // We try to retrieve usage on the job I just ran
    List<JobUsage> adminUsages = firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
    assertFalse(adminUsages.isEmpty());
    // Do we properly check for user connection ?
    firstUser.disconnect();
    try {
        firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
        fail("Should throw a not connected exception because i just disconnected");
    } catch (NotConnectedException e) {
    // Ok that is expected
    }
    // another user
    SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
    Scheduler otherUser = auth.login(cred);
    // This user has not ran any job
    List<JobUsage> userUsages = otherUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
    assertTrue(userUsages.isEmpty());
    otherUser.disconnect();
}
Also used : NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage) Date(java.util.Date) JobId(org.ow2.proactive.scheduler.common.job.JobId) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 28 with Connection

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

the class SchedulingService method checkAndReconnectRM.

/**
 * Check the connection to the RM. If the connection is down and automatic reconnection is enabled, this method performs n reconnection attempts before returning the result.
 * These parameters can be set in the configuration :
 * - Enabling/Disabling automatic reconnection: pa.scheduler.core.rmconnection.autoconnect (default is true)
 * - Delay in ms between 2 consecutive attempts: pa.scheduler.core.rmconnection.timespan (default is 5000 ms)
 * - Maximum number of attempts: pa.scheduler.core.rmconnection.attempts (default is 10)
 *
 * @return true if the RM is alive, false otherwise.
 */
private boolean checkAndReconnectRM() {
    // Result of the method.
    boolean alive = false;
    // Checks if the option is enabled (false by default)
    boolean autoReconnectRM = PASchedulerProperties.SCHEDULER_RMCONNECTION_AUTO_CONNECT.isSet() ? PASchedulerProperties.SCHEDULER_RMCONNECTION_AUTO_CONNECT.getValueAsBoolean() : false;
    // Delay (in ms) between each connection attempts (5s by default)
    int timespan = PASchedulerProperties.SCHEDULER_RMCONNECTION_TIMESPAN.isSet() ? PASchedulerProperties.SCHEDULER_RMCONNECTION_TIMESPAN.getValueAsInt() : 5000;
    // Maximum number of attempts (10 by default)
    int maxAttempts = PASchedulerProperties.SCHEDULER_RMCONNECTION_ATTEMPTS.isSet() ? PASchedulerProperties.SCHEDULER_RMCONNECTION_ATTEMPTS.getValueAsInt() : 10;
    // If the options is disabled or the number of attempts is wrong, it is set to 1
    if (!autoReconnectRM || maxAttempts <= 0)
        maxAttempts = 1;
    // Check the timespan option
    if (timespan <= 0)
        timespan = 5000;
    // Save the url in a string of the last connected RM.
    String rmURL = this.lastRmUrl.toString();
    int nbAttempts = 1;
    logger.info("Automatically reconnecting to RM at url " + rmURL + "...");
    while (!alive && nbAttempts <= maxAttempts) {
        try {
            infrastructure.getRMProxiesManager().rebindRMProxiesManager(new URI(rmURL));
            logger.info("Successfully reconnected to Resource Manager at " + rmURL);
            alive = true;
        } catch (Exception rme) {
            alive = false;
            if (nbAttempts != maxAttempts) {
                try {
                    // Sleep before two attempts
                    logger.info("Waiting " + timespan + " ms before the next attempt...");
                    Thread.sleep(timespan);
                } catch (InterruptedException ex) {
                    logger.error("An exception has occurred while waiting.");
                }
            }
        }
        nbAttempts++;
    }
    if (!alive) {
        logger.info("Resource Manager seems to be dead.");
        // Disconnect proxies and freeze the scheduler.
        clearProxiesAndFreeze();
        logger.fatal("\n*****************************************************************************************************************\n" + "* Resource Manager is no more available, Scheduler has been paused waiting for a resource manager to be reconnect\n" + "* Scheduler is in critical state and its functionalities are reduced : \n" + "* \t-> use the linkrm(\"" + rmURL + "\") command in scheduler-client to reconnect a new one.\n" + "*****************************************************************************************************************");
        listener.schedulerStateUpdated(SchedulerEvent.RM_DOWN);
    }
    return alive;
}
Also used : URI(java.net.URI) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) ExecutionException(java.util.concurrent.ExecutionException)

Example 29 with Connection

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

the class TestRMReconnectionWhileRunning method testReconnectionIsNotHappen.

/**
 * This case checks that even if exception was trown in main Scheduler loop it will not cause reconnection to RM.
 * @throws Exception
 */
@Test
public void testReconnectionIsNotHappen() throws Exception {
    ProActiveConfiguration.load();
    RMFactory.setOsJavaProperty();
    schedulerHelper = new SchedulerTHelper(false, true);
    schedulerHelper.createNodeSource("local", 3);
    schedulerHelper.getSchedulerInterface().changePolicy("functionaltests.rm.PolicyWhichThrowsExceptions");
    JobId jobId = schedulerHelper.submitJob(new File(runningJob.toURI()).getAbsolutePath());
    JobId jobId2 = schedulerHelper.submitJob(new File(runningJob1.toURI()).getAbsolutePath());
    JobId jobId3 = schedulerHelper.submitJob(new File(runningJob2.toURI()).getAbsolutePath());
    schedulerHelper.waitForEventTaskRunning(jobId, "running_task_for20s");
    schedulerHelper.waitForEventJobFinished(jobId2);
    schedulerHelper.waitForEventJobFinished(jobId3);
    assertJobFinished(jobId2);
    assertJobFinished(jobId3);
    int numberOfAttemptsToReconnect = LogProcessor.linesThatMatch("Successfully reconnected to Resource Manager ").size();
    int attemptsThatDidNotCauseReconnection = LogProcessor.linesThatMatch("Do not reconnect to the RM as connection is active for ").size();
    int actualNumberOfReconnections = numberOfAttemptsToReconnect - attemptsThatDidNotCauseReconnection;
    assertEquals(0, actualNumberOfReconnections);
}
Also used : File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 30 with Connection

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

the class SchedulerRuntimeDataMBeanTest method testAsUser.

private void testAsUser() throws Exception {
    final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    final HashMap<String, Object> env = new HashMap<>(1);
    env.put(JMXConnector.CREDENTIALS, new Object[] { TestUsers.USER.username, TestUsers.USER.password });
    JMXConnector userJmxConnector = JMXConnectorFactory.connect(new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI)), env);
    try {
        MBeanServerConnection connection = userJmxConnector.getMBeanServerConnection();
        final ObjectName beanName = new ObjectName(SchedulerJMXHelper.RUNTIMEDATA_MBEAN_NAME);
        RuntimeDataMBean bean = JMX.newMXBeanProxy(connection, beanName, RuntimeDataMBean.class);
        checkDataConsistent(bean);
    } finally {
        userJmxConnector.close();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) RuntimeDataMBean(org.ow2.proactive.scheduler.core.jmx.mbean.RuntimeDataMBean) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

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