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.

shared_store.go 2.2 kB

11 months ago
11 months ago
11 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package ops2
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/dag"
  5. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  6. "gitlink.org.cn/cloudream/common/pkgs/logger"
  7. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  8. stgmod "gitlink.org.cn/cloudream/storage/common/models"
  9. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch2"
  10. "gitlink.org.cn/cloudream/storage/common/pkgs/storage/agtpool"
  11. )
  12. func init() {
  13. exec.UseOp[*SharedLoad]()
  14. }
  15. type SharedLoad struct {
  16. Input exec.VarID
  17. StorageID cdssdk.StorageID
  18. ObjectPath string
  19. }
  20. func (o *SharedLoad) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
  21. logger.
  22. WithField("Input", o.Input).
  23. Debugf("load file to shared store")
  24. defer logger.Debugf("load file to shared store finished")
  25. stgAgts, err := exec.GetValueByType[*agtpool.AgentPool](ctx)
  26. if err != nil {
  27. return fmt.Errorf("getting storage manager: %w", err)
  28. }
  29. store, err := stgAgts.GetSharedStore(o.StorageID)
  30. if err != nil {
  31. return fmt.Errorf("getting shard store of storage %v: %w", o.StorageID, err)
  32. }
  33. input, err := exec.BindVar[*exec.StreamValue](e, ctx.Context, o.Input)
  34. if err != nil {
  35. return err
  36. }
  37. defer input.Stream.Close()
  38. return store.Write(o.ObjectPath, input.Stream)
  39. }
  40. func (o *SharedLoad) String() string {
  41. return fmt.Sprintf("SharedLoad %v -> %v:%v", o.Input, o.StorageID, o.ObjectPath)
  42. }
  43. type SharedLoadNode struct {
  44. dag.NodeBase
  45. To ioswitch2.To
  46. Storage stgmod.StorageDetail
  47. ObjectPath string
  48. }
  49. func (b *GraphNodeBuilder) NewSharedLoad(to ioswitch2.To, stg stgmod.StorageDetail, objPath string) *SharedLoadNode {
  50. node := &SharedLoadNode{
  51. To: to,
  52. Storage: stg,
  53. ObjectPath: objPath,
  54. }
  55. b.AddNode(node)
  56. node.InputStreams().Init(1)
  57. return node
  58. }
  59. func (t *SharedLoadNode) GetTo() ioswitch2.To {
  60. return t.To
  61. }
  62. func (t *SharedLoadNode) SetInput(input *dag.StreamVar) {
  63. input.To(t, 0)
  64. }
  65. func (t *SharedLoadNode) Input() dag.StreamInputSlot {
  66. return dag.StreamInputSlot{
  67. Node: t,
  68. Index: 0,
  69. }
  70. }
  71. func (t *SharedLoadNode) GenerateOp() (exec.Op, error) {
  72. return &SharedLoad{
  73. Input: t.InputStreams().Get(0).VarID,
  74. StorageID: t.Storage.Storage.StorageID,
  75. ObjectPath: t.ObjectPath,
  76. }, nil
  77. }

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