2016-11-07 15:09:24 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2014-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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2016-11-30 01:39:32 -05:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/rpc"
|
|
|
|
)
|
2016-11-07 15:09:24 -05:00
|
|
|
|
|
|
|
// BucketMetaState - Interface to update bucket metadata in-memory
|
|
|
|
// state.
|
|
|
|
type BucketMetaState interface {
|
|
|
|
// Updates bucket notification
|
2016-11-21 16:51:05 -05:00
|
|
|
UpdateBucketNotification(args *SetBucketNotificationPeerArgs) error
|
2016-11-07 15:09:24 -05:00
|
|
|
|
|
|
|
// Updates bucket listener
|
2016-11-21 16:51:05 -05:00
|
|
|
UpdateBucketListener(args *SetBucketListenerPeerArgs) error
|
2016-11-07 15:09:24 -05:00
|
|
|
|
|
|
|
// Updates bucket policy
|
2016-11-21 16:51:05 -05:00
|
|
|
UpdateBucketPolicy(args *SetBucketPolicyPeerArgs) error
|
2016-11-07 15:09:24 -05:00
|
|
|
|
|
|
|
// Sends event
|
|
|
|
SendEvent(args *EventArgs) error
|
2016-11-30 16:37:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// BucketUpdater - Interface implementer calls one of BucketMetaState's methods.
|
|
|
|
type BucketUpdater interface {
|
|
|
|
BucketUpdate(client BucketMetaState) error
|
2016-11-07 15:09:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Type that implements BucketMetaState for local node.
|
2016-11-21 16:51:05 -05:00
|
|
|
type localBucketMetaState struct {
|
2016-11-07 15:09:24 -05:00
|
|
|
ObjectAPI func() ObjectLayer
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// localBucketMetaState.UpdateBucketNotification - updates in-memory global bucket
|
2016-11-07 15:09:24 -05:00
|
|
|
// notification info.
|
2016-11-21 16:51:05 -05:00
|
|
|
func (lc *localBucketMetaState) UpdateBucketNotification(args *SetBucketNotificationPeerArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
// check if object layer is available.
|
|
|
|
objAPI := lc.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
globalEventNotifier.SetBucketNotificationConfig(args.Bucket, args.NCfg)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// localBucketMetaState.UpdateBucketListener - updates in-memory global bucket
|
2016-11-07 15:09:24 -05:00
|
|
|
// listeners info.
|
2016-11-21 16:51:05 -05:00
|
|
|
func (lc *localBucketMetaState) UpdateBucketListener(args *SetBucketListenerPeerArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
// check if object layer is available.
|
|
|
|
objAPI := lc.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update in-memory notification config.
|
|
|
|
return globalEventNotifier.SetBucketListenerConfig(args.Bucket, args.LCfg)
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// localBucketMetaState.UpdateBucketPolicy - updates in-memory global bucket
|
2016-11-07 15:09:24 -05:00
|
|
|
// policy info.
|
2016-11-21 16:51:05 -05:00
|
|
|
func (lc *localBucketMetaState) UpdateBucketPolicy(args *SetBucketPolicyPeerArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
// check if object layer is available.
|
|
|
|
objAPI := lc.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
var pCh policyChange
|
|
|
|
if err := json.Unmarshal(args.PChBytes, &pCh); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return globalBucketPolicies.SetBucketPolicy(args.Bucket, pCh)
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// localBucketMetaState.SendEvent - sends event to local event notifier via
|
2016-11-07 15:09:24 -05:00
|
|
|
// `globalEventNotifier`
|
2016-11-21 16:51:05 -05:00
|
|
|
func (lc *localBucketMetaState) SendEvent(args *EventArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
// check if object layer is available.
|
|
|
|
objAPI := lc.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
return globalEventNotifier.SendListenerEvent(args.Arn, args.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type that implements BucketMetaState for remote node.
|
2016-11-21 16:51:05 -05:00
|
|
|
type remoteBucketMetaState struct {
|
2016-11-07 15:09:24 -05:00
|
|
|
*AuthRPCClient
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// remoteBucketMetaState.UpdateBucketNotification - sends bucket notification
|
2016-11-07 15:09:24 -05:00
|
|
|
// change to remote peer via RPC call.
|
2016-11-21 16:51:05 -05:00
|
|
|
func (rc *remoteBucketMetaState) UpdateBucketNotification(args *SetBucketNotificationPeerArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
reply := GenericReply{}
|
2016-11-30 01:39:32 -05:00
|
|
|
err := rc.Call("S3.SetBucketNotificationPeer", args, &reply)
|
|
|
|
// Check for network error and retry once.
|
|
|
|
if err != nil && err == rpc.ErrShutdown {
|
|
|
|
// Close the underlying connection to attempt once more.
|
|
|
|
rc.Close()
|
|
|
|
|
|
|
|
// Attempt again and proceed.
|
|
|
|
err = rc.Call("S3.SetBucketNotificationPeer", args, &reply)
|
|
|
|
}
|
|
|
|
return err
|
2016-11-07 15:09:24 -05:00
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// remoteBucketMetaState.UpdateBucketListener - sends bucket listener change to
|
2016-11-07 15:09:24 -05:00
|
|
|
// remote peer via RPC call.
|
2016-11-21 16:51:05 -05:00
|
|
|
func (rc *remoteBucketMetaState) UpdateBucketListener(args *SetBucketListenerPeerArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
reply := GenericReply{}
|
2016-11-30 01:39:32 -05:00
|
|
|
err := rc.Call("S3.SetBucketListenerPeer", args, &reply)
|
|
|
|
// Check for network error and retry once.
|
|
|
|
if err != nil && err == rpc.ErrShutdown {
|
|
|
|
// Close the underlying connection to attempt once more.
|
|
|
|
rc.Close()
|
|
|
|
|
|
|
|
// Attempt again and proceed.
|
|
|
|
err = rc.Call("S3.SetBucketListenerPeer", args, &reply)
|
|
|
|
}
|
|
|
|
return err
|
2016-11-07 15:09:24 -05:00
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// remoteBucketMetaState.UpdateBucketPolicy - sends bucket policy change to remote
|
2016-11-07 15:09:24 -05:00
|
|
|
// peer via RPC call.
|
2016-11-21 16:51:05 -05:00
|
|
|
func (rc *remoteBucketMetaState) UpdateBucketPolicy(args *SetBucketPolicyPeerArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
reply := GenericReply{}
|
2016-11-30 01:39:32 -05:00
|
|
|
err := rc.Call("S3.SetBucketPolicyPeer", args, &reply)
|
|
|
|
// Check for network error and retry once.
|
|
|
|
if err != nil && err == rpc.ErrShutdown {
|
|
|
|
// Close the underlying connection to attempt once more.
|
|
|
|
rc.Close()
|
|
|
|
|
|
|
|
// Attempt again and proceed.
|
|
|
|
err = rc.Call("S3.SetBucketPolicyPeer", args, &reply)
|
|
|
|
}
|
|
|
|
return err
|
2016-11-07 15:09:24 -05:00
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
// remoteBucketMetaState.SendEvent - sends event for bucket listener to remote
|
2016-11-07 15:09:24 -05:00
|
|
|
// peer via RPC call.
|
2016-11-21 16:51:05 -05:00
|
|
|
func (rc *remoteBucketMetaState) SendEvent(args *EventArgs) error {
|
2016-11-07 15:09:24 -05:00
|
|
|
reply := GenericReply{}
|
2016-11-30 01:39:32 -05:00
|
|
|
err := rc.Call("S3.Event", args, &reply)
|
|
|
|
// Check for network error and retry once.
|
|
|
|
if err != nil && err == rpc.ErrShutdown {
|
|
|
|
// Close the underlying connection to attempt once more.
|
|
|
|
rc.Close()
|
|
|
|
|
|
|
|
// Attempt again and proceed.
|
|
|
|
err = rc.Call("S3.Event", args, &reply)
|
|
|
|
}
|
|
|
|
return err
|
2016-11-07 15:09:24 -05:00
|
|
|
}
|