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

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

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.