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 1.9 kB

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

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