2015-09-16 23:05:57 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EvalMonitorCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *EvalMonitorCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad eval-monitor [options] <evaluation>
|
|
|
|
|
|
|
|
Start an interactive monitoring session for an existing evaluation.
|
|
|
|
The monitor command periodically polls for information about the
|
|
|
|
provided evaluation, including status updates, new allocations,
|
|
|
|
updates to allocations, and failures. Status is printed in near
|
|
|
|
real-time to the terminal.
|
|
|
|
|
|
|
|
The command will exit when the given evaluation reaches a terminal
|
2015-09-21 19:19:34 +00:00
|
|
|
state (completed or failed). Exit code 0 is returned on successful
|
|
|
|
evaluation, and if there are no scheduling problems. If there are
|
|
|
|
job placement issues encountered (unsatisfiable constraints,
|
|
|
|
resource exhaustion, etc), then the exit code will be 2. Any other
|
|
|
|
errors, including client connection issues or internal errors, are
|
|
|
|
indicated by exit code 1.
|
2015-09-16 23:05:57 +00:00
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
2016-01-14 20:57:43 +00:00
|
|
|
` + generalOptionsUsage() + `
|
|
|
|
|
|
|
|
Eval Monitor Options:
|
|
|
|
|
2016-01-15 22:32:38 +00:00
|
|
|
-verbose
|
|
|
|
Show full information.
|
2016-01-14 20:57:43 +00:00
|
|
|
`
|
2015-09-16 23:05:57 +00:00
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *EvalMonitorCommand) Synopsis() string {
|
|
|
|
return "Monitor an evaluation interactively"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *EvalMonitorCommand) Run(args []string) int {
|
2016-01-15 22:32:38 +00:00
|
|
|
var verbose bool
|
2016-01-14 20:57:43 +00:00
|
|
|
|
2015-09-16 23:05:57 +00:00
|
|
|
flags := c.Meta.FlagSet("eval-monitor", FlagSetClient)
|
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
2016-01-15 22:32:38 +00:00
|
|
|
flags.BoolVar(&verbose, "verbose", false, "")
|
2016-01-14 20:57:43 +00:00
|
|
|
|
2015-09-16 23:05:57 +00:00
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:57:43 +00:00
|
|
|
// Truncate the id unless full length is requested
|
2016-01-15 22:32:38 +00:00
|
|
|
length := shortId
|
|
|
|
if verbose {
|
|
|
|
length = fullId
|
2016-01-14 20:57:43 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 23:05:57 +00:00
|
|
|
// Check that we got exactly one eval ID
|
|
|
|
args = flags.Args()
|
|
|
|
if len(args) != 1 {
|
|
|
|
c.Ui.Error(c.Help())
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
evalID := args[0]
|
|
|
|
|
|
|
|
// Get the HTTP client
|
|
|
|
client, err := c.Meta.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start monitoring
|
2016-01-14 20:57:43 +00:00
|
|
|
mon := newMonitor(c.Ui, client, length)
|
2016-01-07 23:25:08 +00:00
|
|
|
return mon.monitor(evalID, true)
|
2015-09-16 23:05:57 +00:00
|
|
|
}
|