Search in sources :

Example 1 with ProgramScheduleMeta

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()));
    }
}
Also used : ProgramScheduleMeta(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta) ProgramScheduleStatus(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleStatus)

Example 2 with ProgramScheduleMeta

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);
}
Also used : ProgramScheduleMeta(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) Get(co.cask.cdap.api.dataset.table.Get) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramScheduleRecord(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleRecord) Row(co.cask.cdap.api.dataset.table.Row)

Example 3 with ProgramScheduleMeta

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();
}
Also used : Scanner(co.cask.cdap.api.dataset.table.Scanner) ProgramScheduleMeta(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta) HashMap(java.util.HashMap) NotFoundException(co.cask.cdap.common.NotFoundException) ScheduleId(co.cask.cdap.proto.id.ScheduleId) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) Get(co.cask.cdap.api.dataset.table.Get) ProgramScheduleRecord(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleRecord) Row(co.cask.cdap.api.dataset.table.Row)

Aggregations

ProgramScheduleMeta (co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta)3 Get (co.cask.cdap.api.dataset.table.Get)2 Row (co.cask.cdap.api.dataset.table.Row)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)2 ProgramScheduleRecord (co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleRecord)2 Scanner (co.cask.cdap.api.dataset.table.Scanner)1 ProgramScheduleStatus (co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleStatus)1 ScheduleId (co.cask.cdap.proto.id.ScheduleId)1 HashMap (java.util.HashMap)1