use of co.cask.cdap.internal.schedule.trigger.Trigger in project cdap by caskdata.
the class TriggerCodecTest method testSerDeserYieldsTrigger.
private void testSerDeserYieldsTrigger(ProtoTrigger proto, Trigger trigger) {
String jsonOfTrigger = GSON.toJson(trigger);
String jsonOfTriggerAsTrigger = GSON.toJson(trigger, Trigger.class);
String jsonOfProto = GSON.toJson(proto);
String jsonOfProtoAsTrigger = GSON.toJson(proto, Trigger.class);
String jsonOfTriggerByProto = GSON_PROTO.toJson(trigger);
String jsonOfTriggerAsTriggerByProto = GSON_PROTO.toJson(trigger, Trigger.class);
String jsonOfProtoByProto = GSON_PROTO.toJson(proto);
String jsonOfProtoAsTriggerByProto = GSON_PROTO.toJson(proto, Trigger.class);
Assert.assertEquals(jsonOfTrigger, jsonOfTriggerAsTrigger);
Assert.assertEquals(jsonOfTrigger, jsonOfProto);
Assert.assertEquals(jsonOfTrigger, jsonOfProtoAsTrigger);
Assert.assertEquals(jsonOfTrigger, jsonOfTriggerByProto);
Assert.assertEquals(jsonOfTrigger, jsonOfTriggerAsTriggerByProto);
Assert.assertEquals(jsonOfTrigger, jsonOfProtoByProto);
Assert.assertEquals(jsonOfTrigger, jsonOfProtoAsTriggerByProto);
Trigger deserialized = GSON.fromJson(jsonOfTrigger, Trigger.class);
Trigger deserializedAsProto = GSON_PROTO.fromJson(jsonOfTrigger, Trigger.class);
Assert.assertEquals(trigger, deserialized);
Assert.assertEquals(proto, deserializedAsProto);
}
use of co.cask.cdap.internal.schedule.trigger.Trigger 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);
}
use of co.cask.cdap.internal.schedule.trigger.Trigger in project cdap by caskdata.
the class Schedulers method toProgramSchedule.
public static ProgramSchedule toProgramSchedule(ApplicationId appId, ScheduleSpecification spec) {
Schedule schedule = spec.getSchedule();
ProgramType programType = ProgramType.valueOfSchedulableType(spec.getProgram().getProgramType());
ProgramId programId = appId.program(programType, spec.getProgram().getProgramName());
Trigger trigger;
if (schedule instanceof TimeSchedule) {
TimeSchedule timeSchedule = (TimeSchedule) schedule;
trigger = new TimeTrigger(timeSchedule.getCronEntry());
} else {
StreamSizeSchedule streamSchedule = (StreamSizeSchedule) schedule;
StreamId streamId = programId.getNamespaceId().stream(streamSchedule.getStreamName());
trigger = new StreamSizeTrigger(streamId, streamSchedule.getDataTriggerMB());
}
Integer maxConcurrentRuns = schedule.getRunConstraints().getMaxConcurrentRuns();
List<Constraint> constraints = maxConcurrentRuns == null ? ImmutableList.<Constraint>of() : ImmutableList.<Constraint>of(new ConcurrencyConstraint(maxConcurrentRuns));
return new ProgramSchedule(schedule.getName(), schedule.getDescription(), programId, spec.getProperties(), trigger, constraints);
}
use of co.cask.cdap.internal.schedule.trigger.Trigger in project cdap by caskdata.
the class ProtoTriggerCodecTest method testTriggerCodec.
@Test
public void testTriggerCodec() {
Trigger trigger = new ProtoTrigger.PartitionTrigger(new DatasetId("test", "myds"), 4);
String json = GSON.toJson(trigger);
Trigger trigger1 = GSON.fromJson(json, Trigger.class);
Assert.assertEquals(trigger, trigger1);
json = GSON.toJson(trigger, Trigger.class);
trigger1 = GSON.fromJson(json, Trigger.class);
Assert.assertEquals(trigger, trigger1);
trigger = new ProtoTrigger.TimeTrigger("* * * * *");
json = GSON.toJson(trigger);
trigger1 = GSON.fromJson(json, Trigger.class);
Assert.assertEquals(trigger, trigger1);
json = GSON.toJson(trigger, Trigger.class);
trigger1 = GSON.fromJson(json, Trigger.class);
Assert.assertEquals(trigger, trigger1);
trigger = new ProtoTrigger.StreamSizeTrigger(new StreamId("x", "y"), 17);
json = GSON.toJson(trigger);
trigger1 = GSON.fromJson(json, Trigger.class);
Assert.assertEquals(trigger, trigger1);
json = GSON.toJson(trigger, Trigger.class);
trigger1 = GSON.fromJson(json, Trigger.class);
Assert.assertEquals(trigger, trigger1);
}
Aggregations