use of co.cask.cdap.proto.ScheduleType 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);
}
use of co.cask.cdap.proto.ScheduleType in project cdap by caskdata.
the class ScheduleSpecificationCodec method serialize.
@SuppressWarnings("deprecation")
@Override
public JsonElement serialize(ScheduleSpecification src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject jsonObj = new JsonObject();
ScheduleType scheduleType = ScheduleType.fromSchedule(src.getSchedule());
if (scheduleType.equals(ScheduleType.TIME)) {
jsonObj.add("scheduleType", context.serialize(ScheduleType.TIME, ScheduleType.class));
jsonObj.add("schedule", context.serialize(src.getSchedule(), TimeSchedule.class));
} else if (scheduleType.equals(ScheduleType.STREAM)) {
jsonObj.add("scheduleType", context.serialize(ScheduleType.STREAM, ScheduleType.class));
jsonObj.add("schedule", context.serialize(src.getSchedule(), StreamSizeSchedule.class));
}
jsonObj.add("program", context.serialize(src.getProgram(), ScheduleProgramInfo.class));
jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class));
return jsonObj;
}
Aggregations