github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/api/evaluations.go (about) 1 package api 2 3 import ( 4 "sort" 5 "time" 6 ) 7 8 // Evaluations is used to query the evaluation endpoints. 9 type Evaluations struct { 10 client *Client 11 } 12 13 // Evaluations returns a new handle on the evaluations. 14 func (c *Client) Evaluations() *Evaluations { 15 return &Evaluations{client: c} 16 } 17 18 // List is used to dump all of the evaluations. 19 func (e *Evaluations) List(q *QueryOptions) ([]*Evaluation, *QueryMeta, error) { 20 var resp []*Evaluation 21 qm, err := e.client.query("/v1/evaluations", &resp, q) 22 if err != nil { 23 return nil, nil, err 24 } 25 sort.Sort(EvalIndexSort(resp)) 26 return resp, qm, nil 27 } 28 29 // Info is used to query a single evaluation by its ID. 30 func (e *Evaluations) Info(evalID string, q *QueryOptions) (*Evaluation, *QueryMeta, error) { 31 var resp Evaluation 32 qm, err := e.client.query("/v1/evaluation/"+evalID, &resp, q) 33 if err != nil { 34 return nil, nil, err 35 } 36 return &resp, qm, nil 37 } 38 39 // Allocations is used to retrieve a set of allocations given 40 // an evaluation ID. 41 func (e *Evaluations) Allocations(evalID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) { 42 var resp []*AllocationListStub 43 qm, err := e.client.query("/v1/evaluation/"+evalID+"/allocations", &resp, q) 44 if err != nil { 45 return nil, nil, err 46 } 47 sort.Sort(AllocIndexSort(resp)) 48 return resp, qm, nil 49 } 50 51 // Evaluation is used to serialize an evaluation. 52 type Evaluation struct { 53 ID string 54 Priority int 55 Type string 56 TriggeredBy string 57 JobID string 58 JobModifyIndex uint64 59 NodeID string 60 NodeModifyIndex uint64 61 Status string 62 StatusDescription string 63 Wait time.Duration 64 NextEval string 65 PreviousEval string 66 CreateIndex uint64 67 ModifyIndex uint64 68 } 69 70 // EvalIndexSort is a wrapper to sort evaluations by CreateIndex. 71 // We reverse the test so that we get the highest index first. 72 type EvalIndexSort []*Evaluation 73 74 func (e EvalIndexSort) Len() int { 75 return len(e) 76 } 77 78 func (e EvalIndexSort) Less(i, j int) bool { 79 return e[i].CreateIndex > e[j].CreateIndex 80 } 81 82 func (e EvalIndexSort) Swap(i, j int) { 83 e[i], e[j] = e[j], e[i] 84 }