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.

package.go 6.2 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package coordinator
  2. import (
  3. "time"
  4. "gitlink.org.cn/cloudream/common/pkgs/mq"
  5. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  6. "gitlink.org.cn/cloudream/storage/common/pkgs/db/model"
  7. )
  8. type PackageService interface {
  9. GetPackage(msg *GetPackage) (*GetPackageResp, *mq.CodeMessage)
  10. CreatePackage(msg *CreatePackage) (*CreatePackageResp, *mq.CodeMessage)
  11. UpdatePackage(msg *UpdatePackage) (*UpdatePackageResp, *mq.CodeMessage)
  12. DeletePackage(msg *DeletePackage) (*DeletePackageResp, *mq.CodeMessage)
  13. GetPackageCachedNodes(msg *GetPackageCachedNodes) (*GetPackageCachedNodesResp, *mq.CodeMessage)
  14. GetPackageLoadedNodes(msg *GetPackageLoadedNodes) (*GetPackageLoadedNodesResp, *mq.CodeMessage)
  15. }
  16. // 获取Package基本信息
  17. var _ = Register(Service.GetPackage)
  18. type GetPackage struct {
  19. mq.MessageBodyBase
  20. UserID cdssdk.UserID `json:"userID"`
  21. PackageID cdssdk.PackageID `json:"packageID"`
  22. }
  23. type GetPackageResp struct {
  24. mq.MessageBodyBase
  25. model.Package
  26. }
  27. func NewGetPackage(userID cdssdk.UserID, packageID cdssdk.PackageID) *GetPackage {
  28. return &GetPackage{
  29. UserID: userID,
  30. PackageID: packageID,
  31. }
  32. }
  33. func NewGetPackageResp(pkg model.Package) *GetPackageResp {
  34. return &GetPackageResp{
  35. Package: pkg,
  36. }
  37. }
  38. func (client *Client) GetPackage(msg *GetPackage) (*GetPackageResp, error) {
  39. return mq.Request(Service.GetPackage, client.rabbitCli, msg)
  40. }
  41. // 创建一个Package
  42. var _ = Register(Service.CreatePackage)
  43. type CreatePackage struct {
  44. mq.MessageBodyBase
  45. UserID cdssdk.UserID `json:"userID"`
  46. BucketID cdssdk.BucketID `json:"bucketID"`
  47. Name string `json:"name"`
  48. }
  49. type CreatePackageResp struct {
  50. mq.MessageBodyBase
  51. PackageID cdssdk.PackageID `json:"packageID"`
  52. }
  53. func NewCreatePackage(userID cdssdk.UserID, bucketID cdssdk.BucketID, name string) *CreatePackage {
  54. return &CreatePackage{
  55. UserID: userID,
  56. BucketID: bucketID,
  57. Name: name,
  58. }
  59. }
  60. func NewCreatePackageResp(packageID cdssdk.PackageID) *CreatePackageResp {
  61. return &CreatePackageResp{
  62. PackageID: packageID,
  63. }
  64. }
  65. func (client *Client) CreatePackage(msg *CreatePackage) (*CreatePackageResp, error) {
  66. return mq.Request(Service.CreatePackage, client.rabbitCli, msg)
  67. }
  68. // 更新Package
  69. var _ = Register(Service.UpdatePackage)
  70. type UpdatePackage struct {
  71. mq.MessageBodyBase
  72. PackageID cdssdk.PackageID `json:"packageID"`
  73. Adds []AddObjectEntry `json:"adds"`
  74. Deletes []cdssdk.ObjectID `json:"deletes"`
  75. }
  76. type UpdatePackageResp struct {
  77. mq.MessageBodyBase
  78. }
  79. type AddObjectEntry struct {
  80. Path string `json:"path"`
  81. Size int64 `json:"size,string"`
  82. FileHash string `json:"fileHash"`
  83. UploadTime time.Time `json:"uploadTime"` // 开始上传文件的时间
  84. NodeID cdssdk.NodeID `json:"nodeID"`
  85. }
  86. func NewUpdatePackage(packageID cdssdk.PackageID, adds []AddObjectEntry, deletes []cdssdk.ObjectID) *UpdatePackage {
  87. return &UpdatePackage{
  88. PackageID: packageID,
  89. Adds: adds,
  90. Deletes: deletes,
  91. }
  92. }
  93. func NewUpdatePackageResp() *UpdatePackageResp {
  94. return &UpdatePackageResp{}
  95. }
  96. func NewAddObjectEntry(path string, size int64, fileHash string, uploadTime time.Time, nodeID cdssdk.NodeID) AddObjectEntry {
  97. return AddObjectEntry{
  98. Path: path,
  99. Size: size,
  100. FileHash: fileHash,
  101. UploadTime: uploadTime,
  102. NodeID: nodeID,
  103. }
  104. }
  105. func (client *Client) UpdatePackage(msg *UpdatePackage) (*UpdatePackageResp, error) {
  106. return mq.Request(Service.UpdatePackage, client.rabbitCli, msg)
  107. }
  108. // 删除对象
  109. var _ = Register(Service.DeletePackage)
  110. type DeletePackage struct {
  111. mq.MessageBodyBase
  112. UserID cdssdk.UserID `db:"userID"`
  113. PackageID cdssdk.PackageID `db:"packageID"`
  114. }
  115. type DeletePackageResp struct {
  116. mq.MessageBodyBase
  117. }
  118. func NewDeletePackage(userID cdssdk.UserID, packageID cdssdk.PackageID) *DeletePackage {
  119. return &DeletePackage{
  120. UserID: userID,
  121. PackageID: packageID,
  122. }
  123. }
  124. func NewDeletePackageResp() *DeletePackageResp {
  125. return &DeletePackageResp{}
  126. }
  127. func (client *Client) DeletePackage(msg *DeletePackage) (*DeletePackageResp, error) {
  128. return mq.Request(Service.DeletePackage, client.rabbitCli, msg)
  129. }
  130. // 根据PackageID获取object分布情况
  131. var _ = Register(Service.GetPackageCachedNodes)
  132. type GetPackageCachedNodes struct {
  133. mq.MessageBodyBase
  134. UserID cdssdk.UserID `json:"userID"`
  135. PackageID cdssdk.PackageID `json:"packageID"`
  136. }
  137. type PackageCachedNodeInfo struct {
  138. NodeID int64 `json:"nodeID"`
  139. FileSize int64 `json:"fileSize"`
  140. ObjectCount int64 `json:"objectCount"`
  141. }
  142. type GetPackageCachedNodesResp struct {
  143. mq.MessageBodyBase
  144. cdssdk.PackageCachingInfo
  145. }
  146. func NewGetPackageCachedNodes(userID cdssdk.UserID, packageID cdssdk.PackageID) *GetPackageCachedNodes {
  147. return &GetPackageCachedNodes{
  148. UserID: userID,
  149. PackageID: packageID,
  150. }
  151. }
  152. func NewGetPackageCachedNodesResp(nodeInfos []cdssdk.NodePackageCachingInfo, packageSize int64) *GetPackageCachedNodesResp {
  153. return &GetPackageCachedNodesResp{
  154. PackageCachingInfo: cdssdk.PackageCachingInfo{
  155. NodeInfos: nodeInfos,
  156. PackageSize: packageSize,
  157. },
  158. }
  159. }
  160. func (client *Client) GetPackageCachedNodes(msg *GetPackageCachedNodes) (*GetPackageCachedNodesResp, error) {
  161. return mq.Request(Service.GetPackageCachedNodes, client.rabbitCli, msg)
  162. }
  163. // 根据PackageID获取storage分布情况
  164. var _ = Register(Service.GetPackageLoadedNodes)
  165. type GetPackageLoadedNodes struct {
  166. mq.MessageBodyBase
  167. UserID cdssdk.UserID `json:"userID"`
  168. PackageID cdssdk.PackageID `json:"packageID"`
  169. }
  170. type GetPackageLoadedNodesResp struct {
  171. mq.MessageBodyBase
  172. NodeIDs []cdssdk.NodeID `json:"nodeIDs"`
  173. }
  174. func NewGetPackageLoadedNodes(userID cdssdk.UserID, packageID cdssdk.PackageID) *GetPackageLoadedNodes {
  175. return &GetPackageLoadedNodes{
  176. UserID: userID,
  177. PackageID: packageID,
  178. }
  179. }
  180. func NewGetPackageLoadedNodesResp(nodeIDs []cdssdk.NodeID) *GetPackageLoadedNodesResp {
  181. return &GetPackageLoadedNodesResp{
  182. NodeIDs: nodeIDs,
  183. }
  184. }
  185. func (client *Client) GetPackageLoadedNodes(msg *GetPackageLoadedNodes) (*GetPackageLoadedNodesResp, error) {
  186. return mq.Request(Service.GetPackageLoadedNodes, client.rabbitCli, msg)
  187. }

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