Skip to content
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

Merged
merged 14 commits into from
May 21, 2018

Conversation

preetapan
Copy link
Member

This PR changes the /job//evaluate end point to support specifying a json payload EvalOptions. Setting ForceReschedule 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 run nomad job eval -force-reschedule

@preetapan preetapan requested a review from dadgar May 9, 2018 21:06
@preetapan
Copy link
Member Author

preetapan commented May 9, 2018

@dadgar Documentation updates aren't in this PR yet, coming in a future commit
Docs committed in 2d0e273 and b5e18b6

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth renaming to EvaluateWithOpts?

Copy link
Member Author

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.

Copy link
Contributor

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

JobID: jobName,
var args structs.JobEvaluateRequest

// TODO(preetha) remove in 0.9
Copy link
Contributor

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

helpText := `
Usage: nomad job eval [options] <job_id>

Force an evaluation of the provided job id
Copy link
Contributor

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.

Eval Options:

-force-reschedule
Force reschedule any failed allocations even if they are not currently
Copy link
Contributor

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.

}

func (c *JobEvalCommand) Synopsis() string {
return "Force evaluating a job using its job id"
Copy link
Contributor

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

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() {
Copy link
Contributor

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

- `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
Copy link
Contributor

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

### Sample Request

```text
$ curl \
--request POST \
-d@sample.json \
Copy link
Contributor

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>
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment on any

})
}

func (c *JobEvalCommand) Name() string { return "eval" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return "job eval"

@preetapan
Copy link
Member Author

preetapan commented May 10, 2018

@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) {
Copy link
Contributor

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

-force-reschedule
Force reschedule failed allocations even if they are not currently
eligible for rescheduling.
-detach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line above

}

func (c *JobEvalCommand) Synopsis() string {
return "Force an evaluation for the job using its job ID"
Copy link
Contributor

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"

Force reschedule failed allocations even if they are not currently
eligible for rescheduling.
-detach
Return immediately instead of entering monitor mode. After deployment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After deployment resume?

c.Ui.Error(fmt.Sprintf("Error evaluating job: %s", err))
return 1
}
c.Ui.Output(fmt.Sprintf("Created eval ID: %q ", limit(evalId, length)))
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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"
Copy link
Contributor

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

@preetapan preetapan merged commit 447527a into master May 21, 2018
@preetapan preetapan deleted the f-force-rescheduling branch May 21, 2018 23:26
JobID: jobName,
var args structs.JobEvaluateRequest

// TODO(preetha): remove in 0.9
Copy link
Contributor

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 :)

@github-actions
Copy link

github-actions bot commented Mar 4, 2023

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants