/** * List schedule records with the given key prefix and only returns the schedules that can pass the filter. * * @param prefix the prefix of the schedule records to be listed * @param filter a filter that only returns true if the schedule record will be returned in the result * @return the schedule records with the given key prefix that can pass the filter */ private List<ProgramScheduleRecord> listSchedulesRecordsWithPrefix(byte[] prefix, Predicate<ProgramSchedule> filter) { List<ProgramScheduleRecord> result = new ArrayList<>(); try (Scanner scanner = store.scan(new Scan(prefix, Bytes.stopKeyForPrefix(prefix)))) { Row row; while ((row = scanner.next()) != null) { byte[] serialized = row.get(SCHEDULE_COLUMN_BYTES); if (serialized != null) { ProgramSchedule schedule = GSON.fromJson(Bytes.toString(serialized), ProgramSchedule.class); if (schedule != null && filter.test(schedule)) { result.add(new ProgramScheduleRecord(schedule, extractMetaFromRow(schedule.getScheduleId(), row))); } } } } return result; }
/** * List schedule records with the given key prefix and only returns the schedules that can pass the filter. * * @param prefix the prefix of the schedule records to be listed * @param filter a filter that only returns true if the schedule record will be returned in the result * @return the schedule records with the given key prefix that can pass the filter */ private List<ProgramScheduleRecord> listSchedulesRecordsWithPrefix(byte[] prefix, Predicate<ProgramSchedule> filter) { List<ProgramScheduleRecord> result = new ArrayList<>(); try (Scanner scanner = store.scan(new Scan(prefix, Bytes.stopKeyForPrefix(prefix)))) { Row row; while ((row = scanner.next()) != null) { byte[] serialized = row.get(SCHEDULE_COLUMN_BYTES); if (serialized != null) { ProgramSchedule schedule = GSON.fromJson(Bytes.toString(serialized), ProgramSchedule.class); if (schedule != null && filter.test(schedule)) { result.add(new ProgramScheduleRecord(schedule, extractMetaFromRow(schedule.getScheduleId(), row))); } } } } return result; }
ProgramScheduleRecord record = new ProgramScheduleRecord(schedule, meta); schedulesFound.put(scheduleId, record); } catch (IllegalArgumentException | NotFoundException e) {
ProgramScheduleRecord record = new ProgramScheduleRecord(schedule, meta); schedulesFound.put(scheduleId, record); } catch (IllegalArgumentException | NotFoundException e) {
/** * Read all information about a schedule from the store. * * @param scheduleId the id of the schedule to read * @return the schedule record from the store * @throws NotFoundException if the schedule does not exist in the store */ public ProgramScheduleRecord getScheduleRecord(ScheduleId scheduleId) throws NotFoundException { Row row = store.get(new Get(rowKeyForSchedule(scheduleId))); byte[] serialized = row.get(SCHEDULE_COLUMN_BYTES); if (serialized == null) { throw new NotFoundException(scheduleId); } ProgramSchedule schedule = GSON.fromJson(Bytes.toString(serialized), ProgramSchedule.class); ProgramScheduleMeta meta = extractMetaFromRow(scheduleId, row); return new ProgramScheduleRecord(schedule, meta); }
/** * Read all information about a schedule from the store. * * @param scheduleId the id of the schedule to read * @return the schedule record from the store * @throws NotFoundException if the schedule does not exist in the store */ public ProgramScheduleRecord getScheduleRecord(ScheduleId scheduleId) throws NotFoundException { Row row = store.get(new Get(rowKeyForSchedule(scheduleId))); byte[] serialized = row.get(SCHEDULE_COLUMN_BYTES); if (serialized == null) { throw new NotFoundException(scheduleId); } ProgramSchedule schedule = GSON.fromJson(Bytes.toString(serialized), ProgramSchedule.class); ProgramScheduleMeta meta = extractMetaFromRow(scheduleId, row); return new ProgramScheduleRecord(schedule, meta); }
@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()); } });
new ProgramScheduleRecord(SCHED1, new ProgramScheduleMeta(ProgramScheduleStatus.SCHEDULED, 0L)), notification);