-
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
Preemption for system jobs #4794
Changes from 36 commits
5f27e00
8004160
bf7192c
fc266f7
715d869
b5cbd73
13e314c
fd6bff2
51c5bae
784b96c
2143fa2
6966e3c
24b3934
9f35923
a960cce
655689a
c4e0e66
c3b8e4f
12af2ae
c4a04eb
191b862
21432d6
4cc21fb
35635ba
8800585
17344a7
f2b0277
22d156f
993b6a2
3ad7b3f
06ad182
35d31f8
b3738a0
0015095
8235919
1380acb
c49a3e2
97cf4e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,3 +208,73 @@ func (s *HTTPServer) OperatorServerHealth(resp http.ResponseWriter, req *http.Re | |
|
||
return out, nil | ||
} | ||
|
||
// OperatorSchedulerConfiguration is used to inspect the current Scheduler configuration. | ||
// This supports the stale query mode in case the cluster doesn't have a leader. | ||
func (s *HTTPServer) OperatorSchedulerConfiguration(resp http.ResponseWriter, req *http.Request) (interface{}, error) { | ||
// Switch on the method | ||
switch req.Method { | ||
case "GET": | ||
var args structs.GenericRequest | ||
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. Generally split the methods up so that it only handles one type of HTTP verb: https://github.com/hashicorp/nomad/blob/master/command/agent/job_endpoint.go#L15 |
||
if done := s.parse(resp, req, &args.Region, &args.QueryOptions); done { | ||
return nil, nil | ||
} | ||
|
||
var reply structs.SchedulerConfigurationResponse | ||
if err := s.agent.RPC("Operator.SchedulerGetConfiguration", &args, &reply); err != nil { | ||
return nil, err | ||
} | ||
|
||
out := api.SchedulerConfiguration{ | ||
PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: reply.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled}, | ||
CreateIndex: reply.CreateIndex, | ||
ModifyIndex: reply.ModifyIndex, | ||
} | ||
|
||
resp := api.SchedulerConfigurationResponse{ | ||
SchedulerConfig: out, | ||
CreateIndex: out.CreateIndex, | ||
ModifyIndex: out.ModifyIndex, | ||
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. |
||
} | ||
|
||
return resp, nil | ||
|
||
case "PUT": | ||
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. We accept POST and PUT |
||
var args structs.SchedulerSetConfigRequest | ||
s.parseWriteRequest(req, &args.WriteRequest) | ||
|
||
var conf api.SchedulerConfiguration | ||
if err := decodeBody(req, &conf); err != nil { | ||
return nil, CodedError(http.StatusBadRequest, fmt.Sprintf("Error parsing scheduler config: %v", err)) | ||
} | ||
|
||
args.Config = structs.SchedulerConfiguration{ | ||
PreemptionConfig: structs.PreemptionConfig{SystemSchedulerEnabled: conf.PreemptionConfig.SystemSchedulerEnabled}, | ||
} | ||
|
||
// Check for cas value | ||
params := req.URL.Query() | ||
if _, ok := params["cas"]; ok { | ||
casVal, err := strconv.ParseUint(params.Get("cas"), 10, 64) | ||
if err != nil { | ||
return nil, CodedError(http.StatusBadRequest, fmt.Sprintf("Error parsing cas value: %v", err)) | ||
} | ||
args.Config.ModifyIndex = casVal | ||
args.CAS = true | ||
} | ||
|
||
var reply bool | ||
if err := s.agent.RPC("Operator.SchedulerSetConfiguration", &args, &reply); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Only use the out value if this was a CAS | ||
if !args.CAS { | ||
return true, nil | ||
} | ||
return reply, nil | ||
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. |
||
|
||
default: | ||
return nil, CodedError(404, ErrInvalidMethod) | ||
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. 404 -> 405 |
||
} | ||
} |
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.
Should be WriteMeta and QueryMeta: https://github.com/hashicorp/nomad/blob/master/api/jobs.go#L1039-L1046