Search in sources :

Example 1 with Schedule

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);
    }
}
Also used : JobDetail(org.quartz.JobDetail) Schedule(co.cask.cdap.api.schedule.Schedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule)

Example 2 with Schedule

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());
    }
}
Also used : Schedule(co.cask.cdap.api.schedule.Schedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule)

Example 3 with Schedule

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);
}
Also used : Schedule(co.cask.cdap.api.schedule.Schedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) Gson(com.google.gson.Gson) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification) Test(org.junit.Test)

Example 4 with Schedule

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);
}
Also used : Schedule(co.cask.cdap.api.schedule.Schedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification) Test(org.junit.Test)

Example 5 with Schedule

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

Aggregations

Schedule (co.cask.cdap.api.schedule.Schedule)8 TimeSchedule (co.cask.cdap.internal.schedule.TimeSchedule)8 StreamSizeSchedule (co.cask.cdap.internal.schedule.StreamSizeSchedule)6 ScheduleSpecification (co.cask.cdap.api.schedule.ScheduleSpecification)5 ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)3 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)2 Test (org.junit.Test)2 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 RunConstraints (co.cask.cdap.api.schedule.RunConstraints)1 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)1 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)1 ConcurrencyConstraint (co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint)1 StreamSizeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger)1 TimeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger)1 Trigger (co.cask.cdap.internal.schedule.trigger.Trigger)1 ProgramType (co.cask.cdap.proto.ProgramType)1 ScheduleType (co.cask.cdap.proto.ScheduleType)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 StreamId (co.cask.cdap.proto.id.StreamId)1 Gson (com.google.gson.Gson)1