1313from urllib3 .exceptions import HTTPWarning
1414
1515from 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
1717from ydb .tools .ydbd_slice .kube import handlers as kube_handlers , docker
1818
19- warnings .filterwarnings ("ignore" , category = DeprecationWarning )
19+ # warnings.filterwarnings("ignore", category=DeprecationWarning)
2020warnings .filterwarnings ("ignore" , category = HTTPWarning )
2121
2222
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+
550565def 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
866950def 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 ('\n Stopped by KeyboardInterrupt.' )
14361545 except Terminate :
0 commit comments