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

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

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