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