Search in sources :

Example 6 with JobScheduleRequest

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

the class SchedulerService method getJobInfo.

public JobScheduleRequest getJobInfo() {
    JobScheduleRequest jobRequest = new JobScheduleRequest();
    ComplexJobTriggerProxy proxyTrigger = new ComplexJobTriggerProxy();
    proxyTrigger.setDaysOfMonth(new int[] { 1, 2, 3 });
    proxyTrigger.setDaysOfWeek(new int[] { 1, 2, 3 });
    proxyTrigger.setMonthsOfYear(new int[] { 1, 2, 3 });
    proxyTrigger.setYears(new int[] { 2012, 2013 });
    proxyTrigger.setStartTime(new Date());
    jobRequest.setComplexJobTrigger(proxyTrigger);
    jobRequest.setInputFile("aaaaa");
    jobRequest.setOutputFile("bbbbb");
    ArrayList<JobScheduleParam> jobParams = new ArrayList<>();
    jobParams.add(new JobScheduleParam("param1", "aString"));
    jobParams.add(new JobScheduleParam("param2", 1));
    jobParams.add(new JobScheduleParam("param3", true));
    jobParams.add(new JobScheduleParam("param4", new Date()));
    jobRequest.setJobParameters(jobParams);
    return jobRequest;
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) ComplexJobTriggerProxy(org.pentaho.platform.web.http.api.resources.ComplexJobTriggerProxy) ArrayList(java.util.ArrayList) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Date(java.util.Date)

Example 7 with JobScheduleRequest

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

the class SchedulerServiceTest method testCreateJobException.

@Test
public void testCreateJobException() throws Exception {
    List<JobScheduleParam> jobParameters = new ArrayList<>();
    JobScheduleParam jobScheduleParam1 = mock(JobScheduleParam.class);
    doReturn("name1").when(jobScheduleParam1).getName();
    doReturn("value1").when(jobScheduleParam1).getValue();
    jobParameters.add(jobScheduleParam1);
    Job job = mock(Job.class);
    JobScheduleRequest scheduleRequest = mock(JobScheduleRequest.class);
    doReturn("className").when(scheduleRequest).getActionClass();
    doReturn("jobName").when(scheduleRequest).getJobName();
    doReturn(jobParameters).when(scheduleRequest).getJobParameters();
    doNothing().when(scheduleRequest).setJobName(anyString());
    doReturn(true).when(schedulerService).isPdiFile(any(RepositoryFile.class));
    SchedulerOutputPathResolver schedulerOutputPathResolver = mock(SchedulerOutputPathResolver.class);
    doReturn("outputFile").when(schedulerOutputPathResolver).resolveOutputFilePath();
    SimpleJobTrigger simpleJobTrigger = mock(SimpleJobTrigger.class);
    ComplexJobTriggerProxy complexJobTriggerProxy = mock(ComplexJobTriggerProxy.class);
    CronJobTrigger cronJobTrigger = mock(CronJobTrigger.class);
    RepositoryFile repositoryFile = mock(RepositoryFile.class);
    doReturn("file.ext").when(repositoryFile).getName();
    Map<String, Serializable> metadata = mock(Map.class);
    doReturn(metadata).when(schedulerService.repository).getFileMetadata(anyString());
    doReturn(true).when(metadata).containsKey(RepositoryFile.SCHEDULABLE_KEY);
    doReturn("True").when(metadata).get(RepositoryFile.SCHEDULABLE_KEY);
    doReturn(simpleJobTrigger).when(scheduleRequest).getSimpleJobTrigger();
    doReturn(complexJobTriggerProxy).when(scheduleRequest).getComplexJobTrigger();
    doReturn(cronJobTrigger).when(scheduleRequest).getCronJobTrigger();
    doReturn(false).when(schedulerService.policy).isAllowed(SchedulerAction.NAME);
    doReturn("file.ext").when(scheduleRequest).getInputFile();
    doReturn(repositoryFile).when(schedulerService.repository).getFile(anyString());
    doReturn("ext.backgroundExecution").when(schedulerService).resolveActionId(anyString());
    doReturn(true).when(schedulerService).getAutoCreateUniqueFilename(any(JobScheduleRequest.class));
    doReturn(job).when(schedulerService.scheduler).createJob(anyString(), anyString(), any(Map.class), any(IJobTrigger.class), any(IBackgroundExecutionStreamProvider.class));
    doReturn(Class.class).when(schedulerService).getAction(anyString());
    doReturn(job).when(schedulerService.scheduler).createJob(anyString(), any(Class.class), any(Map.class), any(IJobTrigger.class));
    // Test 1
    try {
        schedulerService.createJob(scheduleRequest);
        fail();
    } catch (SecurityException e) {
    // Should catch it
    }
    // Test 2
    doReturn(true).when(schedulerService.policy).isAllowed(SchedulerAction.NAME);
    doReturn("false").when(metadata).get(RepositoryFile.SCHEDULABLE_KEY);
    try {
        schedulerService.createJob(scheduleRequest);
        fail();
    } catch (IllegalAccessException e) {
    // Should catch it
    }
    // Test 3
    doReturn("").when(scheduleRequest).getInputFile();
    doThrow(new ClassNotFoundException()).when(schedulerService).getAction(anyString());
    try {
        schedulerService.createJob(scheduleRequest);
        fail();
    } catch (RuntimeException e) {
    // Should catch it
    }
    verify(scheduleRequest, times(7)).getSimpleJobTrigger();
    verify(scheduleRequest, times(3)).getInputFile();
    verify(schedulerService.policy, times(3)).isAllowed(SchedulerAction.NAME);
    verify(schedulerService.repository, times(1)).getFile(anyString());
    verify(scheduleRequest, times(1)).getJobName();
    verify(scheduleRequest, times(2)).setJobName(anyString());
    verify(scheduleRequest, times(7)).getActionClass();
    verify(schedulerService.repository, times(1)).getFileMetadata(anyString());
    verify(schedulerService, times(1)).isPdiFile(any(RepositoryFile.class));
    verify(schedulerService, times(1)).handlePDIScheduling(any(RepositoryFile.class), any(HashMap.class), any(HashMap.class));
    verify(scheduleRequest, times(7)).getActionClass();
    verify(schedulerService).getAction(anyString());
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) SchedulerOutputPathResolver(org.pentaho.platform.web.http.api.resources.SchedulerOutputPathResolver) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) ComplexJobTriggerProxy(org.pentaho.platform.web.http.api.resources.ComplexJobTriggerProxy) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Map(java.util.Map) HashMap(java.util.HashMap) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 8 with JobScheduleRequest

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

