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 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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) GetHubs(msg *coormq.GetHubs) (*coormq.GetHubsResp, *mq.CodeMessage) {
  11. var hubs []*cortypes.Hub
  12. if msg.HubIDs == nil {
  13. get, err := svc.db.Hub().GetAllHubs(svc.db.DefCtx())
  14. if err != nil {
  15. logger.Warnf("getting all hubs: %s", err.Error())
  16. return nil, mq.Failed(errorcode.OperationFailed, "get all hub failed")
  17. }
  18. for _, hub := range get {
  19. h := hub
  20. hubs = append(hubs, &h)
  21. }
  22. } else {
  23. // 可以不用事务
  24. get, err := svc.db.Hub().BatchGetByID(svc.db.DefCtx(), msg.HubIDs)
  25. if err != nil {
  26. logger.Warnf("batch get hubs by id: %s", err.Error())
  27. return nil, mq.Failed(errorcode.OperationFailed, fmt.Sprintf("batch get hubs by id: %v", err))
  28. }
  29. getMp := make(map[cortypes.HubID]cortypes.Hub)
  30. for _, hub := range get {
  31. getMp[hub.HubID] = hub
  32. }
  33. for _, id := range msg.HubIDs {
  34. if hub, ok := getMp[id]; ok {
  35. h := hub
  36. hubs = append(hubs, &h)
  37. } else {
  38. hubs = append(hubs, nil)
  39. }
  40. }
  41. }
  42. return mq.ReplyOK(coormq.NewGetHubsResp(hubs))
  43. }
  44. func (svc *Service) GetHubConnectivities(msg *coormq.GetHubConnectivities) (*coormq.GetHubConnectivitiesResp, *mq.CodeMessage) {
  45. cons, err := svc.db.HubConnectivity().BatchGetByFromHub(svc.db.DefCtx(), msg.HubIDs)
  46. if err != nil {
  47. logger.Warnf("batch get hub connectivities by from hub: %s", err.Error())
  48. return nil, mq.Failed(errorcode.OperationFailed, "batch get hub connectivities by from hub failed")
  49. }
  50. return mq.ReplyOK(coormq.RespGetHubConnectivities(cons))
  51. }

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