Skip to content

Commit

Permalink
Merge pull request #1623 from novilabs/alloc-status-created-at
Browse files Browse the repository at this point in the history
add 'Created At' to nomad alloc-status
  • Loading branch information
dadgar committed Aug 19, 2016
2 parents 6d4f8b9 + 89d3feb commit 8af1609
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ 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("Created At|%s", formatUnixNanoTime(alloc.CreateTime)),
}

if verbose {
Expand Down
51 changes: 51 additions & 0 deletions command/alloc_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"
"testing"

"github.com/hashicorp/nomad/testutil"
"github.com/mitchellh/cli"
)

Expand Down Expand Up @@ -71,3 +72,53 @@ func TestAllocStatusCommand_Fails(t *testing.T) {
t.Fatalf("expected getting formatter error, got: %s", out)
}
}

func TestAllocStatusCommand_Run(t *testing.T) {
srv, client, url := testServer(t, func(c *testutil.TestServerConfig) {
c.DevMode = true
})
defer srv.Stop()
ui := new(cli.MockUi)
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}

jobID := "job1_sfx"
job1 := testJob(jobID)
evalId1, _, err := client.Jobs().Register(job1, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if code := waitForSuccess(ui, client, fullId, t, evalId1); code != 0 {
t.Fatalf("status code non zero saw %d", code)
}
// get an alloc id
allocId1 := ""
if allocs, _, err := client.Jobs().Allocations(jobID, nil); err == nil {
if len(allocs) > 0 {
allocId1 = allocs[0].ID
}
}
if allocId1 == "" {
t.Fatal("unable to find an allocation")
}

if code := cmd.Run([]string{"-address=" + url, allocId1}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
}
out := ui.OutputWriter.String()
if !strings.Contains(out, "Created At") {
t.Fatalf("expected to have 'Created At' but saw: %s", out)
}
ui.OutputWriter.Reset()

if code := cmd.Run([]string{"-address=" + url, "-verbose", allocId1}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
}
out = ui.OutputWriter.String()
if !strings.Contains(out, allocId1) {
t.Fatal("expected to find alloc id in output");
}
if !strings.Contains(out, "Created At") {
t.Fatalf("expected to have 'Created At' but saw: %s", out)
}
ui.OutputWriter.Reset()
}
5 changes: 4 additions & 1 deletion website/source/docs/commands/alloc-status.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Name = example.cache[0]
Node ID = 1f029d38
Job ID = example
Client Status = running
Created At = 29/03/16 03:04:53 UTC

==> Tasks
Name State Last Event Time
Expand All @@ -63,6 +64,7 @@ Name = example.cache[0]
Node ID = 1f029d38
Job ID = example
Client Status = running
Created At = 29/03/16 03:04:53 UTC

==> Task Resources
Task: "redis"
Expand Down Expand Up @@ -91,13 +93,14 @@ Time Type Description
Verbose status can also be accessed:

```
$ nomad alloc-status a7365fe4
$ nomad alloc-status --verbose a7365fe4
ID = a7365fe4-cb28-a6e9-f3d4-f99e49c89776
Eval ID = c3c9a1db-dbeb-8afa-0a83-4f1b8b5a03f5
Name = example.cache[0]
Node ID = 1f029d38-8d4b-a552-261f-e457b60f9b4b
Job ID = example
Client Status = running
Created At = 29/03/16 03:04:53 UTC
Evaluated Nodes = 1
Filtered Nodes = 0
Exhausted Nodes = 0
Expand Down
3 changes: 3 additions & 0 deletions website/source/docs/jobops/inspecting.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Name = example.cache[1]
Node ID = 4beef22f
Job ID = example
Client Status = running
Created At = 06/28/16 15:37:44 UTC
Task "redis" is "running"
Task Resources
Expand Down Expand Up @@ -126,6 +127,7 @@ Name = example.cache[0]
Node ID = 13063955
Job ID = example
Client Status = failed
Created At = 06/28/16 15:50:22 UTC
Task "redis" is "dead"
Task Resources
Expand Down Expand Up @@ -153,6 +155,7 @@ Name = example.cache[0]
Node ID = 83ef596c
Job ID = example
Client Status = pending
Created At = 06/28/16 15:55:48
Task "redis" is "pending"
Task Resources
Expand Down
1 change: 1 addition & 0 deletions website/source/docs/jobops/resources.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Name = example.cache[0]
Node ID = 39acd6e0
Job ID = example
Client Status = running
Created At = 06/28/16 16:42:42 UTC
Task "redis" is "running"
Task Resources
Expand Down
1 change: 1 addition & 0 deletions website/source/intro/getting-started/jobs.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Name = example.cache[0]
Node ID = 72687b1a
Job ID = example
Client Status = running
Created At = 06/23/16 01:41:13 UTC
Task "redis" is "running"
Task Resources
Expand Down

0 comments on commit 8af1609

Please sign in to comment.