use of co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta in project cdap by caskdata.
the class ProgramScheduleStoreDataset method extractMetaFromRow.
/**
* 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()));
}
}
use of co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta in project cdap by caskdata.
the class ProgramScheduleStoreDataset method getScheduleRecord.
/**
* 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);
}
use of co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta in project cdap by caskdata.
the class ProgramScheduleStoreDataset method findSchedules.
/**
* Find all schedules that have a trigger with a given trigger key.
*
* @param triggerKey the trigger key to look up
* @return a list of all schedules that are triggered by this key; never null
*/
public Collection<ProgramScheduleRecord> findSchedules(String triggerKey) {
Map<ScheduleId, ProgramScheduleRecord> schedulesFound = new HashMap<>();
try (Scanner scanner = store.readByIndex(TRIGGER_KEY_COLUMN_BYTES, Bytes.toBytes(triggerKey))) {
Row triggerRow;
while ((triggerRow = scanner.next()) != null) {
String triggerRowKey = Bytes.toString(triggerRow.getRow());
try {
ScheduleId scheduleId = extractScheduleIdFromTriggerKey(triggerRowKey);
if (schedulesFound.containsKey(scheduleId)) {
continue;
}
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);
ProgramScheduleRecord record = new ProgramScheduleRecord(schedule, meta);
schedulesFound.put(scheduleId, record);
} catch (IllegalArgumentException | NotFoundException e) {
// the only exceptions we know to be thrown here are IllegalArgumentException (ill-formed key) or
// NotFoundException (if the schedule does not exist). Both should never happen, so we warn and ignore.
// we will let any other exception propagate up, because it would be a DataSetException or similarly serious.
LOG.warn("Problem with trigger id '{}' found for trigger key '{}': {}. Skipping entry.", triggerRowKey, triggerKey, e.getMessage());
}
}
}
return schedulesFound.values();
}
Aggregations