Add SchedulerAlgorithm to SchedulerConfig

This commit is contained in:
Charlie Voiselle 2020-04-03 19:03:14 -04:00 committed by Mahmood Ali
parent 2b8fc650c9
commit 663fb677cf
4 changed files with 46 additions and 0 deletions

View File

@ -112,7 +112,11 @@ func (op *Operator) RaftRemovePeerByID(id string, q *WriteOptions) error {
return nil
}
// SchedulerConfiguration is the config for controlling scheduler behavior
type SchedulerConfiguration struct {
// SchedulerAlgorithm lets you select between available scheduling algorithms.
SchedulerAlgorithm string
// PreemptionConfig specifies whether to enable eviction of lower
// priority jobs to place higher priority jobs.
PreemptionConfig PreemptionConfig
@ -140,6 +144,11 @@ type SchedulerSetConfigurationResponse struct {
WriteMeta
}
// SchedulerAlgorithm is an enum string that encapsulates the valid options for a
// SchedulerConfiguration stanza's SchedulerAlgorithm. These modes will allow the
// scheduler to be user-selectable.
type SchedulerAlgorithm string
// PreemptionConfig specifies whether preemption is enabled based on scheduler type
type PreemptionConfig struct {
SystemSchedulerEnabled bool

View File

@ -14,6 +14,8 @@ import (
"github.com/hashicorp/raft"
)
// OperatorRequest is used route operator/raft API requests to the implementing
// functions.
func (s *HTTPServer) OperatorRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
path := strings.TrimPrefix(req.URL.Path, "/v1/operator/raft/")
switch {
@ -251,7 +253,12 @@ func (s *HTTPServer) schedulerUpdateConfig(resp http.ResponseWriter, req *http.R
return nil, CodedError(http.StatusBadRequest, fmt.Sprintf("Error parsing scheduler config: %v", err))
}
if !structs.SchedulerAlgorithmIsValid(conf.SchedulerAlgorithm) {
return nil, CodedError(http.StatusBadRequest, fmt.Sprintf("Invalid scheduler algorithm selected."))
}
args.Config = structs.SchedulerConfiguration{
SchedulerAlgorithm: conf.SchedulerAlgorithm,
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: conf.PreemptionConfig.SystemSchedulerEnabled,
BatchSchedulerEnabled: conf.PreemptionConfig.BatchSchedulerEnabled,

View File

@ -403,6 +403,7 @@ func DefaultConfig() *Config {
ServerHealthInterval: 2 * time.Second,
AutopilotInterval: 10 * time.Second,
DefaultSchedulerConfig: structs.SchedulerConfiguration{
SchedulerAlgorithm: structs.SchedulerAlgorithmBinpack,
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: true,
BatchSchedulerEnabled: false,

View File

@ -124,8 +124,37 @@ type AutopilotConfig struct {
ModifyIndex uint64
}
// SchedulerAlgorithm is an enum string that encapsulates the valid options for a
// SchedulerConfiguration stanza's SchedulerAlgorithm. These modes will allow the
// scheduler to be user-selectable.
type SchedulerAlgorithm string
const (
// SchedulerAlgorithmBinpack indicates that the scheduler should spread
// allocations as evenly as possible over the available hardware.
SchedulerAlgorithmBinpack string = "binpack"
// SchedulerAlgorithmSpread indicates that the scheduler should spread
// allocations as evenly as possible over the available hardware.
SchedulerAlgorithmSpread string = "spread"
)
// SchedulerAlgorithmIsValid validates the given SchedulerAlgorithm string and
// returns true only when a correct algorithm is specified.
func SchedulerAlgorithmIsValid(alg string) bool {
switch alg {
case SchedulerAlgorithmBinpack, SchedulerAlgorithmSpread:
return true
default:
return false
}
}
// SchedulerConfiguration is the config for controlling scheduler behavior
type SchedulerConfiguration struct {
// SchedulerAlgorithm lets you select between available scheduling algorithms.
SchedulerAlgorithm string `hcl:"scheduler_algorithm"`
// PreemptionConfig specifies whether to enable eviction of lower
// priority jobs to place higher priority jobs.
PreemptionConfig PreemptionConfig `hcl:"preemption_config"`