Search in sources :

Example 41 with SchedulerException

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

the class SchedulerServiceTest method testPauseJobException.

@Test
public void testPauseJobException() throws SchedulerException {
    Job job = mock(Job.class);
    doReturn(job).when(schedulerService).getJob(anyString());
    doReturn(true).when(schedulerService).isScheduleAllowed();
    doThrow(new SchedulerException("pause-exception")).when(schedulerService.scheduler).pauseJob(anyString());
    try {
        schedulerService.pauseJob("job-id");
    } catch (SchedulerException e) {
        assertEquals("pause-exception", e.getMessage());
    }
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 42 with SchedulerException

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

Example 43 with SchedulerException

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

the class SolutionImportHandlerIT method init.

@Before
public void init() throws PlatformInitializationException, SchedulerException {
    MicroPlatform mp = new MicroPlatform();
    mp.define("IScheduler", TestQuartzScheduler.class);
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
    when(policy.isAllowed(anyString())).thenReturn(true);
    mp.defineInstance(IAuthorizationPolicy.class, policy);
    mp.start();
    scheduler = PentahoSystem.get(IScheduler.class);
    scheduler.start();
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) Before(org.junit.Before)

Example 44 with SchedulerException

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

the class SchedulerService method getJobInfo.

public Job getJobInfo(String jobId) throws SchedulerException {
    Job job = getJob(jobId);
    if (job == null) {
        return null;
    }
    if (canAdminister() || getSession().getName().equals(job.getUserName())) {
        for (String key : job.getJobParams().keySet()) {
            Serializable value = job.getJobParams().get(key);
            if (value != null && value.getClass() != null && value.getClass().isArray()) {
                String[] sa = (new String[0]).getClass().cast(value);
                ArrayList<String> list = new ArrayList<>();
                for (int i = 0; i < sa.length; i++) {
                    list.add(sa[i]);
                }
                job.getJobParams().put(key, list);
            }
        }
        return job;
    } else {
        throw new RuntimeException("Job not found or improper credentials for access");
    }
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job)

Example 45 with SchedulerException

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

the class SchedulerService method getContentCleanerJob.

public Job getContentCleanerJob() 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 = getPolicy().isAllowed(AdministerSecurityAction.NAME);
    List<Job> jobs = getScheduler().getJobs(getJobFilter(canAdminister, principalName));
    if (jobs.size() > 0) {
        return jobs.get(0);
    }
    return null;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Job(org.pentaho.platform.api.scheduler2.Job)

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