Skip to content

Commit

Permalink
add msgtype to upsert evals signature, update test call sites with te…
Browse files Browse the repository at this point in the history
…st 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
  • Loading branch information
drewbailey committed Oct 18, 2020
1 parent 836217e commit 2f2696f
Show file tree
Hide file tree
Showing 50 changed files with 652 additions and 694 deletions.
6 changes: 3 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ 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 {
Expand Down Expand Up @@ -581,7 +581,7 @@ 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 {
Expand Down Expand Up @@ -687,7 +687,7 @@ 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))
Expand Down
2 changes: 1 addition & 1 deletion client/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down
10 changes: 5 additions & 5 deletions command/agent/deployment_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ 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(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a1, a2}), "UpsertAllocs")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -259,7 +259,7 @@ 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(structs.MsgTypeTestSetup, 1000, []*structs.Allocation{a}), "UpsertAllocs")

Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions command/agent/eval_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -160,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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/fs_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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.UpsertJob(structs.MsgTypeTestSetup, 999, alloc.Job))
require.Nil(state.UpsertAllocs(structs.MsgTypeTestSetup, 1003, []*structs.Allocation{alloc}))

if wait == noWaitClientAlloc {
Expand Down
2 changes: 1 addition & 1 deletion command/agent/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 3 additions & 4 deletions command/agent/search_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion command/eval_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 5 additions & 3 deletions command/job_deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion command/job_dispatch_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
structs2 "github.com/hashicorp/nomad/nomad/structs"
"strings"
"testing"

Expand Down Expand Up @@ -60,7 +61,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(structs2.MsgTypeTestSetup, 1000, j))

prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}
Expand Down
4 changes: 2 additions & 2 deletions command/job_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion command/job_history_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
structs2 "github.com/hashicorp/nomad/nomad/structs"
"strings"
"testing"

Expand Down Expand Up @@ -51,7 +52,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(structs2.MsgTypeTestSetup, 1000, j))

prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}
Expand Down
3 changes: 2 additions & 1 deletion command/job_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions command/job_periodic_force_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion command/job_promote_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
structs2 "github.com/hashicorp/nomad/nomad/structs"
"strings"
"testing"

Expand Down Expand Up @@ -51,7 +52,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(structs2.MsgTypeTestSetup, 1000, j))

prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}
Expand Down
3 changes: 2 additions & 1 deletion command/job_revert_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
structs2 "github.com/hashicorp/nomad/nomad/structs"
"strings"
"testing"

Expand Down Expand Up @@ -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(structs2.MsgTypeTestSetup, 1000, j))

prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}
Expand Down
6 changes: 3 additions & 3 deletions command/job_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion command/job_stop_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
structs2 "github.com/hashicorp/nomad/nomad/structs"
"strings"
"testing"

Expand Down Expand Up @@ -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(structs2.MsgTypeTestSetup, 1000, j))

prefix := j.ID[:len(j.ID)-5]
args := complete.Args{Last: prefix}
Expand Down
Loading

0 comments on commit 2f2696f

Please sign in to comment.