Search in sources :

Example 11 with ConnectStringParser

use of org.apache.zookeeper.client.ConnectStringParser in project samza by apache.

the class ZkCoordinationUtilsFactory method validateZkNameSpace.

/**
 * if ZkConnectString contains namespace path at the end, but it does not exist we should fail
 * @param zkConnect - connect string
 * @param zkClient - zkClient object to talk to the ZK
 */
public static void validateZkNameSpace(String zkConnect, ZkClient zkClient) {
    ConnectStringParser parser = new ConnectStringParser(zkConnect);
    String path = parser.getChrootPath();
    if (Strings.isNullOrEmpty(path)) {
        // no namespace path
        return;
    }
    LOG.info("connectString = " + zkConnect + "; path =" + path);
    // if namespace specified (path above) but "/" does not exists, we will fail
    if (!zkClient.exists("/")) {
        throw new SamzaException("Zookeeper namespace: " + path + " does not exist for zk at " + zkConnect);
    }
}
Also used : ConnectStringParser(org.apache.zookeeper.client.ConnectStringParser) SamzaException(org.apache.samza.SamzaException)

Aggregations

ConnectStringParser (org.apache.zookeeper.client.ConnectStringParser)11 Test (org.junit.jupiter.api.Test)6 InetSocketAddress (java.net.InetSocketAddress)3 HostProvider (org.apache.zookeeper.client.HostProvider)3 StaticHostProvider (org.apache.zookeeper.client.StaticHostProvider)3 IOException (java.io.IOException)2 List (java.util.List)2 ZkException (org.I0Itec.zkclient.exception.ZkException)2 ClientCnxn (org.apache.zookeeper.ClientCnxn)2 SamzaException (org.apache.samza.SamzaException)1 ZKClientConfig (org.apache.zookeeper.client.ZKClientConfig)1