Skip to content

Commit

Permalink
fix: nameservice_config backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres committed Jan 23, 2025
1 parent dffe95a commit eefa7f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
7 changes: 4 additions & 3 deletions ydb/tools/cfg/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,8 @@ def __generate_log_txt(self):

def __generate_names_txt(self):
self.__proto_configs["names.txt"] = config_pb2.TStaticNameserviceConfig()
json_format.ParseDict(utils.convert_keys(self.__cluster_details.nameservice_config), self.names_txt)
if self.__cluster_details.nameservice_config is not None:
utils.wrap_parse_dict(self.__cluster_details.nameservice_config, self.names_txt)

for host in self.__cluster_details.hosts:
node = self.names_txt.Node.add(
Expand Down Expand Up @@ -1254,7 +1255,7 @@ def __generate_names_txt(self):
# cluster_uuid can be initialized from `nameservice_config` proto, same as `config.yaml`,
# OR in the old manner, through `cluster_uuid: ...` key in `template.yaml`
cluster_uuid = self.names_txt.ClusterUUID # already read from proto
if cluster_uuid is None:
if len(cluster_uuid) == 0:
cluster_uuid = self.__cluster_details.cluster_uuid # fall back to `cluster_uuid: ...`

cluster_uuid = "ydb:{}".format(utils.uuid()) if cluster_uuid is None else cluster_uuid
Expand Down Expand Up @@ -1289,7 +1290,7 @@ def __generate_tracing_txt(self):
pb = config_pb2.TAppConfig()
if self.__tracing:
tracing_pb = pb.TracingConfig
json_format.ParseDict(utils.convert_keys(self.__tracing), tracing_pb)
utils.wrap_parse_dict(self.__tracing, tracing_pb)
self.__proto_configs["tracing.txt"] = pb

def __generate_sys_txt_advanced(self):
Expand Down
39 changes: 24 additions & 15 deletions ydb/tools/cfg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,27 @@ def random_int(low, high, *seed):
return random.randint(low, high)


def get_camel_case_string(snake_str):
abbreviations = {
'uuid': 'UUID',
}
components = snake_str.split('_')
return ''.join(abbreviations.get(x.lower(), x.capitalize()) for x in components)


def convert_keys(data):
if isinstance(data, dict):
return {get_camel_case_string(k): convert_keys(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_keys(item) for item in data]
else:
return data
def wrap_parse_dict(dictionary, proto):
def get_camel_case_string(snake_str):
components = snake_str.split('_')
camelCased = ''.join(x.capitalize() for x in components)
abbreviations = {
'Uuid': 'UUID',
'Pdisk': 'PDisk',
'Vdisk': 'VDisk',
'NtoSelect': 'NToSelect',
'Ssid': 'SSId',
}
for k, v in abbreviations.items():
camelCased = camelCased.replace(k, v)
return camelCased

def convert_keys(data):
if isinstance(data, dict):
return {get_camel_case_string(k): convert_keys(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_keys(item) for item in data]
else:
return data

json_format.ParseDict(convert_keys(dictionary), proto)

0 comments on commit eefa7f6

Please sign in to comment.