diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b30863bc..68642e04 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Brewtils Changelog ------ TBD +- Expanded Topic/Subscriber models to include counters - Formalized Status Info model and added helper features to track the history of the status changes. - Added support models for tracking primary replication - New Models for User, UserToken, Role, and AliasUserMap diff --git a/brewtils/models.py b/brewtils/models.py index 321952be..c9ee4a52 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -1829,6 +1829,7 @@ def __init__( instance=None, command=None, subscriber_type=None, + consumer_count=0, ): self.garden = garden self.namespace = namespace @@ -1837,6 +1838,7 @@ def __init__( self.instance = instance self.command = command self.subscriber_type = subscriber_type or "DYNAMIC" + self.consumer_count = consumer_count def __str__(self): return "%s" % self.__dict__ @@ -1844,7 +1846,7 @@ def __str__(self): def __repr__(self): return ( "" + "command=%s, subscriber_type=%s, consumer_count=%s>" % ( self.garden, self.namespace, @@ -1853,6 +1855,7 @@ def __repr__(self): self.instance, self.command, self.subscriber_type, + self.consumer_count, ) ) @@ -1875,18 +1878,22 @@ def __eq__(self, other): class Topic(BaseModel): schema = "TopicSchema" - def __init__(self, id=None, name=None, subscribers=None): # noqa # shadows built-in + def __init__( + self, id=None, name=None, subscribers=None, publisher_count=0 + ): # noqa # shadows built-in self.id = id self.name = name self.subscribers = subscribers or [] + self.publisher_count = publisher_count def __str__(self): return "%s: %s" % (self.name, [str(s) for s in self.subscribers]) def __repr__(self): - return "" % ( + return "" % ( self.name, self.subscribers, + self.publisher_count, ) diff --git a/brewtils/schemas.py b/brewtils/schemas.py index 8fdf561f..913435f8 100644 --- a/brewtils/schemas.py +++ b/brewtils/schemas.py @@ -601,12 +601,14 @@ class SubscriberSchema(BaseSchema): instance = fields.Str(allow_none=True) command = fields.Str(allow_none=True) subscriber_type = fields.Str(allow_none=True) + consumer_count = fields.Int(allow_none=True) class TopicSchema(BaseSchema): id = fields.Str(allow_none=True) name = fields.Str(allow_none=True) subscribers = fields.List(fields.Nested(SubscriberSchema, allow_none=True)) + publisher_count = fields.Int(allow_none=True) class ReplicationSchema(BaseSchema): diff --git a/brewtils/test/fixtures.py b/brewtils/test/fixtures.py index 24e31009..95a67e17 100644 --- a/brewtils/test/fixtures.py +++ b/brewtils/test/fixtures.py @@ -1051,6 +1051,7 @@ def subscriber_dict(): "instance": "inst", "command": "run", "subscriber_type": "DYNAMIC", + "consumer_count": 10, } @@ -1062,7 +1063,12 @@ def bg_subscriber(subscriber_dict): @pytest.fixture def topic_dict(subscriber_dict): """Topic as dict""" - return {"id": "5d174df1", "name": "foo", "subscribers": [subscriber_dict]} + return { + "id": "5d174df1", + "name": "foo", + "subscribers": [subscriber_dict], + "publisher_count": 10, + } @pytest.fixture diff --git a/test/models_test.py b/test/models_test.py index 022875d5..ca562d1a 100644 --- a/test/models_test.py +++ b/test/models_test.py @@ -694,7 +694,7 @@ def subscriber1(): @pytest.fixture def topic1(subscriber1): - return Topic(name="foo.*", subscribers=[subscriber1]) + return Topic(name="foo.*", subscribers=[subscriber1], publisher_count=10) class TestSubscriber(object): @@ -715,9 +715,12 @@ def test_str(self, topic1, subscriber1): assert str(topic1) == "%s: %s" % (topic1.name, [str(subscriber1)]) def test_repr(self, topic1, subscriber1): - assert repr(topic1) == "" % ( + assert repr( + topic1 + ) == "" % ( topic1.name, [subscriber1], + topic1.publisher_count, )