From fb0e0dfc2be596ad435a00a2e131a2000146b1f1 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 23 Oct 2015 16:31:45 -0700 Subject: [PATCH] dont hard code scheduler type name --- nomad/node_endpoint.go | 2 +- nomad/node_endpoint_test.go | 6 +++--- nomad/state/state_store_test.go | 2 +- nomad/structs/structs.go | 3 ++- scheduler/scheduler.go | 6 +++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/nomad/node_endpoint.go b/nomad/node_endpoint.go index 9ce14aadd..f22208c8c 100644 --- a/nomad/node_endpoint.go +++ b/nomad/node_endpoint.go @@ -450,7 +450,7 @@ func (n *Node) createNodeEvals(nodeID string, nodeIndex uint64) ([]string, uint6 return nil, 0, fmt.Errorf("failed to find allocs for '%s': %v", nodeID, err) } - sysJobsIter, err := snap.JobsByScheduler("system") + sysJobsIter, err := snap.JobsByScheduler(structs.JobTypeSystem) if err != nil { return nil, 0, fmt.Errorf("failed to find system jobs for '%s': %v", nodeID, err) } diff --git a/nomad/node_endpoint_test.go b/nomad/node_endpoint_test.go index 62f4a4959..97f224171 100644 --- a/nomad/node_endpoint_test.go +++ b/nomad/node_endpoint_test.go @@ -207,8 +207,8 @@ func TestClientEndpoint_UpdateStatus_GetEvals(t *testing.T) { t.Fatalf("could not get eval %v", evalID) } - if eval.Type != "system" { - t.Fatalf("unexpected eval type; got %v; want %q", eval.Type, "system") + if eval.Type != structs.JobTypeSystem { + t.Fatalf("unexpected eval type; got %v; want %q", eval.Type, structs.JobTypeSystem) } // Check for heartbeat interval @@ -605,7 +605,7 @@ func TestClientEndpoint_CreateNodeEvals(t *testing.T) { for schedType, eval := range evalByType { expPriority := alloc.Job.Priority expJobID := alloc.JobID - if schedType == "system" { + if schedType == structs.JobTypeSystem { expPriority = job.Priority expJobID = job.ID } diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 1c4b60238..d202db811 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -387,7 +387,7 @@ func TestStateStore_JobsByScheduler(t *testing.T) { outService = append(outService, raw.(*structs.Job)) } - iter, err = state.JobsByScheduler("system") + iter, err = state.JobsByScheduler(structs.JobTypeSystem) if err != nil { t.Fatalf("err: %v", err) } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 8d58a9857..ef770bf66 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/go-msgpack/codec" "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-version" + "github.com/hashicorp/nomad/nomad/structs" ) var ( @@ -830,7 +831,7 @@ func (j *Job) Validate() error { taskGroups[tg.Name] = idx } - if j.Type == "system" && tg.Count != 1 { + if j.Type == structs.JobTypeSystem && tg.Count != 1 { mErr.Errors = append(mErr.Errors, fmt.Errorf("Job task group %d has count %d. Only count of 1 is supported with system scheduler", idx+1, tg.Count)) diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index baed71e73..8624c1b6d 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -11,9 +11,9 @@ import ( // BuiltinSchedulers contains the built in registered schedulers // which are available var BuiltinSchedulers = map[string]Factory{ - "service": NewServiceScheduler, - "batch": NewBatchScheduler, - "system": NewSystemScheduler, + structs.JobTypeService: NewServiceScheduler, + structs.JobTypeBatch: NewBatchScheduler, + structs.JobTypeSystem: NewSystemScheduler, } // NewScheduler is used to instantiate and return a new scheduler