Merge pull request #4045 from hashicorp/f-rename-linear-constant

s/linear/constant/g
This commit is contained in:
Preetha 2018-03-26 16:22:21 -05:00 committed by GitHub
commit b4ae8c48eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 41 additions and 41 deletions

View file

@ -92,7 +92,7 @@ type ReschedulePolicy struct {
Delay *time.Duration `mapstructure:"delay"`
// DelayFunction determines how the delay progressively changes on subsequent reschedule
// attempts. Valid values are "exponential", "linear", and "fibonacci".
// attempts. Valid values are "exponential", "constant", and "fibonacci".
DelayFunction *string `mapstructure:"delay_function"`
// MaxDelay is an upper bound on the delay.

View file

@ -319,7 +319,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
Interval: helper.TimeToPtr(20 * time.Second),
Delay: helper.TimeToPtr(20 * time.Second),
MaxDelay: helper.TimeToPtr(10 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
taskReschedulePolicy: nil,
@ -328,7 +328,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
Interval: helper.TimeToPtr(20 * time.Second),
Delay: helper.TimeToPtr(20 * time.Second),
MaxDelay: helper.TimeToPtr(10 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
},
@ -340,7 +340,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
Interval: helper.TimeToPtr(2 * time.Minute),
Delay: helper.TimeToPtr(20 * time.Second),
MaxDelay: helper.TimeToPtr(10 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
expected: &ReschedulePolicy{
@ -348,7 +348,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
Interval: helper.TimeToPtr(2 * time.Minute),
Delay: helper.TimeToPtr(20 * time.Second),
MaxDelay: helper.TimeToPtr(10 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
},
@ -361,7 +361,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
},
taskReschedulePolicy: &ReschedulePolicy{
Interval: helper.TimeToPtr(5 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
expected: &ReschedulePolicy{
@ -369,7 +369,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
Interval: helper.TimeToPtr(5 * time.Minute),
Delay: helper.TimeToPtr(20 * time.Second),
MaxDelay: helper.TimeToPtr(10 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
},
@ -383,7 +383,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
Attempts: helper.IntToPtr(5),
Delay: helper.TimeToPtr(20 * time.Second),
MaxDelay: helper.TimeToPtr(20 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
expected: &ReschedulePolicy{
@ -391,7 +391,7 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) {
Interval: helper.TimeToPtr(structs.DefaultBatchJobReschedulePolicy.Interval),
Delay: helper.TimeToPtr(20 * time.Second),
MaxDelay: helper.TimeToPtr(20 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Unlimited: helper.BoolToPtr(false),
},
},

View file

@ -1173,7 +1173,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
ReschedulePolicy: &api.ReschedulePolicy{
Interval: helper.TimeToPtr(12 * time.Hour),
Attempts: helper.IntToPtr(5),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Delay: helper.TimeToPtr(30 * time.Second),
Unlimited: helper.BoolToPtr(true),
MaxDelay: helper.TimeToPtr(20 * time.Minute),
@ -1395,7 +1395,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
ReschedulePolicy: &structs.ReschedulePolicy{
Interval: 12 * time.Hour,
Attempts: 5,
DelayFunction: "linear",
DelayFunction: "constant",
Delay: 30 * time.Second,
Unlimited: true,
MaxDelay: 20 * time.Minute,

View file

@ -687,7 +687,7 @@ func TestParse(t *testing.T) {
Reschedule: &api.ReschedulePolicy{
Attempts: helper.IntToPtr(15),
Interval: helper.TimeToPtr(30 * time.Minute),
DelayFunction: helper.StringToPtr("linear"),
DelayFunction: helper.StringToPtr("constant"),
Delay: helper.TimeToPtr(10 * time.Second),
},
TaskGroups: []*api.TaskGroup{

View file

@ -5,7 +5,7 @@ job "foo" {
attempts = 15
interval = "30m"
delay = "10s",
delay_function = "linear"
delay_function = "constant"
}
group "bar" {
count = 3

View file

@ -96,7 +96,7 @@ func Job() *structs.Job {
Attempts: 2,
Interval: 10 * time.Minute,
Delay: 5 * time.Second,
DelayFunction: "linear",
DelayFunction: "constant",
},
Migrate: structs.DefaultMigrateStrategy(),
Tasks: []*structs.Task{
@ -196,7 +196,7 @@ func BatchJob() *structs.Job {
Attempts: 2,
Interval: 10 * time.Minute,
Delay: 5 * time.Second,
DelayFunction: "linear",
DelayFunction: "constant",
},
Tasks: []*structs.Task{
{

View file

@ -1632,7 +1632,7 @@ func TestTaskGroupDiff(t *testing.T) {
ReschedulePolicy: &ReschedulePolicy{
Attempts: 2,
Interval: 2 * time.Second,
DelayFunction: "linear",
DelayFunction: "constant",
Delay: 30 * time.Second,
MaxDelay: 1 * time.Minute,
Unlimited: true,
@ -1661,7 +1661,7 @@ func TestTaskGroupDiff(t *testing.T) {
Type: DiffTypeEdited,
Name: "DelayFunction",
Old: "exponential",
New: "linear",
New: "constant",
},
{
Type: DiffTypeEdited,

View file

@ -2766,7 +2766,7 @@ var (
Attempts: 1,
Interval: 24 * time.Hour,
Delay: 5 * time.Second,
DelayFunction: "linear",
DelayFunction: "constant",
}
)
@ -2851,7 +2851,7 @@ func NewRestartPolicy(jobType string) *RestartPolicy {
const ReschedulePolicyMinInterval = 15 * time.Second
const ReschedulePolicyMinDelay = 5 * time.Second
var RescheduleDelayFunctions = [...]string{"linear", "exponential", "fibonacci"}
var RescheduleDelayFunctions = [...]string{"constant", "exponential", "fibonacci"}
// ReschedulePolicy configures how Tasks are rescheduled when they crash or fail.
type ReschedulePolicy struct {
@ -2866,7 +2866,7 @@ type ReschedulePolicy struct {
Delay time.Duration
// DelayFunction determines how the delay progressively changes on subsequent reschedule
// attempts. Valid values are "exponential", "linear", and "fibonacci".
// attempts. Valid values are "exponential", "constant", and "fibonacci".
DelayFunction string
// MaxDelay is an upper bound on the delay.
@ -2888,7 +2888,7 @@ func (r *ReschedulePolicy) Copy() *ReschedulePolicy {
// Validate uses different criteria to validate the reschedule policy
// Delay must be a minimum of 5 seconds
// Delay Ceiling is ignored if Delay Function is "linear"
// Delay Ceiling is ignored if Delay Function is "constant"
// Number of possible attempts is validated, given the interval, delay and delay function
func (r *ReschedulePolicy) Validate() error {
enabled := r != nil && (r.Attempts > 0 || r.Unlimited)
@ -2922,7 +2922,7 @@ func (r *ReschedulePolicy) Validate() error {
}
// Validate MaxDelay if not using linear delay progression
if r.DelayFunction != "linear" {
if r.DelayFunction != "constant" {
if r.MaxDelay.Nanoseconds() < ReschedulePolicyMinDelay.Nanoseconds() {
multierror.Append(&mErr, fmt.Errorf("Max Delay cannot be less than %v (got %v)", ReschedulePolicyMinDelay, r.Delay))
delayPreCheck = false
@ -2966,7 +2966,7 @@ func (r *ReschedulePolicy) validateDelayParams() error {
return nil
}
var mErr multierror.Error
if r.DelayFunction == "linear" {
if r.DelayFunction == "constant" {
multierror.Append(&mErr, fmt.Errorf("Nomad can only make %v attempts in %v with initial delay %v and "+
"delay function %q", possibleAttempts, r.Interval, r.Delay, r.DelayFunction))
} else {
@ -2982,7 +2982,7 @@ func (r *ReschedulePolicy) viableAttempts() (bool, int, time.Duration) {
var recommendedInterval time.Duration
valid := true
switch r.DelayFunction {
case "linear":
case "constant":
recommendedInterval = time.Duration(r.Attempts) * r.Delay
if r.Interval < recommendedInterval {
possibleAttempts = int(r.Interval / r.Delay)

View file

@ -233,7 +233,7 @@ func testJob() *Job {
Interval: 5 * time.Minute,
Attempts: 10,
Delay: 5 * time.Second,
DelayFunction: "linear",
DelayFunction: "constant",
},
Tasks: []*Task{
{
@ -678,7 +678,7 @@ func TestTaskGroup_Validate(t *testing.T) {
Interval: 5 * time.Minute,
Attempts: 10,
Delay: 5 * time.Second,
DelayFunction: "linear",
DelayFunction: "constant",
},
}
@ -2116,7 +2116,7 @@ func TestReschedulePolicy_Validate(t *testing.T) {
Attempts: 1,
Interval: 5 * time.Minute,
Delay: 10 * time.Second,
DelayFunction: "linear"},
DelayFunction: "constant"},
},
{
desc: "Valid Exponential Delay",
@ -2166,7 +2166,7 @@ func TestReschedulePolicy_Validate(t *testing.T) {
ReschedulePolicy: &ReschedulePolicy{
Attempts: 1,
Interval: 1 * time.Second,
DelayFunction: "linear"},
DelayFunction: "constant"},
errors: []error{
fmt.Errorf("Interval cannot be less than %v (got %v)", ReschedulePolicyMinInterval, time.Second),
fmt.Errorf("Delay cannot be less than %v (got %v)", ReschedulePolicyMinDelay, 0*time.Second),
@ -2178,11 +2178,11 @@ func TestReschedulePolicy_Validate(t *testing.T) {
Attempts: 10,
Interval: 1 * time.Hour,
Delay: 20 * time.Minute,
DelayFunction: "linear",
DelayFunction: "constant",
},
errors: []error{
fmt.Errorf("Nomad can only make %v attempts in %v with initial delay %v and"+
" delay function %q", 3, time.Hour, 20*time.Minute, "linear"),
" delay function %q", 3, time.Hour, 20*time.Minute, "constant"),
fmt.Errorf("Set the interval to at least %v to accommodate %v attempts",
200*time.Minute, 10),
},
@ -2708,7 +2708,7 @@ func TestAllocation_NextDelay(t *testing.T) {
{
desc: "Allocation hasn't failed yet",
reschedulePolicy: &ReschedulePolicy{
DelayFunction: "linear",
DelayFunction: "constant",
Delay: 5 * time.Second,
},
alloc: &Allocation{},
@ -2718,7 +2718,7 @@ func TestAllocation_NextDelay(t *testing.T) {
{
desc: "Allocation lacks task state",
reschedulePolicy: &ReschedulePolicy{
DelayFunction: "linear",
DelayFunction: "constant",
Delay: 5 * time.Second,
},
alloc: &Allocation{ClientStatus: AllocClientStatusFailed},
@ -2728,7 +2728,7 @@ func TestAllocation_NextDelay(t *testing.T) {
{
desc: "linear delay, unlimited restarts, no reschedule tracker",
reschedulePolicy: &ReschedulePolicy{
DelayFunction: "linear",
DelayFunction: "constant",
Delay: 5 * time.Second,
Unlimited: true,
},
@ -2744,7 +2744,7 @@ func TestAllocation_NextDelay(t *testing.T) {
{
desc: "linear delay with reschedule tracker",
reschedulePolicy: &ReschedulePolicy{
DelayFunction: "linear",
DelayFunction: "constant",
Delay: 5 * time.Second,
Interval: 10 * time.Minute,
Attempts: 2,
@ -2766,7 +2766,7 @@ func TestAllocation_NextDelay(t *testing.T) {
{
desc: "linear delay with reschedule tracker, attempts exhausted",
reschedulePolicy: &ReschedulePolicy{
DelayFunction: "linear",
DelayFunction: "constant",
Delay: 5 * time.Second,
Interval: 10 * time.Minute,
Attempts: 2,

View file

@ -2657,7 +2657,7 @@ func TestServiceSched_Reschedule_OnceNow(t *testing.T) {
Interval: 15 * time.Minute,
Delay: 5 * time.Second,
MaxDelay: 1 * time.Minute,
DelayFunction: "linear",
DelayFunction: "constant",
}
tgName := job.TaskGroups[0].Name
now := time.Now()
@ -2770,7 +2770,7 @@ func TestServiceSched_Reschedule_Later(t *testing.T) {
Interval: 15 * time.Minute,
Delay: delayDuration,
MaxDelay: 1 * time.Minute,
DelayFunction: "linear",
DelayFunction: "constant",
}
tgName := job.TaskGroups[0].Name
now := time.Now()
@ -2857,7 +2857,7 @@ func TestServiceSched_Reschedule_MultipleNow(t *testing.T) {
Attempts: maxRestartAttempts,
Interval: 30 * time.Minute,
Delay: 5 * time.Second,
DelayFunction: "linear",
DelayFunction: "constant",
}
tgName := job.TaskGroups[0].Name
now := time.Now()

View file

@ -1227,7 +1227,7 @@ func TestReconciler_RescheduleLater_Batch(t *testing.T) {
// Set up reschedule policy
delayDur := 15 * time.Second
job.TaskGroups[0].ReschedulePolicy = &structs.ReschedulePolicy{Attempts: 3, Interval: 24 * time.Hour, Delay: delayDur, DelayFunction: "linear"}
job.TaskGroups[0].ReschedulePolicy = &structs.ReschedulePolicy{Attempts: 3, Interval: 24 * time.Hour, Delay: delayDur, DelayFunction: "constant"}
tgName := job.TaskGroups[0].Name
// Create 6 existing allocations - 2 running, 1 complete and 3 failed
@ -1319,7 +1319,7 @@ func TestReconciler_RescheduleLaterWithBatchedEvals_Batch(t *testing.T) {
// Set up reschedule policy
delayDur := 15 * time.Second
job.TaskGroups[0].ReschedulePolicy = &structs.ReschedulePolicy{Attempts: 3, Interval: 24 * time.Hour, Delay: delayDur, DelayFunction: "linear"}
job.TaskGroups[0].ReschedulePolicy = &structs.ReschedulePolicy{Attempts: 3, Interval: 24 * time.Hour, Delay: delayDur, DelayFunction: "constant"}
tgName := job.TaskGroups[0].Name
// Create 10 existing allocations
@ -1401,7 +1401,7 @@ func TestReconciler_RescheduleNow_Batch(t *testing.T) {
job.TaskGroups[0].Count = 4
now := time.Now()
// Set up reschedule policy
job.TaskGroups[0].ReschedulePolicy = &structs.ReschedulePolicy{Attempts: 3, Interval: 24 * time.Hour, Delay: 5 * time.Second, DelayFunction: "linear"}
job.TaskGroups[0].ReschedulePolicy = &structs.ReschedulePolicy{Attempts: 3, Interval: 24 * time.Hour, Delay: 5 * time.Second, DelayFunction: "constant"}
tgName := job.TaskGroups[0].Name
// Create 6 existing allocations - 2 running, 1 complete and 3 failed
var allocs []*structs.Allocation