core cpu,内存, 存储接口汇总

This commit is contained in:
tzwang 2023-05-05 18:04:36 +08:00
parent cb8a955c33
commit bec7722adc
10 changed files with 147 additions and 18 deletions

View File

@ -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) {

View File

@ -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")

View File

@ -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)),
}
}

View File

@ -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 (

View File

@ -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)
}

View File

@ -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)
}
}
}

View File

@ -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",

View File

@ -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
}

View File

@ -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"`

View File

@ -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
}