forked from JointCloud/pcm-coordinator
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package schedule
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetComputeCardsByClusterLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetComputeCardsByClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetComputeCardsByClusterLogic {
|
|
return &GetComputeCardsByClusterLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetComputeCardsByClusterLogic) GetComputeCardsByCluster(req *types.GetComputeCardsByClusterReq) (resp *types.GetComputeCardsByClusterResp, err error) {
|
|
resp = &types.GetComputeCardsByClusterResp{}
|
|
adapter, ok := l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[req.AdapterId]
|
|
if !ok {
|
|
return nil, errors.New("adapterId does not exist")
|
|
}
|
|
cluster, ok := adapter[req.ClusterId]
|
|
if !ok {
|
|
return nil, errors.New("clusterId does not exist")
|
|
}
|
|
cards, err := cluster.GetComputeCards(l.ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp.Cards = cards
|
|
|
|
return resp, nil
|
|
}
|