Search in sources :

Example 11 with IJobTrigger

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

the class BlockoutManagerUtil method willFire.

public static boolean willFire(IJobTrigger jobTrigger, List<IJobTrigger> blockOutTriggers, IScheduler scheduler) {
    // Short return as to avoid having to calculate fire times
    if (blockOutTriggers.isEmpty()) {
        return true;
    }
    List<Date> fireTimes = getFireTimes(jobTrigger, scheduler);
    for (IJobTrigger blockOutJobTrigger : blockOutTriggers) {
        // We must verify further if the schedule is blocked completely or if it will fire
        if (willBlockSchedule(jobTrigger, blockOutJobTrigger, scheduler)) {
            boolean isBlockoutComplex = isComplexTrigger(blockOutJobTrigger);
            // If recurrence intervals are the same, it will never fire
            if (!isBlockoutComplex && !isComplexTrigger(jobTrigger) && getRecurrenceInterval(blockOutJobTrigger) == getRecurrenceInterval(jobTrigger)) {
                return false;
            }
            List<Date> blockoutFireTimes = null;
            if (isBlockoutComplex) {
                blockoutFireTimes = getFireTimes(blockOutJobTrigger, scheduler);
            }
            // Loop through fire times and verify whether block out is blocking the schedule completely
            boolean scheduleCompletelyBlocked = true;
            for (Date fireTime : fireTimes) {
                scheduleCompletelyBlocked = isBlockoutComplex ? willComplexBlockOutTriggerBlockDate(blockOutJobTrigger, blockoutFireTimes, fireTime) : willBlockDate(blockOutJobTrigger, fireTime, scheduler);
                if (!scheduleCompletelyBlocked) {
                    break;
                }
            }
            // Return false if after n iterations
            if (scheduleCompletelyBlocked) {
                return false;
            }
        }
    }
    return true;
}
Also used : IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Date(java.util.Date)

Example 12 with IJobTrigger

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

the class PentahoBlockoutManager method willBlockSchedules.

@Override
public List<IJobTrigger> willBlockSchedules(IJobTrigger testBlockOutJobTrigger) {
    List<IJobTrigger> blockedSchedules = new ArrayList<IJobTrigger>();
    List<Job> scheduledJobs = new ArrayList<Job>();
    try {
        scheduledJobs = this.scheduler.getJobs(new IJobFilter() {

            @Override
            public boolean accept(Job job) {
                return !BLOCK_OUT_JOB_NAME.equals(job.getJobName());
            }
        });
    } catch (SchedulerException e) {
        throw new RuntimeException(e);
    }
    // Loop over trigger group names
    for (Job scheduledJob : scheduledJobs) {
        // Add schedule to list if block out conflicts at all
        if (BlockoutManagerUtil.willBlockSchedule(scheduledJob.getJobTrigger(), testBlockOutJobTrigger, this.scheduler)) {
            blockedSchedules.add(scheduledJob.getJobTrigger());
        }
    }
    return blockedSchedules;
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job)

Example 13 with IJobTrigger

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

the class SchedulerService method createJob.

