package hpc import ( "context" "github.com/go-resty/resty/v2" "github.com/pkg/errors" "github.com/zeromicro/go-zero/core/logx" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "gitlink.org.cn/JointCloud/pcm-hpc/slurm" ) type CancelJobLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewCancelJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelJobLogic { return &CancelJobLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *CancelJobLogic) CancelJob(req *types.CancelJobReq) error { var clusterInfo *types.ClusterInfo tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&clusterInfo) if tx.Error != nil { return tx.Error } // 查询p端调用地址 var adapterAddress string l.svcCtx.DbEngin.Raw("SELECT server FROM `t_adapter` where id = ?", clusterInfo.AdapterId).Scan(&adapterAddress) var jobResp slurm.GetJobResp httpClient := resty.New().R() _, err := httpClient.SetHeader("Content-Type", "application/json"). SetQueryParams(map[string]string{ "jobId": req.JobId, "server": clusterInfo.Server, "version": clusterInfo.Version, "token": clusterInfo.Token, "username": clusterInfo.Username, }). SetResult(&jobResp). Delete(adapterAddress + "/api/v1/job/cancel") if err != nil { return err } if len(jobResp.Errors) != 0 { return errors.Errorf(jobResp.Errors[0].Description) } return nil }