use of co.cask.cdap.api.schedule.Schedule 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.api.schedule.Schedule 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.api.schedule.Schedule in project cdap by caskdata.
the class ScheduleSpecificationCodecTest method testBackwardsCompatibility.
@Test
public void testBackwardsCompatibility() throws Exception {
// Before 2.8, the ScheduleSpecificationCodec used to have the same behavior as what Gson would do by
// default, and only Schedules existed. We make sure that ScheduleSpecification persisted before
// 2.8 can still be deserialized using the new codec.
String cronEntry = "* * * * *";
Schedule schedule = new OldSchedule("foo", "bar", cronEntry);
ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, "testWorkflow");
ImmutableMap<String, String> properties = ImmutableMap.of("a", "b", "c", "d");
ScheduleSpecification specification = new ScheduleSpecification(schedule, programInfo, properties);
// Use default Gson to serialize
String jsonStr = new Gson().toJson(specification);
ScheduleSpecification deserialized = GSON.fromJson(jsonStr, ScheduleSpecification.class);
ScheduleSpecification expectedSpec = new ScheduleSpecification(Schedules.builder(schedule.getName()).setDescription(schedule.getDescription()).createTimeSchedule(cronEntry), programInfo, properties);
Assert.assertEquals(expectedSpec, deserialized);
}
use of co.cask.cdap.api.schedule.Schedule in project cdap by caskdata.
the class ScheduleSpecificationCodecTest method testStreamSizeSchedule.
@Test
public void testStreamSizeSchedule() throws Exception {
Schedule dataSchedule = Schedules.builder("foo").setDescription("bar").createDataSchedule(Schedules.Source.STREAM, "stream", 10);
ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, "testWorkflow");
ImmutableMap<String, String> properties = ImmutableMap.of("a", "b", "c", "d");
ScheduleSpecification specification = new ScheduleSpecification(dataSchedule, programInfo, properties);
String jsonStr = GSON.toJson(specification);
ScheduleSpecification deserialized = GSON.fromJson(jsonStr, ScheduleSpecification.class);
Assert.assertEquals(specification, deserialized);
}
use of co.cask.cdap.api.schedule.Schedule in project cdap by caskdata.
the class ScheduleSpecificationCodec method deserialize.
@Override
public ScheduleSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
JsonElement scheduleTypeJson = jsonObj.get("scheduleType");
ScheduleType scheduleType;
if (scheduleTypeJson == null) {
// For backwards compatibility with spec persisted with older versions than 2.8, we need these lines
scheduleType = null;
} else {
scheduleType = context.deserialize(jsonObj.get("scheduleType"), ScheduleType.class);
}
Schedule schedule = null;
if (scheduleType == null) {
JsonObject scheduleObj = jsonObj.get("schedule").getAsJsonObject();
String name = context.deserialize(scheduleObj.get("name"), String.class);
String description = context.deserialize(scheduleObj.get("description"), String.class);
String cronEntry = context.deserialize(scheduleObj.get("cronEntry"), String.class);
schedule = Schedules.builder(name).setDescription(description).createTimeSchedule(cronEntry);
} else {
switch(scheduleType) {
case TIME:
schedule = context.deserialize(jsonObj.get("schedule"), TimeSchedule.class);
break;
case STREAM:
schedule = context.deserialize(jsonObj.get("schedule"), StreamSizeSchedule.class);
break;
}
}
ScheduleProgramInfo program = context.deserialize(jsonObj.get("program"), ScheduleProgramInfo.class);
Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
return new ScheduleSpecification(schedule, program, properties);
}
Aggregations