コード例 #1
0
def test_pykafka_config(mocker: mock, config: Config):
    ssl_config_sentinel = mock.sentinel.ssl_config
    ssl_config_mock = mocker.patch("esque.config.SslConfig", return_value=ssl_config_sentinel)
    plain_authenticator_sentinel = mock.sentinel.plain_authenticator
    plain_authenticator_mock = mocker.patch(
        "pykafka.sasl_authenticators.PlainAuthenticator", return_value=plain_authenticator_sentinel
    )

    config.context_switch("context_5")
    expected_config = {
        "hosts": "kafka:9094,kafka1:9094,kafka2:9094,kafka3:9094",
        "sasl_authenticator": plain_authenticator_sentinel,
        "ssl_config": ssl_config_sentinel,
    }
    actual_config = config.create_pykafka_config()
    assert expected_config == actual_config
    ssl_config_mock.assert_called_with(
        **{
            "cafile": "/my/ca.crt",
            "certfile": "/my/certificate.crt",
            "keyfile": "/my/certificate.key",
            "password": "******",
        }
    )
    plain_authenticator_mock.assert_called_with(user="******", password="******", security_protocol="SASL_SSL")
コード例 #2
0
ファイル: cluster.py プロジェクト: garrettthomaskth/esque
class Cluster:
    def __init__(self):
        self._config = Config()
        self.confluent_client = AdminClient(
            self._config.create_confluent_config())
        self.pykafka_client = pykafka.client.KafkaClient(
            **self._config.create_pykafka_config(), broker_version="1.0.0")
        self.confluent_client.poll(timeout=1)
        self.__topic_controller = None

    @property
    def topic_controller(self) -> TopicController:
        if self.__topic_controller is None:
            self.__topic_controller = TopicController(self, self._config)
        return self.__topic_controller

    @property
    def bootstrap_servers(self):
        return self._config.bootstrap_servers

    def get_metadata(self):
        return self.confluent_client.list_topics(timeout=1)

    @property
    def brokers(self):
        metadata = self.confluent_client.list_topics(timeout=1)
        return sorted(
            [{
                "id": broker.id,
                "host": broker.host,
                "port": broker.port
            } for broker in metadata.brokers.values()],
            key=operator.itemgetter("id"),
        )

    def retrieve_config(self, config_type: ConfigResource.Type, id):
        requested_resources = [ConfigResource(config_type, str(id))]
        futures = self.confluent_client.describe_configs(requested_resources)
        (old_resource, future), = futures.items()
        future = ensure_kafka_futures_done([future])
        result = future.result()
        return unpack_confluent_config(result)