filer_grpc_server_admin.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package weed_server
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "github.com/seaweedfs/seaweedfs/weed/cluster"
  7. "github.com/seaweedfs/seaweedfs/weed/glog"
  8. "github.com/seaweedfs/seaweedfs/weed/pb"
  9. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  10. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  11. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  12. "github.com/seaweedfs/seaweedfs/weed/util"
  13. )
  14. func (fs *FilerServer) Statistics(ctx context.Context, req *filer_pb.StatisticsRequest) (resp *filer_pb.StatisticsResponse, err error) {
  15. var output *master_pb.StatisticsResponse
  16. err = fs.filer.MasterClient.WithClient(false, func(masterClient master_pb.SeaweedClient) error {
  17. grpcResponse, grpcErr := masterClient.Statistics(context.Background(), &master_pb.StatisticsRequest{
  18. Replication: req.Replication,
  19. Collection: req.Collection,
  20. Ttl: req.Ttl,
  21. DiskType: req.DiskType,
  22. })
  23. if grpcErr != nil {
  24. return grpcErr
  25. }
  26. output = grpcResponse
  27. return nil
  28. })
  29. if err != nil {
  30. return nil, err
  31. }
  32. return &filer_pb.StatisticsResponse{
  33. TotalSize: output.TotalSize,
  34. UsedSize: output.UsedSize,
  35. FileCount: output.FileCount,
  36. }, nil
  37. }
  38. func (fs *FilerServer) Ping(ctx context.Context, req *filer_pb.PingRequest) (resp *filer_pb.PingResponse, pingErr error) {
  39. resp = &filer_pb.PingResponse{
  40. StartTimeNs: time.Now().UnixNano(),
  41. }
  42. if req.TargetType == cluster.FilerType {
  43. pingErr = pb.WithFilerClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
  44. pingResp, err := client.Ping(ctx, &filer_pb.PingRequest{})
  45. if pingResp != nil {
  46. resp.RemoteTimeNs = pingResp.StartTimeNs
  47. }
  48. return err
  49. })
  50. }
  51. if req.TargetType == cluster.VolumeServerType {
  52. pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
  53. pingResp, err := client.Ping(ctx, &volume_server_pb.PingRequest{})
  54. if pingResp != nil {
  55. resp.RemoteTimeNs = pingResp.StartTimeNs
  56. }
  57. return err
  58. })
  59. }
  60. if req.TargetType == cluster.MasterType {
  61. pingErr = pb.WithMasterClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, false, func(client master_pb.SeaweedClient) error {
  62. pingResp, err := client.Ping(ctx, &master_pb.PingRequest{})
  63. if pingResp != nil {
  64. resp.RemoteTimeNs = pingResp.StartTimeNs
  65. }
  66. return err
  67. })
  68. }
  69. if pingErr != nil {
  70. pingErr = fmt.Errorf("ping %s %s: %v", req.TargetType, req.Target, pingErr)
  71. }
  72. resp.StopTimeNs = time.Now().UnixNano()
  73. return
  74. }
  75. func (fs *FilerServer) GetFilerConfiguration(ctx context.Context, req *filer_pb.GetFilerConfigurationRequest) (resp *filer_pb.GetFilerConfigurationResponse, err error) {
  76. clusterId, _ := fs.filer.Store.KvGet(context.Background(), []byte("clusterId"))
  77. t := &filer_pb.GetFilerConfigurationResponse{
  78. Masters: pb.ToAddressStringsFromMap(fs.option.Masters),
  79. Collection: fs.option.Collection,
  80. Replication: fs.option.DefaultReplication,
  81. MaxMb: uint32(fs.option.MaxMB),
  82. DirBuckets: fs.filer.DirBucketsPath,
  83. Cipher: fs.filer.Cipher,
  84. Signature: fs.filer.Signature,
  85. MetricsAddress: fs.metricsAddress,
  86. MetricsIntervalSec: int32(fs.metricsIntervalSec),
  87. Version: util.Version(),
  88. ClusterId: string(clusterId),
  89. FilerGroup: fs.option.FilerGroup,
  90. }
  91. glog.V(4).Infof("GetFilerConfiguration: %v", t)
  92. return t, nil
  93. }