the class SchedulerServiceTest method testAddBlockout.

@Test
public void testAddBlockout() throws Exception {
    JobScheduleRequest jobScheduleRequest = mock(JobScheduleRequest.class);
    Job jobMock = mock(Job.class);
    JobScheduleParam jobScheduleParamMock1 = mock(JobScheduleParam.class);
    JobScheduleParam jobScheduleParamMock2 = mock(JobScheduleParam.class);
    List<JobScheduleParam> jobScheduleParams = new ArrayList<>();
    doReturn(true).when(schedulerService).canAdminister();
    doNothing().when(jobScheduleRequest).setActionClass(anyString());
    doReturn(jobScheduleParams).when(jobScheduleRequest).getJobParameters();
    doReturn(jobScheduleParamMock1).when(schedulerService).getJobScheduleParam(anyString(), anyString());
    doReturn(jobScheduleParamMock2).when(schedulerService).getJobScheduleParam(anyString(), anyLong());
    doNothing().when(schedulerService).updateStartDateForTimeZone(jobScheduleRequest);
    doReturn(jobMock).when(schedulerService).createJob(any(JobScheduleRequest.class));
    Job job = schedulerService.addBlockout(jobScheduleRequest);
    assertNotNull(job);
    assertEquals(2, jobScheduleParams.size());
    verify(schedulerService).canAdminister();
    verify(jobScheduleRequest).setActionClass(anyString());
    verify(jobScheduleRequest, times(2)).getJobParameters();
    verify(schedulerService).createJob(any(JobScheduleRequest.class));
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 9 with JobScheduleRequest

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

the class SchedulerServiceTest method testCreateJob.

@Test
public void testCreateJob() throws Exception {
    List<JobScheduleParam> jobParameters = new ArrayList<>();
    JobScheduleParam jobScheduleParam1 = mock(JobScheduleParam.class);
    doReturn("name1").when(jobScheduleParam1).getName();
    doReturn("value1").when(jobScheduleParam1).getValue();
    jobParameters.add(jobScheduleParam1);
    Job job = mock(Job.class);
    JobScheduleRequest scheduleRequest = mock(JobScheduleRequest.class);
    doReturn("className").when(scheduleRequest).getActionClass();
    doReturn("jobName").when(scheduleRequest).getJobName();
    doReturn(jobParameters).when(scheduleRequest).getJobParameters();
    doNothing().when(scheduleRequest).setJobName(anyString());
    doReturn("timezone").when(scheduleRequest).getTimeZone();
    doNothing().when(schedulerService).updateStartDateForTimeZone(scheduleRequest);
    doReturn(true).when(schedulerService).isPdiFile(any(RepositoryFile.class));
    SchedulerOutputPathResolver schedulerOutputPathResolver = mock(SchedulerOutputPathResolver.class);
    doReturn("outputFile").when(schedulerOutputPathResolver).resolveOutputFilePath();
    SimpleJobTrigger simpleJobTrigger = mock(SimpleJobTrigger.class);
    ComplexJobTriggerProxy complexJobTriggerProxy = mock(ComplexJobTriggerProxy.class);
    CronJobTrigger cronJobTrigger = mock(CronJobTrigger.class);
    RepositoryFile repositoryFile = mock(RepositoryFile.class);
    doReturn("file.ext").when(repositoryFile).getName();
    Map<String, Serializable> metadata = mock(Map.class);
    doReturn(metadata).when(schedulerService.repository).getFileMetadata(anyString());
    doReturn(true).when(metadata).containsKey(RepositoryFile.SCHEDULABLE_KEY);
    doReturn("true").when(metadata).get(RepositoryFile.SCHEDULABLE_KEY);
    doReturn(simpleJobTrigger).when(scheduleRequest).getSimpleJobTrigger();
    doReturn(complexJobTriggerProxy).when(scheduleRequest).getComplexJobTrigger();
    doReturn(cronJobTrigger).when(scheduleRequest).getCronJobTrigger();
    doReturn(true).when(schedulerService.policy).isAllowed(SchedulerAction.NAME);
    doReturn("file.ext").when(scheduleRequest).getInputFile();
    doReturn(repositoryFile).when(schedulerService.repository).getFile(anyString());
    doReturn("ext.backgroundExecution").when(schedulerService).resolveActionId(anyString());
    doReturn(true).when(schedulerService).getAutoCreateUniqueFilename(any(JobScheduleRequest.class));
    doReturn(job).when(schedulerService.scheduler).createJob(anyString(), anyString(), any(Map.class), any(IJobTrigger.class), any(IBackgroundExecutionStreamProvider.class));
    doReturn(Class.class).when(schedulerService).getAction(anyString());
    doReturn(job).when(schedulerService.scheduler).createJob(anyString(), any(Class.class), any(Map.class), any(IJobTrigger.class));
    // Test 1
    schedulerService.createJob(scheduleRequest);
    // Test 2
    doReturn("").when(scheduleRequest).getJobName();
    schedulerService.createJob(scheduleRequest);
    // Test 3
    doReturn("").when(scheduleRequest).getInputFile();
    doReturn("").when(scheduleRequest).getActionClass();
    schedulerService.createJob(scheduleRequest);
    verify(scheduleRequest, times(15)).getSimpleJobTrigger();
    verify(scheduleRequest, times(11)).getInputFile();
    verify(schedulerService.policy, times(3)).isAllowed(SchedulerAction.NAME);
    verify(schedulerService.repository, times(2)).getFile(anyString());
    verify(scheduleRequest, times(9)).getJobName();
    verify(scheduleRequest, times(3)).setJobName(anyString());
    verify(scheduleRequest, times(5)).getActionClass();
    verify(schedulerService.repository, times(2)).getFileMetadata(anyString());
    verify(schedulerService, times(3)).isPdiFile(any(RepositoryFile.class));
    verify(schedulerService, times(3)).handlePDIScheduling(any(RepositoryFile.class), any(HashMap.class), any(HashMap.class));
    verify(schedulerService, times(2)).getSchedulerOutputPathResolver(any(JobScheduleRequest.class));
    // verify( schedulerService, times( 2 ) ).resolveActionId( anyString() );
    verify(scheduleRequest, times(5)).getActionClass();
    verify(schedulerService).getAction(anyString());
    verify(schedulerService, times(3)).updateStartDateForTimeZone(scheduleRequest);
    verify(schedulerService.scheduler).createJob(anyString(), any(Class.class), any(Map.class), any(IJobTrigger.class));
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) SchedulerOutputPathResolver(org.pentaho.platform.web.http.api.resources.SchedulerOutputPathResolver) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) ComplexJobTriggerProxy(org.pentaho.platform.web.http.api.resources.ComplexJobTriggerProxy) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Map(java.util.Map) HashMap(java.util.HashMap) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 10 with JobScheduleRequest

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

