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.

agent_plan.go 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package plans
  2. import (
  3. stgmod "gitlink.org.cn/cloudream/storage/common/models"
  4. "gitlink.org.cn/cloudream/storage/common/pkgs/db/model"
  5. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch"
  6. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch/ops"
  7. )
  8. func (b *AgentPlanBuilder) GRCPFetch(node model.Node, str *AgentStream) *AgentStream {
  9. agtStr := &AgentStream{
  10. owner: b,
  11. info: b.owner.newStream(),
  12. }
  13. b.ops = append(b.ops, &ops.GRPCFetch{
  14. RemoteID: str.info.ID,
  15. LocalID: agtStr.info.ID,
  16. Node: node,
  17. })
  18. return agtStr
  19. }
  20. func (s *AgentStream) GRPCSend(node model.Node) *AgentStream {
  21. agtStr := &AgentStream{
  22. owner: s.owner.owner.AtAgent(node),
  23. info: s.owner.owner.newStream(),
  24. }
  25. s.owner.ops = append(s.owner.ops, &ops.GRPCSend{
  26. LocalID: s.info.ID,
  27. RemoteID: agtStr.info.ID,
  28. Node: node,
  29. })
  30. return agtStr
  31. }
  32. func (b *AgentPlanBuilder) FileRead(filePath string) *AgentStream {
  33. agtStr := &AgentStream{
  34. owner: b,
  35. info: b.owner.newStream(),
  36. }
  37. b.ops = append(b.ops, &ops.FileRead{
  38. OutputID: agtStr.info.ID,
  39. FilePath: filePath,
  40. })
  41. return agtStr
  42. }
  43. func (b *AgentStream) FileWrite(filePath string) {
  44. b.owner.ops = append(b.owner.ops, &ops.FileWrite{
  45. InputID: b.info.ID,
  46. FilePath: filePath,
  47. })
  48. }
  49. func (b *AgentPlanBuilder) ECCompute(ec stgmod.EC, inBlockIndexes []int, outBlockIndexes []int, streams ...*AgentStream) *MultiStream {
  50. mstr := &MultiStream{}
  51. var inputStrIDs []ioswitch.StreamID
  52. for _, str := range streams {
  53. inputStrIDs = append(inputStrIDs, str.info.ID)
  54. }
  55. var outputStrIDs []ioswitch.StreamID
  56. for i := 0; i < ec.N-ec.K; i++ {
  57. info := b.owner.newStream()
  58. mstr.Streams = append(mstr.Streams, &AgentStream{
  59. owner: b,
  60. info: info,
  61. })
  62. outputStrIDs = append(outputStrIDs, info.ID)
  63. }
  64. b.ops = append(b.ops, &ops.ECCompute{
  65. EC: ec,
  66. InputIDs: inputStrIDs,
  67. OutputIDs: outputStrIDs,
  68. InputBlockIndexes: inBlockIndexes,
  69. OutputBlockIndexes: outBlockIndexes,
  70. })
  71. return mstr
  72. }
  73. func (b *AgentPlanBuilder) ECReconstruct(ec stgmod.EC, inBlockIndexes []int, streams ...*AgentStream) *MultiStream {
  74. mstr := &MultiStream{}
  75. var inputStrIDs []ioswitch.StreamID
  76. for _, str := range streams {
  77. inputStrIDs = append(inputStrIDs, str.info.ID)
  78. }
  79. var outputStrIDs []ioswitch.StreamID
  80. for i := 0; i < ec.K; i++ {
  81. info := b.owner.newStream()
  82. mstr.Streams = append(mstr.Streams, &AgentStream{
  83. owner: b,
  84. info: info,
  85. })
  86. outputStrIDs = append(outputStrIDs, info.ID)
  87. }
  88. b.ops = append(b.ops, &ops.ECReconstruct{
  89. EC: ec,
  90. InputIDs: inputStrIDs,
  91. OutputIDs: outputStrIDs,
  92. InputBlockIndexes: inBlockIndexes,
  93. })
  94. return mstr
  95. }

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