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.

deployinstancelistlogic.go 3.2 kB

5 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package inference
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/common"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  10. )
  11. type DeployInstanceListLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewDeployInstanceListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeployInstanceListLogic {
  17. return &DeployInstanceListLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *DeployInstanceListLogic) DeployInstanceList(req *types.DeployInstanceListReq) (resp *types.DeployInstanceListResp, err error) {
  24. limit := req.PageSize
  25. offset := req.PageSize * (req.PageNum - 1)
  26. resp = &types.DeployInstanceListResp{}
  27. var tasklist []*models.AiDeployInstanceTask
  28. tx := l.svcCtx.DbEngin.Raw("select * from ai_deploy_instance_task").Scan(&tasklist)
  29. if req.UserName != "" && req.UserName != "admin" {
  30. tx = tx.Where("user_id = ?", req.UserId)
  31. }
  32. if tx.Error != nil {
  33. logx.Errorf(tx.Error.Error())
  34. return nil, tx.Error
  35. }
  36. if len(tasklist) == 0 {
  37. resp.List = nil
  38. resp.PageSize = req.PageSize
  39. resp.PageNum = req.PageNum
  40. resp.Total = 0
  41. return
  42. }
  43. //count total
  44. var total int64
  45. err = tx.Count(&total).Error
  46. tx.Limit(limit).Offset(offset)
  47. if err != nil {
  48. return resp, err
  49. }
  50. err = tx.Order("create_time desc").Find(&tasklist).Error
  51. if err != nil {
  52. return nil, errors.New(err.Error())
  53. }
  54. deployTasks, err := l.GenerateDeployTasks(tasklist)
  55. if err != nil {
  56. return nil, errors.New(err.Error())
  57. }
  58. slices := make([][]*models.AiInferDeployInstance, len(deployTasks))
  59. for i := 0; i < len(deployTasks); i++ {
  60. slices[i] = deployTasks[i].Instances
  61. }
  62. list := common.ConcatMultipleSlices(slices)
  63. if len(list) != 0 {
  64. go l.svcCtx.Scheduler.AiService.Si.UpdateDeployInstanceStatusBatch(list, true)
  65. }
  66. resp.List = &deployTasks
  67. resp.PageSize = req.PageSize
  68. resp.PageNum = req.PageNum
  69. resp.Total = total
  70. return
  71. }
  72. func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeployInstanceTask) ([]*DeployTask, error) {
  73. var tasks []*DeployTask
  74. for _, t := range tasklist {
  75. list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(t.Id)
  76. if err != nil {
  77. logx.Errorf("db GetInstanceListByDeployTaskId error")
  78. return nil, errors.New(err.Error())
  79. }
  80. if len(list) == 0 {
  81. //err := l.svcCtx.Scheduler.AiStorages.DeleteDeployTaskById(t.Id)
  82. //if err != nil {
  83. // logx.Errorf("db DeleteByDeployTaskId error")
  84. // return nil, errors.New(err.Error())
  85. //}
  86. continue
  87. }
  88. deployTask := &DeployTask{
  89. Id: t.Id,
  90. Name: t.Name,
  91. Desc: t.Desc,
  92. Instances: list,
  93. }
  94. tasks = append(tasks, deployTask)
  95. }
  96. return tasks, nil
  97. }
  98. type DeployTask struct {
  99. Id int64 `json:"id,string"`
  100. Name string `json:"name"`
  101. Desc string `json:"desc"`
  102. Instances []*models.AiInferDeployInstance `json:"instances,string"`
  103. }

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.