Skip to content

Commit

Permalink
[API change] reload (updated) backend creds
Browse files Browse the repository at this point in the history
* add new admin API
* part one

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Dec 20, 2024
1 parent 83c2ae8 commit 3661cee
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 6 deletions.
27 changes: 27 additions & 0 deletions ais/prxclu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions ais/tgtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 */) {
Expand Down
2 changes: 2 additions & 0 deletions api/apc/actmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const (

ActRotateLogs = "rotate-logs"

ActReloadBackendCreds = "reload-creds"

ActShutdownCluster = "shutdown" // see also: ActShutdownNode

// multi-object (via `ListRange`)
Expand Down
4 changes: 4 additions & 0 deletions api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions cmd/cli/cli/cluster_hdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ var (
Action: resetStatsHandler,
BashComplete: suggestAllNodes,
},
{
Name: cmdReloadCreds,
Usage: "reload (updated) backend credentials",
ArgsUsage: "[PROVIDER]",
Action: reloadCredsHandler,
BashComplete: suggestProvider,
},
},
}
)
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions cmd/cli/cli/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/cli/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const (
cmdDetach = "detach"
cmdResetStats = "reset-stats"

cmdReloadCreds = "reload-backend-creds"

cmdDownloadLogs = "download-logs"
cmdViewLogs = "view-logs" // etl

Expand Down
8 changes: 5 additions & 3 deletions cmd/cli/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 3661cee

Please sign in to comment.