Exemplo n.º 1
0
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)

    kc = KarapaceSchemaRegistry(config_file_path=arg.config_file.name,
                                config=config)
    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
Exemplo n.º 2
0
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)

    logging.basicConfig(level=logging.INFO, format=DEFAULT_LOG_FORMAT_JOURNAL)
    logging.getLogger().setLevel(config["log_level"])
    kc = KarapaceSchemaRegistry(config=config)
    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
Exemplo n.º 3
0
    def __init__(self, config_path: str, backup_path: str, topic_option: Optional[str] = None) -> None:
        with open(config_path) as handler:
            self.config = read_config(handler)

        self.backup_location = backup_path
        self.topic_name = topic_option or self.config["topic_name"]
        self.log = logging.getLogger("SchemaBackup")
        self.consumer = None
        self.producer = None
        self.admin_client = None
        self.timeout_ms = 1000
Exemplo n.º 4
0
async def make_ser_deser(config_path, mock_client):
    with open(config_path) as handler:
        config = read_config(handler)
    serializer = SchemaRegistrySerializer(config_path=config_path,
                                          config=config)
    deserializer = SchemaRegistryDeserializer(config_path=config_path,
                                              config=config)
    await serializer.registry_client.close()
    await deserializer.registry_client.close()
    serializer.registry_client = mock_client
    deserializer.registry_client = mock_client
    return serializer, deserializer
Exemplo n.º 5
0
 def __init__(self, **cfg):
     if not cfg.get("config_path"):
         raise ValueError("config_path is empty or missing")
     config_path = cfg["config_path"]
     self.config = read_config(config_path)
     self.state_lock = asyncio.Lock()
     registry_url = f"http://{self.config['registry_host']}:{self.config['registry_port']}"
     registry_client = SchemaRegistryClient(registry_url)
     self.subject_name_strategy = NAME_STRATEGIES[cfg.get(
         "name_strategy", "topic_name")]
     self.registry_client = registry_client
     self.ids_to_schemas = {}
     self.schemas_to_ids = {}
Exemplo n.º 6
0
 def __init__(
         self,
         config_path: str,
         name_strategy: str = "topic_name",
         **cfg,  # pylint: disable=unused-argument
 ) -> None:
     self.config = read_config(config_path)
     self.state_lock = asyncio.Lock()
     registry_url = f"http://{self.config['registry_host']}:{self.config['registry_port']}"
     registry_client = SchemaRegistryClient(registry_url)
     self.subject_name_strategy = NAME_STRATEGIES[name_strategy]
     self.registry_client: Optional[SchemaRegistryClient] = registry_client
     self.ids_to_schemas: Dict[int, TypedSchema] = {}
     self.schemas_to_ids: Dict[str, int] = {}
Exemplo n.º 7
0
def main() -> int:
    args = parse_args()

    with open(args.config) as handler:
        config = read_config(handler)

    sb = SchemaBackup(config, args.location, args.topic)

    if args.command == "get":
        sb.request_backup()
        return 0
    if args.command == "restore":
        sb.restore_backup()
        return 0
    return 1
Exemplo n.º 8
0
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
Exemplo n.º 9
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
Exemplo n.º 10
0
 def read_config(config_path):
     return read_config(config_path)