@Override public Trigger onPartitions(String datasetName, int numPartitions) { return new PartitionTrigger(namespaceId.dataset(datasetName), numPartitions); }
@Override public boolean isSatisfied(ProgramSchedule schedule, List<Notification> notifications) { return getPartitionsCount(notifications) >= numPartitions; }
@Override public Trigger onPartitions(String datasetName, int numPartitions) { return new PartitionTrigger(namespaceId.dataset(datasetName), numPartitions); }
@Override public boolean isSatisfied(ProgramSchedule schedule, List<Notification> notifications) { return getPartitionsCount(notifications) >= numPartitions; }
@Override public Trigger onPartitions(String datasetNamespace, String datasetName, int numPartitions) { return new PartitionTrigger(new DatasetId(datasetNamespace, datasetName), numPartitions); }
@Override public List<TriggerInfo> getTriggerInfos(TriggerInfoContext context) { TriggerInfo triggerInfo = new DefaultPartitionTriggerInfo(dataset.getNamespace(), dataset.getDataset(), numPartitions, getPartitionsCount(context.getNotifications())); return Collections.singletonList(triggerInfo); }
@Override public Trigger onPartitions(String datasetNamespace, String datasetName, int numPartitions) { return new PartitionTrigger(new DatasetId(datasetNamespace, datasetName), numPartitions); }
@Override public List<TriggerInfo> getTriggerInfos(TriggerInfoContext context) { TriggerInfo triggerInfo = new DefaultPartitionTriggerInfo(dataset.getNamespace(), dataset.getDataset(), numPartitions, getPartitionsCount(context.getNotifications())); return Collections.singletonList(triggerInfo); }
ProgramSchedule schedule = new ProgramSchedule("sched" + i, "one partition schedule", WORKFLOW_ID, ImmutableMap.<String, String>of(), new PartitionTrigger(DATASET_ID, 1), ImmutableList.<Constraint>of()); Job job = new SimpleJob(schedule, now + i, ImmutableList.<Notification>of(),
@Test public void testDelayConstraint() { long now = System.currentTimeMillis(); ProgramSchedule schedule = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1), ImmutableList.<Constraint>of()); SimpleJob job = new SimpleJob(schedule, now, Collections.<Notification>emptyList(), Job.State.PENDING_TRIGGER, 0L); // test with 10 minute delay DelayConstraint tenMinuteDelayConstraint = new DelayConstraint(10, TimeUnit.MINUTES); // a check against 12 minutes after 'now' will return SATISFIED ConstraintContext constraintContext = new ConstraintContext(job, now + TimeUnit.MINUTES.toMillis(12), null); ConstraintResult result = tenMinuteDelayConstraint.check(schedule, constraintContext); Assert.assertEquals(ConstraintResult.SATISFIED, result); // a check against 9 minutes after 'now' will return NOT_SATISFIED, with 1 minute to wait until next retry constraintContext = new ConstraintContext(job, now + TimeUnit.MINUTES.toMillis(9), null); result = tenMinuteDelayConstraint.check(schedule, constraintContext); Assert.assertEquals(ConstraintResult.SatisfiedState.NOT_SATISFIED, result.getSatisfiedState()); Assert.assertEquals(constraintContext.getCheckTimeMillis() + TimeUnit.MINUTES.toMillis(1), (long) result.getNextCheckTime()); }
new PartitionTrigger(DATASET_ID, 1), ImmutableList.<Constraint>of());
ProgramSchedule schedule = new ProgramSchedule("sched" + i, "one partition schedule", WORKFLOW_ID, ImmutableMap.<String, String>of(), new PartitionTrigger(DATASET_ID, 1), ImmutableList.<Constraint>of()); Job job = new SimpleJob(schedule, now + i, ImmutableList.<Notification>of(),
new OrTrigger(new PartitionTrigger(DS1_ID, 1), prog1Trigger, new AndTrigger(new OrTrigger(prog1Trigger, prog2Trigger), new PartitionTrigger(DS2_ID, 1)), new OrTrigger(prog2Trigger)), ImmutableList.<Constraint>of()); new AndTrigger(new PartitionTrigger(DS1_ID, 1), prog2Trigger, new AndTrigger(prog1Trigger, new PartitionTrigger(DS2_ID, 1))), ImmutableList.<Constraint>of()); final ProgramSchedule schedOrNew = new ProgramSchedule("schedOr", "an OR trigger", PROG3_ID, ImmutableMap.of("propper", "popper"), new OrTrigger(new PartitionTrigger(DS1_ID, 1), new AndTrigger(prog2Trigger, new PartitionTrigger(DS2_ID, 1)), prog2Trigger), final ProgramSchedule schedOrNew1 = new ProgramSchedule("schedOr", "an OR trigger", PROG3_ID, ImmutableMap.of("propper", "popper"), new PartitionTrigger(DS1_ID, 1), ImmutableList.of()); final Set<ProgramSchedule> ds1Schedules = new HashSet<>();
new PartitionTrigger(DS1_ID, 1), ImmutableList.<Constraint>of()); final ProgramSchedule sched12 = new ProgramSchedule("sched12", "two partition schedule", PROG1_ID, ImmutableMap.of("propper", "popper"), new PartitionTrigger(DS2_ID, 2), ImmutableList.<Constraint>of()); final ProgramSchedule sched22 = new ProgramSchedule("sched22", "twentytwo partition schedule", PROG2_ID, ImmutableMap.of("nn", "4"), new PartitionTrigger(DS2_ID, 22), ImmutableList.<Constraint>of()); final ProgramSchedule sched31 = new ProgramSchedule("sched31", "a program status trigger", PROG3_ID, final ProgramSchedule sched12New = new ProgramSchedule(sched12.getName(), "one partition schedule", PROG1_ID, ImmutableMap.of("pp", "p"), new PartitionTrigger(DS1_ID, 2), ImmutableList.<Constraint>of()); final ProgramSchedule sched22New = new ProgramSchedule(sched22.getName(), "program3 failed schedule", PROG2_ID,
Collections.emptyMap(), new PartitionTrigger(DS1_ID, 1), Collections.emptyList()); final ProgramSchedule sched2 = new ProgramSchedule("sched2", "time schedule", PROG2_ID, Collections.emptyMap(), new TimeTrigger("* * * 1 1"), Collections.emptyList()); final ProgramSchedule sched3 = new ProgramSchedule("sched3", "two partitions schedule", PROG4_ID, Collections.emptyMap(), new PartitionTrigger(DS1_ID, 2), Collections.emptyList()); final ProgramSchedule sched4 = new ProgramSchedule("sched4", "time schedule", PROG5_ID, Collections.emptyMap(), new TimeTrigger("* * * 2 1"), Collections.emptyList());
new PartitionTrigger(DATASET_ID, 1), ImmutableList.<Constraint>of());
new PartitionTrigger(DS1_ID, 1), Collections.emptyList()); ProgramSchedule tsched11 = new ProgramSchedule("tsched11", "two times schedule", PROG11_ID, ImmutableMap.of("prop2", "xx"), ProgramSchedule psched2 = new ProgramSchedule("psched2", "two partition schedule", PROG2_ID, ImmutableMap.of("propper", "popper"), new PartitionTrigger(DS2_ID, 2), Collections.emptyList()); scheduler.addSchedules(ImmutableList.of(psched1, tsched11, psched2)); Assert.assertEquals(psched1, scheduler.getSchedule(PSCHED1_ID));
@Test public void testObjectContainingTrigger() { testContainingTrigger(new ProtoTrigger.PartitionTrigger(new DatasetId("test1", "pdfs1"), 1), new PartitionTrigger(new DatasetId("test1", "pdfs1"), 1)); testContainingTrigger(new ProtoTrigger.TimeTrigger("* * * 1 1"), new TimeTrigger("* * * 1 1")); testContainingTrigger(new ProtoTrigger.ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.FAILED)), new ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.FAILED))); }
ProgramSchedule schedule = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1), ImmutableList.of()); SimpleJob job = new SimpleJob(schedule, now, Collections.emptyList(), Job.State.PENDING_TRIGGER, 0L);
ProgramSchedule schedule = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1), ImmutableList.of()); SimpleJob job = new SimpleJob(schedule, now, Collections.emptyList(), Job.State.PENDING_TRIGGER, 0L);