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.

hub_worker.go 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package ioswitchlrc
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. stgglb "gitlink.org.cn/cloudream/jcs-pub/common/globals"
  7. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec"
  8. hubrpc "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc/hub"
  9. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  10. )
  11. // var _ = serder.UseTypeUnionExternallyTagged(types.Ref(types.NewTypeUnion[exec.WorkerInfo](
  12. // (*HubWorker)(nil),
  13. // )))
  14. type HubWorker struct {
  15. Hub jcstypes.Hub
  16. Address jcstypes.GRPCAddressInfo
  17. }
  18. func (w *HubWorker) Name() string {
  19. return fmt.Sprintf("%v", w.Hub.HubID)
  20. }
  21. func (w *HubWorker) NewClient() (exec.WorkerClient, error) {
  22. cli := stgglb.HubRPCPool.Get(stgglb.SelectGRPCAddress(&w.Hub, &w.Address))
  23. return &HubWorkerClient{cli: cli}, nil
  24. }
  25. func (w *HubWorker) String() string {
  26. return w.Hub.String()
  27. }
  28. func (w *HubWorker) Equals(worker exec.WorkerInfo) bool {
  29. aw, ok := worker.(*HubWorker)
  30. if !ok {
  31. return false
  32. }
  33. return w.Hub.HubID == aw.Hub.HubID
  34. }
  35. type HubWorkerClient struct {
  36. workerName string
  37. cli *hubrpc.Client
  38. }
  39. func (c *HubWorkerClient) ExecutePlan(ctx context.Context, plan exec.Plan) (exec.ExecutorResult, error) {
  40. resp, err := c.cli.ExecuteIOPlan(ctx, &hubrpc.ExecuteIOPlan{Plan: plan, WorkerName: c.workerName})
  41. if err != nil {
  42. return exec.ExecutorResult{}, err.ToError()
  43. }
  44. return resp.Result, nil
  45. }
  46. func (c *HubWorkerClient) SendStream(ctx context.Context, planID exec.PlanID, id exec.VarID, stream io.ReadCloser) error {
  47. _, err := c.cli.SendIOStream(ctx, &hubrpc.SendIOStream{
  48. PlanID: planID,
  49. VarID: id,
  50. Stream: stream,
  51. })
  52. return err.ToError()
  53. }
  54. func (c *HubWorkerClient) SendVar(ctx context.Context, planID exec.PlanID, id exec.VarID, value exec.VarValue) error {
  55. _, err := c.cli.SendIOVar(ctx, &hubrpc.SendIOVar{
  56. PlanID: planID, VarID: id, Value: value,
  57. })
  58. return err.ToError()
  59. }
  60. func (c *HubWorkerClient) GetStream(ctx context.Context, planID exec.PlanID, streamID exec.VarID, signalID exec.VarID, signal exec.VarValue) (io.ReadCloser, error) {
  61. resp, err := c.cli.GetIOStream(ctx, &hubrpc.GetIOStream{
  62. PlanID: planID, VarID: streamID, SignalID: signalID, Signal: signal,
  63. })
  64. if err != nil {
  65. return nil, err.ToError()
  66. }
  67. return resp.Stream, nil
  68. }
  69. func (c *HubWorkerClient) GetVar(ctx context.Context, planID exec.PlanID, varID exec.VarID, signalID exec.VarID, signal exec.VarValue) (exec.VarValue, error) {
  70. resp, err := c.cli.GetIOVar(ctx, &hubrpc.GetIOVar{
  71. PlanID: planID, VarID: varID, SignalID: signalID, Signal: signal,
  72. })
  73. if err != nil {
  74. return nil, err.ToError()
  75. }
  76. return resp.Value, nil
  77. }
  78. func (c *HubWorkerClient) Close() error {
  79. c.cli.Release()
  80. return nil
  81. }

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