Search in sources :

Example 1 with SchedulerStatus

use of org.ow2.proactive.scheduler.common.SchedulerStatus in project scheduling by ow2-proactive.

the class SchedulerStateListener method getSchedulerStatus.

public SchedulerStatus getSchedulerStatus(Scheduler scheduler) throws PermissionException, NotConnectedException {
    SchedulerStatus status = state.getStatus();
    if (status == null) {
        status = scheduler.getStatus();
        state.setStatus(status);
    }
    return status;
}
Also used : SchedulerStatus(org.ow2.proactive.scheduler.common.SchedulerStatus)

Example 2 with SchedulerStatus

use of org.ow2.proactive.scheduler.common.SchedulerStatus in project scheduling by ow2-proactive.

the class SchedulerFactory method startLocal.

/**
 * Creates and starts a Scheduler on the local host using the given initializer to configure it.
 * Only one Scheduler can be started by JVM.
 *
 * @param rmURL the URL of a started Resource Manager
 * @param initializer Use to configure the Scheduler before starting it.
 * 		This parameter cannot be null.
 *
 * @return a Scheduler authentication that allow you to administer it or get its connection URL.
 *
 * @throws InternalSchedulerException If Scheduler cannot be created
 */
public static synchronized SchedulerAuthenticationInterface startLocal(URI rmURL, SchedulerInitializer initializer, SchedulerStatus initialStatus) throws InternalSchedulerException {
    if (!schedulerStarted) {
        if (!allowNullInit) {
            if (initializer != null) {
                // configure application
                configure(initializer);
            } else {
                throw new IllegalArgumentException("Initializer cannot be null!");
            }
        }
        if (rmURL == null) {
            throw new IllegalArgumentException("RM url is null!");
        }
        try {
            String policy = initializer.getPolicyFullClassName();
            // start scheduler
            createScheduler(rmURL, policy, initialStatus);
            SchedulerAuthenticationInterface sai = SchedulerConnection.waitAndJoin(null);
            schedulerStarted = true;
            return sai;
        } catch (Exception e) {
            throw new InternalSchedulerException(e);
        }
    } else {
        throw new InternalSchedulerException("Scheduler already localy running");
    }
}
Also used : InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) AdminSchedulerException(org.ow2.proactive.scheduler.exception.AdminSchedulerException) InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 3 with SchedulerStatus

use of org.ow2.proactive.scheduler.common.SchedulerStatus 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 4 with SchedulerStatus

use of org.ow2.proactive.scheduler.common.SchedulerStatus in project scheduling by ow2-proactive.

the class SchedulerStateRecoverHelper method recover.

public RecoveredSchedulerState recover(long loadJobPeriod, RMProxy rmProxy, SchedulerStatus schedulerStatus) {
    dbManager.setTaskDataOwnerIfNull();
    List<InternalJob> notFinishedJobs = dbManager.loadNotFinishedJobs(true);
    Vector<InternalJob> pendingJobs = new Vector<>();
    Vector<InternalJob> runningJobs = new Vector<>();
    ExecutorService recoverRunningTasksThreadPool = PAExecutors.newCachedBoundedThreadPool(1, PASchedulerProperties.SCHEDULER_PARALLEL_SCHEDULER_STATE_RECOVER_NBTHREAD.getValueAsInt(), 60L, TimeUnit.SECONDS, new NamedThreadFactory("TaskRecoverThreadPool"));
    for (InternalJob job : notFinishedJobs) {
        recoverJob(rmProxy, pendingJobs, runningJobs, job, recoverRunningTasksThreadPool);
    }
    recoverRunningTasksThreadPool.shutdown();
    boolean terminatedWithoutTimeout;
    try {
        terminatedWithoutTimeout = recoverRunningTasksThreadPool.awaitTermination(PASchedulerProperties.SCHEDULER_PARALLEL_SCHEDULER_STATE_RECOVER_TIMEOUT.getValueAsInt(), TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        logger.error("Interrupted while waiting for the Scheduler state to be recovered", e);
        Thread.currentThread().interrupt();
        throw new SchedulerStateNotRecoveredException(e);
    }
    failIfSchedulerStateRecoveryTimeout(terminatedWithoutTimeout);
    applyJobUpdates(notFinishedJobs);
    Vector<InternalJob> finishedJobs = new Vector<>();
    for (Iterator<InternalJob> iterator = runningJobs.iterator(); iterator.hasNext(); ) {
        InternalJob job = iterator.next();
        try {
            List<InternalTask> tasksList = copyAndSort(job.getITasks());
            // simulate the running execution to recreate the tree.
            for (InternalTask task : tasksList) {
                job.recoverTask(task.getId());
            }
            if (job.getStatus() == JobStatus.PAUSED) {
                job.setStatus(JobStatus.STALLED);
                job.setPaused();
                // update the count of pending and running task.
                job.setNumberOfPendingTasks(job.getNumberOfPendingTasks() + job.getNumberOfRunningTasks());
                job.setNumberOfRunningTasks(0);
            }
        } catch (Throwable e) {
            logger.error("Failed to recover job " + job.getId() + " " + job.getName() + " job might be in a inconsistent state", e);
            jobLogger.error(job.getId(), "Failed to recover job, job might be in an inconsistent state", e);
            // partially cancel job (not tasks) and move it to finished jobs to avoid running it
            iterator.remove();
            job.setStatus(JobStatus.CANCELED);
            finishedJobs.add(job);
            dbManager.updateJobAndTasksState(job);
        }
    }
    finishedJobs.addAll(dbManager.loadFinishedJobs(false, loadJobPeriod));
    logger.info("[Recovering counters] " + " Pending: " + pendingJobs.size() + " Running: " + runningJobs.size() + " Finished: " + finishedJobs.size());
    return new RecoveredSchedulerState(pendingJobs, runningJobs, finishedJobs, schedulerStatus);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) NamedThreadFactory(org.objectweb.proactive.utils.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) Vector(java.util.Vector)

Example 5 with SchedulerStatus

use of org.ow2.proactive.scheduler.common.SchedulerStatus in project scheduling by ow2-proactive.

the class SchedulerClient method getStatus.

@Override
public SchedulerStatus getStatus() throws NotConnectedException, PermissionException {
    SchedulerStatus status = null;
    try {
        SchedulerStatusData schedulerStatus = restApi().getSchedulerStatus(sid);
        status = SchedulerStatus.valueOf(schedulerStatus.name());
    } catch (Exception e) {
        throwNCEOrPE(e);
    }
    return status;
}
Also used : SchedulerStatus(org.ow2.proactive.scheduler.common.SchedulerStatus) KeyStoreException(java.security.KeyStoreException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) 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) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) SignalApiException(org.ow2.proactive.scheduler.signal.SignalApiException)

Aggregations

SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)3 SchedulerException (org.ow2.proactive.scheduler.common.exception.SchedulerException)3 LoginException (javax.security.auth.login.LoginException)2 Test (org.junit.Test)2 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)2 RMException (org.ow2.proactive.resourcemanager.exception.RMException)2 SchedulerStatus (org.ow2.proactive.scheduler.common.SchedulerStatus)2 InternalSchedulerException (org.ow2.proactive.scheduler.common.exception.InternalSchedulerException)2 JobId (org.ow2.proactive.scheduler.common.job.JobId)2 AdminSchedulerException (org.ow2.proactive.scheduler.exception.AdminSchedulerException)2 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 JMXConnector (javax.management.remote.JMXConnector)1