2015-09-09 01:42:34 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2015-09-17 19:40:51 +00:00
|
|
|
"sort"
|
2015-09-09 01:42:34 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2015-09-09 20:48:56 +00:00
|
|
|
// Evaluations is used to query the evaluation endpoints.
|
|
|
|
type Evaluations struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluations returns a new handle on the evaluations.
|
|
|
|
func (c *Client) Evaluations() *Evaluations {
|
|
|
|
return &Evaluations{client: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List is used to dump all of the evaluations.
|
|
|
|
func (e *Evaluations) List(q *QueryOptions) ([]*Evaluation, *QueryMeta, error) {
|
|
|
|
var resp []*Evaluation
|
|
|
|
qm, err := e.client.query("/v1/evaluations", &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2015-09-17 19:40:51 +00:00
|
|
|
sort.Sort(EvalIndexSort(resp))
|
2015-09-09 20:48:56 +00:00
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
2015-12-24 10:46:59 +00:00
|
|
|
func (e *Evaluations) PrefixList(prefix string) ([]*Evaluation, *QueryMeta, error) {
|
|
|
|
return e.List(&QueryOptions{Prefix: prefix})
|
|
|
|
}
|
|
|
|
|
2015-09-09 20:48:56 +00:00
|
|
|
// Info is used to query a single evaluation by its ID.
|
|
|
|
func (e *Evaluations) Info(evalID string, q *QueryOptions) (*Evaluation, *QueryMeta, error) {
|
|
|
|
var resp Evaluation
|
|
|
|
qm, err := e.client.query("/v1/evaluation/"+evalID, &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return &resp, qm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocations is used to retrieve a set of allocations given
|
|
|
|
// an evaluation ID.
|
2015-09-14 02:55:47 +00:00
|
|
|
func (e *Evaluations) Allocations(evalID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) {
|
|
|
|
var resp []*AllocationListStub
|
2015-09-09 20:48:56 +00:00
|
|
|
qm, err := e.client.query("/v1/evaluation/"+evalID+"/allocations", &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2015-09-17 19:40:51 +00:00
|
|
|
sort.Sort(AllocIndexSort(resp))
|
2015-09-09 20:48:56 +00:00
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
2015-09-09 01:42:34 +00:00
|
|
|
// Evaluation is used to serialize an evaluation.
|
|
|
|
type Evaluation struct {
|
2017-03-09 20:37:41 +00:00
|
|
|
ID string
|
|
|
|
Priority int
|
|
|
|
Type string
|
|
|
|
TriggeredBy string
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace string
|
2017-03-09 20:37:41 +00:00
|
|
|
JobID string
|
|
|
|
JobModifyIndex uint64
|
|
|
|
NodeID string
|
|
|
|
NodeModifyIndex uint64
|
2017-06-26 21:23:52 +00:00
|
|
|
DeploymentID string
|
2017-03-09 20:37:41 +00:00
|
|
|
Status string
|
|
|
|
StatusDescription string
|
|
|
|
Wait time.Duration
|
|
|
|
NextEval string
|
|
|
|
PreviousEval string
|
|
|
|
BlockedEval string
|
|
|
|
FailedTGAllocs map[string]*AllocationMetric
|
|
|
|
ClassEligibility map[string]bool
|
|
|
|
EscapedComputedClass bool
|
|
|
|
AnnotatePlan bool
|
|
|
|
QueuedAllocations map[string]int
|
|
|
|
SnapshotIndex uint64
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
2015-09-17 19:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EvalIndexSort is a wrapper to sort evaluations by CreateIndex.
|
|
|
|
// We reverse the test so that we get the highest index first.
|
|
|
|
type EvalIndexSort []*Evaluation
|
|
|
|
|
|
|
|
func (e EvalIndexSort) Len() int {
|
|
|
|
return len(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e EvalIndexSort) Less(i, j int) bool {
|
|
|
|
return e[i].CreateIndex > e[j].CreateIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e EvalIndexSort) Swap(i, j int) {
|
|
|
|
e[i], e[j] = e[j], e[i]
|
2015-09-09 01:42:34 +00:00
|
|
|
}
|