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-09-23 08:47:48 +02:00
|
|
|
import "errors"
|
|
|
|
|
|
|
|
// 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-08-24 19:14:14 +02:00
|
|
|
/// Auth operations
|
|
|
|
|
|
|
|
// Login - login handler.
|
|
|
|
func (c *controllerAPIHandlers) 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
|
|
|
|
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
|
|
|
|
Objects []string
|
|
|
|
}
|
|
|
|
|
2016-08-21 21:06:53 +02:00
|
|
|
// ListObjects - list all objects that needs healing.
|
2016-08-24 19:14:14 +02:00
|
|
|
func (c *controllerAPIHandlers) 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-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
|
|
|
|
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 19:14:14 +02:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
|
|
|
|
|
|
|
// Name of the bucket.
|
2016-08-17 20:36:33 +02:00
|
|
|
Bucket string
|
2016-08-24 19:14:14 +02:00
|
|
|
|
|
|
|
// Name of the object.
|
2016-08-17 20:36:33 +02:00
|
|
|
Object string
|
|
|
|
}
|
|
|
|
|
|
|
|
// HealObjectReply - reply by HealObject RPC.
|
|
|
|
type HealObjectReply struct{}
|
|
|
|
|
2016-09-26 23:28:35 +02:00
|
|
|
// HealObject - heal the object.
|
2016-08-24 19:14:14 +02:00
|
|
|
func (c *controllerAPIHandlers) HealObjectHandler(args *HealObjectArgs, reply *GenericReply) 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
|
|
|
|
}
|
|
|
|
return objAPI.HealObject(args.Bucket, args.Object)
|
2016-08-21 21:06:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-26 23:28:35 +02:00
|
|
|
// HealObject - heal the object.
|
2016-08-29 04:31:59 +02:00
|
|
|
func (c *controllerAPIHandlers) HealDiskMetadataHandler(args *GenericArgs, reply *GenericReply) error {
|
|
|
|
if !isRPCTokenValid(args.Token) {
|
|
|
|
return errInvalidToken
|
|
|
|
}
|
2016-10-05 21:48:07 +02:00
|
|
|
err := repairDiskMetadata(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-08-21 21:06:53 +02:00
|
|
|
// ShutdownArgs - argument for Shutdown RPC.
|
|
|
|
type ShutdownArgs struct {
|
2016-08-24 19:14:14 +02:00
|
|
|
// Authentication token generated by Login.
|
|
|
|
GenericArgs
|
2016-08-21 21:06:53 +02:00
|
|
|
|
2016-09-22 04:58:50 +02:00
|
|
|
// Should the server be restarted, all active connections are
|
|
|
|
// served before server is restarted.
|
2016-08-24 19:14:14 +02:00
|
|
|
Restart bool
|
|
|
|
}
|
2016-08-21 21:06:53 +02:00
|
|
|
|
2016-08-24 19:14:14 +02: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 21:06:53 +02:00
|
|
|
globalShutdownSignalCh <- shutdownRestart
|
|
|
|
} else {
|
|
|
|
globalShutdownSignalCh <- shutdownHalt
|
|
|
|
}
|
|
|
|
return nil
|
2016-08-17 20:36:33 +02:00
|
|
|
}
|
2016-08-31 04:22:27 +02:00
|
|
|
|
2016-08-31 20:39:08 +02: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
|
|
|
|
}
|