/vendor/github.com/pydio/minio-srv/cmd/admin-rpc-server.go

https://github.com/pydio/cells · Go · 103 lines · 59 code · 17 blank · 27 comment · 2 complexity · d6b66ad2324104e680ac3d37cccff7ae MD5 · raw file

  1. /*
  2. * Minio Cloud Storage, (C) 2016, 2017, 2018 Minio, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package cmd
  17. import (
  18. "path"
  19. "github.com/gorilla/mux"
  20. "github.com/pydio/minio-srv/cmd/logger"
  21. xrpc "github.com/pydio/minio-srv/cmd/rpc"
  22. )
  23. const adminServiceName = "Admin"
  24. const adminServiceSubPath = "/admin"
  25. var adminServicePath = path.Join(minioReservedBucketPath, adminServiceSubPath)
  26. // adminRPCReceiver - Admin RPC receiver for admin RPC server.
  27. type adminRPCReceiver struct {
  28. local *localAdminClient
  29. }
  30. // SignalServiceArgs - provides the signal argument to SignalService RPC
  31. type SignalServiceArgs struct {
  32. AuthArgs
  33. Sig serviceSignal
  34. }
  35. // SignalService - Send a restart or stop signal to the service
  36. func (receiver *adminRPCReceiver) SignalService(args *SignalServiceArgs, reply *VoidReply) error {
  37. return receiver.local.SignalService(args.Sig)
  38. }
  39. // ServerInfo - returns the server info when object layer was initialized on this server.
  40. func (receiver *adminRPCReceiver) ServerInfo(args *AuthArgs, reply *ServerInfoData) (err error) {
  41. *reply, err = receiver.local.ServerInfo()
  42. return err
  43. }
  44. // StartProfilingArgs - holds the RPC argument for StartingProfiling RPC call
  45. type StartProfilingArgs struct {
  46. AuthArgs
  47. Profiler string
  48. }
  49. // StartProfiling - starts profiling of this server
  50. func (receiver *adminRPCReceiver) StartProfiling(args *StartProfilingArgs, reply *VoidReply) error {
  51. return receiver.local.StartProfiling(args.Profiler)
  52. }
  53. // DownloadProfilingData - stops and returns profiling data of this server
  54. func (receiver *adminRPCReceiver) DownloadProfilingData(args *AuthArgs, reply *[]byte) (err error) {
  55. *reply, err = receiver.local.DownloadProfilingData()
  56. return
  57. }
  58. // GetConfig - returns the config.json of this server.
  59. func (receiver *adminRPCReceiver) GetConfig(args *AuthArgs, reply *[]byte) (err error) {
  60. *reply, err = receiver.local.GetConfig()
  61. return err
  62. }
  63. // ReInitFormatArgs - provides dry-run information to re-initialize format.json
  64. type ReInitFormatArgs struct {
  65. AuthArgs
  66. DryRun bool
  67. }
  68. // ReInitFormat - re-init 'format.json'
  69. func (receiver *adminRPCReceiver) ReInitFormat(args *ReInitFormatArgs, reply *VoidReply) error {
  70. return receiver.local.ReInitFormat(args.DryRun)
  71. }
  72. // NewAdminRPCServer - returns new admin RPC server.
  73. func NewAdminRPCServer() (*xrpc.Server, error) {
  74. rpcServer := xrpc.NewServer()
  75. if err := rpcServer.RegisterName(adminServiceName, &adminRPCReceiver{&localAdminClient{}}); err != nil {
  76. return nil, err
  77. }
  78. return rpcServer, nil
  79. }
  80. // registerAdminRPCRouter - creates and registers Admin RPC server and its router.
  81. func registerAdminRPCRouter(router *mux.Router) {
  82. rpcServer, err := NewAdminRPCServer()
  83. logger.FatalIf(err, "Unable to initialize Lock RPC Server")
  84. subrouter := router.PathPrefix(minioReservedBucketPath).Subrouter()
  85. subrouter.Path(adminServiceSubPath).HandlerFunc(httpTraceHdrs(rpcServer.ServeHTTP))
  86. }