use of co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule in project cdap by caskdata.
the class JobQueueDataset method addNotification.
@Override
public void addNotification(ProgramScheduleRecord record, Notification notification) {
boolean jobExists = false;
ProgramSchedule schedule = record.getSchedule();
// Only add notifications for enabled schedules
if (record.getMeta().getStatus() != ProgramScheduleStatus.SCHEDULED) {
return;
}
// for the same schedule.
if (schedule.getTrigger() instanceof AbstractSatisfiableCompositeTrigger) {
scheduleIds.add(getRowKeyPrefix(schedule.getScheduleId()));
}
try (CloseableIterator<Job> jobs = getJobsForSchedule(schedule.getScheduleId())) {
while (jobs.hasNext()) {
Job job = jobs.next();
if (job.getState() == Job.State.PENDING_TRIGGER) {
// ConstraintCheckerService
if (job.isToBeDeleted()) {
// ignore, it will be deleted by ConstraintCheckerService
continue;
}
long scheduleLastUpdated = record.getMeta().getLastUpdated();
if (job.getScheduleLastUpdatedTime() != scheduleLastUpdated) {
// schedule has changed: this job is obsolete
table.put(getRowKey(job.getJobKey().getScheduleId(), job.getJobKey().getCreationTime()), IS_OBSOLETE_COL, Bytes.toBytes(System.currentTimeMillis()));
} else if (System.currentTimeMillis() - job.getCreationTime() > job.getSchedule().getTimeoutMillis()) {
// job has timed out; mark it obsolete
table.put(getRowKey(job.getJobKey().getScheduleId(), job.getJobKey().getCreationTime()), IS_OBSOLETE_COL, Bytes.toBytes(System.currentTimeMillis()));
} else {
jobExists = true;
addNotification(job, notification);
break;
}
}
}
}
// if no job exists for the scheduleId, add a new job with the first notification
if (!jobExists) {
List<Notification> notifications = Collections.singletonList(notification);
Job.State jobState = isTriggerSatisfied(schedule, notifications) ? Job.State.PENDING_CONSTRAINT : Job.State.PENDING_TRIGGER;
put(new SimpleJob(schedule, System.currentTimeMillis(), notifications, jobState, record.getMeta().getLastUpdated()));
}
}
use of co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule in project cdap by caskdata.
the class CoreSchedulerService method addSchedules.
@Override
public void addSchedules(final Iterable<? extends ProgramSchedule> schedules) throws AlreadyExistsException, BadRequestException {
checkStarted();
for (ProgramSchedule schedule : schedules) {
if (!schedule.getProgramId().getType().equals(ProgramType.WORKFLOW)) {
throw new BadRequestException(String.format("Cannot schedule program %s of type %s: Only workflows can be scheduled", schedule.getProgramId().getProgram(), schedule.getProgramId().getType()));
}
}
execute((StoreTxRunnable<Void, AlreadyExistsException>) store -> {
store.addSchedules(schedules);
for (ProgramSchedule schedule : schedules) {
try {
timeSchedulerService.addProgramSchedule(schedule);
} catch (SchedulerException e) {
LOG.error("Exception occurs when adding schedule {}", schedule, e);
throw new RuntimeException(e);
}
}
return null;
}, AlreadyExistsException.class);
}
use of co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule in project cdap by caskdata.
the class ProgramScheduleService method getStatus.
/**
* 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);
}
use of co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule in project cdap by caskdata.
the class ProgramScheduleService method resume.
/**
* 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);
}
use of co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule in project cdap by caskdata.
the class ProgramScheduleService method get.
/**
* 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;
}
Aggregations