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.

servicecontext.go 3.7 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package svc
  2. import (
  3. "github.com/aws/aws-sdk-go/aws"
  4. "github.com/aws/aws-sdk-go/aws/credentials"
  5. "github.com/aws/aws-sdk-go/aws/session"
  6. "github.com/aws/aws-sdk-go/service/s3/s3manager"
  7. "github.com/docker/docker/client"
  8. "github.com/go-redis/redis"
  9. "github.com/robfig/cron/v3"
  10. "github.com/zeromicro/go-queue/kq"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. "github.com/zeromicro/go-zero/zrpc"
  13. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/config"
  14. "gitlink.org.cn/jcce-pcm/pcm-participant-ac/hpcacclient"
  15. "gitlink.org.cn/jcce-pcm/pcm-participant-ceph/cephclient"
  16. "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelartsclient"
  17. "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopusclient"
  18. "gitlink.org.cn/jcce-pcm/pcm-participant-slurm/hpcthclient"
  19. "gorm.io/driver/mysql"
  20. "gorm.io/gorm"
  21. "gorm.io/gorm/schema"
  22. )
  23. type ServiceContext struct {
  24. Config config.Config
  25. RedisClient *redis.Client
  26. ScheduleHpcClient *kq.Pusher
  27. ScheduleCloudClient *kq.Pusher
  28. ScheduleAiClient *kq.Pusher
  29. Cron *cron.Cron
  30. ModelArtsRpc modelartsclient.ModelArts
  31. DbEngin *gorm.DB
  32. ACRpc hpcacclient.HpcAC
  33. THRpc hpcthclient.HpcTH
  34. OctopusRpc octopusclient.Octopus
  35. CephRpc cephclient.Ceph
  36. DockerClient *client.Client
  37. Downloader *s3manager.Downloader
  38. Uploader *s3manager.Uploader
  39. }
  40. func NewServiceContext(c config.Config) *ServiceContext {
  41. // 创建s3 session
  42. session, _ := session.NewSession(&aws.Config{
  43. Credentials: credentials.NewStaticCredentials(c.MinioConf.AccessKey, c.MinioConf.Secret, ""), //使用静态凭据,硬编码
  44. Endpoint: aws.String(c.MinioConf.Endpoint), //配置端点
  45. Region: aws.String("default"), //配置区域
  46. DisableSSL: aws.Bool(false), //是否禁用https,这里表示不禁用,即使用HTTPS
  47. S3ForcePathStyle: aws.Bool(true), //使用路径样式而非虚拟主机样式,区别请参考:https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
  48. })
  49. downloader := s3manager.NewDownloader(session)
  50. uploader := s3manager.NewUploader(session)
  51. //启动Gorm支持
  52. dbEngin, _ := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{
  53. NamingStrategy: schema.NamingStrategy{
  54. SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user`
  55. },
  56. })
  57. dockerClient, err := client.NewClientWithOpts()
  58. if err != nil {
  59. logx.Error(err.Error())
  60. return nil
  61. }
  62. return &ServiceContext{
  63. Cron: cron.New(cron.WithSeconds()),
  64. DbEngin: dbEngin,
  65. Config: c,
  66. RedisClient: redis.NewClient(&redis.Options{
  67. Addr: c.Redis.Host,
  68. Password: c.Redis.Pass,
  69. }),
  70. ScheduleHpcClient: kq.NewPusher(c.KqProducerConf.Brokers, c.KqProducerConf.HpcTopic),
  71. ScheduleCloudClient: kq.NewPusher(c.KqProducerConf.Brokers, c.KqProducerConf.CloudTopic),
  72. ScheduleAiClient: kq.NewPusher(c.KqProducerConf.Brokers, c.KqProducerConf.AiTopic),
  73. ModelArtsRpc: modelartsclient.NewModelArts(zrpc.MustNewClient(c.ModelArtsRpcConf)),
  74. CephRpc: cephclient.NewCeph(zrpc.MustNewClient(c.CephRpcConf)),
  75. ACRpc: hpcacclient.NewHpcAC(zrpc.MustNewClient(c.ACRpcConf)),
  76. OctopusRpc: octopusclient.NewOctopus(zrpc.MustNewClient(c.OctopusRpcConf)),
  77. DockerClient: dockerClient,
  78. Downloader: downloader,
  79. Uploader: uploader,
  80. }
  81. }

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.