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.

main.go 2.5 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package main
  2. import (
  3. "fmt"
  4. "net"
  5. "os"
  6. "sync"
  7. "gitlink.org.cn/cloudream/agent/internal/config"
  8. "gitlink.org.cn/cloudream/agent/internal/task"
  9. log "gitlink.org.cn/cloudream/common/pkg/logger"
  10. "gitlink.org.cn/cloudream/common/utils/ipfs"
  11. agentserver "gitlink.org.cn/cloudream/proto"
  12. "google.golang.org/grpc"
  13. rasvr "gitlink.org.cn/cloudream/rabbitmq/server/agent"
  14. cmdsvc "gitlink.org.cn/cloudream/agent/internal/services/cmd"
  15. grpcsvc "gitlink.org.cn/cloudream/agent/internal/services/grpc"
  16. )
  17. // TODO 此数据是否在运行时会发生变化?
  18. var AgentIpList []string
  19. func main() {
  20. // TODO 放到配置里读取
  21. AgentIpList = []string{"pcm01", "pcm1", "pcm2"}
  22. err := config.Init()
  23. if err != nil {
  24. fmt.Printf("init config failed, err: %s", err.Error())
  25. os.Exit(1)
  26. }
  27. err = log.Init(&config.Cfg().Logger)
  28. if err != nil {
  29. fmt.Printf("init logger failed, err: %s", err.Error())
  30. os.Exit(1)
  31. }
  32. ipfs, err := ipfs.NewIPFS(&config.Cfg().IPFS)
  33. if err != nil {
  34. log.Fatalf("new ipfs failed, err: %s", err.Error())
  35. }
  36. //处置协调端、客户端命令(可多建几个)
  37. wg := sync.WaitGroup{}
  38. wg.Add(4)
  39. taskMgr := task.NewManager(ipfs)
  40. // 启动命令服务器
  41. // TODO 需要设计AgentID持久化机制
  42. agtSvr, err := rasvr.NewServer(cmdsvc.NewService(ipfs, &taskMgr), config.Cfg().ID, &config.Cfg().RabbitMQ)
  43. if err != nil {
  44. log.Fatalf("new agent server failed, err: %s", err.Error())
  45. }
  46. agtSvr.OnError = func(err error) {
  47. log.Warnf("agent server err: %s", err.Error())
  48. }
  49. go serveAgentServer(agtSvr, &wg)
  50. go reportStatus(&wg) //网络延迟感知
  51. //面向客户端收发数据
  52. listenAddr := config.Cfg().GRPCListenAddress
  53. lis, err := net.Listen("tcp", listenAddr)
  54. if err != nil {
  55. log.Fatalf("listen on %s failed, err: %s", listenAddr, err.Error())
  56. }
  57. s := grpc.NewServer()
  58. agentserver.RegisterFileTransportServer(s, grpcsvc.NewService(ipfs))
  59. go serveGRPC(s, lis, &wg)
  60. wg.Wait()
  61. }
  62. func serveAgentServer(server *rasvr.Server, wg *sync.WaitGroup) {
  63. log.Info("start serving command server")
  64. err := server.Serve()
  65. if err != nil {
  66. log.Errorf("command server stopped with error: %s", err.Error())
  67. }
  68. log.Info("command server stopped")
  69. wg.Done()
  70. }
  71. func serveGRPC(s *grpc.Server, lis net.Listener, wg *sync.WaitGroup) {
  72. log.Info("start serving grpc")
  73. err := s.Serve(lis)
  74. if err != nil {
  75. log.Errorf("grpc stopped with error: %s", err.Error())
  76. }
  77. log.Info("grpc stopped")
  78. wg.Done()
  79. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。