2016-12-16 01:26:15 -05:00
|
|
|
/*
|
2018-03-15 16:03:41 -04:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017, 2018 Minio, Inc.
|
2016-12-16 01:26:15 -05:00
|
|
|
*
|
|
|
|
* 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 cmd
|
|
|
|
|
|
|
|
import (
|
2018-03-15 16:27:16 -04:00
|
|
|
"context"
|
2018-06-06 04:51:56 -04:00
|
|
|
"path"
|
2017-01-04 02:39:22 -05:00
|
|
|
"time"
|
2016-12-16 01:26:15 -05:00
|
|
|
|
2018-04-21 22:23:54 -04:00
|
|
|
"github.com/gorilla/mux"
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-06-06 04:51:56 -04:00
|
|
|
xrpc "github.com/minio/minio/cmd/rpc"
|
2016-12-16 01:26:15 -05:00
|
|
|
)
|
|
|
|
|
2018-06-06 04:51:56 -04:00
|
|
|
const adminServiceName = "Admin"
|
|
|
|
const adminServiceSubPath = "/admin"
|
2016-12-16 01:26:15 -05:00
|
|
|
|
2018-06-06 04:51:56 -04:00
|
|
|
var adminServicePath = path.Join(minioReservedBucketPath, adminServiceSubPath)
|
|
|
|
|
|
|
|
// adminRPCReceiver - Admin RPC receiver for admin RPC server.
|
|
|
|
type adminRPCReceiver struct {
|
|
|
|
local *localAdminClient
|
2016-12-16 01:26:15 -05:00
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// SignalServiceArgs - provides the signal argument to SignalService RPC
|
|
|
|
type SignalServiceArgs struct {
|
2018-06-06 04:51:56 -04:00
|
|
|
AuthArgs
|
2018-01-22 17:54:55 -05:00
|
|
|
Sig serviceSignal
|
|
|
|
}
|
|
|
|
|
2018-06-06 04:51:56 -04:00
|
|
|
// SignalService - Send a restart or stop signal to the service
|
|
|
|
func (receiver *adminRPCReceiver) SignalService(args *SignalServiceArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.SignalService(args.Sig)
|
|
|
|
}
|
|
|
|
|
2017-01-04 02:39:22 -05:00
|
|
|
// ListLocksQuery - wraps ListLocks API's query values to send over RPC.
|
|
|
|
type ListLocksQuery struct {
|
2018-06-06 04:51:56 -04:00
|
|
|
AuthArgs
|
2018-01-22 17:54:55 -05:00
|
|
|
Bucket string
|
|
|
|
Prefix string
|
|
|
|
Duration time.Duration
|
2017-01-04 02:39:22 -05:00
|
|
|
}
|
|
|
|
|
2018-06-06 04:51:56 -04:00
|
|
|
// ListLocks - lists locks held by requests handled by this server instance.
|
|
|
|
func (receiver *adminRPCReceiver) ListLocks(args *ListLocksQuery, reply *[]VolumeLockInfo) (err error) {
|
|
|
|
*reply, err = receiver.local.ListLocks(args.Bucket, args.Prefix, args.Duration)
|
|
|
|
return err
|
2017-02-08 03:13:02 -05:00
|
|
|
}
|
|
|
|
|
2018-06-06 04:51:56 -04:00
|
|
|
// ServerInfo - returns the server info when object layer was initialized on this server.
|
|
|
|
func (receiver *adminRPCReceiver) ServerInfo(args *AuthArgs, reply *ServerInfoData) (err error) {
|
|
|
|
*reply, err = receiver.local.ServerInfo()
|
|
|
|
return err
|
2017-02-20 15:58:50 -05:00
|
|
|
}
|
|
|
|
|
2018-06-06 04:51:56 -04:00
|
|
|
// GetConfig - returns the config.json of this server.
|
|
|
|
func (receiver *adminRPCReceiver) GetConfig(args *AuthArgs, reply *[]byte) (err error) {
|
|
|
|
*reply, err = receiver.local.GetConfig()
|
|
|
|
return err
|
2016-12-16 01:26:15 -05:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// ReInitFormatArgs - provides dry-run information to re-initialize format.json
|
|
|
|
type ReInitFormatArgs struct {
|
2018-06-06 04:51:56 -04:00
|
|
|
AuthArgs
|
2018-02-15 20:45:57 -05:00
|
|
|
DryRun bool
|
2017-01-04 02:39:22 -05:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
// ReInitFormat - re-init 'format.json'
|
2018-06-06 04:51:56 -04:00
|
|
|
func (receiver *adminRPCReceiver) ReInitFormat(args *ReInitFormatArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.ReInitFormat(args.DryRun)
|
2017-02-20 15:58:50 -05:00
|
|
|
}
|
|
|
|
|
2017-02-27 14:40:27 -05:00
|
|
|
// WriteConfigArgs - wraps the bytes to be written and temporary file name.
|
|
|
|
type WriteConfigArgs struct {
|
2018-06-06 04:51:56 -04:00
|
|
|
AuthArgs
|
2017-02-27 14:40:27 -05:00
|
|
|
TmpFileName string
|
|
|
|
Buf []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteTmpConfig - writes the supplied config contents onto the
|
|
|
|
// supplied temporary file.
|
2018-06-06 04:51:56 -04:00
|
|
|
func (receiver *adminRPCReceiver) WriteTmpConfig(args *WriteConfigArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.WriteTmpConfig(args.TmpFileName, args.Buf)
|
2017-02-27 14:40:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// CommitConfigArgs - wraps the config file name that needs to be
|
|
|
|
// committed into config.json on this node.
|
|
|
|
type CommitConfigArgs struct {
|
2018-06-06 04:51:56 -04:00
|
|
|
AuthArgs
|
2017-02-27 14:40:27 -05:00
|
|
|
FileName string
|
|
|
|
}
|
|
|
|
|
|
|
|
// CommitConfig - Renames the temporary file into config.json on this node.
|
2018-06-06 04:51:56 -04:00
|
|
|
func (receiver *adminRPCReceiver) CommitConfig(args *CommitConfigArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.CommitConfig(args.FileName)
|
2017-02-27 14:40:27 -05:00
|
|
|
}
|
|
|
|
|
2018-06-06 04:51:56 -04:00
|
|
|
// NewAdminRPCServer - returns new admin RPC server.
|
|
|
|
func NewAdminRPCServer() (*xrpc.Server, error) {
|
|
|
|
rpcServer := xrpc.NewServer()
|
|
|
|
if err := rpcServer.RegisterName(adminServiceName, &adminRPCReceiver{&localAdminClient{}}); err != nil {
|
|
|
|
return nil, err
|
2016-12-16 01:26:15 -05:00
|
|
|
}
|
2018-06-06 04:51:56 -04:00
|
|
|
return rpcServer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// registerAdminRPCRouter - creates and registers Admin RPC server and its router.
|
|
|
|
func registerAdminRPCRouter(router *mux.Router) {
|
|
|
|
rpcServer, err := NewAdminRPCServer()
|
2018-06-14 13:17:07 -04:00
|
|
|
logger.FatalIf(err, "Unable to initialize Lock RPC Server", context.Background())
|
2018-06-06 04:51:56 -04:00
|
|
|
subrouter := router.PathPrefix(minioReservedBucketPath).Subrouter()
|
|
|
|
subrouter.Path(adminServiceSubPath).Handler(rpcServer)
|
2016-12-16 01:26:15 -05:00
|
|
|
}
|