From d4afb2f4318f911dd6824cba116512551c63e0ca Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 6 Aug 2015 17:08:40 -0700 Subject: [PATCH] nomad: create system scheduler as needed --- nomad/server.go | 7 ------- nomad/system_sched.go | 28 ++++++++++++++++++++++++++++ nomad/worker.go | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 nomad/system_sched.go diff --git a/nomad/server.go b/nomad/server.go index e91c79315..1b4501f97 100644 --- a/nomad/server.go +++ b/nomad/server.go @@ -99,10 +99,6 @@ type Server struct { // plans that are waiting to be assessed by the leader planQueue *PlanQueue - // systemSched is the special system scheduler used for - // various maintanence and book keeping. - systemSched *SystemScheduler - left bool shutdown bool shutdownCh chan struct{} @@ -161,9 +157,6 @@ func NewServer(config *Config) (*Server, error) { shutdownCh: make(chan struct{}), } - // Create the system scheduler - s.systemSched = &SystemScheduler{srv: s} - // Initialize the RPC layer // TODO: TLS... if err := s.setupRPC(nil); err != nil { diff --git a/nomad/system_sched.go b/nomad/system_sched.go new file mode 100644 index 000000000..57de8550b --- /dev/null +++ b/nomad/system_sched.go @@ -0,0 +1,28 @@ +package nomad + +import ( + "github.com/hashicorp/nomad/nomad/structs" + "github.com/hashicorp/nomad/scheduler" +) + +// SystemScheduler is a special "scheduler" that is registered +// as "system". It is used to run various administrative work +// across the cluster. +type SystemScheduler struct { + srv *Server + snap *StateSnapshot +} + +// NewSystemScheduler is used to return a new system scheduler instance +func NewSystemScheduler(srv *Server, snap *StateSnapshot) scheduler.Scheduler { + s := &SystemScheduler{ + srv: srv, + snap: snap, + } + return s +} + +// Process is used to implement the scheduler.Scheduler interface +func (s *SystemScheduler) Process(*structs.Evaluation) error { + return nil +} diff --git a/nomad/worker.go b/nomad/worker.go index c44f008c6..c59f15101 100644 --- a/nomad/worker.go +++ b/nomad/worker.go @@ -193,7 +193,7 @@ func (w *Worker) invokeScheduler(eval *structs.Evaluation) error { // Create the scheduler, or use the special system scheduler var sched scheduler.Scheduler if eval.Type == structs.JobTypeSystem { - sched = w.srv.systemSched + sched = NewSystemScheduler(w.srv, snap) } else { sched, err = scheduler.NewScheduler(eval.Type, snap, w) if err != nil {