From c6615bab53d2c2bf798e0988c0f24b88bea879e0 Mon Sep 17 00:00:00 2001 From: qiwang <1364512070@qq.com> Date: Wed, 26 Apr 2023 11:25:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A2=9E=E5=8A=A0=E5=A4=A7=E5=B1=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BB=A3=E7=A0=81=E5=88=B02.0=E5=88=86?= =?UTF-8?q?=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adaptor/PCM-CORE/api/desc/pcm.api | 4 ++ .../PCM-CORE/api/desc/storage/pcm-storage.api | 42 +++++++++++++- .../PCM-CORE/api/internal/handler/routes.go | 10 ++++ .../storage/dailypowerscreenhandler.go | 28 +++++++++ .../storage/percentercomputerpowershandler.go | 28 +++++++++ .../logic/storage/dailypowerscreenlogic.go | 49 ++++++++++++++++ .../storage/percentercomputerpowerslogic.go | 49 ++++++++++++++++ adaptor/PCM-CORE/api/internal/types/types.go | 58 +++++++++++++++---- 8 files changed, 255 insertions(+), 13 deletions(-) create mode 100644 adaptor/PCM-CORE/api/internal/handler/storage/dailypowerscreenhandler.go create mode 100644 adaptor/PCM-CORE/api/internal/handler/storage/percentercomputerpowershandler.go create mode 100644 adaptor/PCM-CORE/api/internal/logic/storage/dailypowerscreenlogic.go create mode 100644 adaptor/PCM-CORE/api/internal/logic/storage/percentercomputerpowerslogic.go diff --git a/adaptor/PCM-CORE/api/desc/pcm.api b/adaptor/PCM-CORE/api/desc/pcm.api index 14f54855..388a9982 100644 --- a/adaptor/PCM-CORE/api/desc/pcm.api +++ b/adaptor/PCM-CORE/api/desc/pcm.api @@ -163,4 +163,8 @@ service pcm { service pcm { @handler screenStorageHandler get /storage/screenStorage (StorageScreenReq) returns (StorageScreenResp) + @handler dailyPowerScreenHandler + get /storage/dailyPowerScreen (DailyPowerScreenReq) returns (DailyPowerScreenResp) + @handler perCenterComputerPowersHandler + get /storage/perCenterComputerPowers (PerCenterComputerPowersReq) returns (PerCenterComputerPowersResp) } \ No newline at end of file diff --git a/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api b/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api index eee71c56..62b2dd33 100644 --- a/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api +++ b/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api @@ -48,5 +48,45 @@ type( JobCount int32 `json:"jobCount" copier:"JobCount"` } ) - /******************screen storage end*************************/ + +/******************screen computing power Start*************************/ +type( + DailyPowerScreenReq{ + + } + + DailyPowerScreenResp{ + TotalSize int32 `json:"totalSize" copier:"TotalSize"` + DailyComputerPowers []DailyComputerPowers `json:"dailyComputerPowers" copier:"DailyComputerPowers"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` + ErrorMsg string `json:"ErrorMsg,omitempty"` + } + + DailyComputerPowers{ + Date string `json:"date" copier:"Date"` + ComputerPower float32 `json:"computerPower" copier:"ComputerPower"` + } +) +type( + PerCenterComputerPowersReq{ + + } + PerCenterComputerPowersResp{ + TotalSize int32 `json:"totalSize" copier:"TotalSize"` + PerCenterComputerPowers []PerCenterComputerPowers `json:"perCenterComputerPowers" copier:"PerCenterComputerPowers"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` + ErrorMsg string `json:"ErrorMsg,omitempty"` + } + + PerCenterComputerPowers{ + CenterName string `json:"centerName" copier:"CenterName"` + ComputerPower float32`json:"computerPower" copier:"ComputerPower"` + JobCount int32 `json:"jobCount" copier:"JobCount"` + CenterId string `json:"centerId" copier:"CenterId"` +} +) + +/******************screen computing power End*************************/ diff --git a/adaptor/PCM-CORE/api/internal/handler/routes.go b/adaptor/PCM-CORE/api/internal/handler/routes.go index 4402013e..1fb4d60e 100644 --- a/adaptor/PCM-CORE/api/internal/handler/routes.go +++ b/adaptor/PCM-CORE/api/internal/handler/routes.go @@ -234,6 +234,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/storage/screenStorage", Handler: storage.ScreenStorageHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/storage/dailyPowerScreen", + Handler: storage.DailyPowerScreenHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/storage/perCenterComputerPowers", + Handler: storage.PerCenterComputerPowersHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/adaptor/PCM-CORE/api/internal/handler/storage/dailypowerscreenhandler.go b/adaptor/PCM-CORE/api/internal/handler/storage/dailypowerscreenhandler.go new file mode 100644 index 00000000..e2cb33ea --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/handler/storage/dailypowerscreenhandler.go @@ -0,0 +1,28 @@ +package storage + +import ( + "net/http" + + "PCM/adaptor/PCM-CORE/api/internal/logic/storage" + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func DailyPowerScreenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DailyPowerScreenReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := storage.NewDailyPowerScreenLogic(r.Context(), svcCtx) + resp, err := l.DailyPowerScreen(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/adaptor/PCM-CORE/api/internal/handler/storage/percentercomputerpowershandler.go b/adaptor/PCM-CORE/api/internal/handler/storage/percentercomputerpowershandler.go new file mode 100644 index 00000000..25ae29c5 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/handler/storage/percentercomputerpowershandler.go @@ -0,0 +1,28 @@ +package storage + +import ( + "net/http" + + "PCM/adaptor/PCM-CORE/api/internal/logic/storage" + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func PerCenterComputerPowersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.PerCenterComputerPowersReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := storage.NewPerCenterComputerPowersLogic(r.Context(), svcCtx) + resp, err := l.PerCenterComputerPowers(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/adaptor/PCM-CORE/api/internal/logic/storage/dailypowerscreenlogic.go b/adaptor/PCM-CORE/api/internal/logic/storage/dailypowerscreenlogic.go new file mode 100644 index 00000000..5203704d --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/logic/storage/dailypowerscreenlogic.go @@ -0,0 +1,49 @@ +package storage + +import ( + "PCM/adaptor/PCM-STORAGE/PCM-CEPH/rpc/ceph" + "PCM/common/result" + "PCM/common/tool" + "PCM/common/xerr" + "context" + "github.com/jinzhu/copier" + "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/util/json" + + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DailyPowerScreenLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDailyPowerScreenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DailyPowerScreenLogic { + return &DailyPowerScreenLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DailyPowerScreenLogic) DailyPowerScreen(req *types.DailyPowerScreenReq) (resp *types.DailyPowerScreenResp, err error) { + // todo: add your logic here and delete this line + dailyPowerScreenReq := &ceph.DailyPowerScreenReq{} + err = copier.CopyWithOption(dailyPowerScreenReq, req, copier.Option{Converters: tool.Converters}) + DailyPowerScreenResp, err := l.svcCtx.CephRpc.DailyPowerScreen(l.ctx, dailyPowerScreenReq) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get db storage list"), "Failed to get db storage list err : %v ,req:%+v", err, req) + } + marshal, err := json.Marshal(&DailyPowerScreenResp) + if err != nil { + return nil, result.NewDefaultError(err.Error()) + } + json.Unmarshal(marshal, &resp) + err = copier.CopyWithOption(&resp, &DailyPowerScreenResp, copier.Option{Converters: tool.Converters}) + + return resp, nil +} diff --git a/adaptor/PCM-CORE/api/internal/logic/storage/percentercomputerpowerslogic.go b/adaptor/PCM-CORE/api/internal/logic/storage/percentercomputerpowerslogic.go new file mode 100644 index 00000000..4086f25d --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/logic/storage/percentercomputerpowerslogic.go @@ -0,0 +1,49 @@ +package storage + +import ( + "PCM/adaptor/PCM-STORAGE/PCM-CEPH/rpc/ceph" + "PCM/common/result" + "PCM/common/tool" + "PCM/common/xerr" + "context" + "github.com/jinzhu/copier" + "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/util/json" + + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type PerCenterComputerPowersLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewPerCenterComputerPowersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerCenterComputerPowersLogic { + return &PerCenterComputerPowersLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *PerCenterComputerPowersLogic) PerCenterComputerPowers(req *types.PerCenterComputerPowersReq) (resp *types.PerCenterComputerPowersResp, err error) { + // todo: add your logic here and delete this line + perCenterComputerPowersReq := &ceph.PerCenterComputerPowersReq{} + err = copier.CopyWithOption(perCenterComputerPowersReq, req, copier.Option{Converters: tool.Converters}) + PerCenterComputerPowersResp, err := l.svcCtx.CephRpc.PerCenterComputerPowerScreen(l.ctx, perCenterComputerPowersReq) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get db storage list"), "Failed to get db storage list err : %v ,req:%+v", err, req) + } + marshal, err := json.Marshal(&PerCenterComputerPowersResp) + if err != nil { + return nil, result.NewDefaultError(err.Error()) + } + json.Unmarshal(marshal, &resp) + err = copier.CopyWithOption(&resp, &PerCenterComputerPowersResp, copier.Option{Converters: tool.Converters}) + + return resp, nil +} diff --git a/adaptor/PCM-CORE/api/internal/types/types.go b/adaptor/PCM-CORE/api/internal/types/types.go index 8e87ad37..7d4e6c52 100644 --- a/adaptor/PCM-CORE/api/internal/types/types.go +++ b/adaptor/PCM-CORE/api/internal/types/types.go @@ -250,22 +250,22 @@ type CpResp struct { } type DomainResourceResp struct { + TotalCount int `json:"totalCount"` DomainResourceList []DomainResource `json:"domainResourceList"` } type DomainResource struct { - Id int64 `json:"id"` // id - DomainId string `json:"domainId"` // 资源域id - DomainName string `json:"domainName"` // 资源域名称 - JobCount int64 `json:"jobCount"` // 资源域任务数量 - DomainSource int64 `json:"domainSource"` // 资源域数据来源:0-nudt,1-鹏城 - Stack string `json:"stack"` // 技术栈 - ResourceType string `json:"resourceType"` // 资源类型 - Cpu string `json:"cpu"` // cpu - Memory string `json:"memory"` // 内存 - Disk string `json:"disk"` // 存储 - NodeCount string `json:"nodeCount"` //节点数量 - DeleteFlag int64 `json:"deleteFlag"` // 是否删除 0:未删除,1:已经删除 + Id int64 `json:"id"` // id + DomainId string `json:"domain_id"` // 资源域id + DomainName string `json:"domain_name"` // 资源域名称 + JobCount int64 `json:"job_count"` // 资源域任务数量 + DomainSource int64 `json:"domain_source"` // 资源域数据来源:0-nudt,1-鹏城 + Stack string `json:"stack"` // 技术栈 + ResourceType string `json:"resource_type"` // 资源类型 + Cpu string `json:"cpu"` // cpu + Memory string `json:"memory"` // 内存 + Disk string `json:"disk"` // 存储 + NodeCount string `json:"nodeCount"` //节点数量 } type Job struct { @@ -1862,3 +1862,37 @@ type AiCenterInfos struct { CardRunTime int32 `json:"cardRunTime" copier:"CardRunTime"` JobCount int32 `json:"jobCount" copier:"JobCount"` } + +type DailyPowerScreenReq struct { +} + +type DailyPowerScreenResp struct { + TotalSize int32 `json:"totalSize" copier:"TotalSize"` + DailyComputerPowers []DailyComputerPowers `json:"dailyComputerPowers" copier:"DailyComputerPowers"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` + ErrorMsg string `json:"ErrorMsg,omitempty"` +} + +type DailyComputerPowers struct { + Date string `json:"date" copier:"Date"` + ComputerPower float32 `json:"computerPower" copier:"ComputerPower"` +} + +type PerCenterComputerPowersReq struct { +} + +type PerCenterComputerPowersResp struct { + TotalSize int32 `json:"totalSize" copier:"TotalSize"` + PerCenterComputerPowers []PerCenterComputerPowers `json:"perCenterComputerPowers" copier:"PerCenterComputerPowers"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` + ErrorMsg string `json:"ErrorMsg,omitempty"` +} + +type PerCenterComputerPowers struct { + CenterName string `json:"centerName" copier:"CenterName"` + ComputerPower float32 `json:"computerPower" copier:"ComputerPower"` + JobCount int32 `json:"jobCount" copier:"JobCount"` + CenterId string `json:"centerId" copier:"CenterId"` +}