fix: del the disruptions code

pull/1868/head
luhaoling 2 years ago
parent 6e2b50d63b
commit e0fd4ee4c1

@ -15,7 +15,6 @@
package main package main
import ( import (
"errors"
"flag" "flag"
"fmt" "fmt"
"github.com/IBM/sarama" "github.com/IBM/sarama"
@ -43,12 +42,7 @@ const (
) )
var ( var (
cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file") cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file")
MongoAuthFailed = "Authentication failed."
RedisAuthFailed = "NOAUTH Authentication required."
MinioAuthFailed = "Minio Authentication failed"
ZkAuthFailed = "zk Authentication failed"
KafkaAuthFailed = "SASL Authentication failed"
) )
func initCfg() error { func initCfg() error {
@ -61,9 +55,8 @@ func initCfg() error {
} }
type checkFunc struct { type checkFunc struct {
name string name string
function func() error function func() error
authErrInfo string
} }
func main() { func main() {
@ -79,11 +72,11 @@ func main() {
checks := []checkFunc{ checks := []checkFunc{
//{name: "Mysql", function: checkMysql}, //{name: "Mysql", function: checkMysql},
{name: "Mongo", function: checkMongo, authErrInfo: MongoAuthFailed}, {name: "Mongo", function: checkMongo},
{name: "Redis", function: checkRedis, authErrInfo: RedisAuthFailed}, {name: "Redis", function: checkRedis},
{name: "Minio", function: checkMinio, authErrInfo: MinioAuthFailed}, {name: "Minio", function: checkMinio},
{name: "Zookeeper", function: checkZookeeper, authErrInfo: ZkAuthFailed}, {name: "Zookeeper", function: checkZookeeper},
{name: "Kafka", function: checkKafka, authErrInfo: KafkaAuthFailed}, {name: "Kafka", function: checkKafka},
} }
for i := 0; i < maxRetry; i++ { for i := 0; i < maxRetry; i++ {
@ -92,29 +85,16 @@ func main() {
} }
fmt.Printf("Checking components Round %v...\n", i+1) fmt.Printf("Checking components Round %v...\n", i+1)
var ( var err error
err error
errInfo string
disruptions bool
)
allSuccess := true allSuccess := true
for _, check := range checks { for _, check := range checks {
err = check.function() err = check.function()
if err != nil { if err != nil {
if errorJudge(err, check.authErrInfo) { ErrorPrint(fmt.Sprintf("Starting %s failed:%v.", check.name, err))
disruptions = true
}
ErrorPrint(fmt.Sprintf("Starting %s failed:%v, conneted info:%s", check.name, err, errInfo))
allSuccess = false allSuccess = false
} else { } else {
component.SuccessPrint(fmt.Sprintf("%s connected successfully, address:%s", check.name, errInfo)) component.SuccessPrint(fmt.Sprintf("%s connected successfully", check.name))
} }
}
if disruptions {
component.ErrorPrint(fmt.Sprintf("component check exit,err: %v", err))
return
} }
if allSuccess { if allSuccess {
@ -275,9 +255,3 @@ func colorPrint(colorCode int, format string, a ...interface{}) {
log.Printf("\x1b[%dm%s\x1b[0m\n", colorCode, fmt.Sprintf(format, a...)) log.Printf("\x1b[%dm%s\x1b[0m\n", colorCode, fmt.Sprintf(format, a...))
} }
func errorJudge(err error, errMsg string) bool {
if strings.Contains(errors.Unwrap(err).Error(), errMsg) {
return true
}
return false
}

Loading…
Cancel
Save