Fix heal admin API to honor json/quiet flags correctly (#2370)
Update the madmin updated package as well Fixes #2369 Fixes #2368 Fixes #2367
This commit is contained in:
committed by
Nitish Tiwari
parent
99ee2a5042
commit
55f06077e5
@@ -96,8 +96,6 @@ type uiData struct {
|
||||
ForceStart bool
|
||||
HealOpts *madmin.HealOpts
|
||||
LastItem *hri
|
||||
Quiet bool
|
||||
JSON bool
|
||||
|
||||
// Total time since heal start
|
||||
HealDuration time.Duration
|
||||
@@ -362,8 +360,7 @@ func (ui *uiData) updateUI(s *madmin.HealTaskStatus) (err error) {
|
||||
humanize.Comma(ui.ObjectsHealed), totalObjects,
|
||||
totalSize, totalTime)
|
||||
|
||||
yellow := color.New(color.FgYellow, color.Bold)
|
||||
console.PrintfCustomColor(yellow, " %s", <-ui.CurChan)
|
||||
console.Print(console.Colorize("HealUpdateUI", fmt.Sprintf(" %s", <-ui.CurChan)))
|
||||
console.PrintC(fmt.Sprintf(" %s\n", scannedStr))
|
||||
console.PrintC(fmt.Sprintf(" %s\n", healedStr))
|
||||
|
||||
@@ -397,9 +394,9 @@ func (ui *uiData) UpdateDisplay(s *madmin.HealTaskStatus) (err error) {
|
||||
|
||||
// Update display
|
||||
switch {
|
||||
case ui.JSON:
|
||||
case globalJSON:
|
||||
err = ui.printItemsJSON(s)
|
||||
case ui.Quiet:
|
||||
case globalQuiet:
|
||||
err = ui.printItemsQuietly(s)
|
||||
default:
|
||||
err = ui.updateUI(s)
|
||||
@@ -432,15 +429,15 @@ func (ui *uiData) DisplayAndFollowHealStatus() (err error) {
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
if !ui.JSON && !ui.Quiet {
|
||||
if !globalQuiet && !globalJSON {
|
||||
console.RewindLines(8)
|
||||
}
|
||||
}
|
||||
if ui.JSON {
|
||||
if globalJSON {
|
||||
ui.printStatsJSON(&res)
|
||||
return nil
|
||||
}
|
||||
if ui.Quiet {
|
||||
if globalQuiet {
|
||||
ui.printStatsQuietly(&res)
|
||||
}
|
||||
return nil
|
||||
|
||||
+8
-8
@@ -45,6 +45,7 @@ var adminHealCmd = cli.Command{
|
||||
Name: "heal",
|
||||
Usage: "Start an object heal operation",
|
||||
Action: mainAdminHeal,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminHealFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
@@ -92,6 +93,7 @@ func mainAdminHeal(ctx *cli.Context) error {
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
console.SetColor("Heal", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("HealUpdateUI", color.New(color.FgYellow, color.Bold))
|
||||
|
||||
// Create a new Minio Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
@@ -114,14 +116,12 @@ func mainAdminHeal(ctx *cli.Context) error {
|
||||
errorIf(probe.NewError(herr), "Failed to start heal sequence.")
|
||||
|
||||
ui := uiData{
|
||||
Bucket: bucket,
|
||||
Prefix: prefix,
|
||||
Client: client,
|
||||
ClientToken: healStart.ClientToken,
|
||||
ForceStart: forceStart,
|
||||
HealOpts: &opts,
|
||||
Quiet: ctx.Bool("quiet"),
|
||||
JSON: ctx.Bool("json"),
|
||||
Bucket: bucket,
|
||||
Prefix: prefix,
|
||||
Client: client,
|
||||
ClientToken: healStart.ClientToken,
|
||||
ForceStart: forceStart,
|
||||
HealOpts: &opts,
|
||||
ObjectsByOnlineDrives: make(map[int]int64),
|
||||
HealthCols: make(map[hCol]int64),
|
||||
CurChan: cursorAnimate(),
|
||||
|
||||
@@ -56,6 +56,7 @@ var (
|
||||
globalDebug = false // Debug flag set via command line
|
||||
globalNoColor = false // No Color flag set via command line
|
||||
globalInsecure = false // Insecure flag set via command line
|
||||
|
||||
// WHEN YOU ADD NEXT GLOBAL FLAG, MAKE SURE TO ALSO UPDATE SESSION CODE AND CODE BELOW.
|
||||
)
|
||||
|
||||
|
||||
@@ -64,12 +64,6 @@ var (
|
||||
return
|
||||
}
|
||||
|
||||
// PrintfCustomColor - prints a formatted string in a custom color.
|
||||
PrintfCustomColor = func(c *color.Color, format string, data ...interface{}) {
|
||||
consolePrintf("Print", c, format, data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Fatal print a error message and exit.
|
||||
Fatal = func(data ...interface{}) {
|
||||
consolePrint("Fatal", Theme["Fatal"], data...)
|
||||
|
||||
+15
-17
@@ -1,7 +1,7 @@
|
||||
# Minio Admin Library. [](https://slack.minio.io)
|
||||
The Minio Admin Golang Client SDK provides APIs to manage Minio services.
|
||||
|
||||
This quickstart guide will show you how to install the Minio Admin client SDK, connect to Minio admin service, and provide a walkthrough of a simple file uploader.
|
||||
This quickstart guide will show you how to install the Minio Admin client SDK, connect to Minio admin service, and provide a walkthrough of a simple file uploader.
|
||||
|
||||
This document assumes that you have a working [Golang setup](https://docs.minio.io/docs/how-to-install-golang).
|
||||
|
||||
@@ -42,21 +42,18 @@ func main() {
|
||||
useSSL := true
|
||||
|
||||
// Initialize minio admin client object.
|
||||
madmClnt, err := madmin.New(endpoint, accessKeyID, secretAccessKey, useSSL)
|
||||
madmClnt, err := madmin.New(endpoint, accessKeyID, secretAccessKey, useSSL)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
log.Println("%v", madmClnt) // Minio admin client is now setup
|
||||
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
## Quick Start Example - Service Status.
|
||||
## Quick Start Example - Server Info
|
||||
|
||||
This example program connects to minio server, gets the current disk status.
|
||||
|
||||
We will use the Minio server running at [https://your-minio.example.com:9000](https://your-minio.example.com:9000) in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public.
|
||||
This example program connects to minio server, gets the current disk status and other useful server information.
|
||||
|
||||
#### ServiceStatus.go
|
||||
|
||||
@@ -64,6 +61,8 @@ We will use the Minio server running at [https://your-minio.example.com:9000](ht
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
@@ -81,23 +80,23 @@ func main() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
st, err := madmClnt.ServiceStatus()
|
||||
si, err := mdmClnt.ServerInfo()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Printf("%#v\n", st)
|
||||
|
||||
b, err := json.Marshal(si)
|
||||
fmt.Printf("%s\n", string(b))
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Replace the endpoint and access credentials above according to an actual setup.
|
||||
|
||||
#### Run ServiceStatus
|
||||
|
||||
The sample output below shows the result of executing the above program against a locally hosted server.
|
||||
|
||||
```sh
|
||||
|
||||
go run service-status.go
|
||||
2016/12/20 16:46:01 madmin.ServiceStatusMetadata{Total:177038229504, Free:120365559808, Backend:struct { Type madmin.BackendType; OnlineDisks int; OfflineDisks int; ReadQuorum int; WriteQuorum int }{Type:1, OnlineDisks:0, OfflineDisks:0, StandardSCParity:0, RRSCParity:0}}
|
||||
|
||||
[{"error":"","addr":"localhost:9000","data":{"storage":{"Total":460373336064,"Free":77001187328,"Backend":{"Type":2,"OnlineDisks":4,"OfflineDisks":0,"StandardSCParity":2,"RRSCParity":2}},"network":{"transferred":30599,"received":36370},"http":{"totalHEADs":{"count":0,"avgDuration":"0s"},"successHEADs":{"count":0,"avgDuration":"0s"},"totalGETs":{"count":11,"avgDuration":"0s"},"successGETs":{"count":11,"avgDuration":"0s"},"totalPUTs":{"count":0,"avgDuration":"0s"},"successPUTs":{"count":0,"avgDuration":"0s"},"totalPOSTs":{"count":0,"avgDuration":"0s"},"successPOSTs":{"count":0,"avgDuration":"0s"},"totalDELETEs":{"count":0,"avgDuration":"0s"},"successDELETEs":{"count":0,"avgDuration":"0s"}},"server":{"uptime":596915001694,"version":"2018-01-18T20:33:21Z","commitID":"e2d5a87b2676e3e01f0f4fa7ebd01205364cfb16","region":"us-east-1","sqsARN":null}}},{"error":"","addr":"minio2:9000","data":{"storage":{"Total":460373336064,"Free":77001187328,"Backend":{"Type":2,"OnlineDisks":4,"OfflineDisks":0,"StandardSCParity":2,"RRSCParity":2}},"network":{"transferred":28538,"received":11845},"http":{"totalHEADs":{"count":0,"avgDuration":"0s"},"successHEADs":{"count":0,"avgDuration":"0s"},"totalGETs":{"count":0,"avgDuration":"0s"},"successGETs":{"count":0,"avgDuration":"0s"},"totalPUTs":{"count":0,"avgDuration":"0s"},"successPUTs":{"count":0,"avgDuration":"0s"},"totalPOSTs":{"count":0,"avgDuration":"0s"},"successPOSTs":{"count":0,"avgDuration":"0s"},"totalDELETEs":{"count":0,"avgDuration":"0s"},"successDELETEs":{"count":0,"avgDuration":"0s"}},"server":{"uptime":595852367296,"version":"2018-01-18T20:33:21Z","commitID":"e2d5a87b2676e3e01f0f4fa7ebd01205364cfb16","region":"us-east-1","sqsARN":null}}},{"error":"","addr":"minio3:9000","data":{"storage":{"Total":460373336064,"Free":77001187328,"Backend":{"Type":2,"OnlineDisks":4,"OfflineDisks":0,"StandardSCParity":2,"RRSCParity":2}},"network":{"transferred":27624,"received":11708},"http":{"totalHEADs":{"count":0,"avgDuration":"0s"},"successHEADs":{"count":0,"avgDuration":"0s"},"totalGETs":{"count":0,"avgDuration":"0s"},"successGETs":{"count":0,"avgDuration":"0s"},"totalPUTs":{"count":0,"avgDuration":"0s"},"successPUTs":{"count":0,"avgDuration":"0s"},"totalPOSTs":{"count":0,"avgDuration":"0s"},"successPOSTs":{"count":0,"avgDuration":"0s"},"totalDELETEs":{"count":0,"avgDuration":"0s"},"successDELETEs":{"count":0,"avgDuration":"0s"}},"server":{"uptime":595831126778,"version":"2018-01-18T20:33:21Z","commitID":"e2d5a87b2676e3e01f0f4fa7ebd01205364cfb16","region":"us-east-1","sqsARN":null}}},{"error":"","addr":"minio4:9000","data":{"storage":{"Total":460373336064,"Free":77001187328,"Backend":{"Type":2,"OnlineDisks":4,"OfflineDisks":0,"StandardSCParity":2,"RRSCParity":2}},"network":{"transferred":27740,"received":12116},"http":{"totalHEADs":{"count":0,"avgDuration":"0s"},"successHEADs":{"count":0,"avgDuration":"0s"},"totalGETs":{"count":0,"avgDuration":"0s"},"successGETs":{"count":0,"avgDuration":"0s"},"totalPUTs":{"count":0,"avgDuration":"0s"},"successPUTs":{"count":0,"avgDuration":"0s"},"totalPOSTs":{"count":0,"avgDuration":"0s"},"successPOSTs":{"count":0,"avgDuration":"0s"},"totalDELETEs":{"count":0,"avgDuration":"0s"},"successDELETEs":{"count":0,"avgDuration":"0s"}},"server":{"uptime":595349958375,"version":"2018-01-18T20:33:21Z","commitID":"e2d5a87b2676e3e01f0f4fa7ebd01205364cfb16","region":"us-east-1","sqsARN":null}}}]
|
||||
```
|
||||
|
||||
## API Reference
|
||||
@@ -119,4 +118,3 @@ go run service-status.go
|
||||
## Contribute
|
||||
|
||||
[Contributors Guide](https://github.com/minio/minio/blob/master/CONTRIBUTING.md)
|
||||
|
||||
|
||||
+1
@@ -138,6 +138,7 @@ func (adm *AdminClient) Heal(bucket, prefix string, healOpts HealOpts,
|
||||
var contentBody io.Reader
|
||||
if clientToken != "" {
|
||||
queryVals.Set("clientToken", clientToken)
|
||||
body = []byte{}
|
||||
} else {
|
||||
// Set a body only if clientToken is not given
|
||||
contentBody = bytes.NewReader(body)
|
||||
|
||||
Vendored
+3
-3
@@ -98,10 +98,10 @@
|
||||
"revisionTime": "2017-10-28T03:50:25Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "gWUkcm51sWJmmk64Fai+q7pKDEg=",
|
||||
"checksumSHA1": "n3+/OaoRx2CGB9ltQhSInfuaS4g=",
|
||||
"path": "github.com/minio/minio/pkg/madmin",
|
||||
"revision": "a337ea4d11eb2ae87144a76cdefd6f77ae7303a4",
|
||||
"revisionTime": "2018-01-22T22:54:55Z"
|
||||
"revision": "5cdcc73bd5c3b3461274e009f435f502988a09f0",
|
||||
"revisionTime": "2018-01-25T13:54:00Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "5r3V/rzpVqjJvzE/K5sR2LHEteM=",
|
||||
|
||||
Reference in New Issue
Block a user