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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 StorageService interface {
  8. StartStorageLoadPackage(msg *StartStorageLoadPackage) (*StartStorageLoadPackageResp, *mq.CodeMessage)
  9. WaitStorageLoadPackage(msg *WaitStorageLoadPackage) (*WaitStorageLoadPackageResp, *mq.CodeMessage)
  10. StorageCheck(msg *StorageCheck) (*StorageCheckResp, *mq.CodeMessage)
  11. StartStorageCreatePackage(msg *StartStorageCreatePackage) (*StartStorageCreatePackageResp, *mq.CodeMessage)
  12. WaitStorageCreatePackage(msg *WaitStorageCreatePackage) (*WaitStorageCreatePackageResp, *mq.CodeMessage)
  13. }
  14. // 启动调度Package的任务
  15. var _ = Register(StorageService.StartStorageLoadPackage)
  16. type StartStorageLoadPackage struct {
  17. UserID int64 `json:"userID"`
  18. PackageID int64 `json:"packageID"`
  19. StorageID int64 `json:"storageID"`
  20. }
  21. type StartStorageLoadPackageResp struct {
  22. TaskID string `json:"taskID"`
  23. }
  24. func NewStartStorageLoadPackage(userID int64, packageID int64, storageID int64) StartStorageLoadPackage {
  25. return StartStorageLoadPackage{
  26. UserID: userID,
  27. PackageID: packageID,
  28. StorageID: storageID,
  29. }
  30. }
  31. func NewStartStorageLoadPackageResp(taskID string) StartStorageLoadPackageResp {
  32. return StartStorageLoadPackageResp{
  33. TaskID: taskID,
  34. }
  35. }
  36. func (client *Client) StartStorageLoadPackage(msg StartStorageLoadPackage, opts ...mq.RequestOption) (*StartStorageLoadPackageResp, error) {
  37. return mq.Request[StartStorageLoadPackageResp](client.rabbitCli, msg, opts...)
  38. }
  39. // 等待调度Package的任务
  40. var _ = Register(StorageService.WaitStorageLoadPackage)
  41. type WaitStorageLoadPackage struct {
  42. TaskID string `json:"taskID"`
  43. WaitTimeoutMs int64 `json:"waitTimeout"`
  44. }
  45. type WaitStorageLoadPackageResp struct {
  46. IsComplete bool `json:"isComplete"`
  47. Error string `json:"error"`
  48. }
  49. func NewWaitStorageLoadPackage(taskID string, waitTimeoutMs int64) WaitStorageLoadPackage {
  50. return WaitStorageLoadPackage{
  51. TaskID: taskID,
  52. WaitTimeoutMs: waitTimeoutMs,
  53. }
  54. }
  55. func NewWaitStorageLoadPackageResp(isComplete bool, err string) WaitStorageLoadPackageResp {
  56. return WaitStorageLoadPackageResp{
  57. IsComplete: isComplete,
  58. Error: err,
  59. }
  60. }
  61. func (client *Client) WaitStorageLoadPackage(msg WaitStorageLoadPackage, opts ...mq.RequestOption) (*WaitStorageLoadPackageResp, error) {
  62. return mq.Request[WaitStorageLoadPackageResp](client.rabbitCli, msg, opts...)
  63. }
  64. // 检查Storage
  65. var _ = Register(StorageService.StorageCheck)
  66. const (
  67. CHECK_STORAGE_RESP_OP_DELETE = "Delete"
  68. CHECK_STORAGE_RESP_OP_SET_NORMAL = "SetNormal"
  69. )
  70. type StorageCheck struct {
  71. StorageID int64 `json:"storageID"`
  72. Directory string `json:"directory"`
  73. IsComplete bool `json:"isComplete"`
  74. Packages []model.StoragePackage `json:"packages"`
  75. }
  76. type StorageCheckResp struct {
  77. DirectoryState string `json:"directoryState"`
  78. Entries []StorageCheckRespEntry `json:"entries"`
  79. }
  80. type StorageCheckRespEntry struct {
  81. PackageID int64 `json:"packageID"`
  82. UserID int64 `json:"userID"`
  83. Operation string `json:"operation"`
  84. }
  85. func NewStorageCheck(storageID int64, directory string, isComplete bool, packages []model.StoragePackage) StorageCheck {
  86. return StorageCheck{
  87. StorageID: storageID,
  88. Directory: directory,
  89. IsComplete: isComplete,
  90. Packages: packages,
  91. }
  92. }
  93. func NewStorageCheckResp(dirState string, entries []StorageCheckRespEntry) StorageCheckResp {
  94. return StorageCheckResp{
  95. DirectoryState: dirState,
  96. Entries: entries,
  97. }
  98. }
  99. func NewStorageCheckRespEntry(packageID int64, userID int64, op string) StorageCheckRespEntry {
  100. return StorageCheckRespEntry{
  101. PackageID: packageID,
  102. UserID: userID,
  103. Operation: op,
  104. }
  105. }
  106. func (client *Client) StorageCheck(msg StorageCheck, opts ...mq.RequestOption) (*StorageCheckResp, error) {
  107. return mq.Request[StorageCheckResp](client.rabbitCli, msg, opts...)
  108. }
  109. // 启动从Storage上传Package的任务
  110. var _ = Register(StorageService.StartStorageCreatePackage)
  111. type StartStorageCreatePackage struct {
  112. UserID int64 `json:"userID"`
  113. BucketID int64 `json:"bucketID"`
  114. Name string `json:"name"`
  115. StorageID int64 `json:"storageID"`
  116. Path string `json:"path"`
  117. Redundancy models.TypedRedundancyInfo `json:"redundancy"`
  118. }
  119. type StartStorageCreatePackageResp struct {
  120. TaskID string `json:"taskID"`
  121. }
  122. func NewStartStorageCreatePackage(userID int64, bucketID int64, name string, storageID int64, path string, redundancy models.TypedRedundancyInfo) StartStorageCreatePackage {
  123. return StartStorageCreatePackage{
  124. UserID: userID,
  125. BucketID: bucketID,
  126. Name: name,
  127. StorageID: storageID,
  128. Path: path,
  129. Redundancy: redundancy,
  130. }
  131. }
  132. func NewStartStorageCreatePackageResp(taskID string) StartStorageCreatePackageResp {
  133. return StartStorageCreatePackageResp{
  134. TaskID: taskID,
  135. }
  136. }
  137. func (client *Client) StartStorageCreatePackage(msg StartStorageCreatePackage, opts ...mq.RequestOption) (*StartStorageCreatePackageResp, error) {
  138. return mq.Request[StartStorageCreatePackageResp](client.rabbitCli, msg, opts...)
  139. }
  140. // 等待从Storage上传Package的任务
  141. var _ = Register(StorageService.WaitStorageCreatePackage)
  142. type WaitStorageCreatePackage struct {
  143. TaskID string `json:"taskID"`
  144. WaitTimeoutMs int64 `json:"waitTimeout"`
  145. }
  146. type WaitStorageCreatePackageResp struct {
  147. IsComplete bool `json:"isComplete"`
  148. Error string `json:"error"`
  149. PackageID int64 `json:"packageID"`
  150. }
  151. func NewWaitStorageCreatePackage(taskID string, waitTimeoutMs int64) WaitStorageCreatePackage {
  152. return WaitStorageCreatePackage{
  153. TaskID: taskID,
  154. WaitTimeoutMs: waitTimeoutMs,
  155. }
  156. }
  157. func NewWaitStorageCreatePackageResp(isComplete bool, err string, packageID int64) WaitStorageCreatePackageResp {
  158. return WaitStorageCreatePackageResp{
  159. IsComplete: isComplete,
  160. Error: err,
  161. PackageID: packageID,
  162. }
  163. }
  164. func (client *Client) WaitStorageCreatePackage(msg WaitStorageCreatePackage, opts ...mq.RequestOption) (*WaitStorageCreatePackageResp, error) {
  165. return mq.Request[WaitStorageCreatePackageResp](client.rabbitCli, msg, opts...)
  166. }

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