Search in sources :

Example 6 with Trigger

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);
}
Also used : ProtoTrigger(co.cask.cdap.proto.ProtoTrigger) Trigger(co.cask.cdap.internal.schedule.trigger.Trigger)

Example 7 with Trigger

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

Example 8 with Trigger

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);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) 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) ProgramId(co.cask.cdap.proto.id.ProgramId) 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) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) Schedule(co.cask.cdap.api.schedule.Schedule) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) ProgramType(co.cask.cdap.proto.ProgramType) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule)

Example 9 with Trigger

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);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) Trigger(co.cask.cdap.internal.schedule.trigger.Trigger) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Aggregations

Trigger (co.cask.cdap.internal.schedule.trigger.Trigger)9 StreamSizeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger)6 TimeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger)5 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)4 StreamId (co.cask.cdap.proto.id.StreamId)4 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)3 StreamSizeSchedule (co.cask.cdap.internal.schedule.StreamSizeSchedule)3 TimeSchedule (co.cask.cdap.internal.schedule.TimeSchedule)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3 ConcurrencyConstraint (co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint)2 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)2 ProtoConstraint (co.cask.cdap.proto.ProtoConstraint)2 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)2 ProgramSpecification (co.cask.cdap.api.ProgramSpecification)1 Schedule (co.cask.cdap.api.schedule.Schedule)1 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)1 VerifyResult (co.cask.cdap.app.verification.VerifyResult)1 BadRequestException (co.cask.cdap.common.BadRequestException)1 ProgramType (co.cask.cdap.proto.ProgramType)1 ProtoTrigger (co.cask.cdap.proto.ProtoTrigger)1