diff --git a/api/nodes_test.go b/api/nodes_test.go index ed13ba78a6b3..2e0ed5a9246a 100644 --- a/api/nodes_test.go +++ b/api/nodes_test.go @@ -67,18 +67,13 @@ func TestNodes_PrefixList(t *testing.T) { }) // Find node based on four character prefix - testutil.WaitForResult(func() (bool, error) { - out, qm, err = nodes.PrefixList(nodeID[:4]) - if err != nil { - return false, err - } - if n := len(out); n != 1 { - return false, fmt.Errorf("expected 1 node, got: %d ", n) - } - return true, nil - }, func(err error) { + out, qm, err = nodes.PrefixList(nodeID[:4]) + if err != nil { t.Fatalf("err: %s", err) - }) + } + if n := len(out); n != 1 { + t.Fatalf("expected 1 node, got: %d ", n) + } // Check that we got valid QueryMeta. assertQueryMeta(t, qm) diff --git a/command/agent/alloc_endpoint_test.go b/command/agent/alloc_endpoint_test.go index daa1fdfee92e..7bb80a3053d5 100644 --- a/command/agent/alloc_endpoint_test.go +++ b/command/agent/alloc_endpoint_test.go @@ -45,7 +45,7 @@ func TestHTTP_AllocsList(t *testing.T) { t.Fatalf("missing last contact") } - // Check the job + // Check the alloc n := obj.([]*structs.AllocListStub) if len(n) != 2 { t.Fatalf("bad: %#v", n) @@ -91,11 +91,16 @@ func TestHTTP_AllocsPrefixList(t *testing.T) { t.Fatalf("missing last contact") } - // Check the job + // Check the alloc n := obj.([]*structs.AllocListStub) if len(n) != 1 { t.Fatalf("bad: %#v", n) } + + // Check the identifier + if n[0].ID != alloc2.ID { + t.Fatalf("expected alloc ID: %v, Actual: %v", alloc2.ID, n[0].ID) + } }) } diff --git a/command/agent/eval_endpoint_test.go b/command/agent/eval_endpoint_test.go index ad3897185905..102c3d7c2666 100644 --- a/command/agent/eval_endpoint_test.go +++ b/command/agent/eval_endpoint_test.go @@ -45,7 +45,7 @@ func TestHTTP_EvalList(t *testing.T) { t.Fatalf("missing last contact") } - // Check the job + // Check the eval e := obj.([]*structs.Evaluation) if len(e) != 2 { t.Fatalf("bad: %#v", e) @@ -91,11 +91,16 @@ func TestHTTP_EvalPrefixList(t *testing.T) { t.Fatalf("missing last contact") } - // Check the job + // Check the eval e := obj.([]*structs.Evaluation) if len(e) != 1 { t.Fatalf("bad: %#v", e) } + + // Check the identifier + if e[0].ID != eval2.ID { + t.Fatalf("expected eval ID: %v, Actual: %v", eval2.ID, e[0].ID) + } }) } diff --git a/command/agent/node_endpoint_test.go b/command/agent/node_endpoint_test.go index ba5018803344..ec52d8149096 100644 --- a/command/agent/node_endpoint_test.go +++ b/command/agent/node_endpoint_test.go @@ -48,7 +48,7 @@ func TestHTTP_NodesList(t *testing.T) { t.Fatalf("missing last contact") } - // Check the job + // Check the nodes n := obj.([]*structs.NodeListStub) if len(n) < 3 { // Maybe 4 including client t.Fatalf("bad: %#v", n) @@ -97,7 +97,7 @@ func TestHTTP_NodesPrefixList(t *testing.T) { t.Fatalf("missing last contact") } - // Check the job + // Check the nodes n := obj.([]*structs.NodeListStub) if len(n) != 3 { t.Fatalf("bad: %#v", n) diff --git a/command/alloc_status.go b/command/alloc_status.go index d5c8104ff627..3616817686af 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -70,7 +70,7 @@ func (c *AllocStatusCommand) Run(args []string) int { if err != nil { allocs, _, err := client.Allocations().PrefixList(allocID) if err != nil { - c.Ui.Error(fmt.Sprintf("Error querying allocation: %s", err)) + c.Ui.Error(fmt.Sprintf("Error querying allocation: %v", err)) return 1 } if len(allocs) == 0 { @@ -90,9 +90,10 @@ func (c *AllocStatusCommand) Run(args []string) int { alloc.DesiredStatus, alloc.ClientStatus) } - c.Ui.Output(formatList(out)) + c.Ui.Output(fmt.Sprintf("Please disambiguate the desired allocation\n\n%s", formatList(out))) return 0 } + // Prefix lookup matched a single allocation alloc, _, err = client.Allocations().Info(allocs[0].ID, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error querying allocation: %s", err)) diff --git a/command/monitor.go b/command/monitor.go index dfcc5341fa75..c47007e4e57f 100644 --- a/command/monitor.go +++ b/command/monitor.go @@ -203,9 +203,10 @@ func (m *monitor) monitor(evalID string) int { eval.TriggeredBy, eval.Status) } - m.ui.Output(formatList(out)) + m.ui.Output(fmt.Sprintf("Please disambiguate the desired evaluation\n\n%s", formatList(out))) return 0 } + // Prefix lookup matched a single evaluation eval, _, err = m.client.Evaluations().Info(evals[0].ID, nil) if err != nil { m.ui.Error(fmt.Sprintf("Error reading evaluation: %s", err)) diff --git a/command/node_drain.go b/command/node_drain.go index 6e8321d21c51..4a0a696ecaf6 100644 --- a/command/node_drain.go +++ b/command/node_drain.go @@ -97,9 +97,10 @@ func (c *NodeDrainCommand) Run(args []string) int { node.Status) } // Dump the output - c.Ui.Output(formatList(out)) + c.Ui.Output(fmt.Sprintf("Please disambiguate the desired node\n\n%s", formatList(out))) return 0 } + // Prefix lookup matched a single node node, _, err = client.Nodes().Info(nodes[0].ID, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error toggling drain mode: %s", err)) diff --git a/command/node_status.go b/command/node_status.go index d2de4161348e..fd29f2335ce6 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -126,10 +126,10 @@ func (c *NodeStatusCommand) Run(args []string) int { node.Status) } // Dump the output - c.Ui.Output(formatList(out)) + c.Ui.Output(fmt.Sprintf("Please disambiguate the desired node\n\n%s", formatList(out))) return 0 } - // Query full node information for unique prefix match + // Prefix lookup matched a single node node, _, err = client.Nodes().Info(nodes[0].ID, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error querying node info: %s", err)) diff --git a/command/status.go b/command/status.go index d1359cbcb0c9..cbfdefc6dcff 100644 --- a/command/status.go +++ b/command/status.go @@ -114,9 +114,10 @@ func (c *StatusCommand) Run(args []string) int { job.Priority, job.Status) } - c.Ui.Output(formatList(out)) + c.Ui.Output(fmt.Sprintf("Please disambiguate the desired job\n\n%s", formatList(out))) return 0 } + // Prefix lookup matched a single job job, _, err = client.Jobs().Info(jobs[0].ID, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error querying job: %s", err)) diff --git a/command/stop.go b/command/stop.go index 87f49a32d968..a309dd26a01c 100644 --- a/command/stop.go +++ b/command/stop.go @@ -86,9 +86,10 @@ func (c *StopCommand) Run(args []string) int { job.Priority, job.Status) } - c.Ui.Output(formatList(out)) + c.Ui.Output(fmt.Sprintf("Please disambiguate the desired job\n\n%s", formatList(out))) return 0 } + // Prefix lookup matched a single job job, _, err = client.Jobs().Info(jobs[0].ID, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error deregistering job: %s", err)) diff --git a/website/source/docs/commands/alloc-status.html.md.erb b/website/source/docs/commands/alloc-status.html.md.erb index 8427a2910f4a..b0dcc2ad114f 100644 --- a/website/source/docs/commands/alloc-status.html.md.erb +++ b/website/source/docs/commands/alloc-status.html.md.erb @@ -19,8 +19,9 @@ current state of its tasks. nomad alloc-status [options] ``` -An allocation ID (prefix) must be provided. This specific allocation will be -queried and detailed information for it will be dumped. +An allocation ID or prefix must be provided. If there is an exact match, the +full details of the allocation will be displayed. Otherwise, a list of matching +allocations and information will be displayed. ## General Options diff --git a/website/source/docs/commands/eval-monitor.html.md.erb b/website/source/docs/commands/eval-monitor.html.md.erb index 2a969d763cb5..0159debe84b8 100644 --- a/website/source/docs/commands/eval-monitor.html.md.erb +++ b/website/source/docs/commands/eval-monitor.html.md.erb @@ -20,10 +20,12 @@ reaches a terminal state. nomad eval-monitor [options] ``` -The eval-monitor command requires a single argument, specifying the -evaluation ID (prefix) to monitor. An interactive monitoring session -will be started in the terminal. It is safe to exit the monitor at any -time using ctrl+c. +An evaluation ID or prefix must be provided. If there is an exact match, the +the evaluation will be monitored. Otherwise, a list of matching evaluations and +information will be displayed. + +An interactive monitoring session will be started in the terminal. It is safe +to exit the monitor at any time using ctrl+c. The command will exit when the given evaluation reaches a terminal state (completed or failed). Exit code 0 is returned on successful diff --git a/website/source/docs/commands/node-drain.html.md.erb b/website/source/docs/commands/node-drain.html.md.erb index 3c7bdcd84cf1..919989f4261b 100644 --- a/website/source/docs/commands/node-drain.html.md.erb +++ b/website/source/docs/commands/node-drain.html.md.erb @@ -21,9 +21,12 @@ nicely by providing the current drain status of a given node. nomad node-drain [options] ``` -This command expects exactly one argument to specify the node ID (prefix) -to enable or disable drain mode for. It is also required to pass one of -`-enable` or `-disable`, depending on which operation is desired. +A node ID or prefix must be provided. If there is an exact match, the +drain mode will be adjusted for that node. Otherwise, a list of matching +nodes and information will be displayed. + +It is also required to pass one of `-enable` or `-disable`, depending on which +operation is desired. ## General Options diff --git a/website/source/docs/commands/node-status.html.md.erb b/website/source/docs/commands/node-status.html.md.erb index 9cd8ad602204..066f99ab1859 100644 --- a/website/source/docs/commands/node-status.html.md.erb +++ b/website/source/docs/commands/node-status.html.md.erb @@ -20,9 +20,11 @@ nomad node-status [options] [node] If no node ID is passed, then the command will enter "list mode" and dump a high-level list of all known nodes. This list output contains less information -but is a good way to get a bird's-eye view of things. If a node ID (prefix) is -specified, then that particular node will be queried, and detailed information -will be displayed. +but is a good way to get a bird's-eye view of things. + +If there is an exact match based on the provided node ID or prefix, then that +particular node will be queried, and detailed information will be displayed. +Otherwise, a list of matching nodes and information will be displayed. ## General Options diff --git a/website/source/docs/commands/status.html.md.erb b/website/source/docs/commands/status.html.md.erb index c5492e1ec44d..e1b10f8f5f00 100644 --- a/website/source/docs/commands/status.html.md.erb +++ b/website/source/docs/commands/status.html.md.erb @@ -16,10 +16,13 @@ The `status` command displays status information for jobs. nomad status [options] [job] ``` -This command accepts an optional job ID (prefix) as the sole argument. If the -job ID is provided, information about the specific job is queried and displayed. -If the ID is omitted, the command lists out all of the existing jobs and a few -of the most useful status fields for each. +This command accepts an optional job ID or prefix as the sole argument. If there +is an exact match based on the provided job ID or prefix, then information about +the specific job is queried and displayed. Otherwise, a list of matching jobs and +information will be displayed. + +If the ID is omitted, the command lists out all of the existing jobs and a few of +the most useful status fields for each. ## General Options diff --git a/website/source/docs/commands/stop.html.md.erb b/website/source/docs/commands/stop.html.md.erb index b2c2cdc8c10b..08fcec3eecc0 100644 --- a/website/source/docs/commands/stop.html.md.erb +++ b/website/source/docs/commands/stop.html.md.erb @@ -17,8 +17,10 @@ to cancel all of the running allocations. nomad stop [options] ``` -The stop command requires a single argument, specifying the job ID (prefix) to -cancel. +The stop command requires a single argument, specifying the job ID or prefix to +cancel. If there is an exact match based on the provided job ID or prefix, then +the job will be cancelled. Otherwise, a list of matching jobs and information +will be displayed. Upon successful deregistration, an interactive monitor session will start to display log lines as the job unwinds its allocations and completes shutting