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.

cluster.go 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package clirpc
  2. import (
  3. "context"
  4. "io"
  5. "time"
  6. "github.com/hashicorp/raft"
  7. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc"
  8. )
  9. type ClusterService interface {
  10. GetClusterMasterInfo(ctx context.Context, req *GetClusterMasterInfo) (*GetClusterMasterInfoResp, *rpc.CodeError)
  11. ClusterRaftRPC(ctx context.Context, req *ClusterRaftRPC) (*ClusterRaftRPCResp, *rpc.CodeError)
  12. ClusterRaftInstallSnapshot(ctx context.Context, req *ClusterRaftInstallSnapshot) (*ClusterRaftInstallSnapshotResp, *rpc.CodeError)
  13. ClusterApplyLog(ctx context.Context, req *ClusterApplyLog) (*ClusterApplyLogResp, *rpc.CodeError)
  14. }
  15. type GetClusterMasterInfo struct {
  16. }
  17. type GetClusterMasterInfoResp struct {
  18. Name string
  19. }
  20. func (c *Client) GetClusterMasterInfo(ctx context.Context, msg *GetClusterMasterInfo) (*GetClusterMasterInfoResp, *rpc.CodeError) {
  21. if c.fusedErr != nil {
  22. return nil, c.fusedErr
  23. }
  24. return rpc.UnaryClient[*GetClusterMasterInfoResp](c.cli.GetClusterMasterInfo, ctx, msg)
  25. }
  26. func (s *Server) GetClusterMasterInfo(ctx context.Context, msg *rpc.Request) (*rpc.Response, error) {
  27. return rpc.UnaryServer(s.svrImpl.GetClusterMasterInfo, ctx, msg)
  28. }
  29. type ClusterRaftRPC struct {
  30. Type string
  31. Data string
  32. }
  33. type ClusterRaftRPCResp struct {
  34. Data string
  35. }
  36. func (c *Client) ClusterRaftRPC(ctx context.Context, msg *ClusterRaftRPC) (*ClusterRaftRPCResp, *rpc.CodeError) {
  37. if c.fusedErr != nil {
  38. return nil, c.fusedErr
  39. }
  40. return rpc.UnaryClient[*ClusterRaftRPCResp](c.cli.ClusterRaftRPC, ctx, msg)
  41. }
  42. func (s *Server) ClusterRaftRPC(ctx context.Context, msg *rpc.Request) (*rpc.Response, error) {
  43. return rpc.UnaryServer(s.svrImpl.ClusterRaftRPC, ctx, msg)
  44. }
  45. type ClusterRaftInstallSnapshot struct {
  46. Args *raft.InstallSnapshotRequest
  47. Data io.Reader `json:"-"`
  48. }
  49. func (r *ClusterRaftInstallSnapshot) GetStream() io.Reader {
  50. return r.Data
  51. }
  52. func (r *ClusterRaftInstallSnapshot) SetStream(stream io.Reader) {
  53. r.Data = stream
  54. }
  55. type ClusterRaftInstallSnapshotResp struct {
  56. Resp *raft.InstallSnapshotResponse
  57. }
  58. func (c *Client) ClusterRaftInstallSnapshot(ctx context.Context, msg *ClusterRaftInstallSnapshot) (*ClusterRaftInstallSnapshotResp, *rpc.CodeError) {
  59. if c.fusedErr != nil {
  60. return nil, c.fusedErr
  61. }
  62. return rpc.UploadStreamClient[*ClusterRaftInstallSnapshotResp](c.cli.ClusterRaftInstallSnapshot, ctx, msg)
  63. }
  64. func (s *Server) ClusterRaftInstallSnapshot(req Client_ClusterRaftInstallSnapshotServer) error {
  65. return rpc.UploadStreamServer(s.svrImpl.ClusterRaftInstallSnapshot, req)
  66. }
  67. type ClusterApplyLog struct {
  68. Data string
  69. Timeout time.Duration
  70. }
  71. type ClusterApplyLogResp struct{}
  72. func (c *Client) ClusterApplyLog(ctx context.Context, msg *ClusterApplyLog) (*ClusterApplyLogResp, *rpc.CodeError) {
  73. if c.fusedErr != nil {
  74. return nil, c.fusedErr
  75. }
  76. return rpc.UnaryClient[*ClusterApplyLogResp](c.cli.ClusterApplyLog, ctx, msg)
  77. }
  78. func (s *Server) ClusterApplyLog(ctx context.Context, msg *rpc.Request) (*rpc.Response, error) {
  79. return rpc.UnaryServer(s.svrImpl.ClusterApplyLog, ctx, msg)
  80. }

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