Search in sources :

Example 1 with StreamSizeSchedule

use of co.cask.cdap.internal.schedule.StreamSizeSchedule in project cdap by caskdata.

the class DefaultAppConfigurer method addSchedule.

@Override
public void addSchedule(Schedule schedule, SchedulableProgramType programType, String programName, Map<String, String> properties) {
    Preconditions.checkNotNull(schedule, "Schedule cannot be null.");
    Preconditions.checkNotNull(schedule.getName(), "Schedule name cannot be null.");
    Preconditions.checkArgument(!schedule.getName().isEmpty(), "Schedule name cannot be empty.");
    Preconditions.checkNotNull(programName, "Program name cannot be null.");
    Preconditions.checkArgument(!programName.isEmpty(), "Program name cannot be empty.");
    Preconditions.checkArgument(!schedules.containsKey(schedule.getName()), "Schedule with the name '" + schedule.getName() + "' already exists.");
    if (schedule instanceof StreamSizeSchedule) {
        Preconditions.checkArgument(((StreamSizeSchedule) schedule).getDataTriggerMB() > 0, "Schedule data trigger must be greater than 0.");
    }
    // TODO: [CDAP-11575] Temporary solution before REST API is merged. ScheduleSpecification will be removed and
    // the block of code below will be refactored
    ScheduleSpecification spec = new ScheduleSpecification(schedule, new ScheduleProgramInfo(programType, programName), properties);
    schedules.put(schedule.getName(), spec);
    ScheduleCreationSpec creationSpec = Schedulers.toScheduleCreationSpec(deployNamespace.toEntityId(), schedule, programName, properties);
    doAddSchedule(creationSpec);
}
Also used : StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification)

Example 2 with StreamSizeSchedule

use of co.cask.cdap.internal.schedule.StreamSizeSchedule 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 3 with StreamSizeSchedule

use of co.cask.cdap.internal.schedule.StreamSizeSchedule in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method toScheduleDetail.

private ScheduleDetail toScheduleDetail(ApplicationId appId, ScheduleSpecification scheduleSpec) {
    if (scheduleSpec.getSchedule() == null) {
        throw new IllegalArgumentException("Schedule specification must contain schedule");
    }
    Trigger trigger;
    if (scheduleSpec.getSchedule() instanceof TimeSchedule) {
        trigger = new TimeTrigger(((TimeSchedule) scheduleSpec.getSchedule()).getCronEntry());
    } else {
        StreamSizeSchedule streamSchedule = (StreamSizeSchedule) scheduleSpec.getSchedule();
        StreamId streamId = appId.getParent().stream(streamSchedule.getStreamName());
        trigger = new StreamSizeTrigger(streamId, streamSchedule.getDataTriggerMB());
    }
    List<Constraint> runConstraints = toConstraints(scheduleSpec.getSchedule().getRunConstraints());
    return new ScheduleDetail(scheduleSpec.getSchedule().getName(), scheduleSpec.getSchedule().getDescription(), scheduleSpec.getProgram(), scheduleSpec.getProperties(), trigger, runConstraints, null);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) 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) ProtoConstraint(co.cask.cdap.proto.ProtoConstraint) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule)

Example 4 with StreamSizeSchedule

use of co.cask.cdap.internal.schedule.StreamSizeSchedule in project cdap by caskdata.

the class StreamSizeScheduler method addProgramSchedule.

@Override
public void addProgramSchedule(ProgramSchedule schedule) throws AlreadyExistsException, SchedulerException {
    ProgramId program = schedule.getProgramId();
    StreamSizeSchedule streamSizeSchedule = Schedulers.toStreamSizeSchedule(schedule);
    scheduleStreamSizeSchedule(program, program.getType().getSchedulableType(), schedule.getProperties(), streamSizeSchedule);
}
Also used : ProgramId(co.cask.cdap.proto.id.ProgramId) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule)

Example 5 with StreamSizeSchedule

use of co.cask.cdap.internal.schedule.StreamSizeSchedule 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

StreamSizeSchedule (co.cask.cdap.internal.schedule.StreamSizeSchedule)8 TimeSchedule (co.cask.cdap.internal.schedule.TimeSchedule)5 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 ProgramId (co.cask.cdap.proto.id.ProgramId)3 Schedule (co.cask.cdap.api.schedule.Schedule)2 ScheduleSpecification (co.cask.cdap.api.schedule.ScheduleSpecification)2 ConcurrencyConstraint (co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint)2 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)2 StreamId (co.cask.cdap.proto.id.StreamId)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 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)1 Row (co.cask.cdap.api.dataset.table.Row)1 Scanner (co.cask.cdap.api.dataset.table.Scanner)1 RunConstraints (co.cask.cdap.api.schedule.RunConstraints)1 SchedulableProgramType (co.cask.cdap.api.schedule.SchedulableProgramType)1