-
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
Job revert #2575
Merged
Merged
Job revert #2575
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b8b18db
Structs
dadgar daeabb9
Revert server endpoint
dadgar 99e9f2a
Agent revert
dadgar 6a9af5a
Agent test
dadgar c818602
Don't allow revert to current version
dadgar 694d9c4
Revert api
dadgar e0af3d7
docs
dadgar 8d01a4b
Swap validation checks
dadgar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,8 +286,8 @@ func (j *Job) Summary(args *structs.JobSummaryRequest, | |
} | ||
|
||
// Validate validates a job | ||
func (j *Job) Validate(args *structs.JobValidateRequest, | ||
reply *structs.JobValidateResponse) error { | ||
func (j *Job) Validate(args *structs.JobValidateRequest, reply *structs.JobValidateResponse) error { | ||
defer metrics.MeasureSince([]string{"nomad", "job", "validate"}, time.Now()) | ||
|
||
if err := validateJob(args.Job); err != nil { | ||
if merr, ok := err.(*multierror.Error); ok { | ||
|
@@ -300,10 +300,69 @@ func (j *Job) Validate(args *structs.JobValidateRequest, | |
reply.Error = err.Error() | ||
} | ||
} | ||
|
||
reply.DriverConfigValidated = true | ||
return nil | ||
} | ||
|
||
// Revert is used to revert the job to a prior version | ||
func (j *Job) Revert(args *structs.JobRevertRequest, reply *structs.JobRegisterResponse) error { | ||
if done, err := j.srv.forward("Job.Revert", args, args, reply); done { | ||
return err | ||
} | ||
defer metrics.MeasureSince([]string{"nomad", "job", "revert"}, time.Now()) | ||
|
||
// Validate the arguments | ||
if args.JobID == "" { | ||
return fmt.Errorf("missing job ID for evaluation") | ||
} | ||
|
||
// Lookup the job by version | ||
snap, err := j.srv.fsm.State().Snapshot() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ws := memdb.NewWatchSet() | ||
cur, err := snap.JobByID(ws, args.JobID) | ||
if err != nil { | ||
return err | ||
} | ||
if cur == nil { | ||
return fmt.Errorf("job %q not found", args.JobID) | ||
} | ||
if args.JobVersion == cur.Version { | ||
return fmt.Errorf("can't revert to current version") | ||
} | ||
|
||
jobV, err := snap.JobByIDAndVersion(ws, args.JobID, args.JobVersion) | ||
if err != nil { | ||
return err | ||
} | ||
if jobV == nil { | ||
return fmt.Errorf("job %q at version %d not found", args.JobID, args.JobVersion) | ||
} | ||
|
||
// Build the register request | ||
reg := &structs.JobRegisterRequest{ | ||
Job: jobV.Copy(), | ||
WriteRequest: args.WriteRequest, | ||
} | ||
|
||
// If the request is enforcing the existing version do a check. | ||
if args.EnforcePriorVersion != nil { | ||
if cur.Version != *args.EnforcePriorVersion { | ||
return fmt.Errorf("Current job has version %d; enforcing version %d", cur.Version, *args.EnforcePriorVersion) | ||
} | ||
|
||
reg.EnforceIndex = true | ||
reg.JobModifyIndex = cur.JobModifyIndex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modify index will get overwritten at Upsert time right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those two are the way to do the CAS operation on the register |
||
} | ||
|
||
// Register the version. | ||
return j.Register(reg, reply) | ||
} | ||
|
||
// Evaluate is used to force a job for re-evaluation | ||
func (j *Job) Evaluate(args *structs.JobEvaluateRequest, reply *structs.JobRegisterResponse) error { | ||
if done, err := j.srv.forward("Job.Evaluate", args, args, reply); done { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is racy, and probably should be evaluated inside the FSM. Effectively this is a check-and-set, but multiple concurrent calls to this API will be allowed to make progress depending on the timing.
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.
Yeah I realized that when implementing this. The register endpoint should push the logic from the RPC layer down into the FSM. This will fix this issue for both this and the register. Just out of scope for this PR. I will put a comment on that part of the code though