From caecd75a2a1b955163a09e909fbba6fae550c230 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 14 Jan 2017 14:48:52 -0800 Subject: [PATCH] Deprecate and remove service stop API. (#3578) Fixes #3570 --- cmd/admin-handlers.go | 18 ------------ cmd/admin-handlers_test.go | 9 ------ cmd/admin-router.go | 3 +- cmd/admin-rpc-client.go | 23 ++------------- cmd/admin-rpc-server.go | 10 ------- cmd/admin-rpc-server_test.go | 10 +------ pkg/madmin/API.md | 18 ------------ pkg/madmin/README.md | 2 -- pkg/madmin/examples/service-stop.go | 44 ----------------------------- pkg/madmin/service.go | 24 ---------------- 10 files changed, 5 insertions(+), 156 deletions(-) delete mode 100644 pkg/madmin/examples/service-stop.go diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index f3e34b8dc..6e5497b7e 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -50,24 +50,6 @@ func (adminAPI adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r * writeSuccessResponseJSON(w, jsonBytes) } -// ServiceStopHandler - POST /?service -// HTTP header x-minio-operation: stop -// ---------- -// Stops minio server gracefully. In a distributed setup, stops all the -// servers in the cluster. -func (adminAPI adminAPIHandlers) ServiceStopHandler(w http.ResponseWriter, r *http.Request) { - adminAPIErr := checkRequestAuthType(r, "", "", "") - if adminAPIErr != ErrNone { - writeErrorResponse(w, adminAPIErr, r.URL) - return - } - - // Reply to the client before stopping minio server. - w.WriteHeader(http.StatusOK) - - sendServiceCmd(globalAdminPeers, serviceStop) -} - // ServiceRestartHandler - POST /?service // HTTP header x-minio-operation: restart // ---------- diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index 01f3f899f..689ac4c9c 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -56,8 +56,6 @@ func (c cmdType) apiMethod() string { switch c { case statusCmd: return "GET" - case stopCmd: - return "POST" case restartCmd: return "POST" } @@ -70,8 +68,6 @@ func (c cmdType) toServiceSignal() serviceSignal { switch c { case statusCmd: return serviceStatus - case stopCmd: - return serviceStop case restartCmd: return serviceRestart } @@ -187,11 +183,6 @@ func TestServiceStatusHandler(t *testing.T) { testServicesCmdHandler(statusCmd, t) } -// Test for service stop management REST API. -func TestServiceStopHandler(t *testing.T) { - testServicesCmdHandler(stopCmd, t) -} - // Test for service restart management REST API. func TestServiceRestartHandler(t *testing.T) { testServicesCmdHandler(restartCmd, t) diff --git a/cmd/admin-router.go b/cmd/admin-router.go index e74d2edc0..053f01164 100644 --- a/cmd/admin-router.go +++ b/cmd/admin-router.go @@ -33,8 +33,7 @@ func registerAdminRouter(mux *router.Router) { // Service status adminRouter.Methods("GET").Queries("service", "").Headers(minioAdminOpHeader, "status").HandlerFunc(adminAPI.ServiceStatusHandler) - // Service stop - adminRouter.Methods("POST").Queries("service", "").Headers(minioAdminOpHeader, "stop").HandlerFunc(adminAPI.ServiceStopHandler) + // Service restart adminRouter.Methods("POST").Queries("service", "").Headers(minioAdminOpHeader, "restart").HandlerFunc(adminAPI.ServiceRestartHandler) diff --git a/cmd/admin-rpc-client.go b/cmd/admin-rpc-client.go index b80ce882f..c117eac9c 100644 --- a/cmd/admin-rpc-client.go +++ b/cmd/admin-rpc-client.go @@ -36,18 +36,10 @@ type remoteAdminClient struct { // adminCmdRunner - abstracts local and remote execution of admin // commands like service stop and service restart. type adminCmdRunner interface { - Stop() error Restart() error ListLocks(bucket, prefix string, relTime time.Duration) ([]VolumeLockInfo, error) } -// Stop - Sends a message over channel to the go-routine responsible -// for stopping the process. -func (lc localAdminClient) Stop() error { - globalServiceSignalCh <- serviceStop - return nil -} - // Restart - Sends a message over channel to the go-routine // responsible for restarting the process. func (lc localAdminClient) Restart() error { @@ -60,13 +52,6 @@ func (lc localAdminClient) ListLocks(bucket, prefix string, relTime time.Duratio return listLocksInfo(bucket, prefix, relTime), nil } -// Stop - Sends stop command to remote server via RPC. -func (rc remoteAdminClient) Stop() error { - args := AuthRPCArgs{} - reply := AuthRPCReply{} - return rc.Call("Admin.Shutdown", &args, &reply) -} - // Restart - Sends restart command to remote server via RPC. func (rc remoteAdminClient) Restart() error { args := AuthRPCArgs{} @@ -88,7 +73,7 @@ func (rc remoteAdminClient) ListLocks(bucket, prefix string, relTime time.Durati return reply.volLocks, nil } -// adminPeer - represents an entity that implements Stop and Restart methods. +// adminPeer - represents an entity that implements Restart methods. type adminPeer struct { addr string cmdRunner adminCmdRunner @@ -146,18 +131,16 @@ func initGlobalAdminPeers(eps []*url.URL) { globalAdminPeers = makeAdminPeers(eps) } -// invokeServiceCmd - Invoke Stop/Restart command. +// invokeServiceCmd - Invoke Restart command. func invokeServiceCmd(cp adminPeer, cmd serviceSignal) (err error) { switch cmd { - case serviceStop: - err = cp.cmdRunner.Stop() case serviceRestart: err = cp.cmdRunner.Restart() } return err } -// sendServiceCmd - Invoke Stop/Restart command on remote peers +// sendServiceCmd - Invoke Restart command on remote peers // adminPeer followed by on the local peer. func sendServiceCmd(cps adminPeers, cmd serviceSignal) { // Send service command like stop or restart to all remote nodes and finally run on local node. diff --git a/cmd/admin-rpc-server.go b/cmd/admin-rpc-server.go index 0980cef11..4bd05549a 100644 --- a/cmd/admin-rpc-server.go +++ b/cmd/admin-rpc-server.go @@ -45,16 +45,6 @@ type ListLocksReply struct { volLocks []VolumeLockInfo } -// Shutdown - Shutdown this instance of minio server. -func (s *adminCmd) Shutdown(args *AuthRPCArgs, reply *AuthRPCReply) error { - if err := args.IsAuthenticated(); err != nil { - return err - } - - globalServiceSignalCh <- serviceStop - return nil -} - // Restart - Restart this instance of minio server. func (s *adminCmd) Restart(args *AuthRPCArgs, reply *AuthRPCReply) error { if err := args.IsAuthenticated(); err != nil { diff --git a/cmd/admin-rpc-server_test.go b/cmd/admin-rpc-server_test.go index 26365d4ab..5894514c7 100644 --- a/cmd/admin-rpc-server_test.go +++ b/cmd/admin-rpc-server_test.go @@ -47,17 +47,13 @@ func testAdminCmd(cmd cmdType, t *testing.T) { } go func() { - // mocking signal receiver + // A test signal receiver <-globalServiceSignalCh }() ga := AuthRPCArgs{AuthToken: reply.AuthToken, RequestTime: time.Now().UTC()} genReply := AuthRPCReply{} switch cmd { - case stopCmd: - if err = adminServer.Shutdown(&ga, &genReply); err != nil { - t.Errorf("stopCmd: Expected: , got: %v", err) - } case restartCmd: if err = adminServer.Restart(&ga, &genReply); err != nil { t.Errorf("restartCmd: Expected: , got: %v", err) @@ -65,10 +61,6 @@ func testAdminCmd(cmd cmdType, t *testing.T) { } } -func TestAdminShutdown(t *testing.T) { - testAdminCmd(stopCmd, t) -} - func TestAdminRestart(t *testing.T) { testAdminCmd(restartCmd, t) } diff --git a/pkg/madmin/API.md b/pkg/madmin/API.md index 2b93991a4..0d60d755b 100644 --- a/pkg/madmin/API.md +++ b/pkg/madmin/API.md @@ -39,7 +39,6 @@ func main() { | Service operations|LockInfo operations|Healing operations| |:---|:---|:---| |[`ServiceStatus`](#ServiceStatus)| | | -|[`ServiceStop`](#ServiceStop)| | | |[`ServiceRestart`](#ServiceRestart)| | | ## 1. Constructor @@ -98,23 +97,6 @@ Fetch service status, replies disk space used, backend type and total disks offl ``` - -### ServiceStop() (error) -If successful shuts down the running minio service, for distributed setup stops all remote minio servers. - - __Example__ - - - ```go - - st, err := madmClnt.ServiceStop() - if err != nil { - log.Fatalln(err) - } - log.Printf("Succes") - - ``` - ### ServiceRestart() (error) If successful restarts the running minio service, for distributed setup restarts all remote minio servers. diff --git a/pkg/madmin/README.md b/pkg/madmin/README.md index 51ba7ae31..4fdb88833 100644 --- a/pkg/madmin/README.md +++ b/pkg/madmin/README.md @@ -105,7 +105,6 @@ go run service-status.go ### API Reference : Service Operations * [`ServiceStatus`](./API.md#ServiceStatus) -* [`ServiceStop`](./API.md#ServiceStop) * [`ServiceRestart`](./API.md#ServiceRestart) ## Full Examples @@ -113,7 +112,6 @@ go run service-status.go #### Full Examples : Service Operations * [service-status.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-status.go) -* [service-stop.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-stop.go) * [service-restart.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-restart.go) ## Contribute diff --git a/pkg/madmin/examples/service-stop.go b/pkg/madmin/examples/service-stop.go deleted file mode 100644 index 05b446eb2..000000000 --- a/pkg/madmin/examples/service-stop.go +++ /dev/null @@ -1,44 +0,0 @@ -// +build ignore - -/* - * Minio Cloud Storage, (C) 2016 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package main - -import ( - "log" - - "github.com/minio/minio/pkg/madmin" -) - -func main() { - // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are - // dummy values, please replace them with original values. - - // API requests are secure (HTTPS) if secure=true and insecure (HTTPS) otherwise. - // New returns an Minio Admin client object. - madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) - if err != nil { - log.Fatalln(err) - } - - err = madmClnt.ServiceStop() - if err != nil { - log.Fatalln(err) - } - log.Println("Success") -} diff --git a/pkg/madmin/service.go b/pkg/madmin/service.go index 6b25a018b..d49213037 100644 --- a/pkg/madmin/service.go +++ b/pkg/madmin/service.go @@ -95,30 +95,6 @@ func (adm *AdminClient) ServiceStatus() (ServiceStatusMetadata, error) { return storageInfo, nil } -// ServiceStop - Call Service Stop Management API to stop a specified Minio server -func (adm *AdminClient) ServiceStop() error { - // - reqData := requestData{} - reqData.queryValues = make(url.Values) - reqData.queryValues.Set("service", "") - reqData.customHeaders = make(http.Header) - reqData.customHeaders.Set(minioAdminOpHeader, "stop") - - // Execute GET on bucket to list objects. - resp, err := adm.executeMethod("POST", reqData) - - defer closeResponse(resp) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - return errors.New("Got HTTP Status: " + resp.Status) - } - - return nil -} - // ServiceRestart - Call Service Restart API to restart a specified Minio server func (adm *AdminClient) ServiceRestart() error { //