2016-08-17 14:36:33 -04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-08-17 14:36:33 -04:00
|
|
|
|
2016-10-10 02:03:10 -04:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
)
|
2016-09-23 02:47:48 -04:00
|
|
|
|
|
|
|
// errServerNotInitialized - server not initialized.
|
|
|
|
var errServerNotInitialized = errors.New("Server not initialized, please try again.")
|
|
|
|
|
2016-09-24 06:34:45 -04:00
|
|
|
// errServerVersionMismatch - server versions do not match.
|
|
|
|
var errServerVersionMismatch = errors.New("Server versions do not match.")
|
|
|
|
|
2016-10-07 14:15:55 -04:00
|
|
|
// errServerTimeMismatch - server times are too far apart.
|
|
|
|
var errServerTimeMismatch = errors.New("Server times are too far apart.")
|
|
|
|
|
2016-08-24 13:14:14 -04:00
|
|
|
/// Auth operations
|
|
|
|
|
|
|
|
// Login - login handler.
|
|
|
|
func (c *controllerAPIHandlers) LoginHandler(args *RPCLoginArgs, reply *RPCLoginReply) error {
|
2016-10-05 13:18:55 -04:00
|
|
|
jwt, err := newJWT(defaultInterNodeJWTExpiry)
|
2016-08-24 13:14:14 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err = jwt.Authenticate(args.Username, args.Password); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
token, err := jwt.GenerateToken(args.Username)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reply.Token = token
|
2016-10-07 14:15:55 -04:00
|
|
|
reply.Timestamp = c.timestamp
|
2016-08-24 13:14:14 -04:00
|
|
|
reply.ServerVersion = Version
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-17 14:36:33 -04:00
|
|
|
// HealListArgs - argument for ListObjects RPC.
|
|
|
|
type HealListArgs struct {
|
2016-08-24 13:14:14 -04:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
|
|
|
|
2016-08-17 14:36:33 -04:00
|
|
|
Bucket string
|
|
|
|
Prefix string
|
|
|
|
Marker string
|
|
|
|
Delimiter string
|
|
|
|
MaxKeys int
|
|
|
|
}
|
|
|
|
|
2016-08-24 13:14:14 -04:00
|
|
|
// HealListReply - reply object by ListObjects RPC.
|
2016-08-17 14:36:33 -04:00
|
|
|
type HealListReply struct {
|
|
|
|
IsTruncated bool
|
|
|
|
NextMarker string
|
|
|
|
Objects []string
|
|
|
|
}
|
|
|
|
|
2016-08-21 15:06:53 -04:00
|
|
|
// ListObjects - list all objects that needs healing.
|
2016-08-24 13:14:14 -04:00
|
|
|
func (c *controllerAPIHandlers) ListObjectsHealHandler(args *HealListArgs, reply *HealListReply) error {
|
2016-08-18 17:50:50 -04:00
|
|
|
objAPI := c.ObjectAPI()
|
2016-08-21 15:06:53 -04:00
|
|
|
if objAPI == nil {
|
2016-09-23 02:47:48 -04:00
|
|
|
return errServerNotInitialized
|
2016-08-24 13:14:14 -04:00
|
|
|
}
|
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
2016-08-21 15:06:53 -04:00
|
|
|
}
|
2016-08-24 13:14:14 -04:00
|
|
|
info, err := objAPI.ListObjectsHeal(args.Bucket, args.Prefix, args.Marker, args.Delimiter, args.MaxKeys)
|
2016-08-17 14:36:33 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reply.IsTruncated = info.IsTruncated
|
|
|
|
reply.NextMarker = info.NextMarker
|
|
|
|
for _, obj := range info.Objects {
|
|
|
|
reply.Objects = append(reply.Objects, obj.Name)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// HealObjectArgs - argument for HealObject RPC.
|
|
|
|
type HealObjectArgs struct {
|
2016-08-24 13:14:14 -04:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
|
|
|
|
|
|
|
// Name of the bucket.
|
2016-08-17 14:36:33 -04:00
|
|
|
Bucket string
|
2016-08-24 13:14:14 -04:00
|
|
|
|
|
|
|
// Name of the object.
|
2016-08-17 14:36:33 -04:00
|
|
|
Object string
|
|
|
|
}
|
|
|
|
|
|
|
|
// HealObjectReply - reply by HealObject RPC.
|
|
|
|
type HealObjectReply struct{}
|
|
|
|
|
2016-09-26 17:28:35 -04:00
|
|
|
// HealObject - heal the object.
|
2016-08-24 13:14:14 -04:00
|
|
|
func (c *controllerAPIHandlers) HealObjectHandler(args *HealObjectArgs, reply *GenericReply) error {
|
2016-08-18 17:50:50 -04:00
|
|
|
objAPI := c.ObjectAPI()
|
2016-08-21 15:06:53 -04:00
|
|
|
if objAPI == nil {
|
2016-09-23 02:47:48 -04:00
|
|
|
return errServerNotInitialized
|
2016-08-21 15:06:53 -04:00
|
|
|
}
|
2016-08-24 13:14:14 -04:00
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
|
|
|
return objAPI.HealObject(args.Bucket, args.Object)
|
2016-08-21 15:06:53 -04:00
|
|
|
}
|
|
|
|
|
2016-09-26 17:28:35 -04:00
|
|
|
// HealObject - heal the object.
|
2016-08-28 22:31:59 -04:00
|
|
|
func (c *controllerAPIHandlers) HealDiskMetadataHandler(args *GenericArgs, reply *GenericReply) error {
|
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
err := repairDiskMetadata(c.StorageDisks)
|
2016-08-30 22:22:27 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
globalWakeupCh <- struct{}{}
|
|
|
|
}()
|
|
|
|
return err
|
2016-08-28 22:31:59 -04:00
|
|
|
}
|
|
|
|
|
2016-10-10 02:03:10 -04:00
|
|
|
// ServiceArgs - argument for Service RPC.
|
|
|
|
type ServiceArgs struct {
|
2016-08-24 13:14:14 -04:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
2016-08-21 15:06:53 -04:00
|
|
|
|
2016-10-10 02:03:10 -04:00
|
|
|
// Represents the type of operation server is requested
|
|
|
|
// to perform. Currently supported signals are
|
|
|
|
// stop, restart and status.
|
|
|
|
Signal serviceSignal
|
|
|
|
|
|
|
|
// Make remote calls.
|
|
|
|
Remote bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceReply - represents service operation success info.
|
|
|
|
type ServiceReply struct {
|
|
|
|
StorageInfo StorageInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *controllerAPIHandlers) remoteCall(serviceMethod string, args interface {
|
|
|
|
SetToken(token string)
|
|
|
|
SetTimestamp(tstamp time.Time)
|
|
|
|
}, reply interface{}) {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for index, clnt := range c.RemoteControllers {
|
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, client *AuthRPCClient) {
|
|
|
|
defer wg.Done()
|
|
|
|
err := client.Call(serviceMethod, args, reply)
|
|
|
|
errorIf(err, "Unable to initiate %s", serviceMethod)
|
|
|
|
}(index, clnt)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2016-08-24 13:14:14 -04:00
|
|
|
}
|
2016-08-21 15:06:53 -04:00
|
|
|
|
2016-10-10 02:03:10 -04:00
|
|
|
// Service - handler for sending service signals across many servers.
|
|
|
|
func (c *controllerAPIHandlers) ServiceHandler(args *ServiceArgs, reply *ServiceReply) error {
|
2016-08-24 13:14:14 -04:00
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
2016-10-10 02:03:10 -04:00
|
|
|
objAPI := c.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
if args.Signal == serviceStatus {
|
|
|
|
reply.StorageInfo = objAPI.StorageInfo()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
switch args.Signal {
|
|
|
|
case serviceRestart:
|
|
|
|
if args.Remote {
|
|
|
|
// Set remote as false for remote calls.
|
|
|
|
args.Remote = false
|
|
|
|
// Send remote call to all neighboring peers to restart minio servers.
|
|
|
|
c.remoteCall("Controller.ServiceHandler", args, reply)
|
|
|
|
}
|
|
|
|
globalServiceSignalCh <- serviceRestart
|
|
|
|
case serviceStop:
|
|
|
|
if args.Remote {
|
|
|
|
// Set remote as false for remote calls.
|
|
|
|
args.Remote = false
|
|
|
|
// Send remote call to all neighboring peers to stop minio servers.
|
|
|
|
c.remoteCall("Controller.ServiceHandler", args, reply)
|
|
|
|
}
|
|
|
|
globalServiceSignalCh <- serviceStop
|
2016-08-21 15:06:53 -04:00
|
|
|
}
|
|
|
|
return nil
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
2016-08-30 22:22:27 -04:00
|
|
|
|
2016-10-10 02:03:10 -04:00
|
|
|
// LockInfo - RPC control handler for `minio control lock`. Returns the info of the locks held in the system.
|
2016-08-31 14:39:08 -04:00
|
|
|
func (c *controllerAPIHandlers) LockInfo(arg *GenericArgs, reply *SystemLockState) error {
|
|
|
|
// obtain the lock state information.
|
|
|
|
lockInfo, err := generateSystemLockResponse()
|
|
|
|
// in case of error, return err to the RPC client.
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-10-10 02:03:10 -04:00
|
|
|
// The response containing the lock info.
|
2016-08-31 14:39:08 -04:00
|
|
|
*reply = lockInfo
|
|
|
|
return nil
|
|
|
|
}
|