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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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-octopus/octopusclient"
  12. "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/imagesservice"
  13. "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/modelartsservice"
  14. "strconv"
  15. )
  16. const (
  17. OCTOPUS = "octopus"
  18. MODELARTS = "modelarts"
  19. SHUGUANGAI = "shuguangAi"
  20. )
  21. type AiService struct {
  22. AiExecutorAdapterMap map[string]map[string]executor.AiExecutor
  23. AiCollectorAdapterMap map[string]map[string]collector.AiCollector
  24. }
  25. func NewAiService(conf *config.Config, storages *database.AiStorage) (*AiService, error) {
  26. var aiType = "1"
  27. adapterIds, err := storages.GetAdapterIdsByType(aiType)
  28. if err != nil {
  29. return nil, err
  30. }
  31. aiService := &AiService{
  32. AiExecutorAdapterMap: make(map[string]map[string]executor.AiExecutor),
  33. AiCollectorAdapterMap: make(map[string]map[string]collector.AiCollector),
  34. }
  35. for _, id := range adapterIds {
  36. clusters, err := storages.GetClustersByAdapterId(id)
  37. if err != nil {
  38. return nil, err
  39. }
  40. exeClusterMap, colClusterMap := InitAiClusterMap(conf, clusters.List)
  41. aiService.AiExecutorAdapterMap[id] = exeClusterMap
  42. aiService.AiCollectorAdapterMap[id] = colClusterMap
  43. }
  44. return aiService, nil
  45. }
  46. func InitAiClusterMap(conf *config.Config, clusters []types.ClusterInfo) (map[string]executor.AiExecutor, map[string]collector.AiCollector) {
  47. executorMap := make(map[string]executor.AiExecutor)
  48. collectorMap := make(map[string]collector.AiCollector)
  49. for _, c := range clusters {
  50. switch c.Name {
  51. case OCTOPUS:
  52. id, _ := strconv.ParseInt(c.Id, 10, 64)
  53. octopusRpc := octopusclient.NewOctopus(zrpc.MustNewClient(conf.OctopusRpcConf))
  54. octopus := storeLink.NewOctopusLink(octopusRpc, c.Nickname, id)
  55. collectorMap[c.Id] = octopus
  56. executorMap[c.Id] = octopus
  57. case MODELARTS:
  58. id, _ := strconv.ParseInt(c.Id, 10, 64)
  59. modelArtsRpc := modelartsservice.NewModelArtsService(zrpc.MustNewClient(conf.ModelArtsRpcConf))
  60. modelArtsImgRpc := imagesservice.NewImagesService(zrpc.MustNewClient(conf.ModelArtsImgRpcConf))
  61. modelarts := storeLink.NewModelArtsLink(modelArtsRpc, modelArtsImgRpc, c.Nickname, id)
  62. collectorMap[c.Id] = modelarts
  63. executorMap[c.Id] = modelarts
  64. case SHUGUANGAI:
  65. id, _ := strconv.ParseInt(c.Id, 10, 64)
  66. aCRpc := hpcacclient.NewHpcAC(zrpc.MustNewClient(conf.ACRpcConf))
  67. sgai := storeLink.NewShuguangAi(aCRpc, c.Nickname, id)
  68. collectorMap[c.Id] = sgai
  69. executorMap[c.Id] = sgai
  70. }
  71. }
  72. return executorMap, collectorMap
  73. }

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.