@Override public Trigger byTime(String cronExpression) { return new TimeTrigger(cronExpression); }
@Override public Trigger byTime(String cronExpression) { return new TimeTrigger(cronExpression); }
/** * Adds and enables time based schedules for the given workflow at the given frequency. * * @param scheduleMins the number of minutes to wait before launching the given workflow each time * @param workflowId the ID of the scheduled workflow */ private ProgramSchedule initializeSchedules(int scheduleMins, WorkflowId workflowId) throws ConflictException, BadRequestException, NotFoundException { ProgramSchedule schedule = new ProgramSchedule(String.format("%dMinSchedule", scheduleMins), "time schedule", workflowId, Collections.emptyMap(), new TimeTrigger(String.format("*/%d * * * *", scheduleMins)), Collections.emptyList()); scheduler.addSchedule(schedule); scheduler.enableSchedule(schedule.getScheduleId()); return schedule; }
@Test public void testNextSchedule() throws Exception { // a schedule to be triggered every 5 minutes ProgramSchedule sched = new ProgramSchedule("tsched11", "two times schedule", PROG1_ID, ImmutableMap.of("prop2", "xx"), new TimeTrigger("*/5 * * * *"), Collections.emptyList()); timeScheduler.addProgramSchedule(sched); // schedule is by default SUSPENDED after being added, resume it to enable the schedule timeScheduler.resumeProgramSchedule(sched); long currentTimeInSeconds = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()); long startTimeInSeconds = currentTimeInSeconds + TimeUnit.HOURS.toSeconds(1); long endTimeInSeconds = currentTimeInSeconds + TimeUnit.HOURS.toSeconds(3); List<ScheduledRuntime> nextRuntimes = timeScheduler.getAllScheduledRunTimes(PROG1_ID, SchedulableProgramType.WORKFLOW, startTimeInSeconds, endTimeInSeconds); // for a scan range of 1pm to 3pm. since start time is inclusive, from 1pm tp 2pm we will have 13 schedules // and from 2:05 pm to 2:55pm will have 11 schedules as end time is exclusive. in total we expect 24 schedules. Assert.assertEquals(24, nextRuntimes.size()); } }
@Test public void testAddDeleteScheduleWithProfileProperty() throws Exception { // put my profile and by default it is enabled ProfileId profileId = NS_ID.profile("MyProfile"); putProfile(profileId, Profile.NATIVE, 200); // add a schedule, it should succeed since the profile is enabled. ProgramSchedule tsched1 = new ProgramSchedule("tsched1", "one time schedule", PROG1_ID, ImmutableMap.of("prop1", "nn", SystemArguments.PROFILE_NAME, profileId.getScopedName()), new TimeTrigger("* * ? * 1"), ImmutableList.<Constraint>of()); scheduler.addSchedule(tsched1); // now disable the profile and delete, deletion should fail because the profile is now associated with the schedule disableProfile(profileId, 200); deleteProfile(profileId, 409); // delete it scheduler.deleteSchedule(TSCHED1_ID); // now deletion should succeed since it should remove assignment from the profile deleteProfile(profileId, 200); }
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());
@Test public void testAddScheduleWithDisabledProfile() throws Exception { // put my profile and by default it is enabled ProfileId profileId = NS_ID.profile("MyProfile"); Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner()); putProfile(profileId, profile, 200); // add a schedule, it should succeed since the profile is enabled. ProgramSchedule tsched1 = new ProgramSchedule("tsched1", "one time schedule", PROG1_ID, ImmutableMap.of("prop1", "nn", SystemArguments.PROFILE_NAME, "USER:MyProfile"), new TimeTrigger("* * ? * 1"), ImmutableList.<Constraint>of()); scheduler.addSchedule(tsched1); Assert.assertEquals(Collections.singletonList(tsched1), scheduler.listSchedules(PROG1_ID)); // now disable the profile disableProfile(profileId, 200); // delete it scheduler.deleteSchedule(TSCHED1_ID); Assert.assertEquals(Collections.emptyList(), scheduler.listSchedules(PROG1_ID)); // add it again should also fail since the profile is disabled try { scheduler.addSchedule(tsched1); Assert.fail(); } catch (ProfileConflictException e) { // expected } // clean up deleteProfile(profileId, 200); }
final ProgramSchedule sched11New = new ProgramSchedule(sched11.getName(), "time schedule", PROG1_ID, ImmutableMap.of("timeprop", "time"), new TimeTrigger("* * * * *"), ImmutableList.<Constraint>of()); final ProgramSchedule sched12New = new ProgramSchedule(sched12.getName(), "one partition schedule", PROG1_ID,
private void testUpdateSchedule(ApplicationId appV2Id) throws Exception { ScheduleDetail updateDetail = new ScheduleDetail(AppWithSchedule.SCHEDULE, "updatedDescription", null, ImmutableMap.of("twoKey", "twoValue", "someKey", "newValue"), new TimeTrigger("0 4 * * *"), ImmutableList.of(new ConcurrencyConstraint(5)), null); new TimeTrigger("0 4 * * *"), ImmutableList.of(new ConcurrencyConstraint(5)), null); response = updateSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null,
new TimeTrigger("* * ? * 1"), ImmutableList.<Constraint>of()); scheduler.addSchedule(tsched1); Assert.assertEquals(tsched1, scheduler.getSchedule(TSCHED1_ID)); ProgramSchedule tsched11 = new ProgramSchedule("tsched11", "two times schedule", PROG11_ID, ImmutableMap.of("prop2", "xx"), new TimeTrigger("* * ? * 1,2"), Collections.emptyList()); ProgramSchedule psched2 = new ProgramSchedule("psched2", "two partition schedule", PROG2_ID, ImmutableMap.of("propper", "popper"),
@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))); }
AppWithSchedule.WORKFLOW_NAME); ImmutableMap<String, String> properties = ImmutableMap.of("a", "b", "c", "d"); TimeTrigger timeTrigger = new TimeTrigger("0 * * * ?"); ScheduleDetail timeDetail = new ScheduleDetail(TEST_NAMESPACE1, AppWithSchedule.NAME, ApplicationId.DEFAULT_VERSION, scheduleName, description, programInfo, properties, new TimeTrigger("0 * * * ?"), Collections.emptyList(), TimeUnit.HOURS.toMillis(6), null); response = addSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, VERSION2, "schedule-100", detail2);
"testSchedule", "Something 2", new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, workflowName), Collections.<String, String>emptyMap(), new TimeTrigger("*/1 * * * *"), Collections.<Constraint>emptyList(), TimeUnit.HOURS.toMillis(6), null);
scheduleService.add(new ProgramSchedule("tsched1", "one time schedule", workflowId, Collections.emptyMap(), new TimeTrigger("* * ? * 1"), ImmutableList.of()));
Assert.assertEquals(SchedulableProgramType.WORKFLOW, schedule.getProgram().getProgramType()); Assert.assertEquals(AppWithSchedule.WORKFLOW_NAME, schedule.getProgram().getProgramName()); Assert.assertEquals(new TimeTrigger("0/15 * * * * ?"), schedule.getTrigger()); Assert.assertEquals(SchedulableProgramType.WORKFLOW, schedule2.getProgram().getProgramType()); Assert.assertEquals(AppWithSchedule.WORKFLOW_NAME, schedule2.getProgram().getProgramName()); Assert.assertEquals(new TimeTrigger("0/15 * * * * ?"), schedule2.getTrigger());
@Test public void testTriggerCodec() { ProtoTrigger.PartitionTrigger protoPartition = new ProtoTrigger.PartitionTrigger(new DatasetId("test", "myds"), 4); PartitionTrigger partitionTrigger = new PartitionTrigger(new DatasetId("test", "myds"), 4); testSerDeserYieldsTrigger(protoPartition, partitionTrigger); ProtoTrigger.TimeTrigger protoTime = new ProtoTrigger.TimeTrigger("* * * * *"); TimeTrigger timeTrigger = new TimeTrigger("* * * * *"); testSerDeserYieldsTrigger(protoTime, timeTrigger); ProtoTrigger.ProgramStatusTrigger protoProgramStatus = new ProtoTrigger.ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.COMPLETED)); ProgramStatusTrigger programStatusTrigger = new ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.COMPLETED)); testSerDeserYieldsTrigger(protoProgramStatus, programStatusTrigger); ProtoTrigger.OrTrigger protoOr = ProtoTrigger.or(protoPartition, ProtoTrigger.and(protoTime, protoProgramStatus)); OrTrigger orTrigger = new OrTrigger(partitionTrigger, new AndTrigger(timeTrigger, programStatusTrigger)); testSerDeserYieldsTrigger(protoOr, orTrigger); ProtoTrigger.AndTrigger protoAnd = ProtoTrigger.and(protoOr, protoTime, ProtoTrigger.or(protoPartition, protoProgramStatus)); AndTrigger andTrigger = new AndTrigger(orTrigger, timeTrigger, new OrTrigger(partitionTrigger, programStatusTrigger)); testSerDeserYieldsTrigger(protoAnd, andTrigger); }