Skip to content

Commit

Permalink
fix component check (#343)
Browse files Browse the repository at this point in the history
* update init config

* update init

* update component check

* update component check

* update component check
  • Loading branch information
AndrewZuo01 committed Dec 25, 2023
1 parent 8d50804 commit ca73750
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tools/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,23 @@ func successPrint(s string, hide bool) {
func newZkClient() (*zk.Conn, error) {
var c *zk.Conn
c, _, err := zk.Connect(config.Config.Zookeeper.ZkAddr, time.Second, zk.WithLogger(log.NewZkLogger()))
result, _, _ := c.Exists("zookeeper")
fmt.Println("zk addr=", config.Config.Zookeeper.ZkAddr)
if err != nil || !result {
if err != nil {
fmt.Println("zookeeper connect error:", err)
return nil, errs.Wrap(err, "Zookeeper Addr: "+strings.Join(config.Config.Zookeeper.ZkAddr, " "))
} else {
if config.Config.Zookeeper.Username != "" && config.Config.Zookeeper.Password != "" {
if err := c.AddAuth("digest", []byte(config.Config.Zookeeper.Username+":"+config.Config.Zookeeper.Password)); err != nil {
return nil, errs.Wrap(err, "Zookeeper Username: "+config.Config.Zookeeper.Username+
", Zookeeper Password: "+config.Config.Zookeeper.Password+
", Zookeeper Addr: "+strings.Join(config.Config.Zookeeper.ZkAddr, " "))
}
}
if config.Config.Zookeeper.Username != "" && config.Config.Zookeeper.Password != "" {
if err := c.AddAuth("digest", []byte(config.Config.Zookeeper.Username+":"+config.Config.Zookeeper.Password)); err != nil {
return nil, errs.Wrap(err, "Zookeeper Username: "+config.Config.Zookeeper.Username+
", Zookeeper Password: "+config.Config.Zookeeper.Password+
", Zookeeper Addr: "+strings.Join(config.Config.Zookeeper.ZkAddr, " "))
}
}
result, _, _ := c.Exists("/zookeeper")
if !result {
err = errors.New("zookeeper not exist")
return nil, errs.Wrap(err, "Zookeeper Addr: "+strings.Join(config.Config.Zookeeper.ZkAddr, " "))
}
return c, nil
}

Expand Down

0 comments on commit ca73750

Please sign in to comment.