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

1 year ago
1 year ago
1 year ago
1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package ioswitch2
  2. import (
  3. "context"
  4. "io"
  5. "strconv"
  6. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  7. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  8. "gitlink.org.cn/cloudream/common/sdks/storage/cdsapi"
  9. )
  10. type HttpHubWorker struct {
  11. Hub cdssdk.Hub
  12. }
  13. func (w *HttpHubWorker) NewClient() (exec.WorkerClient, error) {
  14. addressInfo := w.Hub.Address.(*cdssdk.HttpAddressInfo)
  15. baseUrl := "http://" + addressInfo.ExternalIP + ":" + strconv.Itoa(addressInfo.Port)
  16. config := cdsapi.Config{
  17. URL: baseUrl,
  18. }
  19. pool := cdsapi.NewPool(&config)
  20. cli, err := pool.Acquire()
  21. defer pool.Release(cli)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return &HttpHubWorkerClient{cli: cli}, nil
  26. }
  27. func (w *HttpHubWorker) String() string {
  28. return w.Hub.String()
  29. }
  30. func (w *HttpHubWorker) Equals(worker exec.WorkerInfo) bool {
  31. aw, ok := worker.(*HttpHubWorker)
  32. if !ok {
  33. return false
  34. }
  35. return w.Hub.HubID == aw.Hub.HubID
  36. }
  37. type HttpHubWorkerClient struct {
  38. cli *cdsapi.Client
  39. }
  40. func (c *HttpHubWorkerClient) ExecutePlan(ctx context.Context, plan exec.Plan) error {
  41. return c.cli.ExecuteIOPlan(cdsapi.ExecuteIOPlanReq{
  42. Plan: plan,
  43. })
  44. }
  45. func (c *HttpHubWorkerClient) SendStream(ctx context.Context, planID exec.PlanID, id exec.VarID, stream io.ReadCloser) error {
  46. return c.cli.SendStream(cdsapi.SendStreamReq{
  47. SendStreamInfo: cdsapi.SendStreamInfo{
  48. PlanID: planID,
  49. VarID: id,
  50. },
  51. Stream: stream,
  52. })
  53. }
  54. func (c *HttpHubWorkerClient) SendVar(ctx context.Context, planID exec.PlanID, id exec.VarID, value exec.VarValue) error {
  55. return c.cli.SendVar(cdsapi.SendVarReq{
  56. PlanID: planID,
  57. VarID: id,
  58. VarValue: value,
  59. })
  60. }
  61. func (c *HttpHubWorkerClient) GetStream(ctx context.Context, planID exec.PlanID, streamID exec.VarID, signalID exec.VarID, signal exec.VarValue) (io.ReadCloser, error) {
  62. return c.cli.GetStream(cdsapi.GetStreamReq{
  63. PlanID: planID,
  64. VarID: streamID,
  65. SignalID: signalID,
  66. Signal: signal,
  67. })
  68. }
  69. func (c *HttpHubWorkerClient) GetVar(ctx context.Context, planID exec.PlanID, varID exec.VarID, signalID exec.VarID, signal exec.VarValue) (exec.VarValue, error) {
  70. resp, err := c.cli.GetVar(cdsapi.GetVarReq{
  71. PlanID: planID,
  72. VarID: varID,
  73. SignalID: signalID,
  74. Signal: signal,
  75. })
  76. if err != nil {
  77. return nil, err
  78. }
  79. return resp.Value, err
  80. }
  81. func (c *HttpHubWorkerClient) Close() error {
  82. //stgglb.AgentRPCPool.Release(c.cli)
  83. return nil
  84. }

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