-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CLI and API support for forcing rescheduling of failed allocs #4274
Conversation
api/jobs.go
Outdated
@@ -224,9 +224,14 @@ func (j *Jobs) Deregister(jobID string, purge bool, q *WriteOptions) (string, *W | |||
} | |||
|
|||
// ForceEvaluate is used to force-evaluate an existing job. | |||
func (j *Jobs) ForceEvaluate(jobID string, q *WriteOptions) (string, *WriteMeta, error) { | |||
func (j *Jobs) ForceEvaluate(jobID string, opts EvalOptions, q *WriteOptions) (string, *WriteMeta, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth renaming to EvaluateWithOpts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modeled this after JobDeregisterOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the name of the function. Since it can be more than just force given it takes a generic options object
command/agent/job_endpoint.go
Outdated
JobID: jobName, | ||
var args structs.JobEvaluateRequest | ||
|
||
// TODO(preetha) remove in 0.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the COMPAT tag so we can grep our code base
command/job_eval.go
Outdated
helpText := ` | ||
Usage: nomad job eval [options] <job_id> | ||
|
||
Force an evaluation of the provided job id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...provided job ID. Forcing an evaluation will trigger the scheduler to re-evaluate the job. The force flags allow operators to force the scheduler to create new allocations under certain scenarios.
command/job_eval.go
Outdated
Eval Options: | ||
|
||
-force-reschedule | ||
Force reschedule any failed allocations even if they are not currently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove any and and add a period to then end.
command/job_eval.go
Outdated
} | ||
|
||
func (c *JobEvalCommand) Synopsis() string { | ||
return "Force evaluating a job using its job id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force an evaluation for the job
nomad/job_endpoint.go
Outdated
for _, alloc := range allocs { | ||
taskGroup := job.LookupTaskGroup(alloc.TaskGroup) | ||
// Forcing rescheduling is only allowed if task group has rescheduling enabled | ||
if taskGroup == nil || taskGroup.ReschedulePolicy == nil || !taskGroup.ReschedulePolicy.Enabled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we remove taskGroup.ReschedulePolicy == nil
given that Enabled()
handles the nil case
website/source/api/jobs.html.md
Outdated
- `JobID` `(string: <required>)` - Specify the ID of the job in the JSON payload | ||
|
||
- `EvalOptions` `(<optional>)` - Specify additional options to be used during the forced evaluation. | ||
- `ForceReschedule` `(bool: false)` - If set, any failed allocations of the job are rescheduled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove any�. For me it gives the connotation that all failed evals will be rescheduler but really we mean any failed alloc that doesn't already have a replacement
website/source/api/jobs.html.md
Outdated
### Sample Request | ||
|
||
```text | ||
$ curl \ | ||
--request POST \ | ||
[email protected] \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a space between -d
and @sample.json
## Usage | ||
|
||
``` | ||
nomad job eval [options] <jobID> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
job_id
|
||
## Eval Options | ||
|
||
* `-force-reschedule`: `force-reschedule` is used to force placement of any failed allocations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment on any
command/job_eval.go
Outdated
}) | ||
} | ||
|
||
func (c *JobEvalCommand) Name() string { return "eval" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "job eval"
@dadgar @nickethier ive addressed all the review comments, this is ready for another look |
api/jobs.go
Outdated
@@ -224,9 +224,14 @@ func (j *Jobs) Deregister(jobID string, purge bool, q *WriteOptions) (string, *W | |||
} | |||
|
|||
// ForceEvaluate is used to force-evaluate an existing job. | |||
func (j *Jobs) ForceEvaluate(jobID string, q *WriteOptions) (string, *WriteMeta, error) { | |||
func (j *Jobs) ForceEvaluate(jobID string, opts EvalOptions, q *WriteOptions) (string, *WriteMeta, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the name of the function. Since it can be more than just force given it takes a generic options object
command/job_eval.go
Outdated
-force-reschedule | ||
Force reschedule failed allocations even if they are not currently | ||
eligible for rescheduling. | ||
-detach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line above
command/job_eval.go
Outdated
} | ||
|
||
func (c *JobEvalCommand) Synopsis() string { | ||
return "Force an evaluation for the job using its job ID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove " using its job ID"
command/job_eval.go
Outdated
Force reschedule failed allocations even if they are not currently | ||
eligible for rescheduling. | ||
-detach | ||
Return immediately instead of entering monitor mode. After deployment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After deployment resume?
command/job_eval.go
Outdated
c.Ui.Error(fmt.Sprintf("Error evaluating job: %s", err)) | ||
return 1 | ||
} | ||
c.Ui.Output(fmt.Sprintf("Created eval ID: %q ", limit(evalId, length))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the detach if
|
||
## Eval Options | ||
|
||
* `-force-reschedule`: `force-reschedule` is used to force placement of failed allocations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the detach and verbose flag
api/jobs.go
Outdated
@@ -233,6 +233,21 @@ func (j *Jobs) ForceEvaluate(jobID string, q *WriteOptions) (string, *WriteMeta, | |||
return resp.EvalID, wm, nil | |||
} | |||
|
|||
// ForceEvaluate is used to force-evaluate an existing job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong method name in doc
|
||
``` | ||
$ nomad job eval job1 | ||
Created eval ID: "6754c2e3-9abb-e7e9-dc92-76aab01751c8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update b/c of the new monitoring
JobID: jobName, | ||
var args structs.JobEvaluateRequest | ||
|
||
// TODO(preetha): remove in 0.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.10? i guess this code will go out in 0.9 :)
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
This PR changes the /job//evaluate end point to support specifying a json payload
EvalOptions
. SettingForceReschedule
to true will reschedule any failed allocs irrespective of their reschedule eligibility at the time of calling the endpoint.If the job does not have rescheduling enabled, setting
ForceReschedule
is a no-op.Also added a new CLI
nomad job eval <jobid>
to allow operators to easily force an evaluation without needing to run/register the job with full job hcl. To force an evaluation from the CLI, operators can runnomad job eval -force-reschedule