nomad: adding eval list endpoint

This commit is contained in:
Armon Dadgar 2015-09-06 16:01:16 -07:00
parent 009fc62cc8
commit 2901b544e9
3 changed files with 78 additions and 0 deletions

View file

@ -171,3 +171,42 @@ func (e *Eval) Reap(args *structs.EvalDeleteRequest,
reply.Index = index reply.Index = index
return nil return nil
} }
// List is used to get a list of the evaluations in the system
func (e *Eval) List(args *structs.EvalListRequest,
reply *structs.EvalListResponse) error {
if done, err := e.srv.forward("Eval.List", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "eval", "list"}, time.Now())
// Scan all the evaluations
snap, err := e.srv.fsm.State().Snapshot()
if err != nil {
return err
}
iter, err := snap.Evals()
if err != nil {
return err
}
for {
raw := iter.Next()
if raw == nil {
break
}
eval := raw.(*structs.Evaluation)
reply.Evaluations = append(reply.Evaluations, eval)
}
// Use the last index that affected the jobs table
index, err := snap.GetIndex("evals")
if err != nil {
return err
}
reply.Index = index
// Set the query response
e.srv.setQueryMeta(&reply.QueryMeta)
return nil
}

View file

@ -251,3 +251,31 @@ func TestEvalEndpoint_Reap(t *testing.T) {
t.Fatalf("Bad: %#v", outE) t.Fatalf("Bad: %#v", outE)
} }
} }
func TestEvalEndpoint_List(t *testing.T) {
s1 := testServer(t, nil)
defer s1.Shutdown()
codec := rpcClient(t, s1)
testutil.WaitForLeader(t, s1.RPC)
// Create the register request
eval1 := mock.Eval()
eval2 := mock.Eval()
s1.fsm.State().UpsertEvals(1000, []*structs.Evaluation{eval1, eval2})
// Lookup the eval
get := &structs.EvalListRequest{
QueryOptions: structs.QueryOptions{Region: "region1"},
}
var resp structs.EvalListResponse
if err := msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Index != 1000 {
t.Fatalf("Bad index: %d %d", resp.Index, 1000)
}
if len(resp.Evaluations) != 2 {
t.Fatalf("bad: %#v", resp.Evaluations)
}
}

View file

@ -218,6 +218,11 @@ type EvalDequeueRequest struct {
WriteRequest WriteRequest
} }
// EvalListRequest is used to list the evaluations
type EvalListRequest struct {
QueryOptions
}
// PlanRequest is used to submit an allocation plan to the leader // PlanRequest is used to submit an allocation plan to the leader
type PlanRequest struct { type PlanRequest struct {
Plan *Plan Plan *Plan
@ -367,6 +372,12 @@ type AllocListResponse struct {
QueryMeta QueryMeta
} }
// EvalListResponse is used for a list request
type EvalListResponse struct {
Evaluations []*Evaluation
QueryMeta
}
const ( const (
NodeStatusInit = "initializing" NodeStatusInit = "initializing"
NodeStatusReady = "ready" NodeStatusReady = "ready"