2016-10-05 21:48:07 +02: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"
|
2016-11-09 19:50:14 +01:00
|
|
|
"net"
|
2016-11-02 16:51:06 +01:00
|
|
|
"net/url"
|
2016-10-05 21:48:07 +02:00
|
|
|
"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 21:14:24 +01:00
|
|
|
func formatInts(i int, t int) string {
|
2016-10-05 21:48:07 +02: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-12 01:36:07 +01:00
|
|
|
once.Do(func() {
|
|
|
|
if !globalQuiet {
|
|
|
|
console.Println(msg)
|
|
|
|
}
|
|
|
|
})
|
2016-10-05 21:48:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints custom message when healing is required for XL and Distributed XL backend.
|
2016-11-09 19:50:14 +01:00
|
|
|
func printHealMsg(endpoints []*url.URL, storageDisks []StorageAPI, fn printOnceFunc) {
|
|
|
|
msg := getHealMsg(endpoints, storageDisks)
|
2016-10-05 21:48:07 +02:00
|
|
|
fn(msg)
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:50:14 +01:00
|
|
|
// Heal endpoint constructs the final endpoint URL for control heal command.
|
|
|
|
// Disk heal endpoint needs to be just a URL and no special paths.
|
|
|
|
// This function constructs the right endpoint under various conditions
|
|
|
|
// for single node XL, distributed XL and when minio server is bound
|
|
|
|
// to a specific ip:port.
|
|
|
|
func getHealEndpoint(tls bool, firstEndpoint *url.URL) (cEndpoint *url.URL) {
|
2017-01-18 21:24:34 +01:00
|
|
|
scheme := httpScheme
|
2016-11-09 19:50:14 +01:00
|
|
|
if tls {
|
2017-01-18 21:24:34 +01:00
|
|
|
scheme = httpsScheme
|
2016-11-09 19:50:14 +01:00
|
|
|
}
|
|
|
|
cEndpoint = &url.URL{
|
|
|
|
Scheme: scheme,
|
|
|
|
}
|
|
|
|
// Bind to `--address host:port` was specified.
|
|
|
|
if globalMinioHost != "" {
|
|
|
|
cEndpoint.Host = net.JoinHostPort(globalMinioHost, globalMinioPort)
|
|
|
|
return cEndpoint
|
|
|
|
}
|
|
|
|
// For distributed XL setup.
|
|
|
|
if firstEndpoint.Host != "" {
|
|
|
|
cEndpoint.Host = firstEndpoint.Host
|
|
|
|
return cEndpoint
|
|
|
|
}
|
|
|
|
// For single node XL setup, we need to find the endpoint.
|
|
|
|
cEndpoint.Host = globalMinioAddr
|
|
|
|
// Fetch all the listening ips. For single node XL we
|
|
|
|
// just use the first host.
|
|
|
|
hosts, _, err := getListenIPs(cEndpoint.Host)
|
|
|
|
if err == nil {
|
|
|
|
cEndpoint.Host = net.JoinHostPort(hosts[0], globalMinioPort)
|
|
|
|
}
|
|
|
|
return cEndpoint
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:24:34 +01:00
|
|
|
// Disks offline and online strings..
|
|
|
|
const (
|
|
|
|
diskOffline = "offline"
|
|
|
|
diskOnline = "online"
|
|
|
|
)
|
|
|
|
|
2016-10-05 21:48:07 +02: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.
|
2016-11-09 19:50:14 +01:00
|
|
|
func getHealMsg(endpoints []*url.URL, storageDisks []StorageAPI) string {
|
2016-11-24 02:53:31 +01:00
|
|
|
msg := fmt.Sprintln("\nData volume requires HEALING. Healing is not implemented yet stay tuned:")
|
|
|
|
// FIXME: Enable this after we bring in healing.
|
2017-01-11 22:59:51 +01:00
|
|
|
// msg := "mc admin heal myminio"
|
2016-10-05 21:48:07 +02:00
|
|
|
disksInfo, _, _ := getDisksInfo(storageDisks)
|
|
|
|
for i, info := range disksInfo {
|
2016-10-17 23:31:33 +02:00
|
|
|
if storageDisks[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-10-05 21:48:07 +02:00
|
|
|
msg += fmt.Sprintf(
|
|
|
|
"\n[%s] %s - %s %s",
|
2016-11-28 21:14:24 +01:00
|
|
|
formatInts(i+1, len(storageDisks)),
|
2016-11-09 19:50:14 +01:00
|
|
|
endpoints[i],
|
2016-10-05 21:48:07 +02:00
|
|
|
humanize.IBytes(uint64(info.Total)),
|
|
|
|
func() string {
|
|
|
|
if info.Total > 0 {
|
2017-01-18 21:24:34 +01:00
|
|
|
return diskOnline
|
2016-10-05 21:48:07 +02:00
|
|
|
}
|
2017-01-18 21:24:34 +01:00
|
|
|
return diskOffline
|
2016-10-05 21:48:07 +02:00
|
|
|
}(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints regular message when we have sufficient disks to start the cluster.
|
2016-11-02 16:51:06 +01:00
|
|
|
func printRegularMsg(endpoints []*url.URL, storageDisks []StorageAPI, fn printOnceFunc) {
|
|
|
|
msg := getStorageInitMsg("\nInitializing data volume.", endpoints, storageDisks)
|
2016-10-05 21:48:07 +02:00
|
|
|
fn(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructs a formatted regular message when we have sufficient disks to start the cluster.
|
2016-11-02 16:51:06 +01:00
|
|
|
func getStorageInitMsg(titleMsg string, endpoints []*url.URL, storageDisks []StorageAPI) string {
|
|
|
|
msg := colorBlue(titleMsg)
|
2016-10-05 21:48:07 +02:00
|
|
|
disksInfo, _, _ := getDisksInfo(storageDisks)
|
|
|
|
for i, info := range disksInfo {
|
2016-10-17 23:31:33 +02:00
|
|
|
if storageDisks[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-10-05 21:48:07 +02:00
|
|
|
msg += fmt.Sprintf(
|
|
|
|
"\n[%s] %s - %s %s",
|
2016-11-28 21:14:24 +01:00
|
|
|
formatInts(i+1, len(storageDisks)),
|
2016-11-02 16:51:06 +01:00
|
|
|
endpoints[i],
|
2016-10-05 21:48:07 +02:00
|
|
|
humanize.IBytes(uint64(info.Total)),
|
|
|
|
func() string {
|
|
|
|
if info.Total > 0 {
|
2017-01-18 21:24:34 +01:00
|
|
|
return diskOnline
|
2016-10-05 21:48:07 +02:00
|
|
|
}
|
2017-01-18 21:24:34 +01:00
|
|
|
return diskOffline
|
2016-10-05 21:48:07 +02:00
|
|
|
}(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints initialization message when cluster is being initialized for the first time.
|
2016-11-02 16:51:06 +01:00
|
|
|
func printFormatMsg(endpoints []*url.URL, storageDisks []StorageAPI, fn printOnceFunc) {
|
|
|
|
msg := getStorageInitMsg("\nInitializing data volume for the first time.", endpoints, storageDisks)
|
2016-10-05 21:48:07 +02:00
|
|
|
fn(msg)
|
|
|
|
}
|
|
|
|
|
2016-10-07 20:15:55 +02:00
|
|
|
func printConfigErrMsg(storageDisks []StorageAPI, sErrs []error, fn printOnceFunc) {
|
|
|
|
msg := getConfigErrMsg(storageDisks, sErrs)
|
|
|
|
fn(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a formatted message when cluster is misconfigured.
|
|
|
|
func getConfigErrMsg(storageDisks []StorageAPI, sErrs []error) string {
|
|
|
|
msg := colorBlue("\nDetected configuration inconsistencies in the cluster. Please fix following servers.")
|
|
|
|
for i, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if sErrs[i] == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
msg += fmt.Sprintf(
|
|
|
|
"\n[%s] %s : %s",
|
2016-11-28 21:14:24 +01:00
|
|
|
formatInts(i+1, len(storageDisks)),
|
2016-10-07 20:15:55 +02:00
|
|
|
storageDisks[i],
|
|
|
|
sErrs[i],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|