Code review feedback
This commit is contained in:
parent
a1237d627a
commit
9d15e0c05b
|
@ -171,14 +171,15 @@ func (a Allocation) RescheduleInfo(t time.Time) (int, int) {
|
||||||
reschedulePolicy = tg.ReschedulePolicy
|
reschedulePolicy = tg.ReschedulePolicy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var availableAttempts int
|
if reschedulePolicy == nil {
|
||||||
var interval time.Duration
|
return 0, 0
|
||||||
if reschedulePolicy != nil {
|
|
||||||
availableAttempts = *reschedulePolicy.Attempts
|
|
||||||
interval = *reschedulePolicy.Interval
|
|
||||||
}
|
}
|
||||||
if a.RescheduleTracker != nil && availableAttempts > 0 && interval > 0 {
|
availableAttempts := *reschedulePolicy.Attempts
|
||||||
|
interval := *reschedulePolicy.Interval
|
||||||
attempted := 0
|
attempted := 0
|
||||||
|
|
||||||
|
// Loop over reschedule tracker to find attempts within the restart policy's interval
|
||||||
|
if a.RescheduleTracker != nil && availableAttempts > 0 && interval > 0 {
|
||||||
for j := len(a.RescheduleTracker.Events) - 1; j >= 0; j-- {
|
for j := len(a.RescheduleTracker.Events) - 1; j >= 0; j-- {
|
||||||
lastAttempt := a.RescheduleTracker.Events[j].RescheduleTime
|
lastAttempt := a.RescheduleTracker.Events[j].RescheduleTime
|
||||||
timeDiff := t.UTC().UnixNano() - lastAttempt
|
timeDiff := t.UTC().UnixNano() - lastAttempt
|
||||||
|
@ -186,9 +187,8 @@ func (a Allocation) RescheduleInfo(t time.Time) (int, int) {
|
||||||
attempted += 1
|
attempted += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return attempted, availableAttempts
|
|
||||||
}
|
}
|
||||||
return 0, availableAttempts
|
return attempted, availableAttempts
|
||||||
}
|
}
|
||||||
|
|
||||||
// RescheduleTracker encapsulates previous reschedule events
|
// RescheduleTracker encapsulates previous reschedule events
|
||||||
|
|
|
@ -281,7 +281,7 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength
|
||||||
}
|
}
|
||||||
if alloc.NextAllocation != "" {
|
if alloc.NextAllocation != "" {
|
||||||
basic = append(basic,
|
basic = append(basic,
|
||||||
fmt.Sprintf("Rescheduled Alloc ID|%s", limit(alloc.NextAllocation, uuidLength)))
|
fmt.Sprintf("Replacement Alloc ID|%s", limit(alloc.NextAllocation, uuidLength)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
|
|
|
@ -173,6 +173,31 @@ func TestAllocStatusCommand_Run(t *testing.T) {
|
||||||
}
|
}
|
||||||
ui.OutputWriter.Reset()
|
ui.OutputWriter.Reset()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAllocStatusCommand_RescheduleInfo(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
srv, client, url := testServer(t, true, nil)
|
||||||
|
defer srv.Shutdown()
|
||||||
|
|
||||||
|
// Wait for a node to be ready
|
||||||
|
testutil.WaitForResult(func() (bool, error) {
|
||||||
|
nodes, _, err := client.Nodes().List(nil)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
for _, node := range nodes {
|
||||||
|
if node.Status == structs.NodeStatusReady {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, fmt.Errorf("no ready nodes")
|
||||||
|
}, func(err error) {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
})
|
||||||
|
|
||||||
|
ui := new(cli.MockUi)
|
||||||
|
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
|
||||||
// Test reschedule attempt info
|
// Test reschedule attempt info
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
state := srv.Agent.Server().State()
|
state := srv.Agent.Server().State()
|
||||||
|
@ -194,10 +219,9 @@ func TestAllocStatusCommand_Run(t *testing.T) {
|
||||||
if code := cmd.Run([]string{"-address=" + url, a.ID}); code != 0 {
|
if code := cmd.Run([]string{"-address=" + url, a.ID}); code != 0 {
|
||||||
t.Fatalf("expected exit 0, got: %d", code)
|
t.Fatalf("expected exit 0, got: %d", code)
|
||||||
}
|
}
|
||||||
out = ui.OutputWriter.String()
|
out := ui.OutputWriter.String()
|
||||||
require.Contains(out, "Rescheduled Alloc ID")
|
require.Contains(out, "Replacement Alloc ID")
|
||||||
require.Regexp(regexp.MustCompile(".*Reschedule Attempts\\s*=\\s*1/2"), out)
|
require.Regexp(regexp.MustCompile(".*Reschedule Attempts\\s*=\\s*1/2"), out)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {
|
func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue