Search in sources :

Example 6 with Constraint

use of co.cask.cdap.internal.schedule.constraint.Constraint in project cdap by caskdata.

the class Schedulers method toProgramSchedule.

public static ProgramSchedule toProgramSchedule(ApplicationId appId, ScheduleSpecification spec) {
    Schedule schedule = spec.getSchedule();
    ProgramType programType = ProgramType.valueOfSchedulableType(spec.getProgram().getProgramType());
    ProgramId programId = appId.program(programType, spec.getProgram().getProgramName());
    Trigger trigger;
    if (schedule instanceof TimeSchedule) {
        TimeSchedule timeSchedule = (TimeSchedule) schedule;
        trigger = new TimeTrigger(timeSchedule.getCronEntry());
    } else {
        StreamSizeSchedule streamSchedule = (StreamSizeSchedule) schedule;
        StreamId streamId = programId.getNamespaceId().stream(streamSchedule.getStreamName());
        trigger = new StreamSizeTrigger(streamId, streamSchedule.getDataTriggerMB());
    }
    Integer maxConcurrentRuns = schedule.getRunConstraints().getMaxConcurrentRuns();
    List<Constraint> constraints = maxConcurrentRuns == null ? ImmutableList.<Constraint>of() : ImmutableList.<Constraint>of(new ConcurrencyConstraint(maxConcurrentRuns));
    return new ProgramSchedule(schedule.getName(), schedule.getDescription(), programId, spec.getProperties(), trigger, constraints);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) ProgramId(co.cask.cdap.proto.id.ProgramId) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Trigger(co.cask.cdap.internal.schedule.trigger.Trigger) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) Schedule(co.cask.cdap.api.schedule.Schedule) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) ProgramType(co.cask.cdap.proto.ProgramType) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule)

Example 7 with Constraint

use of co.cask.cdap.internal.schedule.constraint.Constraint in project cdap by caskdata.

the class ScheduleDetail method toScheduleSpec.

/**
   * Return an equivalent schedule specification, or null if there is no equivalent one.
   */
@Deprecated
@Nullable
public ScheduleSpecification toScheduleSpec() {
    RunConstraints constraints = RunConstraints.NONE;
    if (getConstraints() != null) {
        for (Constraint runConstraint : getConstraints()) {
            if (runConstraint instanceof ProtoConstraint.ConcurrencyConstraint) {
                constraints = new RunConstraints(((ProtoConstraint.ConcurrencyConstraint) runConstraint).getMaxConcurrency());
                break;
            }
        }
    }
    Schedule schedule;
    if (getTrigger() instanceof ProtoTrigger.TimeTrigger) {
        ProtoTrigger.TimeTrigger trigger = ((ProtoTrigger.TimeTrigger) getTrigger());
        schedule = new TimeSchedule(getName(), getDescription(), trigger.getCronExpression(), constraints);
    } else if (getTrigger() instanceof ProtoTrigger.StreamSizeTrigger) {
        ProtoTrigger.StreamSizeTrigger trigger = (ProtoTrigger.StreamSizeTrigger) getTrigger();
        schedule = new StreamSizeSchedule(getName(), getDescription(), trigger.getStreamId().getStream(), trigger.getTriggerMB(), constraints);
    } else {
        return null;
    }
    return new ScheduleSpecification(schedule, getProgram(), getProperties());
}
Also used : Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) Schedule(co.cask.cdap.api.schedule.Schedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) RunConstraints(co.cask.cdap.api.schedule.RunConstraints) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification) Nullable(javax.annotation.Nullable)

Aggregations

Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)7 StreamSizeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger)4 TimeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger)4 StreamSizeSchedule (co.cask.cdap.internal.schedule.StreamSizeSchedule)4 TimeSchedule (co.cask.cdap.internal.schedule.TimeSchedule)4 Trigger (co.cask.cdap.internal.schedule.trigger.Trigger)4 ProtoConstraint (co.cask.cdap.proto.ProtoConstraint)3 Schedule (co.cask.cdap.api.schedule.Schedule)2 ConcurrencyConstraint (co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint)2 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)2 StreamId (co.cask.cdap.proto.id.StreamId)2 RunConstraints (co.cask.cdap.api.schedule.RunConstraints)1 ScheduleSpecification (co.cask.cdap.api.schedule.ScheduleSpecification)1 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)1 ScheduleTaskRunner (co.cask.cdap.internal.app.runtime.schedule.ScheduleTaskRunner)1 CheckableConstraint (co.cask.cdap.internal.app.runtime.schedule.constraint.CheckableConstraint)1 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)1 ProgramType (co.cask.cdap.proto.ProgramType)1 ScheduleUpdateDetail (co.cask.cdap.proto.ScheduleUpdateDetail)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1