You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.6 KiB

  1. /*
  2. * Minio Cloud Storage, (C) 2016 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. "net/rpc"
  19. "path"
  20. router "github.com/gorilla/mux"
  21. )
  22. // Routes paths for "minio control" commands.
  23. const (
  24. controlPath = "/control"
  25. )
  26. // Initializes remote control clients for making remote requests.
  27. func initRemoteControlClients(srvCmdConfig serverCmdConfig) []*AuthRPCClient {
  28. if !globalIsDistXL {
  29. return nil
  30. }
  31. // Initialize auth rpc clients.
  32. var remoteControlClnts []*AuthRPCClient
  33. localMap := make(map[string]int)
  34. for _, ep := range srvCmdConfig.endpoints {
  35. // Validates if remote disk is local.
  36. if isLocalStorage(ep) {
  37. continue
  38. }
  39. if localMap[ep.Host] == 1 {
  40. continue
  41. }
  42. localMap[ep.Host]++
  43. remoteControlClnts = append(remoteControlClnts, newAuthClient(&authConfig{
  44. accessKey: serverConfig.GetCredential().AccessKeyID,
  45. secretKey: serverConfig.GetCredential().SecretAccessKey,
  46. secureConn: isSSL(),
  47. address: ep.Host,
  48. path: path.Join(reservedBucket, controlPath),
  49. loginMethod: "Control.LoginHandler",
  50. }))
  51. }
  52. return remoteControlClnts
  53. }
  54. // Represents control object which provides handlers for control
  55. // operations on server.
  56. type controlAPIHandlers struct {
  57. ObjectAPI func() ObjectLayer
  58. IsXL bool
  59. RemoteControls []*AuthRPCClient
  60. LocalNode string
  61. StorageDisks []StorageAPI
  62. }
  63. // Register control RPC handlers.
  64. func registerControlRPCRouter(mux *router.Router, srvCmdConfig serverCmdConfig) (err error) {
  65. // Initialize Control.
  66. ctrlHandlers := &controlAPIHandlers{
  67. ObjectAPI: newObjectLayerFn,
  68. IsXL: globalIsDistXL || len(srvCmdConfig.storageDisks) > 1,
  69. RemoteControls: initRemoteControlClients(srvCmdConfig),
  70. LocalNode: getLocalAddress(srvCmdConfig),
  71. StorageDisks: srvCmdConfig.storageDisks,
  72. }
  73. ctrlRPCServer := rpc.NewServer()
  74. err = ctrlRPCServer.RegisterName("Control", ctrlHandlers)
  75. if err != nil {
  76. return traceError(err)
  77. }
  78. ctrlRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter()
  79. ctrlRouter.Path(controlPath).Handler(ctrlRPCServer)
  80. return nil
  81. }