diff --git a/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/common/httputil.go b/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/common/httputil.go index f9ea9e5e..55bb19e3 100644 --- a/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/common/httputil.go +++ b/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/common/httputil.go @@ -15,7 +15,7 @@ func OctopusHttpClient(method string, url string, payload io.Reader, token strin } else { request.Header.Set("Content-Type", "application/json") } - client := http.Client{Timeout: time.Duration(3) * time.Second} + client := http.Client{Timeout: time.Duration(2) * time.Second} res, err := client.Do(request) if err != nil { if os.IsTimeout(err) { diff --git a/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/config/config.go b/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/config/config.go index 9ec3496c..e3ac2749 100644 --- a/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/config/config.go +++ b/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/config/config.go @@ -11,9 +11,10 @@ import ( type Config struct { zrpc.RpcServerConf - OctopusConfig OctopusConfig - LogConf logx.LogConf - RedisConf redis.RedisConf + OctopusConfig OctopusConfig + PcmCoreRpcConf zrpc.RpcClientConf + LogConf logx.LogConf + RedisConf redis.RedisConf } var configFile = flag.String("f", "adaptor/PCM-AI/PCM-OCTOPUS/rpc/etc/octopus.yaml", "the config file") diff --git a/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/svc/servicecontext.go b/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/svc/servicecontext.go index fb8f3c11..f05cc719 100644 --- a/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/svc/servicecontext.go +++ b/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/svc/servicecontext.go @@ -2,14 +2,18 @@ package svc import ( "PCM/adaptor/PCM-AI/PCM-OCTOPUS/rpc/internal/config" + "PCM/adaptor/PCM-CORE/rpc/pcmcoreclient" + "github.com/zeromicro/go-zero/zrpc" ) type ServiceContext struct { - Config config.Config + Config config.Config + PcmCoreRpc pcmcoreclient.PcmCore } func NewServiceContext(c config.Config) *ServiceContext { return &ServiceContext{ - Config: c, + Config: c, + PcmCoreRpc: pcmcoreclient.NewPcmCore(zrpc.MustNewClient(c.PcmCoreRpcConf)), } } diff --git a/adaptor/PCM-CORE/api/desc/core/pcm-core.api b/adaptor/PCM-CORE/api/desc/core/pcm-core.api index 880fac72..9cd90058 100644 --- a/adaptor/PCM-CORE/api/desc/core/pcm-core.api +++ b/adaptor/PCM-CORE/api/desc/core/pcm-core.api @@ -259,6 +259,12 @@ type ( cpResp { POpsAtFp16 float32 `json:"pOpsAtFp16"` } + + GiResp { + CpuNum int32 `json:"cpuNum,optional"` + MemoryInGib int32 `json:"memoryInGib,optional"` + StorageInGib int32 `json:"storageInGib,optional"` + } ) type ( diff --git a/adaptor/PCM-CORE/api/desc/pcm.api b/adaptor/PCM-CORE/api/desc/pcm.api index 1848bb28..e01e9972 100644 --- a/adaptor/PCM-CORE/api/desc/pcm.api +++ b/adaptor/PCM-CORE/api/desc/pcm.api @@ -42,6 +42,9 @@ service pcm { @handler getComputingPowerHandler get /core/getComputingPower returns (cpResp) + @handler getGeneralInfoHandler + get /core/getGeneralInfo () returns (GiResp) + @handler listDomainResourceHandler get /core/listDomainResource returns (DomainResourceResp) } diff --git a/adaptor/PCM-CORE/api/internal/handler/core/getgeneralinfohandler.go b/adaptor/PCM-CORE/api/internal/handler/core/getgeneralinfohandler.go new file mode 100644 index 00000000..89a4653c --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/handler/core/getgeneralinfohandler.go @@ -0,0 +1,21 @@ +package core + +import ( + "net/http" + + "PCM/adaptor/PCM-CORE/api/internal/logic/core" + "PCM/adaptor/PCM-CORE/api/internal/svc" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func GetGeneralInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + l := core.NewGetGeneralInfoLogic(r.Context(), svcCtx) + resp, err := l.GetGeneralInfo() + 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/routes.go b/adaptor/PCM-CORE/api/internal/handler/routes.go index 1fb4d60e..78edf4f8 100644 --- a/adaptor/PCM-CORE/api/internal/handler/routes.go +++ b/adaptor/PCM-CORE/api/internal/handler/routes.go @@ -51,6 +51,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/core/getComputingPower", Handler: core.GetComputingPowerHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/core/getGeneralInfo", + Handler: core.GetGeneralInfoHandler(serverCtx), + }, { Method: http.MethodGet, Path: "/core/listDomainResource", diff --git a/adaptor/PCM-CORE/api/internal/logic/core/getgeneralinfologic.go b/adaptor/PCM-CORE/api/internal/logic/core/getgeneralinfologic.go new file mode 100644 index 00000000..7004a8f9 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/logic/core/getgeneralinfologic.go @@ -0,0 +1,54 @@ +package core + +import ( + "PCM/adaptor/PCM-AI/PCM-OCTOPUS/rpc/octopus" + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + "PCM/adaptor/PCM-HPC/PCM-AC/rpc/hpcAC" + "context" + "log" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetGeneralInfoLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetGeneralInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGeneralInfoLogic { + return &GetGeneralInfoLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetGeneralInfoLogic) GetGeneralInfo() (resp *types.GiResp, err error) { + apiResp := types.GiResp{} + + //启智章鱼资源统计 + octopusGiReq := &octopus.ResourceReq{} + octopusGiResp, err := l.svcCtx.OctopusRpc.GetGeneralInfo(l.ctx, octopusGiReq) + if err != nil { + log.Println("OctopusRpc 资源请求失败", err) + } + + //曙光账号资源统计 + acGiReq := &hpcAC.ResourceReq{} + acGiResp, err := l.svcCtx.ACRpc.GetGeneralInfo(l.ctx, acGiReq) + if err != nil { + log.Println("ACRpc 资源请求失败", err) + } + + cpu := octopusGiResp.CpuCoreNum + acGiResp.CpuCoreNum + storage := acGiResp.StorageInGib + mem := octopusGiResp.MemoryInGib + acGiResp.MemoryInGib + + apiResp.StorageInGib = storage + apiResp.CpuNum = cpu + apiResp.MemoryInGib = mem + + return &apiResp, nil +} diff --git a/adaptor/PCM-CORE/api/internal/types/types.go b/adaptor/PCM-CORE/api/internal/types/types.go index 92aa28a3..450d8094 100644 --- a/adaptor/PCM-CORE/api/internal/types/types.go +++ b/adaptor/PCM-CORE/api/internal/types/types.go @@ -238,6 +238,12 @@ type CpResp struct { POpsAtFp16 float32 `json:"pOpsAtFp16"` } +type GiResp struct { + CpuNum int32 `json:"cpuNum,optional"` + MemoryInGib int32 `json:"memoryInGib,optional"` + StorageInGib int32 `json:"storageInGib,optional"` +} + type DomainResourceResp struct { TotalCount int `json:"totalCount"` DomainResourceList []DomainResource `json:"domainResourceList"` diff --git a/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/getgeneralinfologic.go b/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/getgeneralinfologic.go index 6931d047..5458a705 100644 --- a/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/getgeneralinfologic.go +++ b/adaptor/PCM-HPC/PCM-AC/rpc/internal/logic/getgeneralinfologic.go @@ -137,16 +137,45 @@ func (l *GetGeneralInfoLogic) GetGeneralInfo(in *hpcAC.ResourceReq) (*hpcAC.GiRe } //获取节点资源限额 - //var resourceResp common.ResourceResp - //resourceUrl := ai_prefix_url + cpConf.AiResourceUrl - // - //resourceGroupReq := tool.GetACHttpRequest() - //_, err = resourceGroupReq.SetHeader(tool.ContentType, tool.ApplicationJson). - // SetHeader("token", token). - // SetResult(&resourceGroupResp). - // Get(resourceGroupUrl) - //if err != nil || resourceGroupResp.Code != "0" { - // return resp, nil - //} - return &hpcAC.GiResp{}, nil + resourceUrl := ai_prefix_url + cpConf.AiResourceUrl + + resourceGroups := []string{ + resourceGroupResp.Data.Cpu[0], + resourceGroupResp.Data.Dcu[0], + } + + var memorySize int32 + for _, group := range resourceGroups { + var resourceResp common.ResourceResp + + resourceReq := tool.GetACHttpRequest() + _, err = resourceReq.SetHeader(tool.ContentType, tool.ApplicationJson). + SetHeader("token", token). + SetQueryString("resourceGroup=" + group). + SetQueryString("acceleratorType=" + "gpu"). + SetResult(&resourceResp). + Get(resourceUrl) + if err != nil || resourceGroupResp.Code != "0" { + return resp, nil + } + memorySize += int32(resourceResp.Data.MemorySize) + } + + //返回数据 + cpuCoreNum := quotaResp.Data.AccountMaxCpu + sharedStorageInGib := parastorQuotaResp.Data[0].Threshold + + if memorySize != 0 { + resp.MemoryInGib = memorySize / 1024 + } + + if cpuCoreNum != -1 { + resp.CpuCoreNum = int32(cpuCoreNum) + } + + if sharedStorageInGib != 0 { + resp.StorageInGib = int32(sharedStorageInGib) + } + + return resp, nil }