13
13
from urllib3 .exceptions import HTTPWarning
14
14
15
15
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
17
17
from ydb .tools .ydbd_slice .kube import handlers as kube_handlers , docker
18
18
19
- warnings .filterwarnings ("ignore" , category = DeprecationWarning )
19
+ # warnings.filterwarnings("ignore", category=DeprecationWarning)
20
20
warnings .filterwarnings ("ignore" , category = HTTPWarning )
21
21
22
22
40
40
\033 [95msample-config\033 [94m - get sample configuration for cluster:
41
41
%(prog)s sample-config --cluster-type=block-4-2-8-nodes --output-file=cluster.yaml
42
42
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
+
43
46
\033 [95minstall\033 [94m - full install process from scratch:
44
47
%(prog)s install cluster.yaml --arcadia
45
48
@@ -254,9 +257,9 @@ def handler(signum, frame):
254
257
raise Terminate (signum , frame )
255
258
256
259
257
- def safe_load_cluster_details (cluster_yaml , walle_provider ):
260
+ def safe_load_cluster_details (cluster_yaml , walle_provider , validator = None ):
258
261
try :
259
- cluster_details = cluster_description .ClusterDetails (cluster_yaml , walle_provider )
262
+ cluster_details = cluster_description .ClusterDetails (cluster_yaml , walle_provider , validator = validator )
260
263
except IOError as io_err :
261
264
print ('' , file = sys .stderr )
262
265
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):
310
313
return result
311
314
312
315
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 ):
315
317
result = cluster_hosts
316
318
317
319
if args .nodes is not None :
@@ -547,6 +549,19 @@ def databases_config_path_args():
547
549
return args
548
550
549
551
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
+
550
565
def cluster_type_args ():
551
566
args = argparse .ArgumentParser (add_help = False )
552
567
available_erasure_types = [
@@ -628,38 +643,64 @@ def dispatch_run(func, args, walle_provider, need_confirmation=False):
628
643
629
644
logger .debug ("run func '%s' with cmd args is '%s'" , func .__name__ , args )
630
645
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
-
636
646
temp_dir = deduce_temp_dir_from_args (args )
647
+ kikimr_bin , kikimr_compressed_bin = deduce_kikimr_bin_from_args (args )
637
648
clear_tmp = not args .dry_run and args .temp_dir is None
638
649
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
+ )
640
668
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 )
648
670
649
671
v = vars (args )
650
672
clear_logs = v .get ('clear_logs' )
651
673
yav_version = v .get ('yav_version' )
674
+
675
+ nodes = deduce_nodes_from_args (args , configurator .hosts_names , args .ssh_user , args .ssh_key_path )
652
676
slice = handlers .Slice (
653
677
components ,
654
678
nodes ,
655
679
cluster_details ,
656
- configurator ,
680
+ kikimr_bin ,
681
+ kikimr_compressed_bin ,
657
682
clear_logs ,
658
683
yav_version ,
659
684
walle_provider ,
685
+ configurator ,
660
686
)
661
687
func (slice )
662
688
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
+
663
704
if clear_tmp :
664
705
logger .debug ("remove temp dirs '%s'" , temp_dir )
665
706
# shutil.rmtree(temp_dir)
@@ -699,6 +740,7 @@ def _run(args):
699
740
parents = [
700
741
direct_nodes_args (),
701
742
cluster_description_args (),
743
+ yaml_config_path_args (),
702
744
binaries_args (),
703
745
component_args (),
704
746
log_args (),
@@ -709,6 +751,13 @@ def _run(args):
709
751
description = "Full installation of the cluster from scratch. "
710
752
"You can use --hosts to specify particular hosts. But it is tricky." ,
711
753
)
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
+ )
712
761
mode .set_defaults (handler = _run )
713
762
714
763
@@ -722,6 +771,7 @@ def _run(args):
722
771
parents = [
723
772
direct_nodes_args (),
724
773
cluster_description_args (),
774
+ yaml_config_path_args (),
725
775
binaries_args (),
726
776
component_args (),
727
777
log_args (),
@@ -759,7 +809,14 @@ def _run(args):
759
809
760
810
mode = modes .add_parser (
761
811
"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
+ ],
763
820
description = "Stop ydbd static instances at the nodes. "
764
821
"If option components specified, try to stop particular component. "
765
822
"Use --hosts to specify particular hosts."
@@ -773,7 +830,14 @@ def _run(args):
773
830
774
831
mode = modes .add_parser (
775
832
"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
+ ],
777
841
description = "Start all ydbd instances at the nodes. "
778
842
"If option components specified, try to start particular component. "
779
843
"Otherwise only kikimr-multi-all will be started. "
@@ -791,6 +855,7 @@ def _run(args):
791
855
parents = [
792
856
direct_nodes_args (),
793
857
cluster_description_args (),
858
+ yaml_config_path_args (),
794
859
binaries_args (),
795
860
component_args (),
796
861
ssh_args (),
@@ -812,6 +877,7 @@ def _run(args):
812
877
parents = [
813
878
direct_nodes_args (),
814
879
cluster_description_args (),
880
+ yaml_config_path_args (),
815
881
binaries_args (),
816
882
component_args (),
817
883
ssh_args (),
@@ -861,6 +927,24 @@ def _run(args):
861
927
mode .set_defaults (handler = _run )
862
928
863
929
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
+
864
948
#
865
949
# docker and kube scenarios
866
950
def build_docker_image (build_args , docker_package , build_ydbd , image , force_rebuild ):
@@ -1413,6 +1497,7 @@ def main(walle_provider=None):
1413
1497
add_format_mode (modes , walle_provider )
1414
1498
add_explain_mode (modes , walle_provider )
1415
1499
add_sample_config_mode (modes )
1500
+ add_dynconfig_generator (modes )
1416
1501
1417
1502
add_docker_build_mode (modes )
1418
1503
add_docker_push_mode (modes )
@@ -1429,8 +1514,32 @@ def main(walle_provider=None):
1429
1514
1430
1515
args = parser .parse_args ()
1431
1516
logging .root .setLevel (args .log_level .upper ())
1432
- args .handler (args )
1433
1517
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 )
1434
1543
except KeyboardInterrupt :
1435
1544
sys .exit ('\n Stopped by KeyboardInterrupt.' )
1436
1545
except Terminate :
0 commit comments