2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-03-14 19:27:31 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/gob"
|
2024-01-19 21:27:58 -05:00
|
|
|
"encoding/hex"
|
2024-01-30 15:49:02 -05:00
|
|
|
"encoding/json"
|
2020-06-17 17:49:26 -04:00
|
|
|
"errors"
|
2020-10-28 12:18:35 -04:00
|
|
|
"fmt"
|
2019-03-14 19:27:31 -04:00
|
|
|
"io"
|
|
|
|
"net/url"
|
2019-06-06 20:46:22 -04:00
|
|
|
"strconv"
|
2024-01-30 15:49:02 -05:00
|
|
|
"sync/atomic"
|
2019-06-08 18:54:41 -04:00
|
|
|
"time"
|
2019-03-14 19:27:31 -04:00
|
|
|
|
2023-06-19 20:53:08 -04:00
|
|
|
"github.com/minio/madmin-go/v3"
|
2023-01-19 08:22:16 -05:00
|
|
|
"github.com/minio/minio/internal/bucket/bandwidth"
|
2024-01-30 15:49:02 -05:00
|
|
|
"github.com/minio/minio/internal/grid"
|
2021-06-01 17:59:40 -04:00
|
|
|
xhttp "github.com/minio/minio/internal/http"
|
|
|
|
"github.com/minio/minio/internal/logger"
|
|
|
|
"github.com/minio/minio/internal/rest"
|
2023-09-04 15:57:37 -04:00
|
|
|
xnet "github.com/minio/pkg/v2/net"
|
2019-03-14 19:27:31 -04:00
|
|
|
)
|
|
|
|
|
2020-03-27 00:07:39 -04:00
|
|
|
// client to talk to peer Nodes.
|
2019-03-14 19:27:31 -04:00
|
|
|
type peerRESTClient struct {
|
|
|
|
host *xnet.Host
|
|
|
|
restClient *rest.Client
|
2024-01-30 15:49:02 -05:00
|
|
|
gridHost string
|
|
|
|
// Function that returns the grid connection for this peer when initialized.
|
|
|
|
// Will return nil if the grid connection is not initialized yet.
|
|
|
|
gridConn func() *grid.Connection
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a peer rest client.
|
|
|
|
func newPeerRESTClient(peer *xnet.Host, gridHost string) *peerRESTClient {
|
|
|
|
scheme := "http"
|
|
|
|
if globalIsTLS {
|
|
|
|
scheme = "https"
|
|
|
|
}
|
|
|
|
|
|
|
|
serverURL := &url.URL{
|
|
|
|
Scheme: scheme,
|
|
|
|
Host: peer.String(),
|
|
|
|
Path: peerRESTPath,
|
|
|
|
}
|
|
|
|
|
|
|
|
restClient := rest.NewClient(serverURL, globalInternodeTransport, newCachedAuthToken())
|
|
|
|
// Use a separate client to avoid recursive calls.
|
|
|
|
healthClient := rest.NewClient(serverURL, globalInternodeTransport, newCachedAuthToken())
|
|
|
|
healthClient.NoMetrics = true
|
|
|
|
|
|
|
|
// Construct a new health function.
|
|
|
|
restClient.HealthCheckFn = func() bool {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), restClient.HealthCheckTimeout)
|
|
|
|
defer cancel()
|
|
|
|
respBody, err := healthClient.Call(ctx, peerRESTMethodHealth, nil, nil, -1)
|
|
|
|
xhttp.DrainBody(respBody)
|
|
|
|
return !isNetworkError(err)
|
|
|
|
}
|
|
|
|
var gridConn atomic.Pointer[grid.Connection]
|
|
|
|
|
|
|
|
return &peerRESTClient{
|
|
|
|
host: peer, restClient: restClient, gridHost: gridHost,
|
|
|
|
gridConn: func() *grid.Connection {
|
|
|
|
// Lazy initialization of grid connection.
|
|
|
|
// When we create this peer client, the grid connection is likely not yet initialized.
|
|
|
|
if gridHost == "" {
|
2024-04-04 08:04:40 -04:00
|
|
|
bugLogIf(context.Background(), fmt.Errorf("gridHost is empty for peer %s", peer.String()), peer.String()+":gridHost")
|
2024-01-30 15:49:02 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
gc := gridConn.Load()
|
|
|
|
if gc != nil {
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
gm := globalGrid.Load()
|
|
|
|
if gm == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
gc = gm.Connection(gridHost)
|
|
|
|
if gc == nil {
|
2024-04-04 08:04:40 -04:00
|
|
|
bugLogIf(context.Background(), fmt.Errorf("gridHost %q not found for peer %s", gridHost, peer.String()), peer.String()+":gridHost")
|
2024-01-30 15:49:02 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
gridConn.Store(gc)
|
|
|
|
return gc
|
|
|
|
},
|
|
|
|
}
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapper to restClient.Call to handle network errors, in case of network error the connection is marked disconnected
|
|
|
|
// permanently. The only way to restore the connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints()
|
|
|
|
// after verifying format.json
|
|
|
|
func (client *peerRESTClient) call(method string, values url.Values, body io.Reader, length int64) (respBody io.ReadCloser, err error) {
|
2020-04-09 12:30:02 -04:00
|
|
|
return client.callWithContext(GlobalContext, method, values, body, length)
|
2019-06-08 18:54:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapper to restClient.Call to handle network errors, in case of network error the connection is marked disconnected
|
|
|
|
// permanently. The only way to restore the connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints()
|
|
|
|
// after verifying format.json
|
|
|
|
func (client *peerRESTClient) callWithContext(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (respBody io.ReadCloser, err error) {
|
2023-03-07 11:13:28 -05:00
|
|
|
if client == nil || !client.IsOnline() {
|
|
|
|
return nil, errPeerNotReachable
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:27:31 -04:00
|
|
|
if values == nil {
|
|
|
|
values = make(url.Values)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
respBody, err = client.restClient.Call(ctx, method, values, body, length)
|
2019-03-14 19:27:31 -04:00
|
|
|
if err == nil {
|
|
|
|
return respBody, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stringer provides a canonicalized representation of node.
|
|
|
|
func (client *peerRESTClient) String() string {
|
|
|
|
return client.host.String()
|
|
|
|
}
|
|
|
|
|
2020-12-22 12:16:07 -05:00
|
|
|
// IsOnline returns true if the peer client is online.
|
|
|
|
func (client *peerRESTClient) IsOnline() bool {
|
|
|
|
return client.restClient.IsOnline()
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:27:31 -04:00
|
|
|
// Close - marks the client as closed.
|
|
|
|
func (client *peerRESTClient) Close() error {
|
|
|
|
client.restClient.Close()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLocks - fetch older locks for a remote node.
|
2020-12-10 10:28:37 -05:00
|
|
|
func (client *peerRESTClient) GetLocks() (lockMap map[string][]lockRequesterInfo, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getLocksRPC.Call(context.Background(), client.gridConn(), grid.NewMSS())
|
|
|
|
if err != nil || resp == nil {
|
|
|
|
return nil, err
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return *resp, nil
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
|
|
|
|
2022-12-01 17:31:35 -05:00
|
|
|
// LocalStorageInfo - fetch server information for a remote node.
|
2023-12-21 19:56:43 -05:00
|
|
|
func (client *peerRESTClient) LocalStorageInfo(metrics bool) (info StorageInfo, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := localStorageInfoRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
|
|
|
peerRESTMetrics: strconv.FormatBool(metrics),
|
|
|
|
}))
|
|
|
|
return resp.ValueOrZero(), err
|
2022-12-01 17:31:35 -05:00
|
|
|
}
|
|
|
|
|
2019-03-14 19:27:31 -04:00
|
|
|
// ServerInfo - fetch server information for a remote node.
|
2024-02-08 22:28:46 -05:00
|
|
|
func (client *peerRESTClient) ServerInfo(metrics bool) (info madmin.ServerProperties, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := serverInfoRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{peerRESTMetrics: strconv.FormatBool(metrics)}))
|
|
|
|
return resp.ValueOrZero(), err
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
// GetCPUs - fetch CPU information for a remote node.
|
|
|
|
func (client *peerRESTClient) GetCPUs(ctx context.Context) (info madmin.CPUs, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getCPUsHandler.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2023-11-02 12:49:49 -04:00
|
|
|
// GetNetInfo - fetch network information for a remote node.
|
|
|
|
func (client *peerRESTClient) GetNetInfo(ctx context.Context) (info madmin.NetInfo, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getNetInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2023-11-02 12:49:49 -04:00
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
// GetPartitions - fetch disk partition information for a remote node.
|
|
|
|
func (client *peerRESTClient) GetPartitions(ctx context.Context) (info madmin.Partitions, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getPartitionsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
// GetOSInfo - fetch OS information for a remote node.
|
|
|
|
func (client *peerRESTClient) GetOSInfo(ctx context.Context) (info madmin.OSInfo, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getOSInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2021-08-12 21:58:40 -04:00
|
|
|
// GetSELinuxInfo - fetch SELinux information for a remote node.
|
|
|
|
func (client *peerRESTClient) GetSELinuxInfo(ctx context.Context) (info madmin.SysServices, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getSysServicesRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2021-08-12 21:58:40 -04:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:09:37 -04:00
|
|
|
// GetSysConfig - fetch sys config for a remote node.
|
|
|
|
func (client *peerRESTClient) GetSysConfig(ctx context.Context) (info madmin.SysConfig, err error) {
|
2022-01-06 04:51:10 -05:00
|
|
|
sent := time.Now()
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getSysConfigRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
info = resp.ValueOrZero()
|
2023-05-10 18:20:48 -04:00
|
|
|
if ti, ok := info.Config["time-info"].(madmin.TimeInfo); ok {
|
2024-02-19 17:54:46 -05:00
|
|
|
rt := int32(time.Since(sent).Milliseconds())
|
|
|
|
ti.RoundtripDuration = rt
|
2022-01-06 04:51:10 -05:00
|
|
|
info.Config["time-info"] = ti
|
|
|
|
}
|
2021-08-24 20:09:37 -04:00
|
|
|
return info, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSysErrors - fetch sys errors for a remote node.
|
2021-07-30 02:05:34 -04:00
|
|
|
func (client *peerRESTClient) GetSysErrors(ctx context.Context) (info madmin.SysErrors, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getSysErrorsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2021-07-30 02:05:34 -04:00
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
// GetMemInfo - fetch memory information for a remote node.
|
|
|
|
func (client *peerRESTClient) GetMemInfo(ctx context.Context) (info madmin.MemInfo, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getMemInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-05 17:45:49 -04:00
|
|
|
// GetMetrics - fetch metrics from a remote node.
|
2022-10-03 05:10:15 -04:00
|
|
|
func (client *peerRESTClient) GetMetrics(ctx context.Context, t madmin.MetricType, opts collectMetricsOpts) (info madmin.RealtimeMetrics, err error) {
|
2022-07-05 17:45:49 -04:00
|
|
|
values := make(url.Values)
|
2022-10-03 05:10:15 -04:00
|
|
|
values.Set(peerRESTMetricsTypes, strconv.FormatUint(uint64(t), 10))
|
|
|
|
for disk := range opts.disks {
|
2023-07-27 14:44:13 -04:00
|
|
|
values.Add(peerRESTDisk, disk)
|
2022-08-16 10:13:49 -04:00
|
|
|
}
|
2023-07-19 02:50:30 -04:00
|
|
|
for host := range opts.hosts {
|
|
|
|
values.Add(peerRESTHost, host)
|
|
|
|
}
|
2022-10-03 05:10:15 -04:00
|
|
|
values.Set(peerRESTJobID, opts.jobID)
|
2022-11-14 10:16:40 -05:00
|
|
|
values.Set(peerRESTDepID, opts.depID)
|
2024-02-19 17:54:46 -05:00
|
|
|
v, err := getMetricsRPC.Call(ctx, client.gridConn(), grid.NewURLValuesWith(values))
|
|
|
|
return v.ValueOrZero(), err
|
2022-07-05 17:45:49 -04:00
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
// GetProcInfo - fetch MinIO process information for a remote node.
|
|
|
|
func (client *peerRESTClient) GetProcInfo(ctx context.Context) (info madmin.ProcInfo, err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getProcInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2019-03-14 19:27:31 -04:00
|
|
|
// StartProfiling - Issues profiling command on the peer node.
|
|
|
|
func (client *peerRESTClient) StartProfiling(profiler string) error {
|
|
|
|
values := make(url.Values)
|
|
|
|
values.Set(peerRESTProfiler, profiler)
|
|
|
|
respBody, err := client.call(peerRESTMethodStartProfiling, values, nil, -1)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2019-03-14 19:27:31 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadProfileData - download profiled data from a remote node.
|
2020-01-10 20:19:58 -05:00
|
|
|
func (client *peerRESTClient) DownloadProfileData() (data map[string][]byte, err error) {
|
2019-03-14 19:27:31 -04:00
|
|
|
respBody, err := client.call(peerRESTMethodDownloadProfilingData, nil, nil, -1)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2019-03-14 19:27:31 -04:00
|
|
|
err = gob.NewDecoder(respBody).Decode(&data)
|
|
|
|
return data, err
|
|
|
|
}
|
|
|
|
|
2021-04-04 18:34:33 -04:00
|
|
|
// GetBucketStats - load bucket statistics
|
|
|
|
func (client *peerRESTClient) GetBucketStats(bucket string) (BucketStats, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getBucketStatsRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
|
|
|
peerRESTBucket: bucket,
|
|
|
|
}))
|
|
|
|
if err != nil || resp == nil {
|
2021-04-04 18:34:33 -04:00
|
|
|
return BucketStats{}, err
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return *resp, nil
|
2021-04-04 18:34:33 -04:00
|
|
|
}
|
|
|
|
|
2024-02-19 17:54:46 -05:00
|
|
|
// GetSRMetrics loads site replication metrics, optionally for a specific bucket
|
2023-08-30 04:00:59 -04:00
|
|
|
func (client *peerRESTClient) GetSRMetrics() (SRMetricsSummary, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getSRMetricsRPC.Call(context.Background(), client.gridConn(), grid.NewMSS())
|
|
|
|
if err != nil || resp == nil {
|
2023-08-30 04:00:59 -04:00
|
|
|
return SRMetricsSummary{}, err
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return *resp, nil
|
2023-08-30 04:00:59 -04:00
|
|
|
}
|
|
|
|
|
2022-05-23 12:15:30 -04:00
|
|
|
// GetAllBucketStats - load replication stats for all buckets
|
|
|
|
func (client *peerRESTClient) GetAllBucketStats() (BucketStatsMap, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getAllBucketStatsRPC.Call(context.Background(), client.gridConn(), grid.NewMSS())
|
|
|
|
if err != nil || resp == nil {
|
2022-09-12 15:40:02 -04:00
|
|
|
return BucketStatsMap{}, err
|
2022-05-23 12:15:30 -04:00
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return *resp, nil
|
2022-05-23 12:15:30 -04:00
|
|
|
}
|
|
|
|
|
2020-05-19 16:53:54 -04:00
|
|
|
// LoadBucketMetadata - load bucket metadata
|
|
|
|
func (client *peerRESTClient) LoadBucketMetadata(bucket string) error {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := loadBucketMetadataRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTBucket: bucket,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
|
|
|
|
2020-05-19 16:53:54 -04:00
|
|
|
// DeleteBucketMetadata - Delete bucket metadata
|
|
|
|
func (client *peerRESTClient) DeleteBucketMetadata(bucket string) error {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := deleteBucketMetadataRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTBucket: bucket,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// DeletePolicy - delete a specific canned policy.
|
|
|
|
func (client *peerRESTClient) DeletePolicy(policyName string) (err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err = deletePolicyRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTPolicy: policyName,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-06-06 20:46:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// LoadPolicy - reload a specific canned policy.
|
|
|
|
func (client *peerRESTClient) LoadPolicy(policyName string) (err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err = loadPolicyRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTPolicy: policyName,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-06-06 20:46:22 -04:00
|
|
|
}
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// LoadPolicyMapping - reload a specific policy mapping
|
2022-08-23 14:11:45 -04:00
|
|
|
func (client *peerRESTClient) LoadPolicyMapping(userOrGroup string, userType IAMUserType, isGroup bool) error {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := loadPolicyMappingRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTUserOrGroup: userOrGroup,
|
|
|
|
peerRESTUserType: strconv.Itoa(int(userType)),
|
|
|
|
peerRESTIsGroup: strconv.FormatBool(isGroup),
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-08-13 16:41:06 -04:00
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// DeleteUser - delete a specific user.
|
|
|
|
func (client *peerRESTClient) DeleteUser(accessKey string) (err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err = deleteUserRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTUser: accessKey,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-06-06 20:46:22 -04:00
|
|
|
}
|
|
|
|
|
2020-04-24 15:10:09 -04:00
|
|
|
// DeleteServiceAccount - delete a specific service account.
|
|
|
|
func (client *peerRESTClient) DeleteServiceAccount(accessKey string) (err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err = deleteSvcActRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTUser: accessKey,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2020-04-24 15:10:09 -04:00
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// LoadUser - reload a specific user.
|
|
|
|
func (client *peerRESTClient) LoadUser(accessKey string, temp bool) (err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err = loadUserRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTUser: accessKey,
|
|
|
|
peerRESTUserTemp: strconv.FormatBool(temp),
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-06-06 20:46:22 -04:00
|
|
|
}
|
|
|
|
|
2020-04-24 15:10:09 -04:00
|
|
|
// LoadServiceAccount - reload a specific service account.
|
|
|
|
func (client *peerRESTClient) LoadServiceAccount(accessKey string) (err error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err = loadSvcActRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTUser: accessKey,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2020-04-24 15:10:09 -04:00
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// LoadGroup - send load group command to peers.
|
|
|
|
func (client *peerRESTClient) LoadGroup(group string) error {
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := loadGroupRPC.Call(context.Background(), client.gridConn(), grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTGroup: group,
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2019-08-02 17:25:00 -04:00
|
|
|
}
|
|
|
|
|
2024-02-13 09:55:54 -05:00
|
|
|
func (client *peerRESTClient) ReloadSiteReplicationConfig(ctx context.Context) error {
|
|
|
|
conn := client.gridConn()
|
|
|
|
if conn == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := reloadSiteReplicationConfigRPC.Call(ctx, conn, grid.NewMSS())
|
2024-02-13 09:55:54 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-29 11:34:30 -04:00
|
|
|
// VerifyBinary - sends verify binary message to remote peers.
|
2024-01-19 21:27:58 -05:00
|
|
|
func (client *peerRESTClient) VerifyBinary(ctx context.Context, u *url.URL, sha256Sum []byte, releaseInfo string, reader io.Reader) error {
|
2019-08-28 18:04:43 -04:00
|
|
|
values := make(url.Values)
|
2024-01-19 21:27:58 -05:00
|
|
|
values.Set(peerRESTURL, u.String())
|
|
|
|
values.Set(peerRESTSha256Sum, hex.EncodeToString(sha256Sum))
|
|
|
|
values.Set(peerRESTReleaseInfo, releaseInfo)
|
|
|
|
|
|
|
|
respBody, err := client.callWithContext(ctx, peerRESTMethodVerifyBinary, values, reader, -1)
|
2022-07-25 20:49:47 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2022-07-25 20:49:47 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CommitBinary - sends commit binary message to remote peers.
|
|
|
|
func (client *peerRESTClient) CommitBinary(ctx context.Context) error {
|
|
|
|
respBody, err := client.callWithContext(ctx, peerRESTMethodCommitBinary, nil, nil, -1)
|
2019-08-28 18:04:43 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2019-08-28 18:04:43 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:27:31 -04:00
|
|
|
// SignalService - sends signal to peer nodes.
|
2024-01-26 11:40:13 -05:00
|
|
|
func (client *peerRESTClient) SignalService(sig serviceSignal, subSys string, dryRun bool) error {
|
2024-02-19 17:54:46 -05:00
|
|
|
values := grid.NewMSS()
|
2019-08-27 14:37:47 -04:00
|
|
|
values.Set(peerRESTSignal, strconv.Itoa(int(sig)))
|
2024-01-19 17:22:36 -05:00
|
|
|
values.Set(peerRESTDryRun, strconv.FormatBool(dryRun))
|
2022-05-16 19:10:51 -04:00
|
|
|
values.Set(peerRESTSubSys, subSys)
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := signalServiceRPC.Call(context.Background(), client.gridConn(), values)
|
|
|
|
return err
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
|
|
|
|
2019-06-25 19:42:24 -04:00
|
|
|
func (client *peerRESTClient) BackgroundHealStatus() (madmin.BgHealState, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getBackgroundHealStatusRPC.Call(context.Background(), client.gridConn(), grid.NewMSS())
|
|
|
|
return resp.ValueOrZero(), err
|
2019-06-25 19:42:24 -04:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
// GetMetacacheListing - get a new or existing metacache.
|
|
|
|
func (client *peerRESTClient) GetMetacacheListing(ctx context.Context, o listPathOptions) (*metacache, error) {
|
2021-12-15 12:19:11 -05:00
|
|
|
if client == nil {
|
|
|
|
resp := localMetacacheMgr.getBucket(ctx, o.Bucket).findCache(o)
|
|
|
|
return &resp, nil
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return getMetacacheListingRPC.Call(ctx, client.gridConn(), &o)
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateMetacacheListing - update an existing metacache it will unconditionally be updated to the new state.
|
|
|
|
func (client *peerRESTClient) UpdateMetacacheListing(ctx context.Context, m metacache) (metacache, error) {
|
2021-12-15 12:19:11 -05:00
|
|
|
if client == nil {
|
|
|
|
return localMetacacheMgr.updateCacheEntry(m)
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := updateMetacacheListingRPC.Call(ctx, client.gridConn(), &m)
|
|
|
|
if err != nil || resp == nil {
|
|
|
|
return metacache{}, err
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return *resp, nil
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
|
|
|
|
2022-01-10 12:07:49 -05:00
|
|
|
func (client *peerRESTClient) ReloadPoolMeta(ctx context.Context) error {
|
2024-02-01 13:47:20 -05:00
|
|
|
conn := client.gridConn()
|
|
|
|
if conn == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := reloadPoolMetaRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2022-10-25 15:36:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (client *peerRESTClient) StopRebalance(ctx context.Context) error {
|
2024-02-01 13:47:20 -05:00
|
|
|
conn := client.gridConn()
|
|
|
|
if conn == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := stopRebalanceRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2022-10-25 15:36:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (client *peerRESTClient) LoadRebalanceMeta(ctx context.Context, startRebalance bool) error {
|
2024-02-01 13:47:20 -05:00
|
|
|
conn := client.gridConn()
|
|
|
|
if conn == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := loadRebalanceMetaRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{
|
2024-02-01 13:47:20 -05:00
|
|
|
peerRESTStartRebalance: strconv.FormatBool(startRebalance),
|
|
|
|
}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2022-01-10 12:07:49 -05:00
|
|
|
}
|
|
|
|
|
2021-04-19 13:30:42 -04:00
|
|
|
func (client *peerRESTClient) LoadTransitionTierConfig(ctx context.Context) error {
|
2024-02-01 13:47:20 -05:00
|
|
|
conn := client.gridConn()
|
|
|
|
if conn == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
_, err := loadTransitionTierConfigRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{}))
|
2024-02-01 22:42:56 -05:00
|
|
|
return err
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:49:02 -05:00
|
|
|
func (client *peerRESTClient) doTrace(ctx context.Context, traceCh chan<- []byte, traceOpts madmin.ServiceTraceOpts) {
|
|
|
|
gridConn := client.gridConn()
|
|
|
|
if gridConn == nil {
|
|
|
|
return
|
|
|
|
}
|
2019-06-27 01:41:12 -04:00
|
|
|
|
2024-01-30 15:49:02 -05:00
|
|
|
payload, err := json.Marshal(traceOpts)
|
2019-06-27 01:41:12 -04:00
|
|
|
if err != nil {
|
2024-04-04 08:04:40 -04:00
|
|
|
bugLogIf(ctx, err)
|
2019-06-27 01:41:12 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-30 15:49:02 -05:00
|
|
|
st, err := gridConn.NewStream(ctx, grid.HandlerTrace, payload)
|
|
|
|
if err != nil {
|
|
|
|
return
|
2019-06-27 01:41:12 -04:00
|
|
|
}
|
2024-01-30 15:49:02 -05:00
|
|
|
st.Results(func(b []byte) error {
|
2019-12-12 13:01:23 -05:00
|
|
|
select {
|
2024-01-30 15:49:02 -05:00
|
|
|
case traceCh <- b:
|
|
|
|
default:
|
|
|
|
// Do not block on slow receivers.
|
|
|
|
// Just recycle the buffer.
|
|
|
|
grid.PutByteBuffer(b)
|
2019-12-12 13:01:23 -05:00
|
|
|
}
|
2024-01-30 15:49:02 -05:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
2019-12-12 13:01:23 -05:00
|
|
|
|
2024-01-30 15:49:02 -05:00
|
|
|
func (client *peerRESTClient) doListen(ctx context.Context, listenCh chan<- []byte, v url.Values) {
|
|
|
|
conn := client.gridConn()
|
|
|
|
if conn == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
st, err := listenRPC.Call(ctx, conn, grid.NewURLValuesWith(v))
|
2019-12-12 13:01:23 -05:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-30 15:49:02 -05:00
|
|
|
st.Results(func(b *grid.Bytes) error {
|
|
|
|
select {
|
|
|
|
case listenCh <- *b:
|
|
|
|
default:
|
|
|
|
// Do not block on slow receivers.
|
|
|
|
b.Recycle()
|
2019-12-12 13:01:23 -05:00
|
|
|
}
|
2024-01-30 15:49:02 -05:00
|
|
|
return nil
|
|
|
|
})
|
2019-12-12 13:01:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Listen - listen on peers.
|
2024-01-30 15:49:02 -05:00
|
|
|
func (client *peerRESTClient) Listen(ctx context.Context, listenCh chan<- []byte, v url.Values) {
|
2019-12-12 13:01:23 -05:00
|
|
|
go func() {
|
|
|
|
for {
|
2024-01-30 15:49:02 -05:00
|
|
|
client.doListen(ctx, listenCh, v)
|
2019-12-12 13:01:23 -05:00
|
|
|
select {
|
2024-01-30 15:49:02 -05:00
|
|
|
case <-ctx.Done():
|
2019-12-12 13:01:23 -05:00
|
|
|
return
|
|
|
|
default:
|
|
|
|
// There was error in the REST request, retry after sometime as probably the peer is down.
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2019-06-27 01:41:12 -04:00
|
|
|
// Trace - send http trace request to peer nodes
|
2024-01-30 15:49:02 -05:00
|
|
|
func (client *peerRESTClient) Trace(ctx context.Context, traceCh chan<- []byte, traceOpts madmin.ServiceTraceOpts) {
|
2019-06-27 01:41:12 -04:00
|
|
|
go func() {
|
2019-06-08 18:54:41 -04:00
|
|
|
for {
|
2024-01-30 15:49:02 -05:00
|
|
|
// Blocks until context is canceled or an error occurs.
|
|
|
|
client.doTrace(ctx, traceCh, traceOpts)
|
2019-06-08 18:54:41 -04:00
|
|
|
select {
|
2024-01-30 15:49:02 -05:00
|
|
|
case <-ctx.Done():
|
2019-06-08 18:54:41 -04:00
|
|
|
return
|
|
|
|
default:
|
2019-06-27 01:41:12 -04:00
|
|
|
// There was error in the REST request, retry after sometime as probably the peer is down.
|
|
|
|
time.Sleep(5 * time.Second)
|
2019-06-08 18:54:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2024-02-19 17:54:46 -05:00
|
|
|
func (client *peerRESTClient) doConsoleLog(ctx context.Context, kind madmin.LogMask, logCh chan<- []byte) {
|
|
|
|
st, err := consoleLogRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{
|
|
|
|
peerRESTLogMask: strconv.Itoa(int(kind)),
|
|
|
|
}))
|
2022-05-06 15:39:58 -04:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
st.Results(func(b *grid.Bytes) error {
|
2022-10-28 13:55:42 -04:00
|
|
|
select {
|
2024-02-19 17:54:46 -05:00
|
|
|
case logCh <- *b:
|
2022-10-28 13:55:42 -04:00
|
|
|
default:
|
2024-02-19 17:54:46 -05:00
|
|
|
consoleLogRPC.PutResponse(b)
|
2022-10-28 13:55:42 -04:00
|
|
|
// Do not block on slow receivers.
|
2022-05-06 15:39:58 -04:00
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return nil
|
|
|
|
})
|
2022-05-06 15:39:58 -04:00
|
|
|
}
|
|
|
|
|
2019-09-03 14:10:48 -04:00
|
|
|
// ConsoleLog - sends request to peer nodes to get console logs
|
2024-02-19 17:54:46 -05:00
|
|
|
func (client *peerRESTClient) ConsoleLog(ctx context.Context, kind madmin.LogMask, logCh chan<- []byte) {
|
2019-09-03 14:10:48 -04:00
|
|
|
go func() {
|
|
|
|
for {
|
2024-02-19 17:54:46 -05:00
|
|
|
client.doConsoleLog(ctx, kind, logCh)
|
2019-09-03 14:10:48 -04:00
|
|
|
select {
|
2024-02-19 17:54:46 -05:00
|
|
|
case <-ctx.Done():
|
2019-09-03 14:10:48 -04:00
|
|
|
return
|
|
|
|
default:
|
2022-05-06 15:39:58 -04:00
|
|
|
// There was error in the REST request, retry after sometime as probably the peer is down.
|
|
|
|
time.Sleep(5 * time.Second)
|
2019-09-03 14:10:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
// newPeerRestClients creates new peer clients.
|
|
|
|
// The two slices will point to the same clients,
|
|
|
|
// but 'all' will contain nil entry for local client.
|
|
|
|
// The 'all' slice will be in the same order across the cluster.
|
2020-12-01 16:50:33 -05:00
|
|
|
func newPeerRestClients(endpoints EndpointServerPools) (remote, all []*peerRESTClient) {
|
2020-10-29 12:25:43 -04:00
|
|
|
if !globalIsDistErasure {
|
|
|
|
// Only useful in distributed setups
|
|
|
|
return nil, nil
|
|
|
|
}
|
2024-01-30 15:49:02 -05:00
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
hosts := endpoints.hostsSorted()
|
|
|
|
remote = make([]*peerRESTClient, 0, len(hosts))
|
|
|
|
all = make([]*peerRESTClient, len(hosts))
|
|
|
|
for i, host := range hosts {
|
|
|
|
if host == nil {
|
2019-11-09 12:27:23 -05:00
|
|
|
continue
|
|
|
|
}
|
2024-01-30 15:49:02 -05:00
|
|
|
all[i] = newPeerRESTClient(host, endpoints.FindGridHostsFromPeer(host))
|
2020-10-28 12:18:35 -04:00
|
|
|
remote = append(remote, all[i])
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
2020-10-28 12:18:35 -04:00
|
|
|
if len(all) != len(remote)+1 {
|
2024-04-04 08:04:40 -04:00
|
|
|
peersLogIf(context.Background(), fmt.Errorf("Expected number of all hosts (%v) to be remote +1 (%v)", len(all), len(remote)), logger.WarningKind)
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
2020-10-28 12:18:35 -04:00
|
|
|
return remote, all
|
2019-03-14 19:27:31 -04:00
|
|
|
}
|
|
|
|
|
2020-10-09 23:36:00 -04:00
|
|
|
// MonitorBandwidth - send http trace request to peer nodes
|
2023-01-19 08:22:16 -05:00
|
|
|
func (client *peerRESTClient) MonitorBandwidth(ctx context.Context, buckets []string) (*bandwidth.BucketBandwidthReport, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
values := grid.NewURLValuesWith(map[string][]string{
|
|
|
|
peerRESTBuckets: buckets,
|
|
|
|
})
|
|
|
|
return getBandwidthRPC.Call(ctx, client.gridConn(), values)
|
2020-10-09 23:36:00 -04:00
|
|
|
}
|
2021-01-18 23:35:38 -05:00
|
|
|
|
2024-03-10 05:15:15 -04:00
|
|
|
func (client *peerRESTClient) GetResourceMetrics(ctx context.Context) (<-chan MetricV2, error) {
|
2024-02-25 03:51:38 -05:00
|
|
|
resp, err := getResourceMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-03-10 05:15:15 -04:00
|
|
|
ch := make(chan MetricV2)
|
|
|
|
go func(ch chan<- MetricV2) {
|
2024-02-25 03:51:38 -05:00
|
|
|
defer close(ch)
|
|
|
|
for _, m := range resp.Value() {
|
|
|
|
if m == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
case ch <- *m:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}(ch)
|
|
|
|
return ch, nil
|
|
|
|
}
|
|
|
|
|
2024-03-10 05:15:15 -04:00
|
|
|
func (client *peerRESTClient) GetPeerMetrics(ctx context.Context) (<-chan MetricV2, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getPeerMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
2021-01-18 23:35:38 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-03-10 05:15:15 -04:00
|
|
|
ch := make(chan MetricV2)
|
2024-02-19 17:54:46 -05:00
|
|
|
go func() {
|
|
|
|
defer close(ch)
|
|
|
|
for _, m := range resp.Value() {
|
|
|
|
if m == nil {
|
|
|
|
continue
|
2021-01-18 23:35:38 -05:00
|
|
|
}
|
2023-02-08 12:11:16 -05:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
2024-02-19 17:54:46 -05:00
|
|
|
case ch <- *m:
|
2023-02-08 12:11:16 -05:00
|
|
|
}
|
2021-01-18 23:35:38 -05:00
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
}()
|
2021-01-18 23:35:38 -05:00
|
|
|
return ch, nil
|
|
|
|
}
|
2021-07-27 15:55:56 -04:00
|
|
|
|
2024-03-10 05:15:15 -04:00
|
|
|
func (client *peerRESTClient) GetPeerBucketMetrics(ctx context.Context) (<-chan MetricV2, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getPeerBucketMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
2023-07-19 01:25:12 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-03-10 05:15:15 -04:00
|
|
|
ch := make(chan MetricV2)
|
2024-02-19 17:54:46 -05:00
|
|
|
go func() {
|
|
|
|
defer close(ch)
|
|
|
|
for _, m := range resp.Value() {
|
|
|
|
if m == nil {
|
|
|
|
continue
|
2023-07-19 01:25:12 -04:00
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
2024-02-19 17:54:46 -05:00
|
|
|
case ch <- *m:
|
2023-07-19 01:25:12 -04:00
|
|
|
}
|
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
}()
|
2023-07-19 01:25:12 -04:00
|
|
|
return ch, nil
|
|
|
|
}
|
|
|
|
|
2022-07-12 13:12:47 -04:00
|
|
|
func (client *peerRESTClient) SpeedTest(ctx context.Context, opts speedTestOpts) (SpeedTestResult, error) {
|
2021-07-27 15:55:56 -04:00
|
|
|
values := make(url.Values)
|
2022-07-12 13:12:47 -04:00
|
|
|
values.Set(peerRESTSize, strconv.Itoa(opts.objectSize))
|
|
|
|
values.Set(peerRESTConcurrent, strconv.Itoa(opts.concurrency))
|
|
|
|
values.Set(peerRESTDuration, opts.duration.String())
|
|
|
|
values.Set(peerRESTStorageClass, opts.storageClass)
|
|
|
|
values.Set(peerRESTBucket, opts.bucketName)
|
2023-12-30 02:56:50 -05:00
|
|
|
values.Set(peerRESTEnableSha256, strconv.FormatBool(opts.enableSha256))
|
2021-07-27 15:55:56 -04:00
|
|
|
|
2022-07-12 13:12:47 -04:00
|
|
|
respBody, err := client.callWithContext(context.Background(), peerRESTMethodSpeedTest, values, nil, -1)
|
2021-07-27 15:55:56 -04:00
|
|
|
if err != nil {
|
2022-07-12 13:12:47 -04:00
|
|
|
return SpeedTestResult{}, err
|
2021-07-27 15:55:56 -04:00
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2021-08-31 17:08:23 -04:00
|
|
|
waitReader, err := waitForHTTPResponse(respBody)
|
|
|
|
if err != nil {
|
2022-07-12 13:12:47 -04:00
|
|
|
return SpeedTestResult{}, err
|
2021-08-31 17:08:23 -04:00
|
|
|
}
|
2021-07-27 15:55:56 -04:00
|
|
|
|
2022-07-12 13:12:47 -04:00
|
|
|
var result SpeedTestResult
|
2021-08-31 17:08:23 -04:00
|
|
|
err = gob.NewDecoder(waitReader).Decode(&result)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
if result.Error != "" {
|
|
|
|
return result, errors.New(result.Error)
|
|
|
|
}
|
|
|
|
return result, nil
|
2021-07-27 15:55:56 -04:00
|
|
|
}
|
2021-10-06 19:36:31 -04:00
|
|
|
|
2022-02-02 01:38:05 -05:00
|
|
|
func (client *peerRESTClient) DriveSpeedTest(ctx context.Context, opts madmin.DriveSpeedTestOpts) (madmin.DriveSpeedTestResult, error) {
|
|
|
|
queryVals := make(url.Values)
|
|
|
|
if opts.Serial {
|
|
|
|
queryVals.Set("serial", "true")
|
|
|
|
}
|
|
|
|
queryVals.Set("blocksize", strconv.FormatUint(opts.BlockSize, 10))
|
|
|
|
queryVals.Set("filesize", strconv.FormatUint(opts.FileSize, 10))
|
|
|
|
|
|
|
|
respBody, err := client.callWithContext(ctx, peerRESTMethodDriveSpeedTest, queryVals, nil, -1)
|
|
|
|
if err != nil {
|
|
|
|
return madmin.DriveSpeedTestResult{}, err
|
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2022-02-02 01:38:05 -05:00
|
|
|
waitReader, err := waitForHTTPResponse(respBody)
|
|
|
|
if err != nil {
|
|
|
|
return madmin.DriveSpeedTestResult{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var result madmin.DriveSpeedTestResult
|
|
|
|
err = gob.NewDecoder(waitReader).Decode(&result)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
if result.Error != "" {
|
|
|
|
return result, errors.New(result.Error)
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
2022-01-26 17:33:10 -05:00
|
|
|
|
2022-04-13 17:21:55 -04:00
|
|
|
func (client *peerRESTClient) GetLastDayTierStats(ctx context.Context) (DailyAllTierStats, error) {
|
2024-02-19 17:54:46 -05:00
|
|
|
resp, err := getLastDayTierStatsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
|
|
|
|
if err != nil || resp == nil {
|
2022-04-13 17:21:55 -04:00
|
|
|
return DailyAllTierStats{}, err
|
2022-01-26 17:33:10 -05:00
|
|
|
}
|
2024-02-19 17:54:46 -05:00
|
|
|
return *resp, nil
|
2022-01-26 17:33:10 -05:00
|
|
|
}
|
2022-03-08 12:54:38 -05:00
|
|
|
|
|
|
|
// DevNull - Used by netperf to pump data to peer
|
|
|
|
func (client *peerRESTClient) DevNull(ctx context.Context, r io.Reader) error {
|
|
|
|
respBody, err := client.callWithContext(ctx, peerRESTMethodDevNull, nil, r, -1)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2022-03-08 12:54:38 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Netperf - To initiate netperf on peer
|
|
|
|
func (client *peerRESTClient) Netperf(ctx context.Context, duration time.Duration) (madmin.NetperfNodeResult, error) {
|
|
|
|
var result madmin.NetperfNodeResult
|
|
|
|
values := make(url.Values)
|
|
|
|
values.Set(peerRESTDuration, duration.String())
|
|
|
|
respBody, err := client.callWithContext(context.Background(), peerRESTMethodNetperf, values, nil, -1)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
2022-12-05 14:18:50 -05:00
|
|
|
defer xhttp.DrainBody(respBody)
|
2022-03-08 12:54:38 -05:00
|
|
|
err = gob.NewDecoder(respBody).Decode(&result)
|
|
|
|
return result, err
|
|
|
|
}
|
2023-07-13 02:51:33 -04:00
|
|
|
|
|
|
|
// GetReplicationMRF - get replication MRF for bucket
|
|
|
|
func (client *peerRESTClient) GetReplicationMRF(ctx context.Context, bucket string) (chan madmin.ReplicationMRF, error) {
|
|
|
|
values := make(url.Values)
|
|
|
|
values.Set(peerRESTBucket, bucket)
|
|
|
|
|
|
|
|
respBody, err := client.callWithContext(ctx, peerRESTMethodGetReplicationMRF, values, nil, -1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
dec := gob.NewDecoder(respBody)
|
|
|
|
ch := make(chan madmin.ReplicationMRF)
|
|
|
|
go func(ch chan madmin.ReplicationMRF) {
|
|
|
|
defer func() {
|
|
|
|
xhttp.DrainBody(respBody)
|
2024-01-30 15:49:02 -05:00
|
|
|
close(ch)
|
2023-07-13 02:51:33 -04:00
|
|
|
}()
|
|
|
|
for {
|
|
|
|
var entry madmin.ReplicationMRF
|
|
|
|
if err := dec.Decode(&entry); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
case ch <- entry:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}(ch)
|
|
|
|
return ch, nil
|
|
|
|
}
|