From c27a0725ccba53060cef3cfd9777072024b4549e Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sun, 6 Sep 2015 20:47:42 -0700 Subject: [PATCH] nomad: cleanup API descrepencies --- client/client_test.go | 8 +++---- command/agent/alloc_endpoint_test.go | 4 ++-- command/agent/eval_endpoint_test.go | 2 +- command/agent/job_endpoint_test.go | 2 +- command/agent/node_endpoint_test.go | 6 ++--- nomad/alloc_endpoint_test.go | 4 ++-- nomad/core_sched_test.go | 2 +- nomad/eval_endpoint_test.go | 2 +- nomad/fsm.go | 28 +++++++++++----------- nomad/fsm_test.go | 20 ++++++++-------- nomad/heartbeat_test.go | 4 ++-- nomad/job_endpoint_test.go | 4 ++-- nomad/node_endpoint_test.go | 12 +++++----- nomad/plan_apply_test.go | 36 ++++++++++++++-------------- scheduler/context_test.go | 2 +- scheduler/generic_sched_test.go | 28 +++++++++++----------- scheduler/rank_test.go | 4 ++-- scheduler/scheduler_test.go | 2 +- scheduler/util_test.go | 16 ++++++------- 19 files changed, 93 insertions(+), 93 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 23b4379f1..848337844 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -219,7 +219,7 @@ func TestClient_UpdateAllocStatus(t *testing.T) { alloc.NodeID = c1.Node().ID state := s1.State() - state.UpdateAllocations(100, []*structs.Allocation{alloc}) + state.UpsertAllocs(100, []*structs.Allocation{alloc}) newAlloc := new(structs.Allocation) *newAlloc = *alloc @@ -257,7 +257,7 @@ func TestClient_WatchAllocs(t *testing.T) { alloc2.NodeID = c1.Node().ID state := s1.State() - err := state.UpdateAllocations(100, + err := state.UpsertAllocs(100, []*structs.Allocation{alloc1, alloc2}) if err != nil { t.Fatalf("err: %v", err) @@ -281,7 +281,7 @@ func TestClient_WatchAllocs(t *testing.T) { // Update the other allocation alloc2.DesiredStatus = structs.AllocDesiredStatusStop - err = state.UpdateAllocations(102, + err = state.UpsertAllocs(102, []*structs.Allocation{alloc2}) if err != nil { t.Fatalf("err: %v", err) @@ -326,7 +326,7 @@ func TestClient_SaveRestoreState(t *testing.T) { task.Config["args"] = "10" state := s1.State() - err := state.UpdateAllocations(100, + err := state.UpsertAllocs(100, []*structs.Allocation{alloc1}) if err != nil { t.Fatalf("err: %v", err) diff --git a/command/agent/alloc_endpoint_test.go b/command/agent/alloc_endpoint_test.go index 5234ec6c0..3f071b0b0 100644 --- a/command/agent/alloc_endpoint_test.go +++ b/command/agent/alloc_endpoint_test.go @@ -15,7 +15,7 @@ func TestHTTP_AllocsList(t *testing.T) { state := s.Agent.server.State() alloc1 := mock.Alloc() alloc2 := mock.Alloc() - err := state.UpdateAllocations(1000, + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}) if err != nil { t.Fatalf("err: %v", err) @@ -58,7 +58,7 @@ func TestHTTP_AllocQuery(t *testing.T) { // Directly manipulate the state state := s.Agent.server.State() alloc := mock.Alloc() - err := state.UpdateAllocations(1000, + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) diff --git a/command/agent/eval_endpoint_test.go b/command/agent/eval_endpoint_test.go index 22adce52a..69a322ca5 100644 --- a/command/agent/eval_endpoint_test.go +++ b/command/agent/eval_endpoint_test.go @@ -60,7 +60,7 @@ func TestHTTP_EvalAllocations(t *testing.T) { alloc1 := mock.Alloc() alloc2 := mock.Alloc() alloc2.EvalID = alloc1.EvalID - err := state.UpdateAllocations(1000, + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}) if err != nil { t.Fatalf("err: %v", err) diff --git a/command/agent/job_endpoint_test.go b/command/agent/job_endpoint_test.go index 78927a31c..8f4f07174 100644 --- a/command/agent/job_endpoint_test.go +++ b/command/agent/job_endpoint_test.go @@ -354,7 +354,7 @@ func TestHTTP_JobAllocations(t *testing.T) { state := s.Agent.server.State() alloc1 := mock.Alloc() alloc1.JobID = job.ID - err := state.UpdateAllocations(1000, []*structs.Allocation{alloc1}) + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1}) if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/agent/node_endpoint_test.go b/command/agent/node_endpoint_test.go index 6e5a260d0..58514a3fa 100644 --- a/command/agent/node_endpoint_test.go +++ b/command/agent/node_endpoint_test.go @@ -73,7 +73,7 @@ func TestHTTP_NodeForceEval(t *testing.T) { state := s.Agent.server.State() alloc1 := mock.Alloc() alloc1.NodeID = node.ID - err := state.UpdateAllocations(1000, []*structs.Allocation{alloc1}) + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1}) if err != nil { t.Fatalf("err: %v", err) } @@ -121,7 +121,7 @@ func TestHTTP_NodeAllocations(t *testing.T) { state := s.Agent.server.State() alloc1 := mock.Alloc() alloc1.NodeID = node.ID - err := state.UpdateAllocations(1000, []*structs.Allocation{alloc1}) + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1}) if err != nil { t.Fatalf("err: %v", err) } @@ -175,7 +175,7 @@ func TestHTTP_NodeDrain(t *testing.T) { state := s.Agent.server.State() alloc1 := mock.Alloc() alloc1.NodeID = node.ID - err := state.UpdateAllocations(1000, []*structs.Allocation{alloc1}) + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1}) if err != nil { t.Fatalf("err: %v", err) } diff --git a/nomad/alloc_endpoint_test.go b/nomad/alloc_endpoint_test.go index 697fb4bf2..5a5972eec 100644 --- a/nomad/alloc_endpoint_test.go +++ b/nomad/alloc_endpoint_test.go @@ -19,7 +19,7 @@ func TestAllocEndpoint_List(t *testing.T) { // Create the register request alloc := mock.Alloc() state := s1.fsm.State() - err := state.UpdateAllocations(1000, []*structs.Allocation{alloc}) + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } @@ -53,7 +53,7 @@ func TestAllocEndpoint_GetAlloc(t *testing.T) { // Create the register request alloc := mock.Alloc() state := s1.fsm.State() - err := state.UpdateAllocations(1000, []*structs.Allocation{alloc}) + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } diff --git a/nomad/core_sched_test.go b/nomad/core_sched_test.go index 69669dddb..58e515fe9 100644 --- a/nomad/core_sched_test.go +++ b/nomad/core_sched_test.go @@ -27,7 +27,7 @@ func TestCoreScheduler_EvalGC(t *testing.T) { alloc := mock.Alloc() alloc.EvalID = eval.ID alloc.DesiredStatus = structs.AllocDesiredStatusFailed - err = state.UpdateAllocations(1001, []*structs.Allocation{alloc}) + err = state.UpsertAllocs(1001, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } diff --git a/nomad/eval_endpoint_test.go b/nomad/eval_endpoint_test.go index c71c35755..d32b8495e 100644 --- a/nomad/eval_endpoint_test.go +++ b/nomad/eval_endpoint_test.go @@ -291,7 +291,7 @@ func TestEvalEndpoint_Allocations(t *testing.T) { alloc2 := mock.Alloc() alloc2.EvalID = alloc1.EvalID state := s1.fsm.State() - err := state.UpdateAllocations(1000, + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}) if err != nil { t.Fatalf("err: %v", err) diff --git a/nomad/fsm.go b/nomad/fsm.go index 94caf1b8a..b716f8e8a 100644 --- a/nomad/fsm.go +++ b/nomad/fsm.go @@ -115,7 +115,7 @@ func (n *nomadFSM) Apply(log *raft.Log) interface{} { switch msgType { case structs.NodeRegisterRequestType: - return n.applyRegisterNode(buf[1:], log.Index) + return n.applyUpsertNode(buf[1:], log.Index) case structs.NodeDeregisterRequestType: return n.applyDeregisterNode(buf[1:], log.Index) case structs.NodeUpdateStatusRequestType: @@ -123,7 +123,7 @@ func (n *nomadFSM) Apply(log *raft.Log) interface{} { case structs.NodeUpdateDrainRequestType: return n.applyDrainUpdate(buf[1:], log.Index) case structs.JobRegisterRequestType: - return n.applyRegisterJob(buf[1:], log.Index) + return n.applyUpsertJob(buf[1:], log.Index) case structs.JobDeregisterRequestType: return n.applyDeregisterJob(buf[1:], log.Index) case structs.EvalUpdateRequestType: @@ -144,15 +144,15 @@ func (n *nomadFSM) Apply(log *raft.Log) interface{} { } } -func (n *nomadFSM) applyRegisterNode(buf []byte, index uint64) interface{} { +func (n *nomadFSM) applyUpsertNode(buf []byte, index uint64) interface{} { defer metrics.MeasureSince([]string{"nomad", "fsm", "register_node"}, time.Now()) var req structs.NodeRegisterRequest if err := structs.Decode(buf, &req); err != nil { panic(fmt.Errorf("failed to decode request: %v", err)) } - if err := n.state.RegisterNode(index, req.Node); err != nil { - n.logger.Printf("[ERR] nomad.fsm: RegisterNode failed: %v", err) + if err := n.state.UpsertNode(index, req.Node); err != nil { + n.logger.Printf("[ERR] nomad.fsm: UpsertNode failed: %v", err) return err } return nil @@ -165,8 +165,8 @@ func (n *nomadFSM) applyDeregisterNode(buf []byte, index uint64) interface{} { panic(fmt.Errorf("failed to decode request: %v", err)) } - if err := n.state.DeregisterNode(index, req.NodeID); err != nil { - n.logger.Printf("[ERR] nomad.fsm: DeregisterNode failed: %v", err) + if err := n.state.DeleteNode(index, req.NodeID); err != nil { + n.logger.Printf("[ERR] nomad.fsm: DeleteNode failed: %v", err) return err } return nil @@ -200,15 +200,15 @@ func (n *nomadFSM) applyDrainUpdate(buf []byte, index uint64) interface{} { return nil } -func (n *nomadFSM) applyRegisterJob(buf []byte, index uint64) interface{} { +func (n *nomadFSM) applyUpsertJob(buf []byte, index uint64) interface{} { defer metrics.MeasureSince([]string{"nomad", "fsm", "register_job"}, time.Now()) var req structs.JobRegisterRequest if err := structs.Decode(buf, &req); err != nil { panic(fmt.Errorf("failed to decode request: %v", err)) } - if err := n.state.RegisterJob(index, req.Job); err != nil { - n.logger.Printf("[ERR] nomad.fsm: RegisterJob failed: %v", err) + if err := n.state.UpsertJob(index, req.Job); err != nil { + n.logger.Printf("[ERR] nomad.fsm: UpsertJob failed: %v", err) return err } return nil @@ -221,8 +221,8 @@ func (n *nomadFSM) applyDeregisterJob(buf []byte, index uint64) interface{} { panic(fmt.Errorf("failed to decode request: %v", err)) } - if err := n.state.DeregisterJob(index, req.JobID); err != nil { - n.logger.Printf("[ERR] nomad.fsm: DeregisterJob failed: %v", err) + if err := n.state.DeleteJob(index, req.JobID); err != nil { + n.logger.Printf("[ERR] nomad.fsm: DeleteJob failed: %v", err) return err } return nil @@ -272,8 +272,8 @@ func (n *nomadFSM) applyAllocUpdate(buf []byte, index uint64) interface{} { panic(fmt.Errorf("failed to decode request: %v", err)) } - if err := n.state.UpdateAllocations(index, req.Alloc); err != nil { - n.logger.Printf("[ERR] nomad.fsm: UpdateAllocations failed: %v", err) + if err := n.state.UpsertAllocs(index, req.Alloc); err != nil { + n.logger.Printf("[ERR] nomad.fsm: UpsertAllocs failed: %v", err) return err } return nil diff --git a/nomad/fsm_test.go b/nomad/fsm_test.go index 278595bea..94f55ee14 100644 --- a/nomad/fsm_test.go +++ b/nomad/fsm_test.go @@ -62,7 +62,7 @@ func makeLog(buf []byte) *raft.Log { } } -func TestFSM_RegisterNode(t *testing.T) { +func TestFSM_UpsertNode(t *testing.T) { fsm := testFSM(t) req := structs.NodeRegisterRequest{ @@ -364,7 +364,7 @@ func TestFSM_DeleteEval(t *testing.T) { } } -func TestFSM_UpdateAllocations(t *testing.T) { +func TestFSM_UpsertAllocs(t *testing.T) { fsm := testFSM(t) alloc := mock.Alloc() @@ -423,7 +423,7 @@ func TestFSM_UpdateAllocFromClient(t *testing.T) { state := fsm.State() alloc := mock.Alloc() - state.UpdateAllocations(1, []*structs.Allocation{alloc}) + state.UpsertAllocs(1, []*structs.Allocation{alloc}) clientAlloc := new(structs.Allocation) *clientAlloc = *alloc @@ -484,9 +484,9 @@ func TestFSM_SnapshotRestore_Nodes(t *testing.T) { fsm := testFSM(t) state := fsm.State() node1 := mock.Node() - state.RegisterNode(1000, node1) + state.UpsertNode(1000, node1) node2 := mock.Node() - state.RegisterNode(1001, node2) + state.UpsertNode(1001, node2) // Verify the contents fsm2 := testSnapshotRestore(t, fsm) @@ -506,9 +506,9 @@ func TestFSM_SnapshotRestore_Jobs(t *testing.T) { fsm := testFSM(t) state := fsm.State() job1 := mock.Job() - state.RegisterJob(1000, job1) + state.UpsertJob(1000, job1) job2 := mock.Job() - state.RegisterJob(1001, job2) + state.UpsertJob(1001, job2) // Verify the contents fsm2 := testSnapshotRestore(t, fsm) @@ -550,9 +550,9 @@ func TestFSM_SnapshotRestore_Allocs(t *testing.T) { fsm := testFSM(t) state := fsm.State() alloc1 := mock.Alloc() - state.UpdateAllocations(1000, []*structs.Allocation{alloc1}) + state.UpsertAllocs(1000, []*structs.Allocation{alloc1}) alloc2 := mock.Alloc() - state.UpdateAllocations(1001, []*structs.Allocation{alloc2}) + state.UpsertAllocs(1001, []*structs.Allocation{alloc2}) // Verify the contents fsm2 := testSnapshotRestore(t, fsm) @@ -572,7 +572,7 @@ func TestFSM_SnapshotRestore_Indexes(t *testing.T) { fsm := testFSM(t) state := fsm.State() node1 := mock.Node() - state.RegisterNode(1000, node1) + state.UpsertNode(1000, node1) // Verify the contents fsm2 := testSnapshotRestore(t, fsm) diff --git a/nomad/heartbeat_test.go b/nomad/heartbeat_test.go index 85fa2486e..06adb924b 100644 --- a/nomad/heartbeat_test.go +++ b/nomad/heartbeat_test.go @@ -18,7 +18,7 @@ func TestInitializeHeartbeatTimers(t *testing.T) { node := mock.Node() state := s1.fsm.State() - err := state.RegisterNode(1, node) + err := state.UpsertNode(1, node) if err != nil { t.Fatalf("err: %v", err) } @@ -123,7 +123,7 @@ func TestInvalidateHeartbeat(t *testing.T) { // Create a node node := mock.Node() state := s1.fsm.State() - err := state.RegisterNode(1, node) + err := state.UpsertNode(1, node) if err != nil { t.Fatalf("err: %v", err) } diff --git a/nomad/job_endpoint_test.go b/nomad/job_endpoint_test.go index 60184b738..b5138e1cf 100644 --- a/nomad/job_endpoint_test.go +++ b/nomad/job_endpoint_test.go @@ -364,7 +364,7 @@ func TestJobEndpoint_ListJobs(t *testing.T) { // Create the register request job := mock.Job() state := s1.fsm.State() - err := state.RegisterJob(1000, job) + err := state.UpsertJob(1000, job) if err != nil { t.Fatalf("err: %v", err) } @@ -400,7 +400,7 @@ func TestJobEndpoint_Allocations(t *testing.T) { alloc2 := mock.Alloc() alloc2.JobID = alloc1.JobID state := s1.fsm.State() - err := state.UpdateAllocations(1000, + err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}) if err != nil { t.Fatalf("err: %v", err) diff --git a/nomad/node_endpoint_test.go b/nomad/node_endpoint_test.go index 148c782bb..90fc80daa 100644 --- a/nomad/node_endpoint_test.go +++ b/nomad/node_endpoint_test.go @@ -315,7 +315,7 @@ func TestClientEndpoint_GetAllocs(t *testing.T) { alloc := mock.Alloc() alloc.NodeID = node.ID state := s1.fsm.State() - err := state.UpdateAllocations(100, []*structs.Allocation{alloc}) + err := state.UpsertAllocs(100, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } @@ -378,7 +378,7 @@ func TestClientEndpoint_GetAllocs_Blocking(t *testing.T) { start := time.Now() go func() { time.Sleep(100 * time.Millisecond) - err := state.UpdateAllocations(100, []*structs.Allocation{alloc}) + err := state.UpsertAllocs(100, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } @@ -435,7 +435,7 @@ func TestClientEndpoint_UpdateAlloc(t *testing.T) { alloc := mock.Alloc() alloc.NodeID = node.ID state := s1.fsm.State() - err := state.UpdateAllocations(100, []*structs.Allocation{alloc}) + err := state.UpsertAllocs(100, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } @@ -476,7 +476,7 @@ func TestClientEndpoint_CreateNodeEvals(t *testing.T) { // Inject fake evaluations alloc := mock.Alloc() state := s1.fsm.State() - err := state.UpdateAllocations(1, []*structs.Allocation{alloc}) + err := state.UpsertAllocs(1, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } @@ -539,11 +539,11 @@ func TestClientEndpoint_Evaluate(t *testing.T) { node := mock.Node() node.ID = alloc.NodeID state := s1.fsm.State() - err := state.RegisterNode(1, node) + err := state.UpsertNode(1, node) if err != nil { t.Fatalf("err: %v", err) } - err = state.UpdateAllocations(2, []*structs.Allocation{alloc}) + err = state.UpsertAllocs(2, []*structs.Allocation{alloc}) if err != nil { t.Fatalf("err: %v", err) } diff --git a/nomad/plan_apply_test.go b/nomad/plan_apply_test.go index 43f116b3d..80630ce73 100644 --- a/nomad/plan_apply_test.go +++ b/nomad/plan_apply_test.go @@ -117,7 +117,7 @@ func TestPlanApply_applyPlan(t *testing.T) { func TestPlanApply_EvalPlan_Simple(t *testing.T) { state := testStateStore(t) node := mock.Node() - state.RegisterNode(1000, node) + state.UpsertNode(1000, node) snap, _ := state.Snapshot() alloc := mock.Alloc() @@ -144,9 +144,9 @@ func TestPlanApply_EvalPlan_Simple(t *testing.T) { func TestPlanApply_EvalPlan_Partial(t *testing.T) { state := testStateStore(t) node := mock.Node() - state.RegisterNode(1000, node) + state.UpsertNode(1000, node) node2 := mock.Node() - state.RegisterNode(1001, node2) + state.UpsertNode(1001, node2) snap, _ := state.Snapshot() alloc := mock.Alloc() @@ -178,9 +178,9 @@ func TestPlanApply_EvalPlan_Partial(t *testing.T) { func TestPlanApply_EvalPlan_Partial_AllAtOnce(t *testing.T) { state := testStateStore(t) node := mock.Node() - state.RegisterNode(1000, node) + state.UpsertNode(1000, node) node2 := mock.Node() - state.RegisterNode(1001, node2) + state.UpsertNode(1001, node2) snap, _ := state.Snapshot() alloc := mock.Alloc() @@ -210,7 +210,7 @@ func TestPlanApply_EvalPlan_Partial_AllAtOnce(t *testing.T) { func TestPlanApply_EvalNodePlan_Simple(t *testing.T) { state := testStateStore(t) node := mock.Node() - state.RegisterNode(1000, node) + state.UpsertNode(1000, node) snap, _ := state.Snapshot() alloc := mock.Alloc() @@ -233,7 +233,7 @@ func TestPlanApply_EvalNodePlan_NodeNotReady(t *testing.T) { state := testStateStore(t) node := mock.Node() node.Status = structs.NodeStatusInit - state.RegisterNode(1000, node) + state.UpsertNode(1000, node) snap, _ := state.Snapshot() alloc := mock.Alloc() @@ -256,7 +256,7 @@ func TestPlanApply_EvalNodePlan_NodeDrain(t *testing.T) { state := testStateStore(t) node := mock.Node() node.Drain = true - state.RegisterNode(1000, node) + state.UpsertNode(1000, node) snap, _ := state.Snapshot() alloc := mock.Alloc() @@ -303,8 +303,8 @@ func TestPlanApply_EvalNodePlan_NodeFull(t *testing.T) { alloc.NodeID = node.ID node.Resources = alloc.Resources node.Reserved = nil - state.RegisterNode(1000, node) - state.UpdateAllocations(1001, []*structs.Allocation{alloc}) + state.UpsertNode(1000, node) + state.UpsertAllocs(1001, []*structs.Allocation{alloc}) snap, _ := state.Snapshot() alloc2 := mock.Alloc() @@ -331,8 +331,8 @@ func TestPlanApply_EvalNodePlan_UpdateExisting(t *testing.T) { alloc.NodeID = node.ID node.Resources = alloc.Resources node.Reserved = nil - state.RegisterNode(1000, node) - state.UpdateAllocations(1001, []*structs.Allocation{alloc}) + state.UpsertNode(1000, node) + state.UpsertAllocs(1001, []*structs.Allocation{alloc}) snap, _ := state.Snapshot() plan := &structs.Plan{ @@ -357,8 +357,8 @@ func TestPlanApply_EvalNodePlan_NodeFull_Evict(t *testing.T) { alloc.NodeID = node.ID node.Resources = alloc.Resources node.Reserved = nil - state.RegisterNode(1000, node) - state.UpdateAllocations(1001, []*structs.Allocation{alloc}) + state.UpsertNode(1000, node) + state.UpsertAllocs(1001, []*structs.Allocation{alloc}) snap, _ := state.Snapshot() allocEvict := new(structs.Allocation) @@ -391,8 +391,8 @@ func TestPlanApply_EvalNodePlan_NodeFull_AllocEvict(t *testing.T) { alloc.DesiredStatus = structs.AllocDesiredStatusEvict node.Resources = alloc.Resources node.Reserved = nil - state.RegisterNode(1000, node) - state.UpdateAllocations(1001, []*structs.Allocation{alloc}) + state.UpsertNode(1000, node) + state.UpsertAllocs(1001, []*structs.Allocation{alloc}) snap, _ := state.Snapshot() alloc2 := mock.Alloc() @@ -419,8 +419,8 @@ func TestPlanApply_EvalNodePlan_NodeDown_EvictOnly(t *testing.T) { node.Resources = alloc.Resources node.Reserved = nil node.Status = structs.NodeStatusDown - state.RegisterNode(1000, node) - state.UpdateAllocations(1001, []*structs.Allocation{alloc}) + state.UpsertNode(1000, node) + state.UpsertAllocs(1001, []*structs.Allocation{alloc}) snap, _ := state.Snapshot() allocEvict := new(structs.Allocation) diff --git a/scheduler/context_test.go b/scheduler/context_test.go index 82ff01307..1dc7807b5 100644 --- a/scheduler/context_test.go +++ b/scheduler/context_test.go @@ -74,7 +74,7 @@ func TestEvalContext_ProposedAlloc(t *testing.T) { }, DesiredStatus: structs.AllocDesiredStatusRun, } - noErr(t, state.UpdateAllocations(1000, []*structs.Allocation{alloc1, alloc2})) + noErr(t, state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2})) // Add a planned eviction to alloc1 plan := ctx.Plan() diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index e50970e2f..cebe1f280 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -14,12 +14,12 @@ func TestServiceSched_JobRegister(t *testing.T) { // Create some nodes for i := 0; i < 10; i++ { node := mock.Node() - noErr(t, h.State.RegisterNode(h.NextIndex(), node)) + noErr(t, h.State.UpsertNode(h.NextIndex(), node)) } // Create a job job := mock.Job() - noErr(t, h.State.RegisterJob(h.NextIndex(), job)) + noErr(t, h.State.UpsertJob(h.NextIndex(), job)) // Create a mock evaluation to deregister the job eval := &structs.Evaluation{ @@ -68,7 +68,7 @@ func TestServiceSched_JobRegister_AllocFail(t *testing.T) { // Create NO nodes // Create a job job := mock.Job() - noErr(t, h.State.RegisterJob(h.NextIndex(), job)) + noErr(t, h.State.UpsertJob(h.NextIndex(), job)) // Create a mock evaluation to deregister the job eval := &structs.Evaluation{ @@ -120,12 +120,12 @@ func TestServiceSched_JobModify(t *testing.T) { for i := 0; i < 10; i++ { node := mock.Node() nodes = append(nodes, node) - noErr(t, h.State.RegisterNode(h.NextIndex(), node)) + noErr(t, h.State.UpsertNode(h.NextIndex(), node)) } // Generate a fake job with allocations job := mock.Job() - noErr(t, h.State.RegisterJob(h.NextIndex(), job)) + noErr(t, h.State.UpsertJob(h.NextIndex(), job)) var allocs []*structs.Allocation for i := 0; i < 10; i++ { @@ -135,12 +135,12 @@ func TestServiceSched_JobModify(t *testing.T) { alloc.NodeID = nodes[i].ID allocs = append(allocs, alloc) } - noErr(t, h.State.UpdateAllocations(h.NextIndex(), allocs)) + noErr(t, h.State.UpsertAllocs(h.NextIndex(), allocs)) // Update the job job2 := mock.Job() job2.ID = job.ID - noErr(t, h.State.RegisterJob(h.NextIndex(), job2)) + noErr(t, h.State.UpsertJob(h.NextIndex(), job2)) // Create a mock evaluation to deal with drain eval := &structs.Evaluation{ @@ -206,7 +206,7 @@ func TestServiceSched_JobDeregister(t *testing.T) { alloc.JobID = job.ID allocs = append(allocs, alloc) } - noErr(t, h.State.UpdateAllocations(h.NextIndex(), allocs)) + noErr(t, h.State.UpsertAllocs(h.NextIndex(), allocs)) // Create a mock evaluation to deregister the job eval := &structs.Evaluation{ @@ -252,17 +252,17 @@ func TestServiceSched_NodeDrain(t *testing.T) { // Register a draining node node := mock.Node() node.Drain = true - noErr(t, h.State.RegisterNode(h.NextIndex(), node)) + noErr(t, h.State.UpsertNode(h.NextIndex(), node)) // Create some nodes for i := 0; i < 10; i++ { node := mock.Node() - noErr(t, h.State.RegisterNode(h.NextIndex(), node)) + noErr(t, h.State.UpsertNode(h.NextIndex(), node)) } // Generate a fake job with allocations job := mock.Job() - noErr(t, h.State.RegisterJob(h.NextIndex(), job)) + noErr(t, h.State.UpsertJob(h.NextIndex(), job)) var allocs []*structs.Allocation for i := 0; i < 10; i++ { @@ -273,7 +273,7 @@ func TestServiceSched_NodeDrain(t *testing.T) { alloc.Name = fmt.Sprintf("my-job.web[%d]", i) allocs = append(allocs, alloc) } - noErr(t, h.State.UpdateAllocations(h.NextIndex(), allocs)) + noErr(t, h.State.UpsertAllocs(h.NextIndex(), allocs)) // Create a mock evaluation to deal with drain eval := &structs.Evaluation{ @@ -330,12 +330,12 @@ func TestServiceSched_RetryLimit(t *testing.T) { // Create some nodes for i := 0; i < 10; i++ { node := mock.Node() - noErr(t, h.State.RegisterNode(h.NextIndex(), node)) + noErr(t, h.State.UpsertNode(h.NextIndex(), node)) } // Create a job job := mock.Job() - noErr(t, h.State.RegisterJob(h.NextIndex(), job)) + noErr(t, h.State.UpsertJob(h.NextIndex(), job)) // Create a mock evaluation to deregister the job eval := &structs.Evaluation{ diff --git a/scheduler/rank_test.go b/scheduler/rank_test.go index b56bf7c93..808696c5d 100644 --- a/scheduler/rank_test.go +++ b/scheduler/rank_test.go @@ -205,7 +205,7 @@ func TestBinPackIterator_ExistingAlloc(t *testing.T) { }, DesiredStatus: structs.AllocDesiredStatusRun, } - noErr(t, state.UpdateAllocations(1000, []*structs.Allocation{alloc1, alloc2})) + noErr(t, state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2})) resources := &structs.Resources{ CPU: 1024, @@ -274,7 +274,7 @@ func TestBinPackIterator_ExistingAlloc_PlannedEvict(t *testing.T) { }, DesiredStatus: structs.AllocDesiredStatusRun, } - noErr(t, state.UpdateAllocations(1000, []*structs.Allocation{alloc1, alloc2})) + noErr(t, state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2})) // Add a planned eviction to alloc1 plan := ctx.Plan() diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index 4778e7e64..7ceaedaea 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -89,7 +89,7 @@ func (h *Harness) SubmitPlan(plan *structs.Plan) (*structs.PlanResult, State, er allocs = append(allocs, plan.FailedAllocs...) // Apply the full plan - err := h.State.UpdateAllocations(index, allocs) + err := h.State.UpsertAllocs(index, allocs) return result, nil, err } diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 1fd796261..d4d8e9e08 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -123,10 +123,10 @@ func TestReadyNodesInDCs(t *testing.T) { node4 := mock.Node() node4.Drain = true - noErr(t, state.RegisterNode(1000, node1)) - noErr(t, state.RegisterNode(1001, node2)) - noErr(t, state.RegisterNode(1002, node3)) - noErr(t, state.RegisterNode(1003, node4)) + noErr(t, state.UpsertNode(1000, node1)) + noErr(t, state.UpsertNode(1001, node2)) + noErr(t, state.UpsertNode(1002, node3)) + noErr(t, state.UpsertNode(1003, node4)) nodes, err := readyNodesInDCs(state, []string{"dc1", "dc2"}) if err != nil { @@ -183,10 +183,10 @@ func TestTaintedNodes(t *testing.T) { node3.Status = structs.NodeStatusDown node4 := mock.Node() node4.Drain = true - noErr(t, state.RegisterNode(1000, node1)) - noErr(t, state.RegisterNode(1001, node2)) - noErr(t, state.RegisterNode(1002, node3)) - noErr(t, state.RegisterNode(1003, node4)) + noErr(t, state.UpsertNode(1000, node1)) + noErr(t, state.UpsertNode(1001, node2)) + noErr(t, state.UpsertNode(1002, node3)) + noErr(t, state.UpsertNode(1003, node4)) allocs := []*structs.Allocation{ &structs.Allocation{NodeID: node1.ID},