diff --git a/cmd/admin-heal-ui.go b/cmd/admin-heal-ui.go
index ed118fdf..b097d3bd 100644
--- a/cmd/admin-heal-ui.go
+++ b/cmd/admin-heal-ui.go
@@ -18,9 +18,12 @@ package cmd
import (
"encoding/json"
+ "errors"
"fmt"
"math"
+ "os"
"strings"
+ "syscall"
"time"
humanize "github.com/dustin/go-humanize"
@@ -393,44 +396,58 @@ func (ui *uiData) UpdateDisplay(s *madmin.HealTaskStatus) (err error) {
return
}
-func (ui *uiData) DisplayAndFollowHealStatus() (res madmin.HealTaskStatus, err error) {
+func (ui *uiData) healResumeMsg(aliasedURL string) string {
+ var flags string
+ if ui.HealOpts.Recursive {
+ flags += "--recursive "
+ }
+ if ui.HealOpts.DryRun {
+ flags += "--dry-run "
+ }
+ return fmt.Sprintf("Healing is backgrounded, to resume watching use `mc admin heal %s %s`", flags, aliasedURL)
+}
+
+func (ui *uiData) DisplayAndFollowHealStatus(aliasedURL string) (res madmin.HealTaskStatus, err error) {
+ trapCh := signalTrap(os.Interrupt, syscall.SIGTERM, syscall.SIGKILL)
+ trapMsg := ui.healResumeMsg(aliasedURL)
+
firstIter := true
for {
- _, res, err = ui.Client.Heal(ui.Bucket, ui.Prefix, *ui.HealOpts,
- ui.ClientToken, ui.ForceStart)
- if err != nil {
- return res, err
- }
-
- if firstIter {
- firstIter = false
- } else {
- if !globalQuiet && !globalJSON {
- console.RewindLines(8)
+ select {
+ case <-trapCh:
+ return res, errors.New(trapMsg)
+ default:
+ _, res, err = ui.Client.Heal(ui.Bucket, ui.Prefix, *ui.HealOpts,
+ ui.ClientToken, ui.ForceStart, false)
+ if err != nil {
+ return res, err
+ }
+ if firstIter {
+ firstIter = false
+ } else {
+ if !globalQuiet && !globalJSON {
+ console.RewindLines(8)
+ }
+ }
+ err = ui.UpdateDisplay(&res)
+ if err != nil {
+ return res, err
}
- }
- err = ui.UpdateDisplay(&res)
- if err != nil {
- return res, err
- }
- if res.Summary == "finished" {
- break
- }
+ if res.Summary == "finished" {
+ if globalJSON {
+ ui.printStatsJSON(&res)
+ } else if globalQuiet {
+ ui.printStatsQuietly(&res)
+ }
+ return res, nil
+ }
- if res.Summary == "stopped" {
- fmt.Println("Heal had an error - ", res.FailureDetail)
- break
- }
+ if res.Summary == "stopped" {
+ return res, fmt.Errorf("Heal had an error - %s", res.FailureDetail)
+ }
- time.Sleep(time.Second)
+ time.Sleep(time.Second)
+ }
}
- if globalJSON {
- ui.printStatsJSON(&res)
- return res, nil
- }
- if globalQuiet {
- ui.printStatsQuietly(&res)
- }
- return res, nil
}
diff --git a/cmd/admin-heal.go b/cmd/admin-heal.go
index 7a15f3a5..4af5b838 100644
--- a/cmd/admin-heal.go
+++ b/cmd/admin-heal.go
@@ -40,6 +40,10 @@ var adminHealFlags = []cli.Flag{
Name: "force-start, f",
Usage: "Force start a new heal sequence",
},
+ cli.BoolFlag{
+ Name: "force-stop, s",
+ Usage: "Force stop a running heal sequence",
+ },
}
var adminHealCmd = cli.Command{
@@ -83,6 +87,25 @@ func checkAdminHealSyntax(ctx *cli.Context) {
}
}
+// stopHealMessage is container for stop heal success and failure messages.
+type stopHealMessage struct {
+ Status string `json:"status"`
+ Alias string `json:"alias"`
+}
+
+// String colorized stop heal message.
+func (s stopHealMessage) String() string {
+ return console.Colorize("HealStopped", "Heal stopped successfully at `"+s.Alias+"`.")
+}
+
+// JSON jsonified stop heal message.
+func (s stopHealMessage) JSON() string {
+ stopHealJSONBytes, e := json.Marshal(s)
+ fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
+
+ return string(stopHealJSONBytes)
+}
+
// mainAdminHeal - the entry function of heal command
func mainAdminHeal(ctx *cli.Context) error {
@@ -95,6 +118,7 @@ func mainAdminHeal(ctx *cli.Context) error {
console.SetColor("Heal", color.New(color.FgGreen, color.Bold))
console.SetColor("HealUpdateUI", color.New(color.FgYellow, color.Bold))
+ console.SetColor("HealStopped", color.New(color.FgGreen, color.Bold))
// Create a new Minio Admin Client
client, err := newAdminClient(aliasedURL)
@@ -112,8 +136,17 @@ func mainAdminHeal(ctx *cli.Context) error {
Recursive: ctx.Bool("recursive"),
DryRun: ctx.Bool("dry-run"),
}
+
forceStart := ctx.Bool("force-start")
- healStart, _, herr := client.Heal(bucket, prefix, opts, "", forceStart)
+ forceStop := ctx.Bool("force-stop")
+ if forceStop {
+ _, _, herr := client.Heal(bucket, prefix, opts, "", forceStart, forceStop)
+ errorIf(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)
errorIf(probe.NewError(herr), "Failed to start heal sequence.")
ui := uiData{
@@ -127,11 +160,16 @@ func mainAdminHeal(ctx *cli.Context) error {
HealthCols: make(map[col]int64),
CurChan: cursorAnimate(),
}
- res, e := ui.DisplayAndFollowHealStatus()
+
+ res, e := ui.DisplayAndFollowHealStatus(aliasedURL)
if e != nil {
- data, _ := json.Marshal(res)
- traceStr := string(data)
- errorIf(probe.NewError(e).Trace(traceStr), "Unable to display heal status.")
+ if res.FailureDetail != "" {
+ data, _ := json.Marshal(res)
+ traceStr := string(data)
+ errorIf(probe.NewError(e).Trace(aliasedURL, traceStr), "Unable to display heal status.")
+ } else {
+ errorIf(probe.NewError(e).Trace(aliasedURL), "Unable to display heal status.")
+ }
}
- return e
+ return nil
}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/API.md b/vendor/github.com/minio/minio/pkg/madmin/API.md
index 23aa8e98..04e8642f 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/API.md
+++ b/vendor/github.com/minio/minio/pkg/madmin/API.md
@@ -36,12 +36,12 @@ func main() {
```
-| Service operations | Info operations | Healing operations | Config operations | Misc |
-|:----------------------------|:----------------------------|:--------------------------------------|:--------------------------|:------------------------------------|
-| [`ServiceStatus`](#ServiceStatus) | [`ServerInfo`](#ServerInfo) | [`Heal`](#Heal) | [`GetConfig`](#GetConfig) | [`SetCredentials`](#SetCredentials) |
-| [`ServiceSendAction`](#ServiceSendAction) | | | [`SetConfig`](#SetConfig) | [`StartProfiling`](#StartProfiling) |
-| | | | [`GetConfigKeys`](#GetConfigKeys) | [`DownloadProfilingData`](#DownloadProfilingData) |
-| | | | [`SetConfigKeys`](#SetConfigKeys) | |
+| Service operations | Info operations | Healing operations | Config operations | IAM operations | Misc |
+|:----------------------------|:----------------------------|:--------------------------------------|:--------------------------|:------------------------------------|:------------------------------------|
+| [`ServiceStatus`](#ServiceStatus) | [`ServerInfo`](#ServerInfo) | [`Heal`](#Heal) | [`GetConfig`](#GetConfig) | [`AddUser`](#AddUser) | [`SetAdminCredentials`](#SetAdminCredentials) |
+| [`ServiceSendAction`](#ServiceSendAction) | | | [`SetConfig`](#SetConfig) | [`SetUserPolicy`](#SetUserPolicy) | [`StartProfiling`](#StartProfiling) |
+| | | | [`GetConfigKeys`](#GetConfigKeys) | [`ListUsers`](#ListUsers) | [`DownloadProfilingData`](#DownloadProfilingData) |
+| | | | [`SetConfigKeys`](#SetConfigKeys) | [`AddCannedPolicy`](#AddCannedPolicy) | |
## 1. Constructor
@@ -208,7 +208,7 @@ Fetches information for all cluster nodes, such as server properties, storage in
## 6. Heal operations
-### Heal(bucket, prefix string, healOpts HealOpts, clientToken string, forceStart bool) (start HealStartSuccess, status HealTaskStatus, err error)
+### Heal(bucket, prefix string, healOpts HealOpts, clientToken string, forceStart bool, forceStop bool) (start HealStartSuccess, status HealTaskStatus, err error)
Start a heal sequence that scans data under given (possible empty)
`bucket` and `prefix`. The `recursive` bool turns on recursive
@@ -232,7 +232,8 @@ __Example__
DryRun: false,
}
forceStart := false
- healPath, err := madmClnt.Heal("", "", opts, "", forceStart)
+ forceStop := false
+ healPath, err := madmClnt.Heal("", "", opts, "", forceStart, forceStop)
if err != nil {
log.Fatalln(err)
}
@@ -273,7 +274,7 @@ __Example__
### GetConfig() ([]byte, error)
-Get config.json of a minio setup.
+Get current `config.json` of a Minio server.
__Example__
@@ -295,37 +296,17 @@ __Example__
-### SetConfig(config io.Reader) (SetConfigResult, error)
-Set config.json of a minio setup and restart setup for configuration
-change to take effect.
-
-
-| Param | Type | Description |
-|---|---|---|
-|`st.Status` | _bool_ | true if set-config succeeded, false otherwise. |
-|`st.NodeSummary.Name` | _string_ | Network address of the node. |
-|`st.NodeSummary.ErrSet` | _bool_ | Bool representation indicating if an error is encountered with the node.|
-|`st.NodeSummary.ErrMsg` | _string_ | String representation of the error (if any) on the node.|
-
+### SetConfig(config io.Reader) error
+Set a new `config.json` for a Minio server.
__Example__
``` go
config := bytes.NewReader([]byte(`config.json contents go here`))
- result, err := madmClnt.SetConfig(config)
- if err != nil {
+ if err := madmClnt.SetConfig(config); err != nil {
log.Fatalf("failed due to: %v", err)
}
-
- var buf bytes.Buffer
- enc := json.NewEncoder(&buf)
- enc.SetEscapeHTML(false)
- enc.SetIndent("", "\t")
- err = enc.Encode(result)
- if err != nil {
- log.Fatalln(err)
- }
- log.Println("SetConfig: ", string(buf.Bytes()))
+ log.Println("SetConfig was successful")
```
@@ -367,18 +348,72 @@ __Example__
log.Println("New configuration successfully set")
```
+## 8. IAM operations
+
+### AddCannedPolicy(policyName string, policy string) error
+Create a new canned policy on Minio server.
-## 8. Misc operations
+__Example__
-
-### SetCredentials() error
+```
+ policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::my-bucketname/*"],"Sid": ""}]}`
+
+ if err = madmClnt.AddCannedPolicy("get-only", policy); err != nil {
+ log.Fatalln(err)
+ }
+```
+
+
+### AddUser(user string, secret string) error
+Add a new user on a Minio server.
+
+__Example__
+
+``` go
+ if err = madmClnt.AddUser("newuser", "newstrongpassword"); err != nil {
+ log.Fatalln(err)
+ }
+```
+
+
+### SetUserPolicy(user string, policyName string) error
+Enable a canned policy `get-only` for a given user on Minio server.
+
+__Example__
+
+``` go
+ if err = madmClnt.SetUserPolicy("newuser", "get-only"); err != nil {
+ log.Fatalln(err)
+ }
+```
+
+
+### ListUsers() (map[string]UserInfo, error)
+Lists all users on Minio server.
+
+__Example__
+
+``` go
+ users, err := madmClnt.ListUsers();
+ if err != nil {
+ log.Fatalln(err)
+ }
+ for k, v := range users {
+ fmt.Printf("User %s Status %s\n", k, v.Status)
+ }
+```
+
+## 9. Misc operations
+
+
+### SetAdminCredentials() error
Set new credentials of a Minio setup.
__Example__
``` go
- err = madmClnt.SetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
+ err = madmClnt.SetAdminCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
if err != nil {
log.Fatalln(err)
}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/README.md b/vendor/github.com/minio/minio/pkg/madmin/README.md
index bc25a17d..b2b7dffd 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/README.md
+++ b/vendor/github.com/minio/minio/pkg/madmin/README.md
@@ -113,7 +113,7 @@ The sample output below shows the result of executing the above program against
* [service-status.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-status.go)
* [service-restart.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-restart.go)
-* [service-set-credentials.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-set-credentials.go)
+* [set-credentials.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/set-credentials.go)
## Contribute
diff --git a/vendor/github.com/minio/minio/pkg/madmin/heal-commands.go b/vendor/github.com/minio/minio/pkg/madmin/heal-commands.go
index 3ec5f27a..da18c17f 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/heal-commands.go
+++ b/vendor/github.com/minio/minio/pkg/madmin/heal-commands.go
@@ -40,6 +40,10 @@ type HealStartSuccess struct {
StartTime time.Time `json:"startTime"`
}
+// HealStopSuccess - holds information about a successfully stopped
+// heal operation.
+type HealStopSuccess HealStartSuccess
+
// HealTaskStatus - status struct for a heal task
type HealTaskStatus struct {
Summary string `json:"summary"`
@@ -176,10 +180,17 @@ func (hri *HealResultItem) GetOnlineCounts() (b, a int) {
}
// Heal - API endpoint to start heal and to fetch status
+// forceStart and forceStop are mutually exclusive, you can either
+// set one of them to 'true'. If both are set 'forceStart' will be
+// honored.
func (adm *AdminClient) Heal(bucket, prefix string, healOpts HealOpts,
- clientToken string, forceStart bool) (
+ clientToken string, forceStart, forceStop bool) (
healStart HealStartSuccess, healTaskStatus HealTaskStatus, err error) {
+ if forceStart && forceStop {
+ return healStart, healTaskStatus, ErrInvalidArgument("forceStart and forceStop set to true is not allowed")
+ }
+
body, err := json.Marshal(healOpts)
if err != nil {
return healStart, healTaskStatus, err
@@ -196,8 +207,12 @@ func (adm *AdminClient) Heal(bucket, prefix string, healOpts HealOpts,
queryVals.Set("clientToken", clientToken)
body = []byte{}
}
+
+ // Anyone can be set, either force start or forceStop.
if forceStart {
queryVals.Set("forceStart", "true")
+ } else if forceStop {
+ queryVals.Set("forceStop", "true")
}
resp, err := adm.executeMethod("POST", requestData{
@@ -221,9 +236,24 @@ func (adm *AdminClient) Heal(bucket, prefix string, healOpts HealOpts,
// Was it a status request?
if clientToken == "" {
+ // As a special operation forceStop would return a
+ // similar struct as healStart will have the
+ // heal sequence information about the heal which
+ // was stopped.
err = json.Unmarshal(respBytes, &healStart)
} else {
err = json.Unmarshal(respBytes, &healTaskStatus)
}
- return healStart, healTaskStatus, err
+ if err != nil {
+ // May be the server responded with error after success
+ // message, handle it separately here.
+ var errResp ErrorResponse
+ err = json.Unmarshal(respBytes, &errResp)
+ if err != nil {
+ // Unknown structure return error anyways.
+ return healStart, healTaskStatus, err
+ }
+ return healStart, healTaskStatus, errResp
+ }
+ return healStart, healTaskStatus, nil
}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index 3598bca3..c44f1a7b 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -134,10 +134,10 @@
"revisionTime": "2018-09-25T09:12:15Z"
},
{
- "checksumSHA1": "/OdvNthJAc6DQQ7waRjvzAc7Q3c=",
+ "checksumSHA1": "g8YlJVY8CHJy+N4pAF1522n/Yr8=",
"path": "github.com/minio/minio/pkg/madmin",
- "revision": "aebfceeafb410452d1c03edfa69b7bc5509cc1bc",
- "revisionTime": "2018-09-29T08:17:01Z"
+ "revision": "86f6ca3cea734ba0bd320e8279e90c6025460b0f",
+ "revisionTime": "2018-10-27T02:40:32Z"
},
{
"checksumSHA1": "flg07CqTxM9togozKRQiJugao4s=",