mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
nomad: cleanup API descrepencies
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
28
nomad/fsm.go
28
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user