public Job createJob(JobScheduleRequest scheduleRequest) throws IOException, SchedulerException, IllegalAccessException {
    // Used to determine if created by a RunInBackgroundCommand
    boolean runInBackground = scheduleRequest.getSimpleJobTrigger() == null && scheduleRequest.getComplexJobTrigger() == null && scheduleRequest.getCronJobTrigger() == null;
    if (!runInBackground && !getPolicy().isAllowed(SchedulerAction.NAME)) {
        throw new SecurityException();
    }
    boolean hasInputFile = !StringUtils.isEmpty(scheduleRequest.getInputFile());
    RepositoryFile file = null;
    if (hasInputFile) {
        try {
            file = getRepository().getFile(scheduleRequest.getInputFile());
        } catch (UnifiedRepositoryException ure) {
            hasInputFile = false;
            logger.warn(ure.getMessage(), ure);
        }
    }
    // if we have an inputfile, generate job name based on that if the name is not passed in
    if (hasInputFile && StringUtils.isEmpty(scheduleRequest.getJobName())) {
        // $NON-NLS-1$
        scheduleRequest.setJobName(file.getName().substring(0, file.getName().lastIndexOf(".")));
    } else if (!StringUtils.isEmpty(scheduleRequest.getActionClass())) {
        String actionClass = scheduleRequest.getActionClass().substring(scheduleRequest.getActionClass().lastIndexOf(".") + 1);
        // $NON-NLS-1$
        scheduleRequest.setJobName(actionClass);
    } else if (!hasInputFile && StringUtils.isEmpty(scheduleRequest.getJobName())) {
        // just make up a name
        // $NON-NLS-1$
        scheduleRequest.setJobName("" + System.currentTimeMillis());
    }
    if (hasInputFile) {
        if (file == null) {
            logger.error("Cannot find input source file " + scheduleRequest.getInputFile() + " Aborting schedule...");
            throw new SchedulerException(new ServiceException("Cannot find input source file " + scheduleRequest.getInputFile()));
        }
        Map<String, Serializable> metadata = getRepository().getFileMetadata(file.getId());
        if (metadata.containsKey(RepositoryFile.SCHEDULABLE_KEY)) {
            boolean schedulable = BooleanUtils.toBoolean((String) metadata.get(RepositoryFile.SCHEDULABLE_KEY));
            if (!schedulable) {
                throw new IllegalAccessException();
            }
        }
    }
    if (scheduleRequest.getTimeZone() != null) {
        updateStartDateForTimeZone(scheduleRequest);
    }
    Job job = null;
    IJobTrigger jobTrigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
    HashMap<String, Serializable> parameterMap = new HashMap<>();
    for (JobScheduleParam param : scheduleRequest.getJobParameters()) {
        parameterMap.put(param.getName(), param.getValue());
    }
    if (isPdiFile(file)) {
        parameterMap = handlePDIScheduling(file, parameterMap, scheduleRequest.getPdiParameters());
    }
    parameterMap.put(LocaleHelper.USER_LOCALE_PARAM, LocaleHelper.getLocale());
    if (scheduleRequest.getUseWorkerNodes() != null && !scheduleRequest.getUseWorkerNodes().trim().isEmpty()) {
        parameterMap.put("useWorkerNodes", scheduleRequest.getUseWorkerNodes().trim());
    }
    if (hasInputFile) {
        SchedulerOutputPathResolver outputPathResolver = getSchedulerOutputPathResolver(scheduleRequest);
        String outputFile = outputPathResolver.resolveOutputFilePath();
        String actionId = SchedulerResourceUtil.resolveActionId(scheduleRequest.getInputFile());
        final String inputFile = scheduleRequest.getInputFile();
        parameterMap.put(ActionUtil.QUARTZ_STREAMPROVIDER_INPUT_FILE, inputFile);
        job = getScheduler().createJob(scheduleRequest.getJobName(), actionId, parameterMap, jobTrigger, new RepositoryFileStreamProvider(inputFile, outputFile, getAutoCreateUniqueFilename(scheduleRequest), getAppendDateFormat(scheduleRequest)));
    } else {
        // need to locate actions from plugins if done this way too (but for now, we're just on main)
        String actionClass = scheduleRequest.getActionClass();
        try {
            @SuppressWarnings("unchecked") Class<IAction> iaction = getAction(actionClass);
            job = getScheduler().createJob(scheduleRequest.getJobName(), iaction, parameterMap, jobTrigger);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    return job;
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) SchedulerOutputPathResolver(org.pentaho.platform.web.http.api.resources.SchedulerOutputPathResolver) ServiceException(org.pentaho.platform.api.engine.ServiceException) RepositoryFileStreamProvider(org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Job(org.pentaho.platform.api.scheduler2.Job)

Example 14 with IJobTrigger

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

the class SchedulerService method getBlockStatus.

public BlockStatusProxy getBlockStatus(JobScheduleRequest jobScheduleRequest) throws SchedulerException {
    updateStartDateForTimeZone(jobScheduleRequest);
    IJobTrigger trigger = convertScheduleRequestToJobTrigger(jobScheduleRequest);
    Boolean totallyBlocked = false;
    Boolean partiallyBlocked = getBlockoutManager().isPartiallyBlocked(trigger);
    if (partiallyBlocked) {
        totallyBlocked = !getBlockoutManager().willFire(trigger);
    }
    return getBlockStatusProxy(totallyBlocked, partiallyBlocked);
}
Also used : IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger)

Example 15 with IJobTrigger

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

the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_years.

@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_years() throws Exception {
    complex.setYears(new int[] { 2016, 2020 });
    when(scheduleRequest.getComplexJobTrigger()).thenReturn(complex);
    IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
    assertNotNull(trigger);
    assertTrue(trigger instanceof ComplexJobTrigger);
    ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
    List<ITimeRecurrence> recurrences = trig.getYearlyRecurrences().getRecurrences();
    assertEquals(2, recurrences.size());
    RecurrenceList rec = (RecurrenceList) recurrences.get(0);
    assertEquals(2016, rec.getValues().get(0).intValue());
    rec = (RecurrenceList) recurrences.get(1);
    assertEquals(2020, rec.getValues().get(0).intValue());
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Aggregations

IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)28 Test (org.junit.Test)18 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)13 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)12 Job (org.pentaho.platform.api.scheduler2.Job)11 Date (java.util.Date)8 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)7 ITimeRecurrence (org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence)6 Serializable (java.io.Serializable)4 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 RecurrenceList (org.pentaho.platform.scheduler2.recur.RecurrenceList)4 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 QualifiedDayOfWeek (org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek)3 Trigger (org.quartz.Trigger)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IAction (org.pentaho.platform.api.action.IAction)2 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)2 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)2