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.

hub.go 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package mq
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/common/consts/errorcode"
  5. "gitlink.org.cn/cloudream/common/pkgs/logger"
  6. "gitlink.org.cn/cloudream/common/pkgs/mq"
  7. coormq "gitlink.org.cn/cloudream/storage2/common/pkgs/mq/coordinator"
  8. cortypes "gitlink.org.cn/cloudream/storage2/coordinator/types"
  9. )
  10. func (svc *Service) GetHubConfig(msg *coormq.GetHubConfig) (*coormq.GetHubConfigResp, *mq.CodeMessage) {
  11. log := logger.WithField("HubID", msg.HubID)
  12. hub, err := svc.db.Hub().GetByID(svc.db.DefCtx(), msg.HubID)
  13. if err != nil {
  14. log.Warnf("getting hub: %v", err)
  15. return nil, mq.Failed(errorcode.OperationFailed, fmt.Sprintf("getting hub: %v", err))
  16. }
  17. return mq.ReplyOK(coormq.RespGetHubConfig(hub))
  18. }
  19. func (svc *Service) GetHubs(msg *coormq.GetHubs) (*coormq.GetHubsResp, *mq.CodeMessage) {
  20. var hubs []*cortypes.Hub
  21. if msg.HubIDs == nil {
  22. get, err := svc.db.Hub().GetAllHubs(svc.db.DefCtx())
  23. if err != nil {
  24. logger.Warnf("getting all hubs: %s", err.Error())
  25. return nil, mq.Failed(errorcode.OperationFailed, "get all hub failed")
  26. }
  27. for _, hub := range get {
  28. h := hub
  29. hubs = append(hubs, &h)
  30. }
  31. } else {
  32. // 可以不用事务
  33. get, err := svc.db.Hub().BatchGetByID(svc.db.DefCtx(), msg.HubIDs)
  34. if err != nil {
  35. logger.Warnf("batch get hubs by id: %s", err.Error())
  36. return nil, mq.Failed(errorcode.OperationFailed, fmt.Sprintf("batch get hubs by id: %v", err))
  37. }
  38. getMp := make(map[cortypes.HubID]cortypes.Hub)
  39. for _, hub := range get {
  40. getMp[hub.HubID] = hub
  41. }
  42. for _, id := range msg.HubIDs {
  43. if hub, ok := getMp[id]; ok {
  44. h := hub
  45. hubs = append(hubs, &h)
  46. } else {
  47. hubs = append(hubs, nil)
  48. }
  49. }
  50. }
  51. return mq.ReplyOK(coormq.NewGetHubsResp(hubs))
  52. }
  53. func (svc *Service) GetHubConnectivities(msg *coormq.GetHubConnectivities) (*coormq.GetHubConnectivitiesResp, *mq.CodeMessage) {
  54. cons, err := svc.db.HubConnectivity().BatchGetByFromHub(svc.db.DefCtx(), msg.HubIDs)
  55. if err != nil {
  56. logger.Warnf("batch get hub connectivities by from hub: %s", err.Error())
  57. return nil, mq.Failed(errorcode.OperationFailed, "batch get hub connectivities by from hub failed")
  58. }
  59. return mq.ReplyOK(coormq.RespGetHubConnectivities(cons))
  60. }

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