use of co.cask.cdap.internal.schedule.TimeSchedule in project cdap by caskdata.
the class TimeScheduler method schedule.
public synchronized void schedule(ProgramId program, SchedulableProgramType programType, Iterable<Schedule> schedules, Map<String, String> properties) throws SchedulerException {
checkInitialized();
try {
validateSchedules(program, programType, schedules);
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(e);
}
JobDetail job = addJob(program, programType);
for (Schedule schedule : schedules) {
TimeSchedule timeSchedule = (TimeSchedule) schedule;
String scheduleName = timeSchedule.getName();
String cronEntry = timeSchedule.getCronEntry();
scheduleJob(program, programType, scheduleName, cronEntry, job, properties);
}
}
use of co.cask.cdap.internal.schedule.TimeSchedule in project cdap by caskdata.
the class TimeScheduler method validateSchedules.
private void validateSchedules(ProgramId program, SchedulableProgramType programType, Iterable<Schedule> schedules) throws org.quartz.SchedulerException {
Preconditions.checkNotNull(schedules);
for (Schedule schedule : schedules) {
Preconditions.checkArgument(schedule instanceof TimeSchedule);
TimeSchedule timeSchedule = (TimeSchedule) schedule;
assertScheduleDoesNotExist(program, programType, timeSchedule.getName());
}
}
use of co.cask.cdap.internal.schedule.TimeSchedule in project cdap by caskdata.
the class ScheduleSpecificationCodecTest method testTimeSchedule.
@Test
public void testTimeSchedule() throws Exception {
TimeSchedule timeSchedule = (TimeSchedule) Schedules.builder("foo").setDescription("bar").createTimeSchedule("cronEntry");
ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, "testWorkflow");
ImmutableMap<String, String> properties = ImmutableMap.of("a", "b", "c", "d");
ScheduleSpecification specification = new ScheduleSpecification(timeSchedule, programInfo, properties);
String jsonStr = GSON.toJson(specification);
ScheduleSpecification deserialized = GSON.fromJson(jsonStr, ScheduleSpecification.class);
Assert.assertEquals(specification, deserialized);
}
use of co.cask.cdap.internal.schedule.TimeSchedule in project cdap by caskdata.
the class ScheduleSpecificationCodecTest method testAppConfigurerRoute.
@Test
public void testAppConfigurerRoute() throws Exception {
Application app = new AbstractApplication() {
@Override
public void configure() {
// intentionally use the deprecated scheduleWorkflow method to for timeSchedule
// to test TimeSchedule deserialization
scheduleWorkflow(Schedules.builder("timeSchedule").createTimeSchedule("0 * * * *"), "workflow");
scheduleWorkflow(Schedules.builder("streamSizeSchedule").createDataSchedule(Schedules.Source.STREAM, "stream", 1), "workflow");
}
};
ApplicationSpecification specification = Specifications.from(app);
ApplicationSpecificationAdapter gsonAdapater = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
String jsonStr = gsonAdapater.toJson(specification);
ApplicationSpecification deserializedSpec = gsonAdapater.fromJson(jsonStr);
Assert.assertEquals(new TimeSchedule("timeSchedule", "", "0 * * * *"), deserializedSpec.getSchedules().get("timeSchedule").getSchedule());
Assert.assertEquals(new StreamSizeSchedule("streamSizeSchedule", "", "stream", 1), deserializedSpec.getSchedules().get("streamSizeSchedule").getSchedule());
}
use of co.cask.cdap.internal.schedule.TimeSchedule in project cdap by caskdata.
the class Schedulers method toScheduleCreationSpec.
public static ScheduleCreationSpec toScheduleCreationSpec(NamespaceId deployNamespace, Schedule schedule, String programName, Map<String, String> properties) {
Trigger trigger;
if (schedule instanceof TimeSchedule) {
trigger = new TimeTrigger(((TimeSchedule) schedule).getCronEntry());
} else {
StreamSizeSchedule streamSizeSchedule = ((StreamSizeSchedule) schedule);
trigger = new StreamSizeTrigger(deployNamespace.stream(streamSizeSchedule.getStreamName()), streamSizeSchedule.getDataTriggerMB());
}
Integer maxConcurrentRuns = schedule.getRunConstraints().getMaxConcurrentRuns();
List<Constraint> constraints = maxConcurrentRuns == null ? ImmutableList.<Constraint>of() : ImmutableList.<Constraint>of(new ConcurrencyConstraint(maxConcurrentRuns));
return new ScheduleCreationSpec(schedule.getName(), schedule.getDescription(), programName, properties, trigger, constraints, Schedulers.JOB_QUEUE_TIMEOUT_MILLIS);
}
Aggregations