Search in sources :

Example 1 with ScheduleType

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);
}
Also used : ScheduleType(co.cask.cdap.proto.ScheduleType) JsonElement(com.google.gson.JsonElement) Schedule(co.cask.cdap.api.schedule.Schedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) JsonObject(com.google.gson.JsonObject) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification)

Example 2 with ScheduleType

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;
}
Also used : ScheduleType(co.cask.cdap.proto.ScheduleType) JsonObject(com.google.gson.JsonObject) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo)

Aggregations

ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)2 TimeSchedule (co.cask.cdap.internal.schedule.TimeSchedule)2 ScheduleType (co.cask.cdap.proto.ScheduleType)2 JsonObject (com.google.gson.JsonObject)2 Schedule (co.cask.cdap.api.schedule.Schedule)1 ScheduleSpecification (co.cask.cdap.api.schedule.ScheduleSpecification)1 StreamSizeSchedule (co.cask.cdap.internal.schedule.StreamSizeSchedule)1 JsonElement (com.google.gson.JsonElement)1