Search in sources :

Example 11 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.

the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_monthsOfYear.

@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_monthsOfYear() throws Exception {
    complex.setMonthsOfYear(new int[] { 1, 8 });
    when(scheduleRequest.getComplexJobTrigger()).thenReturn(complex);
    IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
    assertNotNull(trigger);
    assertTrue(trigger instanceof ComplexJobTrigger);
    ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
    List<ITimeRecurrence> recurrences = trig.getMonthlyRecurrences().getRecurrences();
    assertEquals(2, recurrences.size());
    RecurrenceList rec = (RecurrenceList) recurrences.get(0);
    assertEquals(2, rec.getValues().get(0).intValue());
    rec = (RecurrenceList) recurrences.get(1);
    assertEquals(9, rec.getValues().get(0).intValue());
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Example 12 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.

the class ScheduleExportUtil method createJobScheduleRequest.

public static JobScheduleRequest createJobScheduleRequest(Job job) {
    if (job == null) {
        throw new IllegalArgumentException(Messages.getInstance().getString("ScheduleExportUtil.JOB_MUST_NOT_BE_NULL"));
    }
    JobScheduleRequest schedule = new JobScheduleRequest();
    schedule.setJobName(job.getJobName());
    schedule.setDuration(job.getJobTrigger().getDuration());
    schedule.setJobState(job.getState());
    Map<String, Serializable> jobParams = job.getJobParams();
    Object streamProviderObj = jobParams.get(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER);
    RepositoryFileStreamProvider streamProvider = null;
    if (streamProviderObj instanceof RepositoryFileStreamProvider) {
        streamProvider = (RepositoryFileStreamProvider) streamProviderObj;
    } else if (streamProviderObj instanceof String) {
        String inputFilePath = null;
        String outputFilePath = null;
        String inputOutputString = (String) streamProviderObj;
        String[] tokens = inputOutputString.split(":");
        if (!ArrayUtils.isEmpty(tokens) && tokens.length == 2) {
            inputFilePath = tokens[0].split("=")[1].trim();
            outputFilePath = tokens[1].split("=")[1].trim();
            streamProvider = new RepositoryFileStreamProvider(inputFilePath, outputFilePath, true);
        }
    }
    if (streamProvider != null) {
        schedule.setInputFile(streamProvider.getInputFilePath());
        schedule.setOutputFile(streamProvider.getOutputFilePath());
    } else {
        // let's look to see if we can figure out the input and output file
        String directory = (String) jobParams.get("directory");
        String transName = (String) jobParams.get("transformation");
        String jobName = (String) jobParams.get("job");
        String artifact = transName == null ? jobName : transName;
        if (directory != null && artifact != null) {
            String outputFile = RepositoryFilenameUtils.concat(directory, artifact);
            outputFile += "*";
            if (artifact.equals(jobName)) {
                artifact += ".kjb";
            } else {
                artifact += ".ktr";
            }
            String inputFile = RepositoryFilenameUtils.concat(directory, artifact);
            schedule.setInputFile(inputFile);
            schedule.setOutputFile(outputFile);
        }
    }
    for (String key : jobParams.keySet()) {
        Serializable serializable = jobParams.get(key);
        if (RUN_PARAMETERS_KEY.equals(key)) {
            if (schedule.getPdiParameters() == null) {
                schedule.setPdiParameters(new HashMap<String, String>());
            }
            schedule.getPdiParameters().putAll((Map<String, String>) serializable);
        } else {
            JobScheduleParam param = null;
            if (serializable instanceof String) {
                String value = (String) serializable;
                if (QuartzScheduler.RESERVEDMAPKEY_ACTIONCLASS.equals(key)) {
                    schedule.setActionClass(value);
                } else if (IBlockoutManager.TIME_ZONE_PARAM.equals(key)) {
                    schedule.setTimeZone(value);
                }
                param = new JobScheduleParam(key, (String) serializable);
            } else if (serializable instanceof Number) {
                param = new JobScheduleParam(key, (Number) serializable);
            } else if (serializable instanceof Date) {
                param = new JobScheduleParam(key, (Date) serializable);
            } else if (serializable instanceof Boolean) {
                param = new JobScheduleParam(key, (Boolean) serializable);
            }
            if (param != null) {
                schedule.getJobParameters().add(param);
            }
        }
    }
    if (job.getJobTrigger() instanceof SimpleJobTrigger) {
        SimpleJobTrigger jobTrigger = (SimpleJobTrigger) job.getJobTrigger();
        schedule.setSimpleJobTrigger(jobTrigger);
    } else if (job.getJobTrigger() instanceof ComplexJobTrigger) {
        ComplexJobTrigger jobTrigger = (ComplexJobTrigger) job.getJobTrigger();
        // force it to a cron trigger to get the auto-parsing of the complex trigger
        CronJobTrigger cron = new CronJobTrigger();
        cron.setCronString(jobTrigger.getCronString());
        cron.setStartTime(jobTrigger.getStartTime());
        cron.setEndTime(jobTrigger.getEndTime());
        cron.setDuration(jobTrigger.getDuration());
        cron.setUiPassParam(jobTrigger.getUiPassParam());
        schedule.setCronJobTrigger(cron);
    } else if (job.getJobTrigger() instanceof CronJobTrigger) {
        CronJobTrigger jobTrigger = (CronJobTrigger) job.getJobTrigger();
        schedule.setCronJobTrigger(jobTrigger);
    } else {
        // don't know what this is, can't export it
        throw new IllegalArgumentException(Messages.getInstance().getString("PentahoPlatformExporter.UNSUPPORTED_JobTrigger", job.getJobTrigger().getClass().getName()));
    }
    return schedule;
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) Serializable(java.io.Serializable) Date(java.util.Date) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RepositoryFileStreamProvider(org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger)

Example 13 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger 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 14 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger 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)

Example 15 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.

the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_years.

@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_years() throws Exception {
    complex.setYears(new int[] { 2016, 2020 });
    when(scheduleRequest.getComplexJobTrigger()).thenReturn(complex);
    IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
    assertNotNull(trigger);
    assertTrue(trigger instanceof ComplexJobTrigger);
    ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
    List<ITimeRecurrence> recurrences = trig.getYearlyRecurrences().getRecurrences();
    assertEquals(2, recurrences.size());
    RecurrenceList rec = (RecurrenceList) recurrences.get(0);
    assertEquals(2016, rec.getValues().get(0).intValue());
    rec = (RecurrenceList) recurrences.get(1);
    assertEquals(2020, rec.getValues().get(0).intValue());
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Aggregations

ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)28 Test (org.junit.Test)21 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 Job (org.pentaho.platform.api.scheduler2.Job)12 Calendar (java.util.Calendar)8 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)8 ITimeRecurrence (org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence)7 RecurrenceList (org.pentaho.platform.scheduler2.recur.RecurrenceList)6 IncrementalRecurrence (org.pentaho.platform.scheduler2.recur.IncrementalRecurrence)5 Serializable (java.io.Serializable)4 Date (java.util.Date)4 GregorianCalendar (java.util.GregorianCalendar)4 QualifiedDayOfWeek (org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek)4 HashMap (java.util.HashMap)3 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)3 Calendar (org.quartz.Calendar)3 CronTrigger (org.quartz.CronTrigger)3 SimpleTrigger (org.quartz.SimpleTrigger)3 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)2 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)2