From 7cc2423808935401884fbdc5afb0d126ef3e8e49 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 13 May 2016 14:49:46 -0700 Subject: [PATCH] Instead of batch create/update just do singular for now --- delimiter/drivers/zookeeper.py | 29 ++++++++++++++--------------- delimiter/engine.py | 6 +++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/delimiter/drivers/zookeeper.py b/delimiter/drivers/zookeeper.py index 0bb754c..567d1ae 100644 --- a/delimiter/drivers/zookeeper.py +++ b/delimiter/drivers/zookeeper.py @@ -59,23 +59,22 @@ class ZookeeperQuotaEngine(engine.QuotaEngine): limits.append((resource, json.loads(blob))) 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) self.client.ensure_path(who_path) - for resource, limit in zip(resources, limits): - resource_path = paths.join(who_path, resource) - try: - self.client.create(resource_path, json.dumps(limit)) - except exceptions.NodeExistsError: - blob, znode = self.client.get(resource_path) - cur_limit = json.loads(blob) - cur_limit.update(limit) - # Ensure we pass in the version that we read this on so - # that if it was changed by some other actor that we can - # avoid overwriting that value (and retry, or handle in some - # other manner). - self.client.set(resource_path, json.dumps(cur_limit), - version=znode.version) + resource_path = paths.join(who_path, resource) + try: + self.client.create(resource_path, json.dumps(limit)) + except exceptions.NodeExistsError: + blob, znode = self.client.get(resource_path) + cur_limit = json.loads(blob) + cur_limit.update(limit) + # Ensure we pass in the version that we read this on so + # that if it was changed by some other actor that we can + # avoid overwriting that value (and retry, or handle in some + # other manner). + self.client.set(resource_path, json.dumps(cur_limit), + version=znode.version) def consume_many(self, for_who, resources, amounts): who_path = paths.join(self.uri.path, for_who) diff --git a/delimiter/engine.py b/delimiter/engine.py index 76bfcae..caf61e6 100644 --- a/delimiter/engine.py +++ b/delimiter/engine.py @@ -36,10 +36,10 @@ class QuotaEngine(object): """Reads the limits of some entity.""" @abc.abstractmethod - def create_or_update_limits(self, for_who, resources, limits): - """Creates or updates a set of resource limits for some entity. + def create_or_update_limit(self, for_who, resource, limit): + """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