mirror of
https://github.com/newnius/YAO-scheduler.git
synced 2025-12-15 16:16:44 +00:00
add group manager
This commit is contained in:
70
src/main.go
70
src/main.go
@@ -5,7 +5,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var addr = flag.String("addr", ":8080", "http service address")
|
var addr = flag.String("addr", ":8080", "http service address")
|
||||||
@@ -31,7 +30,7 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
case "job_submit":
|
case "job_submit":
|
||||||
var job Job
|
var job Job
|
||||||
fmt.Println("job_submit")
|
log.Debug("job_submit")
|
||||||
msgSubmit := MsgSubmit{Code: 0}
|
msgSubmit := MsgSubmit{Code: 0}
|
||||||
err := json.Unmarshal([]byte(string(r.PostFormValue("job"))), &job)
|
err := json.Unmarshal([]byte(string(r.PostFormValue("job"))), &job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -46,47 +45,102 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case "job_status":
|
case "job_status":
|
||||||
fmt.Println("job_status")
|
log.Debug("job_status")
|
||||||
js, _ := json.Marshal(scheduler.QueryState(r.URL.Query().Get("id")))
|
js, _ := json.Marshal(scheduler.QueryState(r.URL.Query().Get("id")))
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "job_stop":
|
case "job_stop":
|
||||||
fmt.Println("job_stop")
|
log.Debug("job_stop")
|
||||||
js, _ := json.Marshal(scheduler.Stop(string(r.PostFormValue("id"))))
|
js, _ := json.Marshal(scheduler.Stop(string(r.PostFormValue("id"))))
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "task_logs":
|
case "task_logs":
|
||||||
fmt.Println("task_logs")
|
log.Debug("task_logs")
|
||||||
js, _ := json.Marshal(scheduler.QueryLogs(r.URL.Query().Get("job"), r.URL.Query().Get("task")))
|
js, _ := json.Marshal(scheduler.QueryLogs(r.URL.Query().Get("job"), r.URL.Query().Get("task")))
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "jobs":
|
case "jobs":
|
||||||
fmt.Println("job_list")
|
log.Debug("job_list")
|
||||||
js, _ := json.Marshal(scheduler.ListJobs())
|
js, _ := json.Marshal(scheduler.ListJobs())
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "summary":
|
case "summary":
|
||||||
fmt.Println("summary")
|
log.Debug("summary")
|
||||||
js, _ := json.Marshal(scheduler.Summary())
|
js, _ := json.Marshal(scheduler.Summary())
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "pool_status_history":
|
case "pool_status_history":
|
||||||
fmt.Println("pool_status_history")
|
log.Debug("pool_status_history")
|
||||||
js, _ := json.Marshal(pool.statusHistory())
|
js, _ := json.Marshal(pool.statusHistory())
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case "group_list":
|
||||||
|
log.Debug("group_list")
|
||||||
|
js, _ := json.Marshal(InstanceOfGroupManager().List())
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(js)
|
||||||
|
break
|
||||||
|
|
||||||
|
case "group_add":
|
||||||
|
log.Debug("group_add")
|
||||||
|
var group Group
|
||||||
|
msg := MsgGroupCreate{Code: 0}
|
||||||
|
err := json.Unmarshal([]byte(string(r.PostFormValue("job"))), &group)
|
||||||
|
if err != nil {
|
||||||
|
msg.Code = 1
|
||||||
|
msg.Error = err.Error()
|
||||||
|
} else {
|
||||||
|
msg = InstanceOfGroupManager().Add(group)
|
||||||
|
}
|
||||||
|
js, _ := json.Marshal(msg)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(js)
|
||||||
|
break
|
||||||
|
|
||||||
|
case "group_update":
|
||||||
|
log.Debug("group_update")
|
||||||
|
var group Group
|
||||||
|
msg := MsgGroupCreate{Code: 0}
|
||||||
|
err := json.Unmarshal([]byte(string(r.PostFormValue("job"))), &group)
|
||||||
|
if err != nil {
|
||||||
|
msg.Code = 1
|
||||||
|
msg.Error = err.Error()
|
||||||
|
} else {
|
||||||
|
msg = InstanceOfGroupManager().Update(group)
|
||||||
|
}
|
||||||
|
js, _ := json.Marshal(msg)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(js)
|
||||||
|
break
|
||||||
|
|
||||||
|
case "group_remove":
|
||||||
|
log.Debug("group_remove")
|
||||||
|
var group Group
|
||||||
|
msg := MsgGroupCreate{Code: 0}
|
||||||
|
err := json.Unmarshal([]byte(string(r.PostFormValue("job"))), &group)
|
||||||
|
if err != nil {
|
||||||
|
msg.Code = 1
|
||||||
|
msg.Error = err.Error()
|
||||||
|
} else {
|
||||||
|
msg = InstanceOfGroupManager().Remove(group)
|
||||||
|
}
|
||||||
|
js, _ := json.Marshal(msg)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(js)
|
||||||
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
http.Error(w, "Not Found", http.StatusNotFound)
|
http.Error(w, "Not Found", http.StatusNotFound)
|
||||||
break
|
break
|
||||||
|
|||||||
19
src/util.go
19
src/util.go
@@ -43,7 +43,7 @@ type MsgResource struct {
|
|||||||
type MsgJobList struct {
|
type MsgJobList struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
Jobs []Job `json:"jobs"`
|
Jobs []Job `json:"jobs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MsgLog struct {
|
type MsgLog struct {
|
||||||
@@ -136,6 +136,23 @@ type Task struct {
|
|||||||
MemoryGPU int `json:"gpu_memory"`
|
MemoryGPU int `json:"gpu_memory"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Weight int `json:"weight"`
|
||||||
|
NumGPU int `json:"gpu_number"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MsgGroupCreate struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MsgGroupList struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
Groups []Group `json:"groups"`
|
||||||
|
}
|
||||||
|
|
||||||
func str2int(str string, defaultValue int) int {
|
func str2int(str string, defaultValue int) int {
|
||||||
i, err := strconv.Atoi(str)
|
i, err := strconv.Atoi(str)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user