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.0 kB

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

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