17
17
package cmd
18
18
19
19
import (
20
+ "fmt"
20
21
"path/filepath"
21
22
"strings"
23
+ "time"
22
24
23
25
"github.com/fatih/color"
24
26
"github.com/minio/cli"
@@ -133,6 +135,30 @@ func (s stopHealMessage) JSON() string {
133
135
return string (stopHealJSONBytes )
134
136
}
135
137
138
+ // backgroundHealStatusMessage is container for stop heal success and failure messages.
139
+ type backgroundHealStatusMessage struct {
140
+ Status string `json:"status"`
141
+ HealInfo madmin.BgHealState
142
+ }
143
+
144
+ // String colorized to show background heal status message.
145
+ func (s backgroundHealStatusMessage ) String () string {
146
+ healPrettyMsg := console .Colorize ("HealBackgroundTitle" , "Background healing status:\n " )
147
+ healPrettyMsg += fmt .Sprintf (" Total items scanned: %s\n " ,
148
+ console .Colorize ("HealBackground" , s .HealInfo .ScannedItemsCount ))
149
+ healPrettyMsg += fmt .Sprintf (" Last background heal check: %s\n " ,
150
+ console .Colorize ("HealBackground" , timeDurationToHumanizedDuration (time .Since (s .HealInfo .LastHealActivity )).String ()+ " ago" ))
151
+ return healPrettyMsg
152
+ }
153
+
154
+ // JSON jsonified stop heal message.
155
+ func (s backgroundHealStatusMessage ) JSON () string {
156
+ healJSONBytes , e := json .MarshalIndent (s , "" , " " )
157
+ fatalIf (probe .NewError (e ), "Unable to marshal into JSON." )
158
+
159
+ return string (healJSONBytes )
160
+ }
161
+
136
162
func transformScanArg (scanArg string ) madmin.HealScanMode {
137
163
switch scanArg {
138
164
case "deep" :
@@ -152,6 +178,8 @@ func mainAdminHeal(ctx *cli.Context) error {
152
178
aliasedURL := args .Get (0 )
153
179
154
180
console .SetColor ("Heal" , color .New (color .FgGreen , color .Bold ))
181
+ console .SetColor ("HealBackgroundTitle" , color .New (color .FgGreen , color .Bold ))
182
+ console .SetColor ("HealBackground" , color .New (color .Bold ))
155
183
console .SetColor ("HealUpdateUI" , color .New (color .FgYellow , color .Bold ))
156
184
console .SetColor ("HealStopped" , color .New (color .FgGreen , color .Bold ))
157
185
@@ -167,6 +195,15 @@ func mainAdminHeal(ctx *cli.Context) error {
167
195
splits := splitStr (aliasedURL , "/" , 3 )
168
196
bucket , prefix := splits [1 ], splits [2 ]
169
197
198
+ // Return the background heal status when the user
199
+ // doesn't pass a bucket or --recursive flag.
200
+ if bucket == "" && ! ctx .Bool ("recursive" ) {
201
+ bgHealStatus , berr := client .BackgroundHealStatus ()
202
+ fatalIf (probe .NewError (berr ), "Failed to get the status of the background heal." )
203
+ printMsg (backgroundHealStatusMessage {Status : "success" , HealInfo : bgHealStatus })
204
+ return nil
205
+ }
206
+
170
207
opts := madmin.HealOpts {
171
208
ScanMode : transformScanArg (ctx .String ("scan" )),
172
209
Remove : ctx .Bool ("remove" ),
@@ -178,13 +215,13 @@ func mainAdminHeal(ctx *cli.Context) error {
178
215
forceStop := ctx .Bool ("force-stop" )
179
216
if forceStop {
180
217
_ , _ , herr := client .Heal (bucket , prefix , opts , "" , forceStart , forceStop )
181
- errorIf (probe .NewError (herr ), "Failed to stop heal sequence." )
218
+ fatalIf (probe .NewError (herr ), "Failed to stop heal sequence." )
182
219
printMsg (stopHealMessage {Status : "success" , Alias : aliasedURL })
183
220
return nil
184
221
}
185
222
186
223
healStart , _ , herr := client .Heal (bucket , prefix , opts , "" , forceStart , false )
187
- errorIf (probe .NewError (herr ), "Failed to start heal sequence." )
224
+ fatalIf (probe .NewError (herr ), "Failed to start heal sequence." )
188
225
189
226
ui := uiData {
190
227
Bucket : bucket ,
@@ -203,9 +240,9 @@ func mainAdminHeal(ctx *cli.Context) error {
203
240
if res .FailureDetail != "" {
204
241
data , _ := json .MarshalIndent (res , "" , " " )
205
242
traceStr := string (data )
206
- errorIf (probe .NewError (e ).Trace (aliasedURL , traceStr ), "Unable to display heal status." )
243
+ fatalIf (probe .NewError (e ).Trace (aliasedURL , traceStr ), "Unable to display heal status." )
207
244
} else {
208
- errorIf (probe .NewError (e ).Trace (aliasedURL ), "Unable to display heal status." )
245
+ fatalIf (probe .NewError (e ).Trace (aliasedURL ), "Unable to display heal status." )
209
246
}
210
247
}
211
248
return nil
0 commit comments