private boolean containsTimeTrigger(ProgramSchedule schedule) { // A composite trigger may contain a TimeTrigger return schedule.getTrigger() instanceof TimeTrigger || schedule.getTrigger() instanceof AbstractSatisfiableCompositeTrigger; }
private boolean containsTimeTrigger(ProgramSchedule schedule) { // A composite trigger may contain a TimeTrigger return schedule.getTrigger() instanceof TimeTrigger || schedule.getTrigger() instanceof AbstractSatisfiableCompositeTrigger; }
/** * This method extracts all trigger keys from a schedule. These are the keys for which we need to index * the schedule, so that we can do a reverse lookup for an event received. * <p> * For now, we do not support composite trigger, but in the future this is where the triggers need to be * extracted from composite triggers. Hence the return type of this method is a list. */ private static Set<String> extractTriggerKeys(ProgramSchedule schedule) { return ((SatisfiableTrigger) schedule.getTrigger()).getTriggerKeys(); }
/** * This method extracts all trigger keys from a schedule. These are the keys for which we need to index * the schedule, so that we can do a reverse lookup for an event received. * <p> * For now, we do not support composite trigger, but in the future this is where the triggers need to be * extracted from composite triggers. Hence the return type of this method is a list. */ private static Set<String> extractTriggerKeys(ProgramSchedule schedule) { return ((SatisfiableTrigger) schedule.getTrigger()).getTriggerKeys(); }
private boolean isTriggerSatisfied(ProgramSchedule schedule, List<Notification> notifications) { return ((SatisfiableTrigger) schedule.getTrigger()).isSatisfied(schedule, notifications); }
private boolean isTriggerSatisfied(ProgramSchedule schedule, List<Notification> notifications) { return ((SatisfiableTrigger) schedule.getTrigger()).isSatisfied(schedule, notifications); }
/** * Gets all the enabled time schedules in the given namespaces */ private List<ProgramSchedule> getTimeSchedules(Set<NamespaceId> namespaceIds) { return namespaceIds.stream() // get schedules from each namespace .flatMap(ns -> scheduler.listSchedules(ns, schedule -> // create a filter to get only time schedules Trigger.Type.TIME.equals(schedule.getTrigger().getType())) .stream()).collect(Collectors.toList()); }
/** * Gets all the enabled time schedules in the given namespaces */ private List<ProgramSchedule> getTimeSchedules(Set<NamespaceId> namespaceIds) { return namespaceIds.stream() // get schedules from each namespace .flatMap(ns -> scheduler.listSchedules(ns, schedule -> // create a filter to get only time schedules Trigger.Type.TIME.equals(schedule.getTrigger().getType())) .stream()).collect(Collectors.toList()); }
/** * Checks if the given notification satisfies this trigger. */ private boolean isSatisfied(ProgramSchedule schedule, Notification notification) { if (!notification.getNotificationType().equals(Notification.Type.TIME)) { return false; } String systemOverridesJson = notification.getProperties().get(ProgramOptionConstants.SYSTEM_OVERRIDES); if (systemOverridesJson == null) { return false; } Map<String, String> args = GSON.fromJson(systemOverridesJson, STRING_STRING_MAP); String cronExpr = args.get(ProgramOptionConstants.CRON_EXPRESSION); // See if the notification is from pre 4.3 system, which doesn't have the cron expression in the notification. // The checking is done by the fact that in pre 4.3 system, composite trigger is not supported, // hence if there is a time notification, it must be matching with this trigger. return getCronExpression().equals(cronExpr) || (cronExpr == null && schedule.getTrigger().getType() == Type.TIME); } }
/** * Checks if the given notification satisfies this trigger. */ private boolean isSatisfied(ProgramSchedule schedule, Notification notification) { if (!notification.getNotificationType().equals(Notification.Type.TIME)) { return false; } String systemOverridesJson = notification.getProperties().get(ProgramOptionConstants.SYSTEM_OVERRIDES); if (systemOverridesJson == null) { return false; } Map<String, String> args = GSON.fromJson(systemOverridesJson, STRING_STRING_MAP); String cronExpr = args.get(ProgramOptionConstants.CRON_EXPRESSION); // See if the notification is from pre 4.3 system, which doesn't have the cron expression in the notification. // The checking is done by the fact that in pre 4.3 system, composite trigger is not supported, // hence if there is a time notification, it must be matching with this trigger. return getCronExpression().equals(cronExpr) || (cronExpr == null && schedule.getTrigger().getType() == Type.TIME); } }
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()); }
schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis());
schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis());
ProgramId program = schedule.getProgramId(); SchedulableProgramType programType = program.getType().getSchedulableType(); co.cask.cdap.api.schedule.Trigger trigger = schedule.getTrigger(); Map<String, TriggerKey> cronTriggerKeyMap = new HashMap<>(); cronTriggerKeyMap.put(((TimeTrigger) schedule.getTrigger()).getCronExpression(), triggerKeyForName(triggerName)); return cronTriggerKeyMap;
ProgramId program = schedule.getProgramId(); SchedulableProgramType programType = program.getType().getSchedulableType(); co.cask.cdap.api.schedule.Trigger trigger = schedule.getTrigger(); Map<String, TriggerKey> cronTriggerKeyMap = new HashMap<>(); cronTriggerKeyMap.put(((TimeTrigger) schedule.getTrigger()).getCronExpression(), triggerKeyForName(triggerName)); return cronTriggerKeyMap;
private TriggeringScheduleInfo getTriggeringScheduleInfo(Job job) { TriggerInfoContext triggerInfoContext = new TriggerInfoContext(job, store); SatisfiableTrigger trigger = ((SatisfiableTrigger) job.getSchedule().getTrigger()); List<TriggerInfo> triggerInfo = trigger.getTriggerInfos(triggerInfoContext); ProgramSchedule schedule = job.getSchedule(); return new DefaultTriggeringScheduleInfo(schedule.getName(), schedule.getDescription(), triggerInfo, schedule.getProperties()); }
private TriggeringScheduleInfo getTriggeringScheduleInfo(Job job) { TriggerInfoContext triggerInfoContext = new TriggerInfoContext(job, store); SatisfiableTrigger trigger = ((SatisfiableTrigger) job.getSchedule().getTrigger()); List<TriggerInfo> triggerInfo = trigger.getTriggerInfos(triggerInfoContext); ProgramSchedule schedule = job.getSchedule(); return new DefaultTriggeringScheduleInfo(schedule.getName(), schedule.getDescription(), triggerInfo, schedule.getProperties()); }
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 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()); } }