-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from real-digital/22-kafka-topic-terraform-style
Refactoring of topic handling in preparation of #22
- Loading branch information
Showing
16 changed files
with
506 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ wheels/ | |
MANIFEST | ||
*.pyc | ||
*.pyo | ||
pip-wheel-metadata | ||
|
||
# Esque specific | ||
esque.cfg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
from typing import List | ||
import operator | ||
|
||
from confluent_kafka.admin import ConfigResource | ||
|
||
from esque.helpers import unpack_confluent_config | ||
from esque.resource import KafkaResource | ||
|
||
|
||
class Broker: | ||
def __init__(self, cluster, broker_id): | ||
class Broker(KafkaResource): | ||
def __init__(self, cluster, *, broker_id: int = None, host: str = None, port: int = None): | ||
self.cluster = cluster | ||
self.broker_id = broker_id | ||
self.host = host | ||
self.port = port | ||
|
||
@classmethod | ||
def from_id(cls, cluster, broker_id) -> "Broker": | ||
return cls(cluster=cluster, broker_id=broker_id) | ||
|
||
@classmethod | ||
def from_attributes(cls, cluster, broker_id: int, host: str, port: int) -> "Broker": | ||
return cls(cluster, broker_id=broker_id, host=host, port=port) | ||
|
||
@classmethod | ||
def get_all(cls, cluster) -> List["Broker"]: | ||
metadata = cluster.get_metadata().brokers.values() | ||
brokers = [ | ||
cls.from_attributes(cluster, broker_id=broker.id, host=broker.host, port=broker.port) | ||
for broker in metadata | ||
] | ||
return sorted(brokers, key=operator.attrgetter("broker_id")) | ||
|
||
def describe(self): | ||
conf = self.cluster.retrieve_config(ConfigResource.Type.BROKER, self.broker_id) | ||
return unpack_confluent_config(conf) | ||
return self.cluster.retrieve_config(ConfigResource.Type.BROKER, self.broker_id) | ||
|
||
def as_dict(self): | ||
return {"cluster": self.cluster, "broker_id": self.broker_id, "host": self.host, "port": self.port} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.