the class SolutionImportHandlerIT method testImportSchedules.

@Test
@SuppressWarnings("unchecked")
public void testImportSchedules() throws PlatformImportException, SchedulerException {
    SolutionImportHandler importHandler = new SolutionImportHandler(Collections.emptyList());
    importHandler = spy(importHandler);
    List<JobScheduleRequest> requests = new ArrayList<JobScheduleRequest>(4);
    requests.add(createJobScheduleRequest("NORMAL", JobState.NORMAL));
    requests.add(createJobScheduleRequest("PAUSED", JobState.PAUSED));
    requests.add(createJobScheduleRequest("PAUSED", JobState.COMPLETE));
    requests.add(createJobScheduleRequest("PAUSED", JobState.ERROR));
    doReturn(new ArrayList<Job>()).when(importHandler).getAllJobs(any());
    importHandler.importSchedules(requests);
    List<Job> jobs = scheduler.getJobs(new IJobFilter() {

        @Override
        public boolean accept(Job job) {
            return true;
        }
    });
    assertEquals(4, jobs.size());
    for (Iterator<?> iterator = jobs.iterator(); iterator.hasNext(); ) {
        Job job = (Job) iterator.next();
        assertEquals(job.getJobName(), job.getState().toString());
    }
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) ArrayList(java.util.ArrayList) 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