Skip to content

Commit

Permalink
Improvements for short identifiers
Browse files Browse the repository at this point in the history
* Fix tests
* Update documentation
  • Loading branch information
iverberk committed Jan 6, 2016
1 parent c65fdc3 commit 6295108
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 43 deletions.
17 changes: 6 additions & 11 deletions api/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions command/agent/alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
})
}

Expand Down
9 changes: 7 additions & 2 deletions command/agent/eval_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
})
}

Expand Down
4 changes: 2 additions & 2 deletions command/agent/node_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion command/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion command/node_drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion command/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions website/source/docs/commands/alloc-status.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ current state of its tasks.
nomad alloc-status [options] <allocation>
```

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

Expand Down
10 changes: 6 additions & 4 deletions website/source/docs/commands/eval-monitor.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ reaches a terminal state.
nomad eval-monitor [options] <eval>
```

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
Expand Down
9 changes: 6 additions & 3 deletions website/source/docs/commands/node-drain.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ nicely by providing the current drain status of a given node.
nomad node-drain [options] <node>
```

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

Expand Down
8 changes: 5 additions & 3 deletions website/source/docs/commands/node-status.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions website/source/docs/commands/status.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions website/source/docs/commands/stop.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ to cancel all of the running allocations.
nomad stop [options] <job>
```

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
Expand Down

0 comments on commit 6295108

Please sign in to comment.