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.

datamap.go 14 kB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. package stgmod
  2. import (
  3. "fmt"
  4. "time"
  5. "gitlink.org.cn/cloudream/common/pkgs/types"
  6. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  7. "gitlink.org.cn/cloudream/common/utils/serder"
  8. )
  9. // 系统事件
  10. type SysEvent struct {
  11. Timestamp time.Time `json:"timestamp"`
  12. Source SysEventSource `json:"source"`
  13. Body SysEventBody `json:"body"`
  14. }
  15. func (e *SysEvent) String() string {
  16. return fmt.Sprintf("%v [%v] %+v", e.Timestamp.Format("2006-01-02 15:04:05"), e.Source, e.Body)
  17. }
  18. // 事件源
  19. type SysEventSource interface {
  20. GetSourceType() string
  21. }
  22. var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[SysEventSource](
  23. (*SourceCoordinator)(nil),
  24. (*SourceScanner)(nil),
  25. (*SourceHub)(nil),
  26. )), "type")
  27. type SourceCoordinator struct {
  28. serder.Metadata `union:"Coordinator"`
  29. Type string `json:"type"`
  30. }
  31. func (s *SourceCoordinator) GetSourceType() string {
  32. return "Coordinator"
  33. }
  34. func (s *SourceCoordinator) OnUnionSerializing() {
  35. s.Type = s.GetSourceType()
  36. }
  37. func (s *SourceCoordinator) String() string {
  38. return "Coordinator"
  39. }
  40. type SourceScanner struct {
  41. serder.Metadata `union:"Scanner"`
  42. Type string `json:"type"`
  43. }
  44. func (s *SourceScanner) GetSourceType() string {
  45. return "Scanner"
  46. }
  47. func (s *SourceScanner) OnUnionSerializing() {
  48. s.Type = s.GetSourceType()
  49. }
  50. func (s *SourceScanner) String() string {
  51. return "Scanner"
  52. }
  53. type SourceHub struct {
  54. serder.Metadata `union:"Hub"`
  55. Type string `json:"type"`
  56. HubID cdssdk.HubID `json:"hubID"`
  57. HubName string `json:"hubName"`
  58. }
  59. func (s *SourceHub) GetSourceType() string {
  60. return "Hub"
  61. }
  62. func (s *SourceHub) OnUnionSerializing() {
  63. s.Type = s.GetSourceType()
  64. }
  65. func (s *SourceHub) String() string {
  66. return fmt.Sprintf("Hub(%d, %s)", s.HubID, s.HubName)
  67. }
  68. // 事件体
  69. type SysEventBody interface {
  70. GetBodyType() string
  71. }
  72. var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[SysEventBody](
  73. (*BodyNewHub)(nil),
  74. (*BodyHubUpdated)(nil),
  75. (*BodyHubDeleted)(nil),
  76. (*BodyNewStorage)(nil),
  77. (*BodyStorageUpdated)(nil),
  78. (*BodyStorageDeleted)(nil),
  79. (*BodyStorageStats)(nil),
  80. (*BodyHubTransferStats)(nil),
  81. (*BodyHubStorageTransferStats)(nil),
  82. (*BodyBlockTransfer)(nil),
  83. (*BodyBlockDistribution)(nil),
  84. (*BodyNewOrUpdateObject)(nil),
  85. (*BodyObjectInfoUpdated)(nil),
  86. (*BodyObjectDeleted)(nil),
  87. (*BodyNewPackage)(nil),
  88. (*BodyPackageCloned)(nil),
  89. (*BodyPackageDeleted)(nil),
  90. (*BodyNewBucket)(nil),
  91. (*BodyBucketDeleted)(nil),
  92. )), "type")
  93. // 新增Hub的事件
  94. type BodyNewHub struct {
  95. serder.Metadata `union:"NewHub"`
  96. Type string `json:"type"`
  97. Info cdssdk.Hub `json:"info"`
  98. }
  99. func (b *BodyNewHub) GetBodyType() string {
  100. return "NewHub"
  101. }
  102. func (b *BodyNewHub) OnUnionSerializing() {
  103. b.Type = b.GetBodyType()
  104. }
  105. // Hub信息更新的事件
  106. type BodyHubUpdated struct {
  107. serder.Metadata `union:"HubUpdated"`
  108. Type string `json:"type"`
  109. Info cdssdk.Hub `json:"info"`
  110. }
  111. func (b *BodyHubUpdated) GetBodyType() string {
  112. return "HubUpdated"
  113. }
  114. func (b *BodyHubUpdated) OnUnionSerializing() {
  115. b.Type = b.GetBodyType()
  116. }
  117. // Hub删除的事件
  118. type BodyHubDeleted struct {
  119. serder.Metadata `union:"HubDeleted"`
  120. Type string `json:"type"`
  121. HubID cdssdk.HubID `json:"hubID"`
  122. }
  123. func (b *BodyHubDeleted) GetBodyType() string {
  124. return "HubDeleted"
  125. }
  126. func (b *BodyHubDeleted) OnUnionSerializing() {
  127. b.Type = b.GetBodyType()
  128. }
  129. // 新增Storage的事件
  130. type BodyNewStorage struct {
  131. serder.Metadata `union:"NewStorage"`
  132. Info cdssdk.Storage `json:"info"`
  133. Type string `json:"type"`
  134. }
  135. func (b *BodyNewStorage) GetBodyType() string {
  136. return "NewStorage"
  137. }
  138. func (b *BodyNewStorage) OnUnionSerializing() {
  139. b.Type = b.GetBodyType()
  140. }
  141. // Storage信息更新的事件
  142. type BodyStorageUpdated struct {
  143. serder.Metadata `union:"StorageUpdated"`
  144. Type string `json:"type"`
  145. Info cdssdk.Storage `json:"info"`
  146. }
  147. func (b *BodyStorageUpdated) GetBodyType() string {
  148. return "StorageUpdated"
  149. }
  150. func (b *BodyStorageUpdated) OnUnionSerializing() {
  151. b.Type = b.GetBodyType()
  152. }
  153. // Storage删除的事件
  154. type BodyStorageDeleted struct {
  155. serder.Metadata `union:"StorageDeleted"`
  156. Type string `json:"type"`
  157. StorageID cdssdk.StorageID `json:"storageID"`
  158. }
  159. func (b *BodyStorageDeleted) GetBodyType() string {
  160. return "StorageDeleted"
  161. }
  162. func (b *BodyStorageDeleted) OnUnionSerializing() {
  163. b.Type = b.GetBodyType()
  164. }
  165. // Storage统计信息的事件
  166. type BodyStorageStats struct {
  167. serder.Metadata `union:"StorageStats"`
  168. Type string `json:"type"`
  169. StorageID cdssdk.StorageID `json:"storageID"`
  170. DataCount int64 `json:"dataCount"`
  171. }
  172. func (b *BodyStorageStats) GetBodyType() string {
  173. return "StorageStats"
  174. }
  175. func (b *BodyStorageStats) OnUnionSerializing() {
  176. b.Type = b.GetBodyType()
  177. }
  178. // Hub数据传输统计信息的事件
  179. type BodyHubTransferStats struct {
  180. serder.Metadata `union:"HubTransferStats"`
  181. Type string `json:"type"`
  182. SourceHubID cdssdk.HubID `json:"sourceHubID"`
  183. TargetHubID cdssdk.HubID `json:"targetHubID"`
  184. Send DataTrans `json:"send"`
  185. StartTimestamp time.Time `json:"startTimestamp"`
  186. EndTimestamp time.Time `json:"endTimestamp"`
  187. }
  188. func (b *BodyHubTransferStats) GetBodyType() string {
  189. return "HubTransferStats"
  190. }
  191. func (b *BodyHubTransferStats) OnUnionSerializing() {
  192. b.Type = b.GetBodyType()
  193. }
  194. type DataTrans struct {
  195. TotalTransfer int64 `json:"totalTransfer"`
  196. RequestCount int64 `json:"requestCount"`
  197. FailedRequestCount int64 `json:"failedRequestCount"`
  198. AvgTransfer int64 `json:"avgTransfer"`
  199. MaxTransfer int64 `json:"maxTransfer"`
  200. MinTransfer int64 `json:"minTransfer"`
  201. }
  202. // Hub和Storage数据传输统计信息的事件
  203. type BodyHubStorageTransferStats struct {
  204. serder.Metadata `union:"HubStorageTransferStats"`
  205. Type string `json:"type"`
  206. HubID cdssdk.HubID `json:"hubID"`
  207. StorageID cdssdk.StorageID `json:"storageID"`
  208. Send DataTrans `json:"send"`
  209. Receive DataTrans `json:"receive"`
  210. StartTimestamp time.Time `json:"startTimestamp"`
  211. EndTimestamp time.Time `json:"endTimestamp"`
  212. }
  213. func (b *BodyHubStorageTransferStats) GetBodyType() string {
  214. return "HubStorageTransferStats"
  215. }
  216. func (b *BodyHubStorageTransferStats) OnUnionSerializing() {
  217. b.Type = b.GetBodyType()
  218. }
  219. // 块传输的事件
  220. type BodyBlockTransfer struct {
  221. serder.Metadata `union:"BlockTransfer"`
  222. Type string `json:"type"`
  223. ObjectID cdssdk.ObjectID `json:"objectID"`
  224. PackageID cdssdk.PackageID `json:"packageID"`
  225. BlockChanges []BlockChange `json:"blockChanges"`
  226. }
  227. func (b *BodyBlockTransfer) GetBodyType() string {
  228. return "BlockTransfer"
  229. }
  230. func (b *BodyBlockTransfer) OnUnionSerializing() {
  231. b.Type = b.GetBodyType()
  232. }
  233. // 块变化类型
  234. type BlockChange interface {
  235. GetBlockChangeType() string
  236. }
  237. var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[BlockChange](
  238. (*BlockChangeClone)(nil),
  239. (*BlockChangeDeleted)(nil),
  240. (*BlockChangeEnDecode)(nil),
  241. )), "type")
  242. const (
  243. BlockTypeRaw = "Raw"
  244. BlockTypeEC = "EC"
  245. BlockTypeSegment = "Segment"
  246. )
  247. type Block struct {
  248. BlockType string `json:"blockType"`
  249. Index int `json:"index"`
  250. StorageID cdssdk.StorageID `json:"storageID"`
  251. }
  252. type DataTransfer struct {
  253. SourceStorageID cdssdk.StorageID `json:"sourceStorageID"`
  254. TargetStorageID cdssdk.StorageID `json:"targetStorageID"`
  255. TransferBytes int64 `json:"transferBytes"`
  256. }
  257. type BlockChangeClone struct {
  258. serder.Metadata `union:"Clone"`
  259. Type string `json:"type"`
  260. BlockType string `json:"blockType"`
  261. Index int `json:"index"`
  262. SourceStorageID cdssdk.StorageID `json:"sourceStorageID"`
  263. TargetStorageID cdssdk.StorageID `json:"targetStorageID"`
  264. TransferBytes int64 `json:"transferBytes"`
  265. }
  266. func (b *BlockChangeClone) GetBlockChangeType() string {
  267. return "Clone"
  268. }
  269. func (b *BlockChangeClone) OnUnionSerializing() {
  270. b.Type = b.GetBlockChangeType()
  271. }
  272. type BlockChangeDeleted struct {
  273. serder.Metadata `union:"Deleted"`
  274. Type string `json:"type"`
  275. Index int `json:"index"`
  276. StorageID cdssdk.StorageID `json:"storageID"`
  277. }
  278. func (b *BlockChangeDeleted) GetBlockChangeType() string {
  279. return "Deleted"
  280. }
  281. func (b *BlockChangeDeleted) OnUnionSerializing() {
  282. b.Type = b.GetBlockChangeType()
  283. }
  284. type BlockChangeEnDecode struct {
  285. serder.Metadata `union:"EnDecode"`
  286. Type string `json:"type"`
  287. SourceBlocks []Block `json:"sourceBlocks,omitempty"`
  288. TargetBlocks []Block `json:"targetBlocks,omitempty"`
  289. DataTransfers []DataTransfer `json:"dataTransfers,omitempty"`
  290. }
  291. func (b *BlockChangeEnDecode) GetBlockChangeType() string {
  292. return "EnDecode"
  293. }
  294. func (b *BlockChangeEnDecode) OnUnionSerializing() {
  295. b.Type = b.GetBlockChangeType()
  296. }
  297. // 块分布的事件
  298. type BodyBlockDistribution struct {
  299. serder.Metadata `union:"BlockDistribution"`
  300. Type string `json:"type"`
  301. ObjectID cdssdk.ObjectID `json:"objectID"`
  302. PackageID cdssdk.PackageID `json:"packageID"`
  303. Path string `json:"path"`
  304. Size int64 `json:"size"`
  305. FileHash cdssdk.FileHash `json:"fileHash"`
  306. FaultTolerance float64 `json:"faultTolerance"`
  307. Redundancy float64 `json:"redundancy"`
  308. AvgAccessCost float64 `json:"avgAccessCost"`
  309. BlockDistribution []BlockDistributionObjectInfo `json:"blockDistribution"`
  310. DataTransfers []DataTransfer `json:"dataTransfers"`
  311. }
  312. func (b *BodyBlockDistribution) GetBodyType() string {
  313. return "BlockDistribution"
  314. }
  315. func (b *BodyBlockDistribution) OnUnionSerializing() {
  316. b.Type = b.GetBodyType()
  317. }
  318. type BlockDistributionObjectInfo struct {
  319. BlockType string `json:"type"`
  320. Index int `json:"index"`
  321. StorageID cdssdk.StorageID `json:"storageID"`
  322. }
  323. // 新增或者重新上传Object的事件
  324. type BodyNewOrUpdateObject struct {
  325. serder.Metadata `union:"NewOrUpdateObject"`
  326. Type string `json:"type"`
  327. Info cdssdk.Object `json:"info"`
  328. BlockDistribution []BlockDistributionObjectInfo `json:"blockDistribution"`
  329. }
  330. func (b *BodyNewOrUpdateObject) GetBodyType() string {
  331. return "NewOrUpdateObject"
  332. }
  333. func (b *BodyNewOrUpdateObject) OnUnionSerializing() {
  334. b.Type = b.GetBodyType()
  335. }
  336. // Object的基本信息更新的事件
  337. type BodyObjectInfoUpdated struct {
  338. serder.Metadata `union:"ObjectInfoUpdated"`
  339. Type string `json:"type"`
  340. Object cdssdk.Object `json:"object"`
  341. }
  342. func (b *BodyObjectInfoUpdated) GetBodyType() string {
  343. return "ObjectInfoUpdated"
  344. }
  345. func (b *BodyObjectInfoUpdated) OnUnionSerializing() {
  346. b.Type = b.GetBodyType()
  347. }
  348. // Object删除的事件
  349. type BodyObjectDeleted struct {
  350. serder.Metadata `union:"ObjectDeleted"`
  351. Type string `json:"type"`
  352. ObjectID cdssdk.ObjectID `json:"objectID"`
  353. }
  354. func (b *BodyObjectDeleted) GetBodyType() string {
  355. return "ObjectDeleted"
  356. }
  357. func (b *BodyObjectDeleted) OnUnionSerializing() {
  358. b.Type = b.GetBodyType()
  359. }
  360. // 新增Package的事件
  361. type BodyNewPackage struct {
  362. serder.Metadata `union:"NewPackage"`
  363. Type string `json:"type"`
  364. Info cdssdk.Package `json:"info"`
  365. }
  366. func (b *BodyNewPackage) GetBodyType() string {
  367. return "NewPackage"
  368. }
  369. func (b *BodyNewPackage) OnUnionSerializing() {
  370. b.Type = b.GetBodyType()
  371. }
  372. // Package克隆的事件
  373. type BodyPackageCloned struct {
  374. serder.Metadata `union:"PackageCloned"`
  375. Type string `json:"type"`
  376. SourcePackageID cdssdk.PackageID `json:"sourcePackageID"`
  377. NewPackage cdssdk.Package `json:"newPackage"`
  378. }
  379. func (b *BodyPackageCloned) GetBodyType() string {
  380. return "PackageCloned"
  381. }
  382. func (b *BodyPackageCloned) OnUnionSerializing() {
  383. b.Type = b.GetBodyType()
  384. }
  385. // Package删除的事件
  386. type BodyPackageDeleted struct {
  387. serder.Metadata `union:"PackageDeleted"`
  388. Type string `json:"type"`
  389. PackageID cdssdk.PackageID `json:"packageID"`
  390. }
  391. func (b *BodyPackageDeleted) GetBodyType() string {
  392. return "PackageDeleted"
  393. }
  394. func (b *BodyPackageDeleted) OnUnionSerializing() {
  395. b.Type = b.GetBodyType()
  396. }
  397. // 新增Bucket的事件
  398. type BodyNewBucket struct {
  399. serder.Metadata `union:"NewBucket"`
  400. Type string `json:"type"`
  401. Info cdssdk.Bucket `json:"info"`
  402. }
  403. func (b *BodyNewBucket) GetBodyType() string {
  404. return "NewBucket"
  405. }
  406. func (b *BodyNewBucket) OnUnionSerializing() {
  407. b.Type = b.GetBodyType()
  408. }
  409. // Bucket删除的事件
  410. type BodyBucketDeleted struct {
  411. serder.Metadata `union:"BucketDeleted"`
  412. Type string `json:"type"`
  413. BucketID cdssdk.BucketID `json:"bucketID"`
  414. }
  415. func (b *BodyBucketDeleted) GetBodyType() string {
  416. return "BucketDeleted"
  417. }
  418. func (b *BodyBucketDeleted) OnUnionSerializing() {
  419. b.Type = b.GetBodyType()
  420. }

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