alloc-list shows version

This commit is contained in:
Alex Dadgar
2017-07-06 21:51:13 -07:00
parent f3ffc3de4d
commit c5b1e2dcc1
7 changed files with 80 additions and 79 deletions

View File

@@ -138,6 +138,7 @@ type AllocationListStub struct {
Name string
NodeID string
JobID string
JobVersion uint64
TaskGroup string
DesiredStatus string
DesiredDescription string

View File

@@ -135,20 +135,8 @@ func (c *AllocStatusCommand) Run(args []string) int {
return 1
}
if len(allocs) > 1 {
// Format the allocs
out := make([]string, len(allocs)+1)
out[0] = "ID|Eval ID|Job ID|Task Group|Desired Status|Client Status"
for i, alloc := range allocs {
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%s",
limit(alloc.ID, length),
limit(alloc.EvalID, length),
alloc.JobID,
alloc.TaskGroup,
alloc.DesiredStatus,
alloc.ClientStatus,
)
}
c.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", formatList(out)))
out := formatAllocListStubs(allocs, verbose, length)
c.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", out))
return 0
}
// Prefix lookup matched a single allocation

View File

@@ -159,19 +159,8 @@ func (f *FSCommand) Run(args []string) int {
}
if len(allocs) > 1 {
// Format the allocs
out := make([]string, len(allocs)+1)
out[0] = "ID|Eval ID|Job ID|Task Group|Desired Status|Client Status"
for i, alloc := range allocs {
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%s",
limit(alloc.ID, length),
limit(alloc.EvalID, length),
alloc.JobID,
alloc.TaskGroup,
alloc.DesiredStatus,
alloc.ClientStatus,
)
}
f.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", formatList(out)))
out := formatAllocListStubs(allocs, verbose, length)
f.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", out))
return 0
}
// Prefix lookup matched a single allocation

View File

@@ -135,19 +135,8 @@ func (l *LogsCommand) Run(args []string) int {
}
if len(allocs) > 1 {
// Format the allocs
out := make([]string, len(allocs)+1)
out[0] = "ID|Eval ID|Job ID|Task Group|Desired Status|Client Status"
for i, alloc := range allocs {
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%s",
limit(alloc.ID, length),
limit(alloc.EvalID, length),
alloc.JobID,
alloc.TaskGroup,
alloc.DesiredStatus,
alloc.ClientStatus,
)
}
l.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", formatList(out)))
out := formatAllocListStubs(allocs, verbose, length)
l.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", out))
return 0
}
// Prefix lookup matched a single allocation

View File

@@ -340,16 +340,14 @@ func (c *NodeStatusCommand) formatNode(client *api.Client, node *api.Node) int {
}
}
allocs, err := getAllocs(client, node, c.length)
nodeAllocs, _, err := client.Nodes().Allocations(node.ID, nil)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error querying node allocations: %s", err))
return 1
}
if len(allocs) > 1 {
c.Ui.Output(c.Colorize().Color("\n[bold]Allocations[reset]"))
c.Ui.Output(formatList(allocs))
}
c.Ui.Output(c.Colorize().Color("\n[bold]Allocations[reset]"))
c.Ui.Output(formatAllocList(nodeAllocs, c.verbose, c.length))
if c.verbose {
c.formatAttributes(node)
@@ -453,26 +451,6 @@ func getRunningAllocs(client *api.Client, nodeID string) ([]*api.Allocation, err
return allocs, err
}
// getAllocs returns information about every running allocation on the node
func getAllocs(client *api.Client, node *api.Node, length int) ([]string, error) {
var allocs []string
// Query the node allocations
nodeAllocs, _, err := client.Nodes().Allocations(node.ID, nil)
// Format the allocations
allocs = make([]string, len(nodeAllocs)+1)
allocs[0] = "ID|Eval ID|Job ID|Task Group|Desired Status|Client Status"
for i, alloc := range nodeAllocs {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%s",
limit(alloc.ID, length),
limit(alloc.EvalID, length),
alloc.JobID,
alloc.TaskGroup,
alloc.DesiredStatus,
alloc.ClientStatus)
}
return allocs, err
}
// getAllocatedResources returns the resource usage of the node.
func getAllocatedResources(client *api.Client, runningAllocs []*api.Allocation, node *api.Node) []string {
// Compute the total

View File

@@ -279,7 +279,6 @@ func (c *StatusCommand) outputParameterizedInfo(client *api.Client, job *api.Job
// outputJobInfo prints information about the passed non-periodic job. If a
// request fails, an error is returned.
func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
var evals, allocs []string
// Query the allocations
jobAllocs, _, err := client.Jobs().Allocations(*job.ID, c.allAllocs, nil)
@@ -304,7 +303,7 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
blockedEval := false
// Format the evals
evals = make([]string, len(jobEvals)+1)
evals := make([]string, len(jobEvals)+1)
evals[0] = "ID|Priority|Triggered By|Status|Placement Failures"
for i, eval := range jobEvals {
failures, _ := evalFailureStatus(eval)
@@ -341,25 +340,80 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
// Format the allocs
c.Ui.Output(c.Colorize().Color("\n[bold]Allocations[reset]"))
if len(jobAllocs) > 0 {
allocs = make([]string, len(jobAllocs)+1)
allocs[0] = "ID|Eval ID|Node ID|Task Group|Desired|Status|Created At"
for i, alloc := range jobAllocs {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%s|%s",
limit(alloc.ID, c.length),
limit(alloc.EvalID, c.length),
limit(alloc.NodeID, c.length),
c.Ui.Output(formatAllocListStubs(jobAllocs, c.verbose, c.length))
return nil
}
func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLength int) string {
if len(stubs) == 0 {
return "No allocations placed"
}
allocs := make([]string, len(stubs)+1)
if verbose {
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created At"
for i, alloc := range stubs {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.EvalID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
alloc.JobVersion,
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
}
c.Ui.Output(formatList(allocs))
} else {
c.Ui.Output("No allocations placed")
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created At"
for i, alloc := range stubs {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
alloc.JobVersion,
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
}
}
return nil
return formatList(allocs)
}
func formatAllocList(allocations []*api.Allocation, verbose bool, uuidLength int) string {
if len(allocations) == 0 {
return "No allocations placed"
}
allocs := make([]string, len(allocations)+1)
if verbose {
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created At"
for i, alloc := range allocations {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.EvalID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
*alloc.Job.Version,
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
}
} else {
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created At"
for i, alloc := range allocations {
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s",
limit(alloc.ID, uuidLength),
limit(alloc.NodeID, uuidLength),
alloc.TaskGroup,
*alloc.Job.Version,
alloc.DesiredStatus,
alloc.ClientStatus,
formatUnixNanoTime(alloc.CreateTime))
}
}
return formatList(allocs)
}
// outputJobSummary displays the given jobs summary and children job summary

View File

@@ -4375,6 +4375,7 @@ func (a *Allocation) Stub() *AllocListStub {
Name: a.Name,
NodeID: a.NodeID,
JobID: a.JobID,
JobVersion: a.Job.Version,
TaskGroup: a.TaskGroup,
DesiredStatus: a.DesiredStatus,
DesiredDescription: a.DesiredDescription,
@@ -4395,6 +4396,7 @@ type AllocListStub struct {
Name string
NodeID string
JobID string
JobVersion uint64
TaskGroup string
DesiredStatus string
DesiredDescription string