From c1d05a8bd9c8ec6ee5c97babaa1a7bead0cb01b7 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 15 Sep 2015 11:25:48 -0700 Subject: [PATCH] nomad: using struct level validations --- nomad/job_endpoint.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index bfe81ff71..63d31eb3c 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -24,26 +24,13 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis if args.Job == nil { return fmt.Errorf("missing job for registration") } - if args.Job.ID == "" { - return fmt.Errorf("missing job ID for registration") - } - if args.Job.Name == "" { - return fmt.Errorf("missing job name for registration") - } - if args.Job.Type == "" { - return fmt.Errorf("missing job type for registration") + if err := args.Job.Validate(); err != nil { + return err } if args.Job.Type == structs.JobTypeCore { return fmt.Errorf("job type cannot be core") } - // Ensure priorities are bounded - if args.Job.Priority < structs.JobMinPriority { - args.Job.Priority = structs.JobMinPriority - } else if args.Job.Priority > structs.JobMaxPriority { - args.Job.Priority = structs.JobMaxPriority - } - // Commit this update via Raft _, index, err := j.srv.raftApply(structs.JobRegisterRequestType, args) if err != nil {