private void runReadyJobs() { final Iterator<Job> readyJobsIter = readyJobs.iterator(); while (readyJobsIter.hasNext() && !stopping) { final Job job = readyJobsIter.next(); try { transactional.execute(context -> runReadyJob(job)); } catch (TransactionFailureException e) { LOG.warn("Failed to run program {} in schedule {}. Skip running this program.", job.getSchedule().getProgramId(), job.getSchedule().getName(), e); } readyJobsIter.remove(); } }
private void runReadyJobs() { final Iterator<Job> readyJobsIter = readyJobs.iterator(); while (readyJobsIter.hasNext() && !stopping) { final Job job = readyJobsIter.next(); try { transactional.execute(context -> runReadyJob(job)); } catch (TransactionFailureException e) { LOG.warn("Failed to run program {} in schedule {}. Skip running this program.", job.getSchedule().getProgramId(), job.getSchedule().getName(), e); } readyJobsIter.remove(); } }
/** * Get the given schedule * * @return the schedule * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to access the schedule program * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public ProgramSchedule get(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); AuthorizationUtil.ensureAccess(schedule.getProgramId(), authorizationEnforcer, authenticationContext.getPrincipal()); return schedule; }
/** * Get the given schedule * * @return the schedule * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to access the schedule program * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public ProgramSchedule get(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); AuthorizationUtil.ensureAccess(schedule.getProgramId(), authorizationEnforcer, authenticationContext.getPrincipal()); return schedule; }
public void launch(Job job) throws Exception { ProgramSchedule schedule = job.getSchedule(); ProgramId programId = schedule.getProgramId(); Map<String, String> userArgs = Maps.newHashMap(); userArgs.putAll(schedule.getProperties()); userArgs.putAll(propertiesResolver.getUserProperties(Id.Program.fromEntityId(programId))); Map<String, String> systemArgs = Maps.newHashMap(); systemArgs.putAll(propertiesResolver.getSystemProperties(Id.Program.fromEntityId(programId))); // Let the triggers update the arguments first before setting the triggering schedule info ((SatisfiableTrigger) job.getSchedule().getTrigger()).updateLaunchArguments(job.getSchedule(), job.getNotifications(), userArgs, systemArgs); TriggeringScheduleInfo triggeringScheduleInfo = getTriggeringScheduleInfo(job); systemArgs.put(ProgramOptionConstants.TRIGGERING_SCHEDULE_INFO, GSON.toJson(triggeringScheduleInfo)); execute(programId, systemArgs, userArgs); LOG.info("Successfully started program {} in schedule {}.", schedule.getProgramId(), schedule.getName()); }
public void launch(Job job) throws Exception { ProgramSchedule schedule = job.getSchedule(); ProgramId programId = schedule.getProgramId(); Map<String, String> userArgs = Maps.newHashMap(); userArgs.putAll(schedule.getProperties()); userArgs.putAll(propertiesResolver.getUserProperties(Id.Program.fromEntityId(programId))); Map<String, String> systemArgs = Maps.newHashMap(); systemArgs.putAll(propertiesResolver.getSystemProperties(Id.Program.fromEntityId(programId))); // Let the triggers update the arguments first before setting the triggering schedule info ((SatisfiableTrigger) job.getSchedule().getTrigger()).updateLaunchArguments(job.getSchedule(), job.getNotifications(), userArgs, systemArgs); TriggeringScheduleInfo triggeringScheduleInfo = getTriggeringScheduleInfo(job); systemArgs.put(ProgramOptionConstants.TRIGGERING_SCHEDULE_INFO, GSON.toJson(triggeringScheduleInfo)); execute(programId, systemArgs, userArgs); LOG.info("Successfully started program {} in schedule {}.", schedule.getProgramId(), schedule.getName()); }
/** * Retrieve all schedule records for a given program. * * @param programId the program for which to list the schedule records. * @return a list of schedule records for the program; never null */ public List<ProgramScheduleRecord> listScheduleRecords(ProgramId programId) { byte[] prefix = keyPrefixForApplicationScan(programId.getParent()); return listSchedulesRecordsWithPrefix(prefix, schedule -> programId.equals(schedule.getProgramId())); }
/** * Retrieve all schedules for a given program. * * @param programId the program for which to list the schedules. * @return a list of schedules for the program; never null */ public List<ProgramSchedule> listSchedules(ProgramId programId) { byte[] prefix = keyPrefixForApplicationScan(programId.getParent()); return listSchedulesWithPrefix(prefix, schedule -> programId.equals(schedule.getProgramId())); }
/** * Retrieve all schedule records for a given program. * * @param programId the program for which to list the schedule records. * @return a list of schedule records for the program; never null */ public List<ProgramScheduleRecord> listScheduleRecords(ProgramId programId) { byte[] prefix = keyPrefixForApplicationScan(programId.getParent()); return listSchedulesRecordsWithPrefix(prefix, schedule -> programId.equals(schedule.getProgramId())); }
/** * Suspend the given schedule * * @param scheduleId the schedule to suspend * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to suspend the schedule * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public void suspend(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); authorizationEnforcer.enforce(schedule.getProgramId(), authenticationContext.getPrincipal(), Action.EXECUTE); scheduler.disableSchedule(scheduleId); }
/** * Resume the given schedule * * @param scheduleId the schedule to suspend * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to suspend the schedule * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public void resume(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); authorizationEnforcer.enforce(schedule.getProgramId(), authenticationContext.getPrincipal(), Action.EXECUTE); scheduler.enableSchedule(scheduleId); }
/** * Retrieve all schedules for a given program. * * @param programId the program for which to list the schedules. * @return a list of schedules for the program; never null */ public List<ProgramSchedule> listSchedules(ProgramId programId) { byte[] prefix = keyPrefixForApplicationScan(programId.getParent()); return listSchedulesWithPrefix(prefix, schedule -> programId.equals(schedule.getProgramId())); }
/** * Suspend the given schedule * * @param scheduleId the schedule to suspend * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to suspend the schedule * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public void suspend(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); authorizationEnforcer.enforce(schedule.getProgramId(), authenticationContext.getPrincipal(), Action.EXECUTE); scheduler.disableSchedule(scheduleId); }
/** * Get the state of the given schedule * * @return the status of the given schedule * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to access the schedule program * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public ProgramScheduleStatus getStatus(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); AuthorizationUtil.ensureAccess(schedule.getProgramId(), authorizationEnforcer, authenticationContext.getPrincipal()); return scheduler.getScheduleStatus(scheduleId); }
/** * Resume the given schedule * * @param scheduleId the schedule to suspend * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to suspend the schedule * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public void resume(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); authorizationEnforcer.enforce(schedule.getProgramId(), authenticationContext.getPrincipal(), Action.EXECUTE); scheduler.enableSchedule(scheduleId); }
/** * Get the state of the given schedule * * @return the status of the given schedule * @throws NotFoundException if the schedule could not be found * @throws UnauthorizedException if the principal is not authorized to access the schedule program * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public ProgramScheduleStatus getStatus(ScheduleId scheduleId) throws Exception { ProgramSchedule schedule = scheduler.getSchedule(scheduleId); AuthorizationUtil.ensureAccess(schedule.getProgramId(), authorizationEnforcer, authenticationContext.getPrincipal()); return scheduler.getScheduleStatus(scheduleId); }
/** * Add the given schedule * * @param schedule the schedule to add * @throws AlreadyExistsException if one of the schedules already exists * @throws NotFoundException if there is a profile assigned to the schedule and it does not exist * @throws ProfileConflictException if there is a profile assigned to the schedule and it is diabled * @throws BadRequestException if the schedule is invalid * @throws UnauthorizedException if the principal is not authorized as an admin operations on the schedule app * @throws Exception if any other errors occurred while performing the authorization enforcement check */ public void add(ProgramSchedule schedule) throws Exception { authorizationEnforcer.enforce(schedule.getProgramId().getParent(), authenticationContext.getPrincipal(), Action.ADMIN); scheduler.addSchedule(schedule); }
public ScheduleDetail toScheduleDetail() { ScheduleProgramInfo programInfo = new ScheduleProgramInfo(schedule.getProgramId().getType().getSchedulableType(), schedule.getProgramId().getProgram()); ScheduleId scheduleId = schedule.getScheduleId(); return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), schedule.getDescription(), programInfo, schedule.getProperties(), schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis(), meta.getStatus().name()); } }
public void deleteProgramSchedule(ProgramSchedule schedule) throws NotFoundException, SchedulerException { try { Collection<TriggerKey> triggerKeys = getGroupedTriggerKeys(schedule); // Must assert all trigger keys exist before processing each trigger key assertTriggerKeysExist(triggerKeys); for (TriggerKey triggerKey : triggerKeys) { Trigger trigger = getTrigger(triggerKey, schedule.getProgramId(), schedule.getName()); scheduler.unscheduleJob(trigger.getKey()); JobKey jobKey = trigger.getJobKey(); if (scheduler.getTriggersOfJob(jobKey).isEmpty()) { scheduler.deleteJob(jobKey); } } } catch (org.quartz.SchedulerException e) { throw new SchedulerException(e); } }
public ScheduleDetail toScheduleDetail() { ScheduleProgramInfo programInfo = new ScheduleProgramInfo(schedule.getProgramId().getType().getSchedulableType(), schedule.getProgramId().getProgram()); ScheduleId scheduleId = schedule.getScheduleId(); return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), schedule.getDescription(), programInfo, schedule.getProperties(), schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis(), meta.getStatus().name()); } }