Skip to content

Commit 4ca7f5c

Browse files
authored
Feature/ydbd slice/allow slice creation using raw config yaml (#12762)
YdbWorkloadTopic.Full_Statistics_UseTx is muted now
1 parent f036a6c commit 4ca7f5c

File tree

9 files changed

+710
-24
lines changed

9 files changed

+710
-24
lines changed

ydb/tools/cfg/base.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def normalize_domain(domain_name):
264264

265265

266266
class ClusterDetailsProvider(object):
267-
def __init__(self, template, walle_provider, validator=None, database=None):
267+
def __init__(self, template, walle_provider, validator=None, database=None, use_new_style_cfg=False):
268268
if not validator:
269269
validator = validation.default_validator()
270270

@@ -286,7 +286,7 @@ def __init__(self, template, walle_provider, validator=None, database=None):
286286
self.__racks = {}
287287
self.__bodies = {}
288288
self.__dcs = {}
289-
self.use_new_style_kikimr_cfg = self.__cluster_description.get("use_new_style_kikimr_cfg", False)
289+
self.use_new_style_kikimr_cfg = self.__cluster_description.get("use_new_style_kikimr_cfg", use_new_style_cfg)
290290
self.need_generate_app_config = self.__cluster_description.get("need_generate_app_config", False)
291291
self.need_txt_files = self.__cluster_description.get("need_txt_files", True)
292292
self.use_auto_config = self.__cluster_description.get("use_auto_config", False)
@@ -297,6 +297,7 @@ def __init__(self, template, walle_provider, validator=None, database=None):
297297
self.table_profiles_config = self.__cluster_description.get("table_profiles_config")
298298
self.http_proxy_config = self.__cluster_description.get("http_proxy_config")
299299
self.blob_storage_config = self.__cluster_description.get("blob_storage_config")
300+
self.channel_profile_config = self.__cluster_description.get("channel_profile_config")
300301
self.pdisk_key_config = self.__cluster_description.get("pdisk_key_config", {})
301302
if not self.need_txt_files and not self.use_new_style_kikimr_cfg:
302303
assert "cannot remove txt files without new style kikimr cfg!"
@@ -353,16 +354,25 @@ def forbid_implicit_storage_pools(self):
353354
def _get_datacenter(self, host_description):
354355
if host_description.get("datacenter") is not None:
355356
return str(host_description.get("datacenter"))
357+
dc = host_description.get("location", {}).get("data_center", None)
358+
if dc:
359+
return str(dc)
356360
return str(self._walle.get_datacenter(host_description.get("name", host_description.get("host"))))
357361

358362
def _get_rack(self, host_description):
359363
if host_description.get("rack") is not None:
360364
return str(host_description.get("rack"))
365+
rack = host_description.get("location", {}).get("rack", None)
366+
if rack:
367+
return str(rack)
361368
return str(self._walle.get_rack(host_description.get("name", host_description.get("host"))))
362369

363370
def _get_body(self, host_description):
364371
if host_description.get("body") is not None:
365372
return str(host_description.get("body"))
373+
body = host_description.get("location", {}).get("body", None)
374+
if body:
375+
return str(body)
366376
return str(self._walle.get_body(host_description.get("name", host_description.get("host"))))
367377

368378
def _collect_drives_info(self, host_description):
@@ -555,14 +565,16 @@ def domains(self):
555565
domain_name = domain.get("domain_name")
556566

557567
storage_pool_kinds = {
558-
pool_kind.get("kind"): self.__storage_pool_kind(pool_kind) for pool_kind in domain.get("storage_pool_kinds", [])
568+
pool_kind.get("kind"): self.__storage_pool_kind(pool_kind)
569+
for pool_kind in domain.get("storage_pool_kinds", [])
559570
}
560571
assert len(set(storage_pool_kinds.keys())) == len(
561572
storage_pool_kinds.keys()
562573
), "required unique kind value in storage_pool_kinds items"
563574

564575
storage_pools = [
565-
self.__storage_pool(storage_pool_kinds, pool_instance, domain_name) for pool_instance in domain.get("storage_pools", [])
576+
self.__storage_pool(storage_pool_kinds, pool_instance, domain_name)
577+
for pool_instance in domain.get("storage_pools", [])
566578
]
567579

568580
domains.append(
@@ -604,7 +616,9 @@ def nw_cache_file_path(self):
604616

605617
@property
606618
def fail_domain_type(self):
607-
return types.FailDomainType.from_string(str(self.__cluster_description.get("fail_domain_type", DEFAULT_FAIL_DOMAIN_TYPE)))
619+
return types.FailDomainType.from_string(
620+
str(self.__cluster_description.get("fail_domain_type", DEFAULT_FAIL_DOMAIN_TYPE))
621+
)
608622

609623
@property
610624
def min_fail_domains(self):

ydb/tools/cfg/static.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,14 @@ def get_normalized_config(self):
510510
if 'pdisk_config' in vdisk_location:
511511
if 'expected_slot_count' in vdisk_location['pdisk_config']:
512512
vdisk_location['pdisk_config']['expected_slot_count'] = int(vdisk_location['pdisk_config']['expected_slot_count'])
513-
if 'channel_profile_config' in normalized_config:
514-
for profile in normalized_config['channel_profile_config']['profile']:
515-
for channel in profile['channel']:
516-
channel['pdisk_category'] = int(channel['pdisk_category'])
513+
if self.__cluster_details.channel_profile_config is not None:
514+
normalized_config["channel_profile_config"] = self.__cluster_details.channel_profile_config
515+
else:
516+
if 'channel_profile_config' in normalized_config:
517+
for profile in normalized_config['channel_profile_config']['profile']:
518+
for channel in profile['channel']:
519+
print(channel)
520+
channel['pdisk_category'] = int(channel['pdisk_category'])
517521
if 'system_tablets' in normalized_config:
518522
for tablets in normalized_config['system_tablets'].values():
519523
for tablet in tablets:
@@ -754,6 +758,8 @@ def __generate_bs_txt(self):
754758
dc_enumeration = {}
755759

756760
if not self.__cluster_details.get_service("static_groups"):
761+
if self.__cluster_details.blob_storage_config:
762+
return
757763
self.__proto_configs["bs.txt"] = self._read_generated_bs_config(
758764
str(self.__cluster_details.static_erasure),
759765
str(self.__cluster_details.min_fail_domains),
@@ -835,13 +841,17 @@ def __generate_bs_txt(self):
835841
if self.__cluster_details.nw_cache_file_path is not None:
836842
self.__proto_configs["bs.txt"].CacheFilePath = self.__cluster_details.nw_cache_file_path
837843

838-
def _read_generated_bs_config(self, static_erasure, min_fail_domains, static_pdisk_type, fail_domain_type, bs_format_config):
844+
def _read_generated_bs_config(
845+
self, static_erasure, min_fail_domains, static_pdisk_type, fail_domain_type, bs_format_config
846+
):
839847
result = config_pb2.TBlobStorageConfig()
840848

841-
with tempfile.NamedTemporaryFile(delete=True) as t_file:
849+
with tempfile.NamedTemporaryFile(delete=False) as t_file:
842850
utils.write_proto_to_file(t_file.name, bs_format_config)
843851

844-
rx_begin, rx_end, dx_begin, dx_end = types.DistinctionLevels[types.FailDomainType.from_string(fail_domain_type)]
852+
rx_begin, rx_end, dx_begin, dx_end = types.DistinctionLevels[
853+
types.FailDomainType.from_string(fail_domain_type)
854+
]
845855

846856
cmd_base = [
847857
self.__local_binary_path,

ydb/tools/ydbd_slice/__init__.py

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import sys
33
import json
44
import signal
5-
import shutil
65
import tempfile
76
import logging
87
import argparse
98
import subprocess
109
import warnings
10+
11+
import library.python.resource as rs
12+
1113
from urllib3.exceptions import HTTPWarning
1214

1315
from ydb.tools.cfg.walle import NopHostsInformationProvider
@@ -499,7 +501,42 @@ def ssh_args():
499501
metavar="SSH_USER",
500502
default=current_user,
501503
help="user for ssh interaction with slice. Default value is $USER "
502-
"(which equals {user} now)".format(user=current_user),
504+
"(which equals {user} now)".format(user=current_user),
505+
)
506+
return args
507+
508+
509+
def databases_config_path_args():
510+
args = argparse.ArgumentParser(add_help=False)
511+
args.add_argument(
512+
"--databases-config",
513+
metavar="DATABASES_CONFIG",
514+
default="",
515+
required=False,
516+
help="Path to file with databases configuration",
517+
)
518+
return args
519+
520+
521+
def cluster_type_args():
522+
args = argparse.ArgumentParser(add_help=False)
523+
args.add_argument(
524+
"--cluster-type",
525+
metavar="CLUSTER_TYPE",
526+
required=True,
527+
help="Erasure type for slice",
528+
choices=["block-4-2-8-nodes", "mirror-3-dc-3-nodes-in-memory", "mirror-3-dc-3-nodes", "mirror-3-dc-9-nodes"],
529+
)
530+
return args
531+
532+
533+
def output_file():
534+
args = argparse.ArgumentParser(add_help=False)
535+
args.add_argument(
536+
"--output-file",
537+
metavar="OUTPUT_FILE",
538+
required=False,
539+
help="File to save cluster configuration",
503540
)
504541
return args
505542

@@ -583,7 +620,7 @@ def dispatch_run(func, args, walle_provider):
583620

584621
if clear_tmp:
585622
logger.debug("remove temp dirs '%s'", temp_dir)
586-
shutil.rmtree(temp_dir)
623+
# shutil.rmtree(temp_dir)
587624

588625

589626
def add_install_mode(modes, walle_provider):
@@ -593,9 +630,17 @@ def _run(args):
593630
mode = modes.add_parser(
594631
"install",
595632
conflict_handler='resolve',
596-
parents=[direct_nodes_args(), cluster_description_args(), binaries_args(), component_args(), log_args(), ssh_args()],
633+
parents=[
634+
direct_nodes_args(),
635+
cluster_description_args(),
636+
binaries_args(),
637+
component_args(),
638+
log_args(),
639+
ssh_args(),
640+
# databases_config_path_args(),
641+
],
597642
description="Full installation of the cluster from scratch. "
598-
"You can use --hosts to specify particular hosts. But it is tricky."
643+
"You can use --hosts to specify particular hosts. But it is tricky.",
599644
)
600645
mode.set_defaults(handler=_run)
601646

@@ -672,7 +717,7 @@ def _run(args):
672717
"clear",
673718
parents=[direct_nodes_args(), cluster_description_args(), binaries_args(), component_args(), ssh_args()],
674719
description="Stop all kikimr instances at the nodes, format all kikimr drivers, shutdown dynamic slots. "
675-
"And don't start nodes afrer it. "
720+
"And don't start nodes after it. "
676721
"Use --hosts to specify particular hosts."
677722
)
678723
mode.set_defaults(handler=_run)
@@ -686,12 +731,42 @@ def _run(args):
686731
"format",
687732
parents=[direct_nodes_args(), cluster_description_args(), binaries_args(), component_args(), ssh_args()],
688733
description="Stop all kikimr instances at the nodes, format all kikimr drivers at the nodes, start the instances. "
689-
"If you call format for all cluster, you will spoil it. "
690-
"Additional dynamic configuration will required after it. "
691-
"If you call format for few nodes, cluster will regenerate after it. "
692-
"Use --hosts to specify particular hosts."
734+
"If you call format for all cluster, you will spoil it. "
735+
"Additional dynamic configuration will required after it. "
736+
"If you call format for few nodes, cluster will regenerate after it. "
737+
"Use --hosts to specify particular hosts.",
738+
)
739+
mode.set_defaults(handler=_run)
740+
693741

742+
def add_sample_config_mode(modes):
743+
def _run(args):
744+
cluster_type = args.cluster_type
745+
template_path = ""
746+
if cluster_type == "block-4-2-8-nodes":
747+
template_path = "/ydbd_slice/baremetal/templates/block-4-2-8-nodes.yaml"
748+
elif cluster_type == "mirror-3-dc-3-nodes-in-memory":
749+
pass
750+
elif cluster_type == "mirror-3-dc-3-nodes":
751+
template_path = "/ydbd_slice/baremetal/templates/mirror-3-dc-3-nodes.yaml"
752+
elif cluster_type == "mirror-3-dc-9-nodes":
753+
template_path = "/ydbd_slice/baremetal/templates/mirror-3-dc-9-nodes.yaml"
754+
else:
755+
raise "Unreachable code" # TODO(shmel1k@): improve error
756+
757+
f = rs.find(template_path).decode()
758+
if args.output_file is not None and args.output_file != "":
759+
with open(args.output_file, "w+") as f1:
760+
f1.write(f)
761+
else:
762+
print(f)
763+
764+
mode = modes.add_parser(
765+
"sample-config",
766+
parents=[cluster_type_args(), output_file()],
767+
description="Generate default mock-configuration for provided cluster-type"
694768
)
769+
695770
mode.set_defaults(handler=_run)
696771

697772

@@ -1205,6 +1280,8 @@ def main(walle_provider=None):
12051280
add_clear_mode(modes, walle_provider)
12061281
add_format_mode(modes, walle_provider)
12071282
add_explain_mode(modes, walle_provider)
1283+
add_sample_config_mode(modes)
1284+
12081285
add_docker_build_mode(modes)
12091286
add_kube_generate_mode(modes)
12101287
add_kube_install_mode(modes)

0 commit comments

Comments
 (0)