2018-03-15 16:03:41 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2018, 2019 MinIO, Inc.
|
2018-03-15 16:03:41 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
import (
|
2018-10-09 17:00:01 -04:00
|
|
|
"bytes"
|
2018-03-15 16:27:16 -04:00
|
|
|
"context"
|
2018-03-15 16:03:41 -04:00
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
2019-01-14 01:44:20 -05:00
|
|
|
"io"
|
2018-12-18 13:05:26 -05:00
|
|
|
"net"
|
2018-03-15 16:03:41 -04:00
|
|
|
"net/url"
|
|
|
|
"path"
|
2020-03-27 00:07:39 -04:00
|
|
|
"sort"
|
2018-08-24 02:31:14 -04:00
|
|
|
"strings"
|
2018-03-15 16:03:41 -04:00
|
|
|
"sync"
|
2018-06-06 04:51:56 -04:00
|
|
|
"time"
|
2018-03-15 16:03:41 -04:00
|
|
|
|
2019-09-26 02:08:24 -04:00
|
|
|
"github.com/klauspost/compress/zip"
|
2019-05-30 01:29:37 -04:00
|
|
|
"github.com/minio/minio/cmd/crypto"
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2020-02-05 04:42:34 -05:00
|
|
|
|
|
|
|
bucketsse "github.com/minio/minio/pkg/bucket/encryption"
|
2020-01-27 17:12:34 -05:00
|
|
|
"github.com/minio/minio/pkg/bucket/lifecycle"
|
|
|
|
objectlock "github.com/minio/minio/pkg/bucket/object/lock"
|
|
|
|
"github.com/minio/minio/pkg/bucket/policy"
|
2020-02-05 04:42:34 -05:00
|
|
|
|
2020-03-27 00:07:39 -04:00
|
|
|
"github.com/minio/minio-go/v6/pkg/set"
|
2018-03-15 16:03:41 -04:00
|
|
|
"github.com/minio/minio/pkg/event"
|
2019-06-25 19:42:24 -04:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2018-03-15 16:03:41 -04:00
|
|
|
xnet "github.com/minio/minio/pkg/net"
|
2019-10-14 12:44:51 -04:00
|
|
|
"github.com/minio/minio/pkg/sync/errgroup"
|
2018-03-15 16:03:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// NotificationSys - notification system.
|
|
|
|
type NotificationSys struct {
|
|
|
|
sync.RWMutex
|
|
|
|
targetList *event.TargetList
|
|
|
|
bucketRulesMap map[string]event.RulesMap
|
|
|
|
bucketRemoteTargetRulesMap map[string]map[event.TargetID]event.RulesMap
|
2019-03-14 19:27:31 -04:00
|
|
|
peerClients []*peerRESTClient
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetARNList - returns available ARNs.
|
|
|
|
func (sys *NotificationSys) GetARNList() []string {
|
|
|
|
arns := []string{}
|
2019-11-22 01:08:41 -05:00
|
|
|
if sys == nil {
|
|
|
|
return arns
|
|
|
|
}
|
2019-10-23 01:59:13 -04:00
|
|
|
region := globalServerRegion
|
2018-03-15 16:03:41 -04:00
|
|
|
for _, targetID := range sys.targetList.List() {
|
2018-08-24 02:31:14 -04:00
|
|
|
// httpclient target is part of ListenBucketNotification
|
|
|
|
// which doesn't need to be listed as part of the ARN list
|
|
|
|
// This list is only meant for external targets, filter
|
|
|
|
// this out pro-actively.
|
|
|
|
if !strings.HasPrefix(targetID.ID, "httpclient+") {
|
|
|
|
arns = append(arns, targetID.ToARN(region).String())
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return arns
|
|
|
|
}
|
|
|
|
|
2018-05-09 14:25:38 -04:00
|
|
|
// NotificationPeerErr returns error associated for a remote peer.
|
|
|
|
type NotificationPeerErr struct {
|
|
|
|
Host xnet.Host // Remote host on which the rpc call was initiated
|
|
|
|
Err error // Error returned by the remote peer for an rpc call
|
|
|
|
}
|
|
|
|
|
2019-01-14 01:44:20 -05:00
|
|
|
// A NotificationGroup is a collection of goroutines working on subtasks that are part of
|
|
|
|
// the same overall task.
|
|
|
|
//
|
|
|
|
// A zero NotificationGroup is valid and does not cancel on error.
|
|
|
|
type NotificationGroup struct {
|
|
|
|
wg sync.WaitGroup
|
|
|
|
errs []NotificationPeerErr
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithNPeers returns a new NotificationGroup with length of errs slice upto nerrs,
|
|
|
|
// upon Wait() errors are returned collected from all tasks.
|
|
|
|
func WithNPeers(nerrs int) *NotificationGroup {
|
|
|
|
return &NotificationGroup{errs: make([]NotificationPeerErr, nerrs)}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait blocks until all function calls from the Go method have returned, then
|
|
|
|
// returns the slice of errors from all function calls.
|
|
|
|
func (g *NotificationGroup) Wait() []NotificationPeerErr {
|
|
|
|
g.wg.Wait()
|
|
|
|
return g.errs
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go calls the given function in a new goroutine.
|
|
|
|
//
|
|
|
|
// The first call to return a non-nil error will be
|
|
|
|
// collected in errs slice and returned by Wait().
|
|
|
|
func (g *NotificationGroup) Go(ctx context.Context, f func() error, index int, addr xnet.Host) {
|
|
|
|
g.wg.Add(1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer g.wg.Done()
|
|
|
|
g.errs[index] = NotificationPeerErr{
|
|
|
|
Host: addr,
|
|
|
|
}
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
if err := f(); err != nil {
|
|
|
|
g.errs[index].Err = err
|
|
|
|
// Last iteration log the error.
|
|
|
|
if i == 2 {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress", addr.String())
|
|
|
|
ctx := logger.SetReqInfo(ctx, reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
2018-12-18 17:39:21 -05:00
|
|
|
}
|
|
|
|
// Wait for one second and no need wait after last attempt.
|
|
|
|
if i < 2 {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
continue
|
2018-12-18 17:39:21 -05:00
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2018-12-18 17:39:21 -05:00
|
|
|
|
2019-03-14 19:27:31 -04:00
|
|
|
// ReloadFormat - calls ReloadFormat REST call on all peers.
|
2019-01-14 01:44:20 -05:00
|
|
|
func (sys *NotificationSys) ReloadFormat(dryRun bool) []NotificationPeerErr {
|
2019-03-14 19:27:31 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.ReloadFormat(dryRun)
|
2019-03-14 19:27:31 -04:00
|
|
|
}, idx, *client.host)
|
2019-01-14 01:44:20 -05:00
|
|
|
}
|
|
|
|
return ng.Wait()
|
2018-12-18 17:39:21 -05:00
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// DeletePolicy - deletes policy across all peers.
|
|
|
|
func (sys *NotificationSys) DeletePolicy(policyName string) []NotificationPeerErr {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.DeletePolicy(policyName)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadPolicy - reloads a specific modified policy across all peers
|
|
|
|
func (sys *NotificationSys) LoadPolicy(policyName string) []NotificationPeerErr {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.LoadPolicy(policyName)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// LoadPolicyMapping - reloads a policy mapping across all peers
|
|
|
|
func (sys *NotificationSys) LoadPolicyMapping(userOrGroup string, isGroup bool) []NotificationPeerErr {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.LoadPolicyMapping(userOrGroup, isGroup)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// DeleteUser - deletes a specific user across all peers
|
|
|
|
func (sys *NotificationSys) DeleteUser(accessKey string) []NotificationPeerErr {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.DeleteUser(accessKey)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadUser - reloads a specific user across all peers
|
|
|
|
func (sys *NotificationSys) LoadUser(accessKey string, temp bool) []NotificationPeerErr {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.LoadUser(accessKey, temp)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:39:21 -05:00
|
|
|
// LoadUsers - calls LoadUsers RPC call on all peers.
|
2019-01-14 01:44:20 -05:00
|
|
|
func (sys *NotificationSys) LoadUsers() []NotificationPeerErr {
|
2019-03-14 19:27:31 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), client.LoadUsers, idx, *client.host)
|
2018-12-18 17:39:21 -05:00
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
return ng.Wait()
|
2018-12-18 17:39:21 -05:00
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// LoadGroup - loads a specific group on all peers.
|
|
|
|
func (sys *NotificationSys) LoadGroup(group string) []NotificationPeerErr {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error { return client.LoadGroup(group) }, idx, *client.host)
|
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
2019-06-25 19:42:24 -04:00
|
|
|
// BackgroundHealStatus - returns background heal status of all peers
|
|
|
|
func (sys *NotificationSys) BackgroundHealStatus() []madmin.BgHealState {
|
|
|
|
states := make([]madmin.BgHealState, len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
st, err := client.BackgroundHealStatus()
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(context.Background(), err)
|
|
|
|
} else {
|
|
|
|
states[idx] = st
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return states
|
|
|
|
}
|
|
|
|
|
2019-01-14 01:44:20 -05:00
|
|
|
// StartProfiling - start profiling on remote peers, by initiating a remote RPC.
|
|
|
|
func (sys *NotificationSys) StartProfiling(profiler string) []NotificationPeerErr {
|
2019-03-14 19:27:31 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.StartProfiling(profiler)
|
2019-03-14 19:27:31 -04:00
|
|
|
}, idx, *client.host)
|
2019-01-14 01:44:20 -05:00
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadProfilingData - download profiling data from all remote peers.
|
|
|
|
func (sys *NotificationSys) DownloadProfilingData(ctx context.Context, writer io.Writer) bool {
|
|
|
|
profilingDataFound := false
|
|
|
|
|
|
|
|
// Initialize a zip writer which will provide a zipped content
|
|
|
|
// of profiling data of all nodes
|
|
|
|
zipWriter := zip.NewWriter(writer)
|
|
|
|
defer zipWriter.Close()
|
|
|
|
|
2019-03-14 19:27:31 -04:00
|
|
|
for _, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
data, err := client.DownloadProfileData()
|
2019-01-14 01:44:20 -05:00
|
|
|
if err != nil {
|
2019-03-14 19:27:31 -04:00
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress", client.host.String())
|
2019-01-14 01:44:20 -05:00
|
|
|
ctx := logger.SetReqInfo(ctx, reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
profilingDataFound = true
|
|
|
|
|
2020-01-10 20:19:58 -05:00
|
|
|
for typ, data := range data {
|
|
|
|
// Send profiling data to zip as file
|
|
|
|
header, zerr := zip.FileInfoHeader(dummyFileInfo{
|
2020-03-16 14:39:53 -04:00
|
|
|
name: fmt.Sprintf("profile-%s-%s", client.host.String(), typ),
|
2020-01-10 20:19:58 -05:00
|
|
|
size: int64(len(data)),
|
|
|
|
mode: 0600,
|
|
|
|
modTime: UTCNow(),
|
|
|
|
isDir: false,
|
|
|
|
sys: nil,
|
|
|
|
})
|
|
|
|
if zerr != nil {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress", client.host.String())
|
|
|
|
ctx := logger.SetReqInfo(ctx, reqInfo)
|
|
|
|
logger.LogIf(ctx, zerr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
zwriter, zerr := zipWriter.CreateHeader(header)
|
|
|
|
if zerr != nil {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress", client.host.String())
|
|
|
|
ctx := logger.SetReqInfo(ctx, reqInfo)
|
|
|
|
logger.LogIf(ctx, zerr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, err = io.Copy(zwriter, bytes.NewBuffer(data)); err != nil {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress", client.host.String())
|
|
|
|
ctx := logger.SetReqInfo(ctx, reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
continue
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 20:19:58 -05:00
|
|
|
// Local host
|
2019-01-14 01:44:20 -05:00
|
|
|
thisAddr, err := xnet.ParseHost(GetLocalPeer(globalEndpoints))
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return profilingDataFound
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := getProfileData()
|
|
|
|
if err != nil {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress", thisAddr.String())
|
|
|
|
ctx := logger.SetReqInfo(ctx, reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return profilingDataFound
|
|
|
|
}
|
|
|
|
|
|
|
|
profilingDataFound = true
|
|
|
|
|
|
|
|
// Send profiling data to zip as file
|
2020-01-10 20:19:58 -05:00
|
|
|
for typ, data := range data {
|
|
|
|
header, zerr := zip.FileInfoHeader(dummyFileInfo{
|
2020-03-04 09:58:12 -05:00
|
|
|
name: fmt.Sprintf("profile-%s-%s", thisAddr, typ),
|
2020-01-10 20:19:58 -05:00
|
|
|
size: int64(len(data)),
|
|
|
|
mode: 0600,
|
|
|
|
modTime: UTCNow(),
|
|
|
|
isDir: false,
|
|
|
|
sys: nil,
|
|
|
|
})
|
|
|
|
if zerr != nil {
|
|
|
|
return profilingDataFound
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
|
2020-01-10 20:19:58 -05:00
|
|
|
zwriter, zerr := zipWriter.CreateHeader(header)
|
|
|
|
if zerr != nil {
|
|
|
|
return profilingDataFound
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
|
2020-01-10 20:19:58 -05:00
|
|
|
if _, err = io.Copy(zwriter, bytes.NewBuffer(data)); err != nil {
|
|
|
|
return profilingDataFound
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return profilingDataFound
|
|
|
|
}
|
|
|
|
|
2019-08-28 18:04:43 -04:00
|
|
|
// ServerUpdate - updates remote peers.
|
|
|
|
func (sys *NotificationSys) ServerUpdate(updateURL, sha256Hex string, latestReleaseTime time.Time) []NotificationPeerErr {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.ServerUpdate(updateURL, sha256Hex, latestReleaseTime)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
2019-01-14 01:44:20 -05:00
|
|
|
// SignalService - calls signal service RPC call on all peers.
|
|
|
|
func (sys *NotificationSys) SignalService(sig serviceSignal) []NotificationPeerErr {
|
2019-03-14 19:27:31 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-01-14 01:44:20 -05:00
|
|
|
client := client
|
|
|
|
ng.Go(context.Background(), func() error {
|
|
|
|
return client.SignalService(sig)
|
2019-03-14 19:27:31 -04:00
|
|
|
}, idx, *client.host)
|
2019-01-14 01:44:20 -05:00
|
|
|
}
|
|
|
|
return ng.Wait()
|
|
|
|
}
|
|
|
|
|
2019-01-24 10:22:14 -05:00
|
|
|
// GetLocks - makes GetLocks RPC call on all peers.
|
|
|
|
func (sys *NotificationSys) GetLocks(ctx context.Context) []*PeerLocks {
|
2019-03-14 19:27:31 -04:00
|
|
|
locksResp := make([]*PeerLocks, len(sys.peerClients))
|
2019-10-14 12:44:51 -04:00
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
2019-03-14 19:27:31 -04:00
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2019-01-24 10:22:14 -05:00
|
|
|
// Try to fetch serverInfo remotely in three attempts.
|
|
|
|
for i := 0; i < 3; i++ {
|
2019-10-14 12:44:51 -04:00
|
|
|
serverLocksResp, err := sys.peerClients[index].GetLocks()
|
2019-01-24 10:22:14 -05:00
|
|
|
if err == nil {
|
2019-10-14 12:44:51 -04:00
|
|
|
locksResp[index] = &PeerLocks{
|
|
|
|
Addr: sys.peerClients[index].host.String(),
|
2019-01-24 10:22:14 -05:00
|
|
|
Locks: serverLocksResp,
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
return nil
|
2019-01-24 10:22:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Last iteration log the error.
|
|
|
|
if i == 2 {
|
2019-10-14 12:44:51 -04:00
|
|
|
return err
|
2019-01-24 10:22:14 -05:00
|
|
|
}
|
|
|
|
// Wait for one second and no need wait after last attempt.
|
|
|
|
if i < 2 {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
return nil
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress",
|
|
|
|
sys.peerClients[index].host.String())
|
|
|
|
ctx := logger.SetReqInfo(ctx, reqInfo)
|
|
|
|
logger.LogOnceIf(ctx, err, sys.peerClients[index].host.String())
|
2019-01-24 10:22:14 -05:00
|
|
|
}
|
|
|
|
return locksResp
|
|
|
|
}
|
|
|
|
|
2018-04-24 18:53:30 -04:00
|
|
|
// SetBucketPolicy - calls SetBucketPolicy RPC call on all peers.
|
2018-07-03 14:09:36 -04:00
|
|
|
func (sys *NotificationSys) SetBucketPolicy(ctx context.Context, bucketName string, bucketPolicy *policy.Policy) {
|
2018-05-09 18:11:51 -04:00
|
|
|
go func() {
|
2019-10-14 12:44:51 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
2019-03-14 19:27:31 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.SetBucketPolicy(bucketName, bucketPolicy)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
ng.Wait()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteBucket - calls DeleteBucket RPC call on all peers.
|
|
|
|
func (sys *NotificationSys) DeleteBucket(ctx context.Context, bucketName string) {
|
2019-11-21 16:18:32 -05:00
|
|
|
globalNotificationSys.RemoveNotification(bucketName)
|
|
|
|
globalBucketObjectLockConfig.Remove(bucketName)
|
|
|
|
globalPolicySys.Remove(bucketName)
|
|
|
|
globalLifecycleSys.Remove(bucketName)
|
|
|
|
|
2019-10-14 12:44:51 -04:00
|
|
|
go func() {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.DeleteBucket(bucketName)
|
|
|
|
}, idx, *client.host)
|
2018-05-09 18:11:51 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
ng.Wait()
|
2018-05-09 18:11:51 -04:00
|
|
|
}()
|
2018-04-24 18:53:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveBucketPolicy - calls RemoveBucketPolicy RPC call on all peers.
|
2018-07-03 14:09:36 -04:00
|
|
|
func (sys *NotificationSys) RemoveBucketPolicy(ctx context.Context, bucketName string) {
|
2018-05-09 18:11:51 -04:00
|
|
|
go func() {
|
2019-10-14 12:44:51 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
2019-03-14 19:27:31 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.RemoveBucketPolicy(bucketName)
|
|
|
|
}, idx, *client.host)
|
2018-05-09 18:11:51 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
ng.Wait()
|
2018-05-09 18:11:51 -04:00
|
|
|
}()
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
2019-11-21 16:18:32 -05:00
|
|
|
// RemoveBucketObjectLockConfig - calls RemoveBucketObjectLockConfig RPC call on all peers.
|
|
|
|
func (sys *NotificationSys) RemoveBucketObjectLockConfig(ctx context.Context, bucketName string) {
|
|
|
|
go func() {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.RemoveBucketObjectLockConfig(bucketName)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
ng.Wait()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2019-07-19 16:20:33 -04:00
|
|
|
// SetBucketLifecycle - calls SetBucketLifecycle on all peers.
|
2019-10-14 12:44:51 -04:00
|
|
|
func (sys *NotificationSys) SetBucketLifecycle(ctx context.Context, bucketName string,
|
|
|
|
bucketLifecycle *lifecycle.Lifecycle) {
|
2019-07-19 16:20:33 -04:00
|
|
|
go func() {
|
2019-10-14 12:44:51 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
2019-07-19 16:20:33 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.SetBucketLifecycle(bucketName, bucketLifecycle)
|
|
|
|
}, idx, *client.host)
|
2019-07-19 16:20:33 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
ng.Wait()
|
2019-07-19 16:20:33 -04:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveBucketLifecycle - calls RemoveLifecycle on all peers.
|
|
|
|
func (sys *NotificationSys) RemoveBucketLifecycle(ctx context.Context, bucketName string) {
|
|
|
|
go func() {
|
2019-10-14 12:44:51 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
2019-07-19 16:20:33 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.RemoveBucketLifecycle(bucketName)
|
|
|
|
}, idx, *client.host)
|
2019-07-19 16:20:33 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
ng.Wait()
|
2019-07-19 16:20:33 -04:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-02-05 04:42:34 -05:00
|
|
|
// SetBucketSSEConfig - calls SetBucketSSEConfig on all peers.
|
|
|
|
func (sys *NotificationSys) SetBucketSSEConfig(ctx context.Context, bucketName string,
|
|
|
|
encConfig *bucketsse.BucketSSEConfig) {
|
|
|
|
go func() {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.SetBucketSSEConfig(bucketName, encConfig)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
ng.Wait()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveBucketSSEConfig - calls RemoveBucketSSEConfig on all peers.
|
|
|
|
func (sys *NotificationSys) RemoveBucketSSEConfig(ctx context.Context, bucketName string) {
|
|
|
|
go func() {
|
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.RemoveBucketSSEConfig(bucketName)
|
|
|
|
}, idx, *client.host)
|
|
|
|
}
|
|
|
|
ng.Wait()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
// PutBucketNotification - calls PutBucketNotification RPC call on all peers.
|
2018-07-03 14:09:36 -04:00
|
|
|
func (sys *NotificationSys) PutBucketNotification(ctx context.Context, bucketName string, rulesMap event.RulesMap) {
|
2018-05-09 18:11:51 -04:00
|
|
|
go func() {
|
2019-10-14 12:44:51 -04:00
|
|
|
ng := WithNPeers(len(sys.peerClients))
|
|
|
|
for idx, client := range sys.peerClients {
|
2019-03-14 19:27:31 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
client := client
|
|
|
|
ng.Go(ctx, func() error {
|
|
|
|
return client.PutBucketNotification(bucketName, rulesMap)
|
|
|
|
}, idx, *client.host)
|
2018-05-09 18:11:51 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
ng.Wait()
|
2018-05-09 18:11:51 -04:00
|
|
|
}()
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddRemoteTarget - adds event rules map, HTTP/PeerRPC client target to bucket name.
|
|
|
|
func (sys *NotificationSys) AddRemoteTarget(bucketName string, target event.Target, rulesMap event.RulesMap) error {
|
|
|
|
if err := sys.targetList.Add(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
targetMap := sys.bucketRemoteTargetRulesMap[bucketName]
|
|
|
|
if targetMap == nil {
|
|
|
|
targetMap = make(map[event.TargetID]event.RulesMap)
|
|
|
|
}
|
2018-08-23 13:23:18 -04:00
|
|
|
|
|
|
|
rulesMap = rulesMap.Clone()
|
|
|
|
targetMap[target.ID()] = rulesMap
|
2018-03-15 16:03:41 -04:00
|
|
|
sys.bucketRemoteTargetRulesMap[bucketName] = targetMap
|
2018-08-23 13:23:18 -04:00
|
|
|
|
|
|
|
rulesMap = rulesMap.Clone()
|
|
|
|
rulesMap.Add(sys.bucketRulesMap[bucketName])
|
|
|
|
sys.bucketRulesMap[bucketName] = rulesMap
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
sys.Unlock()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoteTargetExist - checks whether given target ID is a HTTP/PeerRPC client target or not.
|
|
|
|
func (sys *NotificationSys) RemoteTargetExist(bucketName string, targetID event.TargetID) bool {
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
targetMap, ok := sys.bucketRemoteTargetRulesMap[bucketName]
|
|
|
|
if ok {
|
|
|
|
_, ok = targetMap[targetID]
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2019-10-01 20:05:02 -04:00
|
|
|
// Loads notification policies for all buckets into NotificationSys.
|
|
|
|
func (sys *NotificationSys) load(buckets []BucketInfo, objAPI ObjectLayer) error {
|
2018-03-15 16:03:41 -04:00
|
|
|
for _, bucket := range buckets {
|
2018-04-05 18:04:40 -04:00
|
|
|
ctx := logger.SetReqInfo(context.Background(), &logger.ReqInfo{BucketName: bucket.Name})
|
|
|
|
config, err := readNotificationConfig(ctx, objAPI, bucket.Name)
|
2018-10-08 18:47:13 -04:00
|
|
|
if err != nil && err != errNoSuchNotifications {
|
2019-06-15 06:14:27 -04:00
|
|
|
if _, ok := err.(*event.ErrARNNotFound); ok {
|
|
|
|
continue
|
|
|
|
}
|
2019-06-18 12:23:33 -04:00
|
|
|
return err
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
2018-10-08 18:47:13 -04:00
|
|
|
if err == errNoSuchNotifications {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
sys.AddRulesMap(bucket.Name, config.ToRulesMap())
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-08 18:47:13 -04:00
|
|
|
// Init - initializes notification system from notification.xml and listener.json of all buckets.
|
2019-10-01 20:05:02 -04:00
|
|
|
func (sys *NotificationSys) Init(buckets []BucketInfo, objAPI ObjectLayer) error {
|
2018-10-08 18:47:13 -04:00
|
|
|
if objAPI == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
2019-10-01 20:05:02 -04:00
|
|
|
// In gateway mode, notifications are not supported.
|
2020-02-02 04:52:07 -05:00
|
|
|
if globalIsGateway && !objAPI.IsNotificationSupported() {
|
2019-10-01 20:05:02 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:35:50 -05:00
|
|
|
if globalConfigTargetList != nil {
|
|
|
|
for _, target := range globalConfigTargetList.Targets() {
|
|
|
|
if err := sys.targetList.Add(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-23 20:09:11 -05:00
|
|
|
return sys.load(buckets, objAPI)
|
2018-10-08 18:47:13 -04:00
|
|
|
}
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
// AddRulesMap - adds rules map for bucket name.
|
|
|
|
func (sys *NotificationSys) AddRulesMap(bucketName string, rulesMap event.RulesMap) {
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
rulesMap = rulesMap.Clone()
|
|
|
|
|
|
|
|
for _, targetRulesMap := range sys.bucketRemoteTargetRulesMap[bucketName] {
|
|
|
|
rulesMap.Add(targetRulesMap)
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:23:18 -04:00
|
|
|
// Do not add for an empty rulesMap.
|
|
|
|
if len(rulesMap) == 0 {
|
|
|
|
delete(sys.bucketRulesMap, bucketName)
|
|
|
|
} else {
|
|
|
|
sys.bucketRulesMap[bucketName] = rulesMap
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveRulesMap - removes rules map for bucket name.
|
|
|
|
func (sys *NotificationSys) RemoveRulesMap(bucketName string, rulesMap event.RulesMap) {
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
sys.bucketRulesMap[bucketName].Remove(rulesMap)
|
|
|
|
if len(sys.bucketRulesMap[bucketName]) == 0 {
|
|
|
|
delete(sys.bucketRulesMap, bucketName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 15:36:45 -05:00
|
|
|
// ConfiguredTargetIDs - returns list of configured target id's
|
|
|
|
func (sys *NotificationSys) ConfiguredTargetIDs() []event.TargetID {
|
2019-12-19 16:45:56 -05:00
|
|
|
if sys == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-13 15:36:45 -05:00
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
|
|
|
var targetIDs []event.TargetID
|
|
|
|
for _, rmap := range sys.bucketRulesMap {
|
|
|
|
for _, rules := range rmap {
|
|
|
|
for _, targetSet := range rules {
|
|
|
|
targetIDs = append(targetIDs, targetSet.ToSlice()...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-14 03:01:15 -04:00
|
|
|
// Filter out targets configured via env
|
|
|
|
var tIDs []event.TargetID
|
|
|
|
for _, targetID := range targetIDs {
|
|
|
|
if !globalEnvTargetList.Exists(targetID) {
|
|
|
|
tIDs = append(tIDs, targetID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tIDs
|
2019-12-13 15:36:45 -05:00
|
|
|
}
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
// RemoveNotification - removes all notification configuration for bucket name.
|
|
|
|
func (sys *NotificationSys) RemoveNotification(bucketName string) {
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
delete(sys.bucketRulesMap, bucketName)
|
|
|
|
|
|
|
|
for targetID := range sys.bucketRemoteTargetRulesMap[bucketName] {
|
|
|
|
sys.targetList.Remove(targetID)
|
|
|
|
delete(sys.bucketRemoteTargetRulesMap[bucketName], targetID)
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(sys.bucketRemoteTargetRulesMap, bucketName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveAllRemoteTargets - closes and removes all HTTP/PeerRPC client targets.
|
|
|
|
func (sys *NotificationSys) RemoveAllRemoteTargets() {
|
2020-03-22 01:10:13 -04:00
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
for _, targetMap := range sys.bucketRemoteTargetRulesMap {
|
|
|
|
for targetID := range targetMap {
|
|
|
|
sys.targetList.Remove(targetID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveRemoteTarget - closes and removes target by target ID.
|
|
|
|
func (sys *NotificationSys) RemoveRemoteTarget(bucketName string, targetID event.TargetID) {
|
2018-05-09 18:11:51 -04:00
|
|
|
for terr := range sys.targetList.Remove(targetID) {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("targetID", terr.ID.Name)
|
2018-04-05 18:04:40 -04:00
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
2018-05-09 18:11:51 -04:00
|
|
|
logger.LogIf(ctx, terr.Err)
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
if _, ok := sys.bucketRemoteTargetRulesMap[bucketName]; ok {
|
|
|
|
delete(sys.bucketRemoteTargetRulesMap[bucketName], targetID)
|
|
|
|
if len(sys.bucketRemoteTargetRulesMap[bucketName]) == 0 {
|
|
|
|
delete(sys.bucketRemoteTargetRulesMap, bucketName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 18:11:51 -04:00
|
|
|
func (sys *NotificationSys) send(bucketName string, eventData event.Event, targetIDs ...event.TargetID) (errs []event.TargetIDErr) {
|
|
|
|
errCh := sys.targetList.Send(eventData, targetIDs...)
|
|
|
|
for terr := range errCh {
|
|
|
|
errs = append(errs, terr)
|
|
|
|
if sys.RemoteTargetExist(bucketName, terr.ID) {
|
|
|
|
sys.RemoveRemoteTarget(bucketName, terr.ID)
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 18:11:51 -04:00
|
|
|
return errs
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send - sends event data to all matching targets.
|
2018-05-09 18:11:51 -04:00
|
|
|
func (sys *NotificationSys) Send(args eventArgs) []event.TargetIDErr {
|
2018-03-15 16:03:41 -04:00
|
|
|
sys.RLock()
|
|
|
|
targetIDSet := sys.bucketRulesMap[args.BucketName].Match(args.EventName, args.Object.Name)
|
|
|
|
sys.RUnlock()
|
2018-10-12 15:25:59 -04:00
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
if len(targetIDSet) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
targetIDs := targetIDSet.ToSlice()
|
|
|
|
return sys.send(args.BucketName, args.ToEvent(), targetIDs...)
|
|
|
|
}
|
|
|
|
|
2019-11-12 17:50:18 -05:00
|
|
|
// PutBucketObjectLockConfig - put bucket object lock configuration to all peers.
|
2020-01-16 18:41:56 -05:00
|
|
|
func (sys *NotificationSys) PutBucketObjectLockConfig(ctx context.Context, bucketName string, retention objectlock.Retention) {
|
2019-11-21 16:18:32 -05:00
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
2019-11-12 17:50:18 -05:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-11-21 16:18:32 -05:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
return sys.peerClients[index].PutBucketObjectLockConfig(bucketName, retention)
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
for i, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
logger.GetReqInfo(ctx).AppendTags("remotePeer", sys.peerClients[i].host.String())
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
}
|
2019-11-12 17:50:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 22:56:32 -04:00
|
|
|
// NetReadPerfInfo - Network read performance information.
|
|
|
|
func (sys *NotificationSys) NetReadPerfInfo(size int64) []ServerNetReadPerfInfo {
|
|
|
|
reply := make([]ServerNetReadPerfInfo, len(sys.peerClients))
|
|
|
|
|
|
|
|
// Execution is done serially.
|
|
|
|
for i, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := client.NetReadPerfInfo(size)
|
|
|
|
if err != nil {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", client.host.String())
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
|
|
|
|
info.Addr = client.host.String()
|
|
|
|
info.Error = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
reply[i] = info
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// CollectNetPerfInfo - Collect network performance information of all peers.
|
|
|
|
func (sys *NotificationSys) CollectNetPerfInfo(size int64) map[string][]ServerNetReadPerfInfo {
|
|
|
|
reply := map[string][]ServerNetReadPerfInfo{}
|
|
|
|
|
|
|
|
// Execution is done serially.
|
|
|
|
for _, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := client.CollectNetPerfInfo(size)
|
|
|
|
if err != nil {
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", client.host.String())
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
reply[client.host.String()] = info
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
2020-03-27 00:07:39 -04:00
|
|
|
// NetOBDInfo - Net OBD information
|
|
|
|
func (sys *NotificationSys) NetOBDInfo(ctx context.Context) madmin.ServerNetOBDInfo {
|
|
|
|
var sortedGlobalEndpoints []string
|
|
|
|
|
|
|
|
/*
|
|
|
|
Ensure that only untraversed links are visited by this server
|
|
|
|
i.e. if netOBD tests have been performed between a -> b, then do
|
|
|
|
not run it between b -> a
|
|
|
|
|
|
|
|
The graph of tests looks like this
|
|
|
|
|
|
|
|
a b c d
|
|
|
|
a | o | x | x | x |
|
|
|
|
b | o | o | x | x |
|
|
|
|
c | o | o | o | x |
|
|
|
|
d | o | o | o | o |
|
|
|
|
|
|
|
|
'x's should be tested, and 'o's should be skipped
|
|
|
|
*/
|
|
|
|
stripPath := func(hostPath string) string {
|
|
|
|
return strings.Split(hostPath, slashSeparator)[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
hostSet := set.NewStringSet()
|
|
|
|
for _, ez := range globalEndpoints {
|
|
|
|
for _, e := range ez.Endpoints {
|
|
|
|
host := stripPath(e.Host)
|
|
|
|
if hostSet.Contains(host) {
|
|
|
|
sortedGlobalEndpoints = append(sortedGlobalEndpoints, host)
|
|
|
|
hostSet.Add(host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Strings(sortedGlobalEndpoints)
|
|
|
|
var remoteTargets []*peerRESTClient
|
|
|
|
search := func(host string) *peerRESTClient {
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if sys.peerClients[index].host.String() == host {
|
|
|
|
return client
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(sortedGlobalEndpoints); i++ {
|
|
|
|
if sortedGlobalEndpoints[i] != GetLocalPeer(globalEndpoints) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for j := 0; j < len(sortedGlobalEndpoints); j++ {
|
|
|
|
if j > i {
|
|
|
|
remoteTarget := search(sortedGlobalEndpoints[j])
|
|
|
|
if remoteTarget != nil {
|
|
|
|
remoteTargets = append(remoteTargets, remoteTarget)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
netOBDs := make([]madmin.NetOBDInfo, len(remoteTargets))
|
|
|
|
|
|
|
|
for index, client := range remoteTargets {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
netOBDs[index], err = client.NetOBDInfo(ctx)
|
|
|
|
|
|
|
|
addr := client.host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
netOBDs[index].Addr = addr
|
|
|
|
if err != nil {
|
|
|
|
netOBDs[index].Error = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return madmin.ServerNetOBDInfo{
|
|
|
|
Net: netOBDs,
|
|
|
|
Addr: GetLocalPeer(globalEndpoints),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DispatchNetOBDInfo - Net OBD information from other nodes
|
|
|
|
func (sys *NotificationSys) DispatchNetOBDInfo(ctx context.Context) []madmin.ServerNetOBDInfo {
|
|
|
|
serverNetOBDs := []madmin.ServerNetOBDInfo{}
|
|
|
|
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
serverNetOBD, err := sys.peerClients[index].DispatchNetOBDInfo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
serverNetOBD.Addr = client.host.String()
|
|
|
|
serverNetOBD.Error = err.Error()
|
|
|
|
}
|
|
|
|
serverNetOBDs = append(serverNetOBDs, serverNetOBD)
|
|
|
|
}
|
|
|
|
return serverNetOBDs
|
|
|
|
}
|
|
|
|
|
|
|
|
// DriveOBDInfo - Drive OBD information
|
|
|
|
func (sys *NotificationSys) DriveOBDInfo(ctx context.Context) []madmin.ServerDrivesOBDInfo {
|
|
|
|
reply := make([]madmin.ServerDrivesOBDInfo, len(sys.peerClients))
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].DriveOBDInfo(ctx)
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// CPUOBDInfo - CPU OBD information
|
|
|
|
func (sys *NotificationSys) CPUOBDInfo(ctx context.Context) []madmin.ServerCPUOBDInfo {
|
|
|
|
reply := make([]madmin.ServerCPUOBDInfo, len(sys.peerClients))
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].CPUOBDInfo(ctx)
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiskHwOBDInfo - Disk HW OBD information
|
|
|
|
func (sys *NotificationSys) DiskHwOBDInfo(ctx context.Context) []madmin.ServerDiskHwOBDInfo {
|
|
|
|
reply := make([]madmin.ServerDiskHwOBDInfo, len(sys.peerClients))
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].DiskHwOBDInfo(ctx)
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// OsOBDInfo - Os OBD information
|
|
|
|
func (sys *NotificationSys) OsOBDInfo(ctx context.Context) []madmin.ServerOsOBDInfo {
|
|
|
|
reply := make([]madmin.ServerOsOBDInfo, len(sys.peerClients))
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].OsOBDInfo(ctx)
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// MemOBDInfo - Mem OBD information
|
|
|
|
func (sys *NotificationSys) MemOBDInfo(ctx context.Context) []madmin.ServerMemOBDInfo {
|
|
|
|
reply := make([]madmin.ServerMemOBDInfo, len(sys.peerClients))
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].MemOBDInfo(ctx)
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProcOBDInfo - Process OBD information
|
|
|
|
func (sys *NotificationSys) ProcOBDInfo(ctx context.Context) []madmin.ServerProcOBDInfo {
|
|
|
|
reply := make([]madmin.ServerProcOBDInfo, len(sys.peerClients))
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].ProcOBDInfo(ctx)
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
2018-12-31 12:46:44 -05:00
|
|
|
// DrivePerfInfo - Drive speed (read and write) information
|
2019-09-12 17:52:30 -04:00
|
|
|
func (sys *NotificationSys) DrivePerfInfo(size int64) []madmin.ServerDrivesPerfInfo {
|
|
|
|
reply := make([]madmin.ServerDrivesPerfInfo, len(sys.peerClients))
|
2019-10-14 12:44:51 -04:00
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
2019-03-14 19:27:31 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].DrivePerfInfo(size)
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
2018-12-31 12:46:44 -05:00
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:04:19 -05:00
|
|
|
// MemUsageInfo - Mem utilization information
|
|
|
|
func (sys *NotificationSys) MemUsageInfo() []ServerMemUsageInfo {
|
2019-03-14 19:27:31 -04:00
|
|
|
reply := make([]ServerMemUsageInfo, len(sys.peerClients))
|
2019-10-14 12:44:51 -04:00
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
2019-03-14 19:27:31 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].MemUsageInfo()
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
2019-01-09 22:04:19 -05:00
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// CPULoadInfo - CPU utilization information
|
|
|
|
func (sys *NotificationSys) CPULoadInfo() []ServerCPULoadInfo {
|
2019-03-14 19:27:31 -04:00
|
|
|
reply := make([]ServerCPULoadInfo, len(sys.peerClients))
|
2019-10-14 12:44:51 -04:00
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(sys.peerClients))
|
|
|
|
for index, client := range sys.peerClients {
|
2019-03-14 19:27:31 -04:00
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
var err error
|
|
|
|
reply[index], err = sys.peerClients[index].CPULoadInfo()
|
|
|
|
return err
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
for index, err := range g.Wait() {
|
|
|
|
if err != nil {
|
|
|
|
addr := sys.peerClients[index].host.String()
|
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags("remotePeer", addr)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
reply[index].Addr = addr
|
|
|
|
reply[index].Error = err.Error()
|
|
|
|
}
|
2019-01-09 22:04:19 -05:00
|
|
|
}
|
2019-10-03 10:48:38 -04:00
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
// CPUInfo - CPU Hardware info
|
|
|
|
func (sys *NotificationSys) CPUInfo() []madmin.ServerCPUHardwareInfo {
|
|
|
|
reply := make([]madmin.ServerCPUHardwareInfo, len(sys.peerClients))
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for i, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(client *peerRESTClient, idx int) {
|
|
|
|
defer wg.Done()
|
|
|
|
cpui, err := client.CPUInfo()
|
|
|
|
if err != nil {
|
|
|
|
cpui.Addr = client.host.String()
|
|
|
|
cpui.Error = err.Error()
|
|
|
|
}
|
|
|
|
reply[idx] = cpui
|
|
|
|
}(client, i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2019-01-09 22:04:19 -05:00
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
2019-10-17 07:09:50 -04:00
|
|
|
// NetworkInfo - Network Hardware info
|
|
|
|
func (sys *NotificationSys) NetworkInfo() []madmin.ServerNetworkHardwareInfo {
|
|
|
|
reply := make([]madmin.ServerNetworkHardwareInfo, len(sys.peerClients))
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for i, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(client *peerRESTClient, idx int) {
|
|
|
|
defer wg.Done()
|
|
|
|
netinfo, err := client.NetworkInfo()
|
|
|
|
if err != nil {
|
|
|
|
netinfo.Addr = client.host.String()
|
|
|
|
netinfo.Error = err.Error()
|
|
|
|
}
|
|
|
|
reply[idx] = netinfo
|
|
|
|
}(client, i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
2019-12-11 17:27:03 -05:00
|
|
|
// ServerInfo - calls ServerInfo RPC call on all peers.
|
|
|
|
func (sys *NotificationSys) ServerInfo() []madmin.ServerProperties {
|
|
|
|
reply := make([]madmin.ServerProperties, len(sys.peerClients))
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for i, client := range sys.peerClients {
|
|
|
|
if client == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(client *peerRESTClient, idx int) {
|
|
|
|
defer wg.Done()
|
|
|
|
info, err := client.ServerInfo()
|
|
|
|
if err != nil {
|
|
|
|
info.Endpoint = client.host.String()
|
|
|
|
info.State = "offline"
|
|
|
|
} else {
|
|
|
|
info.State = "ok"
|
|
|
|
}
|
|
|
|
reply[idx] = info
|
|
|
|
}(client, i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
// NewNotificationSys - creates new notification system object.
|
2019-11-19 20:42:27 -05:00
|
|
|
func NewNotificationSys(endpoints EndpointZones) *NotificationSys {
|
2018-03-15 16:03:41 -04:00
|
|
|
// bucketRulesMap/bucketRemoteTargetRulesMap are initialized by NotificationSys.Init()
|
|
|
|
return &NotificationSys{
|
2019-11-09 12:27:23 -05:00
|
|
|
targetList: event.NewTargetList(),
|
2018-03-15 16:03:41 -04:00
|
|
|
bucketRulesMap: make(map[string]event.RulesMap),
|
|
|
|
bucketRemoteTargetRulesMap: make(map[string]map[event.TargetID]event.RulesMap),
|
2019-11-09 12:27:23 -05:00
|
|
|
peerClients: getRestClients(endpoints),
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type eventArgs struct {
|
2018-08-23 17:40:54 -04:00
|
|
|
EventName event.Name
|
|
|
|
BucketName string
|
|
|
|
Object ObjectInfo
|
|
|
|
ReqParams map[string]string
|
|
|
|
RespElements map[string]string
|
|
|
|
Host string
|
|
|
|
UserAgent string
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToEvent - converts to notification event.
|
|
|
|
func (args eventArgs) ToEvent() event.Event {
|
|
|
|
getOriginEndpoint := func() string {
|
|
|
|
host := globalMinioHost
|
|
|
|
if host == "" {
|
|
|
|
// FIXME: Send FQDN or hostname of this machine than sending IP address.
|
2018-12-18 13:05:26 -05:00
|
|
|
host = sortIPs(localIP4.ToSlice())[0]
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
2018-12-18 13:05:26 -05:00
|
|
|
return fmt.Sprintf("%s://%s", getURLScheme(globalIsSSL), net.JoinHostPort(host, globalMinioPort))
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
eventTime := UTCNow()
|
|
|
|
uniqueID := fmt.Sprintf("%X", eventTime.UnixNano())
|
|
|
|
|
2018-08-23 17:40:54 -04:00
|
|
|
respElements := map[string]string{
|
2018-11-02 21:40:08 -04:00
|
|
|
"x-amz-request-id": args.RespElements["requestId"],
|
2019-04-09 14:39:42 -04:00
|
|
|
"x-minio-origin-endpoint": getOriginEndpoint(), // MinIO specific custom elements.
|
2018-08-23 17:40:54 -04:00
|
|
|
}
|
2018-12-18 13:05:26 -05:00
|
|
|
// Add deployment as part of
|
|
|
|
if globalDeploymentID != "" {
|
|
|
|
respElements["x-minio-deployment-id"] = globalDeploymentID
|
|
|
|
}
|
2018-08-23 17:40:54 -04:00
|
|
|
if args.RespElements["content-length"] != "" {
|
|
|
|
respElements["content-length"] = args.RespElements["content-length"]
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
newEvent := event.Event{
|
|
|
|
EventVersion: "2.0",
|
|
|
|
EventSource: "minio:s3",
|
2018-11-02 21:40:08 -04:00
|
|
|
AwsRegion: args.ReqParams["region"],
|
2018-03-15 16:03:41 -04:00
|
|
|
EventTime: eventTime.Format(event.AMZTimeFormat),
|
|
|
|
EventName: args.EventName,
|
2018-11-14 13:23:44 -05:00
|
|
|
UserIdentity: event.Identity{PrincipalID: args.ReqParams["accessKey"]},
|
2018-03-15 16:03:41 -04:00
|
|
|
RequestParameters: args.ReqParams,
|
2018-08-23 17:40:54 -04:00
|
|
|
ResponseElements: respElements,
|
2018-03-15 16:03:41 -04:00
|
|
|
S3: event.Metadata{
|
|
|
|
SchemaVersion: "1.0",
|
|
|
|
ConfigurationID: "Config",
|
|
|
|
Bucket: event.Bucket{
|
|
|
|
Name: args.BucketName,
|
2018-11-14 13:23:44 -05:00
|
|
|
OwnerIdentity: event.Identity{PrincipalID: args.ReqParams["accessKey"]},
|
2018-04-24 18:53:30 -04:00
|
|
|
ARN: policy.ResourceARNPrefix + args.BucketName,
|
2018-03-15 16:03:41 -04:00
|
|
|
},
|
|
|
|
Object: event.Object{
|
|
|
|
Key: url.QueryEscape(args.Object.Name),
|
|
|
|
VersionID: "1",
|
|
|
|
Sequencer: uniqueID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Source: event.Source{
|
|
|
|
Host: args.Host,
|
|
|
|
UserAgent: args.UserAgent,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if args.EventName != event.ObjectRemovedDelete {
|
|
|
|
newEvent.S3.Object.ETag = args.Object.ETag
|
|
|
|
newEvent.S3.Object.Size = args.Object.Size
|
2018-12-11 20:30:15 -05:00
|
|
|
if args.Object.IsCompressed() {
|
|
|
|
newEvent.S3.Object.Size = args.Object.GetActualSize()
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
newEvent.S3.Object.ContentType = args.Object.ContentType
|
|
|
|
newEvent.S3.Object.UserMetadata = args.Object.UserDefined
|
|
|
|
}
|
|
|
|
|
|
|
|
return newEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func sendEvent(args eventArgs) {
|
2019-05-30 01:29:37 -04:00
|
|
|
// remove sensitive encryption entries in metadata.
|
2019-10-21 02:48:19 -04:00
|
|
|
switch {
|
|
|
|
case crypto.IsEncrypted(args.Object.UserDefined):
|
|
|
|
if totalObjectSize, err := args.Object.DecryptedSize(); err == nil {
|
|
|
|
args.Object.Size = totalObjectSize
|
|
|
|
}
|
|
|
|
case args.Object.IsCompressed():
|
|
|
|
args.Object.Size = args.Object.GetActualSize()
|
|
|
|
}
|
|
|
|
|
2019-05-30 01:29:37 -04:00
|
|
|
crypto.RemoveSensitiveEntries(args.Object.UserDefined)
|
|
|
|
crypto.RemoveInternalEntries(args.Object.UserDefined)
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
// globalNotificationSys is not initialized in gateway mode.
|
|
|
|
if globalNotificationSys == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-13 14:33:11 -05:00
|
|
|
if globalHTTPListen.HasSubscribers() {
|
|
|
|
globalHTTPListen.Publish(args.ToEvent())
|
|
|
|
}
|
|
|
|
|
2018-07-03 14:09:36 -04:00
|
|
|
notifyCh := globalNotificationSys.Send(args)
|
|
|
|
go func() {
|
|
|
|
for _, err := range notifyCh {
|
|
|
|
reqInfo := &logger.ReqInfo{BucketName: args.BucketName, ObjectName: args.Object.Name}
|
|
|
|
reqInfo.AppendTags("EventName", args.EventName.String())
|
|
|
|
reqInfo.AppendTags("targetID", err.ID.Name)
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
|
|
|
logger.LogOnceIf(ctx, err.Err, err.ID)
|
|
|
|
}
|
|
|
|
}()
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
func readNotificationConfig(ctx context.Context, objAPI ObjectLayer, bucketName string) (*event.Config, error) {
|
2018-03-15 16:03:41 -04:00
|
|
|
// Construct path to notification.xml for the given bucket.
|
|
|
|
configFile := path.Join(bucketConfigPrefix, bucketName, bucketNotificationConfig)
|
2018-10-09 17:00:01 -04:00
|
|
|
configData, err := readConfig(ctx, objAPI, configFile)
|
2018-03-15 16:03:41 -04:00
|
|
|
if err != nil {
|
2018-04-24 18:53:30 -04:00
|
|
|
if err == errConfigNotFound {
|
|
|
|
err = errNoSuchNotifications
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:03:41 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
config, err := event.ParseConfig(bytes.NewReader(configData), globalServerRegion, globalNotificationSys.targetList)
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return config, err
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
func saveNotificationConfig(ctx context.Context, objAPI ObjectLayer, bucketName string, config *event.Config) error {
|
2018-03-15 16:03:41 -04:00
|
|
|
data, err := xml.Marshal(config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
configFile := path.Join(bucketConfigPrefix, bucketName, bucketNotificationConfig)
|
2018-10-09 17:00:01 -04:00
|
|
|
return saveConfig(ctx, objAPI, configFile, data)
|
2018-03-15 16:03:41 -04:00
|
|
|
}
|