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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 tx.Error != nil {
  31. logx.Errorf(tx.Error.Error())
  32. return nil, tx.Error
  33. }
  34. if len(tasklist) == 0 {
  35. resp.List = nil
  36. resp.PageSize = req.PageSize
  37. resp.PageNum = req.PageNum
  38. resp.Total = 0
  39. return
  40. }
  41. //count total
  42. var total int64
  43. err = tx.Count(&total).Error
  44. tx.Limit(limit).Offset(offset)
  45. if err != nil {
  46. return resp, err
  47. }
  48. err = tx.Order("create_time desc").Find(&tasklist).Error
  49. if err != nil {
  50. return nil, errors.New(err.Error())
  51. }
  52. deployTasks, err := l.GenerateDeployTasks(tasklist)
  53. if err != nil {
  54. return nil, errors.New(err.Error())
  55. }
  56. slices := make([][]*models.AiInferDeployInstance, len(deployTasks))
  57. for i := 0; i < len(deployTasks); i++ {
  58. slices[i] = deployTasks[i].Instances
  59. }
  60. list := common.ConcatMultipleSlices(slices)
  61. if len(list) != 0 {
  62. go status.UpdateDeployInstanceStatusBatch(l.svcCtx, list, true)
  63. }
  64. resp.List = &deployTasks
  65. resp.PageSize = req.PageSize
  66. resp.PageNum = req.PageNum
  67. resp.Total = total
  68. return
  69. }
  70. func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeployInstanceTask) ([]*DeployTask, error) {
  71. var tasks []*DeployTask
  72. for _, t := range tasklist {
  73. list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(t.Id)
  74. if err != nil {
  75. logx.Errorf("db GetInstanceListByDeployTaskId error")
  76. return nil, errors.New(err.Error())
  77. }
  78. if len(list) == 0 {
  79. //err := l.svcCtx.Scheduler.AiStorages.DeleteDeployTaskById(t.Id)
  80. //if err != nil {
  81. // logx.Errorf("db DeleteByDeployTaskId error")
  82. // return nil, errors.New(err.Error())
  83. //}
  84. continue
  85. }
  86. deployTask := &DeployTask{
  87. Id: t.Id,
  88. Name: t.Name,
  89. Desc: t.Desc,
  90. Instances: list,
  91. }
  92. tasks = append(tasks, deployTask)
  93. }
  94. return tasks, nil
  95. }
  96. type DeployTask struct {
  97. Id int64 `json:"id,string"`
  98. Name string `json:"name"`
  99. Desc string `json:"desc"`
  100. Instances []*models.AiInferDeployInstance `json:"instances,string"`
  101. }

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.