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.

node.go 1.5 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package services
  2. import (
  3. "gitlink.org.cn/cloudream/common/consts/errorcode"
  4. "gitlink.org.cn/cloudream/common/pkgs/logger"
  5. "gitlink.org.cn/cloudream/common/pkgs/mq"
  6. "gitlink.org.cn/cloudream/storage/common/pkgs/db/model"
  7. coormq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/coordinator"
  8. )
  9. func (svc *Service) GetUserNodes(msg *coormq.GetUserNodes) (*coormq.GetUserNodesResp, *mq.CodeMessage) {
  10. nodes, err := svc.db.Node().GetUserNodes(svc.db.SQLCtx(), msg.UserID)
  11. if err != nil {
  12. logger.WithField("UserID", msg.UserID).
  13. Warnf("query user nodes failed, err: %s", err.Error())
  14. return nil, mq.Failed(errorcode.OperationFailed, "query user nodes failed")
  15. }
  16. return mq.ReplyOK(coormq.NewGetUserNodesResp(nodes))
  17. }
  18. func (svc *Service) GetNodes(msg *coormq.GetNodes) (*coormq.GetNodesResp, *mq.CodeMessage) {
  19. var nodes []model.Node
  20. if msg.NodeIDs == nil {
  21. var err error
  22. nodes, err = svc.db.Node().GetAllNodes(svc.db.SQLCtx())
  23. if err != nil {
  24. logger.Warnf("getting all nodes: %s", err.Error())
  25. return nil, mq.Failed(errorcode.OperationFailed, "get all node failed")
  26. }
  27. } else {
  28. for _, id := range msg.NodeIDs {
  29. node, err := svc.db.Node().GetByID(svc.db.SQLCtx(), id)
  30. if err != nil {
  31. logger.WithField("NodeID", id).
  32. Warnf("query node failed, err: %s", err.Error())
  33. return nil, mq.Failed(errorcode.OperationFailed, "query node failed")
  34. }
  35. nodes = append(nodes, node)
  36. }
  37. }
  38. return mq.ReplyOK(coormq.NewGetNodesResp(nodes))
  39. }

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