Events/msgtype cleanup (#9117)

* use msgtype in upsert node

adds message type to signature for upsert node, update tests, remove placeholder method

* UpsertAllocs msg type test setup

* use upsertallocs with msg type in signature

update test usage of delete node

delete placeholder msgtype method

* add msgtype to upsert evals signature, update test call sites with test setup msg type

handle snapshot upsert eval outside of FSM and ignore eval event

remove placeholder upsertevalsmsgtype

handle job plan rpc and prevent event creation for plan

msgtype cleanup upsertnodeevents

updatenodedrain msgtype

msg type 0 is a node registration event, so set the default  to the ignore type

* fix named import

* fix signature ordering on upsertnode to match
This commit is contained in:
Drew Bailey 2020-10-19 09:30:15 -04:00 committed by GitHub
parent 1f215e47d4
commit 6c788fdccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 1298 additions and 1383 deletions

View File

@ -484,13 +484,13 @@ func TestClient_WatchAllocs(t *testing.T) {
alloc2.Job = job
state := s1.State()
if err := state.UpsertJob(100, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job); err != nil {
t.Fatal(err)
}
if err := state.UpsertJobSummary(101, mock.JobSummary(alloc1.JobID)); err != nil {
t.Fatal(err)
}
err := state.UpsertAllocs(102, []*structs.Allocation{alloc1, alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 102, []*structs.Allocation{alloc1, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -515,7 +515,7 @@ func TestClient_WatchAllocs(t *testing.T) {
// alloc runner.
alloc2_2 := alloc2.Copy()
alloc2_2.DesiredStatus = structs.AllocDesiredStatusStop
if err := state.UpsertAllocs(104, []*structs.Allocation{alloc2_2}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 104, []*structs.Allocation{alloc2_2}); err != nil {
t.Fatalf("err upserting stopped alloc: %v", err)
}
@ -581,13 +581,13 @@ func TestClient_SaveRestoreState(t *testing.T) {
alloc1.ClientStatus = structs.AllocClientStatusRunning
state := s1.State()
if err := state.UpsertJob(100, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job); err != nil {
t.Fatal(err)
}
if err := state.UpsertJobSummary(101, mock.JobSummary(alloc1.JobID)); err != nil {
t.Fatal(err)
}
if err := state.UpsertAllocs(102, []*structs.Allocation{alloc1}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 102, []*structs.Allocation{alloc1}); err != nil {
t.Fatalf("err: %v", err)
}
@ -687,13 +687,13 @@ func TestClient_AddAllocError(t *testing.T) {
alloc1.TaskResources = nil
state := s1.State()
err := state.UpsertJob(100, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job)
require.Nil(err)
err = state.UpsertJobSummary(101, mock.JobSummary(alloc1.JobID))
require.Nil(err)
err = state.UpsertAllocs(102, []*structs.Allocation{alloc1})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 102, []*structs.Allocation{alloc1})
require.Nil(err)
// Push this alloc update to the client
@ -795,7 +795,7 @@ func TestClient_BlockedAllocations(t *testing.T) {
}
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
state.UpsertAllocs(100, []*structs.Allocation{alloc})
state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc})
// Wait until the client downloads and starts the allocation
testutil.WaitForResult(func() (bool, error) {
@ -818,7 +818,7 @@ func TestClient_BlockedAllocations(t *testing.T) {
alloc2.Job = alloc.Job
alloc2.JobID = alloc.JobID
alloc2.PreviousAllocation = alloc.ID
if err := state.UpsertAllocs(200, []*structs.Allocation{alloc2}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 200, []*structs.Allocation{alloc2}); err != nil {
t.Fatalf("err: %v", err)
}
@ -839,7 +839,7 @@ func TestClient_BlockedAllocations(t *testing.T) {
// Change the desired state of the parent alloc to stop
alloc1 := alloc.Copy()
alloc1.DesiredStatus = structs.AllocDesiredStatusStop
if err := state.UpsertAllocs(300, []*structs.Allocation{alloc1}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 300, []*structs.Allocation{alloc1}); err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -383,7 +383,7 @@ func TestAllocGarbageCollector_MakeRoomFor_MaxAllocs(t *testing.T) {
upsertJobFn := func(server *nomad.Server, j *structs.Job) {
state := server.State()
require.NoError(state.UpsertJob(nextIndex(), j))
require.NoError(state.UpsertJob(structs.MsgTypeTestSetup, nextIndex(), j))
require.NoError(state.UpsertJobSummary(nextIndex(), mock.JobSummary(j.ID)))
}
@ -392,7 +392,7 @@ func TestAllocGarbageCollector_MakeRoomFor_MaxAllocs(t *testing.T) {
upsertAllocFn := func(server *nomad.Server, a *structs.Allocation) {
state := server.State()
require.NoError(state.UpsertAllocs(nextIndex(), []*structs.Allocation{a}))
require.NoError(state.UpsertAllocs(structs.MsgTypeTestSetup, nextIndex(), []*structs.Allocation{a}))
}
upsertNewAllocFn := func(server *nomad.Server, j *structs.Job) *structs.Allocation {

View File

@ -43,8 +43,7 @@ func TestHTTP_AllocsList(t *testing.T) {
state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID))
state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(1000,
[]*structs.Allocation{alloc1, alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -112,8 +111,7 @@ func TestHTTP_AllocsPrefixList(t *testing.T) {
if err := state.UpsertJobSummary(999, summary2); err != nil {
t.Fatal(err)
}
if err := state.UpsertAllocs(1000,
[]*structs.Allocation{alloc1, alloc2}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2}); err != nil {
t.Fatalf("err: %v", err)
}
@ -167,8 +165,7 @@ func TestHTTP_AllocQuery(t *testing.T) {
if err := state.UpsertJobSummary(999, mock.JobSummary(alloc.JobID)); err != nil {
t.Fatal(err)
}
err := state.UpsertAllocs(1000,
[]*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -220,7 +217,7 @@ func TestHTTP_AllocQuery_Payload(t *testing.T) {
compressed := snappy.Encode(nil, expected)
alloc.Job.Payload = compressed
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -404,7 +401,7 @@ func TestHTTP_AllocStop(t *testing.T) {
require := require.New(t)
require.NoError(state.UpsertJobSummary(999, mock.JobSummary(alloc.JobID)))
require.NoError(state.UpsertAllocs(1000, []*structs.Allocation{alloc}))
require.NoError(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc}))
// Test that the happy path works
{
@ -629,7 +626,7 @@ func TestHTTP_AllocSnapshot_Atomic(t *testing.T) {
}
alloc.NodeID = s.client.NodeID()
state.UpsertJobSummary(998, mock.JobSummary(alloc.JobID))
if err := state.UpsertAllocs(1000, []*structs.Allocation{alloc.Copy()}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc.Copy()}); err != nil {
t.Fatalf("error upserting alloc: %v", err)
}

View File

@ -107,9 +107,9 @@ func TestHTTP_DeploymentAllocations(t *testing.T) {
a2.TaskStates = make(map[string]*structs.TaskState)
a2.TaskStates["test"] = taskState2
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(999, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a1, a2}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a1, a2}), "UpsertAllocs")
// Make the HTTP request
req, err := http.NewRequest("GET", "/v1/deployment/allocations/"+d.ID, nil)
@ -174,7 +174,7 @@ func TestHTTP_DeploymentPause(t *testing.T) {
j := mock.Job()
d := mock.Deployment()
d.JobID = j.ID
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Create the pause request
@ -215,7 +215,7 @@ func TestHTTP_DeploymentPromote(t *testing.T) {
j := mock.Job()
d := mock.Deployment()
d.JobID = j.ID
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Create the pause request
@ -259,9 +259,9 @@ func TestHTTP_DeploymentAllocHealth(t *testing.T) {
a := mock.Alloc()
a.JobID = j.ID
a.DeploymentID = d.ID
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(999, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}), "UpsertAllocs")
// Create the pause request
args := structs.DeploymentAllocHealthRequest{
@ -301,7 +301,7 @@ func TestHTTP_DeploymentFail(t *testing.T) {
j := mock.Job()
d := mock.Deployment()
d.JobID = j.ID
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(999, d), "UpsertDeployment")
// Make the HTTP request

View File

@ -16,8 +16,7 @@ func TestHTTP_EvalList(t *testing.T) {
state := s.Agent.server.State()
eval1 := mock.Eval()
eval2 := mock.Eval()
err := state.UpsertEvals(1000,
[]*structs.Evaluation{eval1, eval2})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -63,8 +62,7 @@ func TestHTTP_EvalPrefixList(t *testing.T) {
eval1.ID = "aaabbbbb-e8f7-fd38-c855-ab94ceb89706"
eval2 := mock.Eval()
eval2.ID = "aaabbbbb-e8f7-fd38-c855-ab94ceb89706"
err := state.UpsertEvals(1000,
[]*structs.Evaluation{eval1, eval2})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -116,8 +114,7 @@ func TestHTTP_EvalAllocations(t *testing.T) {
alloc2.EvalID = alloc1.EvalID
state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID))
state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(1000,
[]*structs.Allocation{alloc1, alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -161,7 +158,7 @@ func TestHTTP_EvalQuery(t *testing.T) {
// Directly manipulate the state
state := s.Agent.server.State()
eval := mock.Eval()
err := state.UpsertEvals(1000, []*structs.Evaluation{eval})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -62,8 +62,8 @@ func addAllocToClient(agent *TestAgent, alloc *structs.Allocation, wait clientAl
// Upsert the allocation
state := agent.server.State()
require.Nil(state.UpsertJob(999, alloc.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{alloc}))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, alloc.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{alloc}))
if wait == noWaitClientAlloc {
return

View File

@ -407,7 +407,7 @@ func TestHTTP_JobQuery_Payload(t *testing.T) {
// Directly manipulate the state
state := s.Agent.server.State()
if err := state.UpsertJob(1000, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job); err != nil {
t.Fatalf("Failed to upsert job: %v", err)
}
@ -1007,7 +1007,7 @@ func TestHTTP_JobAllocations(t *testing.T) {
alloc1.TaskStates = make(map[string]*structs.TaskState)
alloc1.TaskStates["test"] = taskState
state := s.Agent.server.State()
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -139,7 +139,7 @@ func TestHTTP_NodeForceEval(t *testing.T) {
if err := state.UpsertJobSummary(999, mock.JobSummary(alloc1.JobID)); err != nil {
t.Fatal(err)
}
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -199,7 +199,7 @@ func TestHTTP_NodeAllocations(t *testing.T) {
alloc1.TaskStates = make(map[string]*structs.TaskState)
alloc1.TaskStates["test"] = taskState
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -387,7 +387,7 @@ func TestHTTP_NodePurge(t *testing.T) {
if err := state.UpsertJobSummary(999, mock.JobSummary(alloc1.JobID)); err != nil {
t.Fatal(err)
}
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -31,7 +31,7 @@ func createJobForTest(jobID string, s *TestAgent, t *testing.T) {
job.TaskGroups[0].Count = 1
state := s.Agent.server.State()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
assert.Nil(err)
}
@ -147,8 +147,7 @@ func TestHTTP_Search_Evaluation(t *testing.T) {
state := s.Agent.server.State()
eval1 := mock.Eval()
eval2 := mock.Eval()
err := state.UpsertEvals(9000,
[]*structs.Evaluation{eval1, eval2})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 9000, []*structs.Evaluation{eval1, eval2})
assert.Nil(err)
prefix := eval1.ID[:len(eval1.ID)-2]
@ -182,7 +181,7 @@ func TestHTTP_Search_Allocations(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
state := s.Agent.server.State()
alloc := mock.Alloc()
err := state.UpsertAllocs(7000, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 7000, []*structs.Allocation{alloc})
assert.Nil(err)
prefix := alloc.ID[:len(alloc.ID)-2]
@ -215,7 +214,7 @@ func TestHTTP_Search_Nodes(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
state := s.Agent.server.State()
node := mock.Node()
err := state.UpsertNode(6000, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 6000, node)
assert.Nil(err)
prefix := node.ID[:len(node.ID)-2]
@ -307,7 +306,7 @@ func TestHTTP_Search_AllContext(t *testing.T) {
state := s.Agent.server.State()
eval1 := mock.Eval()
eval1.ID = testJobID
err := state.UpsertEvals(8000, []*structs.Evaluation{eval1})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 8000, []*structs.Evaluation{eval1})
assert.Nil(err)
data := structs.SearchRequest{Prefix: testJobPrefix, Context: structs.All}

View File

@ -145,7 +145,7 @@ func TestAllocExecCommand_AutocompleteArgs(t *testing.T) {
// Create a fake alloc
state := srv.Agent.Server().State()
a := mock.Alloc()
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
prefix := a.ID[:5]
args := complete.Args{Last: prefix}

View File

@ -100,7 +100,7 @@ func TestFSCommand_AutocompleteArgs(t *testing.T) {
// Create a fake alloc
state := srv.Agent.Server().State()
a := mock.Alloc()
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
prefix := a.ID[:5]
args := complete.Args{Last: prefix}

View File

@ -82,7 +82,7 @@ func TestLogsCommand_AutocompleteArgs(t *testing.T) {
// Create a fake alloc
state := srv.Agent.Server().State()
a := mock.Alloc()
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
prefix := a.ID[:5]
args := complete.Args{Last: prefix}

View File

@ -163,7 +163,7 @@ func TestAllocRestartCommand_AutocompleteArgs(t *testing.T) {
// Create a fake alloc
state := srv.Agent.Server().State()
a := mock.Alloc()
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
prefix := a.ID[:5]
args := complete.Args{Last: prefix}

View File

@ -68,7 +68,7 @@ func TestAllocSignalCommand_AutocompleteArgs(t *testing.T) {
// Create a fake alloc
state := srv.Agent.Server().State()
a := mock.Alloc()
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
prefix := a.ID[:5]
args := complete.Args{All: []string{"signal", prefix}, Last: prefix}

View File

@ -138,7 +138,7 @@ func TestAllocStatusCommand_LifecycleInfo(t *testing.T) {
"prestart_sidecar": &structs.TaskState{State: "running"},
}
require.Nil(t, state.UpsertAllocs(1000, []*structs.Allocation{a}))
require.Nil(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
if code := cmd.Run([]string{"-address=" + url, a.ID}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
@ -286,7 +286,7 @@ func TestAllocStatusCommand_RescheduleInfo(t *testing.T) {
},
},
}
require.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
if code := cmd.Run([]string{"-address=" + url, a.ID}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
@ -343,7 +343,7 @@ func TestAllocStatusCommand_ScoreMetrics(t *testing.T) {
},
},
}
require.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
if code := cmd.Run([]string{"-address=" + url, "-verbose", a.ID}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
@ -371,7 +371,7 @@ func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {
// Create a fake alloc
state := srv.Agent.Server().State()
a := mock.Alloc()
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
prefix := a.ID[:5]
args := complete.Args{Last: prefix}
@ -437,7 +437,7 @@ func TestAllocStatusCommand_HostVolumes(t *testing.T) {
}
summary := mock.JobSummary(alloc.JobID)
require.NoError(t, state.UpsertJobSummary(1004, summary))
require.NoError(t, state.UpsertAllocs(1005, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1005, []*structs.Allocation{alloc}))
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
@ -466,7 +466,7 @@ func TestAllocStatusCommand_CSIVolumes(t *testing.T) {
NodeInfo: &structs.CSINodeInfo{},
},
}
err := state.UpsertNode(1001, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1001, node)
require.NoError(t, err)
vols := []*structs.CSIVolume{{
@ -512,7 +512,7 @@ func TestAllocStatusCommand_CSIVolumes(t *testing.T) {
}
summary := mock.JobSummary(alloc.JobID)
require.NoError(t, state.UpsertJobSummary(1004, summary))
require.NoError(t, state.UpsertAllocs(1005, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1005, []*structs.Allocation{alloc}))
ui := cli.NewMockUi()
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}

View File

@ -74,7 +74,7 @@ func TestEvalStatusCommand_AutocompleteArgs(t *testing.T) {
// Create a fake eval
state := srv.Agent.Server().State()
e := mock.Eval()
assert.Nil(state.UpsertEvals(1000, []*structs.Evaluation{e}))
assert.Nil(state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{e}))
prefix := e.ID[:5]
args := complete.Args{Last: prefix}

View File

@ -4,6 +4,8 @@ import (
"strings"
"testing"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/mitchellh/cli"
"github.com/posener/complete"
@ -55,7 +57,7 @@ func TestJobDeploymentsCommand_Run(t *testing.T) {
// Create a job without a deployment
job := mock.Job()
state := srv.Agent.Server().State()
assert.Nil(state.UpsertJob(100, job))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 100, job))
// Should display no match if the job doesn't have deployments
if code := cmd.Run([]string{"-address=" + url, job.ID}); code != 0 {
@ -99,7 +101,7 @@ func TestJobDeploymentsCommand_Run_Latest(t *testing.T) {
// Create a job without a deployment
job := mock.Job()
state := srv.Agent.Server().State()
assert.Nil(state.UpsertJob(100, job))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 100, job))
// Should display no match if the job doesn't have deployments
if code := cmd.Run([]string{"-address=" + url, "-latest", job.ID}); code != 0 {
@ -139,7 +141,7 @@ func TestJobDeploymentsCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -4,6 +4,8 @@ import (
"strings"
"testing"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/mitchellh/cli"
"github.com/posener/complete"
@ -60,7 +62,7 @@ func TestJobDispatchCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -74,7 +74,7 @@ func TestJobEvalCommand_Run(t *testing.T) {
// Create a job
job := mock.Job()
err := state.UpsertJob(11, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 11, job)
require.Nil(err)
job, err = state.JobByID(nil, structs.DefaultNamespace, job.ID)
@ -87,7 +87,7 @@ func TestJobEvalCommand_Run(t *testing.T) {
alloc.TaskGroup = job.TaskGroups[0].Name
alloc.Namespace = job.Namespace
alloc.ClientStatus = structs.AllocClientStatusFailed
err = state.UpsertAllocs(12, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 12, []*structs.Allocation{alloc})
require.Nil(err)
if code := cmd.Run([]string{"-address=" + url, "-force-reschedule", "-detach", job.ID}); code != 0 {
@ -115,7 +115,7 @@ func TestJobEvalCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -4,6 +4,8 @@ import (
"strings"
"testing"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/mitchellh/cli"
"github.com/posener/complete"
@ -51,7 +53,7 @@ func TestJobHistoryCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -5,6 +5,7 @@ import (
"testing"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/mitchellh/cli"
"github.com/posener/complete"
"github.com/stretchr/testify/assert"
@ -71,7 +72,7 @@ func TestInspectCommand_AutocompleteArgs(t *testing.T) {
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -49,7 +49,7 @@ func TestJobPeriodicForceCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job, not periodic
state := srv.Agent.Server().State()
j := mock.Job()
require.NoError(t, state.UpsertJob(1000, j))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
predictor := cmd.AutocompleteArgs()
@ -66,7 +66,7 @@ func TestJobPeriodicForceCommand_AutocompleteArgs(t *testing.T) {
ProhibitOverlap: true,
TimeZone: "test zone",
}
require.NoError(t, state.UpsertJob(1000, j2))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1000, j2))
res = predictor.Predict(complete.Args{Last: j2.ID[:len(j.ID)-5]})
require.Equal(t, []string{j2.ID}, res)

View File

@ -4,6 +4,8 @@ import (
"strings"
"testing"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/mitchellh/cli"
"github.com/posener/complete"
@ -51,7 +53,7 @@ func TestJobPromoteCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -5,6 +5,7 @@ import (
"testing"
"github.com/hashicorp/nomad/nomad/mock"
structs "github.com/hashicorp/nomad/nomad/structs"
"github.com/mitchellh/cli"
"github.com/posener/complete"
"github.com/stretchr/testify/assert"
@ -51,7 +52,7 @@ func TestJobRevertCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -254,7 +254,7 @@ func TestJobStatusCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}
@ -361,11 +361,11 @@ func TestJobStatusCommand_RescheduleEvals(t *testing.T) {
// Create state store objects for job, alloc and followup eval with a future WaitUntil value
j := mock.Job()
require.Nil(state.UpsertJob(900, j))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 900, j))
e := mock.Eval()
e.WaitUntil = time.Now().Add(1 * time.Hour)
require.Nil(state.UpsertEvals(902, []*structs.Evaluation{e}))
require.Nil(state.UpsertEvals(structs.MsgTypeTestSetup, 902, []*structs.Evaluation{e}))
a := mock.Alloc()
a.Job = j
a.JobID = j.ID
@ -374,7 +374,7 @@ func TestJobStatusCommand_RescheduleEvals(t *testing.T) {
a.Metrics = &structs.AllocMetric{}
a.DesiredStatus = structs.AllocDesiredStatusRun
a.ClientStatus = structs.AllocClientStatusRunning
require.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a}))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}))
// Query jobs with prefix match
if code := cmd.Run([]string{"-address=" + url, j.ID}); code != 0 {

View File

@ -5,6 +5,7 @@ import (
"testing"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/mitchellh/cli"
"github.com/posener/complete"
"github.com/stretchr/testify/assert"
@ -63,7 +64,7 @@ func TestStopCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -26,7 +26,7 @@ func TestStatusCommand_Run_JobStatus(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
j := mock.Job()
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
// Query to check the job status
if code := cmd.Run([]string{"-address=" + url, j.ID}); code != 0 {
@ -54,8 +54,8 @@ func TestStatusCommand_Run_JobStatus_MultiMatch(t *testing.T) {
j := mock.Job()
j2 := mock.Job()
j2.ID = fmt.Sprintf("%s-more", j.ID)
assert.Nil(state.UpsertJob(1000, j))
assert.Nil(state.UpsertJob(1001, j2))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1001, j2))
// Query to check the job status
if code := cmd.Run([]string{"-address=" + url, j.ID}); code != 0 {
@ -81,7 +81,7 @@ func TestStatusCommand_Run_EvalStatus(t *testing.T) {
// Create a fake eval
state := srv.Agent.Server().State()
eval := mock.Eval()
assert.Nil(state.UpsertEvals(1000, []*structs.Evaluation{eval}))
assert.Nil(state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval}))
// Query to check the eval status
if code := cmd.Run([]string{"-address=" + url, eval.ID}); code != 0 {
@ -147,7 +147,7 @@ func TestStatusCommand_Run_AllocStatus(t *testing.T) {
// Create a fake alloc
state := srv.Agent.Server().State()
alloc := mock.Alloc()
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{alloc}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc}))
if code := cmd.Run([]string{"-address=" + url, alloc.ID}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
@ -198,7 +198,7 @@ func TestStatusCommand_Run_NoPrefix(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
job := mock.Job()
assert.Nil(state.UpsertJob(1000, job))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, job))
// Query to check status
if code := cmd.Run([]string{"-address=" + url}); code != 0 {
@ -224,7 +224,7 @@ func TestStatusCommand_AutocompleteArgs(t *testing.T) {
// Create a fake job
state := srv.Agent.Server().State()
job := mock.Job()
assert.Nil(state.UpsertJob(1000, job))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, job))
prefix := job.ID[:len(job.ID)-5]
args := complete.Args{Last: prefix}

View File

@ -33,7 +33,7 @@ func TestAllocEndpoint_List(t *testing.T) {
if err := state.UpsertJobSummary(999, summary); err != nil {
t.Fatalf("err: %v", err)
}
if err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -97,7 +97,7 @@ func TestAllocEndpoint_List_Fields(t *testing.T) {
state := s1.fsm.State()
require.NoError(t, state.UpsertJobSummary(999, summary))
require.NoError(t, state.UpsertAllocs(1000, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -192,7 +192,7 @@ func TestAllocEndpoint_List_ACL(t *testing.T) {
state := s1.fsm.State()
assert.Nil(state.UpsertJobSummary(999, summary), "UpsertJobSummary")
assert.Nil(state.UpsertAllocs(1000, allocs), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, allocs), "UpsertAllocs")
stubAllocs := []*structs.AllocListStub{alloc.Stub(nil)}
stubAllocs[0].CreateIndex = 1000
@ -251,7 +251,7 @@ func TestAllocEndpoint_List_Blocking(t *testing.T) {
}
// Upsert alloc triggers watches
time.AfterFunc(100*time.Millisecond, func() {
if err := state.UpsertAllocs(2, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 2, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -326,7 +326,7 @@ func TestAllocEndpoint_List_AllNamespaces_OSS(t *testing.T) {
err := state.UpsertJobSummary(999, summary)
require.NoError(t, err)
err = state.UpsertAllocs(1000, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc})
require.NoError(t, err)
t.Run("looking up all allocations", func(t *testing.T) {
@ -405,7 +405,7 @@ func TestAllocEndpoint_GetAlloc(t *testing.T) {
}
state := s1.fsm.State()
state.UpsertJobSummary(999, mock.JobSummary(alloc.JobID))
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -444,7 +444,7 @@ func TestAllocEndpoint_GetAlloc_ACL(t *testing.T) {
state := s1.fsm.State()
assert.Nil(state.UpsertJobSummary(999, summary), "UpsertJobSummary")
assert.Nil(state.UpsertAllocs(1000, allocs), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, allocs), "UpsertAllocs")
// Create the namespace policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid",
@ -494,7 +494,7 @@ func TestAllocEndpoint_GetAlloc_ACL(t *testing.T) {
Name: "valid-node-secret",
F: func(t *testing.T) {
node := mock.Node()
assert.Nil(state.UpsertNode(1005, node))
assert.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1005, node))
get := getReq()
get.AuthToken = node.SecretID
get.AllocID = alloc.ID
@ -555,7 +555,7 @@ func TestAllocEndpoint_GetAlloc_Blocking(t *testing.T) {
// First create an unrelated alloc
time.AfterFunc(100*time.Millisecond, func() {
state.UpsertJobSummary(99, mock.JobSummary(alloc1.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -564,7 +564,7 @@ func TestAllocEndpoint_GetAlloc_Blocking(t *testing.T) {
// Create the alloc we are watching later
time.AfterFunc(200*time.Millisecond, func() {
state.UpsertJobSummary(199, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(200, []*structs.Allocation{alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 200, []*structs.Allocation{alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -609,7 +609,7 @@ func TestAllocEndpoint_GetAllocs(t *testing.T) {
state := s1.fsm.State()
state.UpsertJobSummary(998, mock.JobSummary(alloc.JobID))
state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc, alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -659,7 +659,7 @@ func TestAllocEndpoint_GetAllocs_Blocking(t *testing.T) {
// First create an unrelated alloc
time.AfterFunc(100*time.Millisecond, func() {
state.UpsertJobSummary(99, mock.JobSummary(alloc1.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -668,7 +668,7 @@ func TestAllocEndpoint_GetAllocs_Blocking(t *testing.T) {
// Create the alloc we are watching later
time.AfterFunc(200*time.Millisecond, func() {
state.UpsertJobSummary(199, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(200, []*structs.Allocation{alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 200, []*structs.Allocation{alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -714,7 +714,7 @@ func TestAllocEndpoint_UpdateDesiredTransition(t *testing.T) {
state := s1.fsm.State()
require.Nil(state.UpsertJobSummary(998, mock.JobSummary(alloc.JobID)))
require.Nil(state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID)))
require.Nil(state.UpsertAllocs(1000, []*structs.Allocation{alloc, alloc2}))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc, alloc2}))
t1 := &structs.DesiredTransition{
Migrate: helper.BoolToPtr(true),
@ -798,7 +798,7 @@ func TestAllocEndpoint_Stop_ACL(t *testing.T) {
state := s1.fsm.State()
require.Nil(state.UpsertJobSummary(998, mock.JobSummary(alloc.JobID)))
require.Nil(state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID)))
require.Nil(state.UpsertAllocs(1000, []*structs.Allocation{alloc, alloc2}))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc, alloc2}))
req := &structs.AllocStopRequest{
AllocID: alloc.ID,

View File

@ -162,7 +162,7 @@ func TestClientAllocations_GarbageCollectAll_OldNode(t *testing.T) {
// Test for an old version error
node := mock.Node()
node.Attributes["nomad.version"] = "0.7.1"
require.Nil(state.UpsertNode(1005, node))
require.Nil(state.UpsertNode(nstructs.MsgTypeTestSetup, 1005, node))
req := &structs.NodeSpecificRequest{
NodeID: node.ID,
@ -175,7 +175,7 @@ func TestClientAllocations_GarbageCollectAll_OldNode(t *testing.T) {
// Test for a missing version error
delete(node.Attributes, "nomad.version")
require.Nil(state.UpsertNode(1006, node))
require.Nil(state.UpsertNode(nstructs.MsgTypeTestSetup, 1006, node))
err = msgpackrpc.CallWithCodec(codec, "ClientAllocations.GarbageCollectAll", req, &resp)
require.True(structs.IsErrUnknownNomadVersion(err))
@ -255,11 +255,11 @@ func TestClientAllocations_GarbageCollect_OldNode(t *testing.T) {
// Test for an old version error
node := mock.Node()
node.Attributes["nomad.version"] = "0.7.1"
require.Nil(state.UpsertNode(1005, node))
require.Nil(state.UpsertNode(nstructs.MsgTypeTestSetup, 1005, node))
alloc := mock.Alloc()
alloc.NodeID = node.ID
require.Nil(state.UpsertAllocs(1006, []*structs.Allocation{alloc}))
require.Nil(state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1006, []*structs.Allocation{alloc}))
req := &structs.AllocSpecificRequest{
AllocID: alloc.ID,
@ -275,7 +275,7 @@ func TestClientAllocations_GarbageCollect_OldNode(t *testing.T) {
// Test for a missing version error
delete(node.Attributes, "nomad.version")
require.Nil(state.UpsertNode(1007, node))
require.Nil(state.UpsertNode(nstructs.MsgTypeTestSetup, 1007, node))
err = msgpackrpc.CallWithCodec(codec, "ClientAllocations.GarbageCollect", req, &resp)
require.True(structs.IsErrUnknownNomadVersion(err), err.Error())
@ -324,8 +324,8 @@ func TestClientAllocations_GarbageCollect_Local(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -382,8 +382,8 @@ func TestClientAllocations_GarbageCollect_Local_ACL(t *testing.T) {
// Upsert the allocation
state := s.State()
alloc := mock.Alloc()
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(nstructs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -492,10 +492,10 @@ func TestClientAllocations_GarbageCollect_Remote(t *testing.T) {
// Upsert the allocation
state1 := s1.State()
state2 := s2.State()
require.Nil(state1.UpsertJob(999, a.Job))
require.Nil(state1.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state1.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state1.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -546,11 +546,11 @@ func TestClientAllocations_Stats_OldNode(t *testing.T) {
// Test for an old version error
node := mock.Node()
node.Attributes["nomad.version"] = "0.7.1"
require.Nil(state.UpsertNode(1005, node))
require.Nil(state.UpsertNode(nstructs.MsgTypeTestSetup, 1005, node))
alloc := mock.Alloc()
alloc.NodeID = node.ID
require.Nil(state.UpsertAllocs(1006, []*structs.Allocation{alloc}))
require.Nil(state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1006, []*structs.Allocation{alloc}))
req := &structs.AllocSpecificRequest{
AllocID: alloc.ID,
@ -565,7 +565,7 @@ func TestClientAllocations_Stats_OldNode(t *testing.T) {
// Test for a missing version error
delete(node.Attributes, "nomad.version")
require.Nil(state.UpsertNode(1007, node))
require.Nil(state.UpsertNode(nstructs.MsgTypeTestSetup, 1007, node))
err = msgpackrpc.CallWithCodec(codec, "ClientAllocations.Stats", req, &resp)
require.True(structs.IsErrUnknownNomadVersion(err), err.Error())
@ -613,8 +613,8 @@ func TestClientAllocations_Stats_Local(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -672,8 +672,8 @@ func TestClientAllocations_Stats_Local_ACL(t *testing.T) {
// Upsert the allocation
state := s.State()
alloc := mock.Alloc()
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(nstructs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -769,10 +769,10 @@ func TestClientAllocations_Stats_Remote(t *testing.T) {
// Upsert the allocation
state1 := s1.State()
state2 := s2.State()
require.Nil(state1.UpsertJob(999, a.Job))
require.Nil(state1.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state1.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state1.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -853,8 +853,8 @@ func TestClientAllocations_Restart_Local(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -967,10 +967,10 @@ func TestClientAllocations_Restart_Remote(t *testing.T) {
// Upsert the allocation
state1 := s1.State()
state2 := s2.State()
require.Nil(state1.UpsertJob(999, a.Job))
require.Nil(state1.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state1.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state1.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -1026,8 +1026,8 @@ func TestClientAllocations_Restart_ACL(t *testing.T) {
// Upsert the allocation
state := s.State()
alloc := mock.Alloc()
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(nstructs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(nstructs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -1134,11 +1134,11 @@ func TestAlloc_ExecStreaming(t *testing.T) {
// Upsert the allocation
localState := localServer.State()
require.Nil(t, localState.UpsertJob(999, a.Job))
require.Nil(t, localState.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(t, localState.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(t, localState.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
remoteState := remoteServer.State()
require.Nil(t, remoteState.UpsertJob(999, a.Job))
require.Nil(t, remoteState.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(t, remoteState.UpsertJob(nstructs.MsgTypeTestSetup, 999, a.Job))
require.Nil(t, remoteState.UpsertAllocs(nstructs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {

View File

@ -141,11 +141,11 @@ func TestClientCSI_NodeForControllerPlugin(t *testing.T) {
node3 := mock.Node()
node3.ID = uuid.Generate()
err := state.UpsertNode(1002, node1)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1002, node1)
require.NoError(t, err)
err = state.UpsertNode(1003, node2)
err = state.UpsertNode(structs.MsgTypeTestSetup, 1003, node2)
require.NoError(t, err)
err = state.UpsertNode(1004, node3)
err = state.UpsertNode(structs.MsgTypeTestSetup, 1004, node3)
require.NoError(t, err)
ws := memdb.NewWatchSet()
@ -221,7 +221,7 @@ func setupForward(t *testing.T) (rpc.ClientCodec, func()) {
node1.Attributes["nomad.version"] = "0.11.0" // client RPCs not supported on early versions
node1.CSIControllerPlugins = plugins
s1.fsm.state.UpsertNode(1000, node1)
s1.fsm.state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1)
cleanup := func() {
cleanupS1()
@ -270,7 +270,7 @@ func setupLocal(t *testing.T) (rpc.ClientCodec, func()) {
node1.Attributes["nomad.version"] = "0.11.0" // client RPCs not supported on early versions
node1.CSIControllerPlugins = plugins
s1.fsm.state.UpsertNode(1000, node1)
s1.fsm.state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1)
cleanup := func() {
cleanupS1()

View File

@ -64,8 +64,8 @@ func TestClientFS_List_Local(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -124,8 +124,8 @@ func TestClientFS_List_ACL(t *testing.T) {
// Upsert the allocation
state := s.State()
alloc := mock.Alloc()
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -224,10 +224,10 @@ func TestClientFS_List_Remote(t *testing.T) {
// Upsert the allocation
state1 := s1.State()
state2 := s2.State()
require.Nil(state1.UpsertJob(999, a.Job))
require.Nil(state1.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state1.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state1.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -280,11 +280,11 @@ func TestClientFS_Stat_OldNode(t *testing.T) {
// Test for an old version error
node := mock.Node()
node.Attributes["nomad.version"] = "0.7.1"
require.Nil(state.UpsertNode(1005, node))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1005, node))
alloc := mock.Alloc()
alloc.NodeID = node.ID
require.Nil(state.UpsertAllocs(1006, []*structs.Allocation{alloc}))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1006, []*structs.Allocation{alloc}))
req := &cstructs.FsStatRequest{
AllocID: alloc.ID,
@ -340,8 +340,8 @@ func TestClientFS_Stat_Local(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -400,8 +400,8 @@ func TestClientFS_Stat_ACL(t *testing.T) {
// Upsert the allocation
state := s.State()
alloc := mock.Alloc()
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -500,10 +500,10 @@ func TestClientFS_Stat_Remote(t *testing.T) {
// Upsert the allocation
state1 := s1.State()
state2 := s2.State()
require.Nil(state1.UpsertJob(999, a.Job))
require.Nil(state1.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state1.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state1.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -632,8 +632,8 @@ func TestClientFS_Streaming_ACL(t *testing.T) {
// Upsert the allocation
state := s.State()
alloc := mock.Alloc()
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -773,8 +773,8 @@ func TestClientFS_Streaming_Local(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -909,8 +909,8 @@ func TestClientFS_Streaming_Local_Follow(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -1052,10 +1052,10 @@ func TestClientFS_Streaming_Remote_Server(t *testing.T) {
// Upsert the allocation
state1 := s1.State()
state2 := s2.State()
require.Nil(state1.UpsertJob(999, a.Job))
require.Nil(state1.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state1.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state1.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -1198,8 +1198,8 @@ func TestClientFS_Streaming_Remote_Region(t *testing.T) {
// Upsert the allocation
state2 := s2.State()
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -1375,11 +1375,11 @@ func TestClientFS_Logs_OldNode(t *testing.T) {
// Test for an old version error
node := mock.Node()
node.Attributes["nomad.version"] = "0.7.1"
require.Nil(state.UpsertNode(1005, node))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1005, node))
alloc := mock.Alloc()
alloc.NodeID = node.ID
require.Nil(state.UpsertAllocs(1006, []*structs.Allocation{alloc}))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1006, []*structs.Allocation{alloc}))
req := &cstructs.FsLogsRequest{
AllocID: alloc.ID,
@ -1461,8 +1461,8 @@ func TestClientFS_Logs_ACL(t *testing.T) {
// Upsert the allocation
state := s.State()
alloc := mock.Alloc()
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
cases := []struct {
Name string
@ -1602,8 +1602,8 @@ func TestClientFS_Logs_Local(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -1739,8 +1739,8 @@ func TestClientFS_Logs_Local_Follow(t *testing.T) {
// Upsert the allocation
state := s.State()
require.Nil(state.UpsertJob(999, a.Job))
require.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -1883,10 +1883,10 @@ func TestClientFS_Logs_Remote_Server(t *testing.T) {
// Upsert the allocation
state1 := s1.State()
state2 := s2.State()
require.Nil(state1.UpsertJob(999, a.Job))
require.Nil(state1.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state1.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state1.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {
@ -2030,8 +2030,8 @@ func TestClientFS_Logs_Remote_Region(t *testing.T) {
// Upsert the allocation
state2 := s2.State()
require.Nil(state2.UpsertJob(999, a.Job))
require.Nil(state2.UpsertAllocs(1003, []*structs.Allocation{a}))
require.Nil(state2.UpsertJob(structs.MsgTypeTestSetup, 999, a.Job))
require.Nil(state2.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}))
// Wait for the client to run the allocation
testutil.WaitForResult(func() (bool, error) {

View File

@ -155,7 +155,7 @@ func TestClientStats_Stats_OldNode(t *testing.T) {
// Test for an old version error
node := mock.Node()
node.Attributes["nomad.version"] = "0.7.1"
require.Nil(state.UpsertNode(1005, node))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1005, node))
req := &structs.NodeSpecificRequest{
NodeID: node.ID,

View File

@ -32,7 +32,7 @@ func TestCoreScheduler_EvalGC(t *testing.T) {
eval := mock.Eval()
eval.Status = structs.EvalStatusFailed
state.UpsertJobSummary(999, mock.JobSummary(eval.JobID))
err := state.UpsertEvals(1000, []*structs.Evaluation{eval})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval})
require.Nil(err)
// Insert mock job with rescheduling disabled
@ -42,7 +42,7 @@ func TestCoreScheduler_EvalGC(t *testing.T) {
Attempts: 0,
Interval: 0 * time.Second,
}
err = state.UpsertJob(1001, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 1001, job)
require.Nil(err)
// Insert "dead" alloc
@ -59,7 +59,7 @@ func TestCoreScheduler_EvalGC(t *testing.T) {
alloc2.ClientStatus = structs.AllocClientStatusLost
alloc2.JobID = eval.JobID
alloc2.TaskGroup = job.TaskGroups[0].Name
err = state.UpsertAllocs(1001, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -126,21 +126,21 @@ func TestCoreScheduler_EvalGC_ReschedulingAllocs(t *testing.T) {
eval := mock.Eval()
eval.Status = structs.EvalStatusFailed
state.UpsertJobSummary(999, mock.JobSummary(eval.JobID))
err := state.UpsertEvals(1000, []*structs.Evaluation{eval})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval})
require.Nil(err)
// Insert "pending" eval for same job
eval2 := mock.Eval()
eval2.JobID = eval.JobID
state.UpsertJobSummary(999, mock.JobSummary(eval2.JobID))
err = state.UpsertEvals(1003, []*structs.Evaluation{eval2})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1003, []*structs.Evaluation{eval2})
require.Nil(err)
// Insert mock job with default reschedule policy of 2 in 10 minutes
job := mock.Job()
job.ID = eval.JobID
err = state.UpsertJob(1001, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 1001, job)
require.Nil(err)
// Insert failed alloc with an old reschedule attempt, can be GCed
@ -178,7 +178,7 @@ func TestCoreScheduler_EvalGC_ReschedulingAllocs(t *testing.T) {
},
},
}
err = state.UpsertAllocs(1001, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc, alloc2})
require.Nil(err)
// Update the time tables to make this work
@ -231,7 +231,7 @@ func TestCoreScheduler_EvalGC_StoppedJob_Reschedulable(t *testing.T) {
eval := mock.Eval()
eval.Status = structs.EvalStatusFailed
state.UpsertJobSummary(999, mock.JobSummary(eval.JobID))
err := state.UpsertEvals(1000, []*structs.Evaluation{eval})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval})
require.Nil(err)
// Insert mock stopped job with default reschedule policy of 2 in 10 minutes
@ -239,7 +239,7 @@ func TestCoreScheduler_EvalGC_StoppedJob_Reschedulable(t *testing.T) {
job.ID = eval.JobID
job.Stop = true
err = state.UpsertJob(1001, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 1001, job)
require.Nil(err)
// Insert failed alloc with a recent reschedule attempt
@ -258,7 +258,7 @@ func TestCoreScheduler_EvalGC_StoppedJob_Reschedulable(t *testing.T) {
},
},
}
err = state.UpsertAllocs(1001, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})
require.Nil(err)
// Update the time tables to make this work
@ -306,7 +306,7 @@ func TestCoreScheduler_EvalGC_Batch(t *testing.T) {
job := mock.Job()
job.Type = structs.JobTypeBatch
job.Status = structs.JobStatusDead
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -316,7 +316,7 @@ func TestCoreScheduler_EvalGC_Batch(t *testing.T) {
eval.Status = structs.EvalStatusComplete
eval.Type = structs.JobTypeBatch
eval.JobID = job.ID
err = state.UpsertEvals(1001, []*structs.Evaluation{eval})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -336,7 +336,7 @@ func TestCoreScheduler_EvalGC_Batch(t *testing.T) {
alloc2.DesiredStatus = structs.AllocDesiredStatusRun
alloc2.ClientStatus = structs.AllocClientStatusLost
err = state.UpsertAllocs(1002, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -410,7 +410,7 @@ func TestCoreScheduler_EvalGC_Batch_OldVersion(t *testing.T) {
job := mock.Job()
job.Type = structs.JobTypeBatch
job.Status = structs.JobStatusDead
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -420,7 +420,7 @@ func TestCoreScheduler_EvalGC_Batch_OldVersion(t *testing.T) {
eval.Status = structs.EvalStatusComplete
eval.Type = structs.JobTypeBatch
eval.JobID = job.ID
err = state.UpsertEvals(1001, []*structs.Evaluation{eval})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -451,7 +451,7 @@ func TestCoreScheduler_EvalGC_Batch_OldVersion(t *testing.T) {
alloc3.DesiredStatus = structs.AllocDesiredStatusRun
alloc3.ClientStatus = structs.AllocClientStatusLost
err = state.UpsertAllocs(1002, []*structs.Allocation{alloc, alloc2, alloc3})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc, alloc2, alloc3})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -539,7 +539,7 @@ func TestCoreScheduler_EvalGC_BatchStopped(t *testing.T) {
Attempts: 0,
Interval: 0 * time.Second,
}
err := state.UpsertJob(1001, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1001, job)
require.Nil(err)
// Insert "complete" eval
@ -547,7 +547,7 @@ func TestCoreScheduler_EvalGC_BatchStopped(t *testing.T) {
eval.Status = structs.EvalStatusComplete
eval.Type = structs.JobTypeBatch
eval.JobID = job.ID
err = state.UpsertEvals(1002, []*structs.Evaluation{eval})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1002, []*structs.Evaluation{eval})
require.Nil(err)
// Insert "failed" alloc
@ -565,7 +565,7 @@ func TestCoreScheduler_EvalGC_BatchStopped(t *testing.T) {
alloc2.ClientStatus = structs.AllocClientStatusLost
alloc2.TaskGroup = job.TaskGroups[0].Name
err = state.UpsertAllocs(1003, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -630,7 +630,7 @@ func TestCoreScheduler_EvalGC_Partial(t *testing.T) {
eval := mock.Eval()
eval.Status = structs.EvalStatusComplete
state.UpsertJobSummary(999, mock.JobSummary(eval.JobID))
err := state.UpsertEvals(1000, []*structs.Evaluation{eval})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -655,7 +655,7 @@ func TestCoreScheduler_EvalGC_Partial(t *testing.T) {
alloc2.DesiredStatus = structs.AllocDesiredStatusRun
alloc2.ClientStatus = structs.AllocClientStatusLost
err = state.UpsertAllocs(1002, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -665,7 +665,7 @@ func TestCoreScheduler_EvalGC_Partial(t *testing.T) {
alloc3.EvalID = eval.ID
alloc3.JobID = job.ID
state.UpsertJobSummary(1003, mock.JobSummary(alloc3.JobID))
err = state.UpsertAllocs(1004, []*structs.Allocation{alloc3})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1004, []*structs.Allocation{alloc3})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -675,7 +675,7 @@ func TestCoreScheduler_EvalGC_Partial(t *testing.T) {
Attempts: 0,
Interval: 0 * time.Second,
}
err = state.UpsertJob(1001, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 1001, job)
require.Nil(err)
// Update the time tables to make this work
@ -755,7 +755,7 @@ func TestCoreScheduler_EvalGC_Force(t *testing.T) {
eval := mock.Eval()
eval.Status = structs.EvalStatusFailed
state.UpsertJobSummary(999, mock.JobSummary(eval.JobID))
err := state.UpsertEvals(1000, []*structs.Evaluation{eval})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -767,7 +767,7 @@ func TestCoreScheduler_EvalGC_Force(t *testing.T) {
Attempts: 0,
Interval: 0 * time.Second,
}
err = state.UpsertJob(1001, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 1001, job)
require.Nil(err)
// Insert "dead" alloc
@ -776,7 +776,7 @@ func TestCoreScheduler_EvalGC_Force(t *testing.T) {
alloc.DesiredStatus = structs.AllocDesiredStatusStop
alloc.TaskGroup = job.TaskGroups[0].Name
state.UpsertJobSummary(1001, mock.JobSummary(alloc.JobID))
err = state.UpsertAllocs(1002, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -837,7 +837,7 @@ func TestCoreScheduler_NodeGC(t *testing.T) {
state := server.fsm.State()
node := mock.Node()
node.Status = structs.NodeStatusDown
err := state.UpsertNode(1000, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -887,7 +887,7 @@ func TestCoreScheduler_NodeGC_TerminalAllocs(t *testing.T) {
state := s1.fsm.State()
node := mock.Node()
node.Status = structs.NodeStatusDown
err := state.UpsertNode(1000, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -896,7 +896,7 @@ func TestCoreScheduler_NodeGC_TerminalAllocs(t *testing.T) {
alloc := mock.Alloc()
alloc.DesiredStatus = structs.AllocDesiredStatusStop
state.UpsertJobSummary(1001, mock.JobSummary(alloc.JobID))
if err := state.UpsertAllocs(1002, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -943,7 +943,7 @@ func TestCoreScheduler_NodeGC_RunningAllocs(t *testing.T) {
state := s1.fsm.State()
node := mock.Node()
node.Status = structs.NodeStatusDown
err := state.UpsertNode(1000, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -954,7 +954,7 @@ func TestCoreScheduler_NodeGC_RunningAllocs(t *testing.T) {
alloc.DesiredStatus = structs.AllocDesiredStatusRun
alloc.ClientStatus = structs.AllocClientStatusRunning
state.UpsertJobSummary(1001, mock.JobSummary(alloc.JobID))
if err := state.UpsertAllocs(1002, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -1001,7 +1001,7 @@ func TestCoreScheduler_NodeGC_Force(t *testing.T) {
state := s1.fsm.State()
node := mock.Node()
node.Status = structs.NodeStatusDown
err := state.UpsertNode(1000, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1046,7 +1046,7 @@ func TestCoreScheduler_JobGC_OutstandingEvals(t *testing.T) {
job := mock.Job()
job.Type = structs.JobTypeBatch
job.Status = structs.JobStatusDead
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1059,7 +1059,7 @@ func TestCoreScheduler_JobGC_OutstandingEvals(t *testing.T) {
eval2 := mock.Eval()
eval2.JobID = job.ID
eval2.Status = structs.EvalStatusPending
err = state.UpsertEvals(1001, []*structs.Evaluation{eval, eval2})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval, eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1110,7 +1110,7 @@ func TestCoreScheduler_JobGC_OutstandingEvals(t *testing.T) {
// Update the second eval to be terminal
eval2.Status = structs.EvalStatusComplete
err = state.UpsertEvals(1003, []*structs.Evaluation{eval2})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1003, []*structs.Evaluation{eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1174,7 +1174,7 @@ func TestCoreScheduler_JobGC_OutstandingAllocs(t *testing.T) {
Attempts: 0,
Interval: 0 * time.Second,
}
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1183,7 +1183,7 @@ func TestCoreScheduler_JobGC_OutstandingAllocs(t *testing.T) {
eval := mock.Eval()
eval.JobID = job.ID
eval.Status = structs.EvalStatusComplete
err = state.UpsertEvals(1001, []*structs.Evaluation{eval})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1203,7 +1203,7 @@ func TestCoreScheduler_JobGC_OutstandingAllocs(t *testing.T) {
alloc2.ClientStatus = structs.AllocClientStatusRunning
alloc2.TaskGroup = job.TaskGroups[0].Name
err = state.UpsertAllocs(1002, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1254,7 +1254,7 @@ func TestCoreScheduler_JobGC_OutstandingAllocs(t *testing.T) {
// Update the second alloc to be terminal
alloc2.ClientStatus = structs.AllocClientStatusComplete
err = state.UpsertAllocs(1003, []*structs.Allocation{alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1315,7 +1315,7 @@ func TestCoreScheduler_JobGC_OneShot(t *testing.T) {
state := s1.fsm.State()
job := mock.Job()
job.Type = structs.JobTypeBatch
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1329,7 +1329,7 @@ func TestCoreScheduler_JobGC_OneShot(t *testing.T) {
eval2.JobID = job.ID
eval2.Status = structs.EvalStatusComplete
err = state.UpsertEvals(1001, []*structs.Evaluation{eval, eval2})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval, eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1345,7 +1345,7 @@ func TestCoreScheduler_JobGC_OneShot(t *testing.T) {
alloc2.EvalID = eval2.ID
alloc2.DesiredStatus = structs.AllocDesiredStatusRun
err = state.UpsertAllocs(1002, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1432,7 +1432,7 @@ func TestCoreScheduler_JobGC_Stopped(t *testing.T) {
Attempts: 0,
Interval: 0 * time.Second,
}
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1446,7 +1446,7 @@ func TestCoreScheduler_JobGC_Stopped(t *testing.T) {
eval2.JobID = job.ID
eval2.Status = structs.EvalStatusComplete
err = state.UpsertEvals(1001, []*structs.Evaluation{eval, eval2})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval, eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1457,7 +1457,7 @@ func TestCoreScheduler_JobGC_Stopped(t *testing.T) {
alloc.EvalID = eval.ID
alloc.DesiredStatus = structs.AllocDesiredStatusStop
alloc.TaskGroup = job.TaskGroups[0].Name
err = state.UpsertAllocs(1002, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1537,7 +1537,7 @@ func TestCoreScheduler_JobGC_Force(t *testing.T) {
job := mock.Job()
job.Type = structs.JobTypeBatch
job.Status = structs.JobStatusDead
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1546,7 +1546,7 @@ func TestCoreScheduler_JobGC_Force(t *testing.T) {
eval := mock.Eval()
eval.JobID = job.ID
eval.Status = structs.EvalStatusComplete
err = state.UpsertEvals(1001, []*structs.Evaluation{eval})
err = state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1605,7 +1605,7 @@ func TestCoreScheduler_JobGC_Parameterized(t *testing.T) {
job.ParameterizedJob = &structs.ParameterizedJobConfig{
Payload: structs.DispatchPayloadRequired,
}
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1637,7 +1637,7 @@ func TestCoreScheduler_JobGC_Parameterized(t *testing.T) {
// Mark the job as stopped and try again
job2 := job.Copy()
job2.Stop = true
err = state.UpsertJob(2000, job2)
err = state.UpsertJob(structs.MsgTypeTestSetup, 2000, job2)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1680,7 +1680,7 @@ func TestCoreScheduler_JobGC_Periodic(t *testing.T) {
// Insert a parameterized job.
state := s1.fsm.State()
job := mock.PeriodicJob()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1712,7 +1712,7 @@ func TestCoreScheduler_JobGC_Periodic(t *testing.T) {
// Mark the job as stopped and try again
job2 := job.Copy()
job2.Stop = true
err = state.UpsertJob(2000, job2)
err = state.UpsertJob(structs.MsgTypeTestSetup, 2000, job2)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1764,7 +1764,7 @@ func TestCoreScheduler_DeploymentGC(t *testing.T) {
a := mock.Alloc()
a.JobID = d3.JobID
a.DeploymentID = d3.ID
assert.Nil(state.UpsertAllocs(1003, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{a}), "UpsertAllocs")
// Update the time tables to make this work
tt := s1.fsm.TimeTable()
@ -2283,7 +2283,7 @@ func TestCoreScheduler_CSIVolumeClaimGC(t *testing.T) {
},
}
index++
err := state.UpsertNode(index, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, index, node)
require.NoError(err)
// Note that for volume writes in this test we need to use the
@ -2318,14 +2318,14 @@ func TestCoreScheduler_CSIVolumeClaimGC(t *testing.T) {
index++
state.UpsertJobSummary(index, mock.JobSummary(eval.JobID))
index++
err = state.UpsertEvals(index, []*structs.Evaluation{eval})
err = state.UpsertEvals(structs.MsgTypeTestSetup, index, []*structs.Evaluation{eval})
require.Nil(err)
job := mock.Job()
job.ID = eval.JobID
job.Status = structs.JobStatusRunning
index++
err = state.UpsertJob(index, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, index, job)
require.NoError(err)
alloc1, alloc2 := mock.Alloc(), mock.Alloc()
@ -2348,8 +2348,7 @@ func TestCoreScheduler_CSIVolumeClaimGC(t *testing.T) {
index++
require.NoError(state.UpsertJobSummary(index, summary))
index++
require.NoError(state.UpsertAllocs(index,
[]*structs.Allocation{alloc1, alloc2}))
require.NoError(state.UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc1, alloc2}))
// Claim the volume for the alloc
req := &structs.CSIVolumeClaimRequest{

View File

@ -133,7 +133,7 @@ func TestCSIVolumeEndpoint_Register(t *testing.T) {
NodeInfo: &structs.CSINodeInfo{},
},
}
require.NoError(t, state.UpsertNode(1000, node))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1000, node))
// Create the volume
vols := []*structs.CSIVolume{{
@ -232,7 +232,7 @@ func TestCSIVolumeEndpoint_Claim(t *testing.T) {
index++
require.NoError(t, state.UpsertJobSummary(index, summary))
index++
require.NoError(t, state.UpsertAllocs(index, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc}))
// Create an initial volume claim request; we expect it to fail
// because there's no such volume yet.
@ -260,7 +260,7 @@ func TestCSIVolumeEndpoint_Claim(t *testing.T) {
},
}
index++
err = state.UpsertNode(index, node)
err = state.UpsertNode(structs.MsgTypeTestSetup, index, node)
require.NoError(t, err)
vols := []*structs.CSIVolume{{
@ -312,7 +312,7 @@ func TestCSIVolumeEndpoint_Claim(t *testing.T) {
index++
require.NoError(t, state.UpsertJobSummary(index, summary))
index++
require.NoError(t, state.UpsertAllocs(index, []*structs.Allocation{alloc2}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc2}))
claimReq.AllocationID = alloc2.ID
err = msgpackrpc.CallWithCodec(codec, "CSIVolume.Claim", claimReq, claimResp)
require.EqualError(t, err, "volume max claim reached",
@ -346,7 +346,7 @@ func TestCSIVolumeEndpoint_Claim(t *testing.T) {
index++
require.NoError(t, state.UpsertJobSummary(index, summary))
index++
require.NoError(t, state.UpsertAllocs(index, []*structs.Allocation{alloc3}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc3}))
claimReq.AllocationID = alloc3.ID
err = msgpackrpc.CallWithCodec(codec, "CSIVolume.Claim", claimReq, claimResp)
require.NoError(t, err)
@ -401,7 +401,7 @@ func TestCSIVolumeEndpoint_ClaimWithController(t *testing.T) {
NodeInfo: &structs.CSINodeInfo{},
},
}
err := state.UpsertNode(1002, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1002, node)
require.NoError(t, err)
vols := []*structs.CSIVolume{{
ID: id0,
@ -419,7 +419,7 @@ func TestCSIVolumeEndpoint_ClaimWithController(t *testing.T) {
alloc.NodeID = node.ID
summary := mock.JobSummary(alloc.JobID)
require.NoError(t, state.UpsertJobSummary(1004, summary))
require.NoError(t, state.UpsertAllocs(1005, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1005, []*structs.Allocation{alloc}))
// Make the volume claim
claimReq := &structs.CSIVolumeClaimRequest{
@ -481,7 +481,7 @@ func TestCSIVolumeEndpoint_Unpublish(t *testing.T) {
},
}
index++
require.NoError(t, state.UpsertNode(index, node))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, index, node))
type tc struct {
name string
@ -529,7 +529,7 @@ func TestCSIVolumeEndpoint_Unpublish(t *testing.T) {
alloc.ClientStatus = structs.AllocClientStatusFailed
index++
require.NoError(t, state.UpsertAllocs(index, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc}))
// setup: claim the volume for our alloc
claim := &structs.CSIVolumeClaim{
@ -899,7 +899,7 @@ func TestCSI_RPCVolumeAndPluginLookup(t *testing.T) {
node.CSINodePlugins = map[string]*structs.CSIInfo{
"adam": {PluginID: "adam", Healthy: true},
}
err := state.UpsertNode(3, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 3, node)
require.NoError(t, err)
// Create 2 volumes

View File

@ -29,7 +29,7 @@ func TestDeploymentEndpoint_GetDeployment(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Lookup the deployments
@ -61,7 +61,7 @@ func TestDeploymentEndpoint_GetDeployment_ACL(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Create the namespace policy and tokens
@ -118,8 +118,8 @@ func TestDeploymentEndpoint_GetDeployment_Blocking(t *testing.T) {
d2 := mock.Deployment()
d2.JobID = j2.ID
assert.Nil(state.UpsertJob(98, j1), "UpsertJob")
assert.Nil(state.UpsertJob(99, j2), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 98, j1), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 99, j2), "UpsertJob")
// Upsert a deployment we are not interested in first.
time.AfterFunc(100*time.Millisecond, func() {
@ -167,7 +167,7 @@ func TestDeploymentEndpoint_Fail(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Mark the deployment as failed
@ -217,7 +217,7 @@ func TestDeploymentEndpoint_Fail_ACL(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Create the namespace policy and tokens
@ -294,7 +294,7 @@ func TestDeploymentEndpoint_Fail_Rollback(t *testing.T) {
j.TaskGroups[0].Update = structs.DefaultUpdateStrategy.Copy()
j.TaskGroups[0].Update.MaxParallel = 2
j.TaskGroups[0].Update.AutoRevert = true
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
// Create the second job, deployment and alloc
j2 := j.Copy()
@ -311,9 +311,9 @@ func TestDeploymentEndpoint_Fail_Rollback(t *testing.T) {
a.JobID = j.ID
a.DeploymentID = d.ID
assert.Nil(state.UpsertJob(999, j2), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j2), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Mark the deployment as failed
req := &structs.DeploymentFailRequest{
@ -371,7 +371,7 @@ func TestDeploymentEndpoint_Pause(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Mark the deployment as failed
@ -414,7 +414,7 @@ func TestDeploymentEndpoint_Pause_ACL(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Create the namespace policy and tokens
@ -493,9 +493,9 @@ func TestDeploymentEndpoint_Promote(t *testing.T) {
}
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Promote the deployment
req := &structs.DeploymentPromoteRequest{
@ -558,9 +558,9 @@ func TestDeploymentEndpoint_Promote_ACL(t *testing.T) {
}
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Create the namespace policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid",
@ -644,9 +644,9 @@ func TestDeploymentEndpoint_SetAllocHealth(t *testing.T) {
a.DeploymentID = d.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Set the alloc as healthy
req := &structs.DeploymentAllocHealthRequest{
@ -712,9 +712,9 @@ func TestDeploymentEndpoint_SetAllocHealth_ACL(t *testing.T) {
a.DeploymentID = d.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Create the namespace policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid",
@ -802,7 +802,7 @@ func TestDeploymentEndpoint_SetAllocHealth_Rollback(t *testing.T) {
j.TaskGroups[0].Update = structs.DefaultUpdateStrategy.Copy()
j.TaskGroups[0].Update.MaxParallel = 2
j.TaskGroups[0].Update.AutoRevert = true
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
// Create the second job, deployment and alloc
j2 := j.Copy()
@ -818,9 +818,9 @@ func TestDeploymentEndpoint_SetAllocHealth_Rollback(t *testing.T) {
a.JobID = j.ID
a.DeploymentID = d.ID
assert.Nil(state.UpsertJob(999, j2), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j2), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Set the alloc as unhealthy
req := &structs.DeploymentAllocHealthRequest{
@ -892,7 +892,7 @@ func TestDeploymentEndpoint_SetAllocHealth_NoRollback(t *testing.T) {
j.TaskGroups[0].Update = structs.DefaultUpdateStrategy.Copy()
j.TaskGroups[0].Update.MaxParallel = 2
j.TaskGroups[0].Update.AutoRevert = true
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
// Create the second job, deployment and alloc. Job has same spec as original
j2 := j.Copy()
@ -907,9 +907,9 @@ func TestDeploymentEndpoint_SetAllocHealth_NoRollback(t *testing.T) {
a.JobID = j.ID
a.DeploymentID = d.ID
assert.Nil(state.UpsertJob(999, j2), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j2), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Set the alloc as unhealthy
req := &structs.DeploymentAllocHealthRequest{
@ -976,7 +976,7 @@ func TestDeploymentEndpoint_List(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Lookup the deployments
@ -1023,7 +1023,7 @@ func TestDeploymentEndpoint_List_ACL(t *testing.T) {
d.JobID = j.ID
state := s1.fsm.State()
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
// Create the namespace policy and tokens
@ -1092,7 +1092,7 @@ func TestDeploymentEndpoint_List_Blocking(t *testing.T) {
d := mock.Deployment()
d.JobID = j.ID
assert.Nil(state.UpsertJob(999, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 999, j), "UpsertJob")
// Upsert alloc triggers watches
time.AfterFunc(100*time.Millisecond, func() {
@ -1153,10 +1153,10 @@ func TestDeploymentEndpoint_Allocations(t *testing.T) {
summary := mock.JobSummary(a.JobID)
state := s1.fsm.State()
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
assert.Nil(state.UpsertJobSummary(999, summary), "UpsertJobSummary")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Lookup the allocations
get := &structs.DeploymentSpecificRequest{
@ -1191,10 +1191,10 @@ func TestDeploymentEndpoint_Allocations_ACL(t *testing.T) {
summary := mock.JobSummary(a.JobID)
state := s1.fsm.State()
assert.Nil(state.UpsertJob(998, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 998, j), "UpsertJob")
assert.Nil(state.UpsertJobSummary(999, summary), "UpsertJobSummary")
assert.Nil(state.UpsertDeployment(1000, d), "UpsertDeployment")
assert.Nil(state.UpsertAllocs(1001, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{a}), "UpsertAllocs")
// Create the namespace policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid",
@ -1266,13 +1266,13 @@ func TestDeploymentEndpoint_Allocations_Blocking(t *testing.T) {
a.DeploymentID = d.ID
summary := mock.JobSummary(a.JobID)
assert.Nil(state.UpsertJob(1, j), "UpsertJob")
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1, j), "UpsertJob")
assert.Nil(state.UpsertDeployment(2, d), "UpsertDeployment")
assert.Nil(state.UpsertJobSummary(3, summary), "UpsertJobSummary")
// Upsert alloc triggers watches
time.AfterFunc(100*time.Millisecond, func() {
assert.Nil(state.UpsertAllocs(4, []*structs.Allocation{a}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 4, []*structs.Allocation{a}), "UpsertAllocs")
})
req := &structs.DeploymentSpecificRequest{

View File

@ -39,9 +39,9 @@ func TestWatcher_WatchDeployments(t *testing.T) {
// Create three jobs
j1, j2, j3 := mock.Job(), mock.Job(), mock.Job()
require.Nil(m.state.UpsertJob(100, j1))
require.Nil(m.state.UpsertJob(101, j2))
require.Nil(m.state.UpsertJob(102, j3))
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, 100, j1))
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, 101, j2))
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, 102, j3))
// Create three deployments all running
d1, d2, d3 := mock.Deployment(), mock.Deployment(), mock.Deployment()
@ -154,7 +154,7 @@ func TestWatcher_SetAllocHealth_Unknown(t *testing.T) {
j := mock.Job()
d := mock.Deployment()
d.JobID = j.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
// require that we get a call to UpsertDeploymentAllocHealth
@ -200,9 +200,9 @@ func TestWatcher_SetAllocHealth_Healthy(t *testing.T) {
d.JobID = j.ID
a := mock.Alloc()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// require that we get a call to UpsertDeploymentAllocHealth
matchConfig := &matchDeploymentAllocHealthRequestConfig{
@ -245,9 +245,9 @@ func TestWatcher_SetAllocHealth_Unhealthy(t *testing.T) {
d.JobID = j.ID
a := mock.Alloc()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// require that we get a call to UpsertDeploymentAllocHealth
matchConfig := &matchDeploymentAllocHealthRequestConfig{
@ -303,9 +303,9 @@ func TestWatcher_SetAllocHealth_Unhealthy_Rollback(t *testing.T) {
d.TaskGroups["web"].AutoRevert = true
a := mock.Alloc()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// Upsert the job again to get a new version
j2 := j.Copy()
@ -313,7 +313,7 @@ func TestWatcher_SetAllocHealth_Unhealthy_Rollback(t *testing.T) {
// Modify the job to make its specification different
j2.Meta["foo"] = "bar"
require.Nil(m.state.UpsertJob(m.nextIndex(), j2), "UpsertJob2")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j2), "UpsertJob2")
// require that we get a call to UpsertDeploymentAllocHealth
matchConfig := &matchDeploymentAllocHealthRequestConfig{
@ -370,15 +370,15 @@ func TestWatcher_SetAllocHealth_Unhealthy_NoRollback(t *testing.T) {
d.TaskGroups["web"].AutoRevert = true
a := mock.Alloc()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// Upsert the job again to get a new version
j2 := j.Copy()
j2.Stable = false
require.Nil(m.state.UpsertJob(m.nextIndex(), j2), "UpsertJob2")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j2), "UpsertJob2")
// require that we get a call to UpsertDeploymentAllocHealth
matchConfig := &matchDeploymentAllocHealthRequestConfig{
@ -438,9 +438,9 @@ func TestWatcher_PromoteDeployment_HealthyCanaries(t *testing.T) {
Healthy: helper.BoolToPtr(true),
}
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// require that we get a call to UpsertDeploymentPromotion
matchConfig := &matchDeploymentPromoteRequestConfig{
@ -495,9 +495,9 @@ func TestWatcher_PromoteDeployment_UnhealthyCanaries(t *testing.T) {
d.TaskGroups[a.TaskGroup].PlacedCanaries = []string{a.ID}
d.TaskGroups[a.TaskGroup].DesiredCanaries = 2
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// require that we get a call to UpsertDeploymentPromotion
matchConfig := &matchDeploymentPromoteRequestConfig{
@ -574,9 +574,9 @@ func TestWatcher_AutoPromoteDeployment(t *testing.T) {
d.TaskGroups[a.TaskGroup].PlacedCanaries = []string{a.ID, b.ID}
d.TaskGroups[a.TaskGroup].DesiredCanaries = 2
require.NoError(t, m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.NoError(t, m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.NoError(t, m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.NoError(t, m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a, b}), "UpsertAllocs")
require.NoError(t, m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a, b}), "UpsertAllocs")
// =============================================================
// Support method calls
@ -667,7 +667,7 @@ func TestWatcher_PauseDeployment_Pause_Running(t *testing.T) {
j := mock.Job()
d := mock.Deployment()
d.JobID = j.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
// require that we get a call to UpsertDeploymentStatusUpdate
@ -710,7 +710,7 @@ func TestWatcher_PauseDeployment_Pause_Paused(t *testing.T) {
d := mock.Deployment()
d.JobID = j.ID
d.Status = structs.DeploymentStatusPaused
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
// require that we get a call to UpsertDeploymentStatusUpdate
@ -750,7 +750,7 @@ func TestWatcher_PauseDeployment_Unpause_Paused(t *testing.T) {
d := mock.Deployment()
d.JobID = j.ID
d.Status = structs.DeploymentStatusPaused
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
// require that we get a call to UpsertDeploymentStatusUpdate
@ -790,7 +790,7 @@ func TestWatcher_PauseDeployment_Unpause_Running(t *testing.T) {
j := mock.Job()
d := mock.Deployment()
d.JobID = j.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
// require that we get a call to UpsertDeploymentStatusUpdate
@ -830,7 +830,7 @@ func TestWatcher_FailDeployment_Running(t *testing.T) {
j := mock.Job()
d := mock.Deployment()
d.JobID = j.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
// require that we get a call to UpsertDeploymentStatusUpdate
@ -878,16 +878,16 @@ func TestDeploymentWatcher_Watch_NoProgressDeadline(t *testing.T) {
d.TaskGroups["web"].AutoRevert = true
a := mock.Alloc()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// Upsert the job again to get a new version
j2 := j.Copy()
// Modify the job to make its specification different
j2.Meta["foo"] = "bar"
j2.Stable = false
require.Nil(m.state.UpsertJob(m.nextIndex(), j2), "UpsertJob2")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j2), "UpsertJob2")
// require that we will get a update allocation call only once. This will
// verify that the watcher is batching allocation changes
@ -1000,9 +1000,9 @@ func TestDeploymentWatcher_Watch_ProgressDeadline(t *testing.T) {
a.CreateTime = now.UnixNano()
a.ModifyTime = now.UnixNano()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// require that we get a call to UpsertDeploymentStatusUpdate
c := &matchDeploymentStatusUpdateConfig{
@ -1095,9 +1095,9 @@ func TestDeploymentWatcher_ProgressCutoff(t *testing.T) {
a2.ModifyTime = now.UnixNano()
a2.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a, a2}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a, a2}), "UpsertAllocs")
// We may get an update for the desired transition.
m1 := matchUpdateAllocDesiredTransitions([]string{d.ID})
@ -1126,7 +1126,7 @@ func TestDeploymentWatcher_ProgressCutoff(t *testing.T) {
// Update the first allocation to be healthy
a3 := a.Copy()
a3.DeploymentStatus = &structs.AllocDeploymentStatus{Healthy: helper.BoolToPtr(true)}
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a3}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a3}), "UpsertAllocs")
// Get the updated deployment
d2, err := m.state.DeploymentByID(nil, d.ID)
@ -1145,7 +1145,7 @@ func TestDeploymentWatcher_ProgressCutoff(t *testing.T) {
// Update the second allocation to be healthy
a4 := a2.Copy()
a4.DeploymentStatus = &structs.AllocDeploymentStatus{Healthy: helper.BoolToPtr(true)}
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a4}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a4}), "UpsertAllocs")
// Get the updated deployment
d3, err := m.state.DeploymentByID(nil, d.ID)
@ -1189,9 +1189,9 @@ func TestDeploymentWatcher_Watch_ProgressDeadline_Canaries(t *testing.T) {
a.CreateTime = now.UnixNano()
a.ModifyTime = now.UnixNano()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// require that we will get a createEvaluation call only once. This will
// verify that the watcher is batching allocation changes
@ -1281,9 +1281,9 @@ func TestDeploymentWatcher_PromotedCanary_UpdatedAllocs(t *testing.T) {
Healthy: helper.BoolToPtr(true),
Timestamp: now,
}
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
w.SetEnabled(true, m.state)
testutil.WaitForResult(func() (bool, error) { return 1 == watchersCount(w), nil },
@ -1306,7 +1306,7 @@ func TestDeploymentWatcher_PromotedCanary_UpdatedAllocs(t *testing.T) {
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
// Wait until batch eval period passes before updating another alloc
time.Sleep(1 * time.Second)
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a2}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a2}), "UpsertAllocs")
// Wait for the deployment to cross the deadline
dout, err := m.state.DeploymentByID(nil, d.ID)
@ -1354,14 +1354,14 @@ func TestDeploymentWatcher_Watch_StartWithoutProgressDeadline(t *testing.T) {
d := mock.Deployment()
d.JobID = j.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
a := mock.Alloc()
a.CreateTime = time.Now().UnixNano()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
d.TaskGroups["web"].ProgressDeadline = 500 * time.Millisecond
// Update the deployment with a progress deadline
@ -1415,15 +1415,15 @@ func TestDeploymentWatcher_RollbackFailed(t *testing.T) {
d.TaskGroups["web"].AutoRevert = true
a := mock.Alloc()
a.DeploymentID = d.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a}), "UpsertAllocs")
// Upsert the job again to get a new version
j2 := j.Copy()
// Modify the job to make its specification different
j2.Stable = false
require.Nil(m.state.UpsertJob(m.nextIndex(), j2), "UpsertJob2")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j2), "UpsertJob2")
// require that we will get a createEvaluation call only once. This will
// verify that the watcher is batching allocation changes
@ -1538,12 +1538,12 @@ func TestWatcher_BatchAllocUpdates(t *testing.T) {
a2.JobID = j2.ID
a2.DeploymentID = d2.ID
require.Nil(m.state.UpsertJob(m.nextIndex(), j1), "UpsertJob")
require.Nil(m.state.UpsertJob(m.nextIndex(), j2), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j1), "UpsertJob")
require.Nil(m.state.UpsertJob(structs.MsgTypeTestSetup, m.nextIndex(), j2), "UpsertJob")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d1), "UpsertDeployment")
require.Nil(m.state.UpsertDeployment(m.nextIndex(), d2), "UpsertDeployment")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a1}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a2}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a1}), "UpsertAllocs")
require.Nil(m.state.UpsertAllocs(structs.MsgTypeTestSetup, m.nextIndex(), []*structs.Allocation{a2}), "UpsertAllocs")
// require that we will get a createEvaluation call only once and it contains
// both deployments. This will verify that the watcher is batching

View File

@ -89,7 +89,7 @@ func matchUpdateAllocDesiredTransitionReschedule(allocIDs []string) func(update
func (m *mockBackend) UpsertJob(job *structs.Job) (uint64, error) {
m.Called(job)
i := m.nextIndex()
return i, m.state.UpsertJob(i, job)
return i, m.state.UpsertJob(structs.MsgTypeTestSetup, i, job)
}
func (m *mockBackend) UpdateDeploymentStatus(u *structs.DeploymentStatusUpdateRequest) (uint64, error) {

View File

@ -23,7 +23,7 @@ func testDrainingNode(t *testing.T) *drainingNode {
ForceDeadline: time.Now().Add(time.Hour),
}
require.Nil(t, state.UpsertNode(100, node))
require.Nil(t, state.UpsertNode(structs.MsgTypeTestSetup, 100, node))
return NewDrainingNode(node, state)
}
@ -66,8 +66,8 @@ func TestDrainingNode_Table(t *testing.T) {
setup: func(t *testing.T, dn *drainingNode) {
alloc := mock.BatchAlloc()
alloc.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, alloc.Job))
require.Nil(t, dn.state.UpsertAllocs(102, []*structs.Allocation{alloc}))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, alloc.Job))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, []*structs.Allocation{alloc}))
},
},
{
@ -78,8 +78,8 @@ func TestDrainingNode_Table(t *testing.T) {
setup: func(t *testing.T, dn *drainingNode) {
alloc := mock.Alloc()
alloc.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, alloc.Job))
require.Nil(t, dn.state.UpsertAllocs(102, []*structs.Allocation{alloc}))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, alloc.Job))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, []*structs.Allocation{alloc}))
},
},
{
@ -90,8 +90,8 @@ func TestDrainingNode_Table(t *testing.T) {
setup: func(t *testing.T, dn *drainingNode) {
alloc := mock.SystemAlloc()
alloc.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, alloc.Job))
require.Nil(t, dn.state.UpsertAllocs(102, []*structs.Allocation{alloc}))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, alloc.Job))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, []*structs.Allocation{alloc}))
},
},
{
@ -103,9 +103,9 @@ func TestDrainingNode_Table(t *testing.T) {
allocs := []*structs.Allocation{mock.Alloc(), mock.BatchAlloc(), mock.SystemAlloc()}
for _, a := range allocs {
a.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, a.Job))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, a.Job))
}
require.Nil(t, dn.state.UpsertAllocs(102, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, allocs))
// StateStore doesn't like inserting new allocs
// with a terminal status, so set the status in
@ -113,7 +113,7 @@ func TestDrainingNode_Table(t *testing.T) {
for _, a := range allocs {
a.ClientStatus = structs.AllocClientStatusComplete
}
require.Nil(t, dn.state.UpsertAllocs(103, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 103, allocs))
},
},
{
@ -125,13 +125,13 @@ func TestDrainingNode_Table(t *testing.T) {
allocs := []*structs.Allocation{mock.Alloc(), mock.BatchAlloc(), mock.SystemAlloc()}
for _, a := range allocs {
a.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, a.Job))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, a.Job))
}
require.Nil(t, dn.state.UpsertAllocs(102, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, allocs))
// Set only the service job as terminal
allocs[0].ClientStatus = structs.AllocClientStatusComplete
require.Nil(t, dn.state.UpsertAllocs(103, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 103, allocs))
},
},
{
@ -143,14 +143,14 @@ func TestDrainingNode_Table(t *testing.T) {
allocs := []*structs.Allocation{mock.Alloc(), mock.BatchAlloc(), mock.SystemAlloc()}
for _, a := range allocs {
a.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, a.Job))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, a.Job))
}
require.Nil(t, dn.state.UpsertAllocs(102, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, allocs))
// Set only the service and batch jobs as terminal
allocs[0].ClientStatus = structs.AllocClientStatusComplete
allocs[2].ClientStatus = structs.AllocClientStatusComplete
require.Nil(t, dn.state.UpsertAllocs(103, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 103, allocs))
},
},
{
@ -162,14 +162,14 @@ func TestDrainingNode_Table(t *testing.T) {
allocs := []*structs.Allocation{mock.Alloc(), mock.BatchAlloc(), mock.SystemAlloc()}
for _, a := range allocs {
a.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, a.Job))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, a.Job))
}
require.Nil(t, dn.state.UpsertAllocs(102, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, allocs))
// Set only the service and batch jobs as terminal
allocs[0].ClientStatus = structs.AllocClientStatusComplete
allocs[1].ClientStatus = structs.AllocClientStatusComplete
require.Nil(t, dn.state.UpsertAllocs(103, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 103, allocs))
},
},
{
@ -188,15 +188,15 @@ func TestDrainingNode_Table(t *testing.T) {
}
for _, a := range allocs {
a.NodeID = dn.node.ID
require.Nil(t, dn.state.UpsertJob(101, a.Job))
require.Nil(t, dn.state.UpsertJob(structs.MsgTypeTestSetup, 101, a.Job))
}
require.Nil(t, dn.state.UpsertAllocs(102, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 102, allocs))
// Set only the service and batch jobs as terminal
allocs[0].ClientStatus = structs.AllocClientStatusComplete
allocs[1].ClientStatus = structs.AllocClientStatusComplete
allocs[2].ClientStatus = structs.AllocClientStatusComplete
require.Nil(t, dn.state.UpsertAllocs(103, allocs))
require.Nil(t, dn.state.UpsertAllocs(structs.MsgTypeTestSetup, 103, allocs))
},
},
}

View File

@ -25,12 +25,12 @@ func testNodes(t *testing.T, state *state.StateStore) (drainingNode, runningNode
},
ForceDeadline: time.Now().Add(time.Minute),
}
require.Nil(t, state.UpsertNode(100, n1))
require.Nil(t, state.UpsertNode(structs.MsgTypeTestSetup, 100, n1))
// Create a non-draining node
n2 := mock.Node()
n2.Name = "running"
require.Nil(t, state.UpsertNode(101, n2))
require.Nil(t, state.UpsertNode(structs.MsgTypeTestSetup, 101, n2))
return n1, n2
}
@ -128,7 +128,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
jnss[i] = structs.NamespacedID{Namespace: job.Namespace, ID: job.ID}
job.TaskGroups[0].Migrate.MaxParallel = 3
job.TaskGroups[0].Count = count
require.Nil(state.UpsertJob(index, job))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, index, job))
index++
var allocs []*structs.Allocation
@ -140,7 +140,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
allocs = append(allocs, a)
}
require.Nil(state.UpsertAllocs(index, allocs))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, allocs))
index++
}
@ -162,7 +162,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
// create a copy so we can reuse this slice
drainedAllocs[i] = a.Copy()
}
require.Nil(state.UpsertAllocs(index, drainedAllocs))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, drainedAllocs))
drains.Resp.Respond(index, nil)
index++
@ -189,7 +189,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
updates = append(updates, a, replacement)
replacements[i] = replacement.Copy()
}
require.Nil(state.UpsertAllocs(index, updates))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, updates))
index++
// The drained allocs stopping cause migrations but no new drains
@ -203,7 +203,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
Healthy: helper.BoolToPtr(true),
}
}
require.Nil(state.UpsertAllocs(index, replacements))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, replacements))
index++
require.NotEmpty(jobWatcher.drainingJobs())
@ -219,7 +219,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
// create a copy so we can reuse this slice
drainedAllocs[i] = a.Copy()
}
require.Nil(state.UpsertAllocs(index, drainedAllocs))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, drainedAllocs))
drains.Resp.Respond(index, nil)
index++
@ -235,7 +235,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
updates = append(updates, a, replacement)
replacements[i] = replacement.Copy()
}
require.Nil(state.UpsertAllocs(index, updates))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, updates))
index++
assertJobWatcherOps(t, jobWatcher, 0, 6)
@ -246,7 +246,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
Healthy: helper.BoolToPtr(true),
}
}
require.Nil(state.UpsertAllocs(index, replacements))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, replacements))
index++
require.NotEmpty(jobWatcher.drainingJobs())
@ -262,7 +262,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
// create a copy so we can reuse this slice
drainedAllocs[i] = a.Copy()
}
require.Nil(state.UpsertAllocs(index, drainedAllocs))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, drainedAllocs))
drains.Resp.Respond(index, nil)
index++
@ -278,7 +278,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
updates = append(updates, a, replacement)
replacements[i] = replacement.Copy()
}
require.Nil(state.UpsertAllocs(index, updates))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, updates))
index++
assertJobWatcherOps(t, jobWatcher, 0, 4)
@ -289,7 +289,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
Healthy: helper.BoolToPtr(true),
}
}
require.Nil(state.UpsertAllocs(index, replacements))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, index, replacements))
// No jobs should be left!
require.Empty(jobWatcher.drainingJobs())
@ -562,7 +562,7 @@ func testHandleTaskGroup(t *testing.T, tc handleTaskGroupTestCase) {
if tc.MaxParallel > 0 {
job.TaskGroups[0].Migrate.MaxParallel = tc.MaxParallel
}
require.Nil(state.UpsertJob(102, job))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 102, job))
var allocs []*structs.Allocation
for i := 0; i < 10; i++ {
@ -585,7 +585,7 @@ func testHandleTaskGroup(t *testing.T, tc handleTaskGroupTestCase) {
allocs = append(allocs, a)
}
require.Nil(state.UpsertAllocs(103, allocs))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 103, allocs))
snap, err := state.Snapshot()
require.Nil(err)
@ -611,10 +611,10 @@ func TestHandleTaskGroup_Migrations(t *testing.T) {
},
ForceDeadline: time.Now().Add(1 * time.Minute),
}
require.Nil(state.UpsertNode(100, n))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 100, n))
job := mock.Job()
require.Nil(state.UpsertJob(101, job))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 101, job))
// Create 10 done allocs
var allocs []*structs.Allocation
@ -634,7 +634,7 @@ func TestHandleTaskGroup_Migrations(t *testing.T) {
}
allocs = append(allocs, a)
}
require.Nil(state.UpsertAllocs(102, allocs))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 102, allocs))
snap, err := state.Snapshot()
require.Nil(err)
@ -680,10 +680,10 @@ func TestHandleTaskGroup_GarbageCollectedNode(t *testing.T) {
},
ForceDeadline: time.Now().Add(1 * time.Minute),
}
require.Nil(state.UpsertNode(100, n))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 100, n))
job := mock.Job()
require.Nil(state.UpsertJob(101, job))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 101, job))
// Create 10 done allocs
var allocs []*structs.Allocation
@ -706,7 +706,7 @@ func TestHandleTaskGroup_GarbageCollectedNode(t *testing.T) {
// Make the first one be on a GC'd node
allocs[0].NodeID = uuid.Generate()
require.Nil(state.UpsertAllocs(102, allocs))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 102, allocs))
snap, err := state.Snapshot()
require.Nil(err)

View File

@ -45,8 +45,8 @@ func TestNodeDrainWatcher_AddDraining(t *testing.T) {
ForceDeadline: time.Now().Add(time.Hour),
}
require.Nil(state.UpsertNode(100, n1))
require.Nil(state.UpsertNode(101, n2))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 100, n1))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 101, n2))
testutil.WaitForResult(func() (bool, error) {
return len(m.events()) == 1, nil
@ -76,7 +76,7 @@ func TestNodeDrainWatcher_Remove(t *testing.T) {
}
// Wait for it to be tracked
require.Nil(state.UpsertNode(100, n))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 100, n))
testutil.WaitForResult(func() (bool, error) {
return len(m.events()) == 1, nil
}, func(err error) {
@ -88,7 +88,7 @@ func TestNodeDrainWatcher_Remove(t *testing.T) {
require.Equal(n, tracked[n.ID])
// Change the node to be not draining and wait for it to be untracked
require.Nil(state.UpdateNodeDrain(101, n.ID, nil, false, 0, nil))
require.Nil(state.UpdateNodeDrain(structs.MsgTypeTestSetup, 101, n.ID, nil, false, 0, nil))
testutil.WaitForResult(func() (bool, error) {
return len(m.events()) == 2, nil
}, func(err error) {
@ -114,7 +114,7 @@ func TestNodeDrainWatcher_Remove_Nonexistent(t *testing.T) {
}
// Wait for it to be tracked
require.Nil(state.UpsertNode(100, n))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 100, n))
testutil.WaitForResult(func() (bool, error) {
return len(m.events()) == 1, nil
}, func(err error) {
@ -126,7 +126,7 @@ func TestNodeDrainWatcher_Remove_Nonexistent(t *testing.T) {
require.Equal(n, tracked[n.ID])
// Delete the node
require.Nil(state.DeleteNode(101, []string{n.ID}))
require.Nil(state.DeleteNode(structs.MsgTypeTestSetup, 101, []string{n.ID}))
testutil.WaitForResult(func() (bool, error) {
return len(m.events()) == 2, nil
}, func(err error) {
@ -152,7 +152,7 @@ func TestNodeDrainWatcher_Update(t *testing.T) {
}
// Wait for it to be tracked
require.Nil(state.UpsertNode(100, n))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 100, n))
testutil.WaitForResult(func() (bool, error) {
return len(m.events()) == 1, nil
}, func(err error) {
@ -166,7 +166,7 @@ func TestNodeDrainWatcher_Update(t *testing.T) {
// Change the node to have a new spec
s2 := n.DrainStrategy.Copy()
s2.Deadline += time.Hour
require.Nil(state.UpdateNodeDrain(101, n.ID, s2, false, 0, nil))
require.Nil(state.UpdateNodeDrain(structs.MsgTypeTestSetup, 101, n.ID, s2, false, 0, nil))
// Wait for it to be updated
testutil.WaitForResult(func() (bool, error) {

View File

@ -798,7 +798,7 @@ func TestDrainer_AllTypes_Deadline_GarbageCollectedNode(t *testing.T) {
alloc.ClientStatus = structs.AllocClientStatusComplete
badAllocs = append(badAllocs, alloc)
}
require.NoError(state.UpsertAllocs(1, badAllocs))
require.NoError(state.UpsertAllocs(structs.MsgTypeTestSetup, 1, badAllocs))
// Create the second node
nodeReg = &structs.NodeRegisterRequest{

View File

@ -29,7 +29,7 @@ func TestEvalEndpoint_GetEval(t *testing.T) {
// Create the register request
eval1 := mock.Eval()
s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1})
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1})
// Lookup the eval
get := &structs.EvalSpecificRequest{
@ -73,7 +73,7 @@ func TestEvalEndpoint_GetEval_ACL(t *testing.T) {
// Create the register request
eval1 := mock.Eval()
state := s1.fsm.State()
state.UpsertEvals(1000, []*structs.Evaluation{eval1})
state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1})
// Create ACL tokens
validToken := mock.CreatePolicyAndToken(t, state, 1003, "test-valid",
@ -137,7 +137,7 @@ func TestEvalEndpoint_GetEval_Blocking(t *testing.T) {
// First create an unrelated eval
time.AfterFunc(100*time.Millisecond, func() {
err := state.UpsertEvals(100, []*structs.Evaluation{eval1})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 100, []*structs.Evaluation{eval1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -145,7 +145,7 @@ func TestEvalEndpoint_GetEval_Blocking(t *testing.T) {
// Upsert the eval we are watching later
time.AfterFunc(200*time.Millisecond, func() {
err := state.UpsertEvals(200, []*structs.Evaluation{eval2})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 200, []*structs.Evaluation{eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -260,9 +260,9 @@ func TestEvalEndpoint_Dequeue_WaitIndex_Snapshot(t *testing.T) {
eval1 := mock.Eval()
eval2 := mock.Eval()
eval2.JobID = eval1.JobID
s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1})
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1})
s1.evalBroker.Enqueue(eval1)
s1.fsm.State().UpsertEvals(1001, []*structs.Evaluation{eval2})
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval2})
// Dequeue the eval
get := &structs.EvalDequeueRequest{
@ -310,7 +310,7 @@ func TestEvalEndpoint_Dequeue_WaitIndex_Eval(t *testing.T) {
eval1 := mock.Eval()
eval2 := mock.Eval()
eval2.JobID = eval1.JobID
s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1})
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1})
eval2.ModifyIndex = 1001
s1.evalBroker.Enqueue(eval2)
@ -351,7 +351,7 @@ func TestEvalEndpoint_Dequeue_UpdateWaitIndex(t *testing.T) {
state := s1.fsm.State()
if err := state.UpsertJob(999, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 999, job); err != nil {
t.Fatalf("err: %v", err)
}
@ -359,7 +359,7 @@ func TestEvalEndpoint_Dequeue_UpdateWaitIndex(t *testing.T) {
eval.JobID = job.ID
// Create an eval
if err := state.UpsertEvals(1, []*structs.Evaluation{eval}); err != nil {
if err := state.UpsertEvals(structs.MsgTypeTestSetup, 1, []*structs.Evaluation{eval}); err != nil {
t.Fatalf("err: %v", err)
}
@ -636,7 +636,7 @@ func TestEvalEndpoint_Reap(t *testing.T) {
// Create the register request
eval1 := mock.Eval()
s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1})
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1})
// Reap the eval
get := &structs.EvalDeleteRequest{
@ -675,7 +675,7 @@ func TestEvalEndpoint_List(t *testing.T) {
eval1.ID = "aaaaaaaa-3350-4b4b-d185-0e1992ed43e9"
eval2 := mock.Eval()
eval2.ID = "aaaabbbb-3350-4b4b-d185-0e1992ed43e9"
s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1, eval2})
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2})
// Lookup the eval
get := &structs.EvalListRequest{
@ -733,7 +733,7 @@ func TestEvalEndpoint_List_ACL(t *testing.T) {
eval2 := mock.Eval()
eval2.ID = "aaaabbbb-3350-4b4b-d185-0e1992ed43e9"
state := s1.fsm.State()
assert.Nil(state.UpsertEvals(1000, []*structs.Evaluation{eval1, eval2}))
assert.Nil(state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2}))
// Create ACL tokens
validToken := mock.CreatePolicyAndToken(t, state, 1003, "test-valid",
@ -798,7 +798,7 @@ func TestEvalEndpoint_List_Blocking(t *testing.T) {
// Upsert eval triggers watches
time.AfterFunc(100*time.Millisecond, func() {
if err := state.UpsertEvals(2, []*structs.Evaluation{eval}); err != nil {
if err := state.UpsertEvals(structs.MsgTypeTestSetup, 2, []*structs.Evaluation{eval}); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -866,8 +866,7 @@ func TestEvalEndpoint_Allocations(t *testing.T) {
state := s1.fsm.State()
state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID))
state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(1000,
[]*structs.Allocation{alloc1, alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -906,7 +905,7 @@ func TestEvalEndpoint_Allocations_ACL(t *testing.T) {
state := s1.fsm.State()
assert.Nil(state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID)))
assert.Nil(state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID)))
assert.Nil(state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2}))
// Create ACL tokens
validToken := mock.CreatePolicyAndToken(t, state, 1003, "test-valid",
@ -971,7 +970,7 @@ func TestEvalEndpoint_Allocations_Blocking(t *testing.T) {
// Upsert an unrelated alloc first
time.AfterFunc(100*time.Millisecond, func() {
state.UpsertJobSummary(99, mock.JobSummary(alloc1.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -980,7 +979,7 @@ func TestEvalEndpoint_Allocations_Blocking(t *testing.T) {
// Upsert an alloc which will trigger the watch later
time.AfterFunc(200*time.Millisecond, func() {
state.UpsertJobSummary(199, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(200, []*structs.Allocation{alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 200, []*structs.Allocation{alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1068,7 +1067,7 @@ func TestEvalEndpoint_Reblock_NonBlocked(t *testing.T) {
s1.evalBroker.Enqueue(eval1)
// Insert it into the state store
if err := s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1}); err != nil {
if err := s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1}); err != nil {
t.Fatal(err)
}
@ -1112,7 +1111,7 @@ func TestEvalEndpoint_Reblock(t *testing.T) {
s1.evalBroker.Enqueue(eval1)
// Insert it into the state store
if err := s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1}); err != nil {
if err := s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1}); err != nil {
t.Fatal(err)
}

View File

@ -276,7 +276,7 @@ func (n *nomadFSM) Apply(log *raft.Log) interface{} {
case structs.SchedulerConfigRequestType:
return n.applySchedulerConfigUpdate(buf[1:], log.Index)
case structs.NodeBatchDeregisterRequestType:
return n.applyDeregisterNodeBatch(buf[1:], log.Index)
return n.applyDeregisterNodeBatch(msgType, buf[1:], log.Index)
case structs.ClusterMetadataRequestType:
return n.applyClusterMetadata(buf[1:], log.Index)
case structs.ServiceIdentityAccessorRegisterRequestType:
@ -339,7 +339,7 @@ func (n *nomadFSM) applyUpsertNode(reqType structs.MessageType, buf []byte, inde
// Handle upgrade paths
req.Node.Canonicalize()
if err := n.state.UpsertNodeMsgType(reqType, index, req.Node); err != nil {
if err := n.state.UpsertNode(reqType, index, req.Node); err != nil {
n.logger.Error("UpsertNode failed", "error", err)
return err
}
@ -360,7 +360,7 @@ func (n *nomadFSM) applyDeregisterNode(reqType structs.MessageType, buf []byte,
panic(fmt.Errorf("failed to decode request: %v", err))
}
if err := n.state.DeleteNodeMsgType(reqType, index, []string{req.NodeID}); err != nil {
if err := n.state.DeleteNode(reqType, index, []string{req.NodeID}); err != nil {
n.logger.Error("DeleteNode failed", "error", err)
return err
}
@ -368,14 +368,14 @@ func (n *nomadFSM) applyDeregisterNode(reqType structs.MessageType, buf []byte,
return nil
}
func (n *nomadFSM) applyDeregisterNodeBatch(buf []byte, index uint64) interface{} {
func (n *nomadFSM) applyDeregisterNodeBatch(reqType structs.MessageType, buf []byte, index uint64) interface{} {
defer metrics.MeasureSince([]string{"nomad", "fsm", "batch_deregister_node"}, time.Now())
var req structs.NodeBatchDeregisterRequest
if err := structs.Decode(buf, &req); err != nil {
panic(fmt.Errorf("failed to decode request: %v", err))
}
if err := n.state.DeleteNode(index, req.NodeIDs); err != nil {
if err := n.state.DeleteNode(reqType, index, req.NodeIDs); err != nil {
n.logger.Error("DeleteNode failed", "error", err)
return err
}
@ -433,7 +433,7 @@ func (n *nomadFSM) applyDrainUpdate(reqType structs.MessageType, buf []byte, ind
}
}
if err := n.state.UpdateNodeDrainMsgType(reqType, index, req.NodeID, req.DrainStrategy, req.MarkEligible, req.UpdatedAt, req.NodeEvent); err != nil {
if err := n.state.UpdateNodeDrain(reqType, index, req.NodeID, req.DrainStrategy, req.MarkEligible, req.UpdatedAt, req.NodeEvent); err != nil {
n.logger.Error("UpdateNodeDrain failed", "error", err)
return err
}
@ -500,7 +500,7 @@ func (n *nomadFSM) applyUpsertJob(msgType structs.MessageType, buf []byte, index
*/
req.Job.Canonicalize()
if err := n.state.UpsertJobMsgType(msgType, index, req.Job); err != nil {
if err := n.state.UpsertJob(msgType, index, req.Job); err != nil {
n.logger.Error("UpsertJob failed", "error", err)
return err
}
@ -708,7 +708,7 @@ func (n *nomadFSM) applyUpdateEval(msgType structs.MessageType, buf []byte, inde
}
func (n *nomadFSM) upsertEvals(msgType structs.MessageType, index uint64, evals []*structs.Evaluation) error {
if err := n.state.UpsertEvalsMsgType(msgType, index, evals); err != nil {
if err := n.state.UpsertEvals(msgType, index, evals); err != nil {
n.logger.Error("UpsertEvals failed", "error", err)
return err
}
@ -788,7 +788,7 @@ func (n *nomadFSM) applyAllocUpdate(msgType structs.MessageType, buf []byte, ind
alloc.Canonicalize()
}
if err := n.state.UpsertAllocsMsgType(msgType, index, req.Alloc); err != nil {
if err := n.state.UpsertAllocs(msgType, index, req.Alloc); err != nil {
n.logger.Error("UpsertAllocs failed", "error", err)
return err
}
@ -892,7 +892,7 @@ func (n *nomadFSM) applyUpsertNodeEvent(msgType structs.MessageType, buf []byte,
panic(fmt.Errorf("failed to decode EmitNodeEventsRequest: %v", err))
}
if err := n.state.UpsertNodeEventsMsgType(msgType, index, req.NodeEvents); err != nil {
if err := n.state.UpsertNodeEvents(msgType, index, req.NodeEvents); err != nil {
n.logger.Error("failed to add node events", "error", err)
return err
}
@ -1711,7 +1711,8 @@ func (n *nomadFSM) reconcileQueuedAllocations(index uint64) error {
Status: structs.EvalStatusPending,
AnnotatePlan: true,
}
snap.UpsertEvals(100, []*structs.Evaluation{eval})
// Ignore eval event creation during snapshot restore
snap.UpsertEvals(structs.IgnoreUnknownTypeFlag, 100, []*structs.Evaluation{eval})
// Create the scheduler and run it
sched, err := scheduler.NewScheduler(eval.Type, n.logger, snap, planner)
if err != nil {

View File

@ -85,7 +85,7 @@ func TestFSM_UpsertNodeEvents(t *testing.T) {
node := mock.Node()
err := state.UpsertNode(1000, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -408,7 +408,7 @@ func TestFSM_UpdateNodeDrain_Pre08_Compatibility(t *testing.T) {
// Force a node into the state store without eligiblity
node := mock.Node()
node.SchedulingEligibility = ""
require.Nil(fsm.State().UpsertNode(1, node))
require.Nil(fsm.State().UpsertNode(structs.MsgTypeTestSetup, 1, node))
// Do an old style drain
req := structs.NodeUpdateDrainRequest{
@ -1449,7 +1449,7 @@ func TestFSM_UpdateAllocFromClient_Unblock(t *testing.T) {
state := fsm.State()
node := mock.Node()
state.UpsertNode(1, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1, node)
// Mark an eval as blocked.
eval := mock.Eval()
@ -1468,7 +1468,7 @@ func TestFSM_UpdateAllocFromClient_Unblock(t *testing.T) {
alloc2.NodeID = node.ID
state.UpsertJobSummary(8, mock.JobSummary(alloc.JobID))
state.UpsertJobSummary(9, mock.JobSummary(alloc2.JobID))
state.UpsertAllocs(10, []*structs.Allocation{alloc, alloc2})
state.UpsertAllocs(structs.MsgTypeTestSetup, 10, []*structs.Allocation{alloc, alloc2})
clientAlloc := new(structs.Allocation)
*clientAlloc = *alloc
@ -1535,7 +1535,7 @@ func TestFSM_UpdateAllocFromClient(t *testing.T) {
alloc := mock.Alloc()
state.UpsertJobSummary(9, mock.JobSummary(alloc.JobID))
state.UpsertAllocs(10, []*structs.Allocation{alloc})
state.UpsertAllocs(structs.MsgTypeTestSetup, 10, []*structs.Allocation{alloc})
clientAlloc := new(structs.Allocation)
*clientAlloc = *alloc
@ -1586,7 +1586,7 @@ func TestFSM_UpdateAllocDesiredTransition(t *testing.T) {
alloc2.Job = alloc.Job
alloc2.JobID = alloc.JobID
state.UpsertJobSummary(9, mock.JobSummary(alloc.JobID))
state.UpsertAllocs(10, []*structs.Allocation{alloc, alloc2})
state.UpsertAllocs(structs.MsgTypeTestSetup, 10, []*structs.Allocation{alloc, alloc2})
t1 := &structs.DesiredTransition{
Migrate: helper.BoolToPtr(true),
@ -1817,7 +1817,7 @@ func TestFSM_ApplyPlanResults(t *testing.T) {
eval := mock.Eval()
eval.JobID = job.ID
fsm.State().UpsertEvals(1, []*structs.Evaluation{eval})
fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1, []*structs.Evaluation{eval})
fsm.State().UpsertJobSummary(1, mock.JobSummary(alloc.JobID))
@ -1835,7 +1835,7 @@ func TestFSM_ApplyPlanResults(t *testing.T) {
alloc2.JobID = job2.ID
alloc2.PreemptedByAllocation = alloc.ID
fsm.State().UpsertAllocs(1, []*structs.Allocation{alloc1, alloc2})
fsm.State().UpsertAllocs(structs.MsgTypeTestSetup, 1, []*structs.Allocation{alloc1, alloc2})
// evals for preempted jobs
eval1 := mock.Eval()
@ -1908,7 +1908,7 @@ func TestFSM_ApplyPlanResults(t *testing.T) {
eval = mock.Eval()
eval.JobID = job.ID
fsm.State().UpsertEvals(2, []*structs.Evaluation{eval})
fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 2, []*structs.Evaluation{eval})
evictAlloc.Job = nil
evictAlloc.DesiredStatus = structs.AllocDesiredStatusEvict
@ -2018,7 +2018,7 @@ func TestFSM_JobStabilityUpdate(t *testing.T) {
// Upsert a deployment
job := mock.Job()
if err := state.UpsertJob(1, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1, job); err != nil {
t.Fatalf("bad: %v", err)
}
@ -2063,7 +2063,7 @@ func TestFSM_DeploymentPromotion(t *testing.T) {
tg2 := tg1.Copy()
tg2.Name = "foo"
j.TaskGroups = append(j.TaskGroups, tg2)
if err := state.UpsertJob(1, j); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1, j); err != nil {
t.Fatalf("bad: %v", err)
}
@ -2101,7 +2101,7 @@ func TestFSM_DeploymentPromotion(t *testing.T) {
Healthy: helper.BoolToPtr(true),
}
if err := state.UpsertAllocs(3, []*structs.Allocation{c1, c2}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{c1, c2}); err != nil {
t.Fatalf("err: %v", err)
}
@ -2173,7 +2173,7 @@ func TestFSM_DeploymentAllocHealth(t *testing.T) {
a1.DeploymentID = d.ID
a2 := mock.Alloc()
a2.DeploymentID = d.ID
if err := state.UpsertAllocs(2, []*structs.Allocation{a1, a2}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 2, []*structs.Allocation{a1, a2}); err != nil {
t.Fatalf("bad: %v", err)
}
@ -2494,12 +2494,12 @@ func TestFSM_SnapshotRestore_Nodes(t *testing.T) {
fsm := testFSM(t)
state := fsm.State()
node1 := mock.Node()
state.UpsertNode(1000, node1)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1)
// Upgrade this node
node2 := mock.Node()
node2.SchedulingEligibility = ""
state.UpsertNode(1001, node2)
state.UpsertNode(structs.MsgTypeTestSetup, 1001, node2)
// Verify the contents
fsm2 := testSnapshotRestore(t, fsm)
@ -2521,9 +2521,9 @@ func TestFSM_SnapshotRestore_Jobs(t *testing.T) {
fsm := testFSM(t)
state := fsm.State()
job1 := mock.Job()
state.UpsertJob(1000, job1)
state.UpsertJob(structs.MsgTypeTestSetup, 1000, job1)
job2 := mock.Job()
state.UpsertJob(1001, job2)
state.UpsertJob(structs.MsgTypeTestSetup, 1001, job2)
// Verify the contents
ws := memdb.NewWatchSet()
@ -2545,9 +2545,9 @@ func TestFSM_SnapshotRestore_Evals(t *testing.T) {
fsm := testFSM(t)
state := fsm.State()
eval1 := mock.Eval()
state.UpsertEvals(1000, []*structs.Evaluation{eval1})
state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1})
eval2 := mock.Eval()
state.UpsertEvals(1001, []*structs.Evaluation{eval2})
state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval2})
// Verify the contents
fsm2 := testSnapshotRestore(t, fsm)
@ -2572,8 +2572,8 @@ func TestFSM_SnapshotRestore_Allocs(t *testing.T) {
alloc2 := mock.Alloc()
state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID))
state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID))
state.UpsertAllocs(1000, []*structs.Allocation{alloc1})
state.UpsertAllocs(1001, []*structs.Allocation{alloc2})
state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1})
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc2})
// Verify the contents
fsm2 := testSnapshotRestore(t, fsm)
@ -2600,7 +2600,7 @@ func TestFSM_SnapshotRestore_Allocs_Canonicalize(t *testing.T) {
alloc.AllocatedResources = nil
state.UpsertJobSummary(998, mock.JobSummary(alloc.JobID))
state.UpsertAllocs(1000, []*structs.Allocation{alloc})
state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc})
// Verify the contents
fsm2 := testSnapshotRestore(t, fsm)
@ -2622,7 +2622,7 @@ func TestFSM_SnapshotRestore_Indexes(t *testing.T) {
fsm := testFSM(t)
state := fsm.State()
node1 := mock.Node()
state.UpsertNode(1000, node1)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1)
// Verify the contents
fsm2 := testSnapshotRestore(t, fsm)
@ -2701,12 +2701,12 @@ func TestFSM_SnapshotRestore_JobSummary(t *testing.T) {
state := fsm.State()
job1 := mock.Job()
state.UpsertJob(1000, job1)
state.UpsertJob(structs.MsgTypeTestSetup, 1000, job1)
ws := memdb.NewWatchSet()
js1, _ := state.JobSummaryByID(ws, job1.Namespace, job1.ID)
job2 := mock.Job()
state.UpsertJob(1001, job2)
state.UpsertJob(structs.MsgTypeTestSetup, 1001, job2)
js2, _ := state.JobSummaryByID(ws, job2.Namespace, job2.ID)
// Verify the contents
@ -2751,10 +2751,10 @@ func TestFSM_SnapshotRestore_JobVersions(t *testing.T) {
fsm := testFSM(t)
state := fsm.State()
job1 := mock.Job()
state.UpsertJob(1000, job1)
state.UpsertJob(structs.MsgTypeTestSetup, 1000, job1)
job2 := mock.Job()
job2.ID = job1.ID
state.UpsertJob(1001, job2)
state.UpsertJob(structs.MsgTypeTestSetup, 1001, job2)
// Verify the contents
ws := memdb.NewWatchSet()
@ -2785,7 +2785,7 @@ func TestFSM_SnapshotRestore_Deployments(t *testing.T) {
d1.JobID = j.ID
d2.JobID = j.ID
state.UpsertJob(999, j)
state.UpsertJob(structs.MsgTypeTestSetup, 999, j)
state.UpsertDeployment(1000, d1)
state.UpsertDeployment(1001, d2)
@ -2891,18 +2891,18 @@ func TestFSM_ReconcileSummaries(t *testing.T) {
// Add a node
node := mock.Node()
require.NoError(t, state.UpsertNode(800, node))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 800, node))
// Make a job so that none of the tasks can be placed
job1 := mock.Job()
job1.TaskGroups[0].Tasks[0].Resources.CPU = 5000
require.NoError(t, state.UpsertJob(1000, job1))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1000, job1))
// make a job which can make partial progress
alloc := mock.Alloc()
alloc.NodeID = node.ID
require.NoError(t, state.UpsertJob(1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(1011, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 1010, alloc.Job))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc}))
// Delete the summaries
require.NoError(t, state.DeleteJobSummary(1030, job1.Namespace, job1.ID))
@ -2973,7 +2973,7 @@ func TestFSM_ReconcileParentJobSummary(t *testing.T) {
// Add a node
node := mock.Node()
state.UpsertNode(800, node)
state.UpsertNode(structs.MsgTypeTestSetup, 800, node)
// Make a parameterized job
job1 := mock.BatchJob()
@ -2982,7 +2982,7 @@ func TestFSM_ReconcileParentJobSummary(t *testing.T) {
Payload: "random",
}
job1.TaskGroups[0].Count = 1
state.UpsertJob(1000, job1)
state.UpsertJob(structs.MsgTypeTestSetup, 1000, job1)
// Make a child job
childJob := job1.Copy()
@ -2998,8 +2998,8 @@ func TestFSM_ReconcileParentJobSummary(t *testing.T) {
alloc.JobID = childJob.ID
alloc.ClientStatus = structs.AllocClientStatusRunning
state.UpsertJob(1010, childJob)
state.UpsertAllocs(1011, []*structs.Allocation{alloc})
state.UpsertJob(structs.MsgTypeTestSetup, 1010, childJob)
state.UpsertAllocs(structs.MsgTypeTestSetup, 1011, []*structs.Allocation{alloc})
// Make the summary incorrect in the state store
summary, err := state.JobSummaryByID(nil, job1.Namespace, job1.ID)

View File

@ -22,7 +22,7 @@ func TestHeartbeat_InitializeHeartbeatTimers(t *testing.T) {
node := mock.Node()
state := s1.fsm.State()
err := state.UpsertNode(1, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1, node)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -153,7 +153,7 @@ func TestHeartbeat_InvalidateHeartbeat(t *testing.T) {
// Create a node
node := mock.Node()
state := s1.fsm.State()
require.NoError(state.UpsertNode(1, node))
require.NoError(state.UpsertNode(structs.MsgTypeTestSetup, 1, node))
// This should cause a status update
s1.invalidateHeartbeat(node.ID)

View File

@ -1704,13 +1704,13 @@ func (j *Job) Plan(args *structs.JobPlanRequest, reply *structs.JobPlanResponse)
if oldJob.SpecChanged(args.Job) {
// Insert the updated Job into the snapshot
updatedIndex = oldJob.JobModifyIndex + 1
if err := snap.UpsertJob(updatedIndex, args.Job); err != nil {
if err := snap.UpsertJob(structs.IgnoreUnknownTypeFlag, updatedIndex, args.Job); err != nil {
return err
}
}
} else if oldJob == nil {
// Insert the updated Job into the snapshot
err := snap.UpsertJob(100, args.Job)
err := snap.UpsertJob(structs.IgnoreUnknownTypeFlag, 100, args.Job)
if err != nil {
return err
}
@ -1733,7 +1733,8 @@ func (j *Job) Plan(args *structs.JobPlanRequest, reply *structs.JobPlanResponse)
ModifyTime: now,
}
snap.UpsertEvals(100, []*structs.Evaluation{eval})
// Ignore eval event creation during snapshot eval creation
snap.UpsertEvals(structs.IgnoreUnknownTypeFlag, 100, []*structs.Evaluation{eval})
// Create an in-memory Planner that returns no errors and stores the
// submitted plan and created evals.

View File

@ -1771,12 +1771,12 @@ func TestJobEndpoint_Register_SemverConstraint(t *testing.T) {
node1 := mock.Node()
node1.Attributes["vault.version"] = "1.3.0-beta1+ent"
node1.ComputeClass()
require.NoError(t, state.UpsertNode(1, node1))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1, node1))
node2 := mock.Node()
delete(node2.Attributes, "vault.version")
node2.ComputeClass()
require.NoError(t, state.UpsertNode(2, node2))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 2, node2))
// Create the register request
req := &structs.JobRegisterRequest{
@ -2528,12 +2528,12 @@ func TestJobEndpoint_Revert_ACL(t *testing.T) {
// Create the jobs
job := mock.Job()
err := state.UpsertJob(300, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 300, job)
require.Nil(err)
job2 := job.Copy()
job2.Priority = 1
err = state.UpsertJob(400, job2)
err = state.UpsertJob(structs.MsgTypeTestSetup, 400, job2)
require.Nil(err)
// Create revert request and enforcing it be at the current version
@ -2656,7 +2656,7 @@ func TestJobEndpoint_Stable_ACL(t *testing.T) {
// Register the job
job := mock.Job()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
// Create stability request
@ -2833,7 +2833,7 @@ func TestJobEndpoint_ForceRescheduleEvaluate(t *testing.T) {
alloc.TaskGroup = job.TaskGroups[0].Name
alloc.Namespace = job.Namespace
alloc.ClientStatus = structs.AllocClientStatusFailed
err = s1.State().UpsertAllocs(resp.Index+1, []*structs.Allocation{alloc})
err = s1.State().UpsertAllocs(structs.MsgTypeTestSetup, resp.Index+1, []*structs.Allocation{alloc})
require.Nil(err)
// Force a re-evaluation
@ -2887,7 +2887,7 @@ func TestJobEndpoint_Evaluate_ACL(t *testing.T) {
// Create the job
job := mock.Job()
err := state.UpsertJob(300, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 300, job)
require.Nil(err)
// Force a re-evaluation
@ -3141,7 +3141,7 @@ func TestJobEndpoint_Deregister_ACL(t *testing.T) {
// Create and register a job
job := mock.Job()
err := state.UpsertJob(100, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job)
require.Nil(err)
// Deregister and purge
@ -3683,8 +3683,8 @@ func TestJobEndpoint_BatchDeregister_ACL(t *testing.T) {
// Create and register a job
job, job2 := mock.Job(), mock.Job()
require.Nil(state.UpsertJob(100, job))
require.Nil(state.UpsertJob(101, job2))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 100, job))
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 101, job2))
// Deregister
req := &structs.JobBatchDeregisterRequest{
@ -3828,7 +3828,7 @@ func TestJobEndpoint_GetJob_ACL(t *testing.T) {
// Create the job
job := mock.Job()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
// Lookup the job
@ -3889,14 +3889,14 @@ func TestJobEndpoint_GetJob_Blocking(t *testing.T) {
// Upsert a job we are not interested in first.
time.AfterFunc(100*time.Millisecond, func() {
if err := state.UpsertJob(100, job1); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job1); err != nil {
t.Fatalf("err: %v", err)
}
})
// Upsert another job later which should trigger the watch.
time.AfterFunc(200*time.Millisecond, func() {
if err := state.UpsertJob(200, job2); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 200, job2); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -4037,11 +4037,11 @@ func TestJobEndpoint_GetJobVersions_ACL(t *testing.T) {
// Create two versions of a job with different priorities
job := mock.Job()
job.Priority = 88
err := state.UpsertJob(10, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 10, job)
require.Nil(err)
job.Priority = 100
err = state.UpsertJob(100, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 100, job)
require.Nil(err)
// Lookup the job
@ -4206,14 +4206,14 @@ func TestJobEndpoint_GetJobVersions_Blocking(t *testing.T) {
// Upsert a job we are not interested in first.
time.AfterFunc(100*time.Millisecond, func() {
if err := state.UpsertJob(100, job1); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job1); err != nil {
t.Fatalf("err: %v", err)
}
})
// Upsert another job later which should trigger the watch.
time.AfterFunc(200*time.Millisecond, func() {
if err := state.UpsertJob(200, job2); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 200, job2); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -4244,7 +4244,7 @@ func TestJobEndpoint_GetJobVersions_Blocking(t *testing.T) {
// Upsert the job again which should trigger the watch.
time.AfterFunc(100*time.Millisecond, func() {
if err := state.UpsertJob(300, job3); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 300, job3); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -4435,7 +4435,7 @@ func TestJobEndpoint_GetJobSummary_Blocking(t *testing.T) {
// Create a job and insert it
job1 := mock.Job()
time.AfterFunc(200*time.Millisecond, func() {
if err := state.UpsertJob(100, job1); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job1); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -4463,7 +4463,7 @@ func TestJobEndpoint_GetJobSummary_Blocking(t *testing.T) {
alloc := mock.Alloc()
alloc.JobID = job1.ID
alloc.Job = job1
if err := state.UpsertAllocs(200, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 200, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -4528,7 +4528,7 @@ func TestJobEndpoint_ListJobs(t *testing.T) {
// Create the register request
job := mock.Job()
state := s1.fsm.State()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -4593,7 +4593,7 @@ func TestJobEndpoint_ListJobs_AllNamespaces_OSS(t *testing.T) {
// Create the register request
job := mock.Job()
state := s1.fsm.State()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -4660,7 +4660,7 @@ func TestJobEndpoint_ListJobs_WithACL(t *testing.T) {
// Create the register request
job := mock.Job()
err = state.UpsertJob(1000, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
req := &structs.JobListRequest{
@ -4718,7 +4718,7 @@ func TestJobEndpoint_ListJobs_Blocking(t *testing.T) {
// Upsert job triggers watches
time.AfterFunc(100*time.Millisecond, func() {
if err := state.UpsertJob(100, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -4786,8 +4786,7 @@ func TestJobEndpoint_Allocations(t *testing.T) {
state := s1.fsm.State()
state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID))
state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(1000,
[]*structs.Allocation{alloc1, alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -4829,8 +4828,7 @@ func TestJobEndpoint_Allocations_ACL(t *testing.T) {
alloc2.JobID = alloc1.JobID
state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID))
state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(1000,
[]*structs.Allocation{alloc1, alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2})
require.Nil(err)
// Look up allocations for that job
@ -4893,7 +4891,7 @@ func TestJobEndpoint_Allocations_Blocking(t *testing.T) {
// First upsert an unrelated alloc
time.AfterFunc(100*time.Millisecond, func() {
state.UpsertJobSummary(99, mock.JobSummary(alloc1.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{alloc1})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -4902,7 +4900,7 @@ func TestJobEndpoint_Allocations_Blocking(t *testing.T) {
// Upsert an alloc for the job we are interested in later
time.AfterFunc(200*time.Millisecond, func() {
state.UpsertJobSummary(199, mock.JobSummary(alloc2.JobID))
err := state.UpsertAllocs(200, []*structs.Allocation{alloc2})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 200, []*structs.Allocation{alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -4971,8 +4969,7 @@ func TestJobEndpoint_Evaluations(t *testing.T) {
eval2 := mock.Eval()
eval2.JobID = eval1.JobID
state := s1.fsm.State()
err := state.UpsertEvals(1000,
[]*structs.Evaluation{eval1, eval2})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -5012,8 +5009,7 @@ func TestJobEndpoint_Evaluations_ACL(t *testing.T) {
eval1 := mock.Eval()
eval2 := mock.Eval()
eval2.JobID = eval1.JobID
err := state.UpsertEvals(1000,
[]*structs.Evaluation{eval1, eval2})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2})
require.Nil(err)
// Lookup the jobs
@ -5075,7 +5071,7 @@ func TestJobEndpoint_Evaluations_Blocking(t *testing.T) {
// First upsert an unrelated eval
time.AfterFunc(100*time.Millisecond, func() {
err := state.UpsertEvals(100, []*structs.Evaluation{eval1})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 100, []*structs.Evaluation{eval1})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -5083,7 +5079,7 @@ func TestJobEndpoint_Evaluations_Blocking(t *testing.T) {
// Upsert an eval for the job we are interested in later
time.AfterFunc(200*time.Millisecond, func() {
err := state.UpsertEvals(200, []*structs.Evaluation{eval2})
err := state.UpsertEvals(structs.MsgTypeTestSetup, 200, []*structs.Evaluation{eval2})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -5131,7 +5127,7 @@ func TestJobEndpoint_Deployments(t *testing.T) {
d2 := mock.Deployment()
d1.JobID = j.ID
d2.JobID = j.ID
require.Nil(state.UpsertJob(1000, j), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j), "UpsertJob")
d1.JobCreateIndex = j.CreateIndex
d2.JobCreateIndex = j.CreateIndex
@ -5168,7 +5164,7 @@ func TestJobEndpoint_Deployments_ACL(t *testing.T) {
d2 := mock.Deployment()
d1.JobID = j.ID
d2.JobID = j.ID
require.Nil(state.UpsertJob(1000, j), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j), "UpsertJob")
d1.JobCreateIndex = j.CreateIndex
d2.JobCreateIndex = j.CreateIndex
require.Nil(state.UpsertDeployment(1001, d1), "UpsertDeployment")
@ -5231,7 +5227,7 @@ func TestJobEndpoint_Deployments_Blocking(t *testing.T) {
d1 := mock.Deployment()
d2 := mock.Deployment()
d2.JobID = j.ID
require.Nil(state.UpsertJob(50, j), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 50, j), "UpsertJob")
d2.JobCreateIndex = j.CreateIndex
// First upsert an unrelated eval
time.AfterFunc(100*time.Millisecond, func() {
@ -5281,7 +5277,7 @@ func TestJobEndpoint_LatestDeployment(t *testing.T) {
d2.JobID = j.ID
d2.CreateIndex = d1.CreateIndex + 100
d2.ModifyIndex = d2.CreateIndex + 100
require.Nil(state.UpsertJob(1000, j), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j), "UpsertJob")
d1.JobCreateIndex = j.CreateIndex
d2.JobCreateIndex = j.CreateIndex
require.Nil(state.UpsertDeployment(1001, d1), "UpsertDeployment")
@ -5320,7 +5316,7 @@ func TestJobEndpoint_LatestDeployment_ACL(t *testing.T) {
d2.JobID = j.ID
d2.CreateIndex = d1.CreateIndex + 100
d2.ModifyIndex = d2.CreateIndex + 100
require.Nil(state.UpsertJob(1000, j), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, j), "UpsertJob")
d1.JobCreateIndex = j.CreateIndex
d2.JobCreateIndex = j.CreateIndex
require.Nil(state.UpsertDeployment(1001, d1), "UpsertDeployment")
@ -5386,7 +5382,7 @@ func TestJobEndpoint_LatestDeployment_Blocking(t *testing.T) {
d1 := mock.Deployment()
d2 := mock.Deployment()
d2.JobID = j.ID
require.Nil(state.UpsertJob(50, j), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 50, j), "UpsertJob")
d2.JobCreateIndex = j.CreateIndex
// First upsert an unrelated eval
@ -5939,7 +5935,7 @@ func TestJobEndpoint_Dispatch_ACL(t *testing.T) {
// Create a parameterized job
job := mock.BatchJob()
job.ParameterizedJob = &structs.ParameterizedJobConfig{}
err := state.UpsertJob(400, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 400, job)
require.Nil(err)
req := &structs.JobDispatchRequest{
@ -6289,7 +6285,7 @@ func TestJobEndpoint_Scale(t *testing.T) {
job := mock.Job()
originalCount := job.TaskGroups[0].Count
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
groupName := job.TaskGroups[0].Name
@ -6346,7 +6342,7 @@ func TestJobEndpoint_Scale_DeploymentBlocking(t *testing.T) {
for _, tc := range cases {
// create a job with a deployment history
job := mock.Job()
require.Nil(state.UpsertJob(1000, job), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, job), "UpsertJob")
d1 := mock.Deployment()
d1.Status = structs.DeploymentStatusCancelled
d1.StatusDescription = structs.DeploymentStatusDescriptionNewerJob
@ -6441,7 +6437,7 @@ func TestJobEndpoint_Scale_InformationalEventsShouldNotBeBlocked(t *testing.T) {
for _, tc := range cases {
// create a job with a deployment history
job := mock.Job()
require.Nil(state.UpsertJob(1000, job), "UpsertJob")
require.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 1000, job), "UpsertJob")
d1 := mock.Deployment()
d1.Status = structs.DeploymentStatusCancelled
d1.StatusDescription = structs.DeploymentStatusDescriptionNewerJob
@ -6507,7 +6503,7 @@ func TestJobEndpoint_Scale_ACL(t *testing.T) {
state := s1.fsm.State()
job := mock.Job()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
scale := &structs.JobScaleRequest{
@ -6621,7 +6617,7 @@ func TestJobEndpoint_Scale_Invalid(t *testing.T) {
require.Contains(err.Error(), "not found")
// register the job
err = state.UpsertJob(1000, job)
err = state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
scale.Count = helper.Int64ToPtr(10)
@ -6708,7 +6704,7 @@ func TestJobEndpoint_InvalidCount(t *testing.T) {
state := s1.fsm.State()
job := mock.Job()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
scale := &structs.JobScaleRequest{
@ -6753,16 +6749,16 @@ func TestJobEndpoint_GetScaleStatus(t *testing.T) {
require.Nil(resp2.JobScaleStatus)
// stopped (previous version)
require.NoError(state.UpsertJob(1000, jobV1), "UpsertJob")
require.NoError(state.UpsertJob(structs.MsgTypeTestSetup, 1000, jobV1), "UpsertJob")
a0 := mock.Alloc()
a0.Job = jobV1
a0.Namespace = jobV1.Namespace
a0.JobID = jobV1.ID
a0.ClientStatus = structs.AllocClientStatusComplete
require.NoError(state.UpsertAllocs(1010, []*structs.Allocation{a0}), "UpsertAllocs")
require.NoError(state.UpsertAllocs(structs.MsgTypeTestSetup, 1010, []*structs.Allocation{a0}), "UpsertAllocs")
jobV2 := jobV1.Copy()
require.NoError(state.UpsertJob(1100, jobV2), "UpsertJob")
require.NoError(state.UpsertJob(structs.MsgTypeTestSetup, 1100, jobV2), "UpsertJob")
a1 := mock.Alloc()
a1.Job = jobV2
a1.Namespace = jobV2.Namespace
@ -6798,7 +6794,7 @@ func TestJobEndpoint_GetScaleStatus(t *testing.T) {
a4.JobID = jobV2.ID
a4.ClientStatus = structs.AllocClientStatusRunning
// upsert allocations
require.NoError(state.UpsertAllocs(1110, []*structs.Allocation{a1, a2, a3, a4}), "UpsertAllocs")
require.NoError(state.UpsertAllocs(structs.MsgTypeTestSetup, 1110, []*structs.Allocation{a1, a2, a3, a4}), "UpsertAllocs")
event := &structs.ScalingEvent{
Time: time.Now().Unix(),
@ -6855,7 +6851,7 @@ func TestJobEndpoint_GetScaleStatus_ACL(t *testing.T) {
// Create the job
job := mock.Job()
err := state.UpsertJob(1000, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.Nil(err)
// Get the job scale status

View File

@ -267,10 +267,10 @@ func TestClientEndpoint_Deregister_ACL(t *testing.T) {
node := mock.Node()
node1 := mock.Node()
state := s1.fsm.State()
if err := state.UpsertNode(1, node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 1, node); err != nil {
t.Fatalf("err: %v", err)
}
if err := state.UpsertNode(2, node1); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 2, node1); err != nil {
t.Fatalf("err: %v", err)
}
@ -584,7 +584,7 @@ func TestClientEndpoint_Register_GetEvals(t *testing.T) {
// Register a system job.
job := mock.SystemJob()
state := s1.fsm.State()
if err := state.UpsertJob(1, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1, job); err != nil {
t.Fatalf("err: %v", err)
}
@ -679,7 +679,7 @@ func TestClientEndpoint_UpdateStatus_GetEvals(t *testing.T) {
// Register a system job.
job := mock.SystemJob()
state := s1.fsm.State()
if err := state.UpsertJob(1, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1, job); err != nil {
t.Fatalf("err: %v", err)
}
@ -938,7 +938,7 @@ func TestClientEndpoint_UpdateDrain(t *testing.T) {
// Register a system job
job := mock.SystemJob()
require.Nil(s1.State().UpsertJob(10, job))
require.Nil(s1.State().UpsertJob(structs.MsgTypeTestSetup, 10, job))
// Update the eligibility and expect evals
dereg.DrainStrategy = nil
@ -978,7 +978,7 @@ func TestClientEndpoint_UpdateDrain_ACL(t *testing.T) {
node := mock.Node()
state := s1.fsm.State()
require.Nil(state.UpsertNode(1, node), "UpsertNode")
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1, node), "UpsertNode")
// Create the policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid", mock.NodePolicy(acl.PolicyWrite))
@ -1200,7 +1200,7 @@ func TestClientEndpoint_UpdateEligibility(t *testing.T) {
// Register a system job
job := mock.SystemJob()
require.Nil(s1.State().UpsertJob(10, job))
require.Nil(s1.State().UpsertJob(structs.MsgTypeTestSetup, 10, job))
// Update the eligibility and expect evals
elig.Eligibility = structs.NodeSchedulingEligible
@ -1229,7 +1229,7 @@ func TestClientEndpoint_UpdateEligibility_ACL(t *testing.T) {
node := mock.Node()
state := s1.fsm.State()
require.Nil(state.UpsertNode(1, node), "UpsertNode")
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1, node), "UpsertNode")
// Create the policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid", mock.NodePolicy(acl.PolicyWrite))
@ -1353,7 +1353,7 @@ func TestClientEndpoint_GetNode_ACL(t *testing.T) {
// Create the node
node := mock.Node()
state := s1.fsm.State()
assert.Nil(state.UpsertNode(1, node), "UpsertNode")
assert.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1, node), "UpsertNode")
// Create the policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid", mock.NodePolicy(acl.PolicyRead))
@ -1420,14 +1420,14 @@ func TestClientEndpoint_GetNode_Blocking(t *testing.T) {
// First create an unrelated node.
time.AfterFunc(100*time.Millisecond, func() {
if err := state.UpsertNode(100, node1); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 100, node1); err != nil {
t.Fatalf("err: %v", err)
}
})
// Upsert the node we are watching later
time.AfterFunc(200*time.Millisecond, func() {
if err := state.UpsertNode(200, node2); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 200, node2); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -1461,7 +1461,7 @@ func TestClientEndpoint_GetNode_Blocking(t *testing.T) {
nodeUpdate := mock.Node()
nodeUpdate.ID = node2.ID
nodeUpdate.Status = structs.NodeStatusDown
if err := state.UpsertNode(300, nodeUpdate); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 300, nodeUpdate); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -1485,7 +1485,7 @@ func TestClientEndpoint_GetNode_Blocking(t *testing.T) {
// Node delete triggers watches
time.AfterFunc(100*time.Millisecond, func() {
if err := state.DeleteNode(400, []string{node2.ID}); err != nil {
if err := state.DeleteNode(structs.MsgTypeTestSetup, 400, []string{node2.ID}); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -1536,7 +1536,7 @@ func TestClientEndpoint_GetAllocs(t *testing.T) {
alloc.NodeID = node.ID
state := s1.fsm.State()
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1585,10 +1585,10 @@ func TestClientEndpoint_GetAllocs_ACL_Basic(t *testing.T) {
node := mock.Node()
allocDefaultNS.NodeID = node.ID
state := s1.fsm.State()
assert.Nil(state.UpsertNode(1, node), "UpsertNode")
assert.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1, node), "UpsertNode")
assert.Nil(state.UpsertJobSummary(2, mock.JobSummary(allocDefaultNS.JobID)), "UpsertJobSummary")
allocs := []*structs.Allocation{allocDefaultNS}
assert.Nil(state.UpsertAllocs(5, allocs), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 5, allocs), "UpsertAllocs")
// Create the namespace policy and tokens
validDefaultToken := mock.CreatePolicyAndToken(t, state, 1001, "test-default-valid", mock.NodePolicy(acl.PolicyRead)+
@ -1661,13 +1661,13 @@ func TestClientEndpoint_GetClientAllocs(t *testing.T) {
// Create the register request
node := mock.Node()
state := s1.fsm.State()
require.Nil(state.UpsertNode(98, node))
require.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 98, node))
// Inject fake evaluations
alloc := mock.Alloc()
alloc.NodeID = node.ID
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1758,7 +1758,7 @@ func TestClientEndpoint_GetClientAllocs_Blocking(t *testing.T) {
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
start := time.Now()
time.AfterFunc(100*time.Millisecond, func() {
err := state.UpsertAllocs(100, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1825,7 +1825,7 @@ func TestClientEndpoint_GetClientAllocs_Blocking(t *testing.T) {
allocUpdate.ID = alloc.ID
allocUpdate.ClientStatus = structs.AllocClientStatusRunning
state.UpsertJobSummary(199, mock.JobSummary(allocUpdate.JobID))
err := state.UpsertAllocs(200, []*structs.Allocation{allocUpdate})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 200, []*structs.Allocation{allocUpdate})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1879,7 +1879,7 @@ func TestClientEndpoint_GetClientAllocs_Blocking_GC(t *testing.T) {
state.UpsertJobSummary(99, mock.JobSummary(alloc1.JobID))
start := time.Now()
time.AfterFunc(100*time.Millisecond, func() {
assert.Nil(state.UpsertAllocs(100, []*structs.Allocation{alloc1, alloc2}))
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc1, alloc2}))
})
// Lookup the allocs in a blocking query
@ -1958,7 +1958,7 @@ func TestClientEndpoint_GetClientAllocs_WithoutMigrateTokens(t *testing.T) {
alloc.DesiredStatus = structs.AllocClientStatusComplete
state := s1.fsm.State()
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{prevAlloc, alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{prevAlloc, alloc})
assert.Nil(err)
// Lookup the allocs
@ -2008,7 +2008,7 @@ func TestClientEndpoint_GetAllocs_Blocking(t *testing.T) {
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
start := time.Now()
time.AfterFunc(100*time.Millisecond, func() {
err := state.UpsertAllocs(100, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -2103,7 +2103,7 @@ func TestClientEndpoint_UpdateAlloc(t *testing.T) {
// Inject mock job
job := mock.Job()
job.ID = "mytestjob"
err := state.UpsertJob(101, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 101, job)
require.Nil(err)
// Inject fake allocations
@ -2121,7 +2121,7 @@ func TestClientEndpoint_UpdateAlloc(t *testing.T) {
require.Nil(err)
alloc2.TaskGroup = job.TaskGroups[0].Name
err = state.UpsertAllocs(100, []*structs.Allocation{alloc, alloc2})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc, alloc2})
require.Nil(err)
// Attempt updates of more than one alloc for the same job
@ -2195,7 +2195,7 @@ func TestClientEndpoint_BatchUpdate(t *testing.T) {
alloc.NodeID = node.ID
state := s1.fsm.State()
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
err := state.UpsertAllocs(100, []*structs.Allocation{alloc})
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -2257,7 +2257,7 @@ func TestClientEndpoint_UpdateAlloc_Vault(t *testing.T) {
alloc.NodeID = node.ID
state := s1.fsm.State()
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
if err := state.UpsertAllocs(100, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 100, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -2271,7 +2271,7 @@ func TestClientEndpoint_UpdateAlloc_Vault(t *testing.T) {
// Inject mock job
job := mock.Job()
job.ID = alloc.JobID
err := state.UpsertJob(101, job)
err := state.UpsertJob(structs.MsgTypeTestSetup, 101, job)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -2324,13 +2324,13 @@ func TestClientEndpoint_CreateNodeEvals(t *testing.T) {
alloc := mock.Alloc()
state := s1.fsm.State()
state.UpsertJobSummary(1, mock.JobSummary(alloc.JobID))
if err := state.UpsertAllocs(2, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 2, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
// Inject a fake system job.
job := mock.SystemJob()
if err := state.UpsertJob(3, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 3, job); err != nil {
t.Fatalf("err: %v", err)
}
@ -2411,12 +2411,12 @@ func TestClientEndpoint_Evaluate(t *testing.T) {
node := mock.Node()
node.ID = alloc.NodeID
state := s1.fsm.State()
err := state.UpsertNode(1, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 1, node)
if err != nil {
t.Fatalf("err: %v", err)
}
state.UpsertJobSummary(2, mock.JobSummary(alloc.JobID))
err = state.UpsertAllocs(3, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{alloc})
if err != nil {
t.Fatalf("err: %v", err)
}
@ -2499,9 +2499,9 @@ func TestClientEndpoint_Evaluate_ACL(t *testing.T) {
node.ID = alloc.NodeID
state := s1.fsm.State()
assert.Nil(state.UpsertNode(1, node), "UpsertNode")
assert.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1, node), "UpsertNode")
assert.Nil(state.UpsertJobSummary(2, mock.JobSummary(alloc.JobID)), "UpsertJobSummary")
assert.Nil(state.UpsertAllocs(3, []*structs.Allocation{alloc}), "UpsertAllocs")
assert.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{alloc}), "UpsertAllocs")
// Create the policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid", mock.NodePolicy(acl.PolicyWrite))
@ -2664,7 +2664,7 @@ func TestClientEndpoint_ListNodes_ACL(t *testing.T) {
// Create the node
node := mock.Node()
state := s1.fsm.State()
assert.Nil(state.UpsertNode(1, node), "UpsertNode")
assert.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1, node), "UpsertNode")
// Create the namespace policy and tokens
validToken := mock.CreatePolicyAndToken(t, state, 1001, "test-valid", mock.NodePolicy(acl.PolicyRead))
@ -2725,7 +2725,7 @@ func TestClientEndpoint_ListNodes_Blocking(t *testing.T) {
// Node upsert triggers watches
errCh := make(chan error, 1)
timer := time.AfterFunc(100*time.Millisecond, func() {
errCh <- state.UpsertNode(2, node)
errCh <- state.UpsertNode(structs.MsgTypeTestSetup, 2, node)
})
defer timer.Stop()
@ -2762,7 +2762,7 @@ func TestClientEndpoint_ListNodes_Blocking(t *testing.T) {
Deadline: 10 * time.Second,
},
}
errCh <- state.UpdateNodeDrain(3, node.ID, s, false, 0, nil)
errCh <- state.UpdateNodeDrain(structs.MsgTypeTestSetup, 3, node.ID, s, false, 0, nil)
})
req.MinQueryIndex = 2
@ -2814,7 +2814,7 @@ func TestClientEndpoint_ListNodes_Blocking(t *testing.T) {
// Node delete triggers watches.
time.AfterFunc(100*time.Millisecond, func() {
errCh <- state.DeleteNode(50, []string{node.ID})
errCh <- state.DeleteNode(structs.MsgTypeTestSetup, 50, []string{node.ID})
})
req.MinQueryIndex = 45
@ -2850,7 +2850,7 @@ func TestClientEndpoint_DeriveVaultToken_Bad(t *testing.T) {
// Create the node
node := mock.Node()
if err := state.UpsertNode(2, node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 2, node); err != nil {
t.Fatalf("err: %v", err)
}
@ -2858,7 +2858,7 @@ func TestClientEndpoint_DeriveVaultToken_Bad(t *testing.T) {
alloc := mock.Alloc()
task := alloc.Job.TaskGroups[0].Tasks[0]
tasks := []string{task.Name}
if err := state.UpsertAllocs(3, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -2894,7 +2894,7 @@ func TestClientEndpoint_DeriveVaultToken_Bad(t *testing.T) {
// Update to be running on the node
alloc.NodeID = node.ID
if err := state.UpsertAllocs(4, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 4, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -2908,7 +2908,7 @@ func TestClientEndpoint_DeriveVaultToken_Bad(t *testing.T) {
// Update to be terminal
alloc.DesiredStatus = structs.AllocDesiredStatusStop
if err := state.UpsertAllocs(5, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 5, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -2941,7 +2941,7 @@ func TestClientEndpoint_DeriveVaultToken(t *testing.T) {
// Create the node
node := mock.Node()
if err := state.UpsertNode(2, node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 2, node); err != nil {
t.Fatalf("err: %v", err)
}
@ -2951,7 +2951,7 @@ func TestClientEndpoint_DeriveVaultToken(t *testing.T) {
task := alloc.Job.TaskGroups[0].Tasks[0]
tasks := []string{task.Name}
task.Vault = &structs.Vault{Policies: []string{"a", "b"}}
if err := state.UpsertAllocs(3, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -3034,7 +3034,7 @@ func TestClientEndpoint_DeriveVaultToken_VaultError(t *testing.T) {
// Create the node
node := mock.Node()
if err := state.UpsertNode(2, node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 2, node); err != nil {
t.Fatalf("err: %v", err)
}
@ -3044,7 +3044,7 @@ func TestClientEndpoint_DeriveVaultToken_VaultError(t *testing.T) {
task := alloc.Job.TaskGroups[0].Tasks[0]
tasks := []string{task.Name}
task.Vault = &structs.Vault{Policies: []string{"a", "b"}}
if err := state.UpsertAllocs(3, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -3168,7 +3168,7 @@ func TestClientEndpoint_DeriveSIToken(t *testing.T) {
// Create the node
node := mock.Node()
err := state.UpsertNode(2, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 2, node)
r.NoError(err)
// Create an alloc with a typical connect service (sidecar) defined
@ -3177,7 +3177,7 @@ func TestClientEndpoint_DeriveSIToken(t *testing.T) {
mutateConnectJob(t, alloc.Job) // appends sidecar task
sidecarTask := alloc.Job.TaskGroups[0].Tasks[1]
err = state.UpsertAllocs(3, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{alloc})
r.NoError(err)
request := &structs.DeriveSITokenRequest{
@ -3220,7 +3220,7 @@ func TestClientEndpoint_DeriveSIToken_ConsulError(t *testing.T) {
// Create the node
node := mock.Node()
err := state.UpsertNode(2, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 2, node)
r.NoError(err)
// Create an alloc with a typical connect service (sidecar) defined
@ -3235,7 +3235,7 @@ func TestClientEndpoint_DeriveSIToken_ConsulError(t *testing.T) {
m := NewConsulACLsAPI(mockACLsAPI, s1.logger, nil)
s1.consulACLs = m
err = state.UpsertAllocs(3, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, 3, []*structs.Allocation{alloc})
r.NoError(err)
request := &structs.DeriveSITokenRequest{
@ -3265,7 +3265,7 @@ func TestClientEndpoint_EmitEvents(t *testing.T) {
// create a node that we can register our event to
node := mock.Node()
err := state.UpsertNode(2, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, 2, node)
require.Nil(err)
nodeEvent := &structs.NodeEvent{

View File

@ -762,7 +762,7 @@ func generateSnapshot(t *testing.T) (*snapshot.Snapshot, *structs.Job) {
err = msgpackrpc.CallWithCodec(codec, "Job.Register", jobReq, &jobResp)
require.NoError(t, err)
err = s.State().UpsertJob(1000, job)
err = s.State().UpsertJob(structs.MsgTypeTestSetup, 1000, job)
require.NoError(t, err)
snapshot, err := snapshot.New(s.logger, s.raft)

View File

@ -26,7 +26,7 @@ func TestPeriodicEndpoint_Force(t *testing.T) {
// Create and insert a periodic job.
job := mock.PeriodicJob()
job.Periodic.ProhibitOverlap = true // Shouldn't affect anything.
if err := state.UpsertJob(100, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job); err != nil {
t.Fatalf("err: %v", err)
}
s1.periodicDispatcher.Add(job)
@ -78,7 +78,7 @@ func TestPeriodicEndpoint_Force_ACL(t *testing.T) {
// Create and insert a periodic job.
job := mock.PeriodicJob()
job.Periodic.ProhibitOverlap = true // Shouldn't affect anything.
assert.Nil(state.UpsertJob(100, job))
assert.Nil(state.UpsertJob(structs.MsgTypeTestSetup, 100, job))
err := s1.periodicDispatcher.Add(job)
assert.Nil(err)
@ -157,7 +157,7 @@ func TestPeriodicEndpoint_Force_NonPeriodic(t *testing.T) {
// Create and insert a non-periodic job.
job := mock.Job()
if err := state.UpsertJob(100, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 100, job); err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -658,7 +658,7 @@ func TestPeriodicDispatch_RunningChildren_NoEvals(t *testing.T) {
// Insert job.
state := s1.fsm.State()
job := mock.PeriodicJob()
if err := state.UpsertJob(1000, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job); err != nil {
t.Fatalf("UpsertJob failed: %v", err)
}
@ -682,12 +682,12 @@ func TestPeriodicDispatch_RunningChildren_ActiveEvals(t *testing.T) {
// Insert periodic job and child.
state := s1.fsm.State()
job := mock.PeriodicJob()
if err := state.UpsertJob(1000, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job); err != nil {
t.Fatalf("UpsertJob failed: %v", err)
}
childjob := deriveChildJob(job)
if err := state.UpsertJob(1001, childjob); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1001, childjob); err != nil {
t.Fatalf("UpsertJob failed: %v", err)
}
@ -695,7 +695,7 @@ func TestPeriodicDispatch_RunningChildren_ActiveEvals(t *testing.T) {
eval := mock.Eval()
eval.JobID = childjob.ID
eval.Status = structs.EvalStatusPending
if err := state.UpsertEvals(1002, []*structs.Evaluation{eval}); err != nil {
if err := state.UpsertEvals(structs.MsgTypeTestSetup, 1002, []*structs.Evaluation{eval}); err != nil {
t.Fatalf("UpsertEvals failed: %v", err)
}
@ -719,12 +719,12 @@ func TestPeriodicDispatch_RunningChildren_ActiveAllocs(t *testing.T) {
// Insert periodic job and child.
state := s1.fsm.State()
job := mock.PeriodicJob()
if err := state.UpsertJob(1000, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job); err != nil {
t.Fatalf("UpsertJob failed: %v", err)
}
childjob := deriveChildJob(job)
if err := state.UpsertJob(1001, childjob); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1001, childjob); err != nil {
t.Fatalf("UpsertJob failed: %v", err)
}
@ -732,7 +732,7 @@ func TestPeriodicDispatch_RunningChildren_ActiveAllocs(t *testing.T) {
eval := mock.Eval()
eval.JobID = childjob.ID
eval.Status = structs.EvalStatusPending
if err := state.UpsertEvals(1002, []*structs.Evaluation{eval}); err != nil {
if err := state.UpsertEvals(structs.MsgTypeTestSetup, 1002, []*structs.Evaluation{eval}); err != nil {
t.Fatalf("UpsertEvals failed: %v", err)
}
@ -741,7 +741,7 @@ func TestPeriodicDispatch_RunningChildren_ActiveAllocs(t *testing.T) {
alloc.JobID = childjob.ID
alloc.EvalID = eval.ID
alloc.DesiredStatus = structs.AllocDesiredStatusRun
if err := state.UpsertAllocs(1003, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("UpsertAllocs failed: %v", err)
}

View File

@ -11,7 +11,7 @@ func TestEvaluatePool(t *testing.T) {
t.Parallel()
state := testStateStore(t)
node := mock.Node()
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
snap, _ := state.Snapshot()
alloc := mock.Alloc()

View File

@ -100,7 +100,7 @@ func TestPlanApply_applyPlan(t *testing.T) {
// Create an eval
eval := mock.Eval()
eval.JobID = alloc.JobID
if err := s1.State().UpsertEvals(1, []*structs.Evaluation{eval}); err != nil {
if err := s1.State().UpsertEvals(structs.MsgTypeTestSetup, 1, []*structs.Evaluation{eval}); err != nil {
t.Fatalf("err: %v", err)
}
@ -284,11 +284,11 @@ func TestPlanApply_applyPlanWithNormalizedAllocs(t *testing.T) {
PreemptedByAllocation: alloc.ID,
}
s1.State().UpsertJobSummary(1000, mock.JobSummary(alloc.JobID))
s1.State().UpsertAllocs(1100, []*structs.Allocation{stoppedAlloc, preemptedAlloc})
s1.State().UpsertAllocs(structs.MsgTypeTestSetup, 1100, []*structs.Allocation{stoppedAlloc, preemptedAlloc})
// Create an eval
eval := mock.Eval()
eval.JobID = alloc.JobID
if err := s1.State().UpsertEvals(1, []*structs.Evaluation{eval}); err != nil {
if err := s1.State().UpsertEvals(structs.MsgTypeTestSetup, 1, []*structs.Evaluation{eval}); err != nil {
t.Fatalf("err: %v", err)
}
@ -393,7 +393,7 @@ func TestPlanApply_EvalPlan_Simple(t *testing.T) {
t.Parallel()
state := testStateStore(t)
node := mock.Node()
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
snap, _ := state.Snapshot()
alloc := mock.Alloc()
@ -455,7 +455,7 @@ func TestPlanApply_EvalPlan_Preemption(t *testing.T) {
},
},
}
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
preemptedAlloc := mock.Alloc()
preemptedAlloc.NodeID = node.ID
@ -485,7 +485,7 @@ func TestPlanApply_EvalPlan_Preemption(t *testing.T) {
}
// Insert a preempted alloc such that the alloc will fit only after preemption
state.UpsertAllocs(1001, []*structs.Allocation{preemptedAlloc})
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{preemptedAlloc})
alloc := mock.Alloc()
alloc.AllocatedResources = &structs.AllocatedResources{
@ -551,9 +551,9 @@ func TestPlanApply_EvalPlan_Partial(t *testing.T) {
t.Parallel()
state := testStateStore(t)
node := mock.Node()
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
node2 := mock.Node()
state.UpsertNode(1001, node2)
state.UpsertNode(structs.MsgTypeTestSetup, 1001, node2)
snap, _ := state.Snapshot()
alloc := mock.Alloc()
@ -609,9 +609,9 @@ func TestPlanApply_EvalPlan_Partial_AllAtOnce(t *testing.T) {
t.Parallel()
state := testStateStore(t)
node := mock.Node()
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
node2 := mock.Node()
state.UpsertNode(1001, node2)
state.UpsertNode(structs.MsgTypeTestSetup, 1001, node2)
snap, _ := state.Snapshot()
alloc := mock.Alloc()
@ -660,7 +660,7 @@ func TestPlanApply_EvalNodePlan_Simple(t *testing.T) {
t.Parallel()
state := testStateStore(t)
node := mock.Node()
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
snap, _ := state.Snapshot()
alloc := mock.Alloc()
@ -688,7 +688,7 @@ func TestPlanApply_EvalNodePlan_NodeNotReady(t *testing.T) {
state := testStateStore(t)
node := mock.Node()
node.Status = structs.NodeStatusInit
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
snap, _ := state.Snapshot()
alloc := mock.Alloc()
@ -716,7 +716,7 @@ func TestPlanApply_EvalNodePlan_NodeDrain(t *testing.T) {
state := testStateStore(t)
node := mock.Node()
node.Drain = true
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
snap, _ := state.Snapshot()
alloc := mock.Alloc()
@ -774,8 +774,8 @@ func TestPlanApply_EvalNodePlan_NodeFull(t *testing.T) {
alloc.NodeID = node.ID
alloc.AllocatedResources = structs.NodeResourcesToAllocatedResources(node.NodeResources)
state.UpsertJobSummary(999, mock.JobSummary(alloc.JobID))
state.UpsertNode(1000, node)
state.UpsertAllocs(1001, []*structs.Allocation{alloc})
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})
alloc2 := mock.Alloc()
alloc2.NodeID = node.ID
@ -824,8 +824,8 @@ func TestPlanApply_EvalNodePlan_NodeFull_Device(t *testing.T) {
}
state.UpsertJobSummary(999, mock.JobSummary(alloc.JobID))
state.UpsertNode(1000, node)
state.UpsertAllocs(1001, []*structs.Allocation{alloc})
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})
// Alloc2 tries to use the same device
alloc2 := mock.Alloc()
@ -864,8 +864,8 @@ func TestPlanApply_EvalNodePlan_UpdateExisting(t *testing.T) {
node.Reserved = nil
alloc.NodeID = node.ID
alloc.AllocatedResources = structs.NodeResourcesToAllocatedResources(node.NodeResources)
state.UpsertNode(1000, node)
state.UpsertAllocs(1001, []*structs.Allocation{alloc})
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})
snap, _ := state.Snapshot()
plan := &structs.Plan{
@ -895,8 +895,8 @@ func TestPlanApply_EvalNodePlan_NodeFull_Evict(t *testing.T) {
node.ReservedResources = nil
alloc.NodeID = node.ID
alloc.AllocatedResources = structs.NodeResourcesToAllocatedResources(node.NodeResources)
state.UpsertNode(1000, node)
state.UpsertAllocs(1001, []*structs.Allocation{alloc})
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})
snap, _ := state.Snapshot()
allocEvict := new(structs.Allocation)
@ -934,8 +934,8 @@ func TestPlanApply_EvalNodePlan_NodeFull_AllocEvict(t *testing.T) {
alloc.NodeID = node.ID
alloc.DesiredStatus = structs.AllocDesiredStatusEvict
alloc.AllocatedResources = structs.NodeResourcesToAllocatedResources(node.NodeResources)
state.UpsertNode(1000, node)
state.UpsertAllocs(1001, []*structs.Allocation{alloc})
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})
snap, _ := state.Snapshot()
alloc2 := mock.Alloc()
@ -967,8 +967,8 @@ func TestPlanApply_EvalNodePlan_NodeDown_EvictOnly(t *testing.T) {
alloc.AllocatedResources = structs.NodeResourcesToAllocatedResources(node.NodeResources)
node.ReservedResources = nil
node.Status = structs.NodeStatusDown
state.UpsertNode(1000, node)
state.UpsertAllocs(1001, []*structs.Allocation{alloc})
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})
snap, _ := state.Snapshot()
allocEvict := new(structs.Allocation)

View File

@ -22,7 +22,7 @@ func registerAndVerifyJob(s *Server, t *testing.T, prefix string, counter int) *
job := mock.Job()
job.ID = prefix + strconv.Itoa(counter)
state := s.fsm.State()
if err := state.UpsertJob(jobIndex, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, jobIndex, job); err != nil {
t.Fatalf("err: %v", err)
}
@ -76,7 +76,7 @@ func TestSearch_PrefixSearch_ACL(t *testing.T) {
state := s.fsm.State()
job := registerAndVerifyJob(s, t, jobID, 0)
assert.Nil(state.UpsertNode(1001, mock.Node()))
assert.Nil(state.UpsertNode(structs.MsgTypeTestSetup, 1001, mock.Node()))
req := &structs.SearchRequest{
Prefix: "",
@ -197,7 +197,7 @@ func TestSearch_PrefixSearch_All_JobWithHyphen(t *testing.T) {
if err := state.UpsertJobSummary(999, summary); err != nil {
t.Fatalf("err: %v", err)
}
if err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -242,7 +242,7 @@ func TestSearch_PrefixSearch_All_LongJob(t *testing.T) {
if err := state.UpsertJobSummary(999, summary); err != nil {
t.Fatalf("err: %v", err)
}
if err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -319,7 +319,7 @@ func TestSearch_PrefixSearch_AllWithJob(t *testing.T) {
eval1 := mock.Eval()
eval1.ID = job.ID
s.fsm.State().UpsertEvals(2000, []*structs.Evaluation{eval1})
s.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 2000, []*structs.Evaluation{eval1})
req := &structs.SearchRequest{
Prefix: prefix,
@ -354,7 +354,7 @@ func TestSearch_PrefixSearch_Evals(t *testing.T) {
testutil.WaitForLeader(t, s.RPC)
eval1 := mock.Eval()
s.fsm.State().UpsertEvals(2000, []*structs.Evaluation{eval1})
s.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 2000, []*structs.Evaluation{eval1})
prefix := eval1.ID[:len(eval1.ID)-2]
@ -397,7 +397,7 @@ func TestSearch_PrefixSearch_Allocation(t *testing.T) {
if err := state.UpsertJobSummary(999, summary); err != nil {
t.Fatalf("err: %v", err)
}
if err := state.UpsertAllocs(90, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 90, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
@ -442,18 +442,18 @@ func TestSearch_PrefixSearch_All_UUID(t *testing.T) {
if err := state.UpsertJobSummary(999, summary); err != nil {
t.Fatalf("err: %v", err)
}
if err := state.UpsertAllocs(1000, []*structs.Allocation{alloc}); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc}); err != nil {
t.Fatalf("err: %v", err)
}
node := mock.Node()
if err := state.UpsertNode(1001, node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 1001, node); err != nil {
t.Fatalf("err: %v", err)
}
eval1 := mock.Eval()
eval1.ID = node.ID
if err := state.UpsertEvals(1002, []*structs.Evaluation{eval1}); err != nil {
if err := state.UpsertEvals(structs.MsgTypeTestSetup, 1002, []*structs.Evaluation{eval1}); err != nil {
t.Fatalf("err: %v", err)
}
@ -490,7 +490,7 @@ func TestSearch_PrefixSearch_Node(t *testing.T) {
state := s.fsm.State()
node := mock.Node()
if err := state.UpsertNode(100, node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 100, node); err != nil {
t.Fatalf("err: %v", err)
}
@ -569,13 +569,13 @@ func TestSearch_PrefixSearch_AllContext(t *testing.T) {
state := s.fsm.State()
node := mock.Node()
if err := state.UpsertNode(100, node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, 100, node); err != nil {
t.Fatalf("err: %v", err)
}
eval1 := mock.Eval()
eval1.ID = node.ID
if err := state.UpsertEvals(1000, []*structs.Evaluation{eval1}); err != nil {
if err := state.UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1}); err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -79,7 +79,7 @@ func WaitForEvents(t *testing.T, s *StateStore, index uint64, minEvents int, tim
}
maxAttempts--
if maxAttempts == 0 {
require.Fail(t, "reached max attempts waiting for desired event count")
require.Failf(t, "reached max attempts waiting for desired event count", "count %d", len(got))
}
time.Sleep(10 * time.Millisecond)
}

View File

@ -244,8 +244,8 @@ func TestGenericEventsFromChanges_UpsertNodeEventsType(t *testing.T) {
n1 := mock.Node()
n2 := mock.Node()
require.NoError(t, s.UpsertNode(10, n1))
require.NoError(t, s.UpsertNode(12, n2))
require.NoError(t, s.UpsertNode(structs.MsgTypeTestSetup, 10, n1))
require.NoError(t, s.UpsertNode(structs.MsgTypeTestSetup, 12, n2))
msgType := structs.UpsertNodeEventsType
req := &structs.EmitNodeEventsRequest{
@ -263,7 +263,7 @@ func TestGenericEventsFromChanges_UpsertNodeEventsType(t *testing.T) {
},
}
require.NoError(t, s.UpsertNodeEventsMsgType(msgType, 100, req.NodeEvents))
require.NoError(t, s.UpsertNodeEvents(msgType, 100, req.NodeEvents))
events := WaitForEvents(t, s, 100, 1, 1*time.Second)
require.Len(t, events, 2)
@ -284,7 +284,7 @@ func TestGenericEventsFromChanges_NodeUpdateStatusRequest(t *testing.T) {
// setup
n1 := mock.Node()
require.NoError(t, s.UpsertNode(10, n1))
require.NoError(t, s.UpsertNode(structs.MsgTypeTestSetup, 10, n1))
updated := time.Now()
msgType := structs.NodeUpdateStatusRequestType
@ -315,7 +315,7 @@ func TestGenericEventsFromChanges_EvalUpdateRequestType(t *testing.T) {
// setup
e1 := mock.Eval()
require.NoError(t, s.UpsertEvals(10, []*structs.Evaluation{e1}))
require.NoError(t, s.UpsertEvals(structs.MsgTypeTestSetup, 10, []*structs.Evaluation{e1}))
e2 := mock.Eval()
e2.ID = e1.ID
@ -327,7 +327,7 @@ func TestGenericEventsFromChanges_EvalUpdateRequestType(t *testing.T) {
Evals: []*structs.Evaluation{e2},
}
require.NoError(t, s.UpsertEvalsMsgType(msgType, 100, req.Evals))
require.NoError(t, s.UpsertEvals(msgType, 100, req.Evals))
events := WaitForEvents(t, s, 100, 1, 1*time.Second)
require.Len(t, events, 1)
@ -355,13 +355,13 @@ func TestGenericEventsFromChanges_ApplyPlanResultsRequestType(t *testing.T) {
alloc.DeploymentID = d.ID
alloc2.DeploymentID = d.ID
require.NoError(t, s.UpsertJob(9, job))
require.NoError(t, s.UpsertJob(structs.MsgTypeTestSetup, 9, job))
eval := mock.Eval()
eval.JobID = job.ID
// Create an eval
require.NoError(t, s.UpsertEvals(10, []*structs.Evaluation{eval}))
require.NoError(t, s.UpsertEvals(structs.MsgTypeTestSetup, 10, []*structs.Evaluation{eval}))
msgType := structs.ApplyPlanResultsRequestType
req := &structs.ApplyPlanResultsRequest{
@ -409,8 +409,8 @@ func TestGenericEventsFromChanges_BatchNodeUpdateDrainRequestType(t *testing.T)
n1 := mock.Node()
n2 := mock.Node()
require.NoError(t, s.UpsertNode(10, n1))
require.NoError(t, s.UpsertNode(11, n2))
require.NoError(t, s.UpsertNode(structs.MsgTypeTestSetup, 10, n1))
require.NoError(t, s.UpsertNode(structs.MsgTypeTestSetup, 11, n2))
updated := time.Now()
msgType := structs.BatchNodeUpdateDrainRequestType
@ -463,7 +463,7 @@ func TestGenericEventsFromChanges_NodeUpdateEligibilityRequestType(t *testing.T)
// setup
n1 := mock.Node()
require.NoError(t, s.UpsertNode(10, n1))
require.NoError(t, s.UpsertNode(structs.MsgTypeTestSetup, 10, n1))
msgType := structs.NodeUpdateEligibilityRequestType
@ -502,8 +502,8 @@ func TestGenericEventsFromChanges_AllocUpdateDesiredTransitionRequestType(t *tes
alloc := mock.Alloc()
require.Nil(t, s.UpsertJob(10, alloc.Job))
require.Nil(t, s.UpsertAllocs(11, []*structs.Allocation{alloc}))
require.Nil(t, s.UpsertJob(structs.MsgTypeTestSetup, 10, alloc.Job))
require.Nil(t, s.UpsertAllocs(structs.MsgTypeTestSetup, 11, []*structs.Allocation{alloc}))
msgType := structs.AllocUpdateDesiredTransitionRequestType

View File

@ -72,6 +72,7 @@ func (c *changeTrackerDB) WriteTxn(idx uint64) *txn {
Txn: c.memdb.Txn(true),
Index: idx,
publish: c.publish,
msgType: structs.IgnoreUnknownTypeFlag, // The zero value of structs.MessageType is noderegistration.
}
t.Txn.TrackChanges()
return t

View File

@ -782,26 +782,11 @@ func (s *StateStore) ScalingEventsByJob(ws memdb.WatchSet, namespace, jobID stri
return nil, 0, nil
}
// UpsertNodeMsgType is used to register a node or update a node definition
// This is assumed to be triggered by the client, so we retain the value
// of drain/eligibility which is set by the scheduler.
// TODO(drew) remove this and update all test callers of UpsertNode to use msgType
func (s *StateStore) UpsertNodeMsgType(msgType structs.MessageType, index uint64, node *structs.Node) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
err := upsertNodeTxn(txn, index, node)
if err != nil {
return nil
}
return txn.Commit()
}
// UpsertNode is used to register a node or update a node definition
// This is assumed to be triggered by the client, so we retain the value
// of drain/eligibility which is set by the scheduler.
func (s *StateStore) UpsertNode(index uint64, node *structs.Node) error {
txn := s.db.WriteTxn(index)
func (s *StateStore) UpsertNode(msgType structs.MessageType, index uint64, node *structs.Node) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
err := upsertNodeTxn(txn, index, node)
@ -864,19 +849,7 @@ func upsertNodeTxn(txn *txn, index uint64, node *structs.Node) error {
}
// DeleteNode deregisters a batch of nodes
func (s *StateStore) DeleteNodeMsgType(msgType structs.MessageType, index uint64, nodes []string) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
err := deleteNodeTxn(txn, index, nodes)
if err != nil {
return nil
}
return txn.Commit()
}
// DeleteNode deregisters a batch of nodes
func (s *StateStore) DeleteNode(index uint64, nodes []string) error {
func (s *StateStore) DeleteNode(msgType structs.MessageType, index uint64, nodes []string) error {
txn := s.db.WriteTxn(index)
defer txn.Abort()
@ -979,20 +952,7 @@ func (s *StateStore) BatchUpdateNodeDrain(msgType structs.MessageType, index uin
}
// UpdateNodeDrain is used to update the drain of a node
func (s *StateStore) UpdateNodeDrainMsgType(msgType structs.MessageType, index uint64, nodeID string,
drain *structs.DrainStrategy, markEligible bool, updatedAt int64, event *structs.NodeEvent) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
if err := s.updateNodeDrainImpl(txn, index, nodeID, drain, markEligible, updatedAt, event); err != nil {
return err
}
return txn.Commit()
}
// UpdateNodeDrain is used to update the drain of a node
func (s *StateStore) UpdateNodeDrain(index uint64, nodeID string,
drain *structs.DrainStrategy, markEligible bool, updatedAt int64, event *structs.NodeEvent) error {
func (s *StateStore) UpdateNodeDrain(msgType structs.MessageType, index uint64, nodeID string, drain *structs.DrainStrategy, markEligible bool, updatedAt int64, event *structs.NodeEvent) error {
txn := s.db.WriteTxn(index)
defer txn.Abort()
@ -1091,23 +1051,10 @@ func (s *StateStore) UpdateNodeEligibility(msgType structs.MessageType, index ui
return txn.Commit()
}
func (s *StateStore) UpsertNodeEventsMsgType(msgType structs.MessageType, index uint64, nodeEvents map[string][]*structs.NodeEvent) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
for nodeID, events := range nodeEvents {
if err := s.upsertNodeEvents(index, nodeID, events, txn); err != nil {
return err
}
}
return txn.Commit()
}
// UpsertNodeEvents adds the node events to the nodes, rotating events as
// necessary.
func (s *StateStore) UpsertNodeEvents(index uint64, nodeEvents map[string][]*structs.NodeEvent) error {
txn := s.db.WriteTxn(index)
func (s *StateStore) UpsertNodeEvents(msgType structs.MessageType, index uint64, nodeEvents map[string][]*structs.NodeEvent) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
for nodeID, events := range nodeEvents {
@ -1496,7 +1443,7 @@ func (s *StateStore) Nodes(ws memdb.WatchSet) (memdb.ResultIterator, error) {
}
// UpsertJob is used to register a job or update a job definition
func (s *StateStore) UpsertJob(index uint64, job *structs.Job) error {
func (s *StateStore) UpsertJob(msgType structs.MessageType, index uint64, job *structs.Job) error {
txn := s.db.WriteTxn(index)
defer txn.Abort()
if err := s.upsertJobImpl(index, job, false, txn); err != nil {
@ -1505,16 +1452,6 @@ func (s *StateStore) UpsertJob(index uint64, job *structs.Job) error {
return txn.Commit()
}
// UpsertJob is used to register a job or update a job definition
func (s *StateStore) UpsertJobMsgType(msgType structs.MessageType, index uint64, job *structs.Job) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
if err := s.upsertJobImpl(index, job, false, txn); err != nil {
return err
}
return txn.Commit()
}
// UpsertJobTxn is used to register a job or update a job definition, like UpsertJob,
// but in a transaction. Useful for when making multiple modifications atomically
func (s *StateStore) UpsertJobTxn(index uint64, job *structs.Job, txn Txn) error {
@ -2711,19 +2648,7 @@ func (s *StateStore) PeriodicLaunches(ws memdb.WatchSet) (memdb.ResultIterator,
}
// UpsertEvals is used to upsert a set of evaluations
func (s *StateStore) UpsertEvals(index uint64, evals []*structs.Evaluation) error {
txn := s.db.WriteTxn(index)
defer txn.Abort()
err := s.UpsertEvalsTxn(index, evals, txn)
if err == nil {
return txn.Commit()
}
return err
}
// UpsertEvals is used to upsert a set of evaluations
func (s *StateStore) UpsertEvalsMsgType(msgType structs.MessageType, index uint64, evals []*structs.Evaluation) error {
func (s *StateStore) UpsertEvals(msgType structs.MessageType, index uint64, evals []*structs.Evaluation) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
@ -3154,7 +3079,7 @@ func (s *StateStore) nestedUpdateAllocFromClient(txn *txn, index uint64, alloc *
// UpsertAllocs is used to evict a set of allocations and allocate new ones at
// the same time.
func (s *StateStore) UpsertAllocs(index uint64, allocs []*structs.Allocation) error {
func (s *StateStore) UpsertAllocs(msgType structs.MessageType, index uint64, allocs []*structs.Allocation) error {
txn := s.db.WriteTxn(index)
defer txn.Abort()
if err := s.upsertAllocsImpl(index, allocs, txn); err != nil {
@ -3163,17 +3088,6 @@ func (s *StateStore) UpsertAllocs(index uint64, allocs []*structs.Allocation) er
return txn.Commit()
}
// UpsertAllocsMsgType is used to evict a set of allocations and allocate new ones at
// the same time.
func (s *StateStore) UpsertAllocsMsgType(msgType structs.MessageType, index uint64, allocs []*structs.Allocation) error {
txn := s.db.WriteTxnMsgT(msgType, index)
defer txn.Abort()
if err := s.upsertAllocsImpl(index, allocs, txn); err != nil {
return err
}
return txn.Commit()
}
// upsertAllocs is the actual implementation of UpsertAllocs so that it may be
// used with an existing transaction.
func (s *StateStore) upsertAllocsImpl(index uint64, allocs []*structs.Allocation, txn *txn) error {

View File

@ -33,7 +33,7 @@ func TestStateStore_Events_OnEvict(t *testing.T) {
// force 3 evictions
for i := 1; i < 13; i++ {
require.NoError(t,
s.UpsertNodeMsgType(structs.NodeRegisterRequestType, uint64(i), mock.Node()),
s.UpsertNode(structs.NodeRegisterRequestType, uint64(i), mock.Node()),
)
}
@ -107,7 +107,7 @@ func TestStateStore_Events_OnEvict_Missing(t *testing.T) {
// Publish 13 events to fill buffer and force 3 evictions
for i := 1; i < 13; i++ {
require.NoError(t,
s.UpsertNodeMsgType(structs.NodeRegisterRequestType, uint64(i), mock.Node()),
s.UpsertNode(structs.NodeRegisterRequestType, uint64(i), mock.Node()),
)
}

File diff suppressed because it is too large Load Diff

View File

@ -108,7 +108,7 @@ func createTestCSIPlugin(s *StateStore, id string, requiresController bool) func
index := uint64(999)
for _, n := range ns {
index++
s.UpsertNode(index, n)
s.UpsertNode(structs.MsgTypeTestSetup, index, n)
}
ids := make([]string, len(ns))
@ -119,6 +119,6 @@ func createTestCSIPlugin(s *StateStore, id string, requiresController bool) func
// Return cleanup function that deletes the nodes
return func() {
index++
s.DeleteNode(index, ids)
s.DeleteNode(structs.MsgTypeTestSetup, index, ids)
}
}

View File

@ -27,14 +27,14 @@ func TestSystemEndpoint_GarbageCollect(t *testing.T) {
job := mock.Job()
job.Type = structs.JobTypeBatch
job.Stop = true
if err := state.UpsertJob(1000, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job); err != nil {
t.Fatalf("UpsertJob() failed: %v", err)
}
eval := mock.Eval()
eval.Status = structs.EvalStatusComplete
eval.JobID = job.ID
if err := state.UpsertEvals(1001, []*structs.Evaluation{eval}); err != nil {
if err := state.UpsertEvals(structs.MsgTypeTestSetup, 1001, []*structs.Evaluation{eval}); err != nil {
t.Fatalf("UpsertEvals() failed: %v", err)
}
@ -122,7 +122,7 @@ func TestSystemEndpoint_ReconcileSummaries(t *testing.T) {
state := s1.fsm.State()
s1.fsm.State()
job := mock.Job()
if err := state.UpsertJob(1000, job); err != nil {
if err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, job); err != nil {
t.Fatalf("UpsertJob() failed: %v", err)
}

View File

@ -35,7 +35,7 @@ func testNode(plugin *structs.CSIPlugin, s *state.StateStore) *structs.Node {
} else {
node.CSIControllerPlugins = map[string]*structs.CSIInfo{}
}
s.UpsertNode(99, node)
s.UpsertNode(structs.MsgTypeTestSetup, 99, node)
return node
}

View File

@ -111,10 +111,10 @@ func TestVolumeWatch_StartStop(t *testing.T) {
alloc2.Job = alloc1.Job
alloc2.ClientStatus = structs.AllocClientStatusRunning
index++
err := srv.State().UpsertJob(index, alloc1.Job)
err := srv.State().UpsertJob(structs.MsgTypeTestSetup, index, alloc1.Job)
require.NoError(err)
index++
err = srv.State().UpsertAllocs(index, []*structs.Allocation{alloc1, alloc2})
err = srv.State().UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc1, alloc2})
require.NoError(err)
// register a volume
@ -160,7 +160,7 @@ func TestVolumeWatch_StartStop(t *testing.T) {
// alloc becomes terminal
alloc1.ClientStatus = structs.AllocClientStatusComplete
index++
err = srv.State().UpsertAllocs(index, []*structs.Allocation{alloc1})
err = srv.State().UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc1})
require.NoError(err)
index++
claim.State = structs.CSIVolumeClaimStateReadyToFree

View File

@ -100,7 +100,7 @@ func TestWorker_dequeueEvaluation_SerialJobs(t *testing.T) {
eval2.JobID = eval1.JobID
// Insert the evals into the state store
if err := s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1, eval2}); err != nil {
if err := s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2}); err != nil {
t.Fatal(err)
}
@ -128,7 +128,7 @@ func TestWorker_dequeueEvaluation_SerialJobs(t *testing.T) {
}
// Update the modify index of the first eval
if err := s1.fsm.State().UpsertEvals(2000, []*structs.Evaluation{eval1}); err != nil {
if err := s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 2000, []*structs.Evaluation{eval1}); err != nil {
t.Fatal(err)
}
@ -297,7 +297,7 @@ func TestWorker_waitForIndex(t *testing.T) {
go func() {
time.Sleep(10 * time.Millisecond)
n := mock.Node()
errCh <- s1.fsm.state.UpsertNode(index+1, n)
errCh <- s1.fsm.state.UpsertNode(structs.MsgTypeTestSetup, index+1, n)
}()
// Wait for a future index
@ -355,8 +355,8 @@ func TestWorker_SubmitPlan(t *testing.T) {
job := mock.Job()
eval1 := mock.Eval()
eval1.JobID = job.ID
s1.fsm.State().UpsertJob(1000, job)
s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1})
s1.fsm.State().UpsertJob(structs.MsgTypeTestSetup, 1000, job)
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1})
// Create the register request
s1.evalBroker.Enqueue(eval1)
@ -422,12 +422,12 @@ func TestWorker_SubmitPlanNormalizedAllocations(t *testing.T) {
job := mock.Job()
eval1 := mock.Eval()
eval1.JobID = job.ID
s1.fsm.State().UpsertJob(0, job)
s1.fsm.State().UpsertEvals(0, []*structs.Evaluation{eval1})
s1.fsm.State().UpsertJob(structs.MsgTypeTestSetup, 0, job)
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 0, []*structs.Evaluation{eval1})
stoppedAlloc := mock.Alloc()
preemptedAlloc := mock.Alloc()
s1.fsm.State().UpsertAllocs(5, []*structs.Allocation{stoppedAlloc, preemptedAlloc})
s1.fsm.State().UpsertAllocs(structs.MsgTypeTestSetup, 5, []*structs.Allocation{stoppedAlloc, preemptedAlloc})
// Create an allocation plan
plan := &structs.Plan{
@ -472,7 +472,7 @@ func TestWorker_SubmitPlan_MissingNodeRefresh(t *testing.T) {
// Create the job
job := mock.Job()
s1.fsm.State().UpsertJob(1000, job)
s1.fsm.State().UpsertJob(structs.MsgTypeTestSetup, 1000, job)
// Create the register request
eval1 := mock.Eval()
@ -640,7 +640,7 @@ func TestWorker_ReblockEval(t *testing.T) {
eval1.QueuedAllocations = map[string]int{"cache": 100}
// Insert it into the state store
if err := s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1}); err != nil {
if err := s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1}); err != nil {
t.Fatal(err)
}

View File

@ -108,7 +108,7 @@ func TestEvalContext_ProposedAlloc(t *testing.T) {
}
require.NoError(t, state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID)))
require.NoError(t, state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID)))
require.NoError(t, state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2}))
// Add a planned eviction to alloc1
plan := ctx.Plan()
@ -247,7 +247,7 @@ func TestEvalContext_ProposedAlloc_EvictPreempt(t *testing.T) {
require.NoError(t, state.UpsertJobSummary(998, mock.JobSummary(allocEvict.JobID)))
require.NoError(t, state.UpsertJobSummary(999, mock.JobSummary(allocPreempt.JobID)))
require.NoError(t, state.UpsertJobSummary(999, mock.JobSummary(allocPropose.JobID)))
require.NoError(t, state.UpsertAllocs(1000, []*structs.Allocation{allocEvict, allocPreempt, allocPropose}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{allocEvict, allocPreempt, allocPropose}))
// Plan to evict one alloc and preempt another
plan := ctx.Plan()

View File

@ -282,7 +282,7 @@ func TestCSIVolumeChecker(t *testing.T) {
// Create the plugins in the state store
index := uint64(999)
for _, node := range nodes {
err := state.UpsertNode(index, node)
err := state.UpsertNode(structs.MsgTypeTestSetup, index, node)
require.NoError(t, err)
index++
}
@ -318,13 +318,13 @@ func TestCSIVolumeChecker(t *testing.T) {
Source: vid2,
},
}
err = state.UpsertJob(index, alloc.Job)
err = state.UpsertJob(structs.MsgTypeTestSetup, index, alloc.Job)
require.NoError(t, err)
index++
summary := mock.JobSummary(alloc.JobID)
require.NoError(t, state.UpsertJobSummary(index, summary))
index++
err = state.UpsertAllocs(index, []*structs.Allocation{alloc})
err = state.UpsertAllocs(structs.MsgTypeTestSetup, index, []*structs.Allocation{alloc})
require.NoError(t, err)
index++
@ -1273,7 +1273,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty(t *testing.T) {
n.Meta["rack"] = fmt.Sprintf("%d", i)
// Add to state store
if err := state.UpsertNode(uint64(100+i), n); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), n); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
}
@ -1418,7 +1418,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty(t *testing.T) {
NodeID: nodes[4].ID,
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}
@ -1451,7 +1451,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_Count(t *testing.T) {
n.Meta["rack"] = fmt.Sprintf("%d", i)
// Add to state store
if err := state.UpsertNode(uint64(100+i), n); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), n); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
}
@ -1625,7 +1625,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_Count(t *testing.T) {
NodeID: nodes[1].ID,
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}
@ -1655,7 +1655,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_RemoveAndReplace(t *testin
nodes[0].Meta["rack"] = "1"
// Add to state store
if err := state.UpsertNode(uint64(100), nodes[0]); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100), nodes[0]); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
@ -1710,7 +1710,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_RemoveAndReplace(t *testin
NodeID: nodes[0].ID,
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}
@ -1739,7 +1739,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_Infeasible(t *testing.T) {
n.Meta["rack"] = fmt.Sprintf("%d", i)
// Add to state store
if err := state.UpsertNode(uint64(100+i), n); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), n); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
}
@ -1787,7 +1787,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_Infeasible(t *testing.T) {
NodeID: nodes[1].ID,
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}
@ -1816,7 +1816,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_Infeasible_Count(t *testin
n.Meta["rack"] = fmt.Sprintf("%d", i)
// Add to state store
if err := state.UpsertNode(uint64(100+i), n); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), n); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
}
@ -1882,7 +1882,7 @@ func TestDistinctPropertyIterator_JobDistinctProperty_Infeasible_Count(t *testin
NodeID: nodes[1].ID,
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}
@ -1912,7 +1912,7 @@ func TestDistinctPropertyIterator_TaskGroupDistinctProperty(t *testing.T) {
n.Meta["rack"] = fmt.Sprintf("%d", i)
// Add to state store
if err := state.UpsertNode(uint64(100+i), n); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), n); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
}
@ -1997,7 +1997,7 @@ func TestDistinctPropertyIterator_TaskGroupDistinctProperty(t *testing.T) {
NodeID: nodes[2].ID,
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}

File diff suppressed because it is too large Load Diff

View File

@ -1337,12 +1337,12 @@ func TestPreemption(t *testing.T) {
Node: node,
},
}
state.UpsertNode(1000, node)
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
for _, alloc := range tc.currentAllocations {
alloc.NodeID = node.ID
}
require := require.New(t)
err := state.UpsertAllocs(1001, tc.currentAllocations)
err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, tc.currentAllocations)
require.Nil(err)
if tc.currentPreemptions != nil {

View File

@ -673,7 +673,7 @@ func TestBinPackIterator_ExistingAlloc(t *testing.T) {
}
require.NoError(t, state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID)))
require.NoError(t, state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID)))
require.NoError(t, state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2}))
taskGroup := &structs.TaskGroup{
EphemeralDisk: &structs.EphemeralDisk{},
@ -788,7 +788,7 @@ func TestBinPackIterator_ExistingAlloc_PlannedEvict(t *testing.T) {
}
require.NoError(t, state.UpsertJobSummary(998, mock.JobSummary(alloc1.JobID)))
require.NoError(t, state.UpsertJobSummary(999, mock.JobSummary(alloc2.JobID)))
require.NoError(t, state.UpsertAllocs(1000, []*structs.Allocation{alloc1, alloc2}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{alloc1, alloc2}))
// Add a planned eviction to alloc1
plan := ctx.Plan()
@ -1108,7 +1108,7 @@ func TestBinPackIterator_Devices(t *testing.T) {
for _, alloc := range c.ExistingAllocs {
alloc.NodeID = c.Node.ID
}
require.NoError(state.UpsertAllocs(1000, c.ExistingAllocs))
require.NoError(state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, c.ExistingAllocs))
}
static := NewStaticRankIterator(ctx, []*RankedNode{{Node: c.Node}})

View File

@ -21,7 +21,7 @@ func TestSpreadIterator_SingleAttribute(t *testing.T) {
for i, dc := range dcs {
node := mock.Node()
node.Datacenter = dc
if err := state.UpsertNode(uint64(100+i), node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), node); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
nodes = append(nodes, &RankedNode{Node: node})
@ -54,7 +54,7 @@ func TestSpreadIterator_SingleAttribute(t *testing.T) {
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}
@ -181,7 +181,7 @@ func TestSpreadIterator_MultipleAttributes(t *testing.T) {
node := mock.Node()
node.Datacenter = dc
node.Meta["rack"] = rack[i]
if err := state.UpsertNode(uint64(100+i), node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), node); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
nodes = append(nodes, &RankedNode{Node: node})
@ -214,7 +214,7 @@ func TestSpreadIterator_MultipleAttributes(t *testing.T) {
},
}
if err := state.UpsertAllocs(1000, upserting); err != nil {
if err := state.UpsertAllocs(structs.MsgTypeTestSetup, 1000, upserting); err != nil {
t.Fatalf("failed to UpsertAllocs: %v", err)
}
@ -280,7 +280,7 @@ func TestSpreadIterator_EvenSpread(t *testing.T) {
for i, dc := range dcs {
node := mock.Node()
node.Datacenter = dc
if err := state.UpsertNode(uint64(100+i), node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), node); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
nodes = append(nodes, &RankedNode{Node: node})
@ -416,7 +416,7 @@ func TestSpreadIterator_EvenSpread(t *testing.T) {
// Add another node in dc3
node := mock.Node()
node.Datacenter = "dc3"
if err := state.UpsertNode(uint64(1111), node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(1111), node); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
nodes = append(nodes, &RankedNode{Node: node})
@ -467,7 +467,7 @@ func TestSpreadIterator_MaxPenalty(t *testing.T) {
for i := 0; i < 5; i++ {
node := mock.Node()
node.Datacenter = "dc3"
if err := state.UpsertNode(uint64(100+i), node); err != nil {
if err := state.UpsertNode(structs.MsgTypeTestSetup, uint64(100+i), node); err != nil {
t.Fatalf("failed to upsert node: %v", err)
}
nodes = append(nodes, &RankedNode{Node: node})

View File

@ -272,7 +272,7 @@ func TestServiceStack_Select_CSI(t *testing.T) {
}}
// Add the node to the state store to index the healthy plugins and mark the volume "foo" healthy
err = state.UpsertNode(1000, zero)
err = state.UpsertNode(structs.MsgTypeTestSetup, 1000, zero)
require.NoError(t, err)
// Use the node to build the stack and test

View File

@ -21,12 +21,12 @@ func TestSystemSched_JobRegister(t *testing.T) {
// Create some nodes
for i := 0; i < 10; i++ {
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Create a job
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to deregister the job
eval := &structs.Evaluation{
@ -37,7 +37,7 @@ func TestSystemSched_JobRegister(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -95,13 +95,13 @@ func TestSystemSched_JobRegister_StickyAllocs(t *testing.T) {
// Create some nodes
for i := 0; i < 10; i++ {
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Create a job
job := mock.SystemJob()
job.TaskGroups[0].EphemeralDisk.Sticky = true
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to register the job
eval := &structs.Evaluation{
@ -112,7 +112,7 @@ func TestSystemSched_JobRegister_StickyAllocs(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
if err := h.Process(NewSystemScheduler, eval); err != nil {
@ -143,7 +143,7 @@ func TestSystemSched_JobRegister_StickyAllocs(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
h1 := NewHarnessWithState(t, h.State)
if err := h1.Process(NewSystemScheduler, eval); err != nil {
t.Fatalf("err: %v", err)
@ -170,18 +170,18 @@ func TestSystemSched_JobRegister_EphemeralDiskConstraint(t *testing.T) {
// Create a nodes
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Create a job
job := mock.SystemJob()
job.TaskGroups[0].EphemeralDisk.SizeMB = 60 * 1024
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create another job with a lot of disk resource ask so that it doesn't fit
// the node
job1 := mock.SystemJob()
job1.TaskGroups[0].EphemeralDisk.SizeMB = 60 * 1024
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job1))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job1))
// Create a mock evaluation to register the job
eval := &structs.Evaluation{
@ -192,7 +192,7 @@ func TestSystemSched_JobRegister_EphemeralDiskConstraint(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
if err := h.Process(NewSystemScheduler, eval); err != nil {
@ -220,7 +220,7 @@ func TestSystemSched_JobRegister_EphemeralDiskConstraint(t *testing.T) {
JobID: job1.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval1}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval1}))
// Process the evaluation
if err := h1.Process(NewSystemScheduler, eval1); err != nil {
@ -239,7 +239,7 @@ func TestSystemSched_ExhaustResources(t *testing.T) {
// Create a nodes
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Enable Preemption
h.State.SchedulerSetConfig(h.NextIndex(), &structs.SchedulerConfiguration{
@ -252,7 +252,7 @@ func TestSystemSched_ExhaustResources(t *testing.T) {
svcJob := mock.Job()
svcJob.TaskGroups[0].Count = 1
svcJob.TaskGroups[0].Tasks[0].Resources.CPU = 3600
require.NoError(t, h.State.UpsertJob(h.NextIndex(), svcJob))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), svcJob))
// Create a mock evaluation to register the job
eval := &structs.Evaluation{
@ -263,7 +263,7 @@ func TestSystemSched_ExhaustResources(t *testing.T) {
JobID: svcJob.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewServiceScheduler, eval)
if err != nil {
@ -272,7 +272,7 @@ func TestSystemSched_ExhaustResources(t *testing.T) {
// Create a system job
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to register the job
eval1 := &structs.Evaluation{
@ -283,7 +283,7 @@ func TestSystemSched_ExhaustResources(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval1}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval1}))
// Process the evaluation
if err := h.Process(NewSystemScheduler, eval1); err != nil {
t.Fatalf("err: %v", err)
@ -324,7 +324,7 @@ func TestSystemSched_JobRegister_Annotate(t *testing.T) {
node.NodeClass = "bar"
}
node.ComputeClass()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Create a job constraining on node class
@ -335,7 +335,7 @@ func TestSystemSched_JobRegister_Annotate(t *testing.T) {
Operand: "==",
}
job.Constraints = append(job.Constraints, fooConstraint)
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to deregister the job
eval := &structs.Evaluation{
@ -347,7 +347,7 @@ func TestSystemSched_JobRegister_Annotate(t *testing.T) {
AnnotatePlan: true,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -416,12 +416,12 @@ func TestSystemSched_JobRegister_AddNode(t *testing.T) {
for i := 0; i < 10; i++ {
node := mock.Node()
nodes = append(nodes, node)
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Generate a fake job with allocations
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
var allocs []*structs.Allocation
for _, node := range nodes {
@ -432,11 +432,11 @@ func TestSystemSched_JobRegister_AddNode(t *testing.T) {
alloc.Name = "my-job.web[0]"
allocs = append(allocs, alloc)
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), allocs))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), allocs))
// Add a new node.
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Create a mock evaluation to deal with the node update
eval := &structs.Evaluation{
@ -447,7 +447,7 @@ func TestSystemSched_JobRegister_AddNode(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
if err != nil {
@ -504,7 +504,7 @@ func TestSystemSched_JobRegister_AllocFail(t *testing.T) {
// Create NO nodes
// Create a job
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to register the job
eval := &structs.Evaluation{
@ -515,7 +515,7 @@ func TestSystemSched_JobRegister_AllocFail(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
if err != nil {
@ -538,12 +538,12 @@ func TestSystemSched_JobModify(t *testing.T) {
for i := 0; i < 10; i++ {
node := mock.Node()
nodes = append(nodes, node)
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Generate a fake job with allocations
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
var allocs []*structs.Allocation
for _, node := range nodes {
@ -554,7 +554,7 @@ func TestSystemSched_JobModify(t *testing.T) {
alloc.Name = "my-job.web[0]"
allocs = append(allocs, alloc)
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), allocs))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), allocs))
// Add a few terminal status allocations, these should be ignored
var terminal []*structs.Allocation
@ -567,7 +567,7 @@ func TestSystemSched_JobModify(t *testing.T) {
alloc.DesiredStatus = structs.AllocDesiredStatusStop
terminal = append(terminal, alloc)
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), terminal))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), terminal))
// Update the job
job2 := mock.SystemJob()
@ -575,7 +575,7 @@ func TestSystemSched_JobModify(t *testing.T) {
// Update the task, such that it cannot be done in-place
job2.TaskGroups[0].Tasks[0].Config["command"] = "/bin/other"
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job2))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job2))
// Create a mock evaluation to deal with drain
eval := &structs.Evaluation{
@ -586,7 +586,7 @@ func TestSystemSched_JobModify(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -640,12 +640,12 @@ func TestSystemSched_JobModify_Rolling(t *testing.T) {
for i := 0; i < 10; i++ {
node := mock.Node()
nodes = append(nodes, node)
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Generate a fake job with allocations
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
var allocs []*structs.Allocation
for _, node := range nodes {
@ -656,7 +656,7 @@ func TestSystemSched_JobModify_Rolling(t *testing.T) {
alloc.Name = "my-job.web[0]"
allocs = append(allocs, alloc)
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), allocs))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), allocs))
// Update the job
job2 := mock.SystemJob()
@ -668,7 +668,7 @@ func TestSystemSched_JobModify_Rolling(t *testing.T) {
// Update the task, such that it cannot be done in-place
job2.TaskGroups[0].Tasks[0].Config["command"] = "/bin/other"
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job2))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job2))
// Create a mock evaluation to deal with drain
eval := &structs.Evaluation{
@ -679,7 +679,7 @@ func TestSystemSched_JobModify_Rolling(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
if err != nil {
@ -743,12 +743,12 @@ func TestSystemSched_JobModify_InPlace(t *testing.T) {
for i := 0; i < 10; i++ {
node := mock.Node()
nodes = append(nodes, node)
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Generate a fake job with allocations
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
var allocs []*structs.Allocation
for _, node := range nodes {
@ -759,12 +759,12 @@ func TestSystemSched_JobModify_InPlace(t *testing.T) {
alloc.Name = "my-job.web[0]"
allocs = append(allocs, alloc)
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), allocs))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), allocs))
// Update the job
job2 := mock.SystemJob()
job2.ID = job.ID
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job2))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job2))
// Create a mock evaluation to deal with drain
eval := &structs.Evaluation{
@ -775,7 +775,7 @@ func TestSystemSched_JobModify_InPlace(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -842,7 +842,7 @@ func TestSystemSched_JobDeregister_Purged(t *testing.T) {
for i := 0; i < 10; i++ {
node := mock.Node()
nodes = append(nodes, node)
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Generate a fake job with allocations
@ -860,7 +860,7 @@ func TestSystemSched_JobDeregister_Purged(t *testing.T) {
for _, alloc := range allocs {
require.NoError(t, h.State.UpsertJobSummary(h.NextIndex(), mock.JobSummary(alloc.JobID)))
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), allocs))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), allocs))
// Create a mock evaluation to deregister the job
eval := &structs.Evaluation{
@ -871,7 +871,7 @@ func TestSystemSched_JobDeregister_Purged(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -914,13 +914,13 @@ func TestSystemSched_JobDeregister_Stopped(t *testing.T) {
for i := 0; i < 10; i++ {
node := mock.Node()
nodes = append(nodes, node)
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Generate a fake job with allocations
job := mock.SystemJob()
job.Stop = true
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
var allocs []*structs.Allocation
for _, node := range nodes {
@ -934,7 +934,7 @@ func TestSystemSched_JobDeregister_Stopped(t *testing.T) {
for _, alloc := range allocs {
require.NoError(t, h.State.UpsertJobSummary(h.NextIndex(), mock.JobSummary(alloc.JobID)))
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), allocs))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), allocs))
// Create a mock evaluation to deregister the job
eval := &structs.Evaluation{
@ -945,7 +945,7 @@ func TestSystemSched_JobDeregister_Stopped(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -986,11 +986,11 @@ func TestSystemSched_NodeDown(t *testing.T) {
// Register a down node
node := mock.Node()
node.Status = structs.NodeStatusDown
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Generate a fake job allocated on that node.
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
alloc := mock.Alloc()
alloc.Job = job
@ -998,7 +998,7 @@ func TestSystemSched_NodeDown(t *testing.T) {
alloc.NodeID = node.ID
alloc.Name = "my-job.web[0]"
alloc.DesiredTransition.Migrate = helper.BoolToPtr(true)
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{alloc}))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Allocation{alloc}))
// Create a mock evaluation to deal with drain
eval := &structs.Evaluation{
@ -1010,7 +1010,7 @@ func TestSystemSched_NodeDown(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -1054,18 +1054,18 @@ func TestSystemSched_NodeDrain_Down(t *testing.T) {
node := mock.Node()
node.Drain = true
node.Status = structs.NodeStatusDown
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Generate a fake job allocated on that node.
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
alloc := mock.Alloc()
alloc.Job = job
alloc.JobID = job.ID
alloc.NodeID = node.ID
alloc.Name = "my-job.web[0]"
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{alloc}))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Allocation{alloc}))
// Create a mock evaluation to deal with the node update
eval := &structs.Evaluation{
@ -1077,7 +1077,7 @@ func TestSystemSched_NodeDrain_Down(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewServiceScheduler, eval)
@ -1115,11 +1115,11 @@ func TestSystemSched_NodeDrain(t *testing.T) {
// Register a draining node
node := mock.Node()
node.Drain = true
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Generate a fake job allocated on that node.
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
alloc := mock.Alloc()
alloc.Job = job
@ -1127,7 +1127,7 @@ func TestSystemSched_NodeDrain(t *testing.T) {
alloc.NodeID = node.ID
alloc.Name = "my-job.web[0]"
alloc.DesiredTransition.Migrate = helper.BoolToPtr(true)
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{alloc}))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Allocation{alloc}))
// Create a mock evaluation to deal with drain
eval := &structs.Evaluation{
@ -1139,7 +1139,7 @@ func TestSystemSched_NodeDrain(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -1181,18 +1181,18 @@ func TestSystemSched_NodeUpdate(t *testing.T) {
// Register a node
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Generate a fake job allocated on that node.
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
alloc := mock.Alloc()
alloc.Job = job
alloc.JobID = job.ID
alloc.NodeID = node.ID
alloc.Name = "my-job.web[0]"
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{alloc}))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Allocation{alloc}))
// Create a mock evaluation to deal
eval := &structs.Evaluation{
@ -1204,7 +1204,7 @@ func TestSystemSched_NodeUpdate(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -1227,12 +1227,12 @@ func TestSystemSched_RetryLimit(t *testing.T) {
// Create some nodes
for i := 0; i < 10; i++ {
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Create a job
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to deregister the job
eval := &structs.Evaluation{
@ -1243,7 +1243,7 @@ func TestSystemSched_RetryLimit(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -1279,11 +1279,11 @@ func TestSystemSched_Queued_With_Constraints(t *testing.T) {
// Register a node
node := mock.Node()
node.Attributes["kernel.name"] = "darwin"
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Generate a system job which can't be placed on the node
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to deal
eval := &structs.Evaluation{
@ -1295,7 +1295,7 @@ func TestSystemSched_Queued_With_Constraints(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -1323,13 +1323,13 @@ func TestSystemSched_JobConstraint_AddNode(t *testing.T) {
node = mock.Node()
node.NodeClass = "Class-A"
node.ComputeClass()
require.Nil(t, h.State.UpsertNode(h.NextIndex(), node))
require.Nil(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
var nodeB *structs.Node
nodeB = mock.Node()
nodeB.NodeClass = "Class-B"
nodeB.ComputeClass()
require.Nil(t, h.State.UpsertNode(h.NextIndex(), nodeB))
require.Nil(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), nodeB))
// Make a job with two task groups, each constraint to a node class
job := mock.SystemJob()
@ -1354,7 +1354,7 @@ func TestSystemSched_JobConstraint_AddNode(t *testing.T) {
// Upsert Job
job.TaskGroups = []*structs.TaskGroup{tgA, tgB}
require.Nil(t, h.State.UpsertJob(h.NextIndex(), job))
require.Nil(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Evaluate the job
eval := &structs.Evaluation{
@ -1366,7 +1366,7 @@ func TestSystemSched_JobConstraint_AddNode(t *testing.T) {
Status: structs.EvalStatusPending,
}
require.Nil(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.Nil(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
require.Nil(t, h.Process(NewSystemScheduler, eval))
require.Equal(t, "complete", h.Evals[0].Status)
@ -1398,7 +1398,7 @@ func TestSystemSched_JobConstraint_AddNode(t *testing.T) {
Status: structs.EvalStatusPending,
}
require.Nil(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval2}))
require.Nil(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval2}))
require.Nil(t, h.Process(NewSystemScheduler, eval2))
require.Equal(t, "complete", h.Evals[1].Status)
@ -1416,7 +1416,7 @@ func TestSystemSched_JobConstraint_AddNode(t *testing.T) {
nodeBTwo = mock.Node()
nodeBTwo.ComputeClass()
nodeBTwo.NodeClass = "Class-B"
require.Nil(t, h.State.UpsertNode(h.NextIndex(), nodeBTwo))
require.Nil(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), nodeBTwo))
// Evaluate the new node
eval3 := &structs.Evaluation{
@ -1430,7 +1430,7 @@ func TestSystemSched_JobConstraint_AddNode(t *testing.T) {
}
// Ensure New eval is complete
require.Nil(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval3}))
require.Nil(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval3}))
require.Nil(t, h.Process(NewSystemScheduler, eval3))
require.Equal(t, "complete", h.Evals[2].Status)
@ -1468,11 +1468,11 @@ func TestSystemSched_ExistingAllocNoNodes(t *testing.T) {
// Create a node
node = mock.Node()
node.ComputeClass()
require.Nil(t, h.State.UpsertNode(h.NextIndex(), node))
require.Nil(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
// Make a job
job := mock.SystemJob()
require.Nil(t, h.State.UpsertJob(h.NextIndex(), job))
require.Nil(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Evaluate the job
eval := &structs.Evaluation{
@ -1484,7 +1484,7 @@ func TestSystemSched_ExistingAllocNoNodes(t *testing.T) {
Status: structs.EvalStatusPending,
}
require.Nil(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.Nil(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
require.Nil(t, h.Process(NewSystemScheduler, eval))
require.Equal(t, "complete", h.Evals[0].Status)
@ -1508,14 +1508,14 @@ func TestSystemSched_ExistingAllocNoNodes(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.Nil(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval2}))
require.Nil(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval2}))
require.Nil(t, h.Process(NewSystemScheduler, eval2))
require.Equal(t, "complete", h.Evals[1].Status)
// Create a new job version, deploy
job2 := job.Copy()
job2.Meta["version"] = "2"
require.Nil(t, h.State.UpsertJob(h.NextIndex(), job2))
require.Nil(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job2))
// Run evaluation as a plan
eval3 := &structs.Evaluation{
@ -1529,7 +1529,7 @@ func TestSystemSched_ExistingAllocNoNodes(t *testing.T) {
}
// Ensure New eval is complete
require.Nil(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval3}))
require.Nil(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval3}))
require.Nil(t, h.Process(NewSystemScheduler, eval3))
require.Equal(t, "complete", h.Evals[2].Status)
@ -1550,7 +1550,7 @@ func TestSystemSched_ConstraintErrors(t *testing.T) {
node = mock.Node()
node.Meta["tag"] = tag
node.ComputeClass()
require.Nil(t, h.State.UpsertNode(h.NextIndex(), node))
require.Nil(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Mark the last node as ineligible
@ -1565,7 +1565,7 @@ func TestSystemSched_ConstraintErrors(t *testing.T) {
Operand: "=",
})
require.Nil(t, h.State.UpsertJob(h.NextIndex(), job))
require.Nil(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Evaluate the job
eval := &structs.Evaluation{
@ -1577,7 +1577,7 @@ func TestSystemSched_ConstraintErrors(t *testing.T) {
Status: structs.EvalStatusPending,
}
require.Nil(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.Nil(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
require.Nil(t, h.Process(NewSystemScheduler, eval))
require.Equal(t, "complete", h.Evals[0].Status)
@ -1616,12 +1616,12 @@ func TestSystemSched_ChainedAlloc(t *testing.T) {
// Create some nodes
for i := 0; i < 10; i++ {
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Create a job
job := mock.SystemJob()
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to register the job
eval := &structs.Evaluation{
@ -1632,7 +1632,7 @@ func TestSystemSched_ChainedAlloc(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
if err := h.Process(NewSystemScheduler, eval); err != nil {
t.Fatalf("err: %v", err)
@ -1652,12 +1652,12 @@ func TestSystemSched_ChainedAlloc(t *testing.T) {
job1.ID = job.ID
job1.TaskGroups[0].Tasks[0].Env = make(map[string]string)
job1.TaskGroups[0].Tasks[0].Env["foo"] = "bar"
require.NoError(t, h1.State.UpsertJob(h1.NextIndex(), job1))
require.NoError(t, h1.State.UpsertJob(structs.MsgTypeTestSetup, h1.NextIndex(), job1))
// Insert two more nodes
for i := 0; i < 2; i++ {
node := mock.Node()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
}
// Create a mock evaluation to update the job
@ -1669,7 +1669,7 @@ func TestSystemSched_ChainedAlloc(t *testing.T) {
JobID: job1.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval1}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval1}))
// Process the evaluation
if err := h1.Process(NewSystemScheduler, eval1); err != nil {
t.Fatalf("err: %v", err)
@ -1712,12 +1712,12 @@ func TestSystemSched_PlanWithDrainedNode(t *testing.T) {
node.NodeClass = "green"
node.Drain = true
node.ComputeClass()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
node2 := mock.Node()
node2.NodeClass = "blue"
node2.ComputeClass()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node2))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node2))
// Create a Job with two task groups, each constrained on node class
job := mock.SystemJob()
@ -1733,7 +1733,7 @@ func TestSystemSched_PlanWithDrainedNode(t *testing.T) {
tg2.Name = "web2"
tg2.Constraints[0].RTarget = "blue"
job.TaskGroups = append(job.TaskGroups, tg2)
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create an allocation on each node
alloc := mock.Alloc()
@ -1750,7 +1750,7 @@ func TestSystemSched_PlanWithDrainedNode(t *testing.T) {
alloc2.NodeID = node2.ID
alloc2.Name = "my-job.web2[0]"
alloc2.TaskGroup = "web2"
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{alloc, alloc2}))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Allocation{alloc, alloc2}))
// Create a mock evaluation to deal with drain
eval := &structs.Evaluation{
@ -1762,7 +1762,7 @@ func TestSystemSched_PlanWithDrainedNode(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -1802,12 +1802,12 @@ func TestSystemSched_QueuedAllocsMultTG(t *testing.T) {
node := mock.Node()
node.NodeClass = "green"
node.ComputeClass()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
node2 := mock.Node()
node2.NodeClass = "blue"
node2.ComputeClass()
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node2))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node2))
// Create a Job with two task groups, each constrained on node class
job := mock.SystemJob()
@ -1823,7 +1823,7 @@ func TestSystemSched_QueuedAllocsMultTG(t *testing.T) {
tg2.Name = "web2"
tg2.Constraints[0].RTarget = "blue"
job.TaskGroups = append(job.TaskGroups, tg2)
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to deal with drain
eval := &structs.Evaluation{
@ -1835,7 +1835,7 @@ func TestSystemSched_QueuedAllocsMultTG(t *testing.T) {
NodeID: node.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)
@ -1907,7 +1907,7 @@ func TestSystemSched_Preemption(t *testing.T) {
},
},
}
require.NoError(t, h.State.UpsertNode(h.NextIndex(), node))
require.NoError(t, h.State.UpsertNode(structs.MsgTypeTestSetup, h.NextIndex(), node))
nodes = append(nodes, node)
}
@ -1969,7 +1969,7 @@ func TestSystemSched_Preemption(t *testing.T) {
},
}
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job1))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job1))
job2 := mock.BatchJob()
job2.Type = structs.JobTypeBatch
@ -2012,7 +2012,7 @@ func TestSystemSched_Preemption(t *testing.T) {
DiskMB: 5 * 1024,
},
}
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job2))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job2))
job3 := mock.Job()
job3.Type = structs.JobTypeBatch
@ -2057,7 +2057,7 @@ func TestSystemSched_Preemption(t *testing.T) {
DiskMB: 5 * 1024,
},
}
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{alloc1, alloc2, alloc3}))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Allocation{alloc1, alloc2, alloc3}))
// Create a high priority job and allocs for it
// These allocs should not be preempted
@ -2104,8 +2104,8 @@ func TestSystemSched_Preemption(t *testing.T) {
DiskMB: 2 * 1024,
},
}
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job4))
require.NoError(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{alloc4}))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job4))
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Allocation{alloc4}))
// Create a system job such that it would need to preempt both allocs to succeed
job := mock.SystemJob()
@ -2119,7 +2119,7 @@ func TestSystemSched_Preemption(t *testing.T) {
},
},
}
require.NoError(t, h.State.UpsertJob(h.NextIndex(), job))
require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job))
// Create a mock evaluation to register the job
eval := &structs.Evaluation{
@ -2130,7 +2130,7 @@ func TestSystemSched_Preemption(t *testing.T) {
JobID: job.ID,
Status: structs.EvalStatusPending,
}
require.NoError(t, h.State.UpsertEvals(h.NextIndex(), []*structs.Evaluation{eval}))
require.NoError(t, h.State.UpsertEvals(structs.MsgTypeTestSetup, h.NextIndex(), []*structs.Evaluation{eval}))
// Process the evaluation
err := h.Process(NewSystemScheduler, eval)

View File

@ -335,10 +335,10 @@ func TestReadyNodesInDCs(t *testing.T) {
node4 := mock.Node()
node4.Drain = true
require.NoError(t, state.UpsertNode(1000, node1))
require.NoError(t, state.UpsertNode(1001, node2))
require.NoError(t, state.UpsertNode(1002, node3))
require.NoError(t, state.UpsertNode(1003, node4))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1001, node2))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1002, node3))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1003, node4))
nodes, dc, err := readyNodesInDCs(state, []string{"dc1", "dc2"})
require.NoError(t, err)
@ -394,10 +394,10 @@ func TestTaintedNodes(t *testing.T) {
node3.Status = structs.NodeStatusDown
node4 := mock.Node()
node4.Drain = true
require.NoError(t, state.UpsertNode(1000, node1))
require.NoError(t, state.UpsertNode(1001, node2))
require.NoError(t, state.UpsertNode(1002, node3))
require.NoError(t, state.UpsertNode(1003, node4))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1001, node2))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1002, node3))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 1003, node4))
allocs := []*structs.Allocation{
{NodeID: node1.ID},
@ -868,7 +868,7 @@ func TestInplaceUpdate_ChangedTaskGroup(t *testing.T) {
job := mock.Job()
node := mock.Node()
require.NoError(t, state.UpsertNode(900, node))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 900, node))
// Register an alloc
alloc := &structs.Allocation{
@ -895,7 +895,7 @@ func TestInplaceUpdate_ChangedTaskGroup(t *testing.T) {
}
alloc.TaskResources = map[string]*structs.Resources{"web": alloc.Resources}
require.NoError(t, state.UpsertJobSummary(1000, mock.JobSummary(alloc.JobID)))
require.NoError(t, state.UpsertAllocs(1001, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc}))
// Create a new task group that prevents in-place updates.
tg := &structs.TaskGroup{}
@ -923,7 +923,7 @@ func TestInplaceUpdate_NoMatch(t *testing.T) {
job := mock.Job()
node := mock.Node()
require.NoError(t, state.UpsertNode(900, node))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 900, node))
// Register an alloc
alloc := &structs.Allocation{
@ -950,7 +950,7 @@ func TestInplaceUpdate_NoMatch(t *testing.T) {
}
alloc.TaskResources = map[string]*structs.Resources{"web": alloc.Resources}
require.NoError(t, state.UpsertJobSummary(1000, mock.JobSummary(alloc.JobID)))
require.NoError(t, state.UpsertAllocs(1001, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc}))
// Create a new task group that requires too much resources.
tg := &structs.TaskGroup{}
@ -974,7 +974,7 @@ func TestInplaceUpdate_Success(t *testing.T) {
job := mock.Job()
node := mock.Node()
require.NoError(t, state.UpsertNode(900, node))
require.NoError(t, state.UpsertNode(structs.MsgTypeTestSetup, 900, node))
// Register an alloc
alloc := &structs.Allocation{
@ -1001,7 +1001,7 @@ func TestInplaceUpdate_Success(t *testing.T) {
}
alloc.TaskResources = map[string]*structs.Resources{"web": alloc.Resources}
require.NoError(t, state.UpsertJobSummary(999, mock.JobSummary(alloc.JobID)))
require.NoError(t, state.UpsertAllocs(1001, []*structs.Allocation{alloc}))
require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc}))
// Create a new task group that updates the resources.
tg := &structs.TaskGroup{}