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.

cache.go 3.5 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package agent
  2. import (
  3. "gitlink.org.cn/cloudream/common/models"
  4. "gitlink.org.cn/cloudream/common/pkgs/mq"
  5. "gitlink.org.cn/cloudream/storage/common/pkgs/db/model"
  6. )
  7. type CacheService interface {
  8. CheckCache(msg *CheckCache) (*CheckCacheResp, *mq.CodeMessage)
  9. StartCacheMovePackage(msg *StartCacheMovePackage) (*StartCacheMovePackageResp, *mq.CodeMessage)
  10. WaitCacheMovePackage(msg *WaitCacheMovePackage) (*WaitCacheMovePackageResp, *mq.CodeMessage)
  11. }
  12. // 检查节点上的IPFS
  13. var _ = Register(Service.CheckCache)
  14. const (
  15. CHECK_IPFS_RESP_OP_DELETE_TEMP = "DeleteTemp"
  16. CHECK_IPFS_RESP_OP_CREATE_TEMP = "CreateTemp"
  17. )
  18. type CheckCache struct {
  19. mq.MessageBodyBase
  20. IsComplete bool `json:"isComplete"`
  21. Caches []model.Cache `json:"caches"`
  22. }
  23. type CheckCacheResp struct {
  24. mq.MessageBodyBase
  25. Entries []CheckIPFSRespEntry `json:"entries"`
  26. }
  27. type CheckIPFSRespEntry struct {
  28. FileHash string `json:"fileHash"`
  29. Operation string `json:"operation"`
  30. }
  31. func NewCheckCache(isComplete bool, caches []model.Cache) *CheckCache {
  32. return &CheckCache{
  33. IsComplete: isComplete,
  34. Caches: caches,
  35. }
  36. }
  37. func NewCheckCacheResp(entries []CheckIPFSRespEntry) *CheckCacheResp {
  38. return &CheckCacheResp{
  39. Entries: entries,
  40. }
  41. }
  42. func NewCheckCacheRespEntry(fileHash string, op string) CheckIPFSRespEntry {
  43. return CheckIPFSRespEntry{
  44. FileHash: fileHash,
  45. Operation: op,
  46. }
  47. }
  48. func (client *Client) CheckCache(msg *CheckCache, opts ...mq.RequestOption) (*CheckCacheResp, error) {
  49. return mq.Request(Service.CheckCache, client.rabbitCli, msg, opts...)
  50. }
  51. // 将Package的缓存移动到这个节点
  52. var _ = Register(Service.StartCacheMovePackage)
  53. type StartCacheMovePackage struct {
  54. mq.MessageBodyBase
  55. UserID int64 `json:"userID"`
  56. PackageID int64 `json:"packageID"`
  57. }
  58. type StartCacheMovePackageResp struct {
  59. mq.MessageBodyBase
  60. TaskID string `json:"taskID"`
  61. }
  62. func NewStartCacheMovePackage(userID int64, packageID int64) *StartCacheMovePackage {
  63. return &StartCacheMovePackage{
  64. UserID: userID,
  65. PackageID: packageID,
  66. }
  67. }
  68. func NewStartCacheMovePackageResp(taskID string) *StartCacheMovePackageResp {
  69. return &StartCacheMovePackageResp{
  70. TaskID: taskID,
  71. }
  72. }
  73. func (client *Client) StartCacheMovePackage(msg *StartCacheMovePackage, opts ...mq.RequestOption) (*StartCacheMovePackageResp, error) {
  74. return mq.Request(Service.StartCacheMovePackage, client.rabbitCli, msg, opts...)
  75. }
  76. // 将Package的缓存移动到这个节点
  77. var _ = Register(Service.WaitCacheMovePackage)
  78. type WaitCacheMovePackage struct {
  79. mq.MessageBodyBase
  80. TaskID string `json:"taskID"`
  81. WaitTimeoutMs int64 `json:"waitTimeout"`
  82. }
  83. type WaitCacheMovePackageResp struct {
  84. mq.MessageBodyBase
  85. IsComplete bool `json:"isComplete"`
  86. Error string `json:"error"`
  87. CacheInfos []models.ObjectCacheInfo `json:"cacheInfos"`
  88. }
  89. func NewWaitCacheMovePackage(taskID string, waitTimeoutMs int64) *WaitCacheMovePackage {
  90. return &WaitCacheMovePackage{
  91. TaskID: taskID,
  92. WaitTimeoutMs: waitTimeoutMs,
  93. }
  94. }
  95. func NewWaitCacheMovePackageResp(isComplete bool, err string, cacheInfos []models.ObjectCacheInfo) *WaitCacheMovePackageResp {
  96. return &WaitCacheMovePackageResp{
  97. IsComplete: isComplete,
  98. Error: err,
  99. CacheInfos: cacheInfos,
  100. }
  101. }
  102. func (client *Client) WaitCacheMovePackage(msg *WaitCacheMovePackage, opts ...mq.RequestOption) (*WaitCacheMovePackageResp, error) {
  103. return mq.Request(Service.WaitCacheMovePackage, client.rabbitCli, msg, opts...)
  104. }

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