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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. "gitlink.org.cn/cloudream/storage/common/pkgs/storage/mgr"
  9. )
  10. func init() {
  11. exec.UseOp[*ShardWrite]()
  12. }
  13. type SharedLoad struct {
  14. Input exec.VarID `json:"input"`
  15. StorageID cdssdk.StorageID `json:"storageID"`
  16. UserID cdssdk.UserID `json:"userID"`
  17. PackageID cdssdk.PackageID `json:"packageID"`
  18. Path string `json:"path"`
  19. FullPathOutput exec.VarID `json:"fullPathOutput"`
  20. }
  21. func (o *SharedLoad) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
  22. logger.
  23. WithField("Input", o.Input).
  24. Debugf("load file to shared store")
  25. defer logger.Debugf("load file to shared store finished")
  26. stgMgr, err := exec.GetValueByType[*mgr.Manager](ctx)
  27. if err != nil {
  28. return fmt.Errorf("getting storage manager: %w", err)
  29. }
  30. store, err := stgMgr.GetSharedStore(o.StorageID)
  31. if err != nil {
  32. return fmt.Errorf("getting shard store of storage %v: %w", o.StorageID, err)
  33. }
  34. input, err := exec.BindVar[*exec.StreamValue](e, ctx.Context, o.Input)
  35. if err != nil {
  36. return err
  37. }
  38. defer input.Stream.Close()
  39. fullPath, err := store.WritePackageObject(o.UserID, o.PackageID, o.Path, input.Stream)
  40. if err != nil {
  41. return fmt.Errorf("writing file to shard store: %w", err)
  42. }
  43. if o.FullPathOutput > 0 {
  44. e.PutVar(o.FullPathOutput, &exec.StringValue{
  45. Value: fullPath,
  46. })
  47. }
  48. return nil
  49. }
  50. func (o *SharedLoad) String() string {
  51. return fmt.Sprintf("SharedLoad %v -> %v:%v/%v/%v", o.Input, o.StorageID, o.UserID, o.PackageID, o.Path)
  52. }
  53. type SharedLoadNode struct {
  54. dag.NodeBase
  55. StorageID cdssdk.StorageID
  56. UserID cdssdk.UserID
  57. PackageID cdssdk.PackageID
  58. Path string
  59. }
  60. func (b *GraphNodeBuilder) NewSharedLoad(stgID cdssdk.StorageID, userID cdssdk.UserID, packageID cdssdk.PackageID, path string) *SharedLoadNode {
  61. node := &SharedLoadNode{
  62. StorageID: stgID,
  63. UserID: userID,
  64. PackageID: packageID,
  65. Path: path,
  66. }
  67. b.AddNode(node)
  68. return node
  69. }
  70. func (t *SharedLoadNode) SetInput(input *dag.Var) {
  71. t.InputStreams().EnsureSize(1)
  72. input.StreamTo(t, 0)
  73. t.OutputValues().SetupNew(t, t.Graph().NewVar())
  74. }
  75. func (t *SharedLoadNode) Input() dag.Slot {
  76. return dag.Slot{
  77. Var: t.InputStreams().Get(0),
  78. Index: 0,
  79. }
  80. }
  81. func (t *SharedLoadNode) FullPathVar() *dag.Var {
  82. return t.OutputValues().Get(0)
  83. }
  84. func (t *SharedLoadNode) GenerateOp() (exec.Op, error) {
  85. return &ShardWrite{
  86. Input: t.InputStreams().Get(0).VarID,
  87. FileHash: t.OutputValues().Get(0).VarID,
  88. StorageID: t.StorageID,
  89. }, nil
  90. }

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