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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. "k8s.io/apimachinery/pkg/util/json"
  8. "math/rand"
  9. "time"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  11. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type CommitHpcTaskLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewCommitHpcTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitHpcTaskLogic {
  20. return &CommitHpcTaskLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) {
  27. // 构建主任务结构体
  28. taskModel := models.Task{
  29. Name: req.Name,
  30. Description: req.Description,
  31. AdapterTypeDict: "2",
  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 in ? and label = ?", req.AdapterIds, req.ClusterType).Scan(&clusterIds)
  40. if len(clusterIds) == 0 || clusterIds == nil {
  41. resp.Code = 400
  42. resp.Msg = "no cluster found"
  43. return resp, nil
  44. }
  45. var clusterName string
  46. var adapterId int64
  47. var adapterName string
  48. clusterId := clusterIds[rand.Intn(len(clusterIds))]
  49. l.svcCtx.DbEngin.Raw("SELECT nickname FROM `t_cluster` where id = ?", clusterId).Scan(&clusterName)
  50. l.svcCtx.DbEngin.Raw("SELECT adapter_id FROM `t_cluster` where id = ?", clusterId).Scan(&adapterId)
  51. l.svcCtx.DbEngin.Raw("SELECT name FROM `t_adapter` where id = ?", adapterId).Scan(&adapterName)
  52. if len(adapterName) == 0 || adapterName == "" {
  53. return nil, errors.New("no corresponding adapter found")
  54. }
  55. env, _ := json.Marshal(req.Environment)
  56. hpcInfo := models.TaskHpc{
  57. TaskId: taskModel.Id,
  58. AdapterId: uint(adapterId),
  59. AdapterName: adapterName,
  60. ClusterId: uint(clusterId),
  61. ClusterName: clusterName,
  62. Name: taskModel.Name,
  63. CmdScript: req.CmdScript,
  64. StartTime: time.Now().String(),
  65. CardCount: req.CardCount,
  66. WorkDir: req.WorkDir,
  67. WallTime: req.WallTime,
  68. AppType: req.AppType,
  69. AppName: req.AppName,
  70. Queue: req.Queue,
  71. SubmitType: req.SubmitType,
  72. NNode: req.NNode,
  73. Account: req.Account,
  74. StdOutFile: req.StdOutFile,
  75. StdErrFile: req.StdErrFile,
  76. StdInput: req.StdInput,
  77. Partition: req.Partition,
  78. Environment: string(env),
  79. }
  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: clusterId,
  88. ClusterName: clusterName,
  89. NoticeType: "create",
  90. TaskName: req.Name,
  91. Incident: "任务创建中",
  92. }
  93. result := l.svcCtx.DbEngin.Table("t_notice").Create(&noticeInfo)
  94. if result.Error != nil {
  95. logx.Errorf("Task creation failure, err: %v", result.Error)
  96. }
  97. // todo mq task manage
  98. //reqMessage, err := json.Marshal(mqInfo)
  99. //if err != nil {
  100. // logx.Error(err)
  101. // return nil, err
  102. //}
  103. //publish := l.svcCtx.RedisClient.Publish(context.Background(), mqInfo.TaskType, reqMessage)
  104. //if publish.Err() != nil {
  105. // return nil, publish.Err()
  106. //}
  107. resp = &types.CommitHpcTaskResp{
  108. Code: 200,
  109. Msg: "success",
  110. TaskId: taskModel.Id,
  111. }
  112. return resp, nil
  113. }

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.