From f6aa384efb162a463acb31734287671e19257c92 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 10 Jun 2016 10:56:32 -0700 Subject: [PATCH 1/2] better placement failure text for blocked evals --- command/eval_status.go | 15 ++++++++++++--- command/status.go | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/command/eval_status.go b/command/eval_status.go index acecc1e0f..6f4a6c54c 100644 --- a/command/eval_status.go +++ b/command/eval_status.go @@ -3,6 +3,7 @@ package command import ( "fmt" "sort" + "strconv" "strings" "github.com/hashicorp/nomad/api" @@ -98,12 +99,16 @@ 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 := strconv.FormatBool(len(eval.FailedTGAllocs) != 0) + if eval.Status == "blocked" { + failures = "N/A - In Progress" + } + 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))) @@ -124,6 +129,10 @@ func (c *EvalStatusCommand) Run(args []string) int { } failures := len(eval.FailedTGAllocs) != 0 + failureString := strconv.FormatBool(failures) + if eval.Status == "blocked" { + failureString = "N/A - In Progress" + } triggerNoun, triggerSubj := getTriggerDetails(eval) statusDesc := eval.StatusDescription if statusDesc == "" { @@ -139,7 +148,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 { diff --git a/command/status.go b/command/status.go index 3351bba67..5764a8404 100644 --- a/command/status.go +++ b/command/status.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/gob" "fmt" + "strconv" "strings" "time" @@ -252,12 +253,17 @@ 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 := strconv.FormatBool(len(eval.FailedTGAllocs) != 0) + if eval.Status == "blocked" { + failures = "N/A - In Progress" + } + + 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" { From 185c896ac014e1531ffc9f62067867fafca4217d Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 10 Jun 2016 11:02:15 -0700 Subject: [PATCH 2/2] helper --- command/eval_status.go | 12 ++---------- command/helpers.go | 17 +++++++++++++++++ command/status.go | 7 +------ 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/command/eval_status.go b/command/eval_status.go index 6f4a6c54c..fc1c1a657 100644 --- a/command/eval_status.go +++ b/command/eval_status.go @@ -3,7 +3,6 @@ package command import ( "fmt" "sort" - "strconv" "strings" "github.com/hashicorp/nomad/api" @@ -99,10 +98,7 @@ 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 { - failures := strconv.FormatBool(len(eval.FailedTGAllocs) != 0) - if eval.Status == "blocked" { - failures = "N/A - In Progress" - } + failures, _ := evalFailureStatus(eval) out[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s", limit(eval.ID, length), eval.Priority, @@ -128,11 +124,7 @@ func (c *EvalStatusCommand) Run(args []string) int { return 1 } - failures := len(eval.FailedTGAllocs) != 0 - failureString := strconv.FormatBool(failures) - if eval.Status == "blocked" { - failureString = "N/A - In Progress" - } + failureString, failures := evalFailureStatus(eval) triggerNoun, triggerSubj := getTriggerDetails(eval) statusDesc := eval.StatusDescription if statusDesc == "" { diff --git a/command/helpers.go b/command/helpers.go index dfc8eea00..430868c43 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -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 +} diff --git a/command/status.go b/command/status.go index 5764a8404..2abbaf704 100644 --- a/command/status.go +++ b/command/status.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/gob" "fmt" - "strconv" "strings" "time" @@ -253,11 +252,7 @@ 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 { - failures := strconv.FormatBool(len(eval.FailedTGAllocs) != 0) - if eval.Status == "blocked" { - failures = "N/A - In Progress" - } - + failures, _ := evalFailureStatus(eval) evals[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s", limit(eval.ID, c.length), eval.Priority,