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-09-23 02:47:48 -04:00
|
|
|
import "errors"
|
|
|
|
|
|
|
|
// 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-08-21 15:06:53 -04:00
|
|
|
// ShutdownArgs - argument for Shutdown RPC.
|
|
|
|
type ShutdownArgs struct {
|
2016-08-24 13:14:14 -04:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
2016-08-21 15:06:53 -04:00
|
|
|
|
2016-09-21 22:58:50 -04:00
|
|
|
// Should the server be restarted, all active connections are
|
|
|
|
// served before server is restarted.
|
2016-08-24 13:14:14 -04:00
|
|
|
Restart bool
|
|
|
|
}
|
2016-08-21 15:06:53 -04:00
|
|
|
|
2016-08-24 13:14:14 -04:00
|
|
|
// Shutdown - Shutsdown the server.
|
|
|
|
func (c *controllerAPIHandlers) ShutdownHandler(args *ShutdownArgs, reply *GenericReply) error {
|
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
|
|
|
if args.Restart {
|
2016-08-21 15:06:53 -04:00
|
|
|
globalShutdownSignalCh <- shutdownRestart
|
|
|
|
} else {
|
|
|
|
globalShutdownSignalCh <- shutdownHalt
|
|
|
|
}
|
|
|
|
return nil
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
2016-08-30 22:22:27 -04:00
|
|
|
|
2016-08-31 14:39:08 -04:00
|
|
|
// LockInfo - RPC control handler for `minio control lock`.
|
|
|
|
// Returns the info of the locks held in the system.
|
|
|
|
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
|
|
|
|
}
|
|
|
|
// the response containing the lock info.
|
|
|
|
*reply = lockInfo
|
|
|
|
return nil
|
|
|
|
}
|