Search in sources :

Example 31 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method testPauseAndResumeJob.

@Test
public void testPauseAndResumeJob() throws SchedulerException {
    String jobName = "complexJob1";
    int counter = TestAction.counter;
    Calendar calendar = Calendar.getInstance();
    int startingMin = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 1;
    if (startingSec > 59) {
        startingSec = startingSec % 60;
        startingMin++;
        if (startingMin > 59) {
            startingMin = startingMin % 60;
        }
    }
    ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
    complexJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    complexJobTrigger.setMinuteRecurrence(startingMin);
    complexJobTrigger.setSecondRecurrence(startingSec);
    Job job = scheduler.createJob(jobName, TestAction.class, jobParams, complexJobTrigger);
    scheduler.pauseJob(job.getJobId());
    sleep(2);
    Assert.assertEquals(counter, TestAction.counter);
    Assert.assertEquals(1, scheduler.getJobs(null).size());
    scheduler.resumeJob(job.getJobId());
    sleep(2);
    Assert.assertTrue(counter != TestAction.counter);
    scheduler.removeJob(job.getJobId());
    Assert.assertEquals(0, scheduler.getJobs(null).size());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Calendar(java.util.Calendar) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 32 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method runComplexTriggerTest.

@Test
public void runComplexTriggerTest() throws SchedulerException {
    Calendar calendar = Calendar.getInstance();
    // seconds
    final int testTime = 7;
    int startingMinute = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 1;
    // we can't finish until end of the minute - sleep for this time
    if (startingSec > 59 - testTime) {
        sleep(59 - startingSec);
        startingSec = 0;
        startingMinute++;
        if (startingMinute > 59) {
            startingMinute = startingMinute % 60;
        }
    }
    int endingSecond = startingSec + 5;
    RecurrenceList recurrenceList = new RecurrenceList(startingSec, endingSecond);
    SequentialRecurrence sequentialRecurrence = new SequentialRecurrence(startingSec, endingSecond);
    IncrementalRecurrence incrementalRecurrence = new IncrementalRecurrence(startingSec, 1);
    ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
    jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    jobTrigger.setMinuteRecurrence(startingMinute);
    jobTrigger.setSecondRecurrence(recurrenceList);
    System.out.println(jobTrigger.toString());
    String jobName = "complexJob1";
    Job job = scheduler.createJob(jobName, TestAction.class, new HashMap<String, Serializable>(), jobTrigger);
    Assert.assertTrue(job.getJobName().contains(jobName));
    Assert.assertEquals(job.getSchedulableClass(), TestAction.class.getName());
    Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
    jobTrigger.setSecondRecurrence(sequentialRecurrence);
    jobName = "complexJob2";
    job = scheduler.createJob(jobName, TestAction2.class, new HashMap<String, Serializable>(), jobTrigger);
    Assert.assertTrue(job.getJobName().contains(jobName));
    Assert.assertEquals(job.getSchedulableClass(), TestAction2.class.getName());
    Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
    jobTrigger.setSecondRecurrence(incrementalRecurrence);
    jobName = "complexJob3";
    job = scheduler.createJob(jobName, TestAction3.class, new HashMap<String, Serializable>(), jobTrigger);
    Assert.assertTrue(job.getJobName().contains(jobName));
    Assert.assertEquals(job.getSchedulableClass(), TestAction3.class.getName());
    Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
    // 
    // Wait for the jobs to complete, then check that each action executed the correct number of times
    // 
    sleep(testTime);
    Assert.assertEquals("Job did not run the correct number of times", 2, TestAction.counter);
    Assert.assertEquals("Job did not run the correct number of times", 6, TestAction2.counter);
    System.out.println("Counter = " + TestAction3.counter);
    Assert.assertTrue("Job did not run.", TestAction3.counter > 3);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Calendar(java.util.Calendar) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) SequentialRecurrence(org.pentaho.platform.scheduler2.recur.SequentialRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IncrementalRecurrence(org.pentaho.platform.scheduler2.recur.IncrementalRecurrence) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 33 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class PentahoBlockoutManager method willBlockSchedules.

@Override
public List<IJobTrigger> willBlockSchedules(IJobTrigger testBlockOutJobTrigger) {
    List<IJobTrigger> blockedSchedules = new ArrayList<IJobTrigger>();
    List<Job> scheduledJobs = new ArrayList<Job>();
    try {
        scheduledJobs = this.scheduler.getJobs(new IJobFilter() {

            @Override
            public boolean accept(Job job) {
                return !BLOCK_OUT_JOB_NAME.equals(job.getJobName());
            }
        });
    } catch (SchedulerException e) {
        throw new RuntimeException(e);
    }
    // Loop over trigger group names
    for (Job scheduledJob : scheduledJobs) {
        // Add schedule to list if block out conflicts at all
        if (BlockoutManagerUtil.willBlockSchedule(scheduledJob.getJobTrigger(), testBlockOutJobTrigger, this.scheduler)) {
            blockedSchedules.add(scheduledJob.getJobTrigger());
        }
    }
    return blockedSchedules;
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job)

Example 34 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method createJobTest.

@Test
public void createJobTest() throws Exception {
    String actionId = "actionId";
    ComplexJobTrigger trigger = getComplexJobTrigger();
    IBackgroundExecutionStreamProvider outputStreamProvider = mock(IBackgroundExecutionStreamProvider.class);
    final Job job = scheduler.createJob(JOB_NAME, actionId, null, trigger, outputStreamProvider);
    assertNotNull(job);
    assertEquals(Job.JobState.NORMAL, job.getState());
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
    assertEquals(actionId, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
    assertEquals(outputStreamProvider, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
    assertNotNull(job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
    assertEquals(USER_NAME, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 35 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method getJobTest.

@Test
public void getJobTest() throws Exception {
    final CronTrigger cronTrigger = mock(CronTrigger.class);
    when(cronTrigger.getCronExpression()).thenReturn(CRON_EXPRESSION);
    when(quartzScheduler.getTriggersOfJob(eq(JOB_ID), eq(USER_NAME))).thenReturn(new Trigger[] { cronTrigger });
    setJobDataMap(USER_NAME);
    final Job job = scheduler.getJob(JOB_ID);
    assertEquals(JOB_ID, job.getJobId());
    assertEquals(jobDetails, job.getJobParams());
    assertEquals(USER_NAME, job.getUserName());
    assertEquals(JOB_NAME, job.getJobName());
    assertEquals(Job.JobState.NORMAL, job.getState());
}
Also used : CronTrigger(org.quartz.CronTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)94 Test (org.junit.Test)80 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)33 Serializable (java.io.Serializable)25 ArrayList (java.util.ArrayList)22 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)21 Job (com.google.cloud.talent.v4beta1.Job)20 HashMap (java.util.HashMap)20 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)19 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)18 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)17 JobServiceClient (com.google.cloud.talent.v4beta1.JobServiceClient)16 Date (java.util.Date)14 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)14 Job (com.google.cloud.video.transcoder.v1.Job)13 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 JobBuilder (io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)11 Map (java.util.Map)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10