Zookeeper Nodes
This module provides a ZkNode object which can load itself from a Zookeeper path, and serialize itself back.
Zookeeper Node
This object provides access to a single node for updating the value that can also track changes to the value from Zookeeper.
The value of the node is coerced into an appropriate Python object when loaded, current supported conversions:
Numbers with decimals -> Decimal
Numbers without decimals -> Int
true/false -> Bool
none -> None
ISO 8601 Date and Datetime -> date or datetime
And optionally, with use_json:
JSON string -> dict/list
Note
The JSON determination is extremely lax, if its a string that starts and ends with brackets or curley marks, its assumed to be a JSON object and will be coerced if possible. If coercion fails, the string will be returned as is.
Example:
from zktools.connection import ZkConnection
from zktools.configuration import ZkNode
conn = ZkConnection()
node = ZkNode(conn, '/some/config/node')
# prints out the current value, defaults to None
print node.value
# Set the value in zookeeper
node.value = 483.24
The default behavior is to track changes to the node, so that the value attribute always reflects the node’s value in Zookeeper.
Warning
Do not delete nodes that are in use, there intentionally is no code to handle such conditions as it creates overly complex scenarios both for ZkNode and for application code using it.
Create a Zookeeper Node
Creating a ZkNode by default attempts to load the value, and if its not found will automatically create a blank string as the value.
In the event the node is deleted once this object is deleted once its being tracked, the deleted attribute will be True.
Parameters: |
|
---|
Returns the current value
If the Zookeeper session expired, it will be reconnected and the value reloaded.
Indicate whether a connection to Zookeeper exists