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.

aiCronTask.go 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package cron
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. )
  10. func GetTaskList(svc *svc.ServiceContext) ([]*types.TaskModel, error) {
  11. limit := 10
  12. offset := 0
  13. var list []*types.TaskModel
  14. db := svc.DbEngin.Model(&types.TaskModel{}).Table("task")
  15. db = db.Where("deleted_at is null")
  16. //count total
  17. var total int64
  18. err := db.Count(&total).Error
  19. db.Limit(limit).Offset(offset)
  20. if err != nil {
  21. return nil, err
  22. }
  23. err = db.Order("created_time desc").Find(&list).Error
  24. if err != nil {
  25. return nil, err
  26. }
  27. return list, nil
  28. }
  29. func UpdateAiAdapterMaps(svc *svc.ServiceContext) {
  30. var aiType = "1"
  31. adapterIds, err := svc.Scheduler.AiStorages.GetAdapterIdsByType(aiType)
  32. if err != nil {
  33. msg := fmt.Sprintf("###UpdateAiAdapterMaps###, error: %v \n", err.Error())
  34. logx.Errorf(errors.New(msg).Error())
  35. return
  36. }
  37. if len(adapterIds) == 0 {
  38. return
  39. }
  40. for _, id := range adapterIds {
  41. clusters, err := svc.Scheduler.AiStorages.GetClustersByAdapterId(id)
  42. if err != nil {
  43. msg := fmt.Sprintf("###UpdateAiAdapterMaps###, error: %v \n", err.Error())
  44. logx.Errorf(errors.New(msg).Error())
  45. return
  46. }
  47. if len(clusters.List) == 0 {
  48. continue
  49. }
  50. if isAdapterExist(svc, id, len(clusters.List)) {
  51. continue
  52. } else {
  53. if isAdapterEmpty(svc, id) {
  54. exeClusterMap, colClusterMap, inferMap := service.InitAiClusterMap(&svc.Config, clusters.List)
  55. svc.Scheduler.AiService.AiExecutorAdapterMap[id] = exeClusterMap
  56. svc.Scheduler.AiService.AiCollectorAdapterMap[id] = colClusterMap
  57. svc.Scheduler.AiService.InferenceAdapterMap[id] = inferMap
  58. } else {
  59. svc.Scheduler.AiService.UpdateClusterMaps(&svc.Config, id, clusters.List)
  60. }
  61. }
  62. }
  63. }
  64. func isAdapterExist(svc *svc.ServiceContext, id string, clusterNum int) bool {
  65. emap, ok := svc.Scheduler.AiService.AiExecutorAdapterMap[id]
  66. cmap, ok2 := svc.Scheduler.AiService.AiCollectorAdapterMap[id]
  67. imap, ok3 := svc.Scheduler.AiService.InferenceAdapterMap[id]
  68. if ok && ok2 && ok3 {
  69. if len(emap) == clusterNum && len(cmap) == clusterNum && len(imap) == clusterNum {
  70. return true
  71. }
  72. }
  73. return false
  74. }
  75. func isAdapterEmpty(svc *svc.ServiceContext, id string) bool {
  76. _, ok := svc.Scheduler.AiService.AiExecutorAdapterMap[id]
  77. _, ok2 := svc.Scheduler.AiService.AiCollectorAdapterMap[id]
  78. _, ok3 := svc.Scheduler.AiService.InferenceAdapterMap[id]
  79. if !ok && !ok2 && !ok3 {
  80. return true
  81. }
  82. return false
  83. }

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.