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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. )))
  15. type AgentWorker struct {
  16. Node cdssdk.Node
  17. }
  18. func (w *AgentWorker) NewClient() (exec.WorkerClient, error) {
  19. cli, err := stgglb.AgentRPCPool.Acquire(stgglb.SelectGRPCAddress(&w.Node))
  20. if err != nil {
  21. return nil, err
  22. }
  23. return &AgentWorkerClient{cli: cli}, nil
  24. }
  25. func (w *AgentWorker) String() string {
  26. return w.Node.String()
  27. }
  28. func (w *AgentWorker) Equals(worker exec.WorkerInfo) bool {
  29. aw, ok := worker.(*AgentWorker)
  30. if !ok {
  31. return false
  32. }
  33. return w.Node.NodeID == aw.Node.NodeID
  34. }
  35. type AgentWorkerClient struct {
  36. cli *agtrpc.PoolClient
  37. }
  38. func (c *AgentWorkerClient) ExecutePlan(ctx context.Context, plan exec.Plan) error {
  39. return c.cli.ExecuteIOPlan(ctx, plan)
  40. }
  41. func (c *AgentWorkerClient) SendStream(ctx context.Context, planID exec.PlanID, id exec.VarID, stream io.ReadCloser) error {
  42. return c.cli.SendStream(ctx, planID, id, stream)
  43. }
  44. func (c *AgentWorkerClient) SendVar(ctx context.Context, planID exec.PlanID, id exec.VarID, value exec.VarValue) error {
  45. return c.cli.SendVar(ctx, planID, id, value)
  46. }
  47. func (c *AgentWorkerClient) GetStream(ctx context.Context, planID exec.PlanID, streamID exec.VarID, signalID exec.VarID, signal exec.VarValue) (io.ReadCloser, error) {
  48. return c.cli.GetStream(ctx, planID, streamID, signalID, signal)
  49. }
  50. func (c *AgentWorkerClient) GetVar(ctx context.Context, planID exec.PlanID, varID exec.VarID, signalID exec.VarID, signal exec.VarValue) (exec.VarValue, error) {
  51. return c.cli.GetVar(ctx, planID, varID, signalID, signal)
  52. }
  53. func (c *AgentWorkerClient) Close() error {
  54. stgglb.AgentRPCPool.Release(c.cli)
  55. return nil
  56. }

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