diff options
author | James E. Blair <jim@acmegating.com> | 2022-01-06 16:03:09 -0800 |
---|---|---|
committer | James E. Blair <jim@acmegating.com> | 2022-01-27 12:19:11 -0800 |
commit | 29fbee73753c8f0febf913fb79d271287201170d (patch) | |
tree | 20a1a615199c99e56e74aa45d1641a5fd9d90302 /zuul/zk/zkobject.py | |
parent | 4c0fef8c1ef5b011f840b3fd4958e1e0e61c8150 (diff) | |
download | zuul-29fbee73753c8f0febf913fb79d271287201170d.tar.gz |
Add a model API version
This is a framework for making upgrades to the ZooKeeper data model
in a manner that can support a rolling Zuul system upgrade.
Change-Id: Iff09c95878420e19234908c2a937e9444832a6ec
Diffstat (limited to 'zuul/zk/zkobject.py')
-rw-r--r-- | zuul/zk/zkobject.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/zuul/zk/zkobject.py b/zuul/zk/zkobject.py index e19c67982..196533889 100644 --- a/zuul/zk/zkobject.py +++ b/zuul/zk/zkobject.py @@ -22,19 +22,25 @@ from kazoo.exceptions import ( from zuul.zk import sharding from zuul.zk.exceptions import InvalidObjectError +from zuul import model class ZKContext: - def __init__(self, zk_client, lock, stop_event, log): + def __init__(self, zk_client, lock, stop_event, log, registry): self.client = zk_client.client self.lock = lock self.stop_event = stop_event self.log = log + self.registry = registry def sessionIsValid(self): return ((not self.lock or self.lock.is_still_valid()) and (not self.stop_event or not self.stop_event.is_set())) + @property + def model_api(self): + return self.registry.model_api + class LocalZKContext: """A Local ZKContext that means don't actually write anything to ZK""" @@ -44,10 +50,15 @@ class LocalZKContext: self.lock = None self.stop_event = None self.log = log + self.registry = None def sessionIsValid(self): return True + @property + def model_api(self): + return model.MODEL_API + class ZKObject: _retry_interval = 5 @@ -60,7 +71,7 @@ class ZKObject: """ raise NotImplementedError() - def serialize(self): + def serialize(self, context): """Implement this method to return the data to save in ZK. :returns: A byte string @@ -154,7 +165,7 @@ class ZKObject: if isinstance(context, LocalZKContext): return b'' try: - return self.serialize() + return self.serialize(context) except Exception: # A higher level must handle this exception, but log # ourself here so we know what object triggered it. |