mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 10:55:42 +03:00
review feedback
This commit is contained in:
@@ -197,48 +197,49 @@ func (c *JobPlanCommand) addPreemptions(resp *api.JobPlanResponse) {
|
||||
allocs = append(allocs, fmt.Sprintf("%s|%s|%s", alloc.ID, alloc.JobID, alloc.TaskGroup))
|
||||
}
|
||||
c.Ui.Output(formatList(allocs))
|
||||
} else {
|
||||
// Display in a summary format if the list is too large
|
||||
// Group by job type and job ids
|
||||
allocDetails := make(map[string]map[namespaceIdPair]int)
|
||||
numJobs := 0
|
||||
for _, alloc := range resp.Annotations.PreemptedAllocs {
|
||||
id := namespaceIdPair{alloc.JobID, alloc.Namespace}
|
||||
countMap := allocDetails[alloc.JobType]
|
||||
if countMap == nil {
|
||||
countMap = make(map[namespaceIdPair]int)
|
||||
}
|
||||
cnt, ok := countMap[id]
|
||||
if !ok {
|
||||
// First time we are seeing this job, increment counter
|
||||
numJobs++
|
||||
}
|
||||
countMap[id] = cnt + 1
|
||||
allocDetails[alloc.JobType] = countMap
|
||||
}
|
||||
|
||||
// Show counts grouped by job ID if its less than a threshold
|
||||
var output []string
|
||||
if numJobs < preemptionDisplayThreshold {
|
||||
output = append(output, fmt.Sprintf("Job ID|Namespace|Job Type|Preemptions"))
|
||||
for jobType, jobCounts := range allocDetails {
|
||||
for jobId, count := range jobCounts {
|
||||
output = append(output, fmt.Sprintf("%s|%s|%s|%d", jobId.id, jobId.namespace, jobType, count))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Show counts grouped by job type
|
||||
output = append(output, fmt.Sprintf("Job Type|Preemptions"))
|
||||
for jobType, jobCounts := range allocDetails {
|
||||
total := 0
|
||||
for _, count := range jobCounts {
|
||||
total += count
|
||||
}
|
||||
output = append(output, fmt.Sprintf("%s|%d", jobType, total))
|
||||
}
|
||||
}
|
||||
c.Ui.Output(formatList(output))
|
||||
return
|
||||
}
|
||||
// Display in a summary format if the list is too large
|
||||
// Group by job type and job ids
|
||||
allocDetails := make(map[string]map[namespaceIdPair]int)
|
||||
numJobs := 0
|
||||
for _, alloc := range resp.Annotations.PreemptedAllocs {
|
||||
id := namespaceIdPair{alloc.JobID, alloc.Namespace}
|
||||
countMap := allocDetails[alloc.JobType]
|
||||
if countMap == nil {
|
||||
countMap = make(map[namespaceIdPair]int)
|
||||
}
|
||||
cnt, ok := countMap[id]
|
||||
if !ok {
|
||||
// First time we are seeing this job, increment counter
|
||||
numJobs++
|
||||
}
|
||||
countMap[id] = cnt + 1
|
||||
allocDetails[alloc.JobType] = countMap
|
||||
}
|
||||
|
||||
// Show counts grouped by job ID if its less than a threshold
|
||||
var output []string
|
||||
if numJobs < preemptionDisplayThreshold {
|
||||
output = append(output, fmt.Sprintf("Job ID|Namespace|Job Type|Preemptions"))
|
||||
for jobType, jobCounts := range allocDetails {
|
||||
for jobId, count := range jobCounts {
|
||||
output = append(output, fmt.Sprintf("%s|%s|%s|%d", jobId.id, jobId.namespace, jobType, count))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Show counts grouped by job type
|
||||
output = append(output, fmt.Sprintf("Job Type|Preemptions"))
|
||||
for jobType, jobCounts := range allocDetails {
|
||||
total := 0
|
||||
for _, count := range jobCounts {
|
||||
total += count
|
||||
}
|
||||
output = append(output, fmt.Sprintf("%s|%d", jobType, total))
|
||||
}
|
||||
}
|
||||
c.Ui.Output(formatList(output))
|
||||
|
||||
}
|
||||
|
||||
type namespaceIdPair struct {
|
||||
|
||||
@@ -4,15 +4,14 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/mitchellh/cli"
|
||||
require2 "github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPlanCommand_Implements(t *testing.T) {
|
||||
@@ -178,7 +177,7 @@ func TestPlanCommad_Preemptions(t *testing.T) {
|
||||
t.Parallel()
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &JobPlanCommand{Meta: Meta{Ui: ui}}
|
||||
require := require2.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
// Only one preempted alloc
|
||||
resp1 := &api.JobPlanResponse{
|
||||
|
||||
Reference in New Issue
Block a user