From 78b6fb357cc721bc9320094f566f869f53d1f178 Mon Sep 17 00:00:00 2001 From: zfrendo <842557664@qq.com> Date: Fri, 27 Sep 2024 14:58:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=9F=E5=9C=B0=E9=87=8D=E5=BB=BA?= =?UTF-8?q?=E9=87=8D=E7=BD=AEserverId=E4=B8=BB=E4=BB=8E=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=90=8E=E6=8F=90=E5=89=8D=E5=8D=B8=E8=BD=BD?= =?UTF-8?q?=E5=91=A8=E8=BE=B9=20#7171?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/flow/consts.py | 1 + .../mysql/mysql_migrate_cluster_remote_flow.py | 11 +++++++++-- .../mysql/mysql_restore_slave_remote_flow.py | 7 +++++++ .../scene/spider/remote_local_slave_recover.py | 8 ++++++++ .../flow/utils/mysql/mysql_act_playload.py | 16 ++++++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/dbm-ui/backend/flow/consts.py b/dbm-ui/backend/flow/consts.py index ce22202c65..b84acdbf83 100644 --- a/dbm-ui/backend/flow/consts.py +++ b/dbm-ui/backend/flow/consts.py @@ -436,6 +436,7 @@ class DBActuatorActionEnum(str, StructuredEnum): PushChecksumConfig = EnumField("push-checksum-config", _("推送mysql-table-checksum配置")) PushNewDbBackupConfig = EnumField("push-new-db-backup-config", _("推送备份配置")) PushMySQLRotatebinlogConfig = EnumField("push-mysql-rotatebinlog-config", _("推送rotatebinlog配置")) + ChangeServerId = EnumField("change-server-id", _("change-server-id")) class RedisActuatorActionEnum(str, StructuredEnum): diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_migrate_cluster_remote_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_migrate_cluster_remote_flow.py index 329da94339..c3b9834674 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_migrate_cluster_remote_flow.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_migrate_cluster_remote_flow.py @@ -344,7 +344,9 @@ def migrate_cluster_flow(self, use_for_upgrade=False): ) # 第四步 卸载实例 uninstall_svr_sub_pipeline_list = [] + uninstall_surrounding_sub_pipeline_list = [] for ip in [self.data["slave_ip"], self.data["master_ip"]]: + uninstall_surrounding_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) uninstall_svr_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) # 考虑到部分实例成对迁移的情况(即拆分) cluster = { @@ -354,7 +356,7 @@ def migrate_cluster_flow(self, use_for_upgrade=False): "bk_cloud_id": cluster_class.bk_cloud_id, } - uninstall_svr_sub_pipeline.add_act( + uninstall_surrounding_sub_pipeline.add_act( act_name=_("下发db-actor到节点{}".format(ip)), act_component_code=TransFileComponent.code, kwargs=asdict( @@ -366,7 +368,7 @@ def migrate_cluster_flow(self, use_for_upgrade=False): ), ) - uninstall_svr_sub_pipeline.add_act( + uninstall_surrounding_sub_pipeline.add_act( act_name=_("清理实例级别周边配置"), act_component_code=ExecuteDBActuatorScriptComponent.code, kwargs=asdict( @@ -413,6 +415,10 @@ def migrate_cluster_flow(self, use_for_upgrade=False): root_id=self.root_id, ticket_data=copy.deepcopy(self.data), ip=ip, ports=self.data["ports"] ) ) + + uninstall_surrounding_sub_pipeline_list.append( + uninstall_surrounding_sub_pipeline.build_sub_process(sub_name=_("卸载remote节点周边{}".format(ip))) + ) uninstall_svr_sub_pipeline_list.append( uninstall_svr_sub_pipeline.build_sub_process(sub_name=_("卸载remote节点{}".format(ip))) ) @@ -494,6 +500,7 @@ def migrate_cluster_flow(self, use_for_upgrade=False): ) ), ) + tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=uninstall_surrounding_sub_pipeline_list) # 卸载流程人工确认 tendb_migrate_pipeline.add_act(act_name=_("人工确认卸载实例"), act_component_code=PauseComponent.code, kwargs={}) # 卸载remote节点 diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_restore_slave_remote_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_restore_slave_remote_flow.py index 569900870f..17fb0cfa8a 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_restore_slave_remote_flow.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_restore_slave_remote_flow.py @@ -506,6 +506,13 @@ def restore_local_slave_flow(self): kwargs=asdict(exec_act_kwargs), ) + exec_act_kwargs.get_mysql_payload_func = MysqlActPayload.mysql_change_server_id.__name__ + tendb_migrate_pipeline.add_act( + act_name=_("重置server_id {}".format(exec_act_kwargs.exec_ip)), + act_component_code=ExecuteDBActuatorScriptComponent.code, + kwargs=asdict(exec_act_kwargs), + ) + cluster = { "cluster_id": cluster_model.id, "master_ip": master.machine.ip, diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/spider/remote_local_slave_recover.py b/dbm-ui/backend/flow/engine/bamboo/scene/spider/remote_local_slave_recover.py index d042736646..08519986f6 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/spider/remote_local_slave_recover.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/spider/remote_local_slave_recover.py @@ -177,6 +177,14 @@ def tendb_remote_slave_local_recover(self): act_component_code=ExecuteDBActuatorScriptComponent.code, kwargs=asdict(exec_act_kwargs), ) + + exec_act_kwargs.get_mysql_payload_func = MysqlActPayload.mysql_change_server_id.__name__ + tendb_migrate_pipeline.add_act( + act_name=_("重置server_id {}".format(exec_act_kwargs.exec_ip)), + act_component_code=ExecuteDBActuatorScriptComponent.code, + kwargs=asdict(exec_act_kwargs), + ) + cluster = { "cluster_id": cluster_class.id, "master_ip": master.machine.ip, diff --git a/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py b/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py index a5010084b9..0a95b2572c 100644 --- a/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py +++ b/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py @@ -2686,3 +2686,19 @@ def truncate_pre_drop_stage_on_remote(self, **kwargs) -> dict: }, }, } + + def mysql_change_server_id(self, **kwargs): + payload = { + "db_type": DBActuatorTypeEnum.MySQL.value, + "action": DBActuatorActionEnum.ChangeServerId.value, + "payload": { + "general": {"runtime_account": self.account}, + "extend": [ + { + "host": self.cluster["new_slave_ip"], + "port": self.cluster["new_slave_port"], + } + ], + }, + } + return payload