Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
272a1fa6
Commit
272a1fa6
authored
3 years ago
by
Tim Gross
Browse files
Options
Download
Email Patches
Plain Diff
[wip] first hacky pass
parent
972708aa
Branches unavailable
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
command/eval_list.go
+182
-0
command/eval_list.go
with
182 additions
and
0 deletions
+182
-0
command/eval_list.go
0 → 100644
+
182
-
0
View file @
272a1fa6
package
command
import
(
"fmt"
"strings"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/api/contexts"
"github.com/posener/complete"
)
type
EvalListCommand
struct
{
Meta
}
func
(
c
*
EvalListCommand
)
Help
()
string
{
helpText
:=
`
Usage: nomad eval list [options]
List is used to list the set of evaluations processed by Nomad.
General Options:
`
+
generalOptionsUsage
(
usageOptsDefault
)
+
`
Eval Status Options:
-verbose
Show full information.
-per_page
How many results to show per page.
-page_token
Where to start pagination.
-job
Only show evaluations for this job ID.
-status
Only show evaluations with this status.
-json
Output the evaluation in its JSON format.
-t
Format and display evaluation using a Go template.
`
return
strings
.
TrimSpace
(
helpText
)
}
func
(
c
*
EvalListCommand
)
Synopsis
()
string
{
return
"Display evaluation status and placement failure reasons"
}
func
(
c
*
EvalListCommand
)
AutocompleteFlags
()
complete
.
Flags
{
return
mergeAutocompleteFlags
(
c
.
Meta
.
AutocompleteFlags
(
FlagSetClient
),
complete
.
Flags
{
"-json"
:
complete
.
PredictNothing
,
"-t"
:
complete
.
PredictAnything
,
"-verbose"
:
complete
.
PredictNothing
,
"-job"
:
complete
.
PredictNothing
,
// TODO
"-status"
:
complete
.
PredictNothing
,
// TODO
"-per_page"
:
complete
.
PredictNothing
,
// TODO
"-page_token"
:
complete
.
PredictNothing
,
// TODO
})
}
func
(
c
*
EvalListCommand
)
AutocompleteArgs
()
complete
.
Predictor
{
return
complete
.
PredictFunc
(
func
(
a
complete
.
Args
)
[]
string
{
client
,
err
:=
c
.
Meta
.
Client
()
if
err
!=
nil
{
return
nil
}
if
err
!=
nil
{
return
nil
}
resp
,
_
,
err
:=
client
.
Search
()
.
PrefixSearch
(
a
.
Last
,
contexts
.
Evals
,
nil
)
if
err
!=
nil
{
return
[]
string
{}
}
return
resp
.
Matches
[
contexts
.
Evals
]
})
}
func
(
c
*
EvalListCommand
)
Name
()
string
{
return
"eval status"
}
func
(
c
*
EvalListCommand
)
Run
(
args
[]
string
)
int
{
var
monitor
,
verbose
,
json
bool
var
perPage
int
var
tmpl
,
pageToken
,
filterJobID
,
filterStatus
string
flags
:=
c
.
Meta
.
FlagSet
(
c
.
Name
(),
FlagSetClient
)
flags
.
Usage
=
func
()
{
c
.
Ui
.
Output
(
c
.
Help
())
}
flags
.
BoolVar
(
&
monitor
,
"monitor"
,
false
,
""
)
flags
.
BoolVar
(
&
verbose
,
"verbose"
,
false
,
""
)
flags
.
BoolVar
(
&
json
,
"json"
,
false
,
""
)
flags
.
StringVar
(
&
tmpl
,
"t"
,
""
,
""
)
flags
.
IntVar
(
&
perPage
,
"per_page"
,
0
,
""
)
flags
.
StringVar
(
&
pageToken
,
"page_token"
,
""
,
""
)
flags
.
StringVar
(
&
filterJobID
,
"job"
,
""
,
""
)
flags
.
StringVar
(
&
filterStatus
,
"status"
,
""
,
""
)
if
err
:=
flags
.
Parse
(
args
);
err
!=
nil
{
return
1
}
client
,
err
:=
c
.
Meta
.
Client
()
if
err
!=
nil
{
c
.
Ui
.
Error
(
fmt
.
Sprintf
(
"Error initializing client: %s"
,
err
))
return
1
}
opts
:=
&
api
.
QueryOptions
{
PerPage
:
int32
(
perPage
),
NextToken
:
pageToken
,
Params
:
map
[
string
]
string
{},
}
if
filterJobID
!=
""
{
opts
.
Params
[
"job"
]
=
filterJobID
}
if
filterStatus
!=
""
{
opts
.
Params
[
"status"
]
=
filterStatus
}
evals
,
qm
,
err
:=
client
.
Evaluations
()
.
List
(
opts
)
if
err
!=
nil
{
c
.
Ui
.
Error
(
fmt
.
Sprintf
(
"Error querying evaluations: %v"
,
err
))
return
1
}
// If args not specified but output format is specified, format
// and output the evaluations data list
if
json
||
len
(
tmpl
)
>
0
{
out
,
err
:=
Format
(
json
,
tmpl
,
evals
)
if
err
!=
nil
{
c
.
Ui
.
Error
(
err
.
Error
())
return
1
}
c
.
Ui
.
Output
(
out
)
return
0
}
if
len
(
evals
)
==
0
{
c
.
Ui
.
Output
(
fmt
.
Sprintf
(
"No evals found"
))
// TODO: what do we d
return
0
}
// Truncate the id unless full length is requested
length
:=
shortId
if
verbose
{
length
=
fullId
}
out
:=
make
([]
string
,
len
(
evals
)
+
1
)
out
[
0
]
=
"ID|Priority|Triggered By|Job ID|Status|Placement Failures"
for
i
,
eval
:=
range
evals
{
failures
,
_
:=
evalFailureStatus
(
eval
)
out
[
i
+
1
]
=
fmt
.
Sprintf
(
"%s|%d|%s|%s|%s|%s"
,
limit
(
eval
.
ID
,
length
),
eval
.
Priority
,
eval
.
TriggeredBy
,
eval
.
JobID
,
eval
.
Status
,
failures
,
)
}
c
.
Ui
.
Output
(
formatList
(
out
))
if
qm
.
NextToken
!=
""
{
c
.
Ui
.
Output
(
""
)
c
.
Ui
.
Output
(
"Results have been paginated, run the following to get the next page:"
)
// TODO: grab the other arguments
c
.
Ui
.
Output
(
fmt
.
Sprintf
(
" nomad eval list -page_token %s"
,
qm
.
NextToken
))
}
return
0
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help