接口调用失败修复

This commit is contained in:
tzwang 2024-02-01 11:34:09 +08:00
parent 34aa5fed00
commit 2d4e27a90c
7 changed files with 127 additions and 5 deletions

View File

@ -41,6 +41,7 @@ CpuCore: 0.0625 #TOpsAtFp16 x86 7285 主频 x 每时钟周期浮点计算次数
AiResourceUrl : "/ai/openapi/v2/instance-service/resources" #获取节点资源限额
AiResourceGroupUrl : "/ai/openapi/v2/instance-service/resource-group" #获取资源分组
ParastorQuotaUrl : "/hpc/openapi/v2/parastor/quota/usernames/{username}" #查询普通共享存储配额及使用量
#查询用户可访问队列
# 曙光Ai 相关配置
BaseUrlAi : "https://ac.sugon.com"
@ -50,6 +51,9 @@ SubmitTaskAi : "/sothisai/api/{taskGroup}/training/tasks"
DeleteTaskAi : "/sothisai/api/tasks"
GetResourceSpec : "/sothisai/api/tasks/resources"
# 作业
GetQueueNames: "/hpc/openapi/v2/queuenames/users/{username}" #查询用户可访问队列
# 文件
GetFileList : "/openapi/v2/file/list"

View File

@ -4,6 +4,7 @@ import (
"flag"
"github.com/zeromicro/go-zero/core/conf"
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/config"
"strconv"
)
var (
@ -19,6 +20,7 @@ type AuthService struct {
EFileUrlPrefix string
JobManagerId int
GroupId string
QueueId string
}
func NewAuthService() *AuthService {
@ -36,6 +38,7 @@ func NewAuthService() *AuthService {
EFileUrlPrefix: getEFileUrlPrefix(&cfg, token),
JobManagerId: getJobManagerId(&cfg, token),
GroupId: getGroupId(&cfg, token),
QueueId: getQueueId(&cfg, token),
}
}
@ -66,6 +69,18 @@ func GetToken() string {
return as.Token
}
func GetQueueId() string {
return as.QueueId
}
func GetGroupId() string {
return as.GroupId
}
func GetClusterId() string {
return as.ClusterId
}
func GetJobManagerId() int {
return as.JobManagerId
}
@ -208,3 +223,27 @@ func getGroupId(cfg *config.Config, token string) string {
return ""
}
func getQueueId(cfg *config.Config, token string) string {
url := getHpcCenterUrl(cfg, token) + cfg.JobConf.GetQueueNames
var qn QueueNamesResp
req := GetRestyRequest(3)
_, err := req.
SetHeader("token", token).
SetPathParam("username", cfg.User).
SetQueryString("strJobManagerID" + "=" + strconv.Itoa(getJobManagerId(cfg, token))).
SetResult(&qn).
Get(url)
if err != nil || qn.Code != "0" {
return ""
}
for _, datum := range qn.Data {
// Todo multiple groups filtering
return datum.Id
}
return ""
}

View File

@ -173,3 +173,30 @@ type GroupMembers struct {
} `json:"groupUsersInfos"`
} `json:"data"`
}
type QueueNamesResp struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data []struct {
QueuePriority int `json:"queuePriority"`
QueFreeNcpus string `json:"queFreeNcpus"`
QueNodes string `json:"queNodes"`
QueNcpus string `json:"queNcpus"`
QueMaxNgpus string `json:"queMaxNgpus"`
QueMaxPPN string `json:"queMaxPPN"`
QueChargeRate string `json:"queChargeRate"`
QueMaxNcpus string `json:"queMaxNcpus"`
AclHosts string `json:"aclHosts"`
QueMaxNdcus string `json:"queMaxNdcus"`
QueueName string `json:"queueName"`
QueMaxNmlus string `json:"queMaxNmlus"`
QueFreeNodes string `json:"queFreeNodes"`
QueMaxNodect string `json:"queMaxNodect"`
QueMaxGpuPN string `json:"queMaxGpuPN"`
Id string `json:"id"`
Text string `json:"text"`
QueMaxWalltime string `json:"queMaxWalltime"`
QueMaxDcuPN string `json:"queMaxDcuPN"`
QueueEnabled bool `json:"queueEnabled"`
} `json:"data"`
}

View File

@ -14,4 +14,6 @@ type Config struct {
AiConf
FileConf
UserConf
JobConf
ContainerConf
}

View File

@ -40,6 +40,11 @@ type AiConf struct {
GetResourceSpec string
}
// 曙光作业
type JobConf struct {
GetQueueNames string
}
// 曙光文件
type FileConf struct {
GetFileList string

View File

@ -2,6 +2,9 @@ package logic
import (
"context"
"errors"
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/common"
"log"
"gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC"
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/svc"
@ -24,7 +27,27 @@ func NewGetMemberJobsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
}
func (l *GetMemberJobsLogic) GetMemberJobs(in *hpcAC.GetMemberJobsReq) (*hpcAC.GetMemberJobsResp, error) {
// todo: add your logic here and delete this line
resp := &hpcAC.GetMemberJobsResp{}
var reqUrl = l.svcCtx.Config.AcBaseUrl + l.svcCtx.Config.UserConf.GetMemberJobs
return &hpcAC.GetMemberJobsResp{}, nil
token := common.GetToken()
if token == "" {
log.Println("获取token失败")
return nil, errors.New("获取token失败")
}
req := common.GetRestyRequest(3)
_, err := req.
SetHeader("token", token).
SetPathParam("clusterId", common.GetClusterId()).
SetPathParam("groupId", common.GetGroupId()).
SetPathParam("clusterUserName", l.svcCtx.Config.User).
SetResult(resp).
Get(reqUrl)
if err != nil {
return nil, err
}
return resp, nil
}

View File

@ -2,9 +2,11 @@ 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"
)
@ -25,7 +27,27 @@ func NewGetNodeResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
// 获取节点资源限额
func (l *GetNodeResourcesLogic) GetNodeResources(in *hpcAC.GetNodeResourcesReq) (*hpcAC.GetNodeResourcesResp, error) {
// todo: add your logic here and delete this line
resp := &hpcAC.GetNodeResourcesResp{}
var reqUrl = common.AiCenterUrlPrefix() + l.svcCtx.Config.ContainerConf.GetNodeResources
return &hpcAC.GetNodeResourcesResp{}, nil
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
}