Search in sources :

Example 16 with IScheduler

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

the class DefaultSchedulerService method getJobs.

/**
 * {@inheritDoc}
 */
public Job[] getJobs() throws SchedulerException {
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    IPentahoSession session = PentahoSessionHolder.getSession();
    String principalName = session.getName();
    Boolean canAdminister = PentahoSystem.get(IAuthorizationPolicy.class).isAllowed(ADMIN_PERM);
    return scheduler.getJobs(job -> {
        if (canAdminister) {
            return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals(job.getJobName());
        }
        return principalName.equals(job.getUserName());
    }).toArray(new Job[0]);
}
Also used : WebService(javax.jws.WebService) IBlockoutManager(org.pentaho.platform.api.scheduler2.IBlockoutManager) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) HashMap(java.util.HashMap) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) PentahoSessionHolder(org.pentaho.platform.engine.core.system.PentahoSessionHolder) Serializable(java.io.Serializable) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Map(java.util.Map) Log(org.apache.commons.logging.Log) Job(org.pentaho.platform.api.scheduler2.Job) LogFactory(org.apache.commons.logging.LogFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Example 17 with IScheduler

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

the class DefaultSchedulerService method pause.

/**
 * {@inheritDoc}
 */
public void pause() throws SchedulerException {
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    scheduler.pause();
}
Also used : IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Example 18 with IScheduler

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

the class DefaultSchedulerService method pauseJob.

/**
 * {@inheritDoc}
 */
public void pauseJob(String jobId) throws SchedulerException {
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    scheduler.pauseJob(jobId);
}
Also used : IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Example 19 with IScheduler

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

the class DefaultSchedulerService method createJob.

private String createJob(String jobName, Map<String, ParamValue> jobParams, JobTrigger trigger) throws SchedulerException {
    // $NON-NLS-1$
    logger.debug("Creating job with schedule " + trigger.toString());
    Job job = null;
    try {
        // $NON-NLS-1$
        IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
        Map<String, Serializable> properJobParams = toProperMap(jobParams);
        scheduler.validateJobParams(properJobParams);
        job = scheduler.createJob(jobName, getDefaultActionId(), properJobParams, trigger);
    } catch (SchedulerException e) {
        // temporary error logging.. this needs to become an aspect
        logger.error(e.getMessage(), e);
        throw e;
    }
    return job.getJobId();
}
Also used : Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Example 20 with IScheduler

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

the class SchedulerResourceUtil method convertScheduleRequestToJobTrigger.

public static IJobTrigger convertScheduleRequestToJobTrigger(JobScheduleRequest scheduleRequest, IScheduler scheduler) throws SchedulerException, UnifiedRepositoryException {
    // Used to determine if created by a RunInBackgroundCommand
    boolean runInBackground = scheduleRequest.getSimpleJobTrigger() == null && scheduleRequest.getComplexJobTrigger() == null && scheduleRequest.getCronJobTrigger() == null;
    // add 10 seconds to the RIB to ensure execution (see PPP-3264)
    IJobTrigger jobTrigger = runInBackground ? new SimpleJobTrigger(new Date(System.currentTimeMillis() + 10000), null, 0, 0) : scheduleRequest.getSimpleJobTrigger();
    if (scheduleRequest.getSimpleJobTrigger() != null) {
        SimpleJobTrigger simpleJobTrigger = scheduleRequest.getSimpleJobTrigger();
        if (simpleJobTrigger.getStartTime() == null) {
            simpleJobTrigger.setStartTime(new Date());
        }
        jobTrigger = simpleJobTrigger;
    } else if (scheduleRequest.getComplexJobTrigger() != null) {
        ComplexJobTriggerProxy proxyTrigger = scheduleRequest.getComplexJobTrigger();
        ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
        complexJobTrigger.setStartTime(proxyTrigger.getStartTime());
        complexJobTrigger.setEndTime(proxyTrigger.getEndTime());
        complexJobTrigger.setDuration(scheduleRequest.getDuration());
        if (proxyTrigger.getDaysOfWeek().length > 0) {
            if (proxyTrigger.getWeeksOfMonth().length > 0) {
                for (int dayOfWeek : proxyTrigger.getDaysOfWeek()) {
                    for (int weekOfMonth : proxyTrigger.getWeeksOfMonth()) {
                        QualifiedDayOfWeek qualifiedDayOfWeek = new QualifiedDayOfWeek();
                        qualifiedDayOfWeek.setDayOfWeek(DayOfWeek.values()[dayOfWeek]);
                        if (weekOfMonth == JobScheduleRequest.LAST_WEEK_OF_MONTH) {
                            qualifiedDayOfWeek.setQualifier(DayOfWeekQualifier.LAST);
                        } else {
                            qualifiedDayOfWeek.setQualifier(DayOfWeekQualifier.values()[weekOfMonth]);
                        }
                        complexJobTrigger.addDayOfWeekRecurrence(qualifiedDayOfWeek);
                    }
                }
            } else {
                for (int dayOfWeek : proxyTrigger.getDaysOfWeek()) {
                    complexJobTrigger.addDayOfWeekRecurrence(dayOfWeek + 1);
                }
            }
        } else if (proxyTrigger.getDaysOfMonth().length > 0) {
            for (int dayOfMonth : proxyTrigger.getDaysOfMonth()) {
                complexJobTrigger.addDayOfMonthRecurrence(dayOfMonth);
            }
        }
        for (int month : proxyTrigger.getMonthsOfYear()) {
            complexJobTrigger.addMonthlyRecurrence(month + 1);
        }
        for (int year : proxyTrigger.getYears()) {
            complexJobTrigger.addYearlyRecurrence(year);
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(complexJobTrigger.getStartTime());
        complexJobTrigger.setHourlyRecurrence(calendar.get(Calendar.HOUR_OF_DAY));
        complexJobTrigger.setMinuteRecurrence(calendar.get(Calendar.MINUTE));
        complexJobTrigger.setUiPassParam(scheduleRequest.getComplexJobTrigger().getUiPassParam());
        jobTrigger = complexJobTrigger;
    } else if (scheduleRequest.getCronJobTrigger() != null) {
        if (scheduler instanceof QuartzScheduler) {
            String cronString = scheduleRequest.getCronJobTrigger().getCronString();
            // $NON-NLS-1$
            String delims = "[ ]+";
            String[] tokens = cronString.split(delims);
            if (tokens.length < 7) {
                cronString += " *";
            }
            ComplexJobTrigger complexJobTrigger = QuartzScheduler.createComplexTrigger(cronString);
            complexJobTrigger.setStartTime(scheduleRequest.getCronJobTrigger().getStartTime());
            complexJobTrigger.setEndTime(scheduleRequest.getCronJobTrigger().getEndTime());
            complexJobTrigger.setDuration(scheduleRequest.getCronJobTrigger().getDuration());
            complexJobTrigger.setUiPassParam(scheduleRequest.getCronJobTrigger().getUiPassParam());
            jobTrigger = complexJobTrigger;
        } else {
            throw new IllegalArgumentException();
        }
    }
    return jobTrigger;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Date(java.util.Date) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) QualifiedDayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger)

Aggregations

IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)14 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)8 Job (org.pentaho.platform.api.scheduler2.Job)7 Serializable (java.io.Serializable)6 Date (java.util.Date)6 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)5 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)5 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)4 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IBlockoutManager (org.pentaho.platform.api.scheduler2.IBlockoutManager)2 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)2 QuartzScheduler (org.pentaho.platform.scheduler2.quartz.QuartzScheduler)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Map (java.util.Map)1 WebService (javax.jws.WebService)1