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.

bypass.go 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  7. "gitlink.org.cn/cloudream/storage/common/pkgs/storage/svcmgr"
  8. "gitlink.org.cn/cloudream/storage/common/pkgs/storage/types"
  9. )
  10. func init() {
  11. exec.UseOp[*BypassToShardStore]()
  12. exec.UseVarValue[*BypassFileInfoValue]()
  13. }
  14. type BypassFileInfoValue struct {
  15. types.BypassFileInfo
  16. }
  17. func (v *BypassFileInfoValue) Clone() exec.VarValue {
  18. return &BypassFileInfoValue{
  19. BypassFileInfo: v.BypassFileInfo,
  20. }
  21. }
  22. type BypassHandleResultValue struct {
  23. Commited bool
  24. }
  25. func (r *BypassHandleResultValue) Clone() exec.VarValue {
  26. return &BypassHandleResultValue{
  27. Commited: r.Commited,
  28. }
  29. }
  30. type BypassToShardStore struct {
  31. StorageID cdssdk.StorageID
  32. BypassFileInfo exec.VarID
  33. BypassCallback exec.VarID
  34. }
  35. func (o *BypassToShardStore) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
  36. svcMgr, err := exec.GetValueByType[*svcmgr.Manager](ctx)
  37. if err != nil {
  38. return err
  39. }
  40. shardStore, err := svcMgr.GetShardStore(o.StorageID)
  41. if err != nil {
  42. return err
  43. }
  44. notifier, ok := shardStore.(types.BypassNotifier)
  45. if !ok {
  46. return fmt.Errorf("shard store %v not support bypass", o.StorageID)
  47. }
  48. fileInfo, err := exec.BindVar[*BypassFileInfoValue](e, ctx.Context, o.BypassFileInfo)
  49. if err != nil {
  50. return err
  51. }
  52. err = notifier.BypassUploaded(fileInfo.BypassFileInfo)
  53. if err != nil {
  54. return err
  55. }
  56. e.PutVar(o.BypassCallback, &BypassHandleResultValue{Commited: true})
  57. return nil
  58. }
  59. func (o *BypassToShardStore) String() string {
  60. return fmt.Sprintf("BypassToShardStore[StorageID:%v] Info: %v, Callback: %v", o.StorageID, o.BypassFileInfo, o.BypassCallback)
  61. }
  62. type BypassToShardStoreNode struct {
  63. dag.NodeBase
  64. StorageID cdssdk.StorageID
  65. }
  66. func (b *GraphNodeBuilder) NewBypassToShardStore(storageID cdssdk.StorageID) *BypassToShardStoreNode {
  67. node := &BypassToShardStoreNode{
  68. StorageID: storageID,
  69. }
  70. b.AddNode(node)
  71. node.InputValues().Init(1)
  72. node.OutputValues().Init(node, 1)
  73. return node
  74. }
  75. func (n *BypassToShardStoreNode) BypassFileInfoSlot() dag.ValueInputSlot {
  76. return dag.ValueInputSlot{
  77. Node: n,
  78. Index: 0,
  79. }
  80. }
  81. func (n *BypassToShardStoreNode) BypassCallbackVar() *dag.ValueVar {
  82. return n.OutputValues().Get(0)
  83. }
  84. func (t *BypassToShardStoreNode) GenerateOp() (exec.Op, error) {
  85. return &BypassToShardStore{
  86. StorageID: t.StorageID,
  87. BypassFileInfo: t.BypassFileInfoSlot().Var().VarID,
  88. BypassCallback: t.BypassCallbackVar().VarID,
  89. }, nil
  90. }

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