nomad: adding special 'system' scheduler

This commit is contained in:
Armon Dadgar
2015-08-06 17:04:35 -07:00
parent e1dfdf45ce
commit 4644a243cb
5 changed files with 24 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import (
"time"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/scheduler"
"github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf"
@@ -164,6 +165,7 @@ func DefaultConfig() *Config {
for name := range scheduler.BuiltinSchedulers {
c.EnabledSchedulers = append(c.EnabledSchedulers, name)
}
c.EnabledSchedulers = append(c.EnabledSchedulers, structs.JobTypeSystem)
// Increase our reap interval to 3 days instead of 24h.
c.SerfConfig.ReconnectTimeout = 3 * 24 * time.Hour

View File

@@ -33,6 +33,9 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
if args.Job.Type == "" {
return fmt.Errorf("missing job type for registration")
}
if args.Job.Type == structs.JobTypeSystem {
return fmt.Errorf("job type cannot be system")
}
// Ensure priorities are bounded
if args.Job.Priority < structs.JobMinPriority {

View File

@@ -99,6 +99,10 @@ 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{}
@@ -157,6 +161,9 @@ 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 {

View File

@@ -440,6 +440,9 @@ func (n *NetworkResource) Add(delta *NetworkResource) {
}
const (
// JobTypeSystem is reserved for internal system tasks and is
// always handled by the SystemScheduler.
JobTypeSystem = "system"
JobTypeService = "service"
JobTypeBatch = "batch"
)

View File

@@ -190,10 +190,15 @@ func (w *Worker) invokeScheduler(eval *structs.Evaluation) error {
return fmt.Errorf("failed to snapshot state: %v", err)
}
// Create the scheduler
sched, err := scheduler.NewScheduler(eval.Type, snap, w)
if err != nil {
return fmt.Errorf("failed to instantiate scheduler: %v", err)
// Create the scheduler, or use the special system scheduler
var sched scheduler.Scheduler
if eval.Type == structs.JobTypeSystem {
sched = w.srv.systemSched
} else {
sched, err = scheduler.NewScheduler(eval.Type, snap, w)
if err != nil {
return fmt.Errorf("failed to instantiate scheduler: %v", err)
}
}
// Process the evaluation