From 6d402f6652785ab57154f7959cd1dfb61a2fd7ba Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 27 Jul 2015 15:31:09 -0700 Subject: [PATCH] nomad: adding skeleton no-op plan evaluator --- nomad/leader.go | 3 ++- nomad/plan_apply.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 nomad/plan_apply.go diff --git a/nomad/leader.go b/nomad/leader.go index 03eea06cd..cbef810ba 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -100,7 +100,8 @@ func (s *Server) establishLeadership() error { // Enable the plan queue, since we are now the leader s.planQueue.SetEnabled(true) - // TODO: Start the plan evaluator + // Start the plan evaluator + go s.planApply() // Enable the eval broker, since we are now the leader s.evalBroker.SetEnabled(true) diff --git a/nomad/plan_apply.go b/nomad/plan_apply.go new file mode 100644 index 000000000..1e5b57c5a --- /dev/null +++ b/nomad/plan_apply.go @@ -0,0 +1,28 @@ +package nomad + +import "github.com/hashicorp/nomad/nomad/structs" + +// planApply is a long lived goroutine that reads plan allocations from +// the plan queue, determines if they can be applied safely and applies +// them via Raft. +func (s *Server) planApply() { + for { + // Pull the next pending plan, exit if we are no longer leader + pending, err := s.planQueue.Dequeue(0) + if err != nil { + return + } + + // TODO: Evaluate the plan + + // TODO: Apply the plan + + // TODO: Prepare the response + result := &structs.PlanResult{ + AllocIndex: 1000, + } + + // Respond to the plan + pending.respond(result, nil) + } +}