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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package ops2
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag"
  5. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec"
  6. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool"
  7. stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
  8. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  9. )
  10. func init() {
  11. exec.UseOp[*GetShardHTTPRequest]()
  12. exec.UseVarValue[*HTTPRequestValue]()
  13. }
  14. // 旁路Http读取
  15. type GetShardHTTPRequest struct {
  16. UserSpace jcstypes.UserSpaceDetail
  17. FileHash jcstypes.FileHash
  18. Output exec.VarID
  19. }
  20. type HTTPRequestValue struct {
  21. stgtypes.HTTPRequest
  22. }
  23. func (v *HTTPRequestValue) Clone() exec.VarValue {
  24. return &HTTPRequestValue{
  25. HTTPRequest: v.HTTPRequest,
  26. }
  27. }
  28. func (o *GetShardHTTPRequest) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
  29. stgPool, err := exec.GetValueByType[*pool.Pool](ctx)
  30. if err != nil {
  31. return err
  32. }
  33. shardStore, err := stgPool.GetShardStore(&o.UserSpace)
  34. if err != nil {
  35. return err
  36. }
  37. br, ok := shardStore.(stgtypes.HTTPShardRead)
  38. if !ok {
  39. return fmt.Errorf("shard store %v not support bypass read", o.UserSpace)
  40. }
  41. req, err := br.MakeHTTPReadRequest(o.FileHash)
  42. if err != nil {
  43. return err
  44. }
  45. e.PutVar(o.Output, &HTTPRequestValue{HTTPRequest: req})
  46. return nil
  47. }
  48. func (o *GetShardHTTPRequest) String() string {
  49. return fmt.Sprintf("GetShardHTTPRequest[UserSpace:%v] FileHash: %v, Output: %v", o.UserSpace, o.FileHash, o.Output)
  50. }
  51. // 旁路Http读取
  52. type GetShardHTTPRequestNode struct {
  53. dag.NodeBase
  54. UserSpace jcstypes.UserSpaceDetail
  55. FileHash jcstypes.FileHash
  56. }
  57. func (b *GraphNodeBuilder) NewGetShardHTTPRequest(userSpace jcstypes.UserSpaceDetail, fileHash jcstypes.FileHash) *GetShardHTTPRequestNode {
  58. node := &GetShardHTTPRequestNode{
  59. UserSpace: userSpace,
  60. FileHash: fileHash,
  61. }
  62. b.AddNode(node)
  63. node.OutputValues().Init(node, 1)
  64. return node
  65. }
  66. func (n *GetShardHTTPRequestNode) HTTPRequestVar() dag.ValueOutputSlot {
  67. return dag.ValueOutputSlot{
  68. Node: n,
  69. Index: 0,
  70. }
  71. }
  72. func (n *GetShardHTTPRequestNode) GenerateOp() (exec.Op, error) {
  73. return &GetShardHTTPRequest{
  74. UserSpace: n.UserSpace,
  75. FileHash: n.FileHash,
  76. Output: n.HTTPRequestVar().Var().VarID,
  77. }, nil
  78. }

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