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

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

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