Sridhar Parimela
Sridhar Parimela

Reputation: 31

Validate if path(znode) exists in zookeeper using zookeeper-shell.sh

I need some help to validate if the znode(path) exists in zookeeper using zookeeper-shell.sh

Example: bin/zookeeper-shell.sh zk:9091 ls /brokers/idss Here /brokers/idss does not exists in the zookeeper it throws message Node does not exist:

I want to use this in my if condition and proceed with logic.

Any help would be really appreciated?

Upvotes: 3

Views: 1682

Answers (1)

Arvanitis Christos
Arvanitis Christos

Reputation: 267

From ZooKeeper 3.4.7 and upwards, there is support in zkCli for command processing. So you could issue a command like the following to check if a znode exists:

zkCli.sh -server host:port get /test/path  

This is a bash command and its return value can be used in an if condition. In case of an error (KeeperError exception, relevant Error codes can be found here), a non zero value will be return. If the node exists and you can have read access to it, 0 is returned.

Upvotes: 0

Related Questions