60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"github.com/go-resty/resty/v2"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
|
|
"gitlink.org.cn/JointCloud/pcm-ac/internal/svc"
|
|
)
|
|
|
|
type GetACClusterIdLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetACClusterIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetACClusterIdLogic {
|
|
return &GetACClusterIdLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// GetACClusterId 曙光ac获取clusterid
|
|
func (l *GetACClusterIdLogic) GetACClusterId(in *hpcAC.ACClusterReq) (*hpcAC.ClusterResp, error) {
|
|
var respAC hpcAC.ACClusterResp
|
|
client := resty.New()
|
|
|
|
queryParams := map[string]string{
|
|
"token": in.Token,
|
|
}
|
|
_, err := client.R().
|
|
SetHeaders(queryParams).
|
|
SetResult(&respAC).
|
|
Get(l.svcCtx.Config.ShuguangConf.ClusterUrl)
|
|
|
|
if err != nil {
|
|
logx.WithContext(l.ctx).Errorf("ACAuth err: %s", err.Error())
|
|
return nil, err
|
|
}
|
|
|
|
var resp hpcAC.ClusterResp
|
|
resp.Code = respAC.GetCode()
|
|
resp.Msg = respAC.GetMsg()
|
|
for _, dt := range respAC.Data {
|
|
if dt.JobManagerType == "SLURM" {
|
|
var data hpcAC.ACClusterData
|
|
data.JobManagerAddr = dt.GetJobManagerAddr()
|
|
data.JobManagerType = dt.GetJobManagerType()
|
|
data.Id = dt.GetId()
|
|
data.Text = dt.GetText()
|
|
data.JobManagerPort = dt.GetJobManagerPort()
|
|
resp.Data = &data
|
|
}
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|