|
|
|
@ -16,6 +16,7 @@ package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
@ -285,10 +286,23 @@ func checkZookeeper() (string, error) {
|
|
|
|
|
|
|
|
|
|
// Connect to Zookeeper
|
|
|
|
|
str := "the addr is:" + address
|
|
|
|
|
c, _, err := zk.Connect(zookeeperAddresses, time.Second) // Adjust the timeout as necessary
|
|
|
|
|
c, eventChan, err := zk.Connect(zookeeperAddresses, time.Second) // Adjust the timeout as necessary
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", errs.Wrap(errStr(err, str))
|
|
|
|
|
}
|
|
|
|
|
timeout := time.After(5 * time.Second)
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case event := <-eventChan:
|
|
|
|
|
if event.State == zk.StateConnected {
|
|
|
|
|
fmt.Println("Connected to Zookeeper")
|
|
|
|
|
goto Connected
|
|
|
|
|
}
|
|
|
|
|
case <-timeout:
|
|
|
|
|
return "", errs.Wrap(errors.New("timeout waiting for Zookeeper connection"), "Zookeeper Addr: "+strings.Join(config.Config.Zookeeper.ZkAddr, " "))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Connected:
|
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
|
|
// Set authentication if username and password are provided
|
|
|
|
@ -298,12 +312,6 @@ func checkZookeeper() (string, error) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if Zookeeper is reachable
|
|
|
|
|
_, _, err = c.Get("/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", errs.Wrap(err, str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|