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.

aiService.go 3.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package service
  2. import (
  3. "github.com/zeromicro/go-zero/zrpc"
  4. "gitlink.org.cn/JointCloud/pcm-ac/hpcacclient"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/config"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/database"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/service/collector"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/service/executor"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/storeLink"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  11. "gitlink.org.cn/JointCloud/pcm-modelarts/client/imagesservice"
  12. "gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
  13. "gitlink.org.cn/JointCloud/pcm-octopus/octopusclient"
  14. "strconv"
  15. "sync"
  16. )
  17. const (
  18. OCTOPUS = "octopus"
  19. MODELARTS = "modelarts"
  20. SHUGUANGAI = "shuguangAi"
  21. )
  22. type AiService struct {
  23. AiExecutorAdapterMap map[string]map[string]executor.AiExecutor
  24. AiCollectorAdapterMap map[string]map[string]collector.AiCollector
  25. Storage *database.AiStorage
  26. mu sync.Mutex
  27. }
  28. func NewAiService(conf *config.Config, storages *database.AiStorage) (*AiService, error) {
  29. var aiType = "1"
  30. adapterIds, err := storages.GetAdapterIdsByType(aiType)
  31. if err != nil {
  32. return nil, err
  33. }
  34. aiService := &AiService{
  35. AiExecutorAdapterMap: make(map[string]map[string]executor.AiExecutor),
  36. AiCollectorAdapterMap: make(map[string]map[string]collector.AiCollector),
  37. Storage: storages,
  38. }
  39. for _, id := range adapterIds {
  40. clusters, err := storages.GetClustersByAdapterId(id)
  41. if err != nil {
  42. return nil, err
  43. }
  44. if len(clusters.List) == 0 {
  45. continue
  46. }
  47. exeClusterMap, colClusterMap := InitAiClusterMap(conf, clusters.List)
  48. aiService.AiExecutorAdapterMap[id] = exeClusterMap
  49. aiService.AiCollectorAdapterMap[id] = colClusterMap
  50. }
  51. return aiService, nil
  52. }
  53. func InitAiClusterMap(conf *config.Config, clusters []types.ClusterInfo) (map[string]executor.AiExecutor, map[string]collector.AiCollector) {
  54. executorMap := make(map[string]executor.AiExecutor)
  55. collectorMap := make(map[string]collector.AiCollector)
  56. for _, c := range clusters {
  57. switch c.Name {
  58. case OCTOPUS:
  59. id, _ := strconv.ParseInt(c.Id, 10, 64)
  60. octopusRpc := octopusclient.NewOctopus(zrpc.MustNewClient(conf.OctopusRpcConf))
  61. octopus := storeLink.NewOctopusLink(octopusRpc, c.Nickname, id)
  62. collectorMap[c.Id] = octopus
  63. executorMap[c.Id] = octopus
  64. case MODELARTS:
  65. id, _ := strconv.ParseInt(c.Id, 10, 64)
  66. modelArtsRpc := modelartsservice.NewModelArtsService(zrpc.MustNewClient(conf.ModelArtsRpcConf))
  67. modelArtsImgRpc := imagesservice.NewImagesService(zrpc.MustNewClient(conf.ModelArtsImgRpcConf))
  68. modelarts := storeLink.NewModelArtsLink(modelArtsRpc, modelArtsImgRpc, c.Name, id, c.Nickname)
  69. collectorMap[c.Id] = modelarts
  70. executorMap[c.Id] = modelarts
  71. case SHUGUANGAI:
  72. id, _ := strconv.ParseInt(c.Id, 10, 64)
  73. aCRpc := hpcacclient.NewHpcAC(zrpc.MustNewClient(conf.ACRpcConf))
  74. sgai := storeLink.NewShuguangAi(aCRpc, c.Nickname, id)
  75. collectorMap[c.Id] = sgai
  76. executorMap[c.Id] = sgai
  77. }
  78. }
  79. return executorMap, collectorMap
  80. }
  81. //func (a *AiService) AddCluster() error {
  82. //
  83. //}
  84. //
  85. //func (a *AiService) AddAdapter() error {
  86. //
  87. //}

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.