mirror of
https://github.com/newnius/YAO-scheduler.git
synced 2025-06-07 14:21:55 +00:00
update api iterface
This commit is contained in:
parent
71ab7bbb75
commit
7d33c85a1a
@ -31,10 +31,13 @@ func (allocator *Allocator) init(conf Configuration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (allocator *Allocator) updateStrategy(strategy string) bool {
|
func (allocator *Allocator) updateStrategy(strategy string) bool {
|
||||||
|
if strategy == "bestfit" || strategy == "ga" || strategy == "mixed" {
|
||||||
allocator.allocationStrategy = strategy
|
allocator.allocationStrategy = strategy
|
||||||
log.Info("Allocator strategy switched to ", strategy)
|
log.Info("Allocator strategy switched to ", strategy)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (allocator *Allocator) allocate(nodes []NodeStatus, tasks []Task) Allocation {
|
func (allocator *Allocator) allocate(nodes []NodeStatus, tasks []Task) Allocation {
|
||||||
//log.Info(nodes)
|
//log.Info(nodes)
|
||||||
|
@ -117,19 +117,11 @@ func InstanceOfConfiguration() *Configuration {
|
|||||||
return configurationInstance
|
return configurationInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Configuration) EnableMock() bool {
|
func (config *Configuration) SetMockEnabled(enabled bool) bool {
|
||||||
config.mu.Lock()
|
config.mu.Lock()
|
||||||
defer config.mu.Unlock()
|
defer config.mu.Unlock()
|
||||||
config.mock = true
|
config.mock = enabled
|
||||||
log.Info("configuration.mock = true")
|
log.Info("configuration.mock = ", enabled)
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *Configuration) DisableMock() bool {
|
|
||||||
config.mu.Lock()
|
|
||||||
defer config.mu.Unlock()
|
|
||||||
config.mock = false
|
|
||||||
log.Info("configuration.mock = false")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
160
src/main.go
160
src/main.go
@ -250,20 +250,6 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
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":
|
case "debug_scheduler_dump":
|
||||||
log.Debug("debug_scheduler_dump")
|
log.Debug("debug_scheduler_dump")
|
||||||
js, _ := json.Marshal(scheduler.DebugDump())
|
js, _ := json.Marshal(scheduler.DebugDump())
|
||||||
@ -271,67 +257,6 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
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":
|
case "debug_pool_dump":
|
||||||
log.Debug("debug_pool_dump")
|
log.Debug("debug_pool_dump")
|
||||||
js, _ := json.Marshal(InstanceOfResourcePool().Dump())
|
js, _ := json.Marshal(InstanceOfResourcePool().Dump())
|
||||||
@ -339,31 +264,82 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "debug_enable_mock":
|
case "conf_list":
|
||||||
log.Debug("debug_enable_mock")
|
log.Debug("conf_list")
|
||||||
js, _ := json.Marshal(InstanceOfConfiguration().EnableMock())
|
var msg MsgConfList
|
||||||
|
msg.Code = 0
|
||||||
|
msg.Options = InstanceOfConfiguration().Dump()
|
||||||
|
js, _ := json.Marshal(msg)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "debug_disable_mock":
|
case "conf_update":
|
||||||
log.Debug("debug_disable_mock")
|
log.Debug("conf_update")
|
||||||
js, _ := json.Marshal(InstanceOfConfiguration().DisableMock())
|
option := r.URL.Query().Get("option")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
value := r.URL.Query().Get("value")
|
||||||
w.Write(js)
|
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
|
break
|
||||||
|
|
||||||
case "debug_conf_dump":
|
case "pool.share.max_utilization":
|
||||||
log.Debug("debug_conf_dump")
|
util, err := strconv.ParseFloat(value, 32)
|
||||||
js, _ := json.Marshal(InstanceOfConfiguration().Dump())
|
if err == nil {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
ok = InstanceOfConfiguration().SetShareMaxUtilization(util)
|
||||||
w.Write(js)
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case "conf_set_share_max_utilization":
|
/* pool.pre_schedule */
|
||||||
log.Debug("conf_set_share_max_utilization")
|
case "pool.pre_schedule.enable_threshold":
|
||||||
util, _ := strconv.ParseFloat(r.URL.Query().Get("util"), 32)
|
if threshold, err := strconv.ParseFloat(value, 32); err == nil {
|
||||||
js, _ := json.Marshal(InstanceOfConfiguration().SetShareMaxUtilization(util))
|
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.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
@ -103,3 +103,14 @@ type MsgJobReqPredict struct {
|
|||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
Labels map[string]float64 `json:"labels"`
|
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"`
|
||||||
|
}
|
||||||
|
@ -1073,15 +1073,9 @@ func (pool *ResourcePool) releaseResource(job Job, agent NodeStatus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pool *ResourcePool) EnableBatch() bool {
|
func (pool *ResourcePool) SetBatchEnabled(enabled bool) bool {
|
||||||
pool.enableBatch = true
|
pool.enableBatch = enabled
|
||||||
log.Info("enableBatch is set to true")
|
log.Info("enableBatch is set to ", enabled)
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pool *ResourcePool) DisableBatch() bool {
|
|
||||||
pool.enableBatch = false
|
|
||||||
log.Info("enableBatch is set to false")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,7 @@ type Scheduler interface {
|
|||||||
|
|
||||||
Summary() MsgSummary
|
Summary() MsgSummary
|
||||||
|
|
||||||
Enable() bool
|
SetEnabled(enabled bool) bool
|
||||||
|
|
||||||
Disable() bool
|
|
||||||
|
|
||||||
UpdateParallelism(parallelism int) bool
|
UpdateParallelism(parallelism int) bool
|
||||||
|
|
||||||
|
@ -167,13 +167,9 @@ func (scheduler *SchedulerFCFS) Summary() MsgSummary {
|
|||||||
return summary
|
return summary
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scheduler *SchedulerFCFS) Enable() bool {
|
func (scheduler *SchedulerFCFS) SetEnabled(enabled bool) bool {
|
||||||
scheduler.enabled = true
|
scheduler.enabled = enabled
|
||||||
return true
|
log.Info("scheduler is set to ", enabled)
|
||||||
}
|
|
||||||
|
|
||||||
func (scheduler *SchedulerFCFS) Disable() bool {
|
|
||||||
scheduler.enabled = false
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,15 +381,9 @@ func (scheduler *SchedulerCapacity) UpdateNextQueue() {
|
|||||||
log.Debug("updateNextQueue ->", next)
|
log.Debug("updateNextQueue ->", next)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scheduler *SchedulerCapacity) Enable() bool {
|
func (scheduler *SchedulerCapacity) SetEnabled(enabled bool) bool {
|
||||||
scheduler.enabled = true
|
scheduler.enabled = enabled
|
||||||
log.Info("scheduler is enabled ", time.Now())
|
log.Info("scheduler is set to ", enabled)
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (scheduler *SchedulerCapacity) Disable() bool {
|
|
||||||
scheduler.enabled = false
|
|
||||||
log.Info("scheduler is disabled ", time.Now())
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,15 +796,9 @@ func (scheduler *SchedulerFair) Summary() MsgSummary {
|
|||||||
return summary
|
return summary
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scheduler *SchedulerFair) Enable() bool {
|
func (scheduler *SchedulerFair) SetEnabled(enabled bool) bool {
|
||||||
scheduler.enabled = true
|
scheduler.enabled = enabled
|
||||||
log.Info("scheduler is enabled ", time.Now())
|
log.Info("scheduler is set to ", enabled)
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (scheduler *SchedulerFair) Disable() bool {
|
|
||||||
scheduler.enabled = false
|
|
||||||
log.Info("scheduler is disabled ", time.Now())
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,13 +311,9 @@ func (scheduler *SchedulerPriority) Summary() MsgSummary {
|
|||||||
return summary
|
return summary
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scheduler *SchedulerPriority) Enable() bool {
|
func (scheduler *SchedulerPriority) SetEnabled(enabled bool) bool {
|
||||||
scheduler.enabled = true
|
scheduler.enabled = enabled
|
||||||
return true
|
log.Info("scheduler is set to ", enabled)
|
||||||
}
|
|
||||||
|
|
||||||
func (scheduler *SchedulerPriority) Disable() bool {
|
|
||||||
scheduler.enabled = false
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user