Search in sources :

Example 1 with SchedulerStateImpl

use of org.ow2.proactive.scheduler.core.SchedulerStateImpl in project scheduling by ow2-proactive.

the class RecoveredSchedulerStateTest method testConstructor.

@Test
public void testConstructor() throws Exception {
    int nbJobs = 2;
    Vector<InternalJob> pendingJobs = createJobs(JobStatus.PENDING, nbJobs);
    Vector<InternalJob> runningJobs = createJobs(JobStatus.RUNNING, nbJobs);
    Vector<InternalJob> finishedJobs = createJobs(JobStatus.FINISHED, nbJobs);
    RecoveredSchedulerState recoveredState = new RecoveredSchedulerState(pendingJobs, runningJobs, finishedJobs);
    assertThat(recoveredState.getPendingJobs()).containsExactlyElementsIn(pendingJobs);
    assertThat(recoveredState.getRunningJobs()).containsExactlyElementsIn(runningJobs);
    assertThat(recoveredState.getFinishedJobs()).containsExactlyElementsIn(finishedJobs);
    SchedulerStateImpl schedulerState = recoveredState.getSchedulerState();
    assertThat(schedulerState).isNotNull();
    assertThat(schedulerState.getPendingJobs()).hasSize(nbJobs);
    assertThat(schedulerState.getRunningJobs()).hasSize(nbJobs);
    assertThat(schedulerState.getFinishedJobs()).hasSize(nbJobs);
    assertThat(schedulerState.getPendingJobs().get(0)).isInstanceOf(ClientJobState.class);
    assertThat(schedulerState.getRunningJobs().get(0)).isInstanceOf(ClientJobState.class);
    assertThat(schedulerState.getFinishedJobs().get(0)).isInstanceOf(ClientJobState.class);
}
Also used : RecoveredSchedulerState(org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) SchedulerStateImpl(org.ow2.proactive.scheduler.core.SchedulerStateImpl) Test(org.junit.Test)

Example 2 with SchedulerStateImpl

use of org.ow2.proactive.scheduler.core.SchedulerStateImpl in project scheduling by ow2-proactive.

the class SchedulerFrontendStateTest method session_removal_should_not_throw_concurrent_modification_exception.

// SCHEDULING-2242
@Test
public void session_removal_should_not_throw_concurrent_modification_exception() throws Exception {
    PASchedulerProperties.SCHEDULER_USER_SESSION_TIME.updateProperty("1");
    SchedulerJMXHelper mockJMX = mock(SchedulerJMXHelper.class);
    when(mockJMX.getSchedulerRuntimeMBean()).thenReturn(new RuntimeDataMBeanImpl(null));
    final SchedulerFrontendState schedulerFrontendState = new SchedulerFrontendState(new SchedulerStateImpl<ClientJobState>(), mockJMX);
    // create a bunch of active sessions, they will be removed in 1s
    for (int i = 0; i < 100; i++) {
        UserIdentificationImpl identification = new UserIdentificationImpl("john");
        identification.setHostName("localhost");
        schedulerFrontendState.connect(new UniqueID("abc" + i), identification, null);
    }
    // use the FrontendState continuously to query the active sessions
    ExecutorService executor = Executors.newFixedThreadPool(1);
    Future<Object> noException = executor.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (; ; ) {
                schedulerFrontendState.getUsers();
            }
        }
    });
    try {
        noException.get(2, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        fail("Should exit with timeout exception " + e.getMessage());
    } catch (TimeoutException e) {
    // expected timeout exception after two seconds
    } finally {
        executor.shutdownNow();
    }
}
Also used : UniqueID(org.objectweb.proactive.core.UniqueID) RuntimeDataMBeanImpl(org.ow2.proactive.scheduler.core.jmx.mbean.RuntimeDataMBeanImpl) UserIdentificationImpl(org.ow2.proactive.scheduler.job.UserIdentificationImpl) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) SchedulerJMXHelper(org.ow2.proactive.scheduler.core.jmx.SchedulerJMXHelper) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 3 with SchedulerStateImpl

