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.

storage.go 2.3 kB

2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package services
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/client/internal/config"
  5. agtcli "gitlink.org.cn/cloudream/rabbitmq/client/agent"
  6. agtmsg "gitlink.org.cn/cloudream/rabbitmq/message/agent"
  7. coormsg "gitlink.org.cn/cloudream/rabbitmq/message/coordinator"
  8. )
  9. type StorageService struct {
  10. *Service
  11. }
  12. func (svc *Service) StorageSvc() *StorageService {
  13. return &StorageService{Service: svc}
  14. }
  15. func (svc *StorageService) MoveObjectToStorage(userID int, objectID int, storageID int) error {
  16. // 先向协调端请求文件相关的元数据
  17. preMoveResp, err := svc.coordinator.PreMoveObjectToStorage(coormsg.NewPreMoveObjectToStorageBody(objectID, storageID, userID))
  18. if err != nil {
  19. return fmt.Errorf("request to coordinator failed, err: %w", err)
  20. }
  21. if preMoveResp.IsFailed() {
  22. return fmt.Errorf("coordinator PreMoveObjectToStorage failed, code: %s, message: %s", preMoveResp.ErrorCode, preMoveResp.ErrorMessage)
  23. }
  24. // 然后向代理端发送移动文件的请求
  25. agentClient, err := agtcli.NewAgentClient(preMoveResp.Body.NodeID, &config.Cfg().RabbitMQ)
  26. if err != nil {
  27. return fmt.Errorf("create agent client to %d failed, err: %w", preMoveResp.Body.NodeID, err)
  28. }
  29. defer agentClient.Close()
  30. agentMoveResp, err := agentClient.MoveObjectToStorage(
  31. agtmsg.NewMoveObjectToStorageBody(preMoveResp.Body.Directory,
  32. objectID,
  33. userID,
  34. preMoveResp.Body.FileSize,
  35. preMoveResp.Body.Redundancy,
  36. preMoveResp.Body.RedundancyData,
  37. ))
  38. if err != nil {
  39. return fmt.Errorf("request to agent %d failed, err: %w", preMoveResp.Body.NodeID, err)
  40. }
  41. if agentMoveResp.IsFailed() {
  42. return fmt.Errorf("agent %d operation failed, code: %s, messsage: %s", preMoveResp.Body.NodeID, agentMoveResp.ErrorCode, agentMoveResp.ErrorMessage)
  43. }
  44. moveResp, err := svc.coordinator.MoveObjectToStorage(coormsg.NewMoveObjectToStorageBody(objectID, storageID, userID))
  45. if err != nil {
  46. return fmt.Errorf("request to coordinator failed, err: %w", err)
  47. }
  48. if preMoveResp.IsFailed() {
  49. return fmt.Errorf("coordinator MoveObjectToStorage failed, code: %s, message: %s", moveResp.ErrorCode, moveResp.ErrorMessage)
  50. }
  51. return nil
  52. }
  53. func (svc *StorageService) DeleteStorageObject(userID int, objectID int, storageID int) error {
  54. // TODO
  55. panic("not implement yet")
  56. }

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