From 3661cee7b7e150c7ae6b7d4d61c4a264f17494a2 Mon Sep 17 00:00:00 2001 From: Alex Aizman Date: Thu, 19 Dec 2024 18:29:25 -0500 Subject: [PATCH] [API change] reload (updated) backend creds * add new admin API * part one Signed-off-by: Alex Aizman --- ais/prxclu.go | 27 +++++++++++++++++++++++++++ ais/tgtcp.go | 2 ++ api/apc/actmsg.go | 2 ++ api/cluster.go | 4 ++++ cmd/cli/cli/cluster_hdlr.go | 15 +++++++++++++++ cmd/cli/cli/completions.go | 7 +++++++ cmd/cli/cli/const.go | 2 ++ cmd/cli/cli/utils.go | 8 +++++--- cmd/cli/go.mod | 2 +- cmd/cli/go.sum | 4 ++-- 10 files changed, 67 insertions(+), 6 deletions(-) diff --git a/ais/prxclu.go b/ais/prxclu.go index 30398299472..b4f34790348 100644 --- a/ais/prxclu.go +++ b/ais/prxclu.go @@ -1052,6 +1052,9 @@ func (p *proxy) cluputMsg(w http.ResponseWriter, r *http.Request) { case apc.ActXactStop: p.xstop(w, r, msg) + case apc.ActReloadBackendCreds: + p.reloadCreds(w, r, msg) + // internal case apc.ActBumpMetasync: p.msyncForceAll(w, r, msg) @@ -1367,6 +1370,30 @@ func (p *proxy) _checkMaint(xargs *xact.ArgsMsg) error { return nil } +func (p *proxy) reloadCreds(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg) { + args := allocBcArgs() + args.req = cmn.HreqArgs{Method: http.MethodPut, Path: apc.URLPathDae.S, Body: cos.MustMarshal(msg)} + args.to = core.AllNodes + results := p.bcastGroup(args) + freeBcArgs(args) + + tag := "backend creds" + if msg.Name != "" { + tag = msg.Name + " " + tag + } + for _, res := range results { + if res.err == nil { + continue + } + err := res.errorf("node %s failed to reload %s (%q)", res.si, tag, msg) + p.writeErr(w, r, err) + freeBcastRes(results) + return + } + freeBcastRes(results) + nlog.Infoln("reloaded", tag) +} + func (p *proxy) rebalanceCluster(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg) { // note operational priority over config-disabled `errRebalanceDisabled` if err := p.canRebalance(); err != nil && err != errRebalanceDisabled { diff --git a/ais/tgtcp.go b/ais/tgtcp.go index 4650eede1aa..1da554528fc 100644 --- a/ais/tgtcp.go +++ b/ais/tgtcp.go @@ -181,6 +181,8 @@ func (t *target) daeputMsg(w http.ResponseWriter, r *http.Request) { case apc.ActResetStats: errorsOnly := msg.Value.(bool) t.statsT.ResetStats(errorsOnly) + case apc.ActReloadBackendCreds: + nlog.Errorln(">>>>", t.String(), msg.String()) // DEBUG case apc.ActStartMaintenance: if !t.ensureIntraControl(w, r, true /* from primary */) { diff --git a/api/apc/actmsg.go b/api/apc/actmsg.go index 022f1e85214..3d2df03aa40 100644 --- a/api/apc/actmsg.go +++ b/api/apc/actmsg.go @@ -64,6 +64,8 @@ const ( ActRotateLogs = "rotate-logs" + ActReloadBackendCreds = "reload-creds" + ActShutdownCluster = "shutdown" // see also: ActShutdownNode // multi-object (via `ListRange`) diff --git a/api/cluster.go b/api/cluster.go index 57ccaa865d3..e7dc8df3428 100644 --- a/api/cluster.go +++ b/api/cluster.go @@ -299,6 +299,10 @@ func RotateClusterLogs(bp BaseParams) error { return _putCluster(bp, apc.ActMsg{Action: apc.ActRotateLogs}) } +func ReloadBackendCreds(bp BaseParams, provider string) error { + return _putCluster(bp, apc.ActMsg{Action: apc.ActReloadBackendCreds, Name: provider}) +} + func _putCluster(bp BaseParams, msg apc.ActMsg) error { bp.Method = http.MethodPut reqParams := AllocRp() diff --git a/cmd/cli/cli/cluster_hdlr.go b/cmd/cli/cli/cluster_hdlr.go index 89c987ae423..e5d09c1faeb 100644 --- a/cmd/cli/cli/cluster_hdlr.go +++ b/cmd/cli/cli/cluster_hdlr.go @@ -220,6 +220,13 @@ var ( Action: resetStatsHandler, BashComplete: suggestAllNodes, }, + { + Name: cmdReloadCreds, + Usage: "reload (updated) backend credentials", + ArgsUsage: "[PROVIDER]", + Action: reloadCredsHandler, + BashComplete: suggestProvider, + }, }, } ) @@ -665,6 +672,14 @@ func resetStatsHandler(c *cli.Context) error { return nil } +func reloadCredsHandler(c *cli.Context) error { + p := c.Args().Get(0) + if p == scopeAll { + p = "" + } + return api.ReloadBackendCreds(apiBP, p) +} + func downloadAllLogs(c *cli.Context) error { sev, err := parseLogSev(c) if err != nil { diff --git a/cmd/cli/cli/completions.go b/cmd/cli/cli/completions.go index 2886b6035b3..22c24934563 100644 --- a/cmd/cli/cli/completions.go +++ b/cmd/cli/cli/completions.go @@ -423,6 +423,13 @@ func (opts *bcmplop) buckets(c *cli.Context) { printNotUsedBuckets(c, buckets, opts.separator, opts.multiple) } +func suggestProvider(*cli.Context) { + fmt.Println(fcyan(scopeAll)) + for p := range apc.Providers { + fmt.Println(p) + } +} + func (opts *bcmplop) remoteBuckets(c *cli.Context) { var ( buckets []cmn.Bck diff --git a/cmd/cli/cli/const.go b/cmd/cli/cli/const.go index 2f0e6edf190..e50dc5f8ff3 100644 --- a/cmd/cli/cli/const.go +++ b/cmd/cli/cli/const.go @@ -111,6 +111,8 @@ const ( cmdDetach = "detach" cmdResetStats = "reset-stats" + cmdReloadCreds = "reload-backend-creds" + cmdDownloadLogs = "download-logs" cmdViewLogs = "view-logs" // etl diff --git a/cmd/cli/cli/utils.go b/cmd/cli/cli/utils.go index e9a4ae3571e..452cdca1522 100644 --- a/cmd/cli/cli/utils.go +++ b/cmd/cli/cli/utils.go @@ -707,12 +707,14 @@ func flattenBackends(backends []string) (flat nvpairList) { for _, b := range backends { nv := nvpair{Name: b} switch b { - case "aws": + case apc.AWS: nv.Value = "Amazon S3" - case "gcp": + case apc.GCP: nv.Value = "Google Cloud Storage" - case "azure": + case apc.Azure: nv.Value = "Azure Blob Storage" + case apc.OCI: + nv.Value = "Oracle Cloud Infrastructure (OCI) Object Storage" } flat = append(flat, nv) } diff --git a/cmd/cli/go.mod b/cmd/cli/go.mod index cd218c84ffe..9908f846186 100644 --- a/cmd/cli/go.mod +++ b/cmd/cli/go.mod @@ -3,7 +3,7 @@ module github.com/NVIDIA/aistore/cmd/cli go 1.23.2 require ( - github.com/NVIDIA/aistore v1.3.26-0.20241217181623-9125ee814733 + github.com/NVIDIA/aistore v1.3.26-0.20241219235246-dd0e0afe4728 github.com/fatih/color v1.18.0 github.com/json-iterator/go v1.1.12 github.com/onsi/ginkgo/v2 v2.21.0 diff --git a/cmd/cli/go.sum b/cmd/cli/go.sum index 7d4332788ec..1fddc2bb82c 100644 --- a/cmd/cli/go.sum +++ b/cmd/cli/go.sum @@ -1,7 +1,7 @@ code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/NVIDIA/aistore v1.3.26-0.20241217181623-9125ee814733 h1:ma6HIYdL3/kjOQA0s9BaLn6dgadhQk1HOnVsvt0BZk0= -github.com/NVIDIA/aistore v1.3.26-0.20241217181623-9125ee814733/go.mod h1:mi1RwL5UAGzscDUxe8KvfM8CJMDnfAHTGbGw9q2epYg= +github.com/NVIDIA/aistore v1.3.26-0.20241219235246-dd0e0afe4728 h1:cuFXdEYYqY/cDtxc/j91p5sM0Wd3inm+Qh12MzbKeDA= +github.com/NVIDIA/aistore v1.3.26-0.20241219235246-dd0e0afe4728/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw= github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8= github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=