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.

commithpctasklogic.go 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package hpc
  2. import (
  3. "context"
  4. "errors"
  5. clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  7. "time"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type CommitHpcTaskLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewCommitHpcTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitHpcTaskLogic {
  18. return &CommitHpcTaskLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) {
  25. var clusterInfo types.ClusterInfo
  26. l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where id = ?", req.ClusterId).First(&clusterInfo)
  27. if len(clusterInfo.Id) == 0 {
  28. resp.Code = 400
  29. resp.Msg = "no cluster found"
  30. return resp, nil
  31. }
  32. // 构建主任务结构体
  33. taskModel := models.Task{
  34. Name: req.Name,
  35. Description: req.Description,
  36. CommitTime: time.Now(),
  37. Status: "Saved",
  38. AdapterTypeDict: "2",
  39. }
  40. // 保存任务数据到数据库
  41. tx := l.svcCtx.DbEngin.Create(&taskModel)
  42. if tx.Error != nil {
  43. return nil, tx.Error
  44. }
  45. var clusterName string
  46. var adapterId int64
  47. var adapterName string
  48. l.svcCtx.DbEngin.Raw("SELECT nickname FROM `t_cluster` where id = ?", req.ClusterId).Scan(&clusterName)
  49. l.svcCtx.DbEngin.Raw("SELECT adapter_id FROM `t_cluster` where id = ?", req.ClusterId).Scan(&adapterId)
  50. l.svcCtx.DbEngin.Raw("SELECT name FROM `t_adapter` where id = ?", adapterId).Scan(&adapterName)
  51. if len(adapterName) == 0 || adapterName == "" {
  52. return nil, errors.New("no corresponding adapter found")
  53. }
  54. hpcInfo := models.TaskHpc{
  55. TaskId: taskModel.Id,
  56. AdapterId: adapterId,
  57. AdapterName: adapterName,
  58. ClusterId: req.ClusterId,
  59. ClusterName: clusterName,
  60. Name: taskModel.Name,
  61. CmdScript: req.CmdScript,
  62. StartTime: time.Now().String(),
  63. CardCount: req.CardCount,
  64. WorkDir: req.WorkDir,
  65. WallTime: req.WallTime,
  66. AppType: req.AppType,
  67. AppName: req.AppName,
  68. Queue: req.Queue,
  69. SubmitType: req.SubmitType,
  70. NNode: req.NNode,
  71. Account: clusterInfo.Username,
  72. StdInput: req.StdInput,
  73. Partition: req.Partition,
  74. Environment: clusterInfo.Environment,
  75. CreatedTime: time.Now(),
  76. UpdatedTime: time.Now(),
  77. Status: "Saved",
  78. }
  79. hpcInfo.WorkDir = clusterInfo.WorkDir + "/" + req.WorkDir
  80. tx = l.svcCtx.DbEngin.Create(&hpcInfo)
  81. if tx.Error != nil {
  82. return nil, tx.Error
  83. }
  84. noticeInfo := clientCore.NoticeInfo{
  85. AdapterId: adapterId,
  86. AdapterName: adapterName,
  87. ClusterId: req.ClusterId,
  88. ClusterName: clusterName,
  89. NoticeType: "create",
  90. TaskName: req.Name,
  91. Incident: "任务创建中",
  92. CreatedTime: time.Now(),
  93. }
  94. result := l.svcCtx.DbEngin.Table("t_notice").Create(&noticeInfo)
  95. if result.Error != nil {
  96. logx.Errorf("Task creation failure, err: %v", result.Error)
  97. }
  98. resp = &types.CommitHpcTaskResp{
  99. Code: 200,
  100. Msg: "success",
  101. TaskId: taskModel.Id,
  102. }
  103. return resp, nil
  104. }

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.