You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
5.8 KiB
223 lines
5.8 KiB
8 years ago
|
/*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
8 years ago
|
|
||
8 years ago
|
import (
|
||
|
"errors"
|
||
|
"sync"
|
||
|
"time"
|
||
|
)
|
||
8 years ago
|
|
||
|
// errServerNotInitialized - server not initialized.
|
||
|
var errServerNotInitialized = errors.New("Server not initialized, please try again.")
|
||
|
|
||
8 years ago
|
// errServerVersionMismatch - server versions do not match.
|
||
|
var errServerVersionMismatch = errors.New("Server versions do not match.")
|
||
|
|
||
8 years ago
|
// errServerTimeMismatch - server times are too far apart.
|
||
|
var errServerTimeMismatch = errors.New("Server times are too far apart.")
|
||
|
|
||
8 years ago
|
/// Auth operations
|
||
|
|
||
|
// Login - login handler.
|
||
8 years ago
|
func (c *controlAPIHandlers) LoginHandler(args *RPCLoginArgs, reply *RPCLoginReply) error {
|
||
8 years ago
|
jwt, err := newJWT(defaultInterNodeJWTExpiry)
|
||
8 years ago
|
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
|
||
8 years ago
|
reply.Timestamp = time.Now().UTC()
|
||
8 years ago
|
reply.ServerVersion = Version
|
||
|
return nil
|
||
|
}
|
||
|
|
||
8 years ago
|
// HealListArgs - argument for ListObjects RPC.
|
||
|
type HealListArgs struct {
|
||
8 years ago
|
// Authentication token generated by Login.
|
||
|
GenericArgs
|
||
|
|
||
8 years ago
|
Bucket string
|
||
|
Prefix string
|
||
|
Marker string
|
||
|
Delimiter string
|
||
|
MaxKeys int
|
||
|
}
|
||
|
|
||
8 years ago
|
// HealListReply - reply object by ListObjects RPC.
|
||
8 years ago
|
type HealListReply struct {
|
||
|
IsTruncated bool
|
||
|
NextMarker string
|
||
|
Objects []string
|
||
|
}
|
||
|
|
||
8 years ago
|
// ListObjects - list all objects that needs healing.
|
||
8 years ago
|
func (c *controlAPIHandlers) ListObjectsHealHandler(args *HealListArgs, reply *HealListReply) error {
|
||
8 years ago
|
objAPI := c.ObjectAPI()
|
||
8 years ago
|
if objAPI == nil {
|
||
8 years ago
|
return errServerNotInitialized
|
||
8 years ago
|
}
|
||
|
if !isRPCTokenValid(args.Token) {
|
||
|
return errInvalidToken
|
||
8 years ago
|
}
|
||
8 years ago
|
info, err := objAPI.ListObjectsHeal(args.Bucket, args.Prefix, args.Marker, args.Delimiter, args.MaxKeys)
|
||
8 years ago
|
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 {
|
||
8 years ago
|
// Authentication token generated by Login.
|
||
|
GenericArgs
|
||
|
|
||
|
// Name of the bucket.
|
||
8 years ago
|
Bucket string
|
||
8 years ago
|
|
||
|
// Name of the object.
|
||
8 years ago
|
Object string
|
||
|
}
|
||
|
|
||
|
// HealObjectReply - reply by HealObject RPC.
|
||
|
type HealObjectReply struct{}
|
||
|
|
||
8 years ago
|
// HealObject - heal the object.
|
||
8 years ago
|
func (c *controlAPIHandlers) HealObjectHandler(args *HealObjectArgs, reply *GenericReply) error {
|
||
8 years ago
|
objAPI := c.ObjectAPI()
|
||
8 years ago
|
if objAPI == nil {
|
||
8 years ago
|
return errServerNotInitialized
|
||
8 years ago
|
}
|
||
8 years ago
|
if !isRPCTokenValid(args.Token) {
|
||
|
return errInvalidToken
|
||
|
}
|
||
|
return objAPI.HealObject(args.Bucket, args.Object)
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
// HealObject - heal the object.
|
||
8 years ago
|
func (c *controlAPIHandlers) HealDiskMetadataHandler(args *GenericArgs, reply *GenericReply) error {
|
||
8 years ago
|
if !isRPCTokenValid(args.Token) {
|
||
|
return errInvalidToken
|
||
|
}
|
||
8 years ago
|
err := repairDiskMetadata(c.StorageDisks)
|
||
8 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
go func() {
|
||
|
globalWakeupCh <- struct{}{}
|
||
|
}()
|
||
|
return err
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
// ServiceArgs - argument for Service RPC.
|
||
|
type ServiceArgs struct {
|
||
8 years ago
|
// Authentication token generated by Login.
|
||
|
GenericArgs
|
||
8 years ago
|
|
||
8 years ago
|
// 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
|
||
|
}
|
||
|
|
||
8 years ago
|
// Remote procedure call, calls serviceMethod with given input args.
|
||
|
func (c *controlAPIHandlers) remoteServiceCall(args *ServiceArgs, replies []*ServiceReply) error {
|
||
8 years ago
|
var wg sync.WaitGroup
|
||
8 years ago
|
var errs = make([]error, len(c.RemoteControls))
|
||
|
// Send remote call to all neighboring peers to restart minio servers.
|
||
|
for index, clnt := range c.RemoteControls {
|
||
8 years ago
|
wg.Add(1)
|
||
|
go func(index int, client *AuthRPCClient) {
|
||
|
defer wg.Done()
|
||
8 years ago
|
errs[index] = client.Call("Control.ServiceHandler", args, replies[index])
|
||
|
errorIf(errs[index], "Unable to initiate control service request to remote node %s", client.Node())
|
||
8 years ago
|
}(index, clnt)
|
||
|
}
|
||
|
wg.Wait()
|
||
8 years ago
|
for _, err := range errs {
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
// Service - handler for sending service signals across many servers.
|
||
8 years ago
|
func (c *controlAPIHandlers) ServiceHandler(args *ServiceArgs, reply *ServiceReply) error {
|
||
8 years ago
|
if !isRPCTokenValid(args.Token) {
|
||
|
return errInvalidToken
|
||
|
}
|
||
8 years ago
|
objAPI := c.ObjectAPI()
|
||
|
if objAPI == nil {
|
||
|
return errServerNotInitialized
|
||
|
}
|
||
|
if args.Signal == serviceStatus {
|
||
|
reply.StorageInfo = objAPI.StorageInfo()
|
||
|
return nil
|
||
|
}
|
||
8 years ago
|
var replies = make([]*ServiceReply, len(c.RemoteControls))
|
||
8 years ago
|
switch args.Signal {
|
||
|
case serviceRestart:
|
||
|
if args.Remote {
|
||
|
// Set remote as false for remote calls.
|
||
|
args.Remote = false
|
||
8 years ago
|
if err := c.remoteServiceCall(args, replies); err != nil {
|
||
|
return err
|
||
|
}
|
||
8 years ago
|
}
|
||
|
globalServiceSignalCh <- serviceRestart
|
||
|
case serviceStop:
|
||
|
if args.Remote {
|
||
|
// Set remote as false for remote calls.
|
||
|
args.Remote = false
|
||
8 years ago
|
if err := c.remoteServiceCall(args, replies); err != nil {
|
||
|
return err
|
||
|
}
|
||
8 years ago
|
}
|
||
|
globalServiceSignalCh <- serviceStop
|
||
8 years ago
|
}
|
||
|
return nil
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
// LockInfo - RPC control handler for `minio control lock`. Returns the info of the locks held in the system.
|
||
8 years ago
|
func (c *controlAPIHandlers) TryInitHandler(args *GenericArgs, reply *GenericReply) error {
|
||
|
if !isRPCTokenValid(args.Token) {
|
||
|
return errInvalidToken
|
||
8 years ago
|
}
|
||
8 years ago
|
go func() {
|
||
|
globalWakeupCh <- struct{}{}
|
||
|
}()
|
||
|
*reply = GenericReply{}
|
||
8 years ago
|
return nil
|
||
|
}
|