Search in sources :

Example 1 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class PentahoPlatformExporter method exportSchedules.

protected void exportSchedules() {
    log.debug("export schedules");
    try {
        List<Job> jobs = getScheduler().getJobs(null);
        for (Job job : jobs) {
            if (job.getJobName().equals(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME)) {
                // if it doesn't exist and fails if you try to import it due to a null ActionClass
                continue;
            }
            try {
                JobScheduleRequest scheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
                getExportManifest().addSchedule(scheduleRequest);
            } catch (IllegalArgumentException e) {
                log.warn(e.getMessage(), e);
            }
        }
    } catch (SchedulerException e) {
        log.error(Messages.getInstance().getString("PentahoPlatformExporter.ERROR_EXPORTING_JOBS"), e);
    }
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest)

Example 2 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_StringStreamProvider.

@Test
public void testCreateJobScheduleRequest_StringStreamProvider() throws Exception {
    String jobName = "JOB";
    Job job = mock(Job.class);
    SimpleJobTrigger trigger = mock(SimpleJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    Map<String, Serializable> params = new HashMap<>();
    params.put(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER, "import file = /home/admin/myJob.kjb:output file=/home/admin/myJob*");
    when(job.getJobParams()).thenReturn(params);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertNotNull(jobScheduleRequest);
    assertEquals(jobName, jobScheduleRequest.getJobName());
    assertEquals(trigger, jobScheduleRequest.getSimpleJobTrigger());
    assertEquals("/home/admin/myJob.kjb", jobScheduleRequest.getInputFile());
    assertEquals("/home/admin/myJob*", jobScheduleRequest.getOutputFile());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 3 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_MultipleTypesJobParam.

@Test
public void testCreateJobScheduleRequest_MultipleTypesJobParam() throws Exception {
    String jobName = "JOB";
    Long l = Long.MAX_VALUE;
    Date d = new Date();
    Boolean b = true;
    Map<String, Serializable> params = new HashMap<>();
    params.put("NumberValue", l);
    params.put("DateValue", d);
    params.put("BooleanValue", b);
    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);
    for (JobScheduleParam jobScheduleParam : jobScheduleRequest.getJobParameters()) {
        assertTrue(jobScheduleParam.getValue().equals(l) || jobScheduleParam.getValue().equals(d) || jobScheduleParam.getValue().equals(b));
    }
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Date(java.util.Date) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 4 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_ActionClassJobParam.

@Test
public void testCreateJobScheduleRequest_ActionClassJobParam() throws Exception {
    String jobName = "JOB";
    String actionClass = "com.pentaho.Action";
    Map<String, Serializable> params = new HashMap<>();
    params.put(QuartzScheduler.RESERVEDMAPKEY_ACTIONCLASS, actionClass);
    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(actionClass, jobScheduleRequest.getActionClass());
    assertEquals(actionClass, 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 5 with JobScheduleRequest

use of org.pentaho.platform.web.http.api.resources.JobScheduleRequest in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_NoStreamProvider.

@Test
public void testCreateJobScheduleRequest_NoStreamProvider() throws Exception {
    String jobName = "JOB";
    Job job = mock(Job.class);
    SimpleJobTrigger trigger = mock(SimpleJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    Map<String, Serializable> params = new HashMap<>();
    params.put("directory", "/home/admin");
    params.put("transformation", "myTransform");
    HashMap<String, String> pdiParams = new HashMap<>();
    pdiParams.put("pdiParam", "pdiParamValue");
    params.put(ScheduleExportUtil.RUN_PARAMETERS_KEY, pdiParams);
    when(job.getJobParams()).thenReturn(params);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertNotNull(jobScheduleRequest);
    assertEquals(jobName, jobScheduleRequest.getJobName());
    assertEquals(trigger, jobScheduleRequest.getSimpleJobTrigger());
    assertEquals("/home/admin/myTransform.ktr", jobScheduleRequest.getInputFile());
    assertEquals("/home/admin/myTransform*", jobScheduleRequest.getOutputFile());
    assertEquals("pdiParamValue", jobScheduleRequest.getPdiParameters().get("pdiParam"));
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Aggregations

JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)29 Test (org.junit.Test)24 Job (org.pentaho.platform.api.scheduler2.Job)19 ArrayList (java.util.ArrayList)11 Serializable (java.io.Serializable)10 HashMap (java.util.HashMap)9 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)9 JobScheduleParam (org.pentaho.platform.web.http.api.resources.JobScheduleParam)8 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)7 IOException (java.io.IOException)6 SchedulerResource (org.pentaho.platform.web.http.api.resources.SchedulerResource)5 Date (java.util.Date)4 Response (javax.ws.rs.core.Response)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)4 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)3 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)3 ComplexJobTriggerProxy (org.pentaho.platform.web.http.api.resources.ComplexJobTriggerProxy)3 Map (java.util.Map)2