use of org.ow2.proactive.scheduler.core.SchedulerStateImpl in project scheduling by ow2-proactive.

the class SchedulerFrontendStateTest method getIdentifiedJobTest.

@Test
public void getIdentifiedJobTest() throws Exception {
    SchedulerJMXHelper mockJMX = mock(SchedulerJMXHelper.class);
    when(mockJMX.getSchedulerRuntimeMBean()).thenReturn(new RuntimeDataMBeanImpl(null));
    SchedulerStateImpl<ClientJobState> schedulerStateImpl = new SchedulerStateImpl<>();
    JobIdImpl jobId = new JobIdImpl(1234L, "job name");
    ClientJobState jobState = mock(ClientJobState.class);
    when(jobState.getId()).thenReturn(jobId);
    schedulerStateImpl.setFinishedJobs(new Vector(Lists.newArrayList(jobState)));
    final SchedulerFrontendState schedulerFrontendState = new SchedulerFrontendState(schedulerStateImpl, mockJMX);
    assertEquals(schedulerFrontendState.getIdentifiedJob(jobId).getJobId(), (jobId));
}
Also used : SchedulerJMXHelper(org.ow2.proactive.scheduler.core.jmx.SchedulerJMXHelper) RuntimeDataMBeanImpl(org.ow2.proactive.scheduler.core.jmx.mbean.RuntimeDataMBeanImpl) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Vector(java.util.Vector) Test(org.junit.Test)

Example 4 with SchedulerStateImpl

use of org.ow2.proactive.scheduler.core.SchedulerStateImpl in project scheduling by ow2-proactive.

the class SchedulerFrontendState method recover.

/**
 * Called to recover the front end state. This method may have to rebuild
 * the different list of userIdentification and job/user association.
 */
private void recover(SchedulerStateImpl sState) {
    Vector<ClientJobState> pendingJobs = sState.getPendingJobs();
    Vector<ClientJobState> runningJobs = sState.getRunningJobs();
    Vector<ClientJobState> finishedJobs = sState.getFinishedJobs();
    // default state = started
    Set<JobState> jobStates = new HashSet<>(pendingJobs.size() + runningJobs.size() + finishedJobs.size());
    if (logger.isInfoEnabled()) {
        logger.info("#Pending jobs: " + pendingJobs.size() + " #Running jobs: " + runningJobs.size() + " #Finished jobs: " + finishedJobs.size());
    }
    for (ClientJobState js : pendingJobs) {
        prepare(jobStates, js, false);
    }
    for (ClientJobState js : runningJobs) {
        prepare(jobStates, js, false);
    }
    for (ClientJobState js : finishedJobs) {
        prepare(jobStates, js, true);
    }
}
Also used : ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) JobState(org.ow2.proactive.scheduler.common.job.JobState) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) HashSet(java.util.HashSet)

Aggregations

Test (org.junit.Test)3 ClientJobState (org.ow2.proactive.scheduler.job.ClientJobState)3 SchedulerJMXHelper (org.ow2.proactive.scheduler.core.jmx.SchedulerJMXHelper)2 RuntimeDataMBeanImpl (org.ow2.proactive.scheduler.core.jmx.mbean.RuntimeDataMBeanImpl)2 HashSet (java.util.HashSet)1 Vector (java.util.Vector)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 UniqueID (org.objectweb.proactive.core.UniqueID)1 JobState (org.ow2.proactive.scheduler.common.job.JobState)1 SchedulerStateImpl (org.ow2.proactive.scheduler.core.SchedulerStateImpl)1 RecoveredSchedulerState (org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState)1 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)1 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)1 UserIdentificationImpl (org.ow2.proactive.scheduler.job.UserIdentificationImpl)1