Loading...
Searching...
No Matches
generate_mulregion_config.py
Go to the documentation of this file.
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18import os
19import json
20import sys
21from proto.replica_info_pb2 import ResConfigData,ReplicaInfo
22from google.protobuf.json_format import MessageToJson
23from google.protobuf.json_format import Parse, ParseDict
24
25
27 region_id = 1
28 tmp_config={}
29 for file_name in files:
30 with open(file_name) as f:
31 for line in f.readlines():
32 if len(line.split()) == 0:
33 continue
34 info={}
35 data = line.split()
36 info["id"] = data[0]
37 info["ip"] = data[1]
38 info["port"] = data[2]
39 if len(data) > 3:
40 region_id = data[3]
41 if region_id not in tmp_config:
42 tmp_config[region_id] = []
43
44 tmp_config[region_id].append({"replica_info":info})
45 region_id=region_id+1
46
47 for idx in range(1,region_id):
48 config_data=ResConfigData()
49 reg_id=1
50 for region_data in tmp_config.values():
51 region = config_data.region.add()
52 for rep in region_data:
53 replica = Parse(json.dumps(rep["replica_info"]), ReplicaInfo())
54 region.replica_info.append(replica)
55 region.region_id=reg_id
56 reg_id=reg_id+1
57 config_data.self_region_id=idx
58
59 json_obj = MessageToJson(config_data)
60 with open("server_region{}.config_json".format(idx),"w") as f:
61 f.write(json_obj)
62
63if __name__ == "__main__":
64 files=[]
65 for x in sys.argv[1:]:
66 files.append(x)
67
69