Deprecate and remove service stop API. (#3578)

Fixes #3570
This commit is contained in:
Harshavardhana 2017-01-14 14:48:52 -08:00 committed by GitHub
parent 2959c104b3
commit caecd75a2a
10 changed files with 5 additions and 156 deletions

View File

@ -50,24 +50,6 @@ func (adminAPI adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r *
writeSuccessResponseJSON(w, jsonBytes) 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 // ServiceRestartHandler - POST /?service
// HTTP header x-minio-operation: restart // HTTP header x-minio-operation: restart
// ---------- // ----------

View File

@ -56,8 +56,6 @@ func (c cmdType) apiMethod() string {
switch c { switch c {
case statusCmd: case statusCmd:
return "GET" return "GET"
case stopCmd:
return "POST"
case restartCmd: case restartCmd:
return "POST" return "POST"
} }
@ -70,8 +68,6 @@ func (c cmdType) toServiceSignal() serviceSignal {
switch c { switch c {
case statusCmd: case statusCmd:
return serviceStatus return serviceStatus
case stopCmd:
return serviceStop
case restartCmd: case restartCmd:
return serviceRestart return serviceRestart
} }
@ -187,11 +183,6 @@ func TestServiceStatusHandler(t *testing.T) {
testServicesCmdHandler(statusCmd, 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. // Test for service restart management REST API.
func TestServiceRestartHandler(t *testing.T) { func TestServiceRestartHandler(t *testing.T) {
testServicesCmdHandler(restartCmd, t) testServicesCmdHandler(restartCmd, t)

View File

@ -33,8 +33,7 @@ func registerAdminRouter(mux *router.Router) {
// Service status // Service status
adminRouter.Methods("GET").Queries("service", "").Headers(minioAdminOpHeader, "status").HandlerFunc(adminAPI.ServiceStatusHandler) 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 // Service restart
adminRouter.Methods("POST").Queries("service", "").Headers(minioAdminOpHeader, "restart").HandlerFunc(adminAPI.ServiceRestartHandler) adminRouter.Methods("POST").Queries("service", "").Headers(minioAdminOpHeader, "restart").HandlerFunc(adminAPI.ServiceRestartHandler)

View File

@ -36,18 +36,10 @@ type remoteAdminClient struct {
// adminCmdRunner - abstracts local and remote execution of admin // adminCmdRunner - abstracts local and remote execution of admin
// commands like service stop and service restart. // commands like service stop and service restart.
type adminCmdRunner interface { type adminCmdRunner interface {
Stop() error
Restart() error Restart() error
ListLocks(bucket, prefix string, relTime time.Duration) ([]VolumeLockInfo, 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 // Restart - Sends a message over channel to the go-routine
// responsible for restarting the process. // responsible for restarting the process.
func (lc localAdminClient) Restart() error { 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 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. // Restart - Sends restart command to remote server via RPC.
func (rc remoteAdminClient) Restart() error { func (rc remoteAdminClient) Restart() error {
args := AuthRPCArgs{} args := AuthRPCArgs{}
@ -88,7 +73,7 @@ func (rc remoteAdminClient) ListLocks(bucket, prefix string, relTime time.Durati
return reply.volLocks, nil 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 { type adminPeer struct {
addr string addr string
cmdRunner adminCmdRunner cmdRunner adminCmdRunner
@ -146,18 +131,16 @@ func initGlobalAdminPeers(eps []*url.URL) {
globalAdminPeers = makeAdminPeers(eps) globalAdminPeers = makeAdminPeers(eps)
} }
// invokeServiceCmd - Invoke Stop/Restart command. // invokeServiceCmd - Invoke Restart command.
func invokeServiceCmd(cp adminPeer, cmd serviceSignal) (err error) { func invokeServiceCmd(cp adminPeer, cmd serviceSignal) (err error) {
switch cmd { switch cmd {
case serviceStop:
err = cp.cmdRunner.Stop()
case serviceRestart: case serviceRestart:
err = cp.cmdRunner.Restart() err = cp.cmdRunner.Restart()
} }
return err return err
} }
// sendServiceCmd - Invoke Stop/Restart command on remote peers // sendServiceCmd - Invoke Restart command on remote peers
// adminPeer followed by on the local peer. // adminPeer followed by on the local peer.
func sendServiceCmd(cps adminPeers, cmd serviceSignal) { func sendServiceCmd(cps adminPeers, cmd serviceSignal) {
// Send service command like stop or restart to all remote nodes and finally run on local node. // Send service command like stop or restart to all remote nodes and finally run on local node.

View File

@ -45,16 +45,6 @@ type ListLocksReply struct {
volLocks []VolumeLockInfo 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. // Restart - Restart this instance of minio server.
func (s *adminCmd) Restart(args *AuthRPCArgs, reply *AuthRPCReply) error { func (s *adminCmd) Restart(args *AuthRPCArgs, reply *AuthRPCReply) error {
if err := args.IsAuthenticated(); err != nil { if err := args.IsAuthenticated(); err != nil {

View File

@ -47,17 +47,13 @@ func testAdminCmd(cmd cmdType, t *testing.T) {
} }
go func() { go func() {
// mocking signal receiver // A test signal receiver
<-globalServiceSignalCh <-globalServiceSignalCh
}() }()
ga := AuthRPCArgs{AuthToken: reply.AuthToken, RequestTime: time.Now().UTC()} ga := AuthRPCArgs{AuthToken: reply.AuthToken, RequestTime: time.Now().UTC()}
genReply := AuthRPCReply{} genReply := AuthRPCReply{}
switch cmd { switch cmd {
case stopCmd:
if err = adminServer.Shutdown(&ga, &genReply); err != nil {
t.Errorf("stopCmd: Expected: <nil>, got: %v", err)
}
case restartCmd: case restartCmd:
if err = adminServer.Restart(&ga, &genReply); err != nil { if err = adminServer.Restart(&ga, &genReply); err != nil {
t.Errorf("restartCmd: Expected: <nil>, got: %v", err) t.Errorf("restartCmd: Expected: <nil>, 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) { func TestAdminRestart(t *testing.T) {
testAdminCmd(restartCmd, t) testAdminCmd(restartCmd, t)
} }

View File

@ -39,7 +39,6 @@ func main() {
| Service operations|LockInfo operations|Healing operations| | Service operations|LockInfo operations|Healing operations|
|:---|:---|:---| |:---|:---|:---|
|[`ServiceStatus`](#ServiceStatus)| | | |[`ServiceStatus`](#ServiceStatus)| | |
|[`ServiceStop`](#ServiceStop)| | |
|[`ServiceRestart`](#ServiceRestart)| | | |[`ServiceRestart`](#ServiceRestart)| | |
## 1. Constructor ## 1. Constructor
@ -98,23 +97,6 @@ Fetch service status, replies disk space used, backend type and total disks offl
``` ```
<a name="ServiceStop"></a>
### 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")
```
<a name="ServiceRestart"></a> <a name="ServiceRestart"></a>
### ServiceRestart() (error) ### ServiceRestart() (error)
If successful restarts the running minio service, for distributed setup restarts all remote minio servers. If successful restarts the running minio service, for distributed setup restarts all remote minio servers.

View File

@ -105,7 +105,6 @@ go run service-status.go
### API Reference : Service Operations ### API Reference : Service Operations
* [`ServiceStatus`](./API.md#ServiceStatus) * [`ServiceStatus`](./API.md#ServiceStatus)
* [`ServiceStop`](./API.md#ServiceStop)
* [`ServiceRestart`](./API.md#ServiceRestart) * [`ServiceRestart`](./API.md#ServiceRestart)
## Full Examples ## Full Examples
@ -113,7 +112,6 @@ go run service-status.go
#### Full Examples : Service Operations #### Full Examples : Service Operations
* [service-status.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-status.go) * [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) * [service-restart.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-restart.go)
## Contribute ## Contribute

View File

@ -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")
}

View File

@ -95,30 +95,6 @@ func (adm *AdminClient) ServiceStatus() (ServiceStatusMetadata, error) {
return storageInfo, nil 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 // ServiceRestart - Call Service Restart API to restart a specified Minio server
func (adm *AdminClient) ServiceRestart() error { func (adm *AdminClient) ServiceRestart() error {
// //