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 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package hpc
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  10. )
  11. type CancelJobLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. hpcService *service.HpcService
  16. }
  17. type TaskHPCResult struct {
  18. ID uint `gorm:"column:id"` // 对应 t.id
  19. JobID string `gorm:"column:job_id"` // 对应 hpc.job_id
  20. AdapterId string `gorm:"column:adapter_id"` // 对应 hpc.adapter_id
  21. }
  22. func NewCancelJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelJobLogic {
  23. cache := make(map[string]interface{}, 10)
  24. hpcService, err := service.NewHpcService(&svcCtx.Config, svcCtx.Scheduler.HpcStorages, cache)
  25. if err != nil {
  26. return nil
  27. }
  28. return &CancelJobLogic{
  29. Logger: logx.WithContext(ctx),
  30. ctx: ctx,
  31. svcCtx: svcCtx,
  32. hpcService: hpcService,
  33. }
  34. }
  35. func (l *CancelJobLogic) CancelJob(req *types.CancelJobReq) error {
  36. //var clusterInfo *types.ClusterInfo
  37. //tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&clusterInfo)
  38. //if tx.Error != nil {
  39. // return tx.Error
  40. //}
  41. //// 查询p端调用地址
  42. //var adapterAddress string
  43. //l.svcCtx.DbEngin.Raw("SELECT server FROM `t_adapter` where id = ?", clusterInfo.AdapterId).Scan(&adapterAddress)
  44. //var jobResp slurm.GetJobResp
  45. //httpClient := resty.New().R()
  46. //_, err := httpClient.SetHeader("Content-Type", "application/json").
  47. // SetQueryParams(map[string]string{
  48. // "jobId": req.JobId,
  49. // "server": clusterInfo.Server,
  50. // "version": clusterInfo.Version,
  51. // "token": clusterInfo.Token,
  52. // "username": clusterInfo.Username,
  53. // }).
  54. // SetResult(&jobResp).
  55. // Delete(adapterAddress + "/api/v1/job/cancel")
  56. //if err != nil {
  57. // return err
  58. //}
  59. //if len(jobResp.Errors) != 0 {
  60. // return errors.Errorf(jobResp.Errors[0].Description)
  61. //}
  62. //return nil
  63. var hpcR TaskHPCResult
  64. tx := l.svcCtx.DbEngin.Raw(
  65. "SELECT t.id, hpc.job_id ,hpc.adapter_id FROM task t "+
  66. "INNER JOIN task_hpc hpc ON t.id = hpc.task_id "+
  67. "WHERE adapter_type_dict = 2 AND t.id = ?",
  68. req.TaskId,
  69. ).Scan(&hpcR).Error
  70. if tx != nil {
  71. return fmt.Errorf("数据库查询失败: %v", tx.Error)
  72. }
  73. if hpcR.ID == 0 || hpcR.JobID == "" {
  74. return fmt.Errorf("作业不存在")
  75. }
  76. var adapterInfo types.AdapterInfo
  77. l.svcCtx.DbEngin.Raw("SELECT * FROM `t_adapter` where id = ?", hpcR.AdapterId).Scan(&adapterInfo)
  78. if adapterInfo.Id == "" {
  79. return fmt.Errorf("adapter not found")
  80. }
  81. // 取消作业
  82. err := l.hpcService.HpcExecutorAdapterMap[adapterInfo.Id].CancelTask(l.ctx, hpcR.JobID)
  83. if err != nil {
  84. return err
  85. }
  86. // 更新数据库状态
  87. tx = l.svcCtx.DbEngin.Model(&types.Task{}).Where("id = ?", hpcR.ID).Update("status", "Canceled").Error
  88. if tx != nil {
  89. return fmt.Errorf("数据库更新失败: %v", tx.Error)
  90. }
  91. // 更新数据库状态
  92. tx = l.svcCtx.DbEngin.Model(&models.TaskHpc{}).Where("task_id = ?", hpcR.ID).Update("status", "Canceled").Error
  93. if tx != nil {
  94. return fmt.Errorf("数据库更新失败: %v", tx.Error)
  95. }
  96. return nil
  97. }

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.