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 | add |
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 | list |
List the contents of the Zookeeper node. |
| Method | retrieve |
Retrieve the Zookeeper node as an INI configuration string. |
| Method | store |
Store the INI configuration in the Zookeeper node. |
| Method | update |
Update the value of the specified key in the Zookeeper node. |
| Method | upsert |
Upsert a key-value pair to the Zookeeper node. |
| Instance Variable | case |
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 | normalized |
The normalized root node, which is always an absolute path. |
| Instance Variable | port |
The port of the Zookeeper server. |
| Instance Variable | root |
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 | _normalize |
Normalize the key to be case-sensitive or not. |
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:str | The hostname of the Zookeeper server. |
port:int | None | The port of the Zookeeper server. |
rootstr | None | The root node of the Zookeeper server. |
logger:Callable | None | The logger function to use for logging. |
verbose:bool | None | Flag to enable verbose output. |
casebool | None | Flag to enable case-sensitive key names. |
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:str | The key to add. This can be node relative to the root node, or an absolute path. |
value:str | The value to add. This is optional and defaults the root node. |
| Returns | |
Zookeeper | The Zookeeper instance. |
| Raises | |
Exception | If the Zookeeper client is not connected or if the key already exists. |
Connect to the Zookeeper server.
| Parameters | |
createbool | None | Flag to create the root node if it doesn't exist. |
| Returns | |
Zookeeper | The Zookeeper instance. |
| Raises | |
Exception | If the Zookeeper client cannot be created or connected. |
Delete the specified key from the Zookeeper node.
| Parameters | |
key:str | The key to delete. This can be node relative to the root node, or an absolute path. |
| Returns | |
Zookeeper | The Zookeeper instance. |
| Raises | |
Exception | If the Zookeeper client is not connected or if the key does not exist. |
Check if the specified Zookeeper node exists.
| Parameters | |
node:str | None | The node to check. This must be an absolute path. |
| Returns | |
bool | True if the node exists, False otherwise. |
| Raises | |
Exception | If the Zookeeper client is not connected. |
List the contents of the Zookeeper node.
| Parameters | |
node:str | The node to list. This can be node relative to the root node, or an absolute path. |
| Returns | |
list[ | A list of Zookeeper nodes. |
Retrieve the Zookeeper node as an INI configuration string.
| Parameters | |
node:str | None | The node to convert. This can be node relative to the root node, or an absolute path. The default is the root node. |
| Returns | |
str | A multi-line string representing the INI configuration for the Zookeeper node. |
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[ | The 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 | None | The node to store the configuration in. This can be node relative to the root node, or an absolute path. |
| Returns | |
Zookeeper | The Zookeeper instance. |
| Raises | |
Exception | If the Zookeeper client is not connected or if the configuration is empty. |
Update the value of the specified key in the Zookeeper node.
| Parameters | |
key:str | The key to update. This can be node relative to the root node, or an absolute path. |
value:str | The new value to set for the key. |
| Returns | |
Zookeeper | The Zookeeper instance. |
| Raises | |
Exception | If the Zookeeper client is not connected or if the key does not exist. |
Upsert a key-value pair to the Zookeeper node.
| Parameters | |
key:str | The key to upsert. This can be node relative to the root node, or an absolute path. |
value:str | The value to upsert. This is optional and defaults to an empty string. |
| Returns | |
Zookeeper | The Zookeeper instance. |
| Raises | |
Exception | If the Zookeeper client is not connected. |