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

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

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.