Search in sources :

Example 46 with SchedulerException

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

the class SchedulerService method triggerNow.

public Job triggerNow(String jobId) throws SchedulerException {
    Job job = getScheduler().getJob(jobId);
    if (getPolicy().isAllowed(SchedulerAction.NAME)) {
        getScheduler().triggerNow(jobId);
    } else {
        if (getSession().getName().equals(job.getUserName())) {
            getScheduler().triggerNow(jobId);
        }
    }
    // udpate job state
    job = getScheduler().getJob(jobId);
    return job;
}
Also used : Job(org.pentaho.platform.api.scheduler2.Job)

Example 47 with SchedulerException

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

the class SchedulerService method getJobs.

public List<Job> getJobs() throws SchedulerException {
    IPentahoSession session = getSession();
    // this authentication wasn't matching with the job user name,
    final String principalName = session.getName();
    // changed to get name via the current session
    final Boolean canAdminister = canAdminister(session);
    List<Job> jobs = getScheduler().getJobs(new IJobFilter() {

        @Override
        public boolean accept(Job job) {
            if (canAdminister) {
                return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals(job.getJobName());
            }
            return principalName.equals(job.getUserName());
        }
    });
    return jobs;
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Job(org.pentaho.platform.api.scheduler2.Job)

Example 48 with SchedulerException

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

the class PentahoPlatformExporterTest method testExportSchedules_SchedulereThrowsException.

@Test
public void testExportSchedules_SchedulereThrowsException() throws Exception {
    when(scheduler.getJobs(null)).thenThrow(new SchedulerException("bad"));
    exporterSpy.exportSchedules();
    verify(scheduler).getJobs(null);
    assertEquals(0, exporterSpy.getExportManifest().getScheduleList().size());
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Test(org.junit.Test)

Example 49 with SchedulerException

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

the class SchedulerResourceTest method testGetJobError.

@Test
public void testGetJobError() throws Exception {
    String jobId = "jobId";
    String asCronString = "asCronString";
    SchedulerException mockSchedulerException = mock(SchedulerException.class);
    doThrow(mockSchedulerException).when(schedulerResource.schedulerService).getJobInfo(jobId);
    try {
        schedulerResource.getJob(jobId, asCronString);
        fail();
    } catch (RuntimeException e) {
    // correct
    }
    verify(schedulerResource.schedulerService, times(1)).getJobInfo(jobId);
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Test(org.junit.Test)

Example 50 with SchedulerException

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

the class SchedulerResourceTest method testCreateJobError.

@Test
public void testCreateJobError() throws Exception {
    JobScheduleRequest mockRequest = mock(JobScheduleRequest.class);
    SchedulerException mockSchedulerException = mock(SchedulerException.class);
    Throwable mockSchedulerExceptionCause = mock(Throwable.class);
    doReturn(mockSchedulerExceptionCause).when(mockSchedulerException).getCause();
    String schedulerExceptionMessage = "schedulerExceptionMessage";
    doReturn(schedulerExceptionMessage).when(mockSchedulerExceptionCause).getMessage();
    Response mockSchedulerExceptionResponse = mock(Response.class);
    doReturn(mockSchedulerExceptionResponse).when(schedulerResource).buildServerErrorResponse(schedulerExceptionMessage);
    IOException mockIOException = mock(IOException.class);
    Throwable mockIOExceptionCause = mock(Throwable.class);
    doReturn(mockIOExceptionCause).when(mockIOException).getCause();
    String ioExceptionMessage = "ioExceptionMessage";
    doReturn(ioExceptionMessage).when(mockIOExceptionCause).getMessage();
    Response mockIOExceptionResponse = mock(Response.class);
    doReturn(mockIOExceptionResponse).when(schedulerResource).buildServerErrorResponse(ioExceptionMessage);
    Response mockUnauthorizedResponse = mock(Response.class);
    doReturn(mockUnauthorizedResponse).when(schedulerResource).buildStatusResponse(UNAUTHORIZED);
    Response mockForbiddenResponse = mock(Response.class);
    doReturn(mockForbiddenResponse).when(schedulerResource).buildStatusResponse(FORBIDDEN);
    // Test 1
    doThrow(mockSchedulerException).when(schedulerResource.schedulerService).createJob(mockRequest);
    Response testResponse = schedulerResource.createJob(mockRequest);
    assertEquals(mockSchedulerExceptionResponse, testResponse);
    // Test 2
    doThrow(mockIOException).when(schedulerResource.schedulerService).createJob(mockRequest);
    testResponse = schedulerResource.createJob(mockRequest);
    assertEquals(mockIOExceptionResponse, testResponse);
    // Test 3
    SecurityException mockSecurityException = mock(SecurityException.class);
    doThrow(mockSecurityException).when(schedulerResource.schedulerService).createJob(mockRequest);
    testResponse = schedulerResource.createJob(mockRequest);
    assertEquals(mockUnauthorizedResponse, testResponse);
    // Test 4
    IllegalAccessException mockIllegalAccessException = mock(IllegalAccessException.class);
    doThrow(mockIllegalAccessException).when(schedulerResource.schedulerService).createJob(mockRequest);
    testResponse = schedulerResource.createJob(mockRequest);
    assertEquals(mockForbiddenResponse, testResponse);
    verify(mockSchedulerException, times(1)).getCause();
    verify(mockSchedulerExceptionCause, times(1)).getMessage();
    verify(schedulerResource, times(1)).buildServerErrorResponse(schedulerExceptionMessage);
    verify(mockIOException, times(1)).getCause();
    verify(mockIOExceptionCause, times(1)).getMessage();
    verify(schedulerResource, times(1)).buildServerErrorResponse(ioExceptionMessage);
    verify(schedulerResource, times(1)).buildStatusResponse(UNAUTHORIZED);
    verify(schedulerResource, times(1)).buildStatusResponse(FORBIDDEN);
    verify(schedulerResource.schedulerService, times(4)).createJob(mockRequest);
}
Also used : Response(javax.ws.rs.core.Response) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)51 Test (org.junit.Test)49 Job (org.pentaho.platform.api.scheduler2.Job)43 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)23 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)16 Serializable (java.io.Serializable)15 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)11 Date (java.util.Date)10 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)9 Scheduler (org.quartz.Scheduler)9 ArrayList (java.util.ArrayList)8 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)8 IOException (java.io.IOException)6 Calendar (java.util.Calendar)6 HashMap (java.util.HashMap)6 CronTrigger (org.quartz.CronTrigger)6 SimpleTrigger (org.quartz.SimpleTrigger)6 Trigger (org.quartz.Trigger)6 Response (javax.ws.rs.core.Response)5