From bb0466f4cedc3a5c7b3b5693e3a8df9111fcb943 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Aug 2016 14:50:50 -0700 Subject: [PATCH] control: Fix controller CLI handling with distributed server object layer. Object layer initialization is done lazily fix it. --- cmd/controller-handlers.go | 4 ++-- cmd/controller-router.go | 2 +- lock-rpc-server.go => cmd/lock-rpc-server.go | 2 +- rpc-client.go => cmd/net-rpc-client.go | 2 +- cmd/routers.go | 9 ++++++++- cmd/storage-rpc-client.go | 4 ++-- cmd/storage-rpc-server-datatypes.go | 2 +- cmd/storage-rpc-server.go | 4 ++-- utils_nix_test.go => cmd/utils_nix_test.go | 2 +- utils_windows_test.go => cmd/utils_windows_test.go | 2 +- 10 files changed, 20 insertions(+), 13 deletions(-) rename lock-rpc-server.go => cmd/lock-rpc-server.go (99%) rename rpc-client.go => cmd/net-rpc-client.go (99%) rename utils_nix_test.go => cmd/utils_nix_test.go (99%) rename utils_windows_test.go => cmd/utils_windows_test.go (99%) diff --git a/cmd/controller-handlers.go b/cmd/controller-handlers.go index e6c0fa9c3..82db95b09 100644 --- a/cmd/controller-handlers.go +++ b/cmd/controller-handlers.go @@ -34,7 +34,7 @@ type HealListReply struct { // ListObjects - list all objects that needs healing. func (c *controllerAPIHandlers) ListObjectsHeal(arg *HealListArgs, reply *HealListReply) error { - objAPI := c.ObjectAPI + objAPI := c.ObjectAPI() if objAPI == nil { return errInvalidArgument } @@ -61,7 +61,7 @@ type HealObjectReply struct{} // HealObject - heal the object. func (c *controllerAPIHandlers) HealObject(arg *HealObjectArgs, reply *HealObjectReply) error { - objAPI := c.ObjectAPI + objAPI := c.ObjectAPI() if objAPI == nil { return errInvalidArgument } diff --git a/cmd/controller-router.go b/cmd/controller-router.go index 8538d95c5..542bc6282 100644 --- a/cmd/controller-router.go +++ b/cmd/controller-router.go @@ -38,5 +38,5 @@ func registerControlRPCRouter(mux *router.Router, ctrlHandlers *controllerAPIHan // Handler for object healing. type controllerAPIHandlers struct { - ObjectAPI ObjectLayer + ObjectAPI func() ObjectLayer } diff --git a/lock-rpc-server.go b/cmd/lock-rpc-server.go similarity index 99% rename from lock-rpc-server.go rename to cmd/lock-rpc-server.go index 5e57c7bed..30ac8d246 100644 --- a/lock-rpc-server.go +++ b/cmd/lock-rpc-server.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package cmd import ( "fmt" diff --git a/rpc-client.go b/cmd/net-rpc-client.go similarity index 99% rename from rpc-client.go rename to cmd/net-rpc-client.go index adb24f1c9..6e53f15cf 100644 --- a/rpc-client.go +++ b/cmd/net-rpc-client.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package cmd import ( "net/rpc" diff --git a/cmd/routers.go b/cmd/routers.go index eb1053f9d..74b76489b 100644 --- a/cmd/routers.go +++ b/cmd/routers.go @@ -106,16 +106,23 @@ func configureServerHandler(srvCmdConfig serverCmdConfig) http.Handler { ObjectAPI: newObjectLayerFn, } + // Initialize Controller. + ctrlHandlers := &controllerAPIHandlers{ + ObjectAPI: newObjectLayerFn, + } + // Initialize router. mux := router.NewRouter() // Register all routers. registerStorageRPCRouters(mux, storageRPCs) + + // Initialize distributed NS lock. initDistributedNSLock(mux, srvCmdConfig) // FIXME: till net/rpc auth is brought in "minio control" can be enabled only though // this env variable. - if os.Getenv("MINIO_CONTROL") != "" { + if !strings.EqualFold(os.Getenv("MINIO_CONTROL"), "off") { registerControlRPCRouter(mux, ctrlHandlers) } diff --git a/cmd/storage-rpc-client.go b/cmd/storage-rpc-client.go index a77cd858e..7c9979ce3 100644 --- a/cmd/storage-rpc-client.go +++ b/cmd/storage-rpc-client.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package cmd import ( "errors" @@ -88,7 +88,7 @@ func loginRPCClient(rpcClient *RPCClient) (tokenStr string, err error) { }, &reply); err != nil { return "", err } - if reply.ServerVersion != minioVersion { + if reply.ServerVersion != Version { return "", errors.New("Server version mismatch") } // Reply back server provided token. diff --git a/cmd/storage-rpc-server-datatypes.go b/cmd/storage-rpc-server-datatypes.go index 7cd908a32..f2c649875 100644 --- a/cmd/storage-rpc-server-datatypes.go +++ b/cmd/storage-rpc-server-datatypes.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package cmd // RPCLoginArgs - login username and password for RPC. type RPCLoginArgs struct { diff --git a/cmd/storage-rpc-server.go b/cmd/storage-rpc-server.go index 6da801545..079b0895d 100644 --- a/cmd/storage-rpc-server.go +++ b/cmd/storage-rpc-server.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package cmd import ( "bytes" @@ -73,7 +73,7 @@ func (s *storageServer) LoginHandler(args *RPCLoginArgs, reply *RPCLoginReply) e return err } reply.Token = token - reply.ServerVersion = minioVersion + reply.ServerVersion = Version return nil } diff --git a/utils_nix_test.go b/cmd/utils_nix_test.go similarity index 99% rename from utils_nix_test.go rename to cmd/utils_nix_test.go index f6c4e65b3..020b2ce08 100644 --- a/utils_nix_test.go +++ b/cmd/utils_nix_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package main +package cmd import ( "net" diff --git a/utils_windows_test.go b/cmd/utils_windows_test.go similarity index 99% rename from utils_windows_test.go rename to cmd/utils_windows_test.go index 821c2d0b0..d50f717f6 100644 --- a/utils_windows_test.go +++ b/cmd/utils_windows_test.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package main +package cmd import ( "net"