mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
nomad: using struct level validations
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user