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.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. Status: constants.Saved,
  29. Description: req.Description,
  30. Name: req.Name,
  31. CommitTime: time.Now(),
  32. }
  33. // 保存任务数据到数据库
  34. tx := l.svcCtx.DbEngin.Create(&taskModel)
  35. if tx.Error != nil {
  36. return nil, tx.Error
  37. }
  38. var clusterIds []int64
  39. l.svcCtx.DbEngin.Raw("SELECT id FROM `t_cluster` where adapter_id = ? and label = ?", req.AdapterId, req.ClusterType).Scan(&clusterIds)
  40. env, _ := json.Marshal(req.Environment)
  41. if len(clusterIds) == 0 || clusterIds == nil {
  42. return nil, nil
  43. }
  44. hpcInfo := models.TaskHpc{
  45. TaskId: taskModel.Id,
  46. ClusterId: clusterIds[rand.Intn(len(clusterIds))],
  47. Name: taskModel.Name,
  48. Status: "Saved",
  49. CmdScript: req.CmdScript,
  50. StartTime: time.Now().String(),
  51. CardCount: req.CardCount,
  52. WorkDir: req.WorkDir,
  53. WallTime: req.WallTime,
  54. AppType: req.AppType,
  55. AppName: req.AppName,
  56. Queue: req.Queue,
  57. SubmitType: req.SubmitType,
  58. NNode: req.NNode,
  59. StdOutFile: req.StdOutFile,
  60. StdErrFile: req.StdErrFile,
  61. StdInput: req.StdInput,
  62. DeletedFlag: 0,
  63. CreatedBy: 0,
  64. CreatedTime: time.Now(),
  65. UpdatedBy: 0,
  66. UpdatedTime: time.Now(),
  67. Environment: string(env),
  68. }
  69. tx = l.svcCtx.DbEngin.Create(&hpcInfo)
  70. if tx.Error != nil {
  71. return nil, tx.Error
  72. }
  73. // todo mq task manage
  74. //reqMessage, err := json.Marshal(mqInfo)
  75. //if err != nil {
  76. // logx.Error(err)
  77. // return nil, err
  78. //}
  79. //publish := l.svcCtx.RedisClient.Publish(context.Background(), mqInfo.TaskType, reqMessage)
  80. //if publish.Err() != nil {
  81. // return nil, publish.Err()
  82. //}
  83. resp = &types.CommitHpcTaskResp{
  84. Code: 200,
  85. Msg: "success",
  86. TaskId: taskModel.Id,
  87. }
  88. return resp, nil
  89. }

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.