From 87c9b23718f29b2439a7370241e10994dc2f9d96 Mon Sep 17 00:00:00 2001 From: Kevin Johnstone Date: Tue, 16 Feb 2016 10:07:36 -0800 Subject: [PATCH] remove schedules from jobs made dependent when previously scheduled --- .../scheduler/api/DependentJobResource.scala | 2 ++ .../jobs/JobSchedulerIntegrationTest.scala | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/scala/org/apache/mesos/chronos/scheduler/api/DependentJobResource.scala b/src/main/scala/org/apache/mesos/chronos/scheduler/api/DependentJobResource.scala index 4ed1d384c..627a444f0 100644 --- a/src/main/scala/org/apache/mesos/chronos/scheduler/api/DependentJobResource.scala +++ b/src/main/scala/org/apache/mesos/chronos/scheduler/api/DependentJobResource.scala @@ -66,6 +66,8 @@ class DependentJobResource @Inject()( } jobScheduler.removeSchedule(j) case j: ScheduleBasedJob => + log.info("Removing schedule for job: %s".format(j)) + jobScheduler.removeSchedule(j) parents.foreach(p => jobGraph.addDependency(p.name, newJob.name)) } diff --git a/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerIntegrationTest.scala b/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerIntegrationTest.scala index 3b0054d97..dc54155e7 100644 --- a/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerIntegrationTest.scala +++ b/src/test/scala/org/apache/mesos/chronos/scheduler/jobs/JobSchedulerIntegrationTest.scala @@ -240,6 +240,30 @@ class JobSchedulerIntegrationTest extends SpecificationWithJUnit with Mockito { there was no(mockTaskManager).enqueue(TaskUtils.getTaskId(job3, DateTime.parse(vJob2.lastError), 0), highPriority = false) } + "Tests that scheduled jobs changed to dependent jobs remove their schedules" in { + val epsilon = Minutes.minutes(1).toPeriod + val job1 = new ScheduleBasedJob(schedule = "R/2012-01-01T00:05:00.000Z/PT10M", + name = "job1", command = "fooo", epsilon = epsilon, disabled = false) + val job2 = new ScheduleBasedJob(schedule = "R/2012-01-01T00:05:00.000Z/PT10M", + name = "job2", command = "fooo", epsilon = epsilon, disabled = false) + val horizon = Minutes.minutes(5).toPeriod + val mockTaskManager = mock[TaskManager] + val graph = new JobGraph() + val mockPersistenceStore = mock[PersistenceStore] + val mockedScheduler = mock[JobScheduler] + val scheduler = mockScheduler(horizon, mockTaskManager, graph, mockPersistenceStore) + scheduler.leader.set(true) + val date = DateTime.parse("2012-01-01T00:00:00.000Z") + scheduler.registerJob(job1, persist = true, date) + scheduler.registerJob(job2, persist = true, date) + val dependentJob2 = new DependencyBasedJob(Set("job1"), name = "job2", command = "CMD", disabled = false) + val jobResource = new DependentJobResource(jobScheduler = mockedScheduler, jobGraph = graph) + + jobResource.handleRequest(dependentJob2) + there was one(mockedScheduler).removeSchedule(job2) + there was one(mockedScheduler).updateJob(job2, dependentJob2) + } + "Tests that dependent jobs runs when they should after changing the jobgraph" in { val epsilon = Minutes.minutes(20).toPeriod val job1 = new ScheduleBasedJob(schedule = "R/2012-01-01T00:01:00.000Z/PT1M",