diff --git a/adaptor/PCM-CORE/api/desc/core/pcm-core.api b/adaptor/PCM-CORE/api/desc/core/pcm-core.api index 127d00d8..880fac72 100644 --- a/adaptor/PCM-CORE/api/desc/core/pcm-core.api +++ b/adaptor/PCM-CORE/api/desc/core/pcm-core.api @@ -184,19 +184,10 @@ type ( serviceName string `yaml:"serviceName"` metadata interface{} `yaml:"metadata"` } - scheduleTaskResp { - Code int32 `json:"code"` - Msg string `json:"msg"` - } ) type ( taskListResp { - Code int32 `json:"code"` - Msg string `json:"msg"` - Data Data `json:"data"` - } - Data { TotalCount int `json:"totalCount"` CardTime float32 `json:"cardTime"` TotalRunTime float32 `json:"totalRunTime"` diff --git a/adaptor/PCM-CORE/api/desc/pcm.api b/adaptor/PCM-CORE/api/desc/pcm.api index 388a9982..1848bb28 100644 --- a/adaptor/PCM-CORE/api/desc/pcm.api +++ b/adaptor/PCM-CORE/api/desc/pcm.api @@ -22,7 +22,7 @@ info( ) service pcm { @handler scheduleTaskHandler - post /core/scheduleTask (scheduleTaskReq) returns (scheduleTaskResp) + post /core/scheduleTask (scheduleTaskReq) returns () @handler TaskListHandler get /core/taskList () returns (taskListResp) @@ -39,9 +39,6 @@ service pcm { @handler listRegionHandler get /core/listRegion () returns (listRegionResp) - // @handler syncInfoHandler - // get /core/syncInfo (syncInfoReq) returns (syncInfoResp) - @handler getComputingPowerHandler get /core/getComputingPower returns (cpResp) diff --git a/adaptor/PCM-CORE/api/internal/handler/core/scheduletaskhandler.go b/adaptor/PCM-CORE/api/internal/handler/core/scheduletaskhandler.go index dfd4c844..04fb4954 100644 --- a/adaptor/PCM-CORE/api/internal/handler/core/scheduletaskhandler.go +++ b/adaptor/PCM-CORE/api/internal/handler/core/scheduletaskhandler.go @@ -1,6 +1,7 @@ package core import ( + "PCM/common/result" "PCM/common/tool" "net/http" @@ -19,16 +20,17 @@ func ScheduleTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { } // 解析yaml文件 _, fileHeader, err := r.FormFile("file") + if err != nil { + result.HttpResult(r, w, nil, err) + return + } err = tool.Yaml2struct(fileHeader, &req) if err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.HttpResult(r, w, nil, err) + return } l := core.NewScheduleTaskLogic(r.Context(), svcCtx) - resp, err := l.ScheduleTask(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + err = l.ScheduleTask(&req) + result.HttpResult(r, w, nil, err) } } diff --git a/adaptor/PCM-CORE/api/internal/handler/core/submitjobhandler.go b/adaptor/PCM-CORE/api/internal/handler/core/submitjobhandler.go index f89e2c13..78781e36 100644 --- a/adaptor/PCM-CORE/api/internal/handler/core/submitjobhandler.go +++ b/adaptor/PCM-CORE/api/internal/handler/core/submitjobhandler.go @@ -1,6 +1,7 @@ package core import ( + "PCM/common/result" "net/http" "PCM/adaptor/PCM-CORE/api/internal/logic/core" @@ -17,11 +18,7 @@ func SubmitJobHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } l := core.NewScheduleTaskLogic(r.Context(), svcCtx) - resp, err := l.ScheduleTask(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + err := l.ScheduleTask(&req) + result.HttpResult(r, w, nil, err) } } diff --git a/adaptor/PCM-CORE/api/internal/handler/core/tasklisthandler.go b/adaptor/PCM-CORE/api/internal/handler/core/tasklisthandler.go index a92a285d..f6c824e7 100644 --- a/adaptor/PCM-CORE/api/internal/handler/core/tasklisthandler.go +++ b/adaptor/PCM-CORE/api/internal/handler/core/tasklisthandler.go @@ -1,21 +1,17 @@ package core import ( + "PCM/common/result" "net/http" "PCM/adaptor/PCM-CORE/api/internal/logic/core" "PCM/adaptor/PCM-CORE/api/internal/svc" - "github.com/zeromicro/go-zero/rest/httpx" ) func TaskListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { l := core.NewTaskListLogic(r.Context(), svcCtx) resp, err := l.TaskList() - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/adaptor/PCM-CORE/api/internal/logic/core/scheduletasklogic.go b/adaptor/PCM-CORE/api/internal/logic/core/scheduletasklogic.go index b3a5313b..e829edaf 100644 --- a/adaptor/PCM-CORE/api/internal/logic/core/scheduletasklogic.go +++ b/adaptor/PCM-CORE/api/internal/logic/core/scheduletasklogic.go @@ -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 //checkResult := l.checkSubmitReq(req) //if checkResult != "" { @@ -39,7 +39,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type //} bytes, err := json.Marshal(req) if err != nil { - return nil, err + return err } // construct task info taskModel := model.Task{ @@ -54,7 +54,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type // save the task in mysql and return id tx := l.svcCtx.DbEngin.Create(&taskModel) if tx.Error != nil { - return nil, tx.Error + return tx.Error } // push message into topic @@ -63,7 +63,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type reqMessage, err := json.Marshal(task) if err != nil { logx.Error(err) - return nil, err + return err } switch task.ServiceName { case "kubeNative": @@ -74,10 +74,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *type l.svcCtx.ScheduleAiClient.Push(string(reqMessage)) } } - return &types.ScheduleTaskResp{ - Code: 200, - Msg: "Success", - }, nil + return nil } func (l *ScheduleTaskLogic) checkSubmitReq(req *types.ScheduleTaskReq) string { diff --git a/adaptor/PCM-CORE/api/internal/logic/core/tasklistlogic.go b/adaptor/PCM-CORE/api/internal/logic/core/tasklistlogic.go index 93606f47..2a36a15c 100644 --- a/adaptor/PCM-CORE/api/internal/logic/core/tasklistlogic.go +++ b/adaptor/PCM-CORE/api/internal/logic/core/tasklistlogic.go @@ -29,7 +29,7 @@ func NewTaskListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskList func (l *TaskListLogic) TaskList() (resp *types.TaskListResp, err error) { 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 { } @@ -55,24 +55,22 @@ func (l *TaskListLogic) TaskList() (resp *types.TaskListResp, err error) { } task.ServiceName = strings.Join(names, ",") } - resp.Data.Tasks = append(resp.Data.Tasks, types.Task{ + resp.Tasks = append(resp.Tasks, types.Task{ ServiceName: task.ServiceName, Name: task.Name, Strategy: int(task.Strategy), - SynergyStatus: enum.Status(task.SynergyStatus).String(), + SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(), 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 { return nil, tx.Error } // 运行任务合计数 - resp.Data.TotalCount = len(tasks) - resp.Code = 200 - resp.Msg = "Success" + resp.TotalCount = len(tasks) return resp, nil } diff --git a/adaptor/PCM-CORE/api/internal/types/types.go b/adaptor/PCM-CORE/api/internal/types/types.go index 7d4e6c52..6dd77ef2 100644 --- a/adaptor/PCM-CORE/api/internal/types/types.go +++ b/adaptor/PCM-CORE/api/internal/types/types.go @@ -166,18 +166,7 @@ type TaskInfo struct { Metadata interface{} `yaml:"metadata"` } -type ScheduleTaskResp struct { - Code int32 `json:"code"` - Msg string `json:"msg"` -} - type TaskListResp struct { - Code int32 `json:"code"` - Msg string `json:"msg"` - Data Data `json:"data"` -} - -type Data struct { TotalCount int `json:"totalCount"` CardTime float32 `json:"cardTime"` TotalRunTime float32 `json:"totalRunTime"` diff --git a/common/enum/synergyStatusEnum.go b/common/enum/synergyStatusEnum.go index ffa7eea3..85417e3e 100644 --- a/common/enum/synergyStatusEnum.go +++ b/common/enum/synergyStatusEnum.go @@ -1,13 +1,13 @@ package enum -type synergyStatus int64 +type SynergyStatus int64 const ( - SYNERGIZED synergyStatus = 0 - NOT_SYNERGIZED synergyStatus = 1 + SYNERGIZED SynergyStatus = 0 + NOT_SYNERGIZED SynergyStatus = 1 ) -func (s synergyStatus) String() string { +func (s SynergyStatus) String() string { switch s { case SYNERGIZED: return "已协同"