Search in sources :

Example 66 with Job

use of com.google.cloud.dataproc.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 67 with Job

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

the class QuartzSchedulerIT method testGetJobs.

@Test
public void testGetJobs() throws SchedulerException {
    QuartzScheduler testGetJobsSchduler = new QuartzScheduler();
    Assert.assertEquals(0, testGetJobsSchduler.getJobs(null).size());
    String PARAM_KEY = "testGetJobsKey";
    jobParams.put(PARAM_KEY, "testParam1-value");
    Calendar calendar = Calendar.getInstance();
    int startingMin = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 10;
    if (startingSec > 59) {
        startingSec = startingSec % 60;
        startingMin++;
        if (startingMin > 59) {
            startingMin = startingMin % 60;
        }
    }
    calendar.set(Calendar.MINUTE, startingMin);
    calendar.set(Calendar.SECOND, startingSec);
    SimpleJobTrigger jobTrigger = new SimpleJobTrigger(calendar.getTime(), null, 0, 0);
    testGetJobsSchduler.createJob("getJobsTestJob", TestAction.class, jobParams, jobTrigger);
    List<Job> jobs = testGetJobsSchduler.getJobs(null);
    Assert.assertEquals(1, jobs.size());
    Job theJob = jobs.get(0);
    Assert.assertTrue(theJob.getJobParams().containsKey(PARAM_KEY));
    Assert.assertTrue(theJob.getJobName().contains("getJobsTestJob"));
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Calendar(java.util.Calendar) TestQuartzScheduler(org.pentaho.platform.scheduler2.ws.test.TestQuartzScheduler) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 68 with Job

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

the class JaxWsSchedulerServiceIT method testUpdateComplexJob.

/*
  public static class TestQuartzScheduler extends QuartzScheduler {
    @Override
    protected String getCurrentUser() {
      SecurityHelper.getInstance().becomeUser( TEST_USER );
      return super.getCurrentUser();
    }
  }
*/
@Test(timeout = 1000 * 5 * 60)
public void testUpdateComplexJob() throws SchedulerException {
    long start = System.currentTimeMillis() + 1000;
    long end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
    int startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 10) % 60;
    ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 1));
    jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    System.out.println(jobTrigger.toString());
    String jobId = schedulerSvc.createComplexJob("test job", jobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    jobTrigger = new ComplexJobTrigger();
    start = System.currentTimeMillis() + 2 * 1000;
    end = System.currentTimeMillis() + 1000 + 7 * 60 * 60 * 100;
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 20) % 60;
    jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 5));
    jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    System.out.println(jobTrigger.toString());
    HashMap<String, ParamValue> newJobParams = new HashMap<String, ParamValue>(jobParams);
    newJobParams.put("newKey", new StringParamValue(""));
    schedulerSvc.updateJobToUseComplexTrigger(jobId, newJobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    Job job = schedulerSvc.getJobs()[0];
    jobTrigger = (ComplexJobTrigger) job.getJobTrigger();
    Assert.assertEquals((Integer) startingMinute, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getStartingValue());
    Assert.assertEquals((Integer) 5, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getIncrement());
    Assert.assertTrue(job.getJobParams().containsKey("newKey"));
    Assert.assertEquals(new Date(start), jobTrigger.getStartTime());
    Assert.assertEquals(new Date(end), jobTrigger.getEndTime());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) HashMap(java.util.HashMap) IncrementalRecurrence(org.pentaho.platform.scheduler2.recur.IncrementalRecurrence) ListParamValue(org.pentaho.platform.scheduler2.ws.ListParamValue) ParamValue(org.pentaho.platform.scheduler2.ws.ParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) MapParamValue(org.pentaho.platform.scheduler2.ws.MapParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Example 69 with Job

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

the class JaxWsSchedulerServiceIT method testUpdateSimpleJob.

@Test
public void testUpdateSimpleJob() throws SchedulerException {
    long start = System.currentTimeMillis() + 1000;
    long end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
    SimpleJobTrigger jobTrigger = new SimpleJobTrigger();
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    jobTrigger.setRepeatInterval(10);
    jobTrigger.setRepeatCount(20);
    System.out.println(jobTrigger.toString());
    String jobId = schedulerSvc.createSimpleJob("test job", jobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    jobTrigger = new SimpleJobTrigger();
    start = System.currentTimeMillis() + 1000;
    end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    jobTrigger.setRepeatInterval(40);
    jobTrigger.setRepeatCount(50);
    System.out.println(jobTrigger.toString());
    HashMap<String, ParamValue> newJobParams = new HashMap<String, ParamValue>(jobParams);
    newJobParams.put("newKey", new StringParamValue(""));
    schedulerSvc.updateJobToUseSimpleTrigger(jobId, newJobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    Job job = schedulerSvc.getJobs()[0];
    jobTrigger = (SimpleJobTrigger) job.getJobTrigger();
    Assert.assertEquals(40, jobTrigger.getRepeatInterval());
    Assert.assertEquals(50, jobTrigger.getRepeatCount());
    Assert.assertTrue(job.getJobParams().containsKey("newKey"));
    jobTrigger.getStartTime();
    Assert.assertEquals(new Date(start), jobTrigger.getStartTime());
    Assert.assertEquals(new Date(end), jobTrigger.getEndTime());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) HashMap(java.util.HashMap) ListParamValue(org.pentaho.platform.scheduler2.ws.ListParamValue) ParamValue(org.pentaho.platform.scheduler2.ws.ParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) MapParamValue(org.pentaho.platform.scheduler2.ws.MapParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Example 70 with Job

use of com.google.cloud.dataproc.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)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)94 Test (org.junit.Test)91 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)38 Serializable (java.io.Serializable)25 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)22 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)21 Job (com.google.cloud.talent.v4beta1.Job)20 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)19 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 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)13 JobBuilder (io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)13 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 Map (java.util.Map)11 Test (org.junit.jupiter.api.Test)10