| @@ -171,21 +171,36 @@ type ( | |||||
| ) | ) | ||||
| type ( | type ( | ||||
| scheduleTaskReq { | |||||
| scheduleTaskByYamlReq { | |||||
| Name string `yaml:"name"` | Name string `yaml:"name"` | ||||
| synergy string `yaml:"synergy"` | synergy string `yaml:"synergy"` | ||||
| Description string `yaml:"description"` | Description string `yaml:"description"` | ||||
| strategy string `yaml:"strategy"` | strategy string `yaml:"strategy"` | ||||
| tasks []TaskInfo `yaml:"tasks"` | |||||
| tasks []TaskYaml `yaml:"tasks"` | |||||
| } | } | ||||
| TaskInfo { | |||||
| TaskYaml { | |||||
| TaskId int64 `yaml:"taskId"` | TaskId int64 `yaml:"taskId"` | ||||
| serviceName string `yaml:"serviceName"` | serviceName string `yaml:"serviceName"` | ||||
| metadata interface{} `yaml:"metadata"` | metadata interface{} `yaml:"metadata"` | ||||
| } | } | ||||
| ) | ) | ||||
| type ( | |||||
| scheduleTaskReq { | |||||
| Name string `json:"name"` | |||||
| synergy string `json:"synergy"` | |||||
| Description string `json:"description"` | |||||
| strategy string `json:"strategy"` | |||||
| tasks []TaskInfo `json:"tasks"` | |||||
| } | |||||
| TaskInfo { | |||||
| TaskId int64 `json:"taskId,optional"` | |||||
| serviceName string `json:"serviceName"` | |||||
| metadata interface{} `json:"metadata"` | |||||
| } | |||||
| ) | |||||
| type ( | type ( | ||||
| taskListResp { | taskListResp { | ||||
| TotalCount int `json:"totalCount"` | TotalCount int `json:"totalCount"` | ||||
| @@ -21,6 +21,9 @@ info( | |||||
| group : core | group : core | ||||
| ) | ) | ||||
| service pcm { | service pcm { | ||||
| @handler scheduleTaskByYamlHandler | |||||
| post /core/scheduleTaskByYaml (scheduleTaskByYamlReq) returns () | |||||
| @handler scheduleTaskHandler | @handler scheduleTaskHandler | ||||
| post /core/scheduleTask (scheduleTaskReq) returns () | post /core/scheduleTask (scheduleTaskReq) returns () | ||||
| @@ -0,0 +1,36 @@ | |||||
| package core | |||||
| import ( | |||||
| "PCM/common/result" | |||||
| "PCM/common/tool" | |||||
| "net/http" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/logic/core" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/svc" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/types" | |||||
| "github.com/zeromicro/go-zero/rest/httpx" | |||||
| ) | |||||
| func ScheduleTaskByYamlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||
| return func(w http.ResponseWriter, r *http.Request) { | |||||
| var req types.ScheduleTaskByYamlReq | |||||
| if err := httpx.Parse(r, &req); err != nil { | |||||
| httpx.ErrorCtx(r.Context(), w, err) | |||||
| return | |||||
| } | |||||
| // 解析yaml文件 | |||||
| _, fileHeader, err := r.FormFile("file") | |||||
| if err != nil { | |||||
| result.HttpResult(r, w, nil, err) | |||||
| return | |||||
| } | |||||
| err = tool.Yaml2struct(fileHeader, &req) | |||||
| if err != nil { | |||||
| result.HttpResult(r, w, nil, err) | |||||
| return | |||||
| } | |||||
| l := core.NewScheduleTaskByYamlLogic(r.Context(), svcCtx) | |||||
| err = l.ScheduleTaskByYaml(&req) | |||||
| result.HttpResult(r, w, nil, err) | |||||
| } | |||||
| } | |||||
| @@ -2,33 +2,25 @@ package core | |||||
| import ( | import ( | ||||
| "PCM/common/result" | "PCM/common/result" | ||||
| "PCM/common/tool" | |||||
| "github.com/zeromicro/go-zero/rest/httpx" | |||||
| "io/ioutil" | |||||
| "k8s.io/apimachinery/pkg/util/json" | |||||
| "net/http" | "net/http" | ||||
| "PCM/adaptor/PCM-CORE/api/internal/logic/core" | "PCM/adaptor/PCM-CORE/api/internal/logic/core" | ||||
| "PCM/adaptor/PCM-CORE/api/internal/svc" | "PCM/adaptor/PCM-CORE/api/internal/svc" | ||||
| "PCM/adaptor/PCM-CORE/api/internal/types" | "PCM/adaptor/PCM-CORE/api/internal/types" | ||||
| "github.com/zeromicro/go-zero/rest/httpx" | |||||
| ) | ) | ||||
| func ScheduleTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | func ScheduleTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||||
| return func(w http.ResponseWriter, r *http.Request) { | return func(w http.ResponseWriter, r *http.Request) { | ||||
| var req types.ScheduleTaskReq | var req types.ScheduleTaskReq | ||||
| if err := httpx.Parse(r, &req); err != nil { | |||||
| httpx.ErrorCtx(r.Context(), w, err) | |||||
| return | |||||
| } | |||||
| // 解析yaml文件 | |||||
| _, fileHeader, err := r.FormFile("file") | |||||
| bytes, err := ioutil.ReadAll(r.Body) | |||||
| if err != nil { | if err != nil { | ||||
| result.HttpResult(r, w, nil, err) | |||||
| return | |||||
| } | |||||
| err = tool.Yaml2struct(fileHeader, &req) | |||||
| if err != nil { | |||||
| result.HttpResult(r, w, nil, err) | |||||
| httpx.ErrorCtx(r.Context(), w, err) | |||||
| return | return | ||||
| } | } | ||||
| json.Unmarshal(bytes, &req) | |||||
| l := core.NewScheduleTaskLogic(r.Context(), svcCtx) | l := core.NewScheduleTaskLogic(r.Context(), svcCtx) | ||||
| err = l.ScheduleTask(&req) | err = l.ScheduleTask(&req) | ||||
| result.HttpResult(r, w, nil, err) | result.HttpResult(r, w, nil, err) | ||||
| @@ -17,6 +17,11 @@ import ( | |||||
| func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||||
| server.AddRoutes( | server.AddRoutes( | ||||
| []rest.Route{ | []rest.Route{ | ||||
| { | |||||
| Method: http.MethodPost, | |||||
| Path: "/core/scheduleTaskByYaml", | |||||
| Handler: core.ScheduleTaskByYamlHandler(serverCtx), | |||||
| }, | |||||
| { | { | ||||
| Method: http.MethodPost, | Method: http.MethodPost, | ||||
| Path: "/core/scheduleTask", | Path: "/core/scheduleTask", | ||||
| @@ -0,0 +1,69 @@ | |||||
| package core | |||||
| import ( | |||||
| "PCM/adaptor/PCM-CORE/model" | |||||
| "context" | |||||
| "k8s.io/apimachinery/pkg/util/json" | |||||
| "time" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/svc" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/types" | |||||
| "github.com/zeromicro/go-zero/core/logx" | |||||
| ) | |||||
| type ScheduleTaskByYamlLogic struct { | |||||
| logx.Logger | |||||
| ctx context.Context | |||||
| svcCtx *svc.ServiceContext | |||||
| } | |||||
| func NewScheduleTaskByYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleTaskByYamlLogic { | |||||
| return &ScheduleTaskByYamlLogic{ | |||||
| Logger: logx.WithContext(ctx), | |||||
| ctx: ctx, | |||||
| svcCtx: svcCtx, | |||||
| } | |||||
| } | |||||
| func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYamlReq) error { | |||||
| bytes, err := json.Marshal(req) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| // construct task info | |||||
| taskModel := model.Task{ | |||||
| Status: "Saved", | |||||
| Description: req.Description, | |||||
| Name: req.Name, | |||||
| YamlString: string(bytes), | |||||
| StartTime: time.Now(), | |||||
| CreatedTime: time.Now(), | |||||
| UpdatedTime: time.Now(), | |||||
| } | |||||
| // save the task in mysql and return id | |||||
| tx := l.svcCtx.DbEngin.Create(&taskModel) | |||||
| if tx.Error != nil { | |||||
| return tx.Error | |||||
| } | |||||
| // push message into topic | |||||
| for _, task := range req.Tasks { | |||||
| task.TaskId = taskModel.Id | |||||
| reqMessage, err := json.Marshal(task) | |||||
| if err != nil { | |||||
| logx.Error(err) | |||||
| return err | |||||
| } | |||||
| switch task.ServiceName { | |||||
| case "kubeNative": | |||||
| l.svcCtx.ScheduleCloudClient.Push(string(reqMessage)) | |||||
| case "ac", "th": | |||||
| l.svcCtx.ScheduleHpcClient.Push(string(reqMessage)) | |||||
| case "modelArts": | |||||
| l.svcCtx.ScheduleAiClient.Push(string(reqMessage)) | |||||
| } | |||||
| } | |||||
| return nil | |||||
| } | |||||
| @@ -152,20 +152,34 @@ type Region struct { | |||||
| RunningJobs int64 `json:"runningJobs"` | RunningJobs int64 `json:"runningJobs"` | ||||
| } | } | ||||
| type ScheduleTaskReq struct { | |||||
| type ScheduleTaskByYamlReq struct { | |||||
| Name string `yaml:"name"` | Name string `yaml:"name"` | ||||
| Synergy string `yaml:"synergy"` | Synergy string `yaml:"synergy"` | ||||
| Description string `yaml:"description"` | Description string `yaml:"description"` | ||||
| Strategy string `yaml:"strategy"` | Strategy string `yaml:"strategy"` | ||||
| Tasks []TaskInfo `yaml:"tasks"` | |||||
| Tasks []TaskYaml `yaml:"tasks"` | |||||
| } | } | ||||
| type TaskInfo struct { | |||||
| type TaskYaml struct { | |||||
| TaskId int64 `yaml:"taskId"` | TaskId int64 `yaml:"taskId"` | ||||
| ServiceName string `yaml:"serviceName"` | ServiceName string `yaml:"serviceName"` | ||||
| Metadata interface{} `yaml:"metadata"` | Metadata interface{} `yaml:"metadata"` | ||||
| } | } | ||||
| type ScheduleTaskReq struct { | |||||
| Name string `json:"name"` | |||||
| Synergy string `json:"synergy"` | |||||
| Description string `json:"description"` | |||||
| Strategy string `json:"strategy"` | |||||
| Tasks []TaskInfo `json:"tasks"` | |||||
| } | |||||
| type TaskInfo struct { | |||||
| TaskId int64 `json:"taskId,optional"` | |||||
| ServiceName string `json:"serviceName"` | |||||
| Metadata interface{} `json:"metadata"` | |||||
| } | |||||
| type TaskListResp struct { | type TaskListResp struct { | ||||
| TotalCount int `json:"totalCount"` | TotalCount int `json:"totalCount"` | ||||
| CardTime float32 `json:"cardTime"` | CardTime float32 `json:"cardTime"` | ||||
| @@ -1570,8 +1584,8 @@ type NotebookResp struct { | |||||
| Volume VolumeRes `json:"volume,omitempty" copier:"Volume"` | Volume VolumeRes `json:"volume,omitempty" copier:"Volume"` | ||||
| WorkspaceId string `json:"workspace_id,omitempty" copier:"WorkspaceId"` | WorkspaceId string `json:"workspace_id,omitempty" copier:"WorkspaceId"` | ||||
| Feature string `json:"feature,omitempty" copier:"Feature"` | Feature string `json:"feature,omitempty" copier:"Feature"` | ||||
| CreateAt int64 `json:"create_at,omitempty" copier:"CreateAt"` // * | |||||
| Hooks Hooks `json:"hooks,omitempty" copier:"Hooks"` | |||||
| CreateAt int64 `json:"create_at,omitempty" copier:"CreateAt"` // * | |||||
| Hooks Hooks `json:"hooks,omitempty" copier:"Hooks"` // * | |||||
| Tags []string `json:"tags,omitempty" copier:"Tags"` // * | Tags []string `json:"tags,omitempty" copier:"Tags"` // * | ||||
| UpdateAt int64 `json:"update_at,omitempty" copier:"UpdateAt"` // * | UpdateAt int64 `json:"update_at,omitempty" copier:"UpdateAt"` // * | ||||
| UserNotebookResp UserNotebookResp `json:"user,omitempty" copier:"UserNotebookResp"` // * | UserNotebookResp UserNotebookResp `json:"user,omitempty" copier:"UserNotebookResp"` // * | ||||