From 13fad5ec213f9f8f1ecc78e1fb7e7061ae4a8e36 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Thu, 31 Aug 2023 17:32:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E7=AE=97=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 1086a71a5fc77ce13f8c143218d7985985ef85f2 --- api/desc/cloud/pcm-cloud.api | 63 ++++++++++++------ api/desc/pcm.api | 64 +++++++++---------- .../handler/cloud/applyyamlhandler.go | 28 -------- .../handler/cloud/cloudlisthandler.go | 17 +++++ api/internal/handler/routes.go | 4 +- api/internal/logic/cloud/applyyamllogic.go | 30 --------- api/internal/logic/cloud/cloudlistlogic.go | 38 +++++++++++ api/internal/pkg/scheduler/hpcScheduler.go | 1 + api/internal/types/types.go | 21 ++++++ rpc/internal/logic/pcmcore/syncinfologic.go | 7 +- 10 files changed, 158 insertions(+), 115 deletions(-) delete mode 100644 api/internal/handler/cloud/applyyamlhandler.go create mode 100644 api/internal/handler/cloud/cloudlisthandler.go delete mode 100644 api/internal/logic/cloud/applyyamllogic.go create mode 100644 api/internal/logic/cloud/cloudlistlogic.go diff --git a/api/desc/cloud/pcm-cloud.api b/api/desc/cloud/pcm-cloud.api index 9bc6c9af..daa250ec 100644 --- a/api/desc/cloud/pcm-cloud.api +++ b/api/desc/cloud/pcm-cloud.api @@ -1,36 +1,57 @@ syntax = "v1" info( - title: "cloud core" - desc: "cloud core微服务" - author: "zhangwei" - email: "" + title: "cloud core" + desc: "cloud core微服务" + author: "zhangwei" + email: "" ) /******************find datasetList start*************************/ -type ApplyReq{ - YamlString string `json:"yamlString" copier:"yamlString"` +type ApplyReq { + YamlString string `json:"yamlString" copier:"yamlString"` } -type DeleteReq{ - YamlString string `json:"yamlString" copier:"yamlString"` +type DeleteReq { + YamlString string `json:"yamlString" copier:"yamlString"` } -type ApplyResp{ - Code int32 `json:"code,omitempty"` - Msg string `json:"msg,omitempty"` - DataSet []DataSet `json:"dataSet,omitempty"` +type ApplyResp { + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` + DataSet []DataSet `json:"dataSet,omitempty"` } -type DeleteResp{ - Code int32 `json:"code,omitempty"` - Msg string `json:"msg,omitempty"` - Data string `json:"data,omitempty"` +type DeleteResp { + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` + Data string `json:"data,omitempty"` } -type DataSet{ - ApiVersion int32 `json:"apiVersion,omitempty"` - Kind string `json:"kind,omitempty"` - Name string `json:"name,omitempty"` - NameSpace string `json:"nameSpace,omitempty"` +type DataSet { + ApiVersion int32 `json:"apiVersion,omitempty"` + Kind string `json:"kind,omitempty"` + Name string `json:"name,omitempty"` + NameSpace string `json:"nameSpace,omitempty"` +} + +type cloudListResp { + Clouds []Cloud `json:"clouds"` + +} +type Cloud{ + Id int64 `json:"id"` // id + TaskId int64 `json:"taskId"` // 任务id + ParticipantId int64 `json:"participantId"` // 集群静态信息id + ApiVersion string `json:"apiVersion"` + Name string `json:"name"` // 名称 + Namespace string `json:"namespace"` // 命名空间 + Kind string `json:"kind"` // 种类 + Status string `json:"status"` // 状态 + StartTime string `json:"startTime"` // 开始时间 + RunningTime int64 `json:"runningTime"` // 运行时长 + CreatedBy int64 `json:"createdBy"` // 创建人 + CreatedTime string `json:"createdTime"` // 创建时间 + YamlString string `json:"yamlString"` + Result string `json:"result"` } \ No newline at end of file diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 3cd07cca..0939a08f 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -25,49 +25,49 @@ info( service pcm { @handler scheduleTaskByYamlHandler post /core/scheduleTaskByYaml (scheduleTaskByYamlReq) returns () - + @handler scheduleTaskHandler post /core/scheduleTask (scheduleTaskReq) returns () - + @handler TaskListHandler get /core/taskList () returns (taskListResp) - + @handler JobTotalHandler get /core/jobTotal () returns (jobTotalResp) - + @handler listCenterHandler get /core/listCenter () returns (listCenterResp) - + @handler listClusterHandler get /core/listCluster/:centerId (listClusterReq) returns (listClusterResp) - + @handler submitJobHandler post /core/submitJob (submitJobReq) returns (submitJobResp) - + @handler getRegionHandler get /core/getRegion () returns (getRegionResp) - + @handler listRegionHandler get /core/listRegion () returns (listRegionResp) - + @handler getComputingPowerHandler get /core/getComputingPower returns (cpResp) - + @handler getGeneralInfoHandler get /core/getGeneralInfo () returns (GiResp) - + @handler listDomainResourceHandler get /core/listDomainResource returns (DomainResourceResp) - + @handler getResourcePanelConfigHandler get /core/getResourcePanelConfigHandler () returns (ResourcePanelConfigResp) - + @handler putResourcePanelConfigHandler put /core/resourcePanelConfigHandler (ResourcePanelConfigReq) returns () - + @handler nodeAssetsHandler get /core/assets () returns (NodeAssetsResp) - + } //hpc二级接口 @@ -78,10 +78,10 @@ service pcm { service pcm { @handler listJobHandler get /hpc/listJob (listJobReq) returns (listJobResp) - + @handler listHistoryJobHandler get /hpc/listHistoryJob (listHistoryJobReq) returns (listHistoryJobResp) - + @handler queueAssetsHandler get /queue/assets () returns (QueueAssetsResp) } @@ -92,12 +92,12 @@ service pcm { group : cloud ) service pcm { - @handler applyYamlHandler - get /cloud/ApplyYaml (ApplyReq) returns (ApplyResp) - + @handler cloudListHandler + get /task/list () returns (cloudListResp) + @handler deleteYamlHandler get /cloud/DeleteYaml (ApplyReq) returns (DeleteResp) - + } //智算二级接口 @@ -108,10 +108,10 @@ service pcm { service pcm { @handler listDataSetHandler get /ai/listDataSet/:projectId (DataSetReq) returns (DataSetResp) - + @handler CreateDataSetHandler post /ai/createDataSet/:projectId (CreateDataSetReq) returns (CreateDataSetResp) - + @handler DeleteDataSetHandler delete /ai/deleteDataSet/:projectId/:datasetId (DeleteDataSetReq) returns (DeleteDataSetResp) // creat task 创建导入任务 @@ -142,7 +142,7 @@ service pcm { // ShowAlgorithmByUuid 展示算法详情 @handler ShowAlgorithmByUuid get /ai/ShowAlgorithmByUuid/:projectId/:algorithmId (ShowAlgorithmByUuidReq) returns (ShowAlgorithmByUuidResp) - + // creat export task 创建导出任务 @handler CreateExportTaskHandler post /ai/CreateExportTask/:projectId/:datasetId (CreateExportTaskReq) returns (ExportTaskDataResp) @@ -150,11 +150,11 @@ service pcm { get /ai/GetExportTasksOfDataset/:projectId/:datasetId (GetExportTasksOfDatasetReq) returns (GetExportTasksOfDatasetResp) @handler GetExportTaskStatusOfDatasetHandler get /ai/GetExportTaskStatusOfDataset/:projectId/:resourceId/:taskId (GetExportTaskStatusOfDatasetReq) returns (GetExportTaskStatusOfDatasetResp) - + // create processor task 创建处理任务 @handler CreateProcessorTaskHandler post /ai/CreateProcessorTask (CreateProcessorTaskReq) returns (CreateProcessorTaskResp) - + // create service 创建服务 @handler CreateServiceHandler post /ai/CreateService/:projectId (CreateServiceReq) returns (CreateServiceResp) @@ -170,7 +170,7 @@ service pcm { // ListClusters查询专属资源池列表 @handler ListClustersHandler get /ai/ListClusters (ListClustersReq) returns (ListClustersResp) - + /******************Notebook Method start*************************/ @handler listNotebookHandler get /ai/listNotebook (ListNotebookReq) returns (ListNotebookResp) @@ -185,7 +185,7 @@ service pcm { @handler mountNotebookStorageHandler post /ai/mountNotebookStorage (MountNotebookStorageReq) returns (MountNotebookStorageResp) /******************Notebook Method end*************************/ - + /******************Visualization Job Method start*************************/ @handler getVisualizationJobHandler get /ai/getVisualizationJob (GetVisualizationJobReq) returns (GetVisualizationJobResp) @@ -216,16 +216,16 @@ service pcm { service pcm { @handler uploadHandler post /upload () returns () - + @handler chunkHandler post /chunk () returns () - + @handler imageListHandler get /image/list () returns (imageListResp) - + @handler dataSetCheckHandler get /dataSet/check/:fileMd5 (checkReq) returns (checkResp) - + @handler uploadDataSetHandler post /dataSet/upload () returns () } diff --git a/api/internal/handler/cloud/applyyamlhandler.go b/api/internal/handler/cloud/applyyamlhandler.go deleted file mode 100644 index 8815347b..00000000 --- a/api/internal/handler/cloud/applyyamlhandler.go +++ /dev/null @@ -1,28 +0,0 @@ -package cloud - -import ( - "net/http" - - "github.com/zeromicro/go-zero/rest/httpx" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/cloud" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" -) - -func ApplyYamlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.ApplyReq - if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) - return - } - - l := cloud.NewApplyYamlLogic(r.Context(), svcCtx) - resp, err := l.ApplyYaml(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } - } -} diff --git a/api/internal/handler/cloud/cloudlisthandler.go b/api/internal/handler/cloud/cloudlisthandler.go new file mode 100644 index 00000000..5af15a19 --- /dev/null +++ b/api/internal/handler/cloud/cloudlisthandler.go @@ -0,0 +1,17 @@ +package cloud + +import ( + "gitlink.org.cn/jcce-pcm/utils/result" + "net/http" + + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/cloud" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" +) + +func CloudListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + l := cloud.NewCloudListLogic(r.Context(), svcCtx) + resp, err := l.CloudList() + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 3fcd6343..8c5d963c 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -123,8 +123,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { []rest.Route{ { Method: http.MethodGet, - Path: "/cloud/ApplyYaml", - Handler: cloud.ApplyYamlHandler(serverCtx), + Path: "/task/list", + Handler: cloud.CloudListHandler(serverCtx), }, { Method: http.MethodGet, diff --git a/api/internal/logic/cloud/applyyamllogic.go b/api/internal/logic/cloud/applyyamllogic.go deleted file mode 100644 index b78187f4..00000000 --- a/api/internal/logic/cloud/applyyamllogic.go +++ /dev/null @@ -1,30 +0,0 @@ -package cloud - -import ( - "context" - - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type ApplyYamlLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewApplyYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyYamlLogic { - return &ApplyYamlLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *ApplyYamlLogic) ApplyYaml(req *types.ApplyReq) (resp *types.ApplyResp, err error) { - // todo: add your logic here and delete this line - - return -} diff --git a/api/internal/logic/cloud/cloudlistlogic.go b/api/internal/logic/cloud/cloudlistlogic.go new file mode 100644 index 00000000..a1d70ac4 --- /dev/null +++ b/api/internal/logic/cloud/cloudlistlogic.go @@ -0,0 +1,38 @@ +package cloud + +import ( + "context" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" + "gitlink.org.cn/jcce-pcm/utils/tool" + + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CloudListLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCloudListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CloudListLogic { + return &CloudListLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CloudListLogic) CloudList() (resp *types.CloudListResp, err error) { + // 查询数据库中数算任务列表 + var clouds []*model.Cloud + tx := l.svcCtx.DbEngin.Find(&clouds) + if tx.Error != nil { + return nil, tx.Error + } + result := types.CloudListResp{} + tool.Convert(clouds, &result.Clouds) + return &result, nil +} diff --git a/api/internal/pkg/scheduler/hpcScheduler.go b/api/internal/pkg/scheduler/hpcScheduler.go index b233b97a..a5b517f0 100644 --- a/api/internal/pkg/scheduler/hpcScheduler.go +++ b/api/internal/pkg/scheduler/hpcScheduler.go @@ -17,6 +17,7 @@ func NewHpcScheduler(val string) *hpcScheduler { func (h *hpcScheduler) getNewStructForDb(task *types.TaskInfo, participantId int64) (interface{}, error) { hpc := model.Hpc{ + Id: tool.GenSnowflakeID(), TaskId: task.TaskId, Status: "Saved", ParticipantId: participantId, diff --git a/api/internal/types/types.go b/api/internal/types/types.go index bd1c6c0d..6819c8d5 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -2592,3 +2592,24 @@ type DataSet struct { Name string `json:"name,omitempty"` NameSpace string `json:"nameSpace,omitempty"` } + +type CloudListResp struct { + Clouds []Cloud `json:"clouds"` +} + +type Cloud struct { + Id int64 `json:"id"` // id + TaskId int64 `json:"taskId"` // 任务id + ParticipantId int64 `json:"participantId"` // 集群静态信息id + ApiVersion string `json:"apiVersion"` + Name string `json:"name"` // 名称 + Namespace string `json:"namespace"` // 命名空间 + Kind string `json:"kind"` // 种类 + Status string `json:"status"` // 状态 + StartTime string `json:"startTime"` // 开始时间 + RunningTime int64 `json:"runningTime"` // 运行时长 + CreatedBy int64 `json:"createdBy"` // 创建人 + CreatedTime string `json:"createdTime"` // 创建时间 + YamlString string `json:"yamlString"` + Result string `json:"result"` +} diff --git a/rpc/internal/logic/pcmcore/syncinfologic.go b/rpc/internal/logic/pcmcore/syncinfologic.go index c0f96cd1..4a4bc2f5 100644 --- a/rpc/internal/logic/pcmcore/syncinfologic.go +++ b/rpc/internal/logic/pcmcore/syncinfologic.go @@ -45,8 +45,11 @@ func (l *SyncInfoLogic) SyncInfo(in *pcmCore.SyncInfoReq) (*pcmCore.SyncInfoResp } case "hpc": for _, hpcInfo := range in.HpcInfoList { - tx := db.Exec("update hpc set status = ?,derived_es = ?,assoc_id = ?,exit_code = ?,version = ?,alloc_cpu = ?,alloc_nodes = ?,cluster = ?,block_id = ?,start_time = ?,running_time = ?,job_id = ? where participant_id = ? and task_id = ? and name = ?", - hpcInfo.Status, hpcInfo.DerivedEs, hpcInfo.AssocId, hpcInfo.ExitCode, hpcInfo.Version, hpcInfo.AllocCpu, hpcInfo.AllocNodes, hpcInfo.Cluster, hpcInfo.BlockId, hpcInfo.StartTime, hpcInfo.RunningTime, hpcInfo.JobId, in.ParticipantId, hpcInfo.TaskId, hpcInfo.Name) + //tx := db.Exec("update hpc set status = ?,derived_es = ?,assoc_id = ?,exit_code = ?,version = ?,alloc_cpu = ?,alloc_nodes = ?,cluster = ?,block_id = ?,start_time = ?,running_time = ?,job_id = ? where participant_id = ? and task_id = ? and name = ?", + // hpcInfo.Status, hpcInfo.DerivedEs, hpcInfo.AssocId, hpcInfo.ExitCode, hpcInfo.Version, hpcInfo.AllocCpu, hpcInfo.AllocNodes, hpcInfo.Cluster, hpcInfo.BlockId, hpcInfo.StartTime, hpcInfo.RunningTime, hpcInfo.JobId, in.ParticipantId, hpcInfo.TaskId, hpcInfo.Name) + //print(tx.Error) + tx := db.Exec("update hpc set status = ?,start_time = ?,running_time = ?,job_id = ? where participant_id = ? and task_id = ? and name = ?", + hpcInfo.Status, hpcInfo.StartTime, hpcInfo.RunningTime, hpcInfo.JobId, in.ParticipantId, hpcInfo.TaskId, hpcInfo.Name) print(tx.Error) } case "ai":