You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

canceljoblogic.go 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package hpc
  2. import (
  3. "context"
  4. "github.com/go-resty/resty/v2"
  5. "github.com/pkg/errors"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. "gitlink.org.cn/JointCloud/pcm-hpc/slurm"
  10. )
  11. type CancelJobLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewCancelJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelJobLogic {
  17. return &CancelJobLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *CancelJobLogic) CancelJob(req *types.CancelJobReq) error {
  24. var clusterInfo *types.ClusterInfo
  25. tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&clusterInfo)
  26. if tx.Error != nil {
  27. return tx.Error
  28. }
  29. // 查询p端调用地址
  30. var adapterAddress string
  31. l.svcCtx.DbEngin.Raw("SELECT server FROM `t_adapter` where id = ?", clusterInfo.AdapterId).Scan(&adapterAddress)
  32. var jobResp slurm.GetJobResp
  33. httpClient := resty.New().R()
  34. _, err := httpClient.SetHeader("Content-Type", "application/json").
  35. SetQueryParams(map[string]string{
  36. "jobId": req.JobId,
  37. "server": clusterInfo.Server,
  38. "version": clusterInfo.Version,
  39. "token": clusterInfo.Token,
  40. "username": clusterInfo.Username,
  41. }).
  42. SetResult(&jobResp).
  43. Delete(adapterAddress + "/api/v1/job/cancel")
  44. if err != nil {
  45. return err
  46. }
  47. if len(jobResp.Errors) != 0 {
  48. return errors.Errorf(jobResp.Errors[0].Description)
  49. }
  50. return nil
  51. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.