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);
}
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());
}
Aggregations