72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
|
|
"gitlink.org.cn/JointCloud/pcm-ac/internal/common"
|
|
"gitlink.org.cn/JointCloud/pcm-ac/internal/svc"
|
|
"io"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ListJobManagerLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewListJobManagerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListJobManagerLogic {
|
|
return &ListJobManagerLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// ListJobManager list all job managers
|
|
func (l *ListJobManagerLogic) ListJobManager(in *hpcAC.JobManagerReq) (*hpcAC.ListJobManagerResp, error) {
|
|
// todo: add your logic here and delete this line
|
|
|
|
var resp hpcAC.ListJobManagerResp
|
|
jobManagerUrl := "/hpc/openapi/v2/cluster"
|
|
|
|
getTokenLogic := NewGetACTokenLogic(l.ctx, l.svcCtx)
|
|
tokenResp, _ := getTokenLogic.GetACToken(&hpcAC.ACTokenReq{})
|
|
token := tokenResp.GetData().Token
|
|
|
|
c := http.Client{Timeout: time.Duration(3) * time.Second}
|
|
|
|
reqUrl, err := http.NewRequest("GET", common.HpcCenterUrlPrefix()+jobManagerUrl, nil)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reqUrl.Header.Add("token", token)
|
|
|
|
respUrl, err := c.Do(reqUrl)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
body, err := io.ReadAll(respUrl.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err = json.Unmarshal(body, &resp); err != nil {
|
|
if resp.Code != "0" {
|
|
resp.Data = nil
|
|
} else {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|