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.

agent_worker.go 2.0 kB

1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package ioswitchlrc
  2. import (
  3. "context"
  4. "io"
  5. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  6. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  7. stgglb "gitlink.org.cn/cloudream/storage/common/globals"
  8. agtrpc "gitlink.org.cn/cloudream/storage/common/pkgs/grpc/agent"
  9. )
  10. // var _ = serder.UseTypeUnionExternallyTagged(types.Ref(types.NewTypeUnion[exec.WorkerInfo](
  11. // (*AgentWorker)(nil),
  12. // )))
  13. type AgentWorker struct {
  14. Hub cdssdk.Hub
  15. Address cdssdk.GRPCAddressInfo
  16. }
  17. func (w *AgentWorker) NewClient() (exec.WorkerClient, error) {
  18. cli, err := stgglb.AgentRPCPool.Acquire(stgglb.SelectGRPCAddress(w.Hub, w.Address))
  19. if err != nil {
  20. return nil, err
  21. }
  22. return &AgentWorkerClient{cli: cli}, nil
  23. }
  24. func (w *AgentWorker) String() string {
  25. return w.Hub.String()
  26. }
  27. func (w *AgentWorker) Equals(worker exec.WorkerInfo) bool {
  28. aw, ok := worker.(*AgentWorker)
  29. if !ok {
  30. return false
  31. }
  32. return w.Hub.HubID == aw.Hub.HubID
  33. }
  34. type AgentWorkerClient struct {
  35. cli *agtrpc.PoolClient
  36. }
  37. func (c *AgentWorkerClient) ExecutePlan(ctx context.Context, plan exec.Plan) error {
  38. return c.cli.ExecuteIOPlan(ctx, plan)
  39. }
  40. func (c *AgentWorkerClient) SendStream(ctx context.Context, planID exec.PlanID, id exec.VarID, stream io.ReadCloser) error {
  41. return c.cli.SendStream(ctx, planID, id, stream)
  42. }
  43. func (c *AgentWorkerClient) SendVar(ctx context.Context, planID exec.PlanID, id exec.VarID, value exec.VarValue) error {
  44. return c.cli.SendVar(ctx, planID, id, value)
  45. }
  46. func (c *AgentWorkerClient) GetStream(ctx context.Context, planID exec.PlanID, streamID exec.VarID, signalID exec.VarID, signal exec.VarValue) (io.ReadCloser, error) {
  47. return c.cli.GetStream(ctx, planID, streamID, signalID, signal)
  48. }
  49. func (c *AgentWorkerClient) GetVar(ctx context.Context, planID exec.PlanID, varID exec.VarID, signalID exec.VarID, signal exec.VarValue) (exec.VarValue, error) {
  50. return c.cli.GetVar(ctx, planID, varID, signalID, signal)
  51. }
  52. func (c *AgentWorkerClient) Close() error {
  53. stgglb.AgentRPCPool.Release(c.cli)
  54. return nil
  55. }

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