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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package hpc
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  6. "k8s.io/apimachinery/pkg/util/json"
  7. "math/rand"
  8. "time"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type CommitHpcTaskLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewCommitHpcTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitHpcTaskLogic {
  19. return &CommitHpcTaskLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) {
  26. // 构建主任务结构体
  27. taskModel := models.Task{
  28. Name: req.Name,
  29. Description: req.Description,
  30. Status: constants.Saved,
  31. Strategy: 0,
  32. SynergyStatus: 0,
  33. CommitTime: time.Now(),
  34. AdapterTypeDict: 2,
  35. }
  36. // 保存任务数据到数据库
  37. tx := l.svcCtx.DbEngin.Create(&taskModel)
  38. if tx.Error != nil {
  39. return nil, tx.Error
  40. }
  41. var clusterIds []int64
  42. l.svcCtx.DbEngin.Raw("SELECT id FROM `t_cluster` where adapter_id = ? and label = ?", req.AdapterId, req.ClusterType).Scan(&clusterIds)
  43. env, _ := json.Marshal(req.Environment)
  44. if len(clusterIds) == 0 || clusterIds == nil {
  45. resp.Code = 400
  46. resp.Msg = "no cluster found"
  47. return resp, nil
  48. }
  49. hpcInfo := models.TaskHpc{
  50. TaskId: taskModel.Id,
  51. ClusterId: clusterIds[rand.Intn(len(clusterIds))],
  52. Name: taskModel.Name,
  53. Status: "Saved",
  54. CmdScript: req.CmdScript,
  55. StartTime: time.Now().String(),
  56. CardCount: req.CardCount,
  57. WorkDir: req.WorkDir,
  58. WallTime: req.WallTime,
  59. AppType: req.AppType,
  60. AppName: req.AppName,
  61. Queue: req.Queue,
  62. SubmitType: req.SubmitType,
  63. NNode: req.NNode,
  64. StdOutFile: req.StdOutFile,
  65. StdErrFile: req.StdErrFile,
  66. StdInput: req.StdInput,
  67. DeletedFlag: 0,
  68. CreatedBy: 0,
  69. CreatedTime: time.Now(),
  70. UpdatedBy: 0,
  71. UpdatedTime: time.Now(),
  72. Environment: string(env),
  73. }
  74. tx = l.svcCtx.DbEngin.Create(&hpcInfo)
  75. if tx.Error != nil {
  76. return nil, tx.Error
  77. }
  78. // todo mq task manage
  79. //reqMessage, err := json.Marshal(mqInfo)
  80. //if err != nil {
  81. // logx.Error(err)
  82. // return nil, err
  83. //}
  84. //publish := l.svcCtx.RedisClient.Publish(context.Background(), mqInfo.TaskType, reqMessage)
  85. //if publish.Err() != nil {
  86. // return nil, publish.Err()
  87. //}
  88. resp = &types.CommitHpcTaskResp{
  89. Code: 200,
  90. Msg: "success",
  91. TaskId: taskModel.Id,
  92. }
  93. return resp, nil
  94. }

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.