From 4a7e646e0e38817855c69845dac25c73559979ed Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Fri, 8 Mar 2024 17:28:50 +0800 Subject: [PATCH 1/5] ClusterList Former-commit-id: 839fd4761ea712bfc0dfccce4c4ad3be2b5784dd --- api/desc/core/pcm-core.api | 4 ++-- api/internal/logic/adapters/clusterlistlogic.go | 4 ++++ api/internal/types/types.go | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 463f2137..5f6be796 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -726,8 +726,8 @@ type ( ) type ClusterReq { - Id string `json:"id,optional"` - AdapterId string `json:"adapterId,optional"` + Id string `form:"id,optional"` + AdapterId string `form:"adapterId,optional"` Name string `json:"name,optional"` Nickname string `json:"nickname,optional"` Description string `json:"description,optional"` diff --git a/api/internal/logic/adapters/clusterlistlogic.go b/api/internal/logic/adapters/clusterlistlogic.go index 5bf7a5bc..a2806a1e 100644 --- a/api/internal/logic/adapters/clusterlistlogic.go +++ b/api/internal/logic/adapters/clusterlistlogic.go @@ -26,7 +26,11 @@ func NewClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clust func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.ClusterListResp, err error) { resp = &types.ClusterListResp{} + sql := fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null`) + if req.AdapterId != "" { + sql = fmt.Sprintf(`select * from t_cluster where adapter_id = %s and deleted_at is null `, req.AdapterId) + } if req.Type != "" { sql = fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null and a.type = %s`, req.Type) } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 002edab4..a38dfb33 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -694,8 +694,8 @@ type AdapterRelation struct { } type ClusterReq struct { - Id string `json:"id,optional"` - AdapterId string `json:"adapterId,optional"` + Id string `form:"id,optional"` + AdapterId string `form:"adapterId,optional"` Name string `json:"name,optional"` Nickname string `json:"nickname,optional"` Description string `json:"description,optional"` From 074c9175cb495c9c1c9a2bb55bb0dd0d74801922 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Mon, 11 Mar 2024 16:52:09 +0800 Subject: [PATCH 2/5] centerResources Former-commit-id: efde0d5a96faf3ee0a05a614671079f05d222a1e --- api/desc/core/pcm-core.api | 1 + .../logic/core/centerresourceslogic.go | 27 ++++++++++--------- api/internal/types/types.go | 9 ++++--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 5f6be796..df879ab2 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -163,6 +163,7 @@ type ( cpu float32 `json:"cpu"` memory float32 `json:"memory"` storage float32 `json:"storage"` + centerType string `json:"centerType"` } ) type ( diff --git a/api/internal/logic/core/centerresourceslogic.go b/api/internal/logic/core/centerresourceslogic.go index a5276474..be3f6da5 100644 --- a/api/internal/logic/core/centerresourceslogic.go +++ b/api/internal/logic/core/centerresourceslogic.go @@ -26,22 +26,25 @@ func NewCenterResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesResp, err error) { // todo: add your logic here and delete this line centerIndex1 := types.CenterIndex{ - Name: "阿里云", - Cpu: float32(12.33), - Memory: float32(64.55), - Storage: float32(33.90), + Name: "阿里云", + Cpu: float32(12.33), + Memory: float32(64.55), + Storage: float32(33.90), + CenterType: "cloud", } centerIndex2 := types.CenterIndex{ - Name: "A超算中心", - Cpu: float32(42.36), - Memory: float32(66.55), - Storage: float32(23.231), + Name: "A超算中心", + Cpu: float32(42.36), + Memory: float32(66.55), + Storage: float32(23.231), + CenterType: "hpc", } centerIndex3 := types.CenterIndex{ - Name: "智算中心", - Cpu: float32(78.33), - Memory: float32(36.55), - Storage: float32(88.93), + Name: "智算中心", + Cpu: float32(78.33), + Memory: float32(36.55), + Storage: float32(88.93), + CenterType: "ai", } resp = &types.CenterResourcesResp{} resp.CentersIndex = append(resp.CentersIndex, centerIndex1) diff --git a/api/internal/types/types.go b/api/internal/types/types.go index a38dfb33..bcc6c69c 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -143,10 +143,11 @@ type CenterResourcesResp struct { } type CenterIndex struct { - Name string `json:"name"` - Cpu float32 `json:"cpu"` - Memory float32 `json:"memory"` - Storage float32 `json:"storage"` + Name string `json:"name"` + Cpu float32 `json:"cpu"` + Memory float32 `json:"memory"` + Storage float32 `json:"storage"` + CenterType string `json:"centerType"` } type GetClusterListReq struct { From b8dbe7312e31c161c40f92f3b4607e59455712c8 Mon Sep 17 00:00:00 2001 From: jagger Date: Mon, 11 Mar 2024 18:34:59 +0800 Subject: [PATCH 3/5] :sparkles: Dictionary configuration function is implemented Signed-off-by: jagger Former-commit-id: 3408273f72bacda5687fae7e0d41d4aff5ff33f7 --- api/desc/core/pcm-core.api | 111 ++++++++++++++++++ api/desc/pcm.api | 37 ++++++ .../handler/dictionary/adddicthandler.go | 24 ++++ .../handler/dictionary/adddictitemhandler.go | 24 ++++ .../handler/dictionary/deletedicthandler.go | 24 ++++ .../dictionary/deletedictitemhandler.go | 24 ++++ .../handler/dictionary/editdicthandler.go | 24 ++++ .../handler/dictionary/editdictitemhandler.go | 24 ++++ .../handler/dictionary/getdicthandler.go | 24 ++++ .../handler/dictionary/getdictitemhandler.go | 24 ++++ .../handler/dictionary/listdicthandler.go | 24 ++++ .../handler/dictionary/listdictitemhandler.go | 24 ++++ api/internal/handler/routes.go | 57 +++++++++ .../logic/dictionary/adddictitemlogic.go | 56 +++++++++ api/internal/logic/dictionary/adddictlogic.go | 43 +++++++ .../logic/dictionary/deletedictitemlogic.go | 39 ++++++ .../logic/dictionary/deletedictlogic.go | 43 +++++++ .../logic/dictionary/editdictitemlogic.go | 38 ++++++ .../logic/dictionary/editdictlogic.go | 40 +++++++ .../logic/dictionary/getdictitemlogic.go | 38 ++++++ api/internal/logic/dictionary/getdictlogic.go | 38 ++++++ .../logic/dictionary/listdictitemlogic.go | 39 ++++++ .../logic/dictionary/listdictlogic.go | 39 ++++++ api/internal/types/types.go | 106 +++++++++++++++++ 24 files changed, 964 insertions(+) create mode 100644 api/internal/handler/dictionary/adddicthandler.go create mode 100644 api/internal/handler/dictionary/adddictitemhandler.go create mode 100644 api/internal/handler/dictionary/deletedicthandler.go create mode 100644 api/internal/handler/dictionary/deletedictitemhandler.go create mode 100644 api/internal/handler/dictionary/editdicthandler.go create mode 100644 api/internal/handler/dictionary/editdictitemhandler.go create mode 100644 api/internal/handler/dictionary/getdicthandler.go create mode 100644 api/internal/handler/dictionary/getdictitemhandler.go create mode 100644 api/internal/handler/dictionary/listdicthandler.go create mode 100644 api/internal/handler/dictionary/listdictitemhandler.go create mode 100644 api/internal/logic/dictionary/adddictitemlogic.go create mode 100644 api/internal/logic/dictionary/adddictlogic.go create mode 100644 api/internal/logic/dictionary/deletedictitemlogic.go create mode 100644 api/internal/logic/dictionary/deletedictlogic.go create mode 100644 api/internal/logic/dictionary/editdictitemlogic.go create mode 100644 api/internal/logic/dictionary/editdictlogic.go create mode 100644 api/internal/logic/dictionary/getdictitemlogic.go create mode 100644 api/internal/logic/dictionary/getdictlogic.go create mode 100644 api/internal/logic/dictionary/listdictitemlogic.go create mode 100644 api/internal/logic/dictionary/listdictlogic.go diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 463f2137..f67c756f 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -819,3 +819,114 @@ type ClusterRelationInfo { CAuthType string `json:"cAuthType,omitempty" db:"auth_type"` CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"` } + +type ( + DictInfo { + Id string `json:"id,omitempty"` + DictName string `json:"dictName,omitempty"` + DictCode string `json:"dictCode,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty" db:"type"` + Status string `json:"status,omitempty" db:"status"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + } + + DictReq { + Id string `form:"id,optional"` + DictName string `form:"dictName,optional"` + DictCode string `form:"dictCode,optional"` + Description string `form:"description,optional"` + Type string `form:"type,optional"` + Status string `form:"status,optional"` + } + + DictEditReq { + Id string `json:"id,optional"` + DictName string `json:"dictName,optional"` + DictCode string `json:"dictCode,optional"` + Description string `json:"description,optional"` + Type string `json:"type,optional"` + Status string `json:"status,optional"` + } + + DictResp { + Id string `json:"id,omitempty"` + DictName string `json:"dictName,omitempty"` + DictCode string `json:"dictCode,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` + Status string `json:"status,omitempty"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + DictItemInfo []*DictItemInfo `json:"dictItemInfo,omitempty"` + } + + Dicts { + List []DictInfo `json:"list,omitempty"` + } + + + DictItemInfo { + Id string `json:"id,omitempty"` + DictId string `json:"dictId,omitempty"` + ItemText string `json:"itemText,omitempty"` + ItemValue string `json:"itemValue,omitempty"` + Description string `json:"description,omitempty"` + SortOrder string `json:"sortOrder,omitempty"` + Type string `json:"type,omitempty" db:"type"` + ParentId string `json:"parentId,omitempty"` + Status string `json:"status,omitempty" db:"status"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + } + + DictItemReq { + Id string `form:"id,optional"` + DictId string `form:"dictId,optional"` + ItemText string `form:"itemText,optional"` + ItemValue string `form:"itemValue,optional"` + Description string `form:"description,optional"` + SortOrder string `form:"sortOrder,optional"` + Type string `form:"type,optional"` + ParentId string `form:"parentId,optional"` + Status string `form:"status,optional"` + } + + DictItemEditReq { + Id string `json:"id,optional"` + DictId string `json:"dictId,optional"` + ItemText string `json:"itemText,optional"` + ItemValue string `json:"itemValue,optional"` + Description string `json:"description,optional"` + SortOrder string `json:"sortOrder,optional"` + Type string `json:"type,optional"` + ParentId string `json:"parentId,optional"` + Status string `json:"status,optional"` + } + + DictItemResp { + Id string `json:"id,omitempty"` + DictId string `json:"dictId,omitempty"` + ItemText string `json:"itemText,omitempty"` + ItemValue string `json:"itemValue,omitempty"` + Description string `json:"description,omitempty"` + SortOrder string `json:"sortOrder,omitempty"` + Type string `json:"type,omitempty"` + ParentId string `json:"parentId,omitempty"` + Status string `json:"status,omitempty"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + DictInfo *DictInfo `json:"dictInfo,omitempty"` + } + + DictItems { + List []DictItemInfo `json:"list,omitempty"` + } +) + +type ( + CId { + Id string `path:"id":"id,omitempty" validate:"required"` + } + + CIds { + Ids []string `json:"ids,omitempty" validate:"required"` + } +) \ No newline at end of file diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 69910fb3..f082f3f2 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -866,4 +866,41 @@ service pcm { @handler ScheduleSubmitHandler post /schedule/submit (ScheduleReq) returns (ScheduleResp) +} + +@server( + prefix: pcm/v1 + group : dictionary +) + +service pcm { + @handler GetDict + get /dict/:id (CId) returns (DictResp) + + @handler ListDict + get /dicts (DictReq) returns (Dicts) + + @handler AddDict + post /dict (DictEditReq) returns (DictResp) + + @handler EditDict + put /dict (DictEditReq) returns (DictResp) + + @handler DeleteDict + delete /dict/:id (CId) returns (DictResp) + + @handler GetDictItem + get /dictItem/:id (CId) returns (DictItemResp) + + @handler ListDictItem + get /dictItems (DictItemReq) returns (DictItems) + + @handler AddDictItem + post /dictItem (DictItemEditReq) returns (DictItemResp) + + @handler EditDictItem + put /dictItem (DictItemEditReq) returns (DictItemResp) + + @handler DeleteDictItem + delete /dictItem/:id (CId) returns (DictItemResp) } \ No newline at end of file diff --git a/api/internal/handler/dictionary/adddicthandler.go b/api/internal/handler/dictionary/adddicthandler.go new file mode 100644 index 00000000..f97da1bb --- /dev/null +++ b/api/internal/handler/dictionary/adddicthandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func AddDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DictEditReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewAddDictLogic(r.Context(), svcCtx) + resp, err := l.AddDict(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/adddictitemhandler.go b/api/internal/handler/dictionary/adddictitemhandler.go new file mode 100644 index 00000000..44dbe883 --- /dev/null +++ b/api/internal/handler/dictionary/adddictitemhandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func AddDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DictItemEditReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewAddDictItemLogic(r.Context(), svcCtx) + resp, err := l.AddDictItem(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/deletedicthandler.go b/api/internal/handler/dictionary/deletedicthandler.go new file mode 100644 index 00000000..e65e54c2 --- /dev/null +++ b/api/internal/handler/dictionary/deletedicthandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func DeleteDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CId + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewDeleteDictLogic(r.Context(), svcCtx) + resp, err := l.DeleteDict(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/deletedictitemhandler.go b/api/internal/handler/dictionary/deletedictitemhandler.go new file mode 100644 index 00000000..65139c09 --- /dev/null +++ b/api/internal/handler/dictionary/deletedictitemhandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func DeleteDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CId + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewDeleteDictItemLogic(r.Context(), svcCtx) + resp, err := l.DeleteDictItem(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/editdicthandler.go b/api/internal/handler/dictionary/editdicthandler.go new file mode 100644 index 00000000..fe0ef391 --- /dev/null +++ b/api/internal/handler/dictionary/editdicthandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func EditDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DictEditReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewEditDictLogic(r.Context(), svcCtx) + resp, err := l.EditDict(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/editdictitemhandler.go b/api/internal/handler/dictionary/editdictitemhandler.go new file mode 100644 index 00000000..295e9095 --- /dev/null +++ b/api/internal/handler/dictionary/editdictitemhandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func EditDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DictItemEditReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewEditDictItemLogic(r.Context(), svcCtx) + resp, err := l.EditDictItem(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/getdicthandler.go b/api/internal/handler/dictionary/getdicthandler.go new file mode 100644 index 00000000..b1b56d0d --- /dev/null +++ b/api/internal/handler/dictionary/getdicthandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func GetDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CId + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewGetDictLogic(r.Context(), svcCtx) + resp, err := l.GetDict(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/getdictitemhandler.go b/api/internal/handler/dictionary/getdictitemhandler.go new file mode 100644 index 00000000..bbfe113f --- /dev/null +++ b/api/internal/handler/dictionary/getdictitemhandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func GetDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CId + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewGetDictItemLogic(r.Context(), svcCtx) + resp, err := l.GetDictItem(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/listdicthandler.go b/api/internal/handler/dictionary/listdicthandler.go new file mode 100644 index 00000000..72dac7c8 --- /dev/null +++ b/api/internal/handler/dictionary/listdicthandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func ListDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DictReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewListDictLogic(r.Context(), svcCtx) + resp, err := l.ListDict(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/dictionary/listdictitemhandler.go b/api/internal/handler/dictionary/listdictitemhandler.go new file mode 100644 index 00000000..16df182d --- /dev/null +++ b/api/internal/handler/dictionary/listdictitemhandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func ListDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DictItemReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewListDictItemLogic(r.Context(), svcCtx) + resp, err := l.ListDictItem(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index decfc7b4..73b25377 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -9,6 +9,7 @@ import ( apps "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/apps" cloud "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/cloud" core "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/core" + dictionary "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/dictionary" hpc "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/hpc" image "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/image" schedule "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/schedule" @@ -1076,4 +1077,60 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, rest.WithPrefix("/pcm/v1"), ) + + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/dict/:id", + Handler: dictionary.GetDictHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/dicts", + Handler: dictionary.ListDictHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/dict", + Handler: dictionary.AddDictHandler(serverCtx), + }, + { + Method: http.MethodPut, + Path: "/dict", + Handler: dictionary.EditDictHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/dict/:id", + Handler: dictionary.DeleteDictHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/dictItem/:id", + Handler: dictionary.GetDictItemHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/dictItems", + Handler: dictionary.ListDictItemHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/dictItem", + Handler: dictionary.AddDictItemHandler(serverCtx), + }, + { + Method: http.MethodPut, + Path: "/dictItem", + Handler: dictionary.EditDictItemHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/dictItem/:id", + Handler: dictionary.DeleteDictItemHandler(serverCtx), + }, + }, + rest.WithPrefix("/pcm/v1"), + ) } diff --git a/api/internal/logic/dictionary/adddictitemlogic.go b/api/internal/logic/dictionary/adddictitemlogic.go new file mode 100644 index 00000000..22f8f667 --- /dev/null +++ b/api/internal/logic/dictionary/adddictitemlogic.go @@ -0,0 +1,56 @@ +package dictionary + +import ( + "context" + "github.com/pkg/errors" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + "gorm.io/gorm" + "time" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AddDictItemLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewAddDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDictItemLogic { + return &AddDictItemLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *AddDictItemLogic) AddDictItem(req *types.DictItemEditReq) (resp *types.DictItemResp, err error) { + dict := &types.DictInfo{} + result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.DictId) + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return nil, errors.New("Dictionary does not exist") + } + var dictItem types.DictItemInfo + dictItem.DictId = req.DictId + dictItem.ItemText = req.ItemText + dictItem.ItemValue = req.ItemValue + dictItem.Description = req.Description + dictItem.SortOrder = req.SortOrder + dictItem.Type = req.Type + if req.ParentId != "" { + dictItem.ParentId = req.ParentId + } + dictItem.ParentId = "0" + dictItem.Status = req.Status + dictItem.Id = utils.GenSnowflakeIDStr() + dictItem.CreateTime = time.Now().Format("2006-01-02 15:04:05") + result = l.svcCtx.DbEngin.Table("t_dict_item").Create(&dictItem) + if result.Error != nil { + logx.Errorf("Failed to create dictionary item , errors: %s", result.Error) + return nil, result.Error + } + return +} diff --git a/api/internal/logic/dictionary/adddictlogic.go b/api/internal/logic/dictionary/adddictlogic.go new file mode 100644 index 00000000..fa8b01bd --- /dev/null +++ b/api/internal/logic/dictionary/adddictlogic.go @@ -0,0 +1,43 @@ +package dictionary + +import ( + "context" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + "time" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AddDictLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewAddDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDictLogic { + return &AddDictLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *AddDictLogic) AddDict(req *types.DictEditReq) (resp *types.DictResp, err error) { + dict := &types.DictInfo{} + dict.DictName = req.DictName + dict.DictCode = req.DictCode + dict.Type = req.Type + dict.Description = req.Description + dict.Id = utils.GenSnowflakeIDStr() + dict.CreateTime = time.Now().Format("2006-01-02 15:04:05") + dict.Status = req.Status + result := l.svcCtx.DbEngin.Table("t_dict").Create(&dict) + if result.Error != nil { + logx.Errorf("Failed to create dictionary , errors: %s", result.Error) + return nil, result.Error + } + return +} diff --git a/api/internal/logic/dictionary/deletedictitemlogic.go b/api/internal/logic/dictionary/deletedictitemlogic.go new file mode 100644 index 00000000..a65a5069 --- /dev/null +++ b/api/internal/logic/dictionary/deletedictitemlogic.go @@ -0,0 +1,39 @@ +package dictionary + +import ( + "context" + "github.com/pkg/errors" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DeleteDictItemLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDeleteDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictItemLogic { + return &DeleteDictItemLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteDictItemLogic) DeleteDictItem(req *types.CId) (resp *types.DictItemResp, err error) { + db := l.svcCtx.DbEngin.Table("t_dict_item").Where("id = ?", req.Id).First(&types.DictItemInfo{}) + if db.Error != nil { + logx.Errorf("err %v", db.Error.Error()) + return nil, errors.New("Dictionary item does not exist") + } + tx := l.svcCtx.DbEngin.Table("t_dict_item").Delete(types.DictItemInfo{}, req.Id) + if tx.Error != nil { + logx.Errorf("err %v", db.Error.Error()) + return nil, errors.New("Delete dictionary item failed") + } + return +} diff --git a/api/internal/logic/dictionary/deletedictlogic.go b/api/internal/logic/dictionary/deletedictlogic.go new file mode 100644 index 00000000..47eb68f8 --- /dev/null +++ b/api/internal/logic/dictionary/deletedictlogic.go @@ -0,0 +1,43 @@ +package dictionary + +import ( + "context" + "github.com/pkg/errors" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DeleteDictLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDeleteDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictLogic { + return &DeleteDictLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteDictLogic) DeleteDict(req *types.CId) (resp *types.DictResp, err error) { + var sId int64 + l.svcCtx.DbEngin.Table("t_dict").Raw("select d.id from t_dict_item di left join t_dict d on di.dict_id=d.id where d.id=? limit 1", req.Id).Scan(&sId) + if sId != 0 { + return nil, errors.New("Delete failed,The dictionary is associated with a dictionary item") + } + db := l.svcCtx.DbEngin.Table("t_dict").Where("id = ?", req.Id).First(&types.DictInfo{}) + if db.Error != nil { + logx.Errorf("err %v", db.Error.Error()) + return nil, errors.New("Dictionary does not exist") + } + tx := l.svcCtx.DbEngin.Table("t_dict").Delete(types.DictInfo{}, req.Id) + if tx.Error != nil { + logx.Errorf("err %v", db.Error.Error()) + return nil, errors.New("Delete dictionary failed") + } + return +} diff --git a/api/internal/logic/dictionary/editdictitemlogic.go b/api/internal/logic/dictionary/editdictitemlogic.go new file mode 100644 index 00000000..1960a483 --- /dev/null +++ b/api/internal/logic/dictionary/editdictitemlogic.go @@ -0,0 +1,38 @@ +package dictionary + +import ( + "context" + "github.com/pkg/errors" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + "gorm.io/gorm" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type EditDictItemLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewEditDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditDictItemLogic { + return &EditDictItemLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *EditDictItemLogic) EditDictItem(req *types.DictItemEditReq) (resp *types.DictItemResp, err error) { + dictItem := &types.DictItemInfo{} + result := l.svcCtx.DbEngin.Table("t_dict_item").First(&dictItem, req.Id) + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return nil, errors.New("DictItem does not exist") + } + utils.Convert(req, &dictItem) + l.svcCtx.DbEngin.Table("t_dict_item").Model(&dictItem).Updates(&dictItem) + return +} diff --git a/api/internal/logic/dictionary/editdictlogic.go b/api/internal/logic/dictionary/editdictlogic.go new file mode 100644 index 00000000..26e6930b --- /dev/null +++ b/api/internal/logic/dictionary/editdictlogic.go @@ -0,0 +1,40 @@ +package dictionary + +import ( + "context" + "fmt" + "github.com/pkg/errors" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + "gorm.io/gorm" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type EditDictLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewEditDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditDictLogic { + return &EditDictLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *EditDictLogic) EditDict(req *types.DictEditReq) (resp *types.DictResp, err error) { + dict := &types.DictInfo{} + result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.Id) + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return nil, errors.New("Dict does not exist") + } + utils.Convert(req, &dict) + tx := l.svcCtx.DbEngin.Table("t_dict").Model(&dict).Updates(&dict) + fmt.Println(tx) + return +} diff --git a/api/internal/logic/dictionary/getdictitemlogic.go b/api/internal/logic/dictionary/getdictitemlogic.go new file mode 100644 index 00000000..3fa71aec --- /dev/null +++ b/api/internal/logic/dictionary/getdictitemlogic.go @@ -0,0 +1,38 @@ +package dictionary + +import ( + "context" + "github.com/pkg/errors" + tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetDictItemLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictItemLogic { + return &GetDictItemLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDictItemLogic) GetDictItem(req *types.CId) (resp *types.DictItemResp, err error) { + resp = &types.DictItemResp{} + item := &types.DictItemInfo{} + db := l.svcCtx.DbEngin.Table("t_dict_item").Where("id = ?", req.Id).First(&item) + if db.Error != nil { + logx.Errorf("err %v", db.Error.Error()) + return nil, errors.New("Dictionary item does not exist") + } + tool.Convert(item, &resp) + return +} diff --git a/api/internal/logic/dictionary/getdictlogic.go b/api/internal/logic/dictionary/getdictlogic.go new file mode 100644 index 00000000..cb230204 --- /dev/null +++ b/api/internal/logic/dictionary/getdictlogic.go @@ -0,0 +1,38 @@ +package dictionary + +import ( + "context" + "github.com/pkg/errors" + tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetDictLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictLogic { + return &GetDictLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDictLogic) GetDict(req *types.CId) (resp *types.DictResp, err error) { + resp = &types.DictResp{} + dict := &types.DictInfo{} + db := l.svcCtx.DbEngin.Table("t_dict").Where("id = ?", req.Id).First(&dict) + if db.Error != nil { + logx.Errorf("err %v", db.Error.Error()) + return nil, errors.New("Dictionary does not exist") + } + tool.Convert(dict, &resp) + return +} diff --git a/api/internal/logic/dictionary/listdictitemlogic.go b/api/internal/logic/dictionary/listdictitemlogic.go new file mode 100644 index 00000000..2179aeec --- /dev/null +++ b/api/internal/logic/dictionary/listdictitemlogic.go @@ -0,0 +1,39 @@ +package dictionary + +import ( + "context" + "fmt" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ListDictItemLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewListDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictItemLogic { + return &ListDictItemLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.DictItems, err error) { + resp = &types.DictItems{} + sql := fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null ORDER BY create_time Desc`) + if req.ItemText != "" { + sql = fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null and c.item_text like '%%%s%%'`, req.ItemText) + } + tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List) + if tx.Error != nil { + logx.Errorf(tx.Error.Error()) + return nil, tx.Error + } + return resp, nil +} diff --git a/api/internal/logic/dictionary/listdictlogic.go b/api/internal/logic/dictionary/listdictlogic.go new file mode 100644 index 00000000..15959cef --- /dev/null +++ b/api/internal/logic/dictionary/listdictlogic.go @@ -0,0 +1,39 @@ +package dictionary + +import ( + "context" + "fmt" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ListDictLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewListDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictLogic { + return &ListDictLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.Dicts, err error) { + resp = &types.Dicts{} + sqlStr := "select * from t_dict where `deleted_at` IS NULL ORDER BY create_time Desc" + if req.DictName != "" { + sqlStr = fmt.Sprintf("select * from t_dict where `deleted_at` IS NULL and dict_name like '%%%s%%' ORDER BY create_time Desc", req.DictName) + } + tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List) + if tx.Error != nil { + logx.Errorf(tx.Error.Error()) + return nil, tx.Error + } + return resp, nil +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 7073c61b..ed84c8ae 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -787,6 +787,112 @@ type ClusterRelationInfo struct { CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"` } +type DictInfo struct { + Id string `json:"id,omitempty"` + DictName string `json:"dictName,omitempty"` + DictCode string `json:"dictCode,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty" db:"type"` + Status string `json:"status,omitempty" db:"status"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` +} + +type DictReq struct { + Id string `form:"id,optional"` + DictName string `form:"dictName,optional"` + DictCode string `form:"dictCode,optional"` + Description string `form:"description,optional"` + Type string `form:"type,optional"` + Status string `form:"status,optional"` +} + +type DictEditReq struct { + Id string `json:"id,optional"` + DictName string `json:"dictName,optional"` + DictCode string `json:"dictCode,optional"` + Description string `json:"description,optional"` + Type string `json:"type,optional"` + Status string `json:"status,optional"` +} + +type DictResp struct { + Id string `json:"id,omitempty"` + DictName string `json:"dictName,omitempty"` + DictCode string `json:"dictCode,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` + Status string `json:"status,omitempty"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + DictItemInfo []*DictItemInfo `json:"dictItemInfo,omitempty"` +} + +type Dicts struct { + List []DictInfo `json:"list,omitempty"` +} + +type DictItemInfo struct { + Id string `json:"id,omitempty"` + DictId string `json:"dictId,omitempty"` + ItemText string `json:"itemText,omitempty"` + ItemValue string `json:"itemValue,omitempty"` + Description string `json:"description,omitempty"` + SortOrder string `json:"sortOrder,omitempty"` + Type string `json:"type,omitempty" db:"type"` + ParentId string `json:"parentId,omitempty"` + Status string `json:"status,omitempty" db:"status"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` +} + +type DictItemReq struct { + Id string `form:"id,optional"` + DictId string `form:"dictId,optional"` + ItemText string `form:"itemText,optional"` + ItemValue string `form:"itemValue,optional"` + Description string `form:"description,optional"` + SortOrder string `form:"sortOrder,optional"` + Type string `form:"type,optional"` + ParentId string `form:"parentId,optional"` + Status string `form:"status,optional"` +} + +type DictItemEditReq struct { + Id string `json:"id,optional"` + DictId string `json:"dictId,optional"` + ItemText string `json:"itemText,optional"` + ItemValue string `json:"itemValue,optional"` + Description string `json:"description,optional"` + SortOrder string `json:"sortOrder,optional"` + Type string `json:"type,optional"` + ParentId string `json:"parentId,optional"` + Status string `json:"status,optional"` +} + +type DictItemResp struct { + Id string `json:"id,omitempty"` + DictId string `json:"dictId,omitempty"` + ItemText string `json:"itemText,omitempty"` + ItemValue string `json:"itemValue,omitempty"` + Description string `json:"description,omitempty"` + SortOrder string `json:"sortOrder,omitempty"` + Type string `json:"type,omitempty"` + ParentId string `json:"parentId,omitempty"` + Status string `json:"status,omitempty"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + DictInfo *DictInfo `json:"dictInfo,omitempty"` +} + +type DictItems struct { + List []DictItemInfo `json:"list,omitempty"` +} + +type CId struct { + Id string `path:"id":"id,omitempty" validate:"required"` +} + +type CIds struct { + Ids []string `json:"ids,omitempty" validate:"required"` +} + type Job struct { SlurmVersion string `json:"slurmVersion"` Name string `json:"name"` From 9824a3e38a508f951441a5f78b8f9b43c462e883 Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Tue, 12 Mar 2024 15:13:30 +0800 Subject: [PATCH 4/5] hpc job submit Former-commit-id: b8bbe255f022d1a2ea7ce405bf3ed3378210451d --- api/desc/core/pcm-core.api | 166 ---------------- api/desc/hpc/pcm-hpc.api | 31 +++ api/desc/pcm.api | 14 +- api/etc/pcm.yaml | 2 +- api/internal/handler/core/submitjobhandler.go | 42 ----- .../{core => hpc}/commithpctaskhandler.go | 6 +- api/internal/logic/core/submitjoblogic.go | 84 --------- api/internal/logic/hpc/commithpctasklogic.go | 86 +++++++++ api/internal/types/types.go | 178 +++--------------- pkg/models/taskhpcmodel.go | 29 +++ pkg/models/taskhpcmodel_gen.go | 121 ++++++++++++ pkg/tracker/tracker_test.go | 11 +- 12 files changed, 307 insertions(+), 463 deletions(-) delete mode 100644 api/internal/handler/core/submitjobhandler.go rename api/internal/handler/{core => hpc}/commithpctaskhandler.go (81%) delete mode 100644 api/internal/logic/core/submitjoblogic.go create mode 100644 api/internal/logic/hpc/commithpctasklogic.go create mode 100644 pkg/models/taskhpcmodel.go create mode 100644 pkg/models/taskhpcmodel_gen.go diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 87a531a6..2e6d0435 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -7,142 +7,6 @@ info( email: "450705171@qq.com" ) -type ( - submitJobReq { - SlurmVersion string `json:"slurmVersion"` - - /****************parmas from ac********************/ - Apptype string `json:"apptype,optional"` - Appname string `json:"appname,optional"` - StrJobManagerID int64 `json:"strJobManagerID,optional"` - MapAppJobInfo MapAppJobInfo `json:"mapAppJobInfo,optional"` - /****************parmas from ac********************/ - - Account string `json:"account,optional"` // - Acctg_freq string `json:"acctg_freq,optional"` - Alloc_node string `json:"alloc_node,optional"` - Alloc_resp_port int32 `json:"alloc_resp_port,optional"` - Alloc_sid int32 `json:"alloc_sid,optional"` - Argc int32 `json:"argc,optional"` - Argv []Argv `json:"Argv,optional"` - Array_inx string `json:"array_inx,optional"` - Begin_time int64 `json:"begin_time,optional"` - Ckpt_interval int32 `json:"ckpt_interval,optional"` - Ckpt_dir string `json:"ckpt_dir,optional"` - Comment string `json:"comment,optional"` - Contiguous int32 `json:"contiguous,optional"` - Cpu_bind string `json:"cpu_bind,optional"` - Cpu_bind_type int32 `json:"cpu_bind_type,optional"` - Dependency string `json:"dependency,optional"` - End_time int64 `json:"end_time,optional"` - Environment []Environment `json:"Environment,optional"` - Env_size int32 `json:"env_size,optional"` - Exc_nodes string `json:"exc_nodes,optional"` - Features string `json:"features,optional"` - Gres string `json:"gres,optional"` - Group_id int32 `json:"group_id,optional"` - Immediate int32 `json:"immediate,optional"` - Job_id int32 `json:"job_id,optional"` - Kill_on_node_fail int32 `json:"kill_on_node_fail,optional"` - Licenses string `json:"licenses,optional"` - Mail_type int32 `json:"mail_type,optional"` - Mail_user string `json:"mail_user,optional"` - Mem_bind string `json:"mem_bind,optional"` - Mem_bind_type int32 `json:"mem_bind_type,optional"` - Name string `json:"name,optional"` // - Network string `json:"network,optional"` - Nice int32 `json:"nice,optional"` - Num_tasks int32 `json:"num_tasks,optional"` - Open_mode int32 `json:"open_mode,optional"` - Other_port int32 `json:"other_port,optional"` - Overcommit int32 `json:"overcommit,optional"` - Partition string `json:"partition,optional"` - Plane_size int32 `json:"plane_size,optional"` - Priority int32 `json:"priority,optional"` - Profile int32 `json:"profile,optional"` - Qos string `json:"qos,optional"` - Resp_host string `json:"resp_host,optional"` - Req_nodes string `json:"req_nodes,optional"` - Requeue int32 `json:"requeue,optional"` - Reservation string `json:"reservation,optional"` - Script string `json:"script,optional"` // - Shared int32 `json:"shared,optional"` - Spank_job_env_size int32 `json:"spank_job_env_size,optional"` - Task_dist int32 `json:"task_dist,optional"` - Time_limit int32 `json:"time_limit,optional"` - Time_min int32 `json:"time_min,optional"` - User_id int32 `json:"user_id,optional"` // - Wait_all_nodes int32 `json:"wait_all_nodes,optional"` - Warn_signal int32 `json:"warn_signal,optional"` - Warn_time int32 `json:"warn_time,optional"` - Work_dir string `json:"work_dir,optional"` - Cpus_per_task int32 `json:"cpus_per_task,optional"` - Min_cpus int32 `json:"min_cpus,optional"` // - Max_cpus int32 `json:"max_cpus,optional"` - Min_nodes int32 `json:"min_nodes,optional"` - Max_nodes int32 `json:"max_nodes,optional"` - Boards_per_node int32 `json:"boards_per_node,optional"` - Sockets_per_board int32 `json:"sockets_per_board,optional"` - Sockets_per_node int32 `json:"sockets_per_node,optional"` - Cores_per_socket int32 `json:"cores_per_socket,optional"` - Threads_per_core int32 `json:"threads_per_core,optional"` - Ntasks_per_node int32 `json:"ntasks_per_node,optional"` - Ntasks_per_socket int32 `json:"ntasks_per_socket,optional"` - Ntasks_per_core int32 `json:"ntasks_per_core,optional"` - Ntasks_per_board int32 `json:"ntasks_per_board,optional"` - Pn_min_cpus int32 `json:"pn_min_cpus,optional"` - Pn_min_memory int32 `json:"pn_min_memory,optional"` - Pn_min_tmp_disk int32 `json:"pn_min_tmp_disk,optional"` - Reboot int32 `json:"reboot,optional"` - Rotate int32 `json:"rotate,optional"` - Req_switch int32 `json:"req_switch,optional"` - Std_err string `json:"std_err,optional"` - Std_in string `json:"std_in,optional"` - Std_out string `json:"std_out,optional"` - Wait4switch int32 `json:"wait4switch,optional"` - Wckey string `json:"wckey,optional"` - } - - submitJobResp { - //Job_id int32 `json:"job_id"` - //Step_id int32 `json:"step_id"` - //Error_code int32 `json:"error_code"` - - Code string `json:"code"` //Error_code 返回码 in Tianhe - Msg string `json:"msg"` - Data string `json:"data"` //Job_id 作业id in Tianhe - } - - MapAppJobInfo { - GAP_CMD_FILE string `json:"GAP_CMD_FILE"` //命令行内容 - GAP_NNODE string `json:"GAP_NNODE"` //节点个数(当指定该参数时,GAP_NODE_STRING必须为"") - GAP_NODE_STRING string `json:"GAP_NODE_STRING,optional"` //指定节点(当指定该参数时,GAP_NNODE必须为"") - GAP_SUBMIT_TYPE string `json:"GAP_SUBMIT_TYPE"` //cmd(命令行模式) - GAP_JOB_NAME string `json:"GAP_JOB_NAME"` //作业名称 - GAP_WORK_DIR string `json:"GAP_WORK_DIR"` //工作路径 - GAP_QUEUE string `json:"GAP_QUEUE"` //队列名称 - GAP_NPROC string `json:"GAP_NPROC,optional"` //总核心数(GAP_NPROC和GAP_PPN选其一填写) - GAP_PPN string `json:"GAP_PPN,optional"` //CPU核心/节点(GAP_NPROC和GAP_PPN选其一填写) - GAP_NGPU string `json:"GAP_NGPU,optional"` //GPU卡数/节点 - GAP_NDCU string `json:"GAP_NDCU,optional"` //DCU卡数/节点 - GAP_JOB_MEM string `json:"GAP_JOB_MEM,optional"` //每个节点内存值,单位为MB/GB - GAP_WALL_TIME string `json:"GAP_WALL_TIME"` //最大运行时长(HH:MM:ss) - GAP_EXCLUSIVE string `json:"GAP_EXCLUSIVE,optional"` // 是否独占节点,1为独占,空为非独占 - GAP_APPNAME string `json:"GAP_APPNAME"` //BASE(基础应用),支持填写具体的应用英文名称 - GAP_MULTI_SUB string `json:"GAP_MULTI_SUB,optional"` //作业组长度,建议为小于等于50的正整数 - GAP_STD_OUT_FILE string `json:"GAP_STD_OUT_FILE"` //工作路径/std.out.%j - GAP_STD_ERR_FILE string `json:"GAP_STD_ERR_FILE"` //工作路径/std.err.%j - } - - Argv { - Argv string `json:"argv,optional"` - } - - Environment { - Environment string `json:"environment,optional"` - } -) - type ( getRegionResp { Code int32 `json:"code"` @@ -221,36 +85,6 @@ type ( } ) -type ( - commitHpcTaskReq { - Name string `json:"name"` - Description string `json:"description,optional"` - tenantId int64 `json:"tenantId,optional"` - TaskId int64 `json:"taskId,optional"` - participantId int64 `json:"participantId,optional"` - matchLabels map[string]string `json:"matchLabels,optional"` - cardCount int64 `json:"cardCount,optional"` - workDir string `json:"workDir,optional"` - wallTime string `json:"wallTime,optional"` - cmdScript string `json:"cmdScript,optional"` - appType string `json:"appType,optional"` - appName string `json:"appName,optional"` - queue string `json:"queue,optional"` - nNode string `json:"nNode,optional"` - submitType string `json:"submitType,optional"` - stdOutFile string `json:"stdOutFile,optional"` - stdErrFile string `json:"stdErrFile,optional"` - stdInput string `json:"stdInput,optional"` - environment map[string]string `json:"environment,optional"` - } -) - -type ( - commitHpcTaskResp { - TaskId int64 `json:"taskId"` - } -) - type ( commitVmTaskReq { server ServerCommit `json:"server,optional"` diff --git a/api/desc/hpc/pcm-hpc.api b/api/desc/hpc/pcm-hpc.api index 2ced78d2..38f0ed08 100644 --- a/api/desc/hpc/pcm-hpc.api +++ b/api/desc/hpc/pcm-hpc.api @@ -16,6 +16,37 @@ type Job { StateofJob string `json:"StateofJob"` } + +type ( + commitHpcTaskReq { + Name string `json:"name"` // paratera:jobName + Description string `json:"description,optional"` + tenantId int64 `json:"tenantId,optional"` + TaskId int64 `json:"taskId,optional"` + participantId int64 `json:"participantId,optional"` + matchLabels map[string]string `json:"matchLabels,optional"` + cardCount int64 `json:"cardCount,optional"` + workDir string `json:"workDir,optional"` //paratera:workingDir + wallTime string `json:"wallTime,optional"` + cmdScript string `json:"cmdScript,optional"` // paratera:bootScript + appType string `json:"appType,optional"` + appName string `json:"appName,optional"` // paratera:jobGroupName ac:appname + queue string `json:"queue,optional"` + nNode string `json:"nNode,optional"` + submitType string `json:"submitType,optional"` + stdOutFile string `json:"stdOutFile,optional"` + stdErrFile string `json:"stdErrFile,optional"` + stdInput string `json:"stdInput,optional"` + environment map[string]string `json:"environment,optional"` + } +) + +type ( + commitHpcTaskResp { + TaskId int64 `json:"taskId"` + } +) + type ( listJobReq { } diff --git a/api/desc/pcm.api b/api/desc/pcm.api index f082f3f2..a5fdc00f 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -37,10 +37,6 @@ service pcm { @handler commitTaskHandler post /core/commitTask (commitTaskReq) - @doc "提交超算任务" - @handler commitHpcTaskHandler - post /core/commitHpcTask (commitHpcTaskReq) returns (commitHpcTaskResp) - @doc "提交虚拟机任务" @handler commitVmTaskHandler post /core/commitVmTask (commitVmTaskReq) returns (commitVmTaskResp) @@ -69,10 +65,6 @@ service pcm { @handler listClusterHandler get /core/listCluster/:centerId (listClusterReq) returns (listClusterResp) - @doc "提交任务(超算)" - @handler submitJobHandler - post /core/submitJob (submitJobReq) returns (submitJobResp) - @doc "获取region" @handler getRegionHandler get /core/getRegion returns (getRegionResp) @@ -120,6 +112,10 @@ service pcm { group : hpc ) service pcm { + @doc "提交超算任务" + @handler commitHpcTaskHandler + post /hpc/commitHpcTask (commitHpcTaskReq) returns (commitHpcTaskResp) + @doc "超算查询任务列表" @handler listJobHandler get /hpc/listJob (listJobReq) returns (listJobResp) @@ -130,7 +126,7 @@ service pcm { @doc "超算查询资产列表" @handler queueAssetsHandler - get /queue/assets returns (QueueAssetsResp) + get /hpc/queueAssets returns (QueueAssetsResp) } //cloud二级接口 diff --git a/api/etc/pcm.yaml b/api/etc/pcm.yaml index 11d07339..32e7b269 100644 --- a/api/etc/pcm.yaml +++ b/api/etc/pcm.yaml @@ -5,7 +5,7 @@ Port: 8999 Timeout: 50000 DB: - DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true&loc=Local + DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true&loc=Local Redis: Host: 10.206.0.12:6379 diff --git a/api/internal/handler/core/submitjobhandler.go b/api/internal/handler/core/submitjobhandler.go deleted file mode 100644 index a719d73e..00000000 --- a/api/internal/handler/core/submitjobhandler.go +++ /dev/null @@ -1,42 +0,0 @@ -/* - - Copyright (c) [2023] [pcm] - [pcm-coordinator] is licensed under Mulan PSL v2. - You can use this software according to the terms and conditions of the Mulan PSL v2. - You may obtain a copy of Mulan PSL v2 at: - http://license.coscl.org.cn/MulanPSL2 - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - See the Mulan PSL v2 for more details. - -*/ - -package core - -import ( - "net/http" - - "github.com/zeromicro/go-zero/rest/httpx" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" -) - -func SubmitJobHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.SubmitJobReq - if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) - return - } - - l := core.NewSubmitJobLogic(r.Context(), svcCtx) - resp, err := l.SubmitJob(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } - } -} diff --git a/api/internal/handler/core/commithpctaskhandler.go b/api/internal/handler/hpc/commithpctaskhandler.go similarity index 81% rename from api/internal/handler/core/commithpctaskhandler.go rename to api/internal/handler/hpc/commithpctaskhandler.go index 3d3d1892..a2043def 100644 --- a/api/internal/handler/core/commithpctaskhandler.go +++ b/api/internal/handler/hpc/commithpctaskhandler.go @@ -1,10 +1,10 @@ -package core +package hpc import ( "net/http" "github.com/zeromicro/go-zero/rest/httpx" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/hpc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" ) @@ -17,7 +17,7 @@ func CommitHpcTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := core.NewCommitHpcTaskLogic(r.Context(), svcCtx) + l := hpc.NewCommitHpcTaskLogic(r.Context(), svcCtx) resp, err := l.CommitHpcTask(&req) if err != nil { httpx.ErrorCtx(r.Context(), w, err) diff --git a/api/internal/logic/core/submitjoblogic.go b/api/internal/logic/core/submitjoblogic.go deleted file mode 100644 index 2d699753..00000000 --- a/api/internal/logic/core/submitjoblogic.go +++ /dev/null @@ -1,84 +0,0 @@ -/* - - Copyright (c) [2023] [pcm] - [pcm-coordinator] is licensed under Mulan PSL v2. - You can use this software according to the terms and conditions of the Mulan PSL v2. - You may obtain a copy of Mulan PSL v2 at: - http://license.coscl.org.cn/MulanPSL2 - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - See the Mulan PSL v2 for more details. - -*/ - -package core - -import ( - "context" - "github.com/jinzhu/copier" - "github.com/pkg/errors" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/xerr" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" - slurmClient "gitlink.org.cn/JointCloud/pcm-slurm/slurmclient" - "gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC" - "strconv" - - "github.com/zeromicro/go-zero/core/logx" -) - -type SubmitJobLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewSubmitJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitJobLogic { - return &SubmitJobLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *SubmitJobLogic) SubmitJob(req *types.SubmitJobReq) (resp *types.SubmitJobResp, err error) { - - coreResp := &types.SubmitJobResp{} - - version := req.SlurmVersion - switch version { - case "ac": - acReq := &hpcAC.SubmitJobReq{} - err = copier.CopyWithOption(acReq, req, copier.Option{Converters: utils.Converters}) - acResp, err := l.svcCtx.ACRpc.SubmitJob(l.ctx, acReq) - - if err != nil { - return nil, errors.Wrapf(xerr.NewErrMsg("Failed to submit job to AC"), "Failed to submit job to Shuguang err : %v ,req:%+v", err, req) - } - - if acResp.Data == "" { - return nil, errors.Wrapf(xerr.NewErrMsg("Failed to submit job to AC, job id is empty"), "Failed to submit job to Shuguang err : %v", err) - } - - coreResp.Msg = acResp.Msg - coreResp.Code = acResp.Code - coreResp.Data = acResp.Data - - case "th": - thReq := &slurmClient.SubmitJobReq{} - err = copier.CopyWithOption(thReq, req, copier.Option{Converters: utils.Converters}) - tianheResp, err := l.svcCtx.THRpc.SubmitJob(l.ctx, thReq) - - if err != nil { - return nil, errors.Wrapf(xerr.NewErrMsg("Failed to submit job to Tianhe"), "Failed to submit job to Tianhe err : %v ,req:%+v", err, req) - } - - coreResp.Msg = "success" - coreResp.Code = strconv.Itoa(200) - coreResp.Data = strconv.Itoa(int(tianheResp.JobId)) - } - - return coreResp, nil -} diff --git a/api/internal/logic/hpc/commithpctasklogic.go b/api/internal/logic/hpc/commithpctasklogic.go new file mode 100644 index 00000000..d8827ce9 --- /dev/null +++ b/api/internal/logic/hpc/commithpctasklogic.go @@ -0,0 +1,86 @@ +package hpc + +import ( + "context" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" + "k8s.io/apimachinery/pkg/util/json" + "time" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CommitHpcTaskLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCommitHpcTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitHpcTaskLogic { + return &CommitHpcTaskLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) { + // 构建主任务结构体 + taskModel := models.Task{ + Status: constants.Saved, + Description: req.Description, + Name: req.Name, + CommitTime: time.Now(), + } + // 保存任务数据到数据库 + tx := l.svcCtx.DbEngin.Create(&taskModel) + if tx.Error != nil { + return nil, tx.Error + } + + env, _ := json.Marshal(req.Environment) + hpcInfo := models.TaskHpc{ + TaskId: taskModel.Id, + ClusterId: 1706858330967773111, + Name: taskModel.Name, + Status: "Saved", + CmdScript: req.CmdScript, + StartTime: time.Now().String(), + CardCount: req.CardCount, + WorkDir: req.WorkDir, + WallTime: req.WallTime, + AppType: req.AppType, + AppName: req.AppName, + Queue: req.Queue, + SubmitType: req.SubmitType, + NNode: req.NNode, + StdOutFile: req.StdOutFile, + StdErrFile: req.StdErrFile, + StdInput: req.StdInput, + DeletedFlag: 0, + CreatedBy: req.ParticipantId, + CreatedTime: time.Now(), + UpdatedBy: req.ParticipantId, + UpdatedTime: time.Now(), + Environment: string(env), + } + + tx = l.svcCtx.DbEngin.Create(&hpcInfo) + if tx.Error != nil { + return nil, tx.Error + } + // 将任务数据转换成消息体 + //reqMessage, err := json.Marshal(mqInfo) + //if err != nil { + // logx.Error(err) + // return nil, err + //} + //publish := l.svcCtx.RedisClient.Publish(context.Background(), mqInfo.TaskType, reqMessage) + //if publish.Err() != nil { + // return nil, publish.Err() + //} + return +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 361b4a4c..7d4c971c 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -1,132 +1,6 @@ // Code generated by goctl. DO NOT EDIT. package types -type SubmitJobReq struct { - SlurmVersion string `json:"slurmVersion"` - Apptype string `json:"apptype,optional"` - Appname string `json:"appname,optional"` - StrJobManagerID int64 `json:"strJobManagerID,optional"` - MapAppJobInfo MapAppJobInfo `json:"mapAppJobInfo,optional"` - Account string `json:"account,optional"` // - Acctg_freq string `json:"acctg_freq,optional"` - Alloc_node string `json:"alloc_node,optional"` - Alloc_resp_port int32 `json:"alloc_resp_port,optional"` - Alloc_sid int32 `json:"alloc_sid,optional"` - Argc int32 `json:"argc,optional"` - Argv []Argv `json:"Argv,optional"` - Array_inx string `json:"array_inx,optional"` - Begin_time int64 `json:"begin_time,optional"` - Ckpt_interval int32 `json:"ckpt_interval,optional"` - Ckpt_dir string `json:"ckpt_dir,optional"` - Comment string `json:"comment,optional"` - Contiguous int32 `json:"contiguous,optional"` - Cpu_bind string `json:"cpu_bind,optional"` - Cpu_bind_type int32 `json:"cpu_bind_type,optional"` - Dependency string `json:"dependency,optional"` - End_time int64 `json:"end_time,optional"` - Environment []Environment `json:"Environment,optional"` - Env_size int32 `json:"env_size,optional"` - Exc_nodes string `json:"exc_nodes,optional"` - Features string `json:"features,optional"` - Gres string `json:"gres,optional"` - Group_id int32 `json:"group_id,optional"` - Immediate int32 `json:"immediate,optional"` - Job_id int32 `json:"job_id,optional"` - Kill_on_node_fail int32 `json:"kill_on_node_fail,optional"` - Licenses string `json:"licenses,optional"` - Mail_type int32 `json:"mail_type,optional"` - Mail_user string `json:"mail_user,optional"` - Mem_bind string `json:"mem_bind,optional"` - Mem_bind_type int32 `json:"mem_bind_type,optional"` - Name string `json:"name,optional"` // - Network string `json:"network,optional"` - Nice int32 `json:"nice,optional"` - Num_tasks int32 `json:"num_tasks,optional"` - Open_mode int32 `json:"open_mode,optional"` - Other_port int32 `json:"other_port,optional"` - Overcommit int32 `json:"overcommit,optional"` - Partition string `json:"partition,optional"` - Plane_size int32 `json:"plane_size,optional"` - Priority int32 `json:"priority,optional"` - Profile int32 `json:"profile,optional"` - Qos string `json:"qos,optional"` - Resp_host string `json:"resp_host,optional"` - Req_nodes string `json:"req_nodes,optional"` - Requeue int32 `json:"requeue,optional"` - Reservation string `json:"reservation,optional"` - Script string `json:"script,optional"` // - Shared int32 `json:"shared,optional"` - Spank_job_env_size int32 `json:"spank_job_env_size,optional"` - Task_dist int32 `json:"task_dist,optional"` - Time_limit int32 `json:"time_limit,optional"` - Time_min int32 `json:"time_min,optional"` - User_id int32 `json:"user_id,optional"` // - Wait_all_nodes int32 `json:"wait_all_nodes,optional"` - Warn_signal int32 `json:"warn_signal,optional"` - Warn_time int32 `json:"warn_time,optional"` - Work_dir string `json:"work_dir,optional"` - Cpus_per_task int32 `json:"cpus_per_task,optional"` - Min_cpus int32 `json:"min_cpus,optional"` // - Max_cpus int32 `json:"max_cpus,optional"` - Min_nodes int32 `json:"min_nodes,optional"` - Max_nodes int32 `json:"max_nodes,optional"` - Boards_per_node int32 `json:"boards_per_node,optional"` - Sockets_per_board int32 `json:"sockets_per_board,optional"` - Sockets_per_node int32 `json:"sockets_per_node,optional"` - Cores_per_socket int32 `json:"cores_per_socket,optional"` - Threads_per_core int32 `json:"threads_per_core,optional"` - Ntasks_per_node int32 `json:"ntasks_per_node,optional"` - Ntasks_per_socket int32 `json:"ntasks_per_socket,optional"` - Ntasks_per_core int32 `json:"ntasks_per_core,optional"` - Ntasks_per_board int32 `json:"ntasks_per_board,optional"` - Pn_min_cpus int32 `json:"pn_min_cpus,optional"` - Pn_min_memory int32 `json:"pn_min_memory,optional"` - Pn_min_tmp_disk int32 `json:"pn_min_tmp_disk,optional"` - Reboot int32 `json:"reboot,optional"` - Rotate int32 `json:"rotate,optional"` - Req_switch int32 `json:"req_switch,optional"` - Std_err string `json:"std_err,optional"` - Std_in string `json:"std_in,optional"` - Std_out string `json:"std_out,optional"` - Wait4switch int32 `json:"wait4switch,optional"` - Wckey string `json:"wckey,optional"` -} - -type SubmitJobResp struct { - Code string `json:"code"` //Error_code 返回码 in Tianhe - Msg string `json:"msg"` - Data string `json:"data"` //Job_id 作业id in Tianhe -} - -type MapAppJobInfo struct { - GAP_CMD_FILE string `json:"GAP_CMD_FILE"` //命令行内容 - GAP_NNODE string `json:"GAP_NNODE"` //节点个数(当指定该参数时,GAP_NODE_STRING必须为"") - GAP_NODE_STRING string `json:"GAP_NODE_STRING,optional"` //指定节点(当指定该参数时,GAP_NNODE必须为"") - GAP_SUBMIT_TYPE string `json:"GAP_SUBMIT_TYPE"` //cmd(命令行模式) - GAP_JOB_NAME string `json:"GAP_JOB_NAME"` //作业名称 - GAP_WORK_DIR string `json:"GAP_WORK_DIR"` //工作路径 - GAP_QUEUE string `json:"GAP_QUEUE"` //队列名称 - GAP_NPROC string `json:"GAP_NPROC,optional"` //总核心数(GAP_NPROC和GAP_PPN选其一填写) - GAP_PPN string `json:"GAP_PPN,optional"` //CPU核心/节点(GAP_NPROC和GAP_PPN选其一填写) - GAP_NGPU string `json:"GAP_NGPU,optional"` //GPU卡数/节点 - GAP_NDCU string `json:"GAP_NDCU,optional"` //DCU卡数/节点 - GAP_JOB_MEM string `json:"GAP_JOB_MEM,optional"` //每个节点内存值,单位为MB/GB - GAP_WALL_TIME string `json:"GAP_WALL_TIME"` //最大运行时长(HH:MM:ss) - GAP_EXCLUSIVE string `json:"GAP_EXCLUSIVE,optional"` // 是否独占节点,1为独占,空为非独占 - GAP_APPNAME string `json:"GAP_APPNAME"` //BASE(基础应用),支持填写具体的应用英文名称 - GAP_MULTI_SUB string `json:"GAP_MULTI_SUB,optional"` //作业组长度,建议为小于等于50的正整数 - GAP_STD_OUT_FILE string `json:"GAP_STD_OUT_FILE"` //工作路径/std.out.%j - GAP_STD_ERR_FILE string `json:"GAP_STD_ERR_FILE"` //工作路径/std.err.%j -} - -type Argv struct { - Argv string `json:"argv,optional"` -} - -type Environment struct { - Environment string `json:"environment,optional"` -} - type GetRegionResp struct { Code int32 `json:"code"` Msg string `json:"msg"` @@ -202,32 +76,6 @@ type TaskYaml struct { Metadata interface{} `yaml:"metadata"` } -type CommitHpcTaskReq struct { - Name string `json:"name"` - Description string `json:"description,optional"` - TenantId int64 `json:"tenantId,optional"` - TaskId int64 `json:"taskId,optional"` - ParticipantId int64 `json:"participantId,optional"` - MatchLabels map[string]string `json:"matchLabels,optional"` - CardCount int64 `json:"cardCount,optional"` - WorkDir string `json:"workDir,optional"` - WallTime string `json:"wallTime,optional"` - CmdScript string `json:"cmdScript,optional"` - AppType string `json:"appType,optional"` - AppName string `json:"appName,optional"` - Queue string `json:"queue,optional"` - NNode string `json:"nNode,optional"` - SubmitType string `json:"submitType,optional"` - StdOutFile string `json:"stdOutFile,optional"` - StdErrFile string `json:"stdErrFile,optional"` - StdInput string `json:"stdInput,optional"` - Environment map[string]string `json:"environment,optional"` -} - -type CommitHpcTaskResp struct { - TaskId int64 `json:"taskId"` -} - type CommitVmTaskReq struct { Server ServerCommit `json:"server,optional"` Platform string `json:"platform,optional"` @@ -902,6 +750,32 @@ type Job struct { StateofJob string `json:"StateofJob"` } +type CommitHpcTaskReq struct { + Name string `json:"name"` // paratera:jobName + Description string `json:"description,optional"` + TenantId int64 `json:"tenantId,optional"` + TaskId int64 `json:"taskId,optional"` + ParticipantId int64 `json:"participantId,optional"` + MatchLabels map[string]string `json:"matchLabels,optional"` + CardCount int64 `json:"cardCount,optional"` + WorkDir string `json:"workDir,optional"` //paratera:workingDir + WallTime string `json:"wallTime,optional"` + CmdScript string `json:"cmdScript,optional"` // paratera:bootScript + AppType string `json:"appType,optional"` + AppName string `json:"appName,optional"` // paratera:jobGroupName ac:appname + Queue string `json:"queue,optional"` + NNode string `json:"nNode,optional"` + SubmitType string `json:"submitType,optional"` + StdOutFile string `json:"stdOutFile,optional"` + StdErrFile string `json:"stdErrFile,optional"` + StdInput string `json:"stdInput,optional"` + Environment map[string]string `json:"environment,optional"` +} + +type CommitHpcTaskResp struct { + TaskId int64 `json:"taskId"` +} + type ListJobReq struct { } diff --git a/pkg/models/taskhpcmodel.go b/pkg/models/taskhpcmodel.go new file mode 100644 index 00000000..0088303b --- /dev/null +++ b/pkg/models/taskhpcmodel.go @@ -0,0 +1,29 @@ +package models + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ TaskHpcModel = (*customTaskHpcModel)(nil) + +type ( + // TaskHpcModel is an interface to be customized, add more methods here, + // and implement the added methods in customTaskHpcModel. + TaskHpcModel interface { + taskHpcModel + withSession(session sqlx.Session) TaskHpcModel + } + + customTaskHpcModel struct { + *defaultTaskHpcModel + } +) + +// NewTaskHpcModel returns a model for the database table. +func NewTaskHpcModel(conn sqlx.SqlConn) TaskHpcModel { + return &customTaskHpcModel{ + defaultTaskHpcModel: newTaskHpcModel(conn), + } +} + +func (m *customTaskHpcModel) withSession(session sqlx.Session) TaskHpcModel { + return NewTaskHpcModel(sqlx.NewSqlConnFromSession(session)) +} diff --git a/pkg/models/taskhpcmodel_gen.go b/pkg/models/taskhpcmodel_gen.go new file mode 100644 index 00000000..9e2fc1cb --- /dev/null +++ b/pkg/models/taskhpcmodel_gen.go @@ -0,0 +1,121 @@ +// Code generated by goctl. DO NOT EDIT. + +package models + +import ( + "context" + "database/sql" + "fmt" + "strings" + "time" + + "github.com/zeromicro/go-zero/core/stores/builder" + "github.com/zeromicro/go-zero/core/stores/sqlc" + "github.com/zeromicro/go-zero/core/stores/sqlx" + "github.com/zeromicro/go-zero/core/stringx" +) + +var ( + taskHpcFieldNames = builder.RawFieldNames(&TaskHpc{}) + taskHpcRows = strings.Join(taskHpcFieldNames, ",") + taskHpcRowsExpectAutoSet = strings.Join(stringx.Remove(taskHpcFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + taskHpcRowsWithPlaceHolder = strings.Join(stringx.Remove(taskHpcFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + taskHpcModel interface { + Insert(ctx context.Context, data *TaskHpc) (sql.Result, error) + FindOne(ctx context.Context, id int64) (*TaskHpc, error) + Update(ctx context.Context, data *TaskHpc) error + Delete(ctx context.Context, id int64) error + } + + defaultTaskHpcModel struct { + conn sqlx.SqlConn + table string + } + + TaskHpc struct { + Id int64 `db:"id"` // id + TaskId int64 `db:"task_id"` // 任务id + JobId string `db:"job_id"` // 作业id(在第三方系统中的作业id) + ClusterId int64 `db:"cluster_id"` // 执行任务的集群id + Name string `db:"name"` // 名称 + Status string `db:"status"` // 状态 + CmdScript string `db:"cmd_script"` + StartTime string `db:"start_time"` // 开始时间 + RunningTime int64 `db:"running_time"` // 运行时间 + DerivedEs string `db:"derived_es"` + Cluster string `db:"cluster"` + BlockId int64 `db:"block_id"` + AllocNodes int64 `db:"alloc_nodes"` + AllocCpu int64 `db:"alloc_cpu"` + CardCount int64 `db:"card_count"` // 卡数 + Version string `db:"version"` + Account string `db:"account"` + WorkDir string `db:"work_dir"` // 工作路径 + AssocId int64 `db:"assoc_id"` + ExitCode int64 `db:"exit_code"` + WallTime string `db:"wall_time"` // 最大运行时间 + Result string `db:"result"` // 运行结果 + DeletedAt sql.NullTime `db:"deleted_at"` // 删除时间 + YamlString string `db:"yaml_string"` + AppType string `db:"app_type"` // 应用类型 + AppName string `db:"app_name"` // 应用名称 + Queue string `db:"queue"` // 队列名称 + SubmitType string `db:"submit_type"` // cmd(命令行模式) + NNode string `db:"n_node"` // 节点个数(当指定该参数时,GAP_NODE_STRING必须为"") + StdOutFile string `db:"std_out_file"` // 工作路径/std.err.%j + StdErrFile string `db:"std_err_file"` // 工作路径/std.err.%j + StdInput string `db:"std_input"` + Environment string `db:"environment"` + DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是) + CreatedBy int64 `db:"created_by"` // 创建人 + CreatedTime time.Time `db:"created_time"` // 创建时间 + UpdatedBy int64 `db:"updated_by"` // 更新人 + UpdatedTime time.Time `db:"updated_time"` // 更新时间 + } +) + +func newTaskHpcModel(conn sqlx.SqlConn) *defaultTaskHpcModel { + return &defaultTaskHpcModel{ + conn: conn, + table: "`task_hpc`", + } +} + +func (m *defaultTaskHpcModel) Delete(ctx context.Context, id int64) error { + query := fmt.Sprintf("delete from %s where `id` = ?", m.table) + _, err := m.conn.ExecCtx(ctx, query, id) + return err +} + +func (m *defaultTaskHpcModel) FindOne(ctx context.Context, id int64) (*TaskHpc, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", taskHpcRows, m.table) + var resp TaskHpc + err := m.conn.QueryRowCtx(ctx, &resp, query, id) + switch err { + case nil: + return &resp, nil + case sqlc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultTaskHpcModel) Insert(ctx context.Context, data *TaskHpc) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskHpcRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.JobId, data.ClusterId, data.Name, data.Status, data.CmdScript, data.StartTime, data.RunningTime, data.DerivedEs, data.Cluster, data.BlockId, data.AllocNodes, data.AllocCpu, data.CardCount, data.Version, data.Account, data.WorkDir, data.AssocId, data.ExitCode, data.WallTime, data.Result, data.DeletedAt, data.YamlString, data.AppType, data.AppName, data.Queue, data.SubmitType, data.NNode, data.StdOutFile, data.StdErrFile, data.StdInput, data.Environment, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime) + return ret, err +} + +func (m *defaultTaskHpcModel) Update(ctx context.Context, data *TaskHpc) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, taskHpcRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.JobId, data.ClusterId, data.Name, data.Status, data.CmdScript, data.StartTime, data.RunningTime, data.DerivedEs, data.Cluster, data.BlockId, data.AllocNodes, data.AllocCpu, data.CardCount, data.Version, data.Account, data.WorkDir, data.AssocId, data.ExitCode, data.WallTime, data.Result, data.DeletedAt, data.YamlString, data.AppType, data.AppName, data.Queue, data.SubmitType, data.NNode, data.StdOutFile, data.StdErrFile, data.StdInput, data.Environment, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id) + return err +} + +func (m *defaultTaskHpcModel) tableName() string { + return m.table +} diff --git a/pkg/tracker/tracker_test.go b/pkg/tracker/tracker_test.go index 6c848cde..5d239ed5 100644 --- a/pkg/tracker/tracker_test.go +++ b/pkg/tracker/tracker_test.go @@ -16,7 +16,6 @@ package tracker import ( "testing" - "time" ) func TestGetNamedMetrics(t *testing.T) { @@ -28,9 +27,9 @@ func TestGetNamedMetrics(t *testing.T) { //}) //println("zzz", result[0].MetricValues[0].Sample.Value()) - client, _ := NewPrometheus("http://10.105.20.4:30766") - result := client.GetNamedMetricsByTime([]string{"pod_cpu_usage", "pod_memory_usage_wo_cache"}, "1700521446", "1700551446", 10*time.Minute, ControllerOption{ - PodsName: "sealos-task-112703-65c776b4b5-q4jgf", - }) - println("zzz", result) + //client, _ := NewPrometheus("http://10.105.20.4:30766") + //result := client.GetNamedMetricsByTime([]string{"pod_cpu_usage", "pod_memory_usage_wo_cache"}, "1700521446", "1700551446", 10*time.Minute, ControllerOption{ + // PodsName: "sealos-task-112703-65c776b4b5-q4jgf", + //}) + //println("zzz", result) } From aa6b343f3444db0d2964ee8b510e319f48bab10f Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Tue, 12 Mar 2024 16:53:50 +0800 Subject: [PATCH 5/5] missing submit to delete routes Former-commit-id: a624db840186bdaa2a7237421e01a96d96e5e27e --- api/internal/handler/routes.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 73b25377..7ccdb138 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -39,11 +39,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/core/commitTask", Handler: core.CommitTaskHandler(serverCtx), }, - { - Method: http.MethodPost, - Path: "/core/commitHpcTask", - Handler: core.CommitHpcTaskHandler(serverCtx), - }, { Method: http.MethodPost, Path: "/core/commitVmTask", @@ -79,11 +74,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/core/listCluster/:centerId", Handler: core.ListClusterHandler(serverCtx), }, - { - Method: http.MethodPost, - Path: "/core/submitJob", - Handler: core.SubmitJobHandler(serverCtx), - }, { Method: http.MethodGet, Path: "/core/getRegion", @@ -140,6 +130,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ + { + Method: http.MethodPost, + Path: "/hpc/commitHpcTask", + Handler: hpc.CommitHpcTaskHandler(serverCtx), + }, { Method: http.MethodGet, Path: "/hpc/listJob", @@ -152,7 +147,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodGet, - Path: "/queue/assets", + Path: "/hpc/queueAssets", Handler: hpc.QueueAssetsHandler(serverCtx), }, },