github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/nomad/plan_endpoint.go (about) 1 package nomad 2 3 import ( 4 "time" 5 6 "github.com/armon/go-metrics" 7 "github.com/hashicorp/nomad/nomad/structs" 8 ) 9 10 // Plan endpoint is used for plan interactions 11 type Plan struct { 12 srv *Server 13 } 14 15 // Submit is used to submit a plan to the leader 16 func (p *Plan) Submit(args *structs.PlanRequest, reply *structs.PlanResponse) error { 17 if done, err := p.srv.forward("Plan.Submit", args, args, reply); done { 18 return err 19 } 20 defer metrics.MeasureSince([]string{"nomad", "plan", "submit"}, time.Now()) 21 22 // Submit the plan to the queue 23 future, err := p.srv.planQueue.Enqueue(args.Plan) 24 if err != nil { 25 return err 26 } 27 28 // Wait for the results 29 result, err := future.Wait() 30 if err != nil { 31 return err 32 } 33 34 // Package the result 35 reply.Result = result 36 reply.Index = result.AllocIndex 37 return nil 38 }