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

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

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