1
0
mirror of https://github.com/newnius/YAO-scheduler.git synced 2025-06-06 05:51:54 +00:00

update api iterface

This commit is contained in:
Newnius 2020-07-11 14:04:20 +08:00
parent 71ab7bbb75
commit 7d33c85a1a
10 changed files with 106 additions and 152 deletions

View File

@ -31,9 +31,12 @@ func (allocator *Allocator) init(conf Configuration) {
}
func (allocator *Allocator) updateStrategy(strategy string) bool {
allocator.allocationStrategy = strategy
log.Info("Allocator strategy switched to ", strategy)
return true
if strategy == "bestfit" || strategy == "ga" || strategy == "mixed" {
allocator.allocationStrategy = strategy
log.Info("Allocator strategy switched to ", strategy)
return true
}
return false
}
func (allocator *Allocator) allocate(nodes []NodeStatus, tasks []Task) Allocation {

View File

@ -117,19 +117,11 @@ func InstanceOfConfiguration() *Configuration {
return configurationInstance
}
func (config *Configuration) EnableMock() bool {
func (config *Configuration) SetMockEnabled(enabled bool) bool {
config.mu.Lock()
defer config.mu.Unlock()
config.mock = true
log.Info("configuration.mock = true")
return true
}
func (config *Configuration) DisableMock() bool {
config.mu.Lock()
defer config.mu.Unlock()
config.mock = false
log.Info("configuration.mock = false")
config.mock = enabled
log.Info("configuration.mock = ", enabled)
return true
}

View File

@ -250,20 +250,6 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
w.Write(js)
break
case "debug_enable":
log.Debug("enable schedule")
js, _ := json.Marshal(scheduler.Enable())
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "debug_disable":
log.Debug("disable schedule")
js, _ := json.Marshal(scheduler.Disable())
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "debug_scheduler_dump":
log.Debug("debug_scheduler_dump")
js, _ := json.Marshal(scheduler.DebugDump())
@ -271,67 +257,6 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
w.Write(js)
break
case "debug_update_parallelism":
log.Debug("update_parallelism")
parallelism, _ := strconv.Atoi(r.URL.Query().Get("parallelism"))
js, _ := json.Marshal(scheduler.UpdateParallelism(parallelism))
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "debug_update_enable_share_ratio":
log.Debug("debug_update_enable_share_ratio")
ratio := 0.75
if t, err := strconv.ParseFloat(r.URL.Query().Get("ratio"), 32); err == nil {
ratio = t
}
js, _ := json.Marshal(InstanceOfConfiguration().SetShareRatio(ratio))
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "debug_update_enable_pre_schedule_ratio":
log.Debug("debug_update_enable_pre_schedule_ratio")
ratio := 0.95
if t, err := strconv.ParseFloat(r.URL.Query().Get("ratio"), 32); err == nil {
ratio = t
}
js, _ := json.Marshal(InstanceOfConfiguration().SetPreScheduleRatio(ratio))
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "allocator_update_strategy":
log.Debug("allocator_update_strategy")
strategy := r.URL.Query().Get("strategy")
js, _ := json.Marshal(InstanceOfAllocator().updateStrategy(strategy))
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "pool_enable_batch":
log.Debug("pool_enable_batch")
js, _ := json.Marshal(InstanceOfResourcePool().EnableBatch())
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "pool_disable_batch":
log.Debug("pool_disable_batch")
js, _ := json.Marshal(InstanceOfResourcePool().DisableBatch())
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "pool_set_batch_interval":
log.Debug("pool_set_batch_interval")
interval := str2int(r.URL.Query().Get("interval"), 1)
js, _ := json.Marshal(InstanceOfResourcePool().SetBatchInterval(interval))
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "debug_pool_dump":
log.Debug("debug_pool_dump")
js, _ := json.Marshal(InstanceOfResourcePool().Dump())
@ -339,31 +264,82 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
w.Write(js)
break
case "debug_enable_mock":
log.Debug("debug_enable_mock")
js, _ := json.Marshal(InstanceOfConfiguration().EnableMock())
case "conf_list":
log.Debug("conf_list")
var msg MsgConfList
msg.Code = 0
msg.Options = InstanceOfConfiguration().Dump()
js, _ := json.Marshal(msg)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "debug_disable_mock":
log.Debug("debug_disable_mock")
js, _ := json.Marshal(InstanceOfConfiguration().DisableMock())
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "conf_update":
log.Debug("conf_update")
option := r.URL.Query().Get("option")
value := r.URL.Query().Get("value")
ok := false
switch option {
/* pool.share */
case "pool.share.enable_threshold":
if threshold, err := strconv.ParseFloat(value, 32); err == nil {
ok = InstanceOfConfiguration().SetShareRatio(threshold)
}
break
case "debug_conf_dump":
log.Debug("debug_conf_dump")
js, _ := json.Marshal(InstanceOfConfiguration().Dump())
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "pool.share.max_utilization":
util, err := strconv.ParseFloat(value, 32)
if err == nil {
ok = InstanceOfConfiguration().SetShareMaxUtilization(util)
}
break
case "conf_set_share_max_utilization":
log.Debug("conf_set_share_max_utilization")
util, _ := strconv.ParseFloat(r.URL.Query().Get("util"), 32)
js, _ := json.Marshal(InstanceOfConfiguration().SetShareMaxUtilization(util))
/* pool.pre_schedule */
case "pool.pre_schedule.enable_threshold":
if threshold, err := strconv.ParseFloat(value, 32); err == nil {
ok = InstanceOfConfiguration().SetPreScheduleRatio(threshold)
}
break
/* pool.batch */
case "pool.batch.enabled":
ok = InstanceOfResourcePool().SetBatchEnabled(value == "true")
break
case "pool.batch.interval":
interval := str2int(value, 1)
ok = InstanceOfResourcePool().SetBatchInterval(interval)
break
/* scheduler.mock */
case "scheduler.mock.enabled":
ok = InstanceOfConfiguration().SetMockEnabled(value == "true")
break
/* scheduler.enabled */
case "scheduler.enabled":
ok = scheduler.SetEnabled(value == "true")
break
/* scheduler.parallelism */
case "scheduler.parallelism":
parallelism, _ := strconv.Atoi(value)
ok = scheduler.UpdateParallelism(parallelism)
break
/* allocator.strategy */
case "allocator.strategy":
ok = InstanceOfAllocator().updateStrategy(value)
break
}
var msg MsgConfUpdate
msg.Code = 0
if !ok {
msg.Code = 1
msg.Error = "Option not exist or invalid value"
}
js, _ := json.Marshal(msg)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break

View File

@ -103,3 +103,14 @@ type MsgJobReqPredict struct {
Error string `json:"error"`
Labels map[string]float64 `json:"labels"`
}
type MsgConfUpdate struct {
Code int `json:"code"`
Error string `json:"error"`
}
type MsgConfList struct {
Code int `json:"code"`
Error string `json:"error"`
Options map[string]interface{} `json:"options"`
}

View File

@ -1073,15 +1073,9 @@ func (pool *ResourcePool) releaseResource(job Job, agent NodeStatus) {
}
}
func (pool *ResourcePool) EnableBatch() bool {
pool.enableBatch = true
log.Info("enableBatch is set to true")
return true
}
func (pool *ResourcePool) DisableBatch() bool {
pool.enableBatch = false
log.Info("enableBatch is set to false")
func (pool *ResourcePool) SetBatchEnabled(enabled bool) bool {
pool.enableBatch = enabled
log.Info("enableBatch is set to ", enabled)
return true
}

View File

@ -21,9 +21,7 @@ type Scheduler interface {
Summary() MsgSummary
Enable() bool
Disable() bool
SetEnabled(enabled bool) bool
UpdateParallelism(parallelism int) bool

View File

@ -167,13 +167,9 @@ func (scheduler *SchedulerFCFS) Summary() MsgSummary {
return summary
}
func (scheduler *SchedulerFCFS) Enable() bool {
scheduler.enabled = true
return true
}
func (scheduler *SchedulerFCFS) Disable() bool {
scheduler.enabled = false
func (scheduler *SchedulerFCFS) SetEnabled(enabled bool) bool {
scheduler.enabled = enabled
log.Info("scheduler is set to ", enabled)
return true
}

View File

@ -381,15 +381,9 @@ func (scheduler *SchedulerCapacity) UpdateNextQueue() {
log.Debug("updateNextQueue ->", next)
}
func (scheduler *SchedulerCapacity) Enable() bool {
scheduler.enabled = true
log.Info("scheduler is enabled ", time.Now())
return true
}
func (scheduler *SchedulerCapacity) Disable() bool {
scheduler.enabled = false
log.Info("scheduler is disabled ", time.Now())
func (scheduler *SchedulerCapacity) SetEnabled(enabled bool) bool {
scheduler.enabled = enabled
log.Info("scheduler is set to ", enabled)
return true
}

View File

@ -796,15 +796,9 @@ func (scheduler *SchedulerFair) Summary() MsgSummary {
return summary
}
func (scheduler *SchedulerFair) Enable() bool {
scheduler.enabled = true
log.Info("scheduler is enabled ", time.Now())
return true
}
func (scheduler *SchedulerFair) Disable() bool {
scheduler.enabled = false
log.Info("scheduler is disabled ", time.Now())
func (scheduler *SchedulerFair) SetEnabled(enabled bool) bool {
scheduler.enabled = enabled
log.Info("scheduler is set to ", enabled)
return true
}

View File

@ -311,13 +311,9 @@ func (scheduler *SchedulerPriority) Summary() MsgSummary {
return summary
}
func (scheduler *SchedulerPriority) Enable() bool {
scheduler.enabled = true
return true
}
func (scheduler *SchedulerPriority) Disable() bool {
scheduler.enabled = false
func (scheduler *SchedulerPriority) SetEnabled(enabled bool) bool {
scheduler.enabled = enabled
log.Info("scheduler is set to ", enabled)
return true
}