Merge pull request #1252 from hashicorp/f-blocked-eval-text

Better placement failure text for blocked evals
This commit is contained in:
Alex Dadgar 2016-06-10 11:41:41 -07:00 committed by GitHub
commit b4fa34a854
3 changed files with 25 additions and 6 deletions

View File

@ -98,12 +98,13 @@ func (c *EvalStatusCommand) Run(args []string) int {
out := make([]string, len(evals)+1)
out[0] = "ID|Priority|Triggered By|Status|Placement Failures"
for i, eval := range evals {
out[i+1] = fmt.Sprintf("%s|%d|%s|%s|%t",
failures, _ := evalFailureStatus(eval)
out[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s",
limit(eval.ID, length),
eval.Priority,
eval.TriggeredBy,
eval.Status,
len(eval.FailedTGAllocs) != 0,
failures,
)
}
c.Ui.Output(fmt.Sprintf("Prefix matched multiple evaluations\n\n%s", formatList(out)))
@ -123,7 +124,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
return 1
}
failures := len(eval.FailedTGAllocs) != 0
failureString, failures := evalFailureStatus(eval)
triggerNoun, triggerSubj := getTriggerDetails(eval)
statusDesc := eval.StatusDescription
if statusDesc == "" {
@ -139,7 +140,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
fmt.Sprintf("TriggeredBy|%s", eval.TriggeredBy),
fmt.Sprintf("%s|%s", triggerNoun, triggerSubj),
fmt.Sprintf("Priority|%d", eval.Priority),
fmt.Sprintf("Placement Failures|%t", failures),
fmt.Sprintf("Placement Failures|%s", failureString),
}
if verbose {

View File

@ -2,6 +2,7 @@ package command
import (
"fmt"
"strconv"
"time"
"github.com/hashicorp/nomad/api"
@ -69,3 +70,19 @@ func getLocalNodeID(client *api.Client) (string, error) {
return nodeID, nil
}
// evalFailureStatus returns whether the evaluation has failures and a string to
// display when presenting users with whether there are failures for the eval
func evalFailureStatus(eval *api.Evaluation) (string, bool) {
if eval == nil {
return "", false
}
hasFailures := len(eval.FailedTGAllocs) != 0
text := strconv.FormatBool(hasFailures)
if eval.Status == "blocked" {
text = "N/A - In Progress"
}
return text, hasFailures
}

View File

@ -252,12 +252,13 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
evals = make([]string, len(jobEvals)+1)
evals[0] = "ID|Priority|Triggered By|Status|Placement Failures"
for i, eval := range jobEvals {
evals[i+1] = fmt.Sprintf("%s|%d|%s|%s|%t",
failures, _ := evalFailureStatus(eval)
evals[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s",
limit(eval.ID, c.length),
eval.Priority,
eval.TriggeredBy,
eval.Status,
len(eval.FailedTGAllocs) != 0,
failures,
)
if eval.Status == "blocked" {