Search in sources :

Example 1 with TimeSchedule

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

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

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);
}
Also used : 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 4 with TimeSchedule

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());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) AbstractApplication(co.cask.cdap.api.app.AbstractApplication) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) Application(co.cask.cdap.api.app.Application) AbstractApplication(co.cask.cdap.api.app.AbstractApplication) Test(org.junit.Test)

Example 5 with TimeSchedule

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);
}
Also used : ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Trigger(co.cask.cdap.internal.schedule.trigger.Trigger) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec)

Aggregations

TimeSchedule (co.cask.cdap.internal.schedule.TimeSchedule)8 StreamSizeSchedule (co.cask.cdap.internal.schedule.StreamSizeSchedule)5 Schedule (co.cask.cdap.api.schedule.Schedule)4 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)4 StreamSizeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger)3 TimeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger)3 Trigger (co.cask.cdap.internal.schedule.trigger.Trigger)3 ScheduleSpecification (co.cask.cdap.api.schedule.ScheduleSpecification)2 ConcurrencyConstraint (co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint)2 StreamId (co.cask.cdap.proto.id.StreamId)2 Test (org.junit.Test)2 AbstractApplication (co.cask.cdap.api.app.AbstractApplication)1 Application (co.cask.cdap.api.app.Application)1 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 RunConstraints (co.cask.cdap.api.schedule.RunConstraints)1 ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)1 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)1 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)1 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)1 ProgramType (co.cask.cdap.proto.ProgramType)1