2016-10-05 15:48:07 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
humanize "github.com/dustin/go-humanize"
|
|
|
|
"github.com/minio/mc/pkg/console"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Helper to generate integer sequences into a friendlier user consumable format.
|
2016-11-28 15:14:24 -05:00
|
|
|
func formatInts(i int, t int) string {
|
2016-10-05 15:48:07 -04:00
|
|
|
if i < 10 {
|
|
|
|
if t < 10 {
|
|
|
|
return fmt.Sprintf("0%d/0%d", i, t)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("0%d/%d", i, t)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%d/%d", i, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print a given message once.
|
|
|
|
type printOnceFunc func(msg string)
|
|
|
|
|
|
|
|
// Print once is a constructor returning a function printing once.
|
|
|
|
// internally print uses sync.Once to perform exactly one action.
|
|
|
|
func printOnceFn() printOnceFunc {
|
|
|
|
var once sync.Once
|
|
|
|
return func(msg string) {
|
2016-11-11 19:36:07 -05:00
|
|
|
once.Do(func() {
|
2017-03-02 17:21:30 -05:00
|
|
|
console.Println(msg)
|
2016-11-11 19:36:07 -05:00
|
|
|
})
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints custom message when healing is required for XL and Distributed XL backend.
|
2017-04-11 18:44:27 -04:00
|
|
|
func printHealMsg(endpoints EndpointList, storageDisks []StorageAPI, fn printOnceFunc) {
|
2016-11-09 13:50:14 -05:00
|
|
|
msg := getHealMsg(endpoints, storageDisks)
|
2016-10-05 15:48:07 -04:00
|
|
|
fn(msg)
|
|
|
|
}
|
|
|
|
|
2017-01-18 15:24:34 -05:00
|
|
|
// Disks offline and online strings..
|
|
|
|
const (
|
|
|
|
diskOffline = "offline"
|
|
|
|
diskOnline = "online"
|
|
|
|
)
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
// Constructs a formatted heal message, when cluster is found to be in state where it requires healing.
|
|
|
|
// healing is optional, server continues to initialize object layer after printing this message.
|
|
|
|
// it is upto the end user to perform a heal if needed.
|
2017-04-11 18:44:27 -04:00
|
|
|
func getHealMsg(endpoints EndpointList, storageDisks []StorageAPI) string {
|
2017-04-03 17:24:25 -04:00
|
|
|
healFmtCmd := `"mc admin heal myminio"`
|
|
|
|
msg := fmt.Sprintf("New disk(s) were found, format them by running - %s\n",
|
|
|
|
healFmtCmd)
|
2016-10-05 15:48:07 -04:00
|
|
|
disksInfo, _, _ := getDisksInfo(storageDisks)
|
|
|
|
for i, info := range disksInfo {
|
2016-10-17 17:31:33 -04:00
|
|
|
if storageDisks[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
msg += fmt.Sprintf(
|
|
|
|
"\n[%s] %s - %s %s",
|
2016-11-28 15:14:24 -05:00
|
|
|
formatInts(i+1, len(storageDisks)),
|
2016-11-09 13:50:14 -05:00
|
|
|
endpoints[i],
|
2016-10-05 15:48:07 -04:00
|
|
|
humanize.IBytes(uint64(info.Total)),
|
|
|
|
func() string {
|
|
|
|
if info.Total > 0 {
|
2017-01-18 15:24:34 -05:00
|
|
|
return diskOnline
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
2017-01-18 15:24:34 -05:00
|
|
|
return diskOffline
|
2016-10-05 15:48:07 -04:00
|
|
|
}(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints regular message when we have sufficient disks to start the cluster.
|
2017-04-11 18:44:27 -04:00
|
|
|
func printRegularMsg(endpoints EndpointList, storageDisks []StorageAPI, fn printOnceFunc) {
|
2016-11-02 11:51:06 -04:00
|
|
|
msg := getStorageInitMsg("\nInitializing data volume.", endpoints, storageDisks)
|
2016-10-05 15:48:07 -04:00
|
|
|
fn(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructs a formatted regular message when we have sufficient disks to start the cluster.
|
2017-04-11 18:44:27 -04:00
|
|
|
func getStorageInitMsg(titleMsg string, endpoints EndpointList, storageDisks []StorageAPI) string {
|
2016-11-02 11:51:06 -04:00
|
|
|
msg := colorBlue(titleMsg)
|
2016-10-05 15:48:07 -04:00
|
|
|
disksInfo, _, _ := getDisksInfo(storageDisks)
|
|
|
|
for i, info := range disksInfo {
|
2016-10-17 17:31:33 -04:00
|
|
|
if storageDisks[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
msg += fmt.Sprintf(
|
|
|
|
"\n[%s] %s - %s %s",
|
2016-11-28 15:14:24 -05:00
|
|
|
formatInts(i+1, len(storageDisks)),
|
2016-11-02 11:51:06 -04:00
|
|
|
endpoints[i],
|
2016-10-05 15:48:07 -04:00
|
|
|
humanize.IBytes(uint64(info.Total)),
|
|
|
|
func() string {
|
|
|
|
if info.Total > 0 {
|
2017-01-18 15:24:34 -05:00
|
|
|
return diskOnline
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
2017-01-18 15:24:34 -05:00
|
|
|
return diskOffline
|
2016-10-05 15:48:07 -04:00
|
|
|
}(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints initialization message when cluster is being initialized for the first time.
|
2017-04-11 18:44:27 -04:00
|
|
|
func printFormatMsg(endpoints EndpointList, storageDisks []StorageAPI, fn printOnceFunc) {
|
2016-11-02 11:51:06 -04:00
|
|
|
msg := getStorageInitMsg("\nInitializing data volume for the first time.", endpoints, storageDisks)
|
2016-10-05 15:48:07 -04:00
|
|
|
fn(msg)
|
|
|
|
}
|
|
|
|
|
2017-06-17 14:20:12 -04:00
|
|
|
// Combines each disk errors in a newline formatted string.
|
|
|
|
// this is a helper function in printing messages across
|
|
|
|
// all disks.
|
|
|
|
func combineDiskErrs(storageDisks []StorageAPI, sErrs []error) string {
|
|
|
|
var msg string
|
2016-10-07 14:15:55 -04:00
|
|
|
for i, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if sErrs[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
msg += fmt.Sprintf(
|
|
|
|
"\n[%s] %s : %s",
|
2016-11-28 15:14:24 -05:00
|
|
|
formatInts(i+1, len(storageDisks)),
|
2016-10-07 14:15:55 -04:00
|
|
|
storageDisks[i],
|
|
|
|
sErrs[i],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|