Merge pull request #4 from harlowja/singular

Instead of batch create/update just do singular for now
This commit is contained in:
Vilobh Meshram 2016-05-13 15:19:25 -07:00
commit 6c11b02d89
2 changed files with 17 additions and 18 deletions

View File

@ -59,23 +59,22 @@ class ZookeeperQuotaEngine(engine.QuotaEngine):
limits.append((resource, json.loads(blob))) limits.append((resource, json.loads(blob)))
return limits return limits
def create_or_update_limits(self, for_who, resources, limits): def create_or_update_limit(self, for_who, resource, limit):
who_path = paths.join(self.uri.path, for_who) who_path = paths.join(self.uri.path, for_who)
self.client.ensure_path(who_path) self.client.ensure_path(who_path)
for resource, limit in zip(resources, limits): resource_path = paths.join(who_path, resource)
resource_path = paths.join(who_path, resource) try:
try: self.client.create(resource_path, json.dumps(limit))
self.client.create(resource_path, json.dumps(limit)) except exceptions.NodeExistsError:
except exceptions.NodeExistsError: blob, znode = self.client.get(resource_path)
blob, znode = self.client.get(resource_path) cur_limit = json.loads(blob)
cur_limit = json.loads(blob) cur_limit.update(limit)
cur_limit.update(limit) # Ensure we pass in the version that we read this on so
# Ensure we pass in the version that we read this on so # that if it was changed by some other actor that we can
# that if it was changed by some other actor that we can # avoid overwriting that value (and retry, or handle in some
# avoid overwriting that value (and retry, or handle in some # other manner).
# other manner). self.client.set(resource_path, json.dumps(cur_limit),
self.client.set(resource_path, json.dumps(cur_limit), version=znode.version)
version=znode.version)
def consume_many(self, for_who, resources, amounts): def consume_many(self, for_who, resources, amounts):
who_path = paths.join(self.uri.path, for_who) who_path = paths.join(self.uri.path, for_who)

View File

@ -36,10 +36,10 @@ class QuotaEngine(object):
"""Reads the limits of some entity.""" """Reads the limits of some entity."""
@abc.abstractmethod @abc.abstractmethod
def create_or_update_limits(self, for_who, resources, limits): def create_or_update_limit(self, for_who, resource, limit):
"""Creates or updates a set of resource limits for some entity. """Updates or creates a resource limit for some entity.
Must operate transactionally; either all created/updated or none. Must operate transactionally; either created/updated or not.
""" """
@abc.abstractmethod @abc.abstractmethod