core 返回统一
This commit is contained in:
parent
adeacc8b3f
commit
a06028d87c
|
@ -184,19 +184,10 @@ type (
|
||||||
serviceName string `yaml:"serviceName"`
|
serviceName string `yaml:"serviceName"`
|
||||||
metadata interface{} `yaml:"metadata"`
|
metadata interface{} `yaml:"metadata"`
|
||||||
}
|
}
|
||||||
scheduleTaskResp {
|
|
||||||
Code int32 `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
taskListResp {
|
taskListResp {
|
||||||
Code int32 `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
Data Data `json:"data"`
|
|
||||||
}
|
|
||||||
Data {
|
|
||||||
TotalCount int `json:"totalCount"`
|
TotalCount int `json:"totalCount"`
|
||||||
CardTime float32 `json:"cardTime"`
|
CardTime float32 `json:"cardTime"`
|
||||||
TotalRunTime float32 `json:"totalRunTime"`
|
TotalRunTime float32 `json:"totalRunTime"`
|
||||||
|
|
|
@ -22,7 +22,7 @@ info(
|
||||||
)
|
)
|
||||||
service pcm {
|
service pcm {
|
||||||
@handler scheduleTaskHandler
|
@handler scheduleTaskHandler
|
||||||
post /core/scheduleTask (scheduleTaskReq) returns (scheduleTaskResp)
|
post /core/scheduleTask (scheduleTaskReq) returns ()
|
||||||
|
|
||||||
@handler TaskListHandler
|
@handler TaskListHandler
|
||||||
get /core/taskList () returns (taskListResp)
|
get /core/taskList () returns (taskListResp)
|
||||||
|
@ -39,9 +39,6 @@ service pcm {
|
||||||
@handler listRegionHandler
|
@handler listRegionHandler
|
||||||
get /core/listRegion () returns (listRegionResp)
|
get /core/listRegion () returns (listRegionResp)
|
||||||
|
|
||||||
// @handler syncInfoHandler
|
|
||||||
// get /core/syncInfo (syncInfoReq) returns (syncInfoResp)
|
|
||||||
|
|
||||||
@handler getComputingPowerHandler
|
@handler getComputingPowerHandler
|
||||||
get /core/getComputingPower returns (cpResp)
|
get /core/getComputingPower returns (cpResp)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PCM/common/result"
|
||||||
"PCM/common/tool"
|
"PCM/common/tool"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -19,16 +20,17 @@ func ScheduleTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
// 解析yaml文件
|
// 解析yaml文件
|
||||||
_, fileHeader, err := r.FormFile("file")
|
_, fileHeader, err := r.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
result.HttpResult(r, w, nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
err = tool.Yaml2struct(fileHeader, &req)
|
err = tool.Yaml2struct(fileHeader, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
l := core.NewScheduleTaskLogic(r.Context(), svcCtx)
|
l := core.NewScheduleTaskLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.ScheduleTask(&req)
|
err = l.ScheduleTask(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PCM/common/result"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"PCM/adaptor/PCM-CORE/api/internal/logic/core"
|
"PCM/adaptor/PCM-CORE/api/internal/logic/core"
|
||||||
|
@ -17,11 +18,7 @@ func SubmitJobHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
l := core.NewScheduleTaskLogic(r.Context(), svcCtx)
|
l := core.NewScheduleTaskLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.ScheduleTask(&req)
|
err := l.ScheduleTask(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PCM/common/result"
|
||||||
"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"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TaskListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func TaskListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := core.NewTaskListLogic(r.Context(), svcCtx)
|
l := core.NewTaskListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.TaskList()
|
resp, err := l.TaskList()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func NewScheduleTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sche
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *types.ScheduleTaskResp, err error) {
|
func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (err error) {
|
||||||
// check param
|
// check param
|
||||||
//checkResult := l.checkSubmitReq(req)
|
//checkResult := l.checkSubmitReq(req)
|
||||||
//if checkResult != "" {
|
//if checkResult != "" {
|
||||||
|
@ -39,7 +39,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type
|
||||||
//}
|
//}
|
||||||
bytes, err := json.Marshal(req)
|
bytes, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
// construct task info
|
// construct task info
|
||||||
taskModel := model.Task{
|
taskModel := model.Task{
|
||||||
|
@ -54,7 +54,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type
|
||||||
// save the task in mysql and return id
|
// save the task in mysql and return id
|
||||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
return nil, tx.Error
|
return tx.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// push message into topic
|
// push message into topic
|
||||||
|
@ -63,7 +63,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type
|
||||||
reqMessage, err := json.Marshal(task)
|
reqMessage, err := json.Marshal(task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
switch task.ServiceName {
|
switch task.ServiceName {
|
||||||
case "kubeNative":
|
case "kubeNative":
|
||||||
|
@ -74,10 +74,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type
|
||||||
l.svcCtx.ScheduleAiClient.Push(string(reqMessage))
|
l.svcCtx.ScheduleAiClient.Push(string(reqMessage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &types.ScheduleTaskResp{
|
return nil
|
||||||
Code: 200,
|
|
||||||
Msg: "Success",
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ScheduleTaskLogic) checkSubmitReq(req *types.ScheduleTaskReq) string {
|
func (l *ScheduleTaskLogic) checkSubmitReq(req *types.ScheduleTaskReq) string {
|
||||||
|
|
|
@ -29,7 +29,7 @@ func NewTaskListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskList
|
||||||
func (l *TaskListLogic) TaskList() (resp *types.TaskListResp, err error) {
|
func (l *TaskListLogic) TaskList() (resp *types.TaskListResp, err error) {
|
||||||
resp = &types.TaskListResp{}
|
resp = &types.TaskListResp{}
|
||||||
// 查询总运行时长
|
// 查询总运行时长
|
||||||
tx := l.svcCtx.DbEngin.Raw("select sum(running_time)/3600 as total_run_time from (select sum(running_time) as running_time from hpc union all select sum(running_time) as running_time from cloud union all select sum(running_time) as running_time from ai) runtime").Scan(&resp.Data.TotalRunTime)
|
tx := l.svcCtx.DbEngin.Raw("select sum(running_time)/3600 as total_run_time from (select sum(running_time) as running_time from hpc union all select sum(running_time) as running_time from cloud union all select sum(running_time) as running_time from ai) runtime").Scan(&resp.TotalRunTime)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,24 +55,22 @@ func (l *TaskListLogic) TaskList() (resp *types.TaskListResp, err error) {
|
||||||
}
|
}
|
||||||
task.ServiceName = strings.Join(names, ",")
|
task.ServiceName = strings.Join(names, ",")
|
||||||
}
|
}
|
||||||
resp.Data.Tasks = append(resp.Data.Tasks, types.Task{
|
resp.Tasks = append(resp.Tasks, types.Task{
|
||||||
ServiceName: task.ServiceName,
|
ServiceName: task.ServiceName,
|
||||||
Name: task.Name,
|
Name: task.Name,
|
||||||
Strategy: int(task.Strategy),
|
Strategy: int(task.Strategy),
|
||||||
SynergyStatus: enum.Status(task.SynergyStatus).String(),
|
SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(),
|
||||||
Status: task.Status,
|
Status: task.Status,
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
// 运行卡时数
|
// 运行卡时数
|
||||||
tx = l.svcCtx.DbEngin.Model(&model.Hpc{}).Select("(CASE WHEN SUM(running_time * card_count)/3600 IS NULL THEN 0 ELSE SUM(running_time * card_count)/3600 END )as cardTime").Find(&resp.Data.CardTime)
|
tx = l.svcCtx.DbEngin.Model(&model.Hpc{}).Select("(CASE WHEN SUM(running_time * card_count)/3600 IS NULL THEN 0 ELSE SUM(running_time * card_count)/3600 END )as cardTime").Find(&resp.CardTime)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
return nil, tx.Error
|
return nil, tx.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// 运行任务合计数
|
// 运行任务合计数
|
||||||
resp.Data.TotalCount = len(tasks)
|
resp.TotalCount = len(tasks)
|
||||||
resp.Code = 200
|
|
||||||
resp.Msg = "Success"
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,18 +166,7 @@ type TaskInfo struct {
|
||||||
Metadata interface{} `yaml:"metadata"`
|
Metadata interface{} `yaml:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScheduleTaskResp struct {
|
|
||||||
Code int32 `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskListResp struct {
|
type TaskListResp struct {
|
||||||
Code int32 `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
Data Data `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Data struct {
|
|
||||||
TotalCount int `json:"totalCount"`
|
TotalCount int `json:"totalCount"`
|
||||||
CardTime float32 `json:"cardTime"`
|
CardTime float32 `json:"cardTime"`
|
||||||
TotalRunTime float32 `json:"totalRunTime"`
|
TotalRunTime float32 `json:"totalRunTime"`
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package enum
|
package enum
|
||||||
|
|
||||||
type synergyStatus int64
|
type SynergyStatus int64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SYNERGIZED synergyStatus = 0
|
SYNERGIZED SynergyStatus = 0
|
||||||
NOT_SYNERGIZED synergyStatus = 1
|
NOT_SYNERGIZED SynergyStatus = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s synergyStatus) String() string {
|
func (s SynergyStatus) String() string {
|
||||||
switch s {
|
switch s {
|
||||||
case SYNERGIZED:
|
case SYNERGIZED:
|
||||||
return "已协同"
|
return "已协同"
|
||||||
|
|
Loading…
Reference in New Issue