Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global context and adapt context change in admin API #3125

Merged
merged 1 commit into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/admin-config-export.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func mainAdminConfigExport(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

// Call get config API
buf, e := client.GetConfig()
buf, e := client.GetConfig(globalContext)
fatalIf(probe.NewError(e), "Cannot get server config")

// Print
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-config-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func mainAdminConfigGet(ctx *cli.Context) error {

if len(ctx.Args()) == 1 {
// Call get config API
hr, e := client.HelpConfigKV("", "", false)
hr, e := client.HelpConfigKV(globalContext, "", "", false)
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")

// Print
Expand All @@ -109,7 +109,7 @@ func mainAdminConfigGet(ctx *cli.Context) error {
}

// Call get config API
buf, e := client.GetConfigKV(strings.Join(args.Tail(), " "))
buf, e := client.GetConfigKV(globalContext, strings.Join(args.Tail(), " "))
fatalIf(probe.NewError(e), "Cannot get server '%s' config", args.Tail())

// Print
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-config-history.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ func mainAdminConfigHistory(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

if ctx.IsSet("clear") {
fatalIf(probe.NewError(client.ClearConfigHistoryKV("all")), "Cannot clear server configuration.")
fatalIf(probe.NewError(client.ClearConfigHistoryKV(globalContext, "all")), "Cannot clear server configuration.")

// Print
printMsg(configHistoryMessage{})
return nil
}

chEntries, e := client.ListConfigHistoryKV(ctx.Int("count"))
chEntries, e := client.ListConfigHistoryKV(globalContext, ctx.Int("count"))
fatalIf(probe.NewError(e), "Cannot list server history configuration.")

hentries := make([]historyEntry, len(chEntries))
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-config-import.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func mainAdminConfigImport(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

// Call set config API
fatalIf(probe.NewError(client.SetConfig(os.Stdin)), "Cannot set server config")
fatalIf(probe.NewError(client.SetConfig(globalContext, os.Stdin)), "Cannot set server config")

// Print
printMsg(configImportMessage{
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-config-reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func mainAdminConfigReset(ctx *cli.Context) error {

if len(ctx.Args()) == 1 {
// Call get config API
hr, e := client.HelpConfigKV("", "", ctx.IsSet("env"))
hr, e := client.HelpConfigKV(globalContext, "", "", ctx.IsSet("env"))
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")

// Print
Expand All @@ -121,7 +121,7 @@ func mainAdminConfigReset(ctx *cli.Context) error {

// Call reset config API
input := strings.Join(args.Tail(), " ")
fatalIf(probe.NewError(client.DelConfigKV(input)),
fatalIf(probe.NewError(client.DelConfigKV(globalContext, input)),
"Cannot reset '%s' on the server", input)

// Print set config result
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-config-restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func mainAdminConfigRestore(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

// Call get config API
fatalIf(probe.NewError(client.RestoreConfigHistoryKV(args.Get(1))), "Cannot restore server configuration.")
fatalIf(probe.NewError(client.RestoreConfigHistoryKV(globalContext, args.Get(1))), "Cannot restore server configuration.")

// Print
printMsg(configRestoreMessage{
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-config-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func mainAdminConfigSet(ctx *cli.Context) error {

if !strings.Contains(input, madmin.KvSeparator) {
// Call get config API
hr, e := client.HelpConfigKV(args.Get(1), args.Get(2), ctx.IsSet("env"))
hr, e := client.HelpConfigKV(globalContext, args.Get(1), args.Get(2), ctx.IsSet("env"))
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")

// Print
Expand All @@ -119,7 +119,7 @@ func mainAdminConfigSet(ctx *cli.Context) error {
}

// Call set config API
fatalIf(probe.NewError(client.SetConfigKV(input)),
fatalIf(probe.NewError(client.SetConfigKV(globalContext, input)),
"Cannot set '%s' to server", input)

// Print set config result
Expand Down
8 changes: 5 additions & 3 deletions cmd/admin-console.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cmd

import (
"context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -195,11 +196,12 @@ func mainAdminConsole(ctx *cli.Context) error {
fatalIf(err.Trace(aliasedURL), "Cannot initialize admin client.")
return nil
}
doneCh := make(chan struct{})
defer close(doneCh)

ctxt, cancel := context.WithCancel(globalContext)
defer cancel()

// Start listening on all console log activity.
logCh := client.GetLogs(node, limit, logType, doneCh)
logCh := client.GetLogs(ctxt, node, limit, logType)
for logInfo := range logCh {
if logInfo.Err != nil {
fatalIf(probe.NewError(logInfo.Err), "Cannot listen to console logs")
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-group-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func mainAdminGroupAdd(ctx *cli.Context) error {
Members: members,
IsRemove: false,
}
fatalIf(probe.NewError(client.UpdateGroupMembers(gAddRemove)).Trace(args...), "Cannot add new group")
fatalIf(probe.NewError(client.UpdateGroupMembers(globalContext, gAddRemove)).Trace(args...), "Cannot add new group")

printMsg(groupMessage{
op: "add",
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-group-enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func mainAdminGroupEnableDisable(ctx *cli.Context) error {
err1 = errors.New("cannot happen")
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group enable")
}
err1 = client.SetGroupStatus(group, status)
err1 = client.SetGroupStatus(globalContext, group, status)
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group enable")

printMsg(groupMessage{
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-group-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func mainAdminGroupInfo(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

group := args.Get(1)
gd, err1 := client.GetGroupDescription(group)
gd, err1 := client.GetGroupDescription(globalContext, group)
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group info")

printMsg(groupMessage{
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-group-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func mainAdminGroupList(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

gs, err1 := client.ListGroups()
gs, err1 := client.ListGroups(globalContext)
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group list")

printMsg(groupMessage{
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-group-remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func mainAdminGroupRemove(ctx *cli.Context) error {
IsRemove: true,
}

e := client.UpdateGroupMembers(gAddRemove)
e := client.UpdateGroupMembers(globalContext, gAddRemove)
fatalIf(probe.NewError(e).Trace(args...), "Could not perform remove operation")

printMsg(groupMessage{
Expand Down
11 changes: 4 additions & 7 deletions cmd/admin-heal-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"errors"
"fmt"
"math"
"os"
"strings"
"syscall"
"time"

humanize "github.com/dustin/go-humanize"
Expand Down Expand Up @@ -404,16 +402,15 @@ func (ui *uiData) healResumeMsg(aliasedURL string) string {
}

func (ui *uiData) DisplayAndFollowHealStatus(aliasedURL string) (res madmin.HealTaskStatus, err error) {
trapCh := signalTrap(os.Interrupt, syscall.SIGTERM, syscall.SIGKILL)
trapMsg := ui.healResumeMsg(aliasedURL)
quitMsg := ui.healResumeMsg(aliasedURL)

firstIter := true
for {
select {
case <-trapCh:
return res, errors.New(trapMsg)
case <-globalContext.Done():
return res, errors.New(quitMsg)
default:
_, res, err = ui.Client.Heal(ui.Bucket, ui.Prefix, *ui.HealOpts,
_, res, err = ui.Client.Heal(globalContext, ui.Bucket, ui.Prefix, *ui.HealOpts,
ui.ClientToken, ui.ForceStart, false)
if err != nil {
return res, err
Expand Down
6 changes: 3 additions & 3 deletions cmd/admin-heal.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func mainAdminHeal(ctx *cli.Context) error {
// Return the background heal status when the user
// doesn't pass a bucket or --recursive flag.
if bucket == "" && !ctx.Bool("recursive") {
bgHealStatus, berr := client.BackgroundHealStatus()
bgHealStatus, berr := client.BackgroundHealStatus(globalContext)
fatalIf(probe.NewError(berr), "Failed to get the status of the background heal.")
printMsg(backgroundHealStatusMessage{Status: "success", HealInfo: bgHealStatus})
return nil
Expand All @@ -247,13 +247,13 @@ func mainAdminHeal(ctx *cli.Context) error {
forceStart := ctx.Bool("force-start")
forceStop := ctx.Bool("force-stop")
if forceStop {
_, _, herr := client.Heal(bucket, prefix, opts, "", forceStart, forceStop)
_, _, herr := client.Heal(globalContext, bucket, prefix, opts, "", forceStart, forceStop)
fatalIf(probe.NewError(herr), "Failed to stop heal sequence.")
printMsg(stopHealMessage{Status: "success", Alias: aliasedURL})
return nil
}

healStart, _, herr := client.Heal(bucket, prefix, opts, "", forceStart, false)
healStart, _, herr := client.Heal(globalContext, bucket, prefix, opts, "", forceStart, false)
fatalIf(probe.NewError(herr), "Failed to start heal sequence.")

ui := uiData{
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func mainAdminInfo(ctx *cli.Context) error {

var clusterInfo clusterStruct
// Fetch info of all servers (cluster or single server)
admInfo, e := client.ServerInfo()
admInfo, e := client.ServerInfo(globalContext)
if e != nil {
clusterInfo.Status = "error"
clusterInfo.Error = e.Error()
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-kms-key-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func mainAdminKMSKeyStatus(ctx *cli.Context) error {
if len(ctx.Args()) == 2 {
keyID = ctx.Args().Get(1)
}
status, e := client.GetKeyStatus(keyID)
status, e := client.GetKeyStatus(globalContext, keyID)
fatalIf(probe.NewError(e), "Failed to get status information")

printMsg(kmsKeyStatusMsg(*status))
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-policy-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func mainAdminPolicyAdd(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

fatalIf(probe.NewError(client.AddCannedPolicy(args.Get(1), string(policy))).Trace(args...), "Cannot add new policy")
fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), string(policy))).Trace(args...), "Cannot add new policy")

printMsg(userPolicyMessage{
op: "add",
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-policy-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func mainAdminPolicyInfo(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

policies, e := client.ListCannedPolicies()
policies, e := client.ListCannedPolicies(globalContext)
fatalIf(probe.NewError(e).Trace(args...), "Cannot list policy")

if len(policies[policyName]) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-policy-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func mainAdminPolicyList(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

policies, e := client.ListCannedPolicies()
policies, e := client.ListCannedPolicies(globalContext)
fatalIf(probe.NewError(e).Trace(args...), "Cannot list policy")

for k := range policies {
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-policy-remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func mainAdminPolicyRemove(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

fatalIf(probe.NewError(client.RemoveCannedPolicy(args.Get(1))).Trace(args...), "Cannot remove policy")
fatalIf(probe.NewError(client.RemoveCannedPolicy(globalContext, args.Get(1))).Trace(args...), "Cannot remove policy")

printMsg(userPolicyMessage{
op: "remove",
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-policy-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func mainAdminPolicySet(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

e := client.SetPolicy(policyName, userOrGroup, isGroup)
e := client.SetPolicy(globalContext, policyName, userOrGroup, isGroup)

if e == nil {
printMsg(userPolicyMessage{
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-profile-start.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func mainAdminProfileStart(ctx *cli.Context) error {
}

// Start profile
_, cmdErr := client.StartProfiling(madmin.ProfilerType(profilers))
_, cmdErr := client.StartProfiling(globalContext, madmin.ProfilerType(profilers))
fatalIf(probe.NewError(cmdErr), "Unable to start profile.")

console.Infoln("Profile data successfully started.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-profile-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func mainAdminProfileStop(ctx *cli.Context) error {
fatalIf(probe.NewError(e), "Unable to download profile data.")

// Ask for profile data, which will come compressed with zip format
zippedData, adminErr := client.DownloadProfilingData()
zippedData, adminErr := client.DownloadProfilingData(globalContext)
fatalIf(probe.NewError(adminErr), "Unable to download profile data.")

// Copy zip content to target download file
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-service-restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func mainAdminServiceRestart(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

// Restart the specified MinIO server
fatalIf(probe.NewError(client.ServiceRestart()), "Cannot restart the server.")
fatalIf(probe.NewError(client.ServiceRestart(globalContext)), "Cannot restart the server.")

// Success..
printMsg(serviceRestartCommand{Status: "success", ServerURL: aliasedURL})
Expand All @@ -125,7 +125,7 @@ func mainAdminServiceRestart(ctx *cli.Context) error {
time.Sleep(6 * time.Second)

// Fetch the service status of the specified MinIO server
_, e := client.ServerInfo()
_, e := client.ServerInfo(globalContext)

if e != nil {
printMsg(serviceRestartMessage{Status: "failure", Err: e, ServerURL: aliasedURL})
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-service-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func mainAdminServiceStop(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

// Stop the specified MinIO server
fatalIf(probe.NewError(client.ServiceStop()), "Unable to stop the server.")
fatalIf(probe.NewError(client.ServiceStop(globalContext)), "Unable to stop the server.")

// Success..
printMsg(serviceStopMessage{Status: "success", ServerURL: aliasedURL})
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-top-locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func mainAdminTopLocks(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")

// Call top locks API
entries, e := client.TopLocks()
entries, e := client.TopLocks(globalContext)
fatalIf(probe.NewError(e), "Cannot get server locks list.")

console.SetColor("StaleLock", color.New(color.FgRed, color.Bold))
Expand Down
8 changes: 5 additions & 3 deletions cmd/admin-trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"bytes"
"context"
"fmt"
"hash/fnv"
"net/http"
Expand Down Expand Up @@ -117,11 +118,12 @@ func mainAdminTrace(ctx *cli.Context) error {
fatalIf(err.Trace(aliasedURL), "Cannot initialize admin client.")
return nil
}
doneCh := make(chan struct{})
defer close(doneCh)

ctxt, cancel := context.WithCancel(globalContext)
defer cancel()

// Start listening on all trace activity.
traceCh := client.ServiceTrace(all, errfltr, doneCh)
traceCh := client.ServiceTrace(ctxt, all, errfltr)
for traceInfo := range traceCh {
if traceInfo.Err != nil {
fatalIf(probe.NewError(traceInfo.Err), "Cannot listen to http trace")
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func mainAdminServerUpdate(ctx *cli.Context) error {

// Update the specified MinIO server, optionally also
// with the provided update URL.
us, e := client.ServerUpdate(updateURL)
us, e := client.ServerUpdate(globalContext, updateURL)
fatalIf(probe.NewError(e), "Unable to update the server.")

// Success..
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-user-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func mainAdminUserAdd(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

fatalIf(probe.NewError(client.AddUser(accessKey, secretKey)).Trace(args...), "Cannot add new user")
fatalIf(probe.NewError(client.AddUser(globalContext, accessKey, secretKey)).Trace(args...), "Cannot add new user")

printMsg(userMessage{
op: "add",
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-user-disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func mainAdminUserDisable(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

e := client.SetUserStatus(args.Get(1), madmin.AccountDisabled)
e := client.SetUserStatus(globalContext, args.Get(1), madmin.AccountDisabled)
fatalIf(probe.NewError(e).Trace(args...), "Cannot disable user")

printMsg(userMessage{
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-user-enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func mainAdminUserEnable(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

e := client.SetUserStatus(args.Get(1), madmin.AccountEnabled)
e := client.SetUserStatus(globalContext, args.Get(1), madmin.AccountEnabled)
fatalIf(probe.NewError(e).Trace(args...), "Cannot enable user")

printMsg(userMessage{
Expand Down
Loading