Search in sources :

Example 1 with ProgramScheduleStatus

use of co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleStatus 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 ProgramScheduleStatus

use of co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleStatus in project cdap by caskdata.

the class CoreSchedulerService method updateSchedule.

@Override
public void updateSchedule(final ProgramSchedule schedule) throws NotFoundException, BadRequestException {
    ProgramScheduleStatus previousStatus = getScheduleStatus(schedule.getScheduleId());
    deleteSchedule(schedule.getScheduleId());
    try {
        addSchedule(schedule);
    } catch (AlreadyExistsException e) {
        // Should never reach here because we just deleted it
        throw new IllegalStateException("Schedule '" + schedule.getScheduleId() + "' already exists despite just being deleted.");
    }
    // if the schedule was previously enabled, it should still/again enabled be after the update
    if (ProgramScheduleStatus.SCHEDULED == previousStatus) {
        try {
            enableSchedule(schedule.getScheduleId());
        } catch (ConflictException e) {
            // Should never reach here because we just added this
            throw new IllegalStateException("Schedule '" + schedule.getScheduleId() + "' already enabled despite just being added.");
        }
    }
}
Also used : ProgramScheduleStatus(co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleStatus) AlreadyExistsException(co.cask.cdap.common.AlreadyExistsException) ConflictException(co.cask.cdap.common.ConflictException)

Aggregations

ProgramScheduleStatus (co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleStatus)2 AlreadyExistsException (co.cask.cdap.common.AlreadyExistsException)1 ConflictException (co.cask.cdap.common.ConflictException)1 ProgramScheduleMeta (co.cask.cdap.internal.app.runtime.schedule.ProgramScheduleMeta)1