|
8 | 8 | import string
|
9 | 9 | import typing # noqa: F401
|
10 | 10 | import sys
|
| 11 | +import yaml |
| 12 | +import copy |
11 | 13 | from six.moves.urllib.parse import urlparse
|
12 | 14 |
|
13 | 15 | from ydb.library.yql.providers.common.proto.gateways_config_pb2 import TGenericConnectorConfig
|
@@ -310,6 +312,54 @@ def enable_pqcd(arguments):
|
310 | 312 | return (getattr(arguments, 'enable_pqcd', False) or os.getenv('YDB_ENABLE_PQCD') == 'true')
|
311 | 313 |
|
312 | 314 |
|
| 315 | +def merge_two_yaml_configs(data_1, data_2): |
| 316 | + _check_types_for_merge(data_1, data_2) |
| 317 | + if isinstance(data_1, dict) and isinstance(data_2, dict): |
| 318 | + data_1, data_2 = data_1.copy(), data_2.copy() |
| 319 | + new_dict = {} |
| 320 | + d2_keys = list(data_2.keys()) |
| 321 | + for d1k in data_1.keys(): |
| 322 | + if d1k in d2_keys: |
| 323 | + d2_keys.remove(d1k) |
| 324 | + new_dict[d1k] = merge_two_yaml_configs(data_1.get(d1k), data_2.get(d1k)) |
| 325 | + else: |
| 326 | + new_dict[d1k] = copy.deepcopy(data_1.get(d1k)) |
| 327 | + |
| 328 | + for d2k in d2_keys: |
| 329 | + new_dict[d2k] = copy.deepcopy(data_2.get(d2k)) |
| 330 | + |
| 331 | + return new_dict |
| 332 | + else: |
| 333 | + if data_2 is None: |
| 334 | + return copy.deepcopy(data_1) |
| 335 | + else: |
| 336 | + return copy.deepcopy(data_2) |
| 337 | + |
| 338 | + |
| 339 | +def _check_types_for_merge(data_1, data_2): |
| 340 | + if isinstance(data_1, dict) and isinstance(data_2, dict): |
| 341 | + return |
| 342 | + if isinstance(data_1, list) and isinstance(data_2, list): |
| 343 | + return |
| 344 | + if data_1 is None and data_2 is None: |
| 345 | + return |
| 346 | + if (data_1 is None and isinstance(data_2, list)) or (data_2 is None and isinstance(data_1, list)): |
| 347 | + return |
| 348 | + if (data_1 is None and isinstance(data_2, dict)) or (data_2 is None and isinstance(data_1, dict)): |
| 349 | + return |
| 350 | + raise TypeError("Type mismatch - " + str(type(data_1)) + " data_1 cannot be merged with " + str(type(data_2)) + " data_2") |
| 351 | + |
| 352 | + |
| 353 | +def get_additional_yaml_config(arguments, path): |
| 354 | + if arguments.ydb_working_dir: |
| 355 | + with open(os.path.join(arguments.ydb_working_dir, path)) as fh: |
| 356 | + additional_yaml_config = yaml.load(fh, Loader=yaml.FullLoader) |
| 357 | + else: |
| 358 | + raise Exception("No working directory") |
| 359 | + |
| 360 | + return additional_yaml_config |
| 361 | + |
| 362 | + |
313 | 363 | def deploy(arguments):
|
314 | 364 | initialize_working_dir(arguments)
|
315 | 365 | recipe = Recipe(arguments)
|
@@ -374,6 +424,10 @@ def deploy(arguments):
|
374 | 424 | **optionals
|
375 | 425 | )
|
376 | 426 |
|
| 427 | + if os.getenv("YDB_CONFIG_PATCH") is not None: |
| 428 | + additional_yaml_config = get_additional_yaml_config(arguments, os.getenv("YDB_CONFIG_PATCH")) |
| 429 | + configuration.yaml_config = merge_two_yaml_configs(configuration.yaml_config, additional_yaml_config) |
| 430 | + |
377 | 431 | cluster = kikimr_cluster_factory(configuration)
|
378 | 432 | cluster.start()
|
379 | 433 |
|
|
0 commit comments