Skip to content

Commit a2d04ce

Browse files
authored
Merge eb7ce73 into 6abead2
2 parents 6abead2 + eb7ce73 commit a2d04ce

File tree

7 files changed

+357
-31
lines changed

7 files changed

+357
-31
lines changed

ydb/tools/cfg/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ def domains(self):
622622
)
623623
return domains
624624

625+
@domains.setter
626+
def domains(self, values):
627+
self.__cluster_description["domains"] = values
628+
625629
@property
626630
def domains_config(self):
627631
domains_config_dict = self.__cluster_description.get("domains_config", {})

ydb/tools/ydbd_slice/__init__.py

Lines changed: 132 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
from urllib3.exceptions import HTTPWarning
1414

1515
from ydb.tools.cfg.walle import NopHostsInformationProvider
16-
from ydb.tools.ydbd_slice import nodes, handlers, cluster_description
16+
from ydb.tools.ydbd_slice import nodes, handlers, cluster_description, yaml_configurator
1717
from ydb.tools.ydbd_slice.kube import handlers as kube_handlers, docker
1818

19-
warnings.filterwarnings("ignore", category=DeprecationWarning)
19+
# warnings.filterwarnings("ignore", category=DeprecationWarning)
2020
warnings.filterwarnings("ignore", category=HTTPWarning)
2121

2222

@@ -40,6 +40,9 @@
4040
\033[95msample-config\033[94m - get sample configuration for cluster:
4141
%(prog)s sample-config --cluster-type=block-4-2-8-nodes --output-file=cluster.yaml
4242
43+
\033[95mdynconfig-generator\033[94m - generate simple dynamic configuration for cluster:
44+
%(prog)s dynconfig-generator --yaml-config=config.yaml --output-file=dynconfig.yaml
45+
4346
\033[95minstall\033[94m - full install process from scratch:
4447
%(prog)s install cluster.yaml --arcadia
4548
@@ -254,9 +257,9 @@ def handler(signum, frame):
254257
raise Terminate(signum, frame)
255258

256259

257-
def safe_load_cluster_details(cluster_yaml, walle_provider):
260+
def safe_load_cluster_details(cluster_yaml, walle_provider, validator=None):
258261
try:
259-
cluster_details = cluster_description.ClusterDetails(cluster_yaml, walle_provider)
262+
cluster_details = cluster_description.ClusterDetails(cluster_yaml, walle_provider, validator=validator)
260263
except IOError as io_err:
261264
print('', file=sys.stderr)
262265
print("unable to open YAML params as a file, check args", file=sys.stderr)
@@ -310,8 +313,7 @@ def deduce_components_from_args(args, cluster_details):
310313
return result
311314

312315

313-
def deduce_nodes_from_args(args, walle_provider, ssh_user, ssh_key_path):
314-
cluster_hosts = safe_load_cluster_details(args.cluster, walle_provider).hosts_names
316+
def deduce_nodes_from_args(args, cluster_hosts, ssh_user, ssh_key_path):
315317
result = cluster_hosts
316318

317319
if args.nodes is not None:
@@ -547,6 +549,19 @@ def databases_config_path_args():
547549
return args
548550

549551

552+
def yaml_config_path_args():
553+
args = argparse.ArgumentParser(add_help=False)
554+
args.add_argument(
555+
"--yaml-config",
556+
metavar="YAML_CONFIG",
557+
default="",
558+
required=False,
559+
help="Path to file with config.yaml configuration",
560+
)
561+
562+
return args
563+
564+
550565
def cluster_type_args():
551566
args = argparse.ArgumentParser(add_help=False)
552567
available_erasure_types = [
@@ -628,38 +643,64 @@ def dispatch_run(func, args, walle_provider, need_confirmation=False):
628643

629644
logger.debug("run func '%s' with cmd args is '%s'", func.__name__, args)
630645

631-
cluster_details = safe_load_cluster_details(args.cluster, walle_provider)
632-
components = deduce_components_from_args(args, cluster_details)
633-
634-
nodes = deduce_nodes_from_args(args, walle_provider, args.ssh_user, args.ssh_key_path)
635-
636646
temp_dir = deduce_temp_dir_from_args(args)
647+
kikimr_bin, kikimr_compressed_bin = deduce_kikimr_bin_from_args(args)
637648
clear_tmp = not args.dry_run and args.temp_dir is None
638649

639-
kikimr_bin, kikimr_compressed_bin = deduce_kikimr_bin_from_args(args)
650+
if args.yaml_config:
651+
configurator = yaml_configurator.YamlConfigurator(
652+
args.cluster,
653+
temp_dir,
654+
kikimr_bin,
655+
kikimr_compressed_bin,
656+
args.yaml_config
657+
)
658+
cluster_details = configurator.cluster_description
659+
else:
660+
cluster_details = safe_load_cluster_details(args.cluster, walle_provider)
661+
configurator = cluster_description.Configurator(
662+
cluster_details,
663+
out_dir=temp_dir,
664+
kikimr_bin=kikimr_bin,
665+
kikimr_compressed_bin=kikimr_compressed_bin,
666+
walle_provider=walle_provider
667+
)
640668

641-
configurator = cluster_description.Configurator(
642-
cluster_details,
643-
out_dir=temp_dir,
644-
kikimr_bin=kikimr_bin,
645-
kikimr_compressed_bin=kikimr_compressed_bin,
646-
walle_provider=walle_provider
647-
)
669+
components = deduce_components_from_args(args, cluster_details)
648670

649671
v = vars(args)
650672
clear_logs = v.get('clear_logs')
651673
yav_version = v.get('yav_version')
674+
675+
nodes = deduce_nodes_from_args(args, configurator.hosts_names, args.ssh_user, args.ssh_key_path)
652676
slice = handlers.Slice(
653677
components,
654678
nodes,
655679
cluster_details,
656-
configurator,
680+
kikimr_bin,
681+
kikimr_compressed_bin,
657682
clear_logs,
658683
yav_version,
659684
walle_provider,
685+
configurator,
660686
)
661687
func(slice)
662688

689+
# used only for configurator and will be removed soon
690+
save_raw_cfg = v.get('save_raw_cfg')
691+
if save_raw_cfg and configurator:
692+
logger.debug("save raw cfg to '%s'", save_raw_cfg)
693+
for root, dirs, files in os.walk(temp_dir):
694+
for dir in dirs:
695+
os.makedirs(os.path.join(save_raw_cfg, dir), 0o755, exist_ok=True)
696+
697+
for file in files:
698+
src = os.path.join(root, file)
699+
dst = os.path.join(save_raw_cfg, os.path.relpath(src, temp_dir))
700+
with open(src, 'r') as src_f:
701+
with open(dst, 'w') as dst_f:
702+
dst_f.write(src_f.read())
703+
663704
if clear_tmp:
664705
logger.debug("remove temp dirs '%s'", temp_dir)
665706
# shutil.rmtree(temp_dir)
@@ -699,6 +740,7 @@ def _run(args):
699740
parents=[
700741
direct_nodes_args(),
701742
cluster_description_args(),
743+
yaml_config_path_args(),
702744
binaries_args(),
703745
component_args(),
704746
log_args(),
@@ -709,6 +751,13 @@ def _run(args):
709751
description="Full installation of the cluster from scratch. "
710752
"You can use --hosts to specify particular hosts. But it is tricky.",
711753
)
754+
mode.add_argument(
755+
"--save-raw-cfg",
756+
metavar="DIR",
757+
required=False,
758+
default="",
759+
help="Directory to save all static configuration files generated by configuration.create_static_cfg and configuration.create_dynamic_cfg",
760+
)
712761
mode.set_defaults(handler=_run)
713762

714763

@@ -722,6 +771,7 @@ def _run(args):
722771
parents=[
723772
direct_nodes_args(),
724773
cluster_description_args(),
774+
yaml_config_path_args(),
725775
binaries_args(),
726776
component_args(),
727777
log_args(),
@@ -759,7 +809,14 @@ def _run(args):
759809

760810
mode = modes.add_parser(
761811
"stop",
762-
parents=[direct_nodes_args(), cluster_description_args(), binaries_args(), component_args(), ssh_args()],
812+
parents=[
813+
direct_nodes_args(),
814+
cluster_description_args(),
815+
yaml_config_path_args(),
816+
binaries_args(),
817+
component_args(),
818+
ssh_args()
819+
],
763820
description="Stop ydbd static instances at the nodes. "
764821
"If option components specified, try to stop particular component. "
765822
"Use --hosts to specify particular hosts."
@@ -773,7 +830,14 @@ def _run(args):
773830

774831
mode = modes.add_parser(
775832
"start",
776-
parents=[direct_nodes_args(), cluster_description_args(), binaries_args(), component_args(), ssh_args()],
833+
parents=[
834+
direct_nodes_args(),
835+
cluster_description_args(),
836+
yaml_config_path_args(),
837+
binaries_args(),
838+
component_args(),
839+
ssh_args()
840+
],
777841
description="Start all ydbd instances at the nodes. "
778842
"If option components specified, try to start particular component. "
779843
"Otherwise only kikimr-multi-all will be started. "
@@ -791,6 +855,7 @@ def _run(args):
791855
parents=[
792856
direct_nodes_args(),
793857
cluster_description_args(),
858+
yaml_config_path_args(),
794859
binaries_args(),
795860
component_args(),
796861
ssh_args(),
@@ -812,6 +877,7 @@ def _run(args):
812877
parents=[
813878
direct_nodes_args(),
814879
cluster_description_args(),
880+
yaml_config_path_args(),
815881
binaries_args(),
816882
component_args(),
817883
ssh_args(),
@@ -861,6 +927,24 @@ def _run(args):
861927
mode.set_defaults(handler=_run)
862928

863929

930+
def add_dynconfig_generator(modes):
931+
def _run(args):
932+
if args.yaml_config:
933+
yaml_config = yaml_configurator.YamlConfig(args.yaml_config)
934+
935+
if args.output_file is not None and args.output_file:
936+
with open(args.output_file, "w") as output:
937+
output.write(yaml_config.dynamic_simple)
938+
939+
mode = modes.add_parser(
940+
"dynconfig-generator",
941+
parents=[yaml_config_path_args(), output_file()],
942+
description="Generate a minimalistic dynconfig.yaml for the provided config.yaml"
943+
)
944+
945+
mode.set_defaults(handler=_run)
946+
947+
864948
#
865949
# docker and kube scenarios
866950
def build_docker_image(build_args, docker_package, build_ydbd, image, force_rebuild):
@@ -1413,6 +1497,7 @@ def main(walle_provider=None):
14131497
add_format_mode(modes, walle_provider)
14141498
add_explain_mode(modes, walle_provider)
14151499
add_sample_config_mode(modes)
1500+
add_dynconfig_generator(modes)
14161501

14171502
add_docker_build_mode(modes)
14181503
add_docker_push_mode(modes)
@@ -1429,8 +1514,32 @@ def main(walle_provider=None):
14291514

14301515
args = parser.parse_args()
14311516
logging.root.setLevel(args.log_level.upper())
1432-
args.handler(args)
14331517

1518+
if not hasattr(args, 'handler'):
1519+
parser.print_help()
1520+
return
1521+
1522+
if not args.yaml_config:
1523+
warnings.warn(
1524+
'''
1525+
Using cluster.yaml for cluster configuration is deprecated.
1526+
Only the 'domains' section should be filled with database and slot configurations.
1527+
The config.yaml should be passed as a raw file through the --yaml-config.
1528+
1529+
Example:
1530+
ydbd_slice install cluster.yaml all --binary /path/to/ydbd --yaml-config /path/to/config.yaml
1531+
1532+
To save the resulting configuration files from an old cluster.yaml, use the --save-raw-cfg option.
1533+
1534+
Example:
1535+
ydbd_slice install cluster.yaml all --binary /path/to/ydbd --save-raw-cfg /path/to/save
1536+
1537+
The resulting configuration files will be saved in the /path/to/save directory. You can find config.yaml in the /path/to/save/kikimr-static directory.
1538+
''',
1539+
DeprecationWarning
1540+
)
1541+
1542+
args.handler(args)
14341543
except KeyboardInterrupt:
14351544
sys.exit('\nStopped by KeyboardInterrupt.')
14361545
except Terminate:

ydb/tools/ydbd_slice/cluster_description.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class ClusterDetails(ClusterDetailsProvider):
2727
SLOTS_PORTS_START = 31000
2828
PORTS_SHIFT = 10
2929

30-
def __init__(self, cluster_description_path, walle_provider):
30+
def __init__(self, cluster_description_path, walle_provider, validator=None):
3131
self.__template = None
3232
self.__details = None
3333
self.__databases = None
3434
self.__dynamic_slots = None
3535
self._cluster_description_file = cluster_description_path
3636
self._walle_provider = walle_provider
3737

38-
super(ClusterDetails, self).__init__(self.template, self._walle_provider, use_new_style_cfg=True)
38+
super(ClusterDetails, self).__init__(self.template, self._walle_provider, validator=validator, use_new_style_cfg=True)
3939

4040
@property
4141
def template(self):
@@ -132,6 +132,10 @@ def template(self):
132132
def detail(self):
133133
return self.__cluster_details
134134

135+
@property
136+
def hosts_names(self):
137+
return self.detail.hosts_names
138+
135139
@staticmethod
136140
def _generate_fake_keys():
137141
content = 'Keys {\n'
@@ -140,6 +144,7 @@ def _generate_fake_keys():
140144
content += ' Id: "fake-secret"\n'
141145
content += ' Version: 1\n'
142146
content += '}\n'
147+
143148
return content
144149

145150
@staticmethod

0 commit comments

Comments
 (0)