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.

http_hub_worker.go 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package ioswitch2
  2. import (
  3. "context"
  4. "io"
  5. "strconv"
  6. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  7. "gitlink.org.cn/cloudream/common/pkgs/types"
  8. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  9. "gitlink.org.cn/cloudream/common/sdks/storage/cdsapi"
  10. "gitlink.org.cn/cloudream/common/utils/serder"
  11. )
  12. var _ = serder.UseTypeUnionExternallyTagged(types.Ref(types.NewTypeUnion[exec.WorkerInfo](
  13. (*HttpHubWorker)(nil),
  14. )))
  15. type HttpHubWorker struct {
  16. Node cdssdk.Node
  17. }
  18. func (w *HttpHubWorker) NewClient() (exec.WorkerClient, error) {
  19. addressInfo := w.Node.Address.(*cdssdk.HttpAddressInfo)
  20. baseUrl := "http://" + addressInfo.ExternalIP + ":" + strconv.Itoa(addressInfo.Port)
  21. config := cdsapi.Config{
  22. URL: baseUrl,
  23. }
  24. pool := cdsapi.NewPool(&config)
  25. cli, err := pool.Acquire()
  26. defer pool.Release(cli)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return &HttpHubWorkerClient{cli: cli}, nil
  31. }
  32. func (w *HttpHubWorker) String() string {
  33. return w.Node.String()
  34. }
  35. func (w *HttpHubWorker) Equals(worker exec.WorkerInfo) bool {
  36. aw, ok := worker.(*HttpHubWorker)
  37. if !ok {
  38. return false
  39. }
  40. return w.Node.NodeID == aw.Node.NodeID
  41. }
  42. type HttpHubWorkerClient struct {
  43. cli *cdsapi.Client
  44. }
  45. func (c *HttpHubWorkerClient) ExecutePlan(ctx context.Context, plan exec.Plan) error {
  46. return c.cli.ExecuteIOPlan(plan)
  47. }
  48. func (c *HttpHubWorkerClient) SendStream(ctx context.Context, planID exec.PlanID, v *exec.StreamVar, str io.ReadCloser) error {
  49. return c.cli.SendStream(planID, v.ID, str)
  50. }
  51. func (c *HttpHubWorkerClient) SendVar(ctx context.Context, planID exec.PlanID, v exec.Var) error {
  52. return c.cli.SendVar(planID, v)
  53. }
  54. func (c *HttpHubWorkerClient) GetStream(ctx context.Context, planID exec.PlanID, v *exec.StreamVar, signal *exec.SignalVar) (io.ReadCloser, error) {
  55. return c.cli.GetStream(planID, v.ID, signal)
  56. }
  57. func (c *HttpHubWorkerClient) GetVar(ctx context.Context, planID exec.PlanID, v exec.Var, signal *exec.SignalVar) error {
  58. return c.cli.GetVar(planID, v, signal)
  59. //return nil
  60. }
  61. func (c *HttpHubWorkerClient) Close() error {
  62. //stgglb.AgentRPCPool.Release(c.cli)
  63. return nil
  64. }

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