Merge "Move over pull request from github #8 to here"

This commit is contained in:
Jenkins 2016-05-17 07:46:25 +00:00 committed by Gerrit Code Review
commit 656fa5f13c
3 changed files with 4 additions and 12 deletions

View File

@ -21,7 +21,7 @@ from kazoo.protocol import paths
from delimiter import engine
from delimiter import exceptions
from delimiter import processors
from delimiter.processors import upper_bound
class ZookeeperQuotaEngine(engine.QuotaEngine):
@ -34,7 +34,7 @@ class ZookeeperQuotaEngine(engine.QuotaEngine):
#: Limit processors that this engine supports.
processors = {
'upper_bound': processors.UpperBoundProcessor(),
'upper_bound': upper_bound.UpperBoundProcessor(),
}
def __init__(self, uri):

View File

View File

@ -16,18 +16,17 @@
import collections
from delimiter import exceptions
from delimiter import processor
BoundedResource = collections.namedtuple('BoundedResource',
['consumed', 'bound'])
class UpperBoundProcessor(object):
class UpperBoundProcessor(processor.Processor):
"""Processes a limit given some upper bound."""
@staticmethod
def create(limit):
"""Given some limit, turn it into a *internal* details dict."""
return {
'consumed': 0,
'bound': limit,
@ -35,23 +34,16 @@ class UpperBoundProcessor(object):
@staticmethod
def decode(details):
"""Turn a internal details dict into a user-viewable one."""
return BoundedResource(details['consumed'], details['bound'])
@staticmethod
def update(details, limit):
"""Given internal details dict update it with the given limit."""
details = details.copy()
details['bound'] = limit
return details
@staticmethod
def process(details, amount):
"""Given internal details dict process the amount given (or die).
Updates (and returns) the internal details dict if
successful (otherwise raises some exception).
"""
consumed = details['consumed']
if consumed + amount > details['bound']:
raise exceptions.OverLimitException(