newProperties.putAll(additionalProperties); return new ProgramSchedule(schedule.getName(), schedule.getDescription(), schedule.getProgramId(), newProperties, schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis());
newProperties.putAll(additionalProperties); return new ProgramSchedule(schedule.getName(), schedule.getDescription(), schedule.getProgramId(), newProperties, schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis());
private void testContainingTrigger(ProtoTrigger proto, Trigger trigger) { ProgramSchedule proto1 = new ProgramSchedule("sched1", "one partition schedule", new NamespaceId("test").app("a").worker("ww"), ImmutableMap.of("prop3", "abc"), proto, ImmutableList.of()); ProgramSchedule sched1 = new ProgramSchedule("sched1", "one partition schedule", new NamespaceId("test").app("a").worker("ww"), ImmutableMap.of("prop3", "abc"), trigger, ImmutableList.of()); Assert.assertEquals(sched1, GSON.fromJson(GSON.toJson(proto1), ProgramSchedule.class)); } }
/** * 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()); } }
private ProgramSchedule toProgramSchedule(ApplicationId appId, ScheduleCreationSpec scheduleCreationSpec) { ProgramId programId = appId.workflow(scheduleCreationSpec.getProgramName()); Trigger trigger = scheduleCreationSpec.getTrigger(); return new ProgramSchedule(scheduleCreationSpec.getName(), scheduleCreationSpec.getDescription(), programId, scheduleCreationSpec.getProperties(), trigger, scheduleCreationSpec.getConstraints(), scheduleCreationSpec.getTimeoutMillis()); } }
private ProgramSchedule toProgramSchedule(ApplicationId appId, ScheduleCreationSpec scheduleCreationSpec) { ProgramId programId = appId.workflow(scheduleCreationSpec.getProgramName()); Trigger trigger = scheduleCreationSpec.getTrigger(); return new ProgramSchedule(scheduleCreationSpec.getName(), scheduleCreationSpec.getDescription(), programId, scheduleCreationSpec.getProperties(), trigger, scheduleCreationSpec.getConstraints(), scheduleCreationSpec.getTimeoutMillis()); } }
addScheduleWithStatus(new ProgramSchedule(schedule.getName(), schedule.getDescription(), schedule.getProgramId(), schedule.getProperties(), updatedTrigger, schedule.getConstraints(), schedule.getTimeoutMillis()),
addScheduleWithStatus(new ProgramSchedule(schedule.getName(), schedule.getDescription(), schedule.getProgramId(), schedule.getProperties(), updatedTrigger, schedule.getConstraints(), schedule.getTimeoutMillis()),
long now = 1494353984967L; for (int i = 0; i < 100; i++) { ProgramSchedule schedule = new ProgramSchedule("sched" + i, "one partition schedule", WORKFLOW_ID, ImmutableMap.<String, String>of(), new PartitionTrigger(DATASET_ID, 1),
@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()); }
long timeoutMillis = Objects.firstNonNull(scheduleFromRequest.getTimeoutMillis(), Schedulers.JOB_QUEUE_TIMEOUT_MILLIS); ProgramSchedule schedule = new ProgramSchedule(scheduleName, description, programId, properties, scheduleFromRequest.getTrigger(), constraints, timeoutMillis); programScheduleService.add(schedule);
long timeoutMillis = Objects.firstNonNull(scheduleFromRequest.getTimeoutMillis(), Schedulers.JOB_QUEUE_TIMEOUT_MILLIS); ProgramSchedule schedule = new ProgramSchedule(scheduleName, description, programId, properties, scheduleFromRequest.getTrigger(), constraints, timeoutMillis); programScheduleService.add(schedule);
Objects.firstNonNull(scheduleDetail.getConstraints(), existing.getConstraints()); Long timeoutMillis = Objects.firstNonNull(scheduleDetail.getTimeoutMillis(), existing.getTimeoutMillis()); ProgramSchedule updatedSchedule = new ProgramSchedule(existing.getName(), description, programId, properties, trigger, constraints, timeoutMillis); scheduler.updateSchedule(updatedSchedule);
Objects.firstNonNull(scheduleDetail.getConstraints(), existing.getConstraints()); Long timeoutMillis = Objects.firstNonNull(scheduleDetail.getTimeoutMillis(), existing.getTimeoutMillis()); ProgramSchedule updatedSchedule = new ProgramSchedule(existing.getName(), description, programId, properties, trigger, constraints, timeoutMillis); scheduler.updateSchedule(updatedSchedule);
@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); }
ProgramSchedule scheduleWithTimeout = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1),
@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); }
ProgramSchedule schedule = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1),
ProgramSchedule schedule = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1),