From 63e172747ab077ec0e618f156692f98cb4f1aaed Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Sun, 20 Mar 2016 16:52:24 -0700 Subject: [PATCH] Reduce verbosity of alloc-status --- client/driver/executor/executor_test.go | 2 +- command/alloc_status.go | 32 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/client/driver/executor/executor_test.go b/client/driver/executor/executor_test.go index ab5d7099d010..f60f978076d7 100644 --- a/client/driver/executor/executor_test.go +++ b/client/driver/executor/executor_test.go @@ -11,11 +11,11 @@ import ( "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/driver/env" + cstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" tu "github.com/hashicorp/nomad/testutil" - cstructs "github.com/hashicorp/nomad/client/driver/structs" ) var ( diff --git a/command/alloc_status.go b/command/alloc_status.go index 5e6807e49af7..c41eb3c05d8a 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -126,14 +126,22 @@ func (c *AllocStatusCommand) Run(args []string) int { fmt.Sprintf("Node ID|%s", limit(alloc.NodeID, length)), fmt.Sprintf("Job ID|%s", alloc.JobID), fmt.Sprintf("Client Status|%s", alloc.ClientStatus), - fmt.Sprintf("Evaluated Nodes|%d", alloc.Metrics.NodesEvaluated), - fmt.Sprintf("Filtered Nodes|%d", alloc.Metrics.NodesFiltered), - fmt.Sprintf("Exhausted Nodes|%d", alloc.Metrics.NodesExhausted), - fmt.Sprintf("Allocation Time|%s", alloc.Metrics.AllocationTime), - fmt.Sprintf("Failures|%d", alloc.Metrics.CoalescedFailures), + } + + if verbose { + basic = append(basic, + fmt.Sprintf("Evaluated Nodes|%d", alloc.Metrics.NodesEvaluated), + fmt.Sprintf("Filtered Nodes|%d", alloc.Metrics.NodesFiltered), + fmt.Sprintf("Exhausted Nodes|%d", alloc.Metrics.NodesExhausted), + fmt.Sprintf("Allocation Time|%s", alloc.Metrics.AllocationTime), + fmt.Sprintf("Failures|%d", alloc.Metrics.CoalescedFailures)) } c.Ui.Output(formatKV(basic)) + if !short { + c.taskResources(alloc) + } + // Print the state of each task. if short { c.shortTaskStatus(alloc) @@ -142,12 +150,9 @@ func (c *AllocStatusCommand) Run(args []string) int { } // Format the detailed status - c.Ui.Output("\n==> Status") - dumpAllocStatus(c.Ui, alloc, length) - - if !short { - c.Ui.Output("\n==> Task Resources") - c.taskResources(alloc) + if verbose || alloc.DesiredStatus == "failed" { + c.Ui.Output("\n==> Status") + dumpAllocStatus(c.Ui, alloc, length) } return 0 @@ -283,6 +288,11 @@ func (c *AllocStatusCommand) allocResources(alloc *api.Allocation) { // taskResources prints out the tasks current resource usage func (c *AllocStatusCommand) taskResources(alloc *api.Allocation) { + if len(alloc.TaskResources) == 0 { + return + } + + c.Ui.Output("\n==> Task Resources") firstLine := true for task, resource := range alloc.TaskResources { header := fmt.Sprintf("\nTask: %q", task)