/** * Reads the meta data from a row in the schedule store. * * @throws IllegalStateException if one of the expected fields is missing or ill-formed. */ private ProgramScheduleMeta extractMetaFromRow(ScheduleId scheduleId, Row row) { Long updatedTime = row.getLong(UPDATED_COLUMN_BYTES); String statusString = row.getString(STATUS_COLUMN_BYTES); try { Preconditions.checkArgument(updatedTime != null, "Last-updated timestamp is null"); Preconditions.checkArgument(statusString != null, "schedule status is null"); ProgramScheduleStatus status = ProgramScheduleStatus.valueOf(statusString); return new ProgramScheduleMeta(status, updatedTime); } catch (IllegalArgumentException e) { throw new IllegalStateException( String.format("Unexpected stored meta data for schedule %s: %s", scheduleId, e.getMessage())); } }
@Override public ProgramScheduleStatus getScheduleStatus(ScheduleId scheduleId) throws NotFoundException { checkStarted(); return execute(store -> store.getScheduleRecord(scheduleId).getMeta().getStatus(), NotFoundException.class); }
if (record.getMeta().getStatus() != ProgramScheduleStatus.SCHEDULED) { return; long scheduleLastUpdated = record.getMeta().getLastUpdated(); if (job.getScheduleLastUpdatedTime() != scheduleLastUpdated) { ? Job.State.PENDING_CONSTRAINT : Job.State.PENDING_TRIGGER; put(new SimpleJob(schedule, System.currentTimeMillis(), notifications, jobState, record.getMeta().getLastUpdated()));
if (record.getMeta().getStatus() != ProgramScheduleStatus.SCHEDULED) { return; long scheduleLastUpdated = record.getMeta().getLastUpdated(); if (job.getScheduleLastUpdatedTime() != scheduleLastUpdated) { ? Job.State.PENDING_CONSTRAINT : Job.State.PENDING_TRIGGER; put(new SimpleJob(schedule, System.currentTimeMillis(), notifications, jobState, record.getMeta().getLastUpdated()));
/** * Reads the meta data from a row in the schedule store. * * @throws IllegalStateException if one of the expected fields is missing or ill-formed. */ private ProgramScheduleMeta extractMetaFromRow(ScheduleId scheduleId, Row row) { Long updatedTime = row.getLong(UPDATED_COLUMN_BYTES); String statusString = row.getString(STATUS_COLUMN_BYTES); try { Preconditions.checkArgument(updatedTime != null, "Last-updated timestamp is null"); Preconditions.checkArgument(statusString != null, "schedule status is null"); ProgramScheduleStatus status = ProgramScheduleStatus.valueOf(statusString); return new ProgramScheduleMeta(status, updatedTime); } catch (IllegalArgumentException e) { throw new IllegalStateException( String.format("Unexpected stored meta data for schedule %s: %s", scheduleId, e.getMessage())); } }
@Override public ProgramScheduleStatus getScheduleStatus(ScheduleId scheduleId) throws NotFoundException { checkStarted(); return execute(store -> store.getScheduleRecord(scheduleId).getMeta().getStatus(), NotFoundException.class); }
@Override public void apply() throws Exception { // should be 0 jobs in the JobQueue to begin with Assert.assertEquals(0, getAllJobs(jobQueue, false).size()); // Construct a partition notification with DATASET_ID Notification notification = Notification.forPartitions(DATASET_ID, ImmutableList.<PartitionKey>of()); Assert.assertNull(jobQueue.getJob(SCHED1_JOB.getJobKey())); jobQueue.put(SCHED1_JOB); Assert.assertEquals(SCHED1_JOB, jobQueue.getJob(SCHED1_JOB.getJobKey())); // Since notification and SCHED1 have the same dataset id DATASET_ID, notification will be added to // SCHED1_JOB, which is a job in SCHED1 jobQueue.addNotification( new ProgramScheduleRecord(SCHED1, new ProgramScheduleMeta(ProgramScheduleStatus.SCHEDULED, 0L)), notification); Assert.assertEquals(ImmutableList.of(notification), jobQueue.getJob(SCHED1_JOB.getJobKey()).getNotifications()); } });
.filter(record -> programScheduleStatus == null || record.getMeta().getStatus().equals(programScheduleStatus)) .map(ProgramScheduleRecord::toScheduleDetail) .collect(Collectors.toList());
new ProgramScheduleRecord(SCHED1, new ProgramScheduleMeta(ProgramScheduleStatus.SCHEDULED, 0L)), notification);
.filter(record -> programScheduleStatus == null || record.getMeta().getStatus().equals(programScheduleStatus)) .map(ProgramScheduleRecord::toScheduleDetail) .collect(Collectors.toList());
predicate = predicate.and(record -> record.getMeta().getStatus().equals(status));
predicate = predicate.and(record -> record.getMeta().getStatus().equals(status));
@Override public void enableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreTxRunnable<Void, Exception>) store -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SUSPENDED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already enabled"); } timeSchedulerService.resumeProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SCHEDULED); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void disableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreAndQueueTxRunnable<Void, Exception>) (store, queue) -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SCHEDULED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already disabled"); } timeSchedulerService.suspendProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SUSPENDED); queue.markJobsForDeletion(scheduleId, System.currentTimeMillis()); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void disableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreAndQueueTxRunnable<Void, Exception>) (store, queue) -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SCHEDULED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already disabled"); } timeSchedulerService.suspendProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SUSPENDED); queue.markJobsForDeletion(scheduleId, System.currentTimeMillis()); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void enableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreTxRunnable<Void, Exception>) store -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SUSPENDED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already enabled"); } timeSchedulerService.resumeProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SCHEDULED); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
schedule.getProgramId(), schedule.getProperties(), updatedTrigger, schedule.getConstraints(), schedule.getTimeoutMillis()), scheduleRecord.getMeta().getStatus(), System.currentTimeMillis()); } catch (AlreadyExistsException e) {
schedule.getProgramId(), schedule.getProperties(), updatedTrigger, schedule.getConstraints(), schedule.getTimeoutMillis()), scheduleRecord.getMeta().getStatus(), System.currentTimeMillis()); } catch (AlreadyExistsException 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()); } }
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()); } }