2016-08-17 20:36:33 +02: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-19 01:23:42 +02:00
|
|
|
package cmd
|
2016-08-17 20:36:33 +02:00
|
|
|
|
2016-10-10 08:03:10 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
)
|
2016-09-23 08:47:48 +02:00
|
|
|
|
|
|
|
// errServerNotInitialized - server not initialized.
|
|
|
|
var errServerNotInitialized = errors.New("Server not initialized, please try again.")
|
|
|
|
|
2016-09-24 12:34:45 +02:00
|
|
|
// errServerVersionMismatch - server versions do not match.
|
|
|
|
var errServerVersionMismatch = errors.New("Server versions do not match.")
|
|
|
|
|
2016-10-07 20:15:55 +02:00
|
|
|
// errServerTimeMismatch - server times are too far apart.
|
|
|
|
var errServerTimeMismatch = errors.New("Server times are too far apart.")
|
|
|
|
|
2016-08-24 19:14:14 +02:00
|
|
|
/// Auth operations
|
|
|
|
|
|
|
|
// Login - login handler.
|
2016-10-11 09:50:27 +02:00
|
|
|
func (c *controlAPIHandlers) LoginHandler(args *RPCLoginArgs, reply *RPCLoginReply) error {
|
2016-10-05 19:18:55 +02:00
|
|
|
jwt, err := newJWT(defaultInterNodeJWTExpiry)
|
2016-08-24 19:14:14 +02: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-11 09:50:27 +02:00
|
|
|
reply.Timestamp = time.Now().UTC()
|
2016-08-24 19:14:14 +02:00
|
|
|
reply.ServerVersion = Version
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-17 20:36:33 +02:00
|
|
|
// HealListArgs - argument for ListObjects RPC.
|
|
|
|
type HealListArgs struct {
|
2016-08-24 19:14:14 +02:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
|
|
|
|
2016-08-17 20:36:33 +02:00
|
|
|
Bucket string
|
|
|
|
Prefix string
|
|
|
|
Marker string
|
|
|
|
Delimiter string
|
|
|
|
MaxKeys int
|
|
|
|
}
|
|
|
|
|
2016-08-24 19:14:14 +02:00
|
|
|
// HealListReply - reply object by ListObjects RPC.
|
2016-08-17 20:36:33 +02:00
|
|
|
type HealListReply struct {
|
|
|
|
IsTruncated bool
|
|
|
|
NextMarker string
|
2016-10-15 04:57:40 +02:00
|
|
|
Objects []ObjectInfo
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
|
|
|
|
2016-08-21 21:06:53 +02:00
|
|
|
// ListObjects - list all objects that needs healing.
|
2016-10-11 09:50:27 +02:00
|
|
|
func (c *controlAPIHandlers) ListObjectsHealHandler(args *HealListArgs, reply *HealListReply) error {
|
2016-08-18 23:50:50 +02:00
|
|
|
objAPI := c.ObjectAPI()
|
2016-08-21 21:06:53 +02:00
|
|
|
if objAPI == nil {
|
2016-09-23 08:47:48 +02:00
|
|
|
return errServerNotInitialized
|
2016-08-24 19:14:14 +02:00
|
|
|
}
|
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
2016-08-21 21:06:53 +02:00
|
|
|
}
|
2016-10-15 04:57:40 +02:00
|
|
|
if !c.IsXL {
|
|
|
|
return nil
|
|
|
|
}
|
2016-08-24 19:14:14 +02:00
|
|
|
info, err := objAPI.ListObjectsHeal(args.Bucket, args.Prefix, args.Marker, args.Delimiter, args.MaxKeys)
|
2016-08-17 20:36:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reply.IsTruncated = info.IsTruncated
|
|
|
|
reply.NextMarker = info.NextMarker
|
2016-10-15 04:57:40 +02:00
|
|
|
reply.Objects = info.Objects
|
2016-08-17 20:36:33 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-10-15 04:57:40 +02:00
|
|
|
// HealBucketArgs - arguments for HealBucket RPC.
|
|
|
|
type HealBucketArgs struct {
|
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
|
|
|
|
|
|
|
// Bucket to be healed.
|
|
|
|
Bucket string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heals missing buckets across disks, if we have enough quorum.
|
|
|
|
func (c *controlAPIHandlers) HealBucketHandler(args *HealBucketArgs, reply *GenericReply) error {
|
|
|
|
objAPI := c.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
|
|
|
if !c.IsXL {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// Proceed to heal the bucket.
|
|
|
|
return objAPI.HealBucket(args.Bucket)
|
|
|
|
}
|
|
|
|
|
2016-08-17 20:36:33 +02:00
|
|
|
// HealObjectArgs - argument for HealObject RPC.
|
|
|
|
type HealObjectArgs struct {
|
2016-08-24 19:14:14 +02:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
|
|
|
|
2016-10-15 04:57:40 +02:00
|
|
|
// Name of the bucket where the object
|
|
|
|
// needs to be healed.
|
2016-08-17 20:36:33 +02:00
|
|
|
Bucket string
|
2016-08-24 19:14:14 +02:00
|
|
|
|
2016-10-15 04:57:40 +02:00
|
|
|
// Name of the object to be healed.
|
|
|
|
Objects []ObjectInfo
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// HealObjectReply - reply by HealObject RPC.
|
2016-10-15 04:57:40 +02:00
|
|
|
type HealObjectReply struct {
|
|
|
|
Results []string
|
|
|
|
}
|
2016-08-17 20:36:33 +02:00
|
|
|
|
2016-10-15 04:57:40 +02:00
|
|
|
// HealObject heals 1000 objects at a time for missing chunks, missing metadata on a given bucket.
|
|
|
|
func (c *controlAPIHandlers) HealObjectsHandler(args *HealObjectArgs, reply *HealObjectReply) error {
|
2016-08-18 23:50:50 +02:00
|
|
|
objAPI := c.ObjectAPI()
|
2016-08-21 21:06:53 +02:00
|
|
|
if objAPI == nil {
|
2016-09-23 08:47:48 +02:00
|
|
|
return errServerNotInitialized
|
2016-08-21 21:06:53 +02:00
|
|
|
}
|
2016-08-24 19:14:14 +02:00
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
2016-10-15 04:57:40 +02:00
|
|
|
if !c.IsXL {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heal all objects that need healing.
|
|
|
|
var errs = make([]error, len(args.Objects))
|
|
|
|
for idx, objInfo := range args.Objects {
|
|
|
|
errs[idx] = objAPI.HealObject(args.Bucket, objInfo.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all the error causes.
|
|
|
|
var causes = make([]string, len(args.Objects))
|
|
|
|
for id, err := range errs {
|
|
|
|
if err != nil {
|
|
|
|
causes[id] = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the causes.
|
|
|
|
reply.Results = causes
|
|
|
|
return nil
|
2016-08-21 21:06:53 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 04:57:40 +02:00
|
|
|
// Heals backend storage format.
|
|
|
|
func (c *controlAPIHandlers) HealFormatHandler(args *GenericArgs, reply *GenericReply) error {
|
2016-08-29 04:31:59 +02:00
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
2016-10-15 04:57:40 +02:00
|
|
|
if !c.IsXL {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err := healFormatXL(c.StorageDisks)
|
2016-08-31 04:22:27 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
globalWakeupCh <- struct{}{}
|
|
|
|
}()
|
|
|
|
return err
|
2016-08-29 04:31:59 +02:00
|
|
|
}
|
|
|
|
|
2016-10-10 08:03:10 +02:00
|
|
|
// ServiceArgs - argument for Service RPC.
|
|
|
|
type ServiceArgs struct {
|
2016-08-24 19:14:14 +02:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
2016-08-21 21:06:53 +02:00
|
|
|
|
2016-10-10 08:03:10 +02:00
|
|
|
// Represents the type of operation server is requested
|
|
|
|
// to perform. Currently supported signals are
|
|
|
|
// stop, restart and status.
|
|
|
|
Signal serviceSignal
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceReply - represents service operation success info.
|
|
|
|
type ServiceReply struct {
|
|
|
|
StorageInfo StorageInfo
|
|
|
|
}
|
|
|
|
|
2016-10-11 09:50:27 +02:00
|
|
|
// Remote procedure call, calls serviceMethod with given input args.
|
|
|
|
func (c *controlAPIHandlers) remoteServiceCall(args *ServiceArgs, replies []*ServiceReply) error {
|
2016-10-10 08:03:10 +02:00
|
|
|
var wg sync.WaitGroup
|
2016-10-11 09:50:27 +02:00
|
|
|
var errs = make([]error, len(c.RemoteControls))
|
|
|
|
// Send remote call to all neighboring peers to restart minio servers.
|
|
|
|
for index, clnt := range c.RemoteControls {
|
2016-10-10 08:03:10 +02:00
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, client *AuthRPCClient) {
|
|
|
|
defer wg.Done()
|
2016-10-11 09:50:27 +02:00
|
|
|
errs[index] = client.Call("Control.ServiceHandler", args, replies[index])
|
|
|
|
errorIf(errs[index], "Unable to initiate control service request to remote node %s", client.Node())
|
2016-10-10 08:03:10 +02:00
|
|
|
}(index, clnt)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2016-10-11 09:50:27 +02:00
|
|
|
for _, err := range errs {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2016-08-24 19:14:14 +02:00
|
|
|
}
|
2016-08-21 21:06:53 +02:00
|
|
|
|
2016-10-10 08:03:10 +02:00
|
|
|
// Service - handler for sending service signals across many servers.
|
2016-10-11 09:50:27 +02:00
|
|
|
func (c *controlAPIHandlers) ServiceHandler(args *ServiceArgs, reply *ServiceReply) error {
|
2016-08-24 19:14:14 +02:00
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
2016-10-10 08:03:10 +02:00
|
|
|
objAPI := c.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
if args.Signal == serviceStatus {
|
|
|
|
reply.StorageInfo = objAPI.StorageInfo()
|
|
|
|
return nil
|
|
|
|
}
|
2016-10-11 09:50:27 +02:00
|
|
|
var replies = make([]*ServiceReply, len(c.RemoteControls))
|
2016-10-10 08:03:10 +02:00
|
|
|
switch args.Signal {
|
|
|
|
case serviceRestart:
|
|
|
|
if args.Remote {
|
|
|
|
// Set remote as false for remote calls.
|
|
|
|
args.Remote = false
|
2016-10-11 09:50:27 +02:00
|
|
|
if err := c.remoteServiceCall(args, replies); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-10-10 08:03:10 +02:00
|
|
|
}
|
|
|
|
globalServiceSignalCh <- serviceRestart
|
|
|
|
case serviceStop:
|
|
|
|
if args.Remote {
|
|
|
|
// Set remote as false for remote calls.
|
|
|
|
args.Remote = false
|
2016-10-11 09:50:27 +02:00
|
|
|
if err := c.remoteServiceCall(args, replies); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-10-10 08:03:10 +02:00
|
|
|
}
|
|
|
|
globalServiceSignalCh <- serviceStop
|
2016-08-21 21:06:53 +02:00
|
|
|
}
|
|
|
|
return nil
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
2016-08-31 04:22:27 +02:00
|
|
|
|
2016-10-10 08:03:10 +02:00
|
|
|
// LockInfo - RPC control handler for `minio control lock`. Returns the info of the locks held in the system.
|
2016-10-11 09:50:27 +02:00
|
|
|
func (c *controlAPIHandlers) TryInitHandler(args *GenericArgs, reply *GenericReply) error {
|
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
2016-08-31 20:39:08 +02:00
|
|
|
}
|
2016-10-15 04:57:40 +02:00
|
|
|
if !c.IsXL {
|
|
|
|
return nil
|
|
|
|
}
|
2016-10-11 09:50:27 +02:00
|
|
|
go func() {
|
|
|
|
globalWakeupCh <- struct{}{}
|
|
|
|
}()
|
|
|
|
*reply = GenericReply{}
|
2016-08-31 20:39:08 +02:00
|
|
|
return nil
|
|
|
|
}
|