(zk_cluster, zk_root_path, tablet_conf, teardown)
| 210 | print("execute cmd[{}] success".format(cmd)) |
| 211 | |
| 212 | def DeployTablet(zk_cluster, zk_root_path, tablet_conf, teardown): |
| 213 | source_file = tablet_conf["package"] |
| 214 | file_name = os.path.basename(source_file) |
| 215 | version = file_name.split("-")[-1][:-7] |
| 216 | for item in tablet_conf["address_arr"]: |
| 217 | real_path = '' |
| 218 | if "path" in item: |
| 219 | real_path = item["path"] |
| 220 | else: |
| 221 | real_path = tablet_conf["path"] |
| 222 | host = item["address"].split(":")[0] |
| 223 | (prefix, suffix, is_local) = GetPrefixAndSuffix(host) |
| 224 | work_path = real_path + "/fedb-tablet-" + version |
| 225 | cmd_arr = [] |
| 226 | if teardown: |
| 227 | print("teardown tablet on {}. path: {}".format(host, real_path)) |
| 228 | cmd_arr.append("{} cd {}; sh bin/start.sh stop {}".format(prefix, work_path, suffix)) |
| 229 | cmd_arr.append("{} cd {}; rm {}; rm -rf {} {}".format(prefix, real_path, file_name, "fedb-tablet-*", suffix)) |
| 230 | else: |
| 231 | print("start tablet on {}. path: {}".format(host, real_path)) |
| 232 | cmd_arr.append("{} mkdir -p {} {}".format(prefix, real_path, suffix)) |
| 233 | if is_local: |
| 234 | cmd_arr.append("cp {} {}".format(source_file, real_path)) |
| 235 | else: |
| 236 | cmd_arr.append("scp {} {}:{}".format(source_file, host, real_path)) |
| 237 | cmd_arr.append("{} cd {}; tar -zxvf {}; mv {} fedb-tablet-{} {}".format(prefix, real_path, file_name, file_name[:-7], version, suffix)) |
| 238 | cmd_arr.append("{} cd {}; sed -i 's/--endpoint=.*/--endpoint={}/g' conf/tablet.flags {}".format(prefix, work_path, item["address"], suffix)) |
| 239 | if zk_cluster != "": |
| 240 | cmd_arr.append("{} cd {}; sed -i 's/#--zk_cluster=.*/--zk_cluster={}/g' conf/tablet.flags;" |
| 241 | "sed -i 's/#--zk_root_path=.*/--zk_root_path={}/g' conf/tablet.flags {}".format( |
| 242 | prefix, work_path, zk_cluster, zk_root_path.replace("/", "\/"), suffix)) |
| 243 | cmd_arr.append("{} cd {}; sh bin/start.sh start {}".format(prefix, work_path, suffix)) |
| 244 | for cmd in cmd_arr: |
| 245 | (returncode,output,errout) = RunWithRetunCode(cmd) |
| 246 | if returncode != 0: |
| 247 | print("execute cmd[{}] failed! error msg: {}".format(cmd, errout)) |
| 248 | return |
| 249 | print("execute cmd[{}] success".format(cmd)) |
| 250 | |
| 251 | if __name__ == "__main__": |
| 252 | conf_file = sys.argv[1] |
no test coverage detected