nomad: adding Eval.Create endpoint
This commit is contained in:
parent
fe2e046481
commit
96a8d079e2
|
@ -153,6 +153,44 @@ func (e *Eval) Update(args *structs.EvalUpdateRequest,
|
|||
return nil
|
||||
}
|
||||
|
||||
// Create is used to make a new evaluation
|
||||
func (e *Eval) Create(args *structs.EvalUpdateRequest,
|
||||
reply *structs.GenericResponse) error {
|
||||
if done, err := e.srv.forward("Eval.Create", args, args, reply); done {
|
||||
return err
|
||||
}
|
||||
defer metrics.MeasureSince([]string{"nomad", "eval", "create"}, time.Now())
|
||||
|
||||
// Ensure there is only a single update with token
|
||||
if len(args.Evals) != 1 {
|
||||
return fmt.Errorf("only a single eval can be created")
|
||||
}
|
||||
eval := args.Evals[0]
|
||||
|
||||
// Look for the eval
|
||||
snap, err := e.srv.fsm.State().Snapshot()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := snap.EvalByID(eval.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if out != nil {
|
||||
return fmt.Errorf("evaluation already exists")
|
||||
}
|
||||
|
||||
// Update via Raft
|
||||
_, index, err := e.srv.raftApply(structs.EvalUpdateRequestType, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update the index
|
||||
reply.Index = index
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reap is used to cleanup dead evaluations and allocations
|
||||
func (e *Eval) Reap(args *structs.EvalDeleteRequest,
|
||||
reply *structs.GenericResponse) error {
|
||||
|
|
|
@ -219,6 +219,35 @@ func TestEvalEndpoint_Update(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEvalEndpoint_Create(t *testing.T) {
|
||||
s1 := testServer(t, nil)
|
||||
defer s1.Shutdown()
|
||||
codec := rpcClient(t, s1)
|
||||
|
||||
// Create the register request
|
||||
eval1 := mock.Eval()
|
||||
get := &structs.EvalUpdateRequest{
|
||||
Evals: []*structs.Evaluation{eval1},
|
||||
WriteRequest: structs.WriteRequest{Region: "region1"},
|
||||
}
|
||||
var resp structs.GenericResponse
|
||||
if err := msgpackrpc.CallWithCodec(codec, "Eval.Create", get, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Ensure created
|
||||
outE, err := s1.fsm.State().EvalByID(eval1.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
eval1.CreateIndex = resp.Index
|
||||
eval1.ModifyIndex = resp.Index
|
||||
if !reflect.DeepEqual(eval1, outE) {
|
||||
t.Fatalf("Bad: %#v %#v", outE, eval1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalEndpoint_Reap(t *testing.T) {
|
||||
s1 := testServer(t, nil)
|
||||
defer s1.Shutdown()
|
||||
|
|
Loading…
Reference in New Issue