github.com/anuvu/nomad@v0.8.7-atom1/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 func (e *Evaluations) PrefixList(prefix string) ([]*Evaluation, *QueryMeta, error) { 30 return e.List(&QueryOptions{Prefix: prefix}) 31 } 32 33 // Info is used to query a single evaluation by its ID. 34 func (e *Evaluations) Info(evalID string, q *QueryOptions) (*Evaluation, *QueryMeta, error) { 35 var resp Evaluation 36 qm, err := e.client.query("/v1/evaluation/"+evalID, &resp, q) 37 if err != nil { 38 return nil, nil, err 39 } 40 return &resp, qm, nil 41 } 42 43 // Allocations is used to retrieve a set of allocations given 44 // an evaluation ID. 45 func (e *Evaluations) Allocations(evalID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) { 46 var resp []*AllocationListStub 47 qm, err := e.client.query("/v1/evaluation/"+evalID+"/allocations", &resp, q) 48 if err != nil { 49 return nil, nil, err 50 } 51 sort.Sort(AllocIndexSort(resp)) 52 return resp, qm, nil 53 } 54 55 // Evaluation is used to serialize an evaluation. 56 type Evaluation struct { 57 ID string 58 Priority int 59 Type string 60 TriggeredBy string 61 Namespace string 62 JobID string 63 JobModifyIndex uint64 64 NodeID string 65 NodeModifyIndex uint64 66 DeploymentID string 67 Status string 68 StatusDescription string 69 Wait time.Duration 70 WaitUntil time.Time 71 NextEval string 72 PreviousEval string 73 BlockedEval string 74 FailedTGAllocs map[string]*AllocationMetric 75 ClassEligibility map[string]bool 76 EscapedComputedClass bool 77 QuotaLimitReached string 78 AnnotatePlan bool 79 QueuedAllocations map[string]int 80 SnapshotIndex uint64 81 CreateIndex uint64 82 ModifyIndex uint64 83 } 84 85 // EvalIndexSort is a wrapper to sort evaluations by CreateIndex. 86 // We reverse the test so that we get the highest index first. 87 type EvalIndexSort []*Evaluation 88 89 func (e EvalIndexSort) Len() int { 90 return len(e) 91 } 92 93 func (e EvalIndexSort) Less(i, j int) bool { 94 return e[i].CreateIndex > e[j].CreateIndex 95 } 96 97 func (e EvalIndexSort) Swap(i, j int) { 98 e[i], e[j] = e[j], e[i] 99 }