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.

asyncommitaitasklogic.go 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package core
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  8. "time"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type AsynCommitAiTaskLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. // 异步提交智算任务
  19. func NewAsynCommitAiTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AsynCommitAiTaskLogic {
  20. return &AsynCommitAiTaskLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *AsynCommitAiTaskLogic) AsynCommitAiTask(req *types.AsynCommitAiTaskReq) (resp *types.AsynCommitAiTaskResp, err error) {
  27. // todo: add your logic here and delete this line
  28. resp = &types.AsynCommitAiTaskResp{}
  29. var adapterName string
  30. var clusterName string
  31. var adapterId int64
  32. //TODO adapter
  33. //adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64)
  34. //taskAiAsynchronous := models.TaskAiAsynchronous{}
  35. // 构建主任务结构体
  36. taskModel := models.Task{
  37. Name: req.Name,
  38. Description: "ai asynchronous task",
  39. CommitTime: time.Now(),
  40. Status: "Saved",
  41. AdapterTypeDict: "1",
  42. }
  43. // 保存任务数据到数据库
  44. tx := l.svcCtx.DbEngin.Create(&taskModel)
  45. if tx.Error != nil {
  46. return nil, tx.Error
  47. }
  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. AiAsynchronousInfo := models.TaskAiAsynchronous{
  55. TaskId: taskModel.Id,
  56. AdapterId: adapterId,
  57. AdapterName: adapterName,
  58. ClusterId: req.ClusterId,
  59. ClusterName: clusterName,
  60. Name: "trainJob" + utils.RandomString(10),
  61. StartTime: time.Now().String(),
  62. Status: "Saved",
  63. ImageId: req.ImageId,
  64. Command: req.Command,
  65. FlavorId: req.FlavorId,
  66. }
  67. tx = l.svcCtx.DbEngin.Create(&AiAsynchronousInfo)
  68. if tx.Error != nil {
  69. return nil, tx.Error
  70. }
  71. noticeInfo := clientCore.NoticeInfo{
  72. AdapterId: adapterId,
  73. AdapterName: adapterName,
  74. ClusterId: req.ClusterId,
  75. ClusterName: clusterName,
  76. NoticeType: "create",
  77. TaskName: req.Name,
  78. Incident: "任务创建中",
  79. }
  80. result := l.svcCtx.DbEngin.Table("t_notice").Create(&noticeInfo)
  81. if result.Error != nil {
  82. logx.Errorf("Task creation failure, err: %v", result.Error)
  83. }
  84. resp = &types.AsynCommitAiTaskResp{
  85. Code: 200,
  86. Msg: "success",
  87. TaskId: taskModel.Id,
  88. }
  89. return resp, nil
  90. }

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.