class documentation

Class to manage Zookeeper configurations.

This class provides methods to connect to a Zookeeper server, list nodes, retrieve and store INI configurations, add, update, delete key-value pairs, and manage the Zookeeper client connection.

Method __init__ Initialize the Zookeeper client.
Method addKeyValue Add a key-value pair to the Zookeeper node.
Method connect Connect to the Zookeeper server.
Method delete Delete the specified key from the Zookeeper node.
Method disconnect Disconnect from the Zookeeper server.
Method exists Check if the specified Zookeeper node exists.
Method listNode List the contents of the Zookeeper node.
Method retrieveIniConfig Retrieve the Zookeeper node as an INI configuration string.
Method storeIniConfig Store the INI configuration in the Zookeeper node.
Method updateKeyValue Update the value of the specified key in the Zookeeper node.
Method upsertKeyValue Upsert a key-value pair to the Zookeeper node.
Instance Variable caseSensitive Flag to indicate if the keys are case-sensitive.
Instance Variable host The hostname of the Zookeeper server.
Instance Variable logger The logger function to use for logging. If None, the default print function is used.
Instance Variable normalizedRootNode The normalized root node, which is always an absolute path.
Instance Variable port The port of the Zookeeper server.
Instance Variable rootNode The root node of the Zookeeper server. This is always an absolute path.
Instance Variable verbose Flag to enable verbose output. If True, the logger will be used to print messages.
Instance Variable zk The Zookeeper client instance.
Method _normalizeKey Normalize the key to be case-sensitive or not.
def __init__(self, host: str, port: int | None = zookeeperDefaultPort, rootNode: str | None = '/', logger: Callable | None = print, verbose: bool | None = False, caseSensitive: bool | None = True):

Initialize the Zookeeper client.

Parameters
host:strThe hostname of the Zookeeper server.
port:int | NoneThe port of the Zookeeper server.
rootNode:str | NoneThe root node of the Zookeeper server.
logger:Callable | NoneThe logger function to use for logging.
verbose:bool | NoneFlag to enable verbose output.
caseSensitive:bool | NoneFlag to enable case-sensitive key names.
def addKeyValue(self, key: str, value: str = '') -> Zookeeper:

Add a key-value pair to the Zookeeper node.

Section that are stored in multiple levels in the Zookeeper tree will be flattened and stored as a single section, separated by dots (.) in the section name.

Parameters
key:strThe key to add. This can be node relative to the root node, or an absolute path.
value:strThe value to add. This is optional and defaults the root node.
Returns
ZookeeperThe Zookeeper instance.
Raises
ExceptionIf the Zookeeper client is not connected or if the key already exists.
def connect(self, createRoot: bool | None = True) -> Zookeeper:

Connect to the Zookeeper server.

Parameters
createRoot:bool | NoneFlag to create the root node if it doesn't exist.
Returns
ZookeeperThe Zookeeper instance.
Raises
ExceptionIf the Zookeeper client cannot be created or connected.
def delete(self, key: str) -> Zookeeper:

Delete the specified key from the Zookeeper node.

Parameters
key:strThe key to delete. This can be node relative to the root node, or an absolute path.
Returns
ZookeeperThe Zookeeper instance.
Raises
ExceptionIf the Zookeeper client is not connected or if the key does not exist.
def disconnect(self) -> Zookeeper:

Disconnect from the Zookeeper server.

Returns
ZookeeperThe Zookeeper instance.
def exists(self, node: str | None = None) -> bool:

Check if the specified Zookeeper node exists.

Parameters
node:str | NoneThe node to check. This must be an absolute path.
Returns
boolTrue if the node exists, False otherwise.
Raises
ExceptionIf the Zookeeper client is not connected.
def listNode(self, node: str) -> list[ZookeperNode]:

List the contents of the Zookeeper node.

Parameters
node:strThe node to list. This can be node relative to the root node, or an absolute path.
Returns
list[ZookeperNode]A list of Zookeeper nodes.
def retrieveIniConfig(self, node: str | None = None) -> str:

Retrieve the Zookeeper node as an INI configuration string.

Parameters
node:str | NoneThe node to convert. This can be node relative to the root node, or an absolute path. The default is the root node.
Returns
strA multi-line string representing the INI configuration for the Zookeeper node.
def storeIniConfig(self, config: ConfigParser | list[ConfigParser] | str, node: str | None = None) -> Zookeeper:

Store the INI configuration in the Zookeeper node.

Dots (.) in the section names will be replaced with slashes (/) and be stored as a path in Zookeeper. For example, the section name 'section.subsection' will be stored as 'section/subsection'.

Parameters
config:ConfigParser | list[ConfigParser] | strThe INI configuration to store. This can be a single ConfigParser object, a list of ConfigParser objects, or a string. If the configuration is a string it will be parsed. The order of the list is important, as entries in the first ConfigParser will be overwritten by entries in the second ConfigParser if they have the same section and key.
node:str | NoneThe node to store the configuration in. This can be node relative to the root node, or an absolute path.
Returns
ZookeeperThe Zookeeper instance.
Raises
ExceptionIf the Zookeeper client is not connected or if the configuration is empty.
def updateKeyValue(self, key: str, value: str) -> Zookeeper:

Update the value of the specified key in the Zookeeper node.

Parameters
key:strThe key to update. This can be node relative to the root node, or an absolute path.
value:strThe new value to set for the key.
Returns
ZookeeperThe Zookeeper instance.
Raises
ExceptionIf the Zookeeper client is not connected or if the key does not exist.
def upsertKeyValue(self, key: str, value: str) -> Zookeeper:

Upsert a key-value pair to the Zookeeper node.

Parameters
key:strThe key to upsert. This can be node relative to the root node, or an absolute path.
value:strThe value to upsert. This is optional and defaults to an empty string.
Returns
ZookeeperThe Zookeeper instance.
Raises
ExceptionIf the Zookeeper client is not connected.
caseSensitive =

Flag to indicate if the keys are case-sensitive.

host =

The hostname of the Zookeeper server.

logger =

The logger function to use for logging. If None, the default print function is used.

normalizedRootNode =

The normalized root node, which is always an absolute path.

port =

The port of the Zookeeper server.

rootNode =

The root node of the Zookeeper server. This is always an absolute path.

verbose =

Flag to enable verbose output. If True, the logger will be used to print messages.

zk =

The Zookeeper client instance.

def _normalizeKey(self, key: str) -> str:

Normalize the key to be case-sensitive or not.

Parameters
key:strThe key to normalize.
Returns
strThe normalized key.