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.

test.go 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package cmdline
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "github.com/spf13/cobra"
  7. "gitlink.org.cn/cloudream/common/pkgs/future"
  8. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  9. stgglb "gitlink.org.cn/cloudream/storage/common/globals"
  10. "gitlink.org.cn/cloudream/storage/common/pkgs/downloader"
  11. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch/plans"
  12. coormq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/coordinator"
  13. )
  14. func init() {
  15. cmd := &cobra.Command{
  16. Use: "test2",
  17. Short: "test2",
  18. // Args: cobra.ExactArgs(1),
  19. Run: func(cmd *cobra.Command, args []string) {
  20. // cmdCtx := GetCmdCtx(cmd)
  21. coorCli, err := stgglb.CoordinatorMQPool.Acquire()
  22. if err != nil {
  23. panic(err)
  24. }
  25. defer stgglb.CoordinatorMQPool.Release(coorCli)
  26. nodes, err := coorCli.GetNodes(coormq.NewGetNodes([]cdssdk.NodeID{1, 2}))
  27. if err != nil {
  28. panic(err)
  29. }
  30. ft := plans.NewFromTo()
  31. // ft.AddFrom(plans.NewFromNode("Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD", &nodes.Nodes[0], -1))
  32. // ft.AddTo(plans.NewToNode(nodes.Nodes[1], -1, "asd"))
  33. // len := int64(3)
  34. // toExec, hd := plans.NewToExecutorWithRange(-1, plans.Range{Offset: 5, Length: &len})
  35. // ft.AddTo(toExec)
  36. // ft.AddTo(plans.NewToNode(nodes.Nodes[1], 0, "0"))
  37. // ft.AddTo(plans.NewToNode(nodes.Nodes[1], 1, "1"))
  38. // ft.AddTo(plans.NewToNode(nodes.Nodes[1], 2, "2"))
  39. ft.AddFrom(plans.NewFromNode("QmS2s8GRYHEurXL7V1zUtKvf2H1BGcQc5NN1T1hiSnWvbd", &nodes.Nodes[0], 1))
  40. ft.AddFrom(plans.NewFromNode("QmUgUEUMzdnjPNx6xu9PDGXpSyXTk8wzPWvyYZ9zasE1WW", &nodes.Nodes[1], 2))
  41. le := int64(3)
  42. toExec, hd := plans.NewToExecutorWithRange(-1, plans.Range{Offset: 5, Length: &le})
  43. // toExec, hd := plans.NewToExecutorWithRange(1, plans.Range{Offset: 0, Length: nil})
  44. // toExec2, hd2 := plans.NewToExecutorWithRange(2, plans.Range{Offset: 0, Length: nil})
  45. ft.AddTo(toExec)
  46. // ft.AddTo(toExec2)
  47. // fromExec, hd := plans.NewFromExecutor(-1)
  48. // ft.AddFrom(fromExec)
  49. // ft.AddTo(plans.NewToNode(nodes.Nodes[1], -1, "asd"))
  50. parser := plans.NewParser(cdssdk.DefaultECRedundancy)
  51. plans := plans.NewPlanBuilder()
  52. err = parser.Parse(ft, plans)
  53. if err != nil {
  54. panic(err)
  55. }
  56. exec := plans.Execute()
  57. fut := future.NewSetVoid()
  58. go func() {
  59. mp, err := exec.Wait(context.Background())
  60. if err != nil {
  61. panic(err)
  62. }
  63. fmt.Printf("mp: %+v\n", mp)
  64. fut.SetVoid()
  65. }()
  66. go func() {
  67. // exec.BeginWrite(io.NopCloser(bytes.NewBuffer([]byte("hello world"))), hd)
  68. // if err != nil {
  69. // panic(err)
  70. // }
  71. str, err := exec.BeginRead(hd)
  72. if err != nil {
  73. panic(err)
  74. }
  75. defer str.Close()
  76. data, err := io.ReadAll(str)
  77. if err != nil && err != io.EOF {
  78. panic(err)
  79. }
  80. fmt.Printf("data: %v(%v)\n", string(data), len(data))
  81. }()
  82. fut.Wait(context.TODO())
  83. },
  84. }
  85. cmd2 := &cobra.Command{
  86. Use: "test",
  87. Short: "test",
  88. // Args: cobra.ExactArgs(1),
  89. Run: func(cmd *cobra.Command, args []string) {
  90. cmdCtx := GetCmdCtx(cmd)
  91. file, _ := cmdCtx.Cmdline.Svc.ObjectSvc().Download(1, downloader.DownloadReqeust{
  92. ObjectID: 27379,
  93. Length: -1,
  94. })
  95. data, _ := io.ReadAll(file.File)
  96. fmt.Printf("data: %v(%v)\n", string(data), len(data))
  97. },
  98. }
  99. rootCmd.AddCommand(cmd)
  100. rootCmd.AddCommand(cmd2)
  101. }

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