async def fixture_registry_async( request, loop, # pylint: disable=unused-argument tmp_path: Path, kafka_servers: KafkaServers, ) -> AsyncIterator[Optional[KarapaceSchemaRegistry]]: # Do not start a registry when the user provided an external service. Doing # so would cause this node to join the existing group and participate in # the election process. Without proper configuration for the listeners that # won't work and will cause test failures. rest_url = request.config.getoption("registry_url") if rest_url: yield None return config_path = tmp_path / "karapace_config.json" config = set_config_defaults({ "bootstrap_uri": kafka_servers.bootstrap_servers, # Using the default settings instead of random values, otherwise it # would not be possible to run the tests with external services. # Because of this every test must be written in such a way that it can # be executed twice with the same servers. # "topic_name": new_random_name("topic"), # "group_id": new_random_name("schema_registry") }) write_config(config_path, config) registry = KarapaceSchemaRegistry(config=config) await registry.get_master() try: yield registry finally: await registry.close()
async def fixture_registry_async( tmp_path: Path, kafka_server: Optional[KafkaConfig] ) -> AsyncIterator[KarapaceSchemaRegistry]: if not kafka_server: assert REGISTRY_URI in os.environ or REST_URI in os.environ instance, _ = mock_factory("registry")() yield instance else: config_path = tmp_path / "karapace_config.json" kafka_port = kafka_server.kafka_port config = set_config_defaults({ "log_level": "WARNING", "bootstrap_uri": f"127.0.0.1:{kafka_port}", "topic_name": new_random_name(), "group_id": new_random_name("schema_registry") }) write_config(config_path, config) registry = KarapaceSchemaRegistry(config_file_path=str(config_path), config=set_config_defaults(config)) await registry.get_master() try: yield registry finally: registry.close()
def main() -> int: parser = argparse.ArgumentParser( prog="karapace", description="Karapace: Your Kafka essentials in one tool") parser.add_argument("--version", action="version", help="show program version", version=karapace_version.__version__) parser.add_argument("config_file", help="configuration file path", type=argparse.FileType()) arg = parser.parse_args() with closing(arg.config_file): config = read_config(arg.config_file) config_file_path = arg.config_file.name logging.getLogger().setLevel(config["log_level"]) kc: RestApp if config["karapace_rest"] and config["karapace_registry"]: info_str = "both services" kc = KarapaceAll(config_file_path=config_file_path, config=config) elif config["karapace_rest"]: info_str = "karapace rest" kc = KafkaRest(config_file_path=config_file_path, config=config) elif config["karapace_registry"]: info_str = "karapace schema registry" kc = KarapaceSchemaRegistry(config_file_path=config_file_path, config=config) else: print("Both rest and registry options are disabled, exiting") return 1 print("=" * 100 + f"\nStarting {info_str}\n" + "=" * 100) try: kc.run(host=kc.config["host"], port=kc.config["port"]) except Exception: # pylint: disable-broad-except if kc.raven_client: kc.raven_client.captureException(tags={"where": "karapace"}) raise return 0
def main(): parser = argparse.ArgumentParser( prog="karapace", description="Karapace: Your Kafka essentials in one tool") parser.add_argument("--version", action="version", help="show program version", version=karapace_version.__version__) parser.add_argument("config_file", help="configuration file path") arg = parser.parse_args() if not os.path.exists(arg.config_file): print("Config file: {} does not exist, exiting".format( arg.config_file)) return 1 config = None kc = None info_str = "" try: config = read_config(arg.config_file) except InvalidConfiguration: print("Config file: {} is invalid, exiting".format(arg.config_file)) return 1 if config["karapace_rest"] and config["karapace_registry"]: info_str = "both services" kc = KarapaceAll(arg.config_file) elif config["karapace_rest"]: info_str = "karapace rest" kc = KafkaRest(arg.config_file) elif config["karapace_registry"]: info_str = "karapace schema registry" kc = KarapaceSchemaRegistry(arg.config_file) else: print("Both rest and registry options are disabled, exiting") return 1 print("=" * 100 + f"\nStarting {info_str}\n" + "=" * 100) try: return kc.run(host=kc.config["host"], port=kc.config["port"]) except Exception: # pylint: disable-broad-except if kc.raven_client: kc.raven_client.captureException(tags={"where": "karapace"}) raise
async def fixture_registry_async(session_tmpdir, kafka_server): if REGISTRY_URI in os.environ or REST_URI in os.environ: instance, _ = mock_factory("registry")() yield instance else: config_path = os.path.join(session_tmpdir(), "karapace_config.json") kafka_port = kafka_server["kafka_port"] write_config( config_path, { "log_level": "WARNING", "bootstrap_uri": f"127.0.0.1:{kafka_port}", "topic_name": new_random_name(), "group_id": new_random_name("schema_registry") }) registry = KarapaceSchemaRegistry(config_path) await registry.get_master() try: yield registry finally: registry.close()