Skip to content

Commit

Permalink
fix 123
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Sep 25, 2024
1 parent 53287d9 commit 3610d97
Showing 1 changed file with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def __init__(self, root_id: str, ticket_data: Optional[Dict]):
"""
self.root_id = root_id
self.ticket_data = ticket_data
self.data = {}
# 仅添加从库。不切换。不复制账号
self.add_slave_only = self.ticket_data.get("add_slave_only", False)

Expand Down Expand Up @@ -109,15 +108,11 @@ def upgrade(self):
subflows = []
created_by = self.ticket_data["ticket_type"]
for info in self.ticket_data["infos"]:
cluster = Cluster.objects.get(id=info["cluster_ids"][0])
ports = get_ports(info["cluster_ids"])
subflow = non_standby_slaves_upgrade_subflow(
uid=str(self.ticket_data["uid"]),
root_id=self.root_id,
cluster=cluster,
new_slave=info["new_slave"],
old_slave=info["old_slave"],
ports=ports,
add_slave_only=self.add_slave_only,
relation_cluster_ids=info["cluster_ids"],
pkg_id=info["pkg_id"],
Expand All @@ -135,10 +130,8 @@ def upgrade(self):
def non_standby_slaves_upgrade_subflow(
uid: str,
root_id: str,
cluster: Cluster,
new_slave: dict,
old_slave: dict,
ports: list,
add_slave_only: bool,
relation_cluster_ids: list,
pkg_id: int,
Expand All @@ -149,18 +142,20 @@ def non_standby_slaves_upgrade_subflow(
"""
一主多从非stanby slaves升级subflow
"""
cluster_cls = Cluster.objects.get(id=relation_cluster_ids[0])
ports = get_ports(relation_cluster_ids)
pkg = Package.objects.get(id=pkg_id, pkg_type=MediumEnum.MySQL, db_type=DBType.MySQL)
charset, db_version = get_version_and_charset(
cluster.bk_biz_id, db_module_id=new_db_module_id, cluster_type=cluster.cluster_type
cluster_cls.bk_biz_id, db_module_id=new_db_module_id, cluster_type=cluster_cls.cluster_type
)
parent_global_data = {
"uid": uid,
"root_id": root_id,
"bk_biz_id": cluster.bk_biz_id,
"bk_cloud_id": cluster.bk_cloud_id,
"bk_biz_id": cluster_cls.bk_biz_id,
"bk_cloud_id": cluster_cls.bk_cloud_id,
"db_module_id": new_db_module_id,
"time_zone": cluster.time_zone,
"cluster_type": cluster.cluster_type,
"time_zone": cluster_cls.time_zone,
"cluster_type": cluster_cls.cluster_type,
"created_by": created_by,
"package": pkg.name,
"ports": ports,
Expand All @@ -172,11 +167,11 @@ def non_standby_slaves_upgrade_subflow(
new_slave_ip = new_slave["ip"]
bk_host_ids = [new_slave["bk_host_id"]]
old_slave_ip = old_slave["ip"]
db_config = get_instance_config(cluster.bk_cloud_id, old_slave_ip, ports=ports)
db_config = get_instance_config(cluster_cls.bk_cloud_id, old_slave_ip, ports=ports)

# 安装mysql
install_sub_pipeline = build_install_sub_pipeline(
uid, root_id, cluster, new_slave_ip, ports, bk_host_ids, db_config, pkg_id, pkg.name, relation_cluster_ids
uid, root_id, cluster_cls, new_slave_ip, ports, bk_host_ids, db_config, pkg_id, pkg.name, relation_cluster_ids
)
sub_pipeline.add_sub_pipeline(sub_flow=install_sub_pipeline)

Expand All @@ -198,17 +193,27 @@ def non_standby_slaves_upgrade_subflow(

# 卸载旧从节点
uninstall_svr_sub_pipeline = build_uninstall_sub_pipeline(
root_id, parent_global_data, old_slave_ip, relation_cluster_ids, cluster, ports
root_id, parent_global_data, old_slave_ip, relation_cluster_ids, cluster_cls.bk_cloud_id, ports
)
sub_pipeline.add_sub_pipeline(sub_flow=uninstall_svr_sub_pipeline)

return sub_pipeline.build_sub_process(sub_name=_("{}:slave迁移升级到:{}").format(old_slave_ip, new_slave_ip))


def build_install_sub_pipeline(
uid, root_id, cluster, new_slave_ip, ports, bk_host_ids, db_config, pkg_id, pkg_name, relation_cluster_ids
uid,
root_id,
parent_global_data,
cluster,
new_slave_ip,
ports,
bk_host_ids,
db_config,
pkg_id,
pkg_name,
relation_cluster_ids,
):
install_sub_pipeline = SubBuilder(root_id=root_id, data={"uid": uid, "root_id": root_id})
install_sub_pipeline = SubBuilder(root_id=root_id, data=copy.deepcopy(parent_global_data))

install_sub_pipeline.add_sub_pipeline(
sub_flow=install_mysql_in_cluster_sub_flow(
Expand Down Expand Up @@ -270,7 +275,7 @@ def build_install_sub_pipeline(


def build_sync_data_sub_pipelines(
root_id, parent_global_data, relation_cluster_ids, new_slave_ip, local_backup: bool, charst: str
root_id, parent_global_data, relation_cluster_ids, new_slave_ip, local_backup: bool, charset: str
):
sync_data_sub_pipeline_list = []
for cluster_id in relation_cluster_ids:
Expand All @@ -286,8 +291,9 @@ def build_sync_data_sub_pipelines(
"new_slave_port": master.port,
"bk_cloud_id": cluster_model.bk_cloud_id,
"file_target_path": f"/data/dbbak/{root_id}/{master.port}",
"charset": charst,
"charset": charset,
"change_master_force": True,
"change_master": True,
}
sync_data_sub_pipeline = SubBuilder(root_id=root_id, data=copy.deepcopy(parent_global_data))
if local_backup:
Expand Down Expand Up @@ -373,7 +379,7 @@ def build_switch_sub_pipelines(root_id, parent_global_data, relation_cluster_ids
return switch_sub_pipeline_list


def build_uninstall_sub_pipeline(root_id, parent_global_data, old_slave_ip, relation_cluster_ids, cluster, ports):
def build_uninstall_sub_pipeline(root_id, parent_global_data, old_slave_ip, relation_cluster_ids, bk_cloud_id, ports):
uninstall_svr_sub_pipeline = SubBuilder(root_id=root_id, data=copy.deepcopy(parent_global_data))
cluster_info = {"uninstall_ip": old_slave_ip, "cluster_ids": relation_cluster_ids}

Expand All @@ -394,7 +400,7 @@ def build_uninstall_sub_pipeline(root_id, parent_global_data, old_slave_ip, rela
act_component_code=TransFileComponent.code,
kwargs=asdict(
DownloadMediaKwargs(
bk_cloud_id=cluster.bk_cloud_id,
bk_cloud_id=bk_cloud_id,
exec_ip=old_slave_ip,
file_list=GetFileList(db_type=DBType.MySQL).get_db_actuator_package(),
)
Expand All @@ -407,7 +413,7 @@ def build_uninstall_sub_pipeline(root_id, parent_global_data, old_slave_ip, rela
kwargs=asdict(
ClearMachineKwargs(
exec_ip=old_slave_ip,
bk_cloud_id=cluster.bk_cloud_id,
bk_cloud_id=bk_cloud_id,
)
),
)
Expand Down

0 comments on commit 3610d97

Please sign in to comment.