forked from JointCloud/pcm-ac
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/common"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/svc"
|
|
"log"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetNodeResourcesLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetNodeResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetNodeResourcesLogic {
|
|
return &GetNodeResourcesLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// 获取节点资源限额
|
|
func (l *GetNodeResourcesLogic) GetNodeResources(in *hpcAC.GetNodeResourcesReq) (*hpcAC.GetNodeResourcesResp, error) {
|
|
resp := &hpcAC.GetNodeResourcesResp{}
|
|
var reqUrl = common.AiCenterUrlPrefix() + l.svcCtx.Config.ContainerConf.GetNodeResources
|
|
|
|
token := common.GetToken()
|
|
if token == "" {
|
|
log.Println("获取token失败")
|
|
return nil, errors.New("获取token失败")
|
|
}
|
|
|
|
queueId := common.GetQueueId()
|
|
req := common.GetRestyRequest(3)
|
|
_, err := req.
|
|
SetHeader("token", token).
|
|
SetQueryString("resourceGroup" + "=" + queueId).
|
|
SetQueryString("acceleratorType" + "=" + "dcu").
|
|
SetResult(resp).
|
|
Get(reqUrl)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp, nil
|
|
}
|