Search in sources :

Example 6 with SchedulerState

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

the class RestSchedulerPushPullFileTest method setUp.

@Before
public void setUp() throws Exception {
    Scheduler scheduler = RestFuncTHelper.getScheduler();
    SchedulerState state = scheduler.getState();
    List<JobState> jobStates = new ArrayList<>();
    jobStates.addAll(state.getPendingJobs());
    jobStates.addAll(state.getRunningJobs());
    jobStates.addAll(state.getFinishedJobs());
    for (JobState jobState : jobStates) {
        JobId jobId = jobState.getId();
        scheduler.killJob(jobId);
        scheduler.removeJob(jobId);
    }
}
Also used : SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) JobId(org.ow2.proactive.scheduler.common.job.JobId) Before(org.junit.Before)

Example 7 with SchedulerState

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

the class RestSchedulerTagTest method submitWorkflowWhichIsUSedByAllTestCasesOnce.

@Before
public void submitWorkflowWhichIsUSedByAllTestCasesOnce() throws Exception {
    if (submittedJobId == null) {
        System.out.println("Setup - no jobId found: Remove all jobs from scheduler");
        scheduler = RestFuncTHelper.getScheduler();
        SchedulerState state = scheduler.getState();
        List<JobState> jobStates = new ArrayList<>();
        jobStates.addAll(state.getPendingJobs());
        jobStates.addAll(state.getRunningJobs());
        jobStates.addAll(state.getFinishedJobs());
        for (JobState jobState : jobStates) {
            JobId jobId = jobState.getId();
            scheduler.killJob(jobId);
            scheduler.removeJob(jobId);
        }
        System.out.println("Scheduler was cleaned.");
        System.out.println("Submit job for test cases.");
        // submit a job with a loop and out and err outputs
        System.out.println("submit a job with loop, out and err outputs");
        submittedJobId = submitJob("flow_loop_out.xml");
    }
    System.out.println("Finished setup test case.");
}
Also used : SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) JobId(org.ow2.proactive.scheduler.common.job.JobId) Before(org.junit.Before)

Example 8 with SchedulerState

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

the class AbstractSchedulerUser method registerListener.

public void registerListener(boolean getInitialState, boolean myEventsOnly, String listenerClazzName) throws SchedulerException, ProActiveException {
    try {
        if (this.scheduler == null)
            throw new IllegalStateException("The user is not connected to the Scheduler yet. " + "Consider calling the connectToScheduler() method first");
        SchedulerEventListener schedulerListener = createEventListener(listenerClazzName);
        logger.trace("Trying to expose the listener as a remote object");
        slExposer = new SchedulerListenerExposer(schedulerListener);
        SchedulerEventListener schedulerListenerRemoteRef = slExposer.createRemoteReference();
        logger.trace("Trying to register the listener to the Scheduler");
        // for the moment, listens only to the Jobs-related events
        SchedulerState initialState = scheduler.addEventListener(schedulerListenerRemoteRef, myEventsOnly, getInitialState, // job-related events
        SchedulerEvent.JOB_SUBMITTED, SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_PENDING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_PAUSED, SchedulerEvent.JOB_RESUMED, SchedulerEvent.JOB_RESTARTED_FROM_ERROR, SchedulerEvent.JOB_CHANGE_PRIORITY, // task-related events
        SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.TASK_WAITING_FOR_RESTART, SchedulerEvent.USERS_UPDATE, // Scheduler state related events
        SchedulerEvent.FROZEN, SchedulerEvent.RESUMED, SchedulerEvent.SHUTDOWN, SchedulerEvent.SHUTTING_DOWN, SchedulerEvent.STARTED, SchedulerEvent.STOPPED, SchedulerEvent.KILLED);
        if (getInitialState) {
            logger.info("Initial state of the scheduler is: " + initialState);
        }
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Class " + listenerClazzName + " is not available on this SchedulerUser's side", e);
    } catch (InstantiationException e) {
        throw new IllegalArgumentException("Cannot instantiate listener of type " + listenerClazzName, e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("Cannot instantiate listener of type " + listenerClazzName, e);
    }
}
Also used : SchedulerListenerExposer(scalabilityTests.framework.listeners.SchedulerListenerExposer) SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) SchedulerEventListener(org.ow2.proactive.scheduler.common.SchedulerEventListener)

Example 9 with SchedulerState

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

the class SchedulerTestUser method connect.

/**
 * Connects the singleton using the given user
 */
public boolean connect(String username, String password, byte[] key, String schedulerUrl) throws LoginException, KeyException, ActiveObjectCreationException, NodeException, SchedulerException {
    this.connectedUserName = username;
    this.connectedUserPassword = password;
    this.connectedUserKey = key;
    disconnectFromScheduler();
    if (schedulerProxy == null) {
        schedulerProxy = PAActiveObject.newActive(SchedulerProxyUserInterface.class, new Object[0]);
    }
    SchedulerTHelper.log("Connecting user " + connectedUserName + " to the Scheduler at url " + schedulerUrl);
    CredData connectedUserCreds = new CredData(CredData.parseLogin(connectedUserName), CredData.parseDomain(connectedUserName), connectedUserPassword, connectedUserKey);
    schedulerProxy.init(schedulerUrl, connectedUserCreds);
    monitorsHandler = new SchedulerMonitorsHandler();
    if (eventReceiver != null) {
        PAActiveObject.terminateActiveObject(eventReceiver, true);
    }
    /**
     * create event receiver then turnActive to avoid deepCopy of MonitorsHandler object
     * 	(shared instance between event receiver and static helpers).
     */
    MonitorEventReceiver passiveEventReceiver = new MonitorEventReceiver(monitorsHandler);
    eventReceiver = PAActiveObject.turnActive(passiveEventReceiver);
    SchedulerState state = schedulerProxy.addEventListener(eventReceiver, true, true);
    monitorsHandler.init(state);
    return true;
}
Also used : MonitorEventReceiver(functionaltests.monitor.MonitorEventReceiver) SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) CredData(org.ow2.proactive.authentication.crypto.CredData) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) SchedulerMonitorsHandler(functionaltests.monitor.SchedulerMonitorsHandler)

Example 10 with SchedulerState

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

the class TestLoadJobs method testLoadJobs.

@Test
public void testLoadJobs() throws Exception {
    long time = System.currentTimeMillis();
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    FileLock fileLock = new FileLock();
    Path lock = fileLock.lock();
    String fileLockPath = lock.toString();
    logger.info("File lock location is " + fileLockPath);
    JobInfo job;
    List<JobInfo> jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    JobId firstJob = scheduler.submit(createJob(fileLockPath));
    schedulerHelper.waitForEventTaskRunning(firstJob, "Test");
    jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob);
    job = jobs.get(0);
    assertEquals(this.getClass().getSimpleName(), job.getJobId().getReadableName());
    assertEquals(1, job.getTotalNumberOfTasks());
    assertEquals(0, job.getNumberOfFinishedTasks());
    assertEquals(0, job.getNumberOfPendingTasks());
    assertEquals(1, job.getNumberOfRunningTasks());
    assertEquals(JobStatus.RUNNING, job.getStatus());
    assertTrue("Unexpected submit time: " + job.getSubmittedTime(), job.getSubmittedTime() > time && job.getSubmittedTime() < System.currentTimeMillis());
    assertTrue("Unexpected start time: " + job.getStartTime(), job.getStartTime() > time && job.getStartTime() < System.currentTimeMillis());
    assertEquals(-1, job.getFinishedTime());
    assertEquals(-1, job.getRemovedTime());
    assertEquals(TestUsers.DEMO.username, job.getJobOwner());
    assertEquals(JobPriority.NORMAL, job.getPriority());
    JobId secondJob = scheduler.submit(createJob(fileLockPath));
    JobId thirdJob = scheduler.submit(createJob(fileLockPath));
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    jobs = scheduler.getJobs(1, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob, thirdJob);
    jobs = scheduler.getJobs(1, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_DESC).getList();
    checkJobs(jobs, thirdJob, secondJob, firstJob);
    fileLock.unlock();
    for (JobInfo jobInfo : jobs) {
        schedulerHelper.waitForEventJobFinished(jobInfo.getJobId(), 30000);
    }
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, false), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    scheduler.disconnect();
    // connect as another user
    SchedulerMonitorsHandler monitorsHandler = new SchedulerMonitorsHandler();
    SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
    scheduler = auth.login(cred);
    eventReceiver = new MonitorEventReceiver(monitorsHandler);
    eventReceiver = PAActiveObject.turnActive(eventReceiver);
    SchedulerState state = scheduler.addEventListener(eventReceiver, true, true);
    monitorsHandler.init(state);
    jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    fileLockPath = fileLock.lock().toString();
    JobId fourthJob = scheduler.submit(createJob(fileLockPath));
    monitorsHandler.waitForEventTask(SchedulerEvent.TASK_PENDING_TO_RUNNING, fourthJob, "Test", 30000);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, fourthJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
    jobs = scheduler.getJobs(2, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, thirdJob, fourthJob);
    fileLock.unlock();
    monitorsHandler.waitForFinishedJob(fourthJob, 30000);
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, fourthJob);
    jobs = scheduler.getJobs(0, 10, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
    jobs = scheduler.getJobs(1, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob);
    jobs = scheduler.getJobs(1, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob, thirdJob);
    jobs = scheduler.getJobs(2, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, thirdJob);
    jobs = scheduler.getJobs(2, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, thirdJob, fourthJob);
    scheduler.disconnect();
    PAActiveObject.terminateActiveObject(eventReceiver, true);
    // connect as a user who can see only its own jobs
    cred = Credentials.createCredentials(new CredData("guest", "pwd"), auth.getPublicKey());
    scheduler = auth.login(cred);
    monitorsHandler = new SchedulerMonitorsHandler();
    eventReceiver = new MonitorEventReceiver(monitorsHandler);
    eventReceiver = PAActiveObject.turnActive(eventReceiver);
    state = scheduler.addEventListener(eventReceiver, true, true);
    monitorsHandler.init(state);
    JobId myjob = scheduler.submit(createJob(fileLockPath));
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, myjob);
    jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, myjob);
    scheduler.disconnect();
}
Also used : Path(java.nio.file.Path) MonitorEventReceiver(functionaltests.monitor.MonitorEventReceiver) SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) FileLock(org.ow2.proactive.scheduler.util.FileLock) JobId(org.ow2.proactive.scheduler.common.job.JobId) SchedulerMonitorsHandler(functionaltests.monitor.SchedulerMonitorsHandler) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Aggregations

SchedulerState (org.ow2.proactive.scheduler.common.SchedulerState)11 JobId (org.ow2.proactive.scheduler.common.job.JobId)6 JobState (org.ow2.proactive.scheduler.common.job.JobState)6 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)3 Test (org.junit.Test)3 MonitorEventReceiver (functionaltests.monitor.MonitorEventReceiver)2 SchedulerMonitorsHandler (functionaltests.monitor.SchedulerMonitorsHandler)2 CredData (org.ow2.proactive.authentication.crypto.CredData)2 RecoveredSchedulerState (org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 PAActiveObject (org.objectweb.proactive.api.PAActiveObject)1 UniqueID (org.objectweb.proactive.core.UniqueID)1 Credentials (org.ow2.proactive.authentication.crypto.Credentials)1 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)1 SchedulerEventListener (org.ow2.proactive.scheduler.common.SchedulerEventListener)1 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)1