Search in sources :

Example 66 with Job

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

the class RepositoryCleanerSystemListener method rescheduleIfNecessary.

private void rescheduleIfNecessary(IScheduler scheduler, List<Job> jobs) throws SchedulerException {
    JobTrigger trigger = findJobTrigger();
    if (trigger == null) {
        return;
    }
    List<Job> matched = new ArrayList<Job>(jobs.size());
    for (Job job : jobs) {
        JobTrigger tr = job.getJobTrigger();
        // unfortunately, JobTrigger does not override equals
        if (trigger.getClass() != tr.getClass()) {
            logger.info("Removing job with id: " + job.getJobId());
            scheduler.removeJob(job.getJobId());
        } else {
            matched.add(job);
        }
    }
    if (matched.isEmpty()) {
        logger.info("Need to re-schedule job");
        scheduleJob(scheduler);
    }
}
Also used : ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger)

Example 67 with Job

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

the class PentahoPlatformExporterTest method testExportSchedules.

@Test
public void testExportSchedules() throws Exception {
    List<Job> jobs = new ArrayList<>();
    ComplexJobTrigger trigger = mock(ComplexJobTrigger.class);
    JobTrigger unknownTrigger = mock(JobTrigger.class);
    Job job1 = mock(Job.class);
    Job job2 = mock(Job.class);
    Job job3 = mock(Job.class);
    jobs.add(job1);
    jobs.add(job2);
    jobs.add(job3);
    when(scheduler.getJobs(null)).thenReturn(jobs);
    when(job1.getJobName()).thenReturn(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME);
    when(job2.getJobName()).thenReturn("job 2");
    when(job2.getJobTrigger()).thenReturn(trigger);
    when(job3.getJobName()).thenReturn("job 3");
    when(job3.getJobTrigger()).thenReturn(unknownTrigger);
    exporterSpy.exportSchedules();
    verify(scheduler).getJobs(null);
    assertEquals(1, exporterSpy.getExportManifest().getScheduleList().size());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Test(org.junit.Test)

Example 68 with Job

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

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_TimeZoneJobParam.

@Test
public void testCreateJobScheduleRequest_TimeZoneJobParam() throws Exception {
    String jobName = "JOB";
    String timeZone = "America/New_York";
    Map<String, Serializable> params = new HashMap<>();
    params.put(IBlockoutManager.TIME_ZONE_PARAM, timeZone);
    Job job = mock(Job.class);
    CronJobTrigger trigger = mock(CronJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    when(job.getJobParams()).thenReturn(params);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertEquals(timeZone, jobScheduleRequest.getTimeZone());
    assertEquals(timeZone, jobScheduleRequest.getJobParameters().get(0).getValue());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 69 with Job

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

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_unknownTrigger.

@Test(expected = IllegalArgumentException.class)
public void testCreateJobScheduleRequest_unknownTrigger() throws Exception {
    String jobName = "JOB";
    Job job = mock(Job.class);
    JobTrigger trigger = mock(JobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
}
Also used : Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Test(org.junit.Test)

Example 70 with Job

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

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_ComplexJobTrigger.

@Test
public void testCreateJobScheduleRequest_ComplexJobTrigger() throws Exception {
    String jobName = "JOB";
    Date now = new Date();
    Job job = mock(Job.class);
    ComplexJobTrigger trigger = mock(ComplexJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    when(trigger.getCronString()).thenReturn("0 30 13 ? * 2,3,4,5,6 *");
    when(trigger.getDuration()).thenReturn(-1L);
    when(trigger.getStartTime()).thenReturn(now);
    when(trigger.getEndTime()).thenReturn(now);
    when(trigger.getUiPassParam()).thenReturn("uiPassParm");
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertNotNull(jobScheduleRequest);
    assertEquals(jobName, jobScheduleRequest.getJobName());
    // we should be getting back a cron trigger, not a complex trigger.
    assertNull(jobScheduleRequest.getSimpleJobTrigger());
    assertNull(jobScheduleRequest.getComplexJobTrigger());
    assertNotNull(jobScheduleRequest.getCronJobTrigger());
    assertEquals(trigger.getCronString(), jobScheduleRequest.getCronJobTrigger().getCronString());
    assertEquals(trigger.getDuration(), jobScheduleRequest.getCronJobTrigger().getDuration());
    assertEquals(trigger.getEndTime(), jobScheduleRequest.getCronJobTrigger().getEndTime());
    assertEquals(trigger.getStartTime(), jobScheduleRequest.getCronJobTrigger().getStartTime());
    assertEquals(trigger.getUiPassParam(), jobScheduleRequest.getCronJobTrigger().getUiPassParam());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)94 Test (org.junit.Test)69 Serializable (java.io.Serializable)25 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)21 HashMap (java.util.HashMap)20 ArrayList (java.util.ArrayList)19 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 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 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)12 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 AudioStream (com.google.cloud.video.transcoder.v1.AudioStream)8 JobConfig (com.google.cloud.video.transcoder.v1.JobConfig)8 VideoStream (com.google.cloud.video.transcoder.v1.VideoStream)8 Map (java.util.Map)8 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)8