Skip to content

Commit

Permalink
Add NodeName to the alloc/job status outputs.
Browse files Browse the repository at this point in the history
Currently when operators need to log onto a machine where an alloc
is running they will need to perform both an alloc/job status
call and then a call to discover the node name from the node list.

This updates both the job status and alloc status output to include
the node name within the information to make operator use easier.

Closes hashicorp#2359
Cloess hashicorp#1180
  • Loading branch information
jrasell committed Jul 17, 2018
1 parent 03f08f1 commit e1e019a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Allocation struct {
EvalID string
Name string
NodeID string
NodeName string
JobID string
Job *Job
TaskGroup string
Expand Down Expand Up @@ -121,6 +122,7 @@ type AllocationListStub struct {
EvalID string
Name string
NodeID string
NodeName string
JobID string
JobVersion uint64
TaskGroup string
Expand Down
1 change: 1 addition & 0 deletions command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength
fmt.Sprintf("Eval ID|%s", limit(alloc.EvalID, uuidLength)),
fmt.Sprintf("Name|%s", alloc.Name),
fmt.Sprintf("Node ID|%s", limit(alloc.NodeID, uuidLength)),
fmt.Sprintf("Node Name|%s", alloc.NodeName),
fmt.Sprintf("Job ID|%s", alloc.JobID),
fmt.Sprintf("Job Version|%d", getVersion(alloc.Job)),
fmt.Sprintf("Client Status|%s", alloc.ClientStatus),
Expand Down
10 changes: 6 additions & 4 deletions command/job_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,13 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen

allocs := make([]string, len(stubs)+1)
if verbose {
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created|Modified"
allocs[0] = "ID|Eval ID|Node ID|Node Name|Task Group|Version|Desired|Status|Created|Modified"
for i, alloc := range stubs {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s|%s",
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%d|%s|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.EvalID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.NodeName,
alloc.TaskGroup,
alloc.JobVersion,
alloc.DesiredStatus,
Expand All @@ -427,14 +428,15 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen
formatUnixNanoTime(alloc.ModifyTime))
}
} else {
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created|Modified"
allocs[0] = "ID|Node ID|Node Name|Task Group|Version|Desired|Status|Created|Modified"
for i, alloc := range stubs {
now := time.Now()
createTimePretty := prettyTimeDiff(time.Unix(0, alloc.CreateTime), now)
modTimePretty := prettyTimeDiff(time.Unix(0, alloc.ModifyTime), now)
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s|%s",
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.NodeName,
alloc.TaskGroup,
alloc.JobVersion,
alloc.DesiredStatus,
Expand Down
5 changes: 5 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5751,6 +5751,9 @@ type Allocation struct {
// NodeID is the node this is being placed on
NodeID string

// NodeName is the name of the node this is being placed on.
NodeName string

// Job is the parent job of the task group being allocated.
// This is copied at allocation time to avoid issues if the job
// definition is updated.
Expand Down Expand Up @@ -6132,6 +6135,7 @@ func (a *Allocation) Stub() *AllocListStub {
EvalID: a.EvalID,
Name: a.Name,
NodeID: a.NodeID,
NodeName: a.NodeName,
JobID: a.JobID,
JobVersion: a.Job.Version,
TaskGroup: a.TaskGroup,
Expand All @@ -6157,6 +6161,7 @@ type AllocListStub struct {
EvalID string
Name string
NodeID string
NodeName string
JobID string
JobVersion uint64
TaskGroup string
Expand Down
1 change: 1 addition & 0 deletions scheduler/generic_sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func (s *GenericScheduler) computePlacements(destructive, place []placementResul
TaskGroup: tg.Name,
Metrics: s.ctx.Metrics(),
NodeID: option.Node.ID,
NodeName: option.Node.Name,
DeploymentID: deploymentID,
TaskResources: option.TaskResources,
DesiredStatus: structs.AllocDesiredStatusRun,
Expand Down
1 change: 1 addition & 0 deletions scheduler/system_sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func (s *SystemScheduler) computePlacements(place []allocTuple) error {
TaskGroup: missing.TaskGroup.Name,
Metrics: s.ctx.Metrics(),
NodeID: option.Node.ID,
NodeName: option.Node.Name,
TaskResources: option.TaskResources,
DesiredStatus: structs.AllocDesiredStatusRun,
ClientStatus: structs.AllocClientStatusPending,
Expand Down

0 comments on commit e1e019a

Please sign in to comment.