diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_migrate_cluster_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_migrate_cluster_flow.py deleted file mode 100644 index 9e3132be79..0000000000 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_migrate_cluster_flow.py +++ /dev/null @@ -1,467 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. -Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at https://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" - -import copy -import logging.config -from dataclasses import asdict -from typing import Dict, Optional - -from django.utils.translation import ugettext as _ - -from backend.components import DBConfigApi -from backend.components.dbconfig.constants import FormatType, LevelName -from backend.configuration.constants import DBType -from backend.constants import IP_PORT_DIVIDER -from backend.db_meta.enums import ClusterType, InstanceInnerRole, InstanceStatus -from backend.db_meta.models import Cluster -from backend.db_package.models import Package -from backend.flow.consts import MediumEnum, MysqlVersionToDBBackupForMap -from backend.flow.engine.bamboo.scene.common.builder import Builder, SubBuilder -from backend.flow.engine.bamboo.scene.common.get_file_list import GetFileList -from backend.flow.engine.bamboo.scene.mysql.common.common_sub_flow import ( - build_surrounding_apps_sub_flow, - install_mysql_in_cluster_sub_flow, -) -from backend.flow.engine.bamboo.scene.mysql.common.get_master_config import get_instance_config -from backend.flow.engine.bamboo.scene.mysql.common.master_and_slave_switch import master_and_slave_switch -from backend.flow.engine.bamboo.scene.mysql.common.mysql_resotre_data_sub_flow import ( - mysql_restore_master_slave_sub_flow, -) -from backend.flow.engine.bamboo.scene.mysql.common.uninstall_instance import uninstall_instance_sub_flow -from backend.flow.plugins.components.collections.common.download_backup_client import DownloadBackupClientComponent -from backend.flow.plugins.components.collections.common.pause import PauseComponent -from backend.flow.plugins.components.collections.mysql.clear_machine import MySQLClearMachineComponent -from backend.flow.plugins.components.collections.mysql.exec_actuator_script import ExecuteDBActuatorScriptComponent -from backend.flow.plugins.components.collections.mysql.mysql_db_meta import MySQLDBMetaComponent -from backend.flow.plugins.components.collections.mysql.trans_flies import TransFileComponent -from backend.flow.utils.common_act_dataclass import DownloadBackupClientKwargs -from backend.flow.utils.mysql.common.mysql_cluster_info import get_ports, get_version_and_charset -from backend.flow.utils.mysql.mysql_act_dataclass import ( - ClearMachineKwargs, - DBMetaOPKwargs, - DownloadMediaKwargs, - ExecActuatorKwargs, -) -from backend.flow.utils.mysql.mysql_act_playload import MysqlActPayload -from backend.flow.utils.mysql.mysql_context_dataclass import ClusterInfoContext -from backend.flow.utils.mysql.mysql_db_meta import MySQLDBMeta - -logger = logging.getLogger("flow") - - -class MySQLMigrateClusterFlow(object): - """ - 构建mysql主从成对迁移抽象类 - 支持多云区域操作 - """ - - def __init__(self, root_id: str, ticket_data: Optional[Dict]): - """ - @param root_id : 任务流程定义的root_id - @param ticket_data : 单据传递参数 - """ - self.root_id = root_id - self.ticket_data = ticket_data - self.data = {} - - def deploy_migrate_cluster_flow(self, use_for_upgrade=False): - """ - 成对迁移集群主从节点。 - 增加单据临时ADMIN账号的添加和删除逻辑 - 元数据信息修改顺序: - 1 mysql_migrate_cluster_add_instance - 2 mysql_migrate_cluster_add_tuple - 3 mysql_migrate_cluster_switch_storage - """ - # 构建流程 - cluster_ids = [] - for i in self.ticket_data["infos"]: - cluster_ids.extend(i["cluster_ids"]) - - tendb_migrate_pipeline_all = Builder( - root_id=self.root_id, - data=copy.deepcopy(self.ticket_data), - need_random_pass_cluster_ids=list(set(cluster_ids)), - ) - # 按照传入的infos信息,循环拼接子流程 - tendb_migrate_pipeline_list = [] - for info in self.ticket_data["infos"]: - self.data = copy.deepcopy(info) - cluster_class = Cluster.objects.get(id=self.data["cluster_ids"][0]) - # 确定要迁移的主节点,从节点. - # todo 获取哪一个节点作为成对迁移? - master_model = cluster_class.storageinstance_set.get(instance_inner_role=InstanceInnerRole.MASTER.value) - slave = cluster_class.storageinstance_set.filter( - instance_inner_role=InstanceInnerRole.SLAVE.value, is_stand_by=True - ).first() - install_pkg_version = cluster_class.major_version - - # 如果是升级用途的话,需要改变module id - db_module_id = cluster_class.db_module_id - self.data["package"] = Package.get_latest_package( - version=install_pkg_version, pkg_type=MediumEnum.MySQL, db_type=DBType.MySQL - ).name - pkg_id = 0 - if use_for_upgrade: - db_module_id = info["new_db_module_id"] - pkg_id = info["pkg_id"] - logger.info("param pkg_id:{}".format(pkg_id)) - self.data["package"] = Package.objects.get(id=pkg_id, pkg_type=MediumEnum.MySQL, db_type=DBType.MySQL) - - self.data["master_ip"] = master_model.machine.ip - self.data["cluster_type"] = cluster_class.cluster_type - self.data["old_slave_ip"] = slave.machine.ip - self.data["slave_ip"] = slave.machine.ip - self.data["mysql_port"] = master_model.port - self.data["bk_biz_id"] = cluster_class.bk_biz_id - self.data["bk_cloud_id"] = cluster_class.bk_cloud_id - self.data["db_module_id"] = db_module_id - self.data["time_zone"] = cluster_class.time_zone - self.data["created_by"] = self.ticket_data["created_by"] - self.data["module"] = db_module_id - self.data["ticket_type"] = self.ticket_data["ticket_type"] - self.data["uid"] = self.ticket_data["uid"] - - self.data["ports"] = get_ports(info["cluster_ids"]) - self.data["force"] = info.get("force", False) - self.data["charset"], self.data["db_version"] = get_version_and_charset( - self.data["bk_biz_id"], - db_module_id=self.data["db_module_id"], - cluster_type=self.data["cluster_type"], - ) - bk_host_ids = [] - if "bk_new_slave" in self.data.keys(): - bk_host_ids.append(self.data["bk_new_slave"]["bk_host_id"]) - if "bk_new_master" in self.data.keys(): - bk_host_ids.append(self.data["bk_new_master"]["bk_host_id"]) - - tendb_migrate_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - # 整机安装数据库 - master = cluster_class.storageinstance_set.get(instance_inner_role=InstanceInnerRole.MASTER.value) - db_config = get_instance_config(cluster_class.bk_cloud_id, master.machine.ip, self.data["ports"]) - install_sub_pipeline_list = [] - install_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - install_sub_pipeline.add_sub_pipeline( - sub_flow=install_mysql_in_cluster_sub_flow( - uid=self.data["uid"], - root_id=self.root_id, - cluster=cluster_class, - new_mysql_list=[self.data["new_slave_ip"], self.data["new_master_ip"]], - install_ports=self.data["ports"], - bk_host_ids=bk_host_ids, - pkg_id=pkg_id, - db_module_id=str(db_module_id), - db_config=db_config, - ) - ) - - # 写入元数据 - cluster = { - "cluster_ports": self.data["ports"], - "new_master_ip": self.data["new_master_ip"], - "new_slave_ip": self.data["new_slave_ip"], - "bk_cloud_id": cluster_class.bk_cloud_id, - } - install_sub_pipeline.add_act( - act_name=_("安装完毕,写入初始化实例的db_meta元信息"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.migrate_cluster_add_instance.__name__, - cluster=copy.deepcopy(cluster), - is_update_trans_data=True, - ) - ), - ) - install_sub_pipeline.add_act( - act_name=_("安装backup-client工具"), - act_component_code=DownloadBackupClientComponent.code, - kwargs=asdict( - DownloadBackupClientKwargs( - bk_cloud_id=cluster_class.bk_cloud_id, - bk_biz_id=int(cluster_class.bk_biz_id), - download_host_list=[cluster["new_master_ip"], cluster["new_slave_ip"]], - ) - ), - ) - - exec_act_kwargs = ExecActuatorKwargs( - cluster=copy.deepcopy(cluster), - bk_cloud_id=cluster_class.bk_cloud_id, - cluster_type=cluster_class.cluster_type, - get_mysql_payload_func=MysqlActPayload.get_install_tmp_db_backup_payload.__name__, - ) - exec_act_kwargs.exec_ip = [cluster["new_master_ip"], cluster["new_slave_ip"]] - install_sub_pipeline.add_act( - act_name=_("安装临时备份程序"), - act_component_code=ExecuteDBActuatorScriptComponent.code, - kwargs=asdict(exec_act_kwargs), - ) - install_sub_pipeline_list.append(install_sub_pipeline.build_sub_process(sub_name=_("安装实例"))) - - sync_data_sub_pipeline_list = [] - for cluster_id in self.data["cluster_ids"]: - sync_data_sub_pipeline = SubBuilder(root_id=self.root_id, data=self.data) - cluster_model = Cluster.objects.get(id=cluster_id) - master_model = cluster_model.storageinstance_set.get( - instance_inner_role=InstanceInnerRole.MASTER.value - ) - cluster = { - "master_ip": self.data["master_ip"], - "slave_ip": self.data["slave_ip"], - "mysql_port": master_model.port, - "master_port": master_model.port, - "slave_port": master_model.port, - "new_master_ip": self.data["new_master_ip"], - "new_master_port": master_model.port, - "new_slave_ip": self.data["new_slave_ip"], - "new_slave_port": master_model.port, - "file_target_path": f"/data/dbbak/{self.root_id}/{master_model.port}", - "cluster_id": cluster_model.id, - "bk_cloud_id": cluster_model.bk_cloud_id, - "change_master_force": False, - "change_master": False, - "charset": self.data["charset"], - } - exec_act_kwargs.cluster = copy.deepcopy(cluster) - - stand_by_slaves = cluster_model.storageinstance_set.filter( - instance_inner_role=InstanceInnerRole.SLAVE.value, - is_stand_by=True, - status=InstanceStatus.RUNNING.value, - ).exclude(machine__ip__in=[self.data["new_slave_ip"], self.data["new_master_ip"]]) - # 从standby从库找备份 - inst_list = ["{}{}{}".format(master_model.machine.ip, IP_PORT_DIVIDER, master_model.port)] - if len(stand_by_slaves) > 0: - inst_list.append( - "{}{}{}".format(stand_by_slaves[0].machine.ip, IP_PORT_DIVIDER, stand_by_slaves[0].port) - ) - sync_data_sub_pipeline.add_sub_pipeline( - sub_flow=mysql_restore_master_slave_sub_flow( - root_id=self.root_id, - ticket_data=copy.deepcopy(self.data), - cluster=cluster, - cluster_model=cluster_model, - ins_list=inst_list, - ) - ) - - sync_data_sub_pipeline.add_act( - act_name=_("数据恢复完毕,写入新主节点和旧主节点的关系链元数据"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.migrate_cluster_add_tuple.__name__, - cluster=cluster, - is_update_trans_data=True, - ) - ), - ) - sync_data_sub_pipeline_list.append(sync_data_sub_pipeline.build_sub_process(sub_name=_("恢复实例数据"))) - - switch_sub_pipeline_list = [] - for cluster_id in self.data["cluster_ids"]: - switch_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - cluster_model = Cluster.objects.get(id=cluster_id) - master_model = cluster_model.storageinstance_set.get( - instance_inner_role=InstanceInnerRole.MASTER.value - ) - other_slave_storage = cluster_model.storageinstance_set.filter( - instance_inner_role=InstanceInnerRole.SLAVE.value - ).exclude( - machine__ip__in=[self.data["old_slave_ip"], self.data["new_slave_ip"], self.data["new_master_ip"]] - ) - other_slaves = [y.machine.ip for y in other_slave_storage] - cluster = { - "cluster_id": cluster_model.id, - "bk_cloud_id": cluster_model.bk_cloud_id, - "old_master_ip": self.data["master_ip"], - "old_master_port": master_model.port, - "old_slave_ip": self.data["old_slave_ip"], - "old_slave_port": master_model.port, - "new_master_ip": self.data["new_master_ip"], - "new_master_port": master_model.port, - "new_slave_ip": self.data["new_slave_ip"], - "new_slave_port": master_model.port, - "mysql_port": master_model.port, - "master_port": master_model.port, - "other_slave_info": other_slaves, - } - switch_sub_pipeline.add_sub_pipeline( - sub_flow=master_and_slave_switch( - root_id=self.root_id, - ticket_data=copy.deepcopy(self.data), - cluster=cluster_model, - cluster_info=copy.deepcopy(cluster), - ) - ) - switch_sub_pipeline.add_act( - act_name=_("集群切换完成,写入 {} 的元信息".format(cluster_model.id)), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.mysql_migrate_cluster_switch_storage.__name__, - cluster=cluster, - is_update_trans_data=True, - ) - ), - ) - switch_sub_pipeline_list.append( - switch_sub_pipeline.build_sub_process(sub_name=_("集群 {} 切换".format(cluster_model.id))) - ) - # 第四步 卸载实例 - uninstall_svr_sub_pipeline_list = [] - for ip in [self.data["slave_ip"], self.data["master_ip"]]: - uninstall_svr_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - - # 考虑到部分实例成对迁移的情况(即拆分) - cluster = { - "uninstall_ip": ip, - "remote_port": self.data["ports"], - "backend_port": self.data["ports"], - "bk_cloud_id": cluster_class.bk_cloud_id, - } - - uninstall_svr_sub_pipeline.add_act( - act_name=_("下发db-actor到节点{}".format(ip)), - act_component_code=TransFileComponent.code, - kwargs=asdict( - DownloadMediaKwargs( - bk_cloud_id=cluster_class.bk_cloud_id, - exec_ip=[ip], - file_list=GetFileList(db_type=DBType.MySQL).get_db_actuator_package(), - ) - ), - ) - - uninstall_svr_sub_pipeline.add_act( - act_name=_("清理实例级别周边配置"), - act_component_code=ExecuteDBActuatorScriptComponent.code, - kwargs=asdict( - ExecActuatorKwargs( - exec_ip=ip, - cluster_type=ClusterType.TenDBHA, - bk_cloud_id=cluster_class.bk_cloud_id, - cluster=cluster, - get_mysql_payload_func=MysqlActPayload.get_clear_surrounding_config_payload.__name__, - ) - ), - ) - - cluster = { - "uninstall_ip": ip, - "ports": self.data["ports"], - "bk_cloud_id": cluster_class.bk_cloud_id, - "cluster_type": cluster_class.cluster_type, - } - uninstall_svr_sub_pipeline.add_act( - act_name=_("卸载实例前先删除元数据"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.uninstall_instance.__name__, - is_update_trans_data=True, - cluster=cluster, - ) - ), - ) - - uninstall_svr_sub_pipeline.add_act( - act_name=_("清理机器配置"), - act_component_code=MySQLClearMachineComponent.code, - kwargs=asdict( - ClearMachineKwargs( - exec_ip=ip, - bk_cloud_id=cluster_class.bk_cloud_id, - ) - ), - ) - uninstall_svr_sub_pipeline.add_sub_pipeline( - sub_flow=uninstall_instance_sub_flow( - root_id=self.root_id, ticket_data=copy.deepcopy(self.data), ip=ip, ports=self.data["ports"] - ) - ) - uninstall_svr_sub_pipeline_list.append( - uninstall_svr_sub_pipeline.build_sub_process(sub_name=_("卸载remote节点{}".format(ip))) - ) - - # 安装实例 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=install_sub_pipeline_list) - # 同步配置 - # tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=sync_mycnf_sub_pipeline_list) - # 数据同步 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=sync_data_sub_pipeline_list) - # 新机器安装周边组件 - tendb_migrate_pipeline.add_sub_pipeline( - sub_flow=build_surrounding_apps_sub_flow( - bk_cloud_id=cluster_class.bk_cloud_id, - master_ip_list=None, - slave_ip_list=[self.data["new_slave_ip"], self.data["new_master_ip"]], - root_id=self.root_id, - parent_global_data=copy.deepcopy(self.data), - collect_sysinfo=True, - cluster_type=ClusterType.TenDBHA.value, - db_backup_pkg_type=MysqlVersionToDBBackupForMap[self.data["db_version"]], - ) - ) - # 人工确认切换迁移实例 - tendb_migrate_pipeline.add_act(act_name=_("人工确认切换"), act_component_code=PauseComponent.code, kwargs={}) - # 切换迁移实例 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=switch_sub_pipeline_list) - tendb_migrate_pipeline.add_sub_pipeline( - sub_flow=build_surrounding_apps_sub_flow( - bk_cloud_id=cluster_class.bk_cloud_id, - master_ip_list=[self.data["new_master_ip"]], - slave_ip_list=[self.data["new_slave_ip"]], - root_id=self.root_id, - parent_global_data=copy.deepcopy(self.data), - is_init=True, - cluster_type=ClusterType.TenDBHA.value, - db_backup_pkg_type=MysqlVersionToDBBackupForMap[self.data["db_version"]], - ) - ) - # 如果是做升级版本的话 则更新集群模块id - if use_for_upgrade: - data = DBConfigApi.query_conf_item( - { - "bk_biz_id": str(self.data["bk_biz_id"]), - "level_name": LevelName.MODULE, - "level_value": str(db_module_id), - "conf_file": "deploy_info", - "conf_type": "deploy", - "namespace": ClusterType.TenDBHA.value, - "format": FormatType.MAP, - } - )["content"] - major_version = data["db_version"] - tendb_migrate_pipeline.add_act( - act_name=_("更新集群模块"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.update_cluster_module.__name__, - cluster={ - "cluster_ids": self.data["cluster_ids"], - "new_module_id": info["new_db_module_id"], - "major_version": major_version, - }, - ) - ), - ) - # 卸载流程人工确认 - tendb_migrate_pipeline.add_act(act_name=_("人工确认卸载实例"), act_component_code=PauseComponent.code, kwargs={}) - # 卸载remote节点 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=uninstall_svr_sub_pipeline_list) - tendb_migrate_pipeline_list.append( - tendb_migrate_pipeline.build_sub_process(sub_name=_("集群{}开始成对迁移").format(cluster_class.id)) - ) - # 运行流程 - tendb_migrate_pipeline_all.add_parallel_sub_pipeline(tendb_migrate_pipeline_list) - tendb_migrate_pipeline_all.run_pipeline(init_trans_data_class=ClusterInfoContext(), is_drop_random_user=True) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_restore_slave_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_restore_slave_flow.py deleted file mode 100644 index 997632a791..0000000000 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_restore_slave_flow.py +++ /dev/null @@ -1,595 +0,0 @@ -# -*- coding: utf-8 -*- -""" -TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. -Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at https://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" -import copy -import logging.config -from dataclasses import asdict -from typing import Dict, Optional - -from django.utils.translation import ugettext as _ - -from backend.configuration.constants import DBType -from backend.constants import IP_PORT_DIVIDER -from backend.db_meta.enums import ClusterType, InstanceInnerRole, InstancePhase, InstanceStatus -from backend.db_meta.models import Cluster -from backend.db_package.models import Package -from backend.flow.consts import MediumEnum -from backend.flow.engine.bamboo.scene.common.builder import Builder, SubBuilder -from backend.flow.engine.bamboo.scene.common.get_file_list import GetFileList -from backend.flow.engine.bamboo.scene.mysql.common.cluster_entrys import get_tendb_ha_entry -from backend.flow.engine.bamboo.scene.mysql.common.common_sub_flow import ( - build_surrounding_apps_sub_flow, - install_mysql_in_cluster_sub_flow, -) -from backend.flow.engine.bamboo.scene.mysql.common.get_master_config import get_instance_config -from backend.flow.engine.bamboo.scene.mysql.common.mysql_resotre_data_sub_flow import mysql_restore_data_sub_flow -from backend.flow.engine.bamboo.scene.mysql.common.slave_recover_switch import slave_migrate_switch_sub_flow -from backend.flow.engine.bamboo.scene.mysql.common.uninstall_instance import uninstall_instance_sub_flow -from backend.flow.plugins.components.collections.common.download_backup_client import DownloadBackupClientComponent -from backend.flow.plugins.components.collections.common.pause import PauseComponent -from backend.flow.plugins.components.collections.mysql.clear_machine import MySQLClearMachineComponent -from backend.flow.plugins.components.collections.mysql.clone_user import CloneUserComponent -from backend.flow.plugins.components.collections.mysql.dns_manage import MySQLDnsManageComponent -from backend.flow.plugins.components.collections.mysql.exec_actuator_script import ExecuteDBActuatorScriptComponent -from backend.flow.plugins.components.collections.mysql.mysql_crond_control import MysqlCrondMonitorControlComponent -from backend.flow.plugins.components.collections.mysql.mysql_db_meta import MySQLDBMetaComponent -from backend.flow.plugins.components.collections.mysql.mysql_rds_execute import MySQLExecuteRdsComponent -from backend.flow.plugins.components.collections.mysql.trans_flies import TransFileComponent -from backend.flow.utils.common_act_dataclass import DownloadBackupClientKwargs -from backend.flow.utils.mysql.common.mysql_cluster_info import get_ports, get_version_and_charset -from backend.flow.utils.mysql.mysql_act_dataclass import ( - ClearMachineKwargs, - CrondMonitorKwargs, - DBMetaOPKwargs, - DownloadMediaKwargs, - ExecActuatorKwargs, - ExecuteRdsKwargs, - InstanceUserCloneKwargs, - UpdateDnsRecordKwargs, -) -from backend.flow.utils.mysql.mysql_act_playload import MysqlActPayload -from backend.flow.utils.mysql.mysql_context_dataclass import ClusterInfoContext -from backend.flow.utils.mysql.mysql_db_meta import MySQLDBMeta - -logger = logging.getLogger("flow") - - -class MySQLRestoreSlaveFlow(object): - """ - mysql 重建slave流程接入新备份系统 - """ - - def __init__(self, root_id: str, tick_data: Optional[Dict]): - """ - @param root_id : 任务流程定义的root_id - @param tick_data : 单据传递过来的参数列表,是dict格式 - """ - self.root_id = root_id - self.ticket_data = tick_data - self.data = {} - # 仅添加从库。不切换。不复制账号 - self.add_slave_only = self.ticket_data.get("add_slave_only", False) - - def deploy_restore_slave_flow(self): - """ - 重建slave节点的流程 - 增加单据临时ADMIN账号的添加和删除逻辑 - 元数据流程: - 1 mysql_restore_slave_add_instance - 2 mysql_add_slave_info - 3 mysql_restore_slave_change_cluster_info - 4 mysql_restore_remove_old_slave - """ - cluster_ids = [] - for i in self.ticket_data["infos"]: - cluster_ids.extend(i["cluster_ids"]) - - tendb_migrate_pipeline_all = Builder( - root_id=self.root_id, - data=copy.deepcopy(self.ticket_data), - need_random_pass_cluster_ids=list(set(cluster_ids)), - ) - tendb_migrate_pipeline_list = [] - for info in self.ticket_data["infos"]: - self.data = copy.deepcopy(info) - cluster_class = Cluster.objects.get(id=self.data["cluster_ids"][0]) - self.data["bk_biz_id"] = cluster_class.bk_biz_id - self.data["bk_cloud_id"] = cluster_class.bk_cloud_id - self.data["db_module_id"] = cluster_class.db_module_id - self.data["time_zone"] = cluster_class.time_zone - self.data["created_by"] = self.ticket_data["created_by"] - self.data["module"] = cluster_class.db_module_id - self.data["ticket_type"] = self.ticket_data["ticket_type"] - self.data["cluster_type"] = cluster_class.cluster_type - self.data["uid"] = self.ticket_data["uid"] - self.data["package"] = Package.get_latest_package( - version=cluster_class.major_version, pkg_type=MediumEnum.MySQL, db_type=DBType.MySQL - ).name - # self.data["package"] = "5.7.20" - self.data["ports"] = get_ports(info["cluster_ids"]) - self.data["force"] = self.ticket_data.get("force", False) - self.data["charset"], self.data["db_version"] = get_version_and_charset( - self.data["bk_biz_id"], - db_module_id=self.data["db_module_id"], - cluster_type=self.data["cluster_type"], - ) - bk_host_ids = [] - if "bk_new_slave" in self.data.keys(): - bk_host_ids.append(self.data["bk_new_slave"]["bk_host_id"]) - - tendb_migrate_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - # 获取信息 - # 整机安装数据库 - master = cluster_class.storageinstance_set.get(instance_inner_role=InstanceInnerRole.MASTER.value) - db_config = get_instance_config(cluster_class.bk_cloud_id, master.machine.ip, self.data["ports"]) - install_sub_pipeline_list = [] - install_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - install_sub_pipeline.add_sub_pipeline( - sub_flow=install_mysql_in_cluster_sub_flow( - uid=self.data["uid"], - root_id=self.root_id, - cluster=cluster_class, - new_mysql_list=[self.data["new_slave_ip"]], - install_ports=self.data["ports"], - bk_host_ids=bk_host_ids, - db_config=db_config, - ) - ) - - cluster = { - "install_ip": self.data["new_slave_ip"], - "cluster_ids": self.data["cluster_ids"], - "package": self.data["package"], - } - install_sub_pipeline.add_act( - act_name=_("写入初始化实例的db_meta元信息"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.slave_recover_add_instance.__name__, - cluster=copy.deepcopy(cluster), - is_update_trans_data=False, - ) - ), - ) - - install_sub_pipeline.add_act( - act_name=_("安装backup-client工具"), - act_component_code=DownloadBackupClientComponent.code, - kwargs=asdict( - DownloadBackupClientKwargs( - bk_cloud_id=cluster_class.bk_cloud_id, - bk_biz_id=int(cluster_class.bk_biz_id), - download_host_list=[self.data["new_slave_ip"]], - ) - ), - ) - - exec_act_kwargs = ExecActuatorKwargs( - cluster=cluster, - bk_cloud_id=cluster_class.bk_cloud_id, - cluster_type=cluster_class.cluster_type, - get_mysql_payload_func=MysqlActPayload.get_install_tmp_db_backup_payload.__name__, - ) - exec_act_kwargs.exec_ip = [self.data["new_slave_ip"]] - install_sub_pipeline.add_act( - act_name=_("安装临时备份程序"), - act_component_code=ExecuteDBActuatorScriptComponent.code, - kwargs=asdict(exec_act_kwargs), - ) - - install_sub_pipeline_list.append(install_sub_pipeline.build_sub_process(sub_name=_("安装从节点"))) - - sync_data_sub_pipeline_list = [] - for cluster_id in info["cluster_ids"]: - cluster_model = Cluster.objects.get(id=cluster_id) - master = cluster_model.storageinstance_set.get(instance_inner_role=InstanceInnerRole.MASTER.value) - cluster = { - "mysql_port": master.port, - "cluster_id": cluster_model.id, - "cluster_type": cluster_class.cluster_type, - "master_ip": master.machine.ip, - "master_port": master.port, - "new_slave_ip": self.data["new_slave_ip"], - "new_slave_port": master.port, - "bk_cloud_id": cluster_model.bk_cloud_id, - "file_target_path": f"/data/dbbak/{self.root_id}/{master.port}", - "charset": self.data["charset"], - "change_master_force": True, - "change_master": True, - } - exec_act_kwargs.cluster = cluster - sync_data_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - # 获取本地备份并恢复 - inst_list = ["{}{}{}".format(master.machine.ip, IP_PORT_DIVIDER, master.port)] - stand_by_slaves = cluster_model.storageinstance_set.filter( - instance_inner_role=InstanceInnerRole.SLAVE.value, - is_stand_by=True, - status=InstanceStatus.RUNNING.value, - ).exclude(machine__ip__in=[self.data["new_slave_ip"]]) - if len(stand_by_slaves) > 0: - inst_list.append( - "{}{}{}".format(stand_by_slaves[0].machine.ip, IP_PORT_DIVIDER, stand_by_slaves[0].port) - ) - sync_data_sub_pipeline.add_sub_pipeline( - sub_flow=mysql_restore_data_sub_flow( - root_id=self.root_id, - ticket_data=copy.deepcopy(self.data), - cluster=cluster, - cluster_model=cluster_model, - ins_list=inst_list, - ) - ) - # 恢复完毕的时候 slave 状态改为running - sync_data_sub_pipeline.add_act( - act_name=_("同步完毕,写入主从关系,设置节点为running状态"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.mysql_add_slave_info.__name__, - cluster=cluster, - is_update_trans_data=True, - ) - ), - ) - - sync_data_sub_pipeline_list.append(sync_data_sub_pipeline.build_sub_process(sub_name=_("恢复实例数据"))) - - switch_sub_pipeline_list = [] - uninstall_svr_sub_pipeline_list = [] - if not self.add_slave_only: - for cluster_id in self.data["cluster_ids"]: - cluster_model = Cluster.objects.get(id=cluster_id) - switch_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - switch_sub_pipeline.add_sub_pipeline( - sub_flow=slave_migrate_switch_sub_flow( - root_id=self.root_id, - ticket_data=copy.deepcopy(self.data), - cluster=cluster_model, - old_slave_ip=self.data["old_slave_ip"], - new_slave_ip=self.data["new_slave_ip"], - ) - ) - domain_map = get_tendb_ha_entry(cluster_model.id) - cluster = { - "slave_domain": domain_map[self.data["old_slave_ip"]], - "new_slave_ip": self.data["new_slave_ip"], - "old_slave_ip": self.data["old_slave_ip"], - "cluster_id": cluster_model.id, - } - switch_sub_pipeline.add_act( - act_name=_("slave切换完毕,修改集群 {} 数据".format(cluster_model.id)), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.mysql_restore_slave_change_cluster_info.__name__, - cluster=cluster, - is_update_trans_data=True, - ) - ), - ) - switch_sub_pipeline_list.append(switch_sub_pipeline.build_sub_process(sub_name=_("切换到新从节点"))) - - uninstall_svr_sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - - # 需要下架的机器可能是坏的根本连接不上, 所以应该先清理元数据 - cluster = {"uninstall_ip": self.data["old_slave_ip"], "cluster_ids": self.data["cluster_ids"]} - uninstall_svr_sub_pipeline.add_act( - act_name=_("卸载实例前先删除元数据"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.slave_recover_del_instance.__name__, - is_update_trans_data=True, - cluster=cluster, - ) - ), - ) - - uninstall_svr_sub_pipeline.add_act( - act_name=_("下发db-actor到节点{}".format(self.data["old_slave_ip"])), - act_component_code=TransFileComponent.code, - kwargs=asdict( - DownloadMediaKwargs( - bk_cloud_id=cluster_class.bk_cloud_id, - exec_ip=[self.data["old_slave_ip"]], - file_list=GetFileList(db_type=DBType.MySQL).get_db_actuator_package(), - ) - ), - ) - - uninstall_svr_sub_pipeline.add_act( - act_name=_("清理机器配置"), - act_component_code=MySQLClearMachineComponent.code, - kwargs=asdict( - ClearMachineKwargs( - exec_ip=self.data["old_slave_ip"], - bk_cloud_id=cluster_class.bk_cloud_id, - ) - ), - ) - - uninstall_svr_sub_pipeline.add_sub_pipeline( - sub_flow=uninstall_instance_sub_flow( - root_id=self.root_id, - ticket_data=copy.deepcopy(self.data), - ip=self.data["old_slave_ip"], - ports=self.data["ports"], - ) - ) - - uninstall_svr_sub_pipeline_list.append( - uninstall_svr_sub_pipeline.build_sub_process( - sub_name=_("卸载remote节点{}".format(self.data["old_slave_ip"])) - ) - ) - - # 安装实例 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=install_sub_pipeline_list) - # 数据同步 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=sync_data_sub_pipeline_list) - # 新机器安装周边组件 - tendb_migrate_pipeline.add_sub_pipeline( - sub_flow=build_surrounding_apps_sub_flow( - bk_cloud_id=cluster_class.bk_cloud_id, - master_ip_list=None, - slave_ip_list=[self.data["new_slave_ip"]], - root_id=self.root_id, - parent_global_data=copy.deepcopy(self.data), - collect_sysinfo=True, - is_install_backup=False, - cluster_type=ClusterType.TenDBHA.value, - ) - ) - if not self.add_slave_only: - # 人工确认切换迁移实例 - tendb_migrate_pipeline.add_act(act_name=_("人工确认切换"), act_component_code=PauseComponent.code, kwargs={}) - # 切换迁移实例 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=switch_sub_pipeline_list) - # 切换后再次刷新周边 - tendb_migrate_pipeline.add_sub_pipeline( - sub_flow=build_surrounding_apps_sub_flow( - bk_cloud_id=cluster_class.bk_cloud_id, - master_ip_list=None, - slave_ip_list=[self.data["new_slave_ip"]], - root_id=self.root_id, - parent_global_data=copy.deepcopy(self.data), - is_init=True, - cluster_type=ClusterType.TenDBHA.value, - ) - ) - # 卸载流程人工确认 - tendb_migrate_pipeline.add_act( - act_name=_("人工确认卸载实例"), act_component_code=PauseComponent.code, kwargs={} - ) - - # # 卸载remote节点 - tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=uninstall_svr_sub_pipeline_list) - tendb_migrate_pipeline_list.append( - tendb_migrate_pipeline.build_sub_process(_("slave重建迁移{}").format(self.data["new_slave_ip"])) - ) - # 运行流程 - tendb_migrate_pipeline_all.add_parallel_sub_pipeline(tendb_migrate_pipeline_list) - tendb_migrate_pipeline_all.run_pipeline(init_trans_data_class=ClusterInfoContext(), is_drop_random_user=True) - - def deploy_restore_local_slave_flow(self): - """ - 原地重建slave - 机器slave数据损坏或者其他原因丢弃实例数据,重新恢复数据。 - 无元数据改动 - 增加单据临时ADMIN账号的添加和删除逻辑 - """ - cluster_ids = [i["cluster_id"] for i in self.ticket_data["infos"]] - tendb_migrate_pipeline_all = Builder( - root_id=self.root_id, - data=copy.deepcopy(self.ticket_data), - need_random_pass_cluster_ids=list(set(cluster_ids)), - ) - tendb_migrate_pipeline_list = [] - for info in self.ticket_data["infos"]: - self.data = copy.deepcopy(info) - cluster_model = Cluster.objects.get(id=self.data["cluster_id"]) - target_slave = cluster_model.storageinstance_set.get( - machine__bk_cloud_id=cluster_model.bk_cloud_id, - machine__ip=self.data["slave_ip"], - port=self.data["slave_port"], - ) - master = cluster_model.storageinstance_set.get(instance_inner_role=InstanceInnerRole.MASTER.value) - self.data["new_slave_ip"] = target_slave.machine.ip - self.data["bk_biz_id"] = cluster_model.bk_biz_id - self.data["bk_cloud_id"] = cluster_model.bk_cloud_id - self.data["db_module_id"] = cluster_model.db_module_id - self.data["time_zone"] = cluster_model.time_zone - self.data["created_by"] = self.ticket_data["created_by"] - self.data["module"] = cluster_model.db_module_id - self.data["force"] = self.ticket_data.get("force", False) - self.data["ticket_type"] = self.ticket_data["ticket_type"] - self.data["cluster_type"] = cluster_model.cluster_type - self.data["uid"] = self.ticket_data["uid"] - self.data["charset"], self.data["db_version"] = get_version_and_charset( - self.data["bk_biz_id"], - db_module_id=self.data["db_module_id"], - cluster_type=self.data["cluster_type"], - ) - tendb_migrate_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(self.data)) - - tendb_migrate_pipeline.add_act( - act_name=_("下发db-actor到节点{} {}".format(target_slave.machine.ip, master.machine.ip)), - act_component_code=TransFileComponent.code, - kwargs=asdict( - DownloadMediaKwargs( - bk_cloud_id=cluster_model.bk_cloud_id, - exec_ip=[target_slave.machine.ip, master.machine.ip], - file_list=GetFileList(db_type=DBType.MySQL).get_db_actuator_package(), - ) - ), - ) - cluster = { - "stop_slave": True, - "reset_slave": True, - "restart": False, - "force": self.data["force"], - "drop_database": True, - "new_slave_ip": target_slave.machine.ip, - "new_slave_port": target_slave.port, - "mysql_port": master.port, - "cluster_id": cluster_model.id, - "cluster_type": cluster_model.cluster_type, - "master_ip": master.machine.ip, - "master_port": master.port, - "bk_cloud_id": cluster_model.bk_cloud_id, - "file_target_path": f"/data/dbbak/{self.root_id}/{master.port}", - "charset": self.data["charset"], - "change_master_force": True, - "change_master": True, - } - - tendb_migrate_pipeline.add_act( - act_name=_("写入初始化实例的db_meta元信息"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.tendb_modify_storage_status.__name__, - cluster={ - "phase": InstancePhase.TRANS_STAGE.value, - "storage_status": InstanceStatus.RESTORING.value, - "storage_id": target_slave.id, - }, - is_update_trans_data=False, - ) - ), - ) - - # 屏蔽 - tendb_migrate_pipeline.add_act( - act_name=_("屏蔽监控 {}").format(target_slave.ip_port), - act_component_code=MysqlCrondMonitorControlComponent.code, - kwargs=asdict( - CrondMonitorKwargs( - bk_cloud_id=cluster_model.bk_cloud_id, - exec_ips=[target_slave.machine.ip], - port=target_slave.port, - ) - ), - ) - - tendb_migrate_pipeline.add_act( - act_name=_("从库reset slave {}").format(target_slave.ip_port), - act_component_code=MySQLExecuteRdsComponent.code, - kwargs=asdict( - ExecuteRdsKwargs( - bk_cloud_id=cluster_model.bk_cloud_id, - instance_ip=target_slave.machine.ip, - instance_port=target_slave.port, - sqls=["stop slave", "reset slave all"], - ) - ), - ) - - exec_act_kwargs = ExecActuatorKwargs( - bk_cloud_id=cluster_model.bk_cloud_id, - cluster_type=cluster_model.cluster_type, - cluster=cluster, - exec_ip=target_slave.machine.ip, - ) - exec_act_kwargs.get_mysql_payload_func = MysqlActPayload.get_clean_mysql_payload.__name__ - tendb_migrate_pipeline.add_act( - act_name=_("slave重建之清理从库{}").format(target_slave.ip_port), - act_component_code=ExecuteDBActuatorScriptComponent.code, - kwargs=asdict(exec_act_kwargs), - ) - - inst_list = ["{}{}{}".format(master.machine.ip, IP_PORT_DIVIDER, master.port)] - tendb_migrate_pipeline.add_sub_pipeline( - sub_flow=mysql_restore_data_sub_flow( - root_id=self.root_id, - ticket_data=copy.deepcopy(self.data), - cluster=cluster, - cluster_model=cluster_model, - ins_list=inst_list, - ) - ) - - # 卸载流程人工确认 - tendb_migrate_pipeline.add_act(act_name=_("人工确认"), act_component_code=PauseComponent.code, kwargs={}) - # 克隆权限 - new_slave = "{}{}{}".format(target_slave.machine.ip, IP_PORT_DIVIDER, master.port) - old_master = "{}{}{}".format(master.machine.ip, IP_PORT_DIVIDER, master.port) - clone_data = [ - { - "source": old_master, - "target": new_slave, - "bk_cloud_id": cluster_model.bk_cloud_id, - } - ] - tendb_migrate_pipeline.add_act( - act_name=_("克隆权限"), - act_component_code=CloneUserComponent.code, - kwargs=asdict(InstanceUserCloneKwargs(clone_data=clone_data)), - ) - # 添加域名 - domain_map = get_tendb_ha_entry(cluster_model.id) - domain_add_list = [] - for domain in domain_map[target_slave.machine.ip]: - domain_add_list.append( - { - "act_name": _("添加从库域名{}:{}").format(target_slave.machine.ip, domain), - "act_component_code": MySQLDnsManageComponent.code, - "kwargs": asdict( - UpdateDnsRecordKwargs( - bk_cloud_id=cluster_model.bk_cloud_id, - old_instance="{}#{}".format(target_slave.machine.ip, master.port), - new_instance="{}#{}".format(target_slave.machine.ip, master.port), - update_domain_name=domain, - ) - ), - } - ) - - if len(domain_add_list) > 0: - tendb_migrate_pipeline.add_parallel_acts(acts_list=domain_add_list) - - tendb_migrate_pipeline.add_act( - act_name=_("写入初始化实例的db_meta元信息"), - act_component_code=MySQLDBMetaComponent.code, - kwargs=asdict( - DBMetaOPKwargs( - db_meta_class_func=MySQLDBMeta.tendb_modify_storage_status.__name__, - cluster={ - "phase": InstancePhase.ONLINE.value, - "storage_status": InstanceStatus.RUNNING.value, - "storage_id": target_slave.id, - }, - is_update_trans_data=False, - ) - ), - ) - - tendb_migrate_pipeline.add_sub_pipeline( - sub_flow=build_surrounding_apps_sub_flow( - bk_cloud_id=cluster_model.bk_cloud_id, - master_ip_list=None, - slave_ip_list=[target_slave.machine.ip], - root_id=self.root_id, - parent_global_data=copy.deepcopy(self.data), - cluster_type=ClusterType.TenDBHA.value, - ) - ) - - tendb_migrate_pipeline_list.append( - tendb_migrate_pipeline.build_sub_process(_("slave原地重建{}").format(target_slave.ip_port)) - ) - - tendb_migrate_pipeline_all.add_parallel_sub_pipeline(sub_flow_list=tendb_migrate_pipeline_list) - tendb_migrate_pipeline_all.run_pipeline(init_trans_data_class=ClusterInfoContext(), is_drop_random_user=True) - - def deploy_add_slave_flow(self): - self.add_slave_only = True - self.deploy_restore_slave_flow() diff --git a/dbm-ui/backend/flow/engine/controller/mysql.py b/dbm-ui/backend/flow/engine/controller/mysql.py index dede529fc9..283a5f81ea 100644 --- a/dbm-ui/backend/flow/engine/controller/mysql.py +++ b/dbm-ui/backend/flow/engine/controller/mysql.py @@ -37,7 +37,6 @@ ) from backend.flow.engine.bamboo.scene.mysql.mysql_master_fail_over import MySQLMasterFailOverFlow from backend.flow.engine.bamboo.scene.mysql.mysql_master_slave_switch import MySQLMasterSlaveSwitchFlow -from backend.flow.engine.bamboo.scene.mysql.mysql_migrate_cluster_flow import MySQLMigrateClusterFlow from backend.flow.engine.bamboo.scene.mysql.mysql_migrate_cluster_remote_flow import MySQLMigrateClusterRemoteFlow from backend.flow.engine.bamboo.scene.mysql.mysql_open_area_flow import MysqlOpenAreaFlow from backend.flow.engine.bamboo.scene.mysql.mysql_partition import MysqlPartitionFlow @@ -48,7 +47,6 @@ from backend.flow.engine.bamboo.scene.mysql.mysql_push_peripheral_config import MySQLPushPeripheralConfigFlow from backend.flow.engine.bamboo.scene.mysql.mysql_random_password import MySQLRandomizePassword from backend.flow.engine.bamboo.scene.mysql.mysql_rename_database_flow import MySQLRenameDatabaseFlow -from backend.flow.engine.bamboo.scene.mysql.mysql_restore_slave_flow import MySQLRestoreSlaveFlow from backend.flow.engine.bamboo.scene.mysql.mysql_restore_slave_remote_flow import MySQLRestoreSlaveRemoteFlow from backend.flow.engine.bamboo.scene.mysql.mysql_rollback_data_flow import MySQLRollbackDataFlow from backend.flow.engine.bamboo.scene.mysql.mysql_single_apply_flow import MySQLSingleApplyFlow @@ -73,27 +71,6 @@ def mysql_single_apply_scene(self): flow = MySQLSingleApplyFlow(root_id=self.root_id, data=self.ticket_data) flow.deploy_flow() - def mysql_restore_slave_scene(self): - """ - tenDB slave 恢复流程编排 - """ - flow = MySQLRestoreSlaveFlow(root_id=self.root_id, tick_data=self.ticket_data) - flow.deploy_restore_slave_flow() - - def mysql_add_slave_scene(self): - """ - 仅添加 slave 流程编排 - """ - flow = MySQLRestoreSlaveFlow(root_id=self.root_id, tick_data=self.ticket_data) - flow.deploy_add_slave_flow() - - def mysql_restore_local_slave_scene(self): - """ - tenDB slave 原地恢复流程编排 - """ - flow = MySQLRestoreSlaveFlow(root_id=self.root_id, tick_data=self.ticket_data) - flow.deploy_restore_local_slave_flow() - # mysql 从节点恢复(接入备份系统) def mysql_restore_slave_remote_scene(self): """ @@ -402,13 +379,6 @@ def mysql_ha_rename_database_scene(self): ) flow.rename_database() - def mysql_migrate_cluster_scene(self): - """ - 主从成对迁移flow编排 - """ - flow = MySQLMigrateClusterFlow(root_id=self.root_id, ticket_data=self.ticket_data) - flow.deploy_migrate_cluster_flow() - def mysql_migrate_remote_scene(self): """ 主从成对迁移flow编排 diff --git a/dbm-ui/backend/flow/urls.py b/dbm-ui/backend/flow/urls.py index c923d8e17b..6b87278e8c 100644 --- a/dbm-ui/backend/flow/urls.py +++ b/dbm-ui/backend/flow/urls.py @@ -104,7 +104,6 @@ MultiReplicasetInstallApiView, ) from backend.flow.views.mysql import MysqlMachineClearApiView -from backend.flow.views.mysql_add_slave import AddMysqlSlaveSceneApiView from backend.flow.views.mysql_add_slave_remote import AddMysqlSlaveRemoteSceneApiView from backend.flow.views.mysql_checksum import MysqlChecksumSceneApiView from backend.flow.views.mysql_data_migrate import MysqlDataMigrateSceneApiView @@ -122,7 +121,6 @@ from backend.flow.views.mysql_ha_rename_database import MySQLHARenameDatabaseView from backend.flow.views.mysql_ha_switch import MySQLHASwitchSceneApiView from backend.flow.views.mysql_ha_truncate_data import MySQLHATruncateDataView -from backend.flow.views.mysql_migrate_cluster import MigrateMysqlClusterSceneApiView from backend.flow.views.mysql_migrate_cluster_remote import MysqlMigrateRemoteSceneApiView from backend.flow.views.mysql_open_area import MysqlOpenAreaSceneApiView from backend.flow.views.mysql_partition import MysqlPartitionSceneApiView @@ -132,8 +130,6 @@ from backend.flow.views.mysql_proxy_upgrade import UpgradeMySQLProxySceneApiView from backend.flow.views.mysql_pt_table_sync import MySQLPtTableSyncApiView from backend.flow.views.mysql_restore_local_remote import RestoreMysqlLocalRemoteSceneApiView -from backend.flow.views.mysql_restore_local_slave import RestoreMysqlLocalSlaveSceneApiView -from backend.flow.views.mysql_restore_slave import RestoreMysqlSlaveSceneApiView from backend.flow.views.mysql_restore_slave_remote import RestoreMysqlSlaveRemoteSceneApiView from backend.flow.views.mysql_rollback_data import MysqlRollbackDataSceneApiView from backend.flow.views.mysql_rollback_to_cluster import MysqlRollbackToClusterSceneApiView @@ -417,15 +413,11 @@ url(r"^scene/import_sqlfile$", ImportSQLFileSceneApiView.as_view()), url(r"^scene/switch_mysql_proxy$", SwitchMySQLProxySceneApiView.as_view()), url(r"^scene/add_mysql_proxy$", AddMySQLProxySceneApiView.as_view()), - url(r"^scene/restore_slave$", RestoreMysqlSlaveSceneApiView.as_view()), - url(r"^scene/add_slave$", AddMysqlSlaveSceneApiView.as_view()), - url(r"^scene/restore_local_slave$", RestoreMysqlLocalSlaveSceneApiView.as_view()), # 从节点数据恢复(接入备份系统) url(r"^scene/restore_slave_remote$", RestoreMysqlSlaveRemoteSceneApiView.as_view()), url(r"^scene/add_slave_remote$", AddMysqlSlaveRemoteSceneApiView.as_view()), url(r"^scene/restore_local_slave_remote$", RestoreMysqlLocalRemoteSceneApiView.as_view()), url(r"^scene/migrate_cluster_remote$", MysqlMigrateRemoteSceneApiView.as_view()), - url(r"^scene/migrate_cluster$", MigrateMysqlClusterSceneApiView.as_view()), url(r"^scene/mysql_rollback_data", MysqlRollbackDataSceneApiView.as_view()), url(r"^scene/mysql_rollback_to_cluster", MysqlRollbackToClusterSceneApiView.as_view()), url(r"^scene/install_es$", InstallEsSceneApiView.as_view()), diff --git a/dbm-ui/backend/flow/views/mysql_add_slave.py b/dbm-ui/backend/flow/views/mysql_add_slave.py deleted file mode 100644 index a916023f5b..0000000000 --- a/dbm-ui/backend/flow/views/mysql_add_slave.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- -""" -TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. -Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at https://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" -import logging - -from django.utils.translation import ugettext as _ -from rest_framework.response import Response - -from backend.flow.engine.controller.mysql import MySQLController -from backend.flow.views.base import FlowTestView -from backend.utils.basic import generate_root_id - -logger = logging.getLogger("root") - - -class AddMysqlSlaveSceneApiView(FlowTestView): - """ - { - "uid":"2022051612120001", - "created_by":"xxxx", - "bk_biz_id":"2005000194", - "module":1, - "ticket_type":"MYSQL_ADD_SLAVE", - "infos":[ - { - "cluster_ids":[ - 6 - ], - "new_slave_ip":"127.0.0.1", - "backup_source":"local" - } - ] - } - """ - - def post(self, request): - logger.info(_("开始添加slave")) - root_id = generate_root_id() - logger.info("define root_id: {}".format(root_id)) - mysql_controller_new = MySQLController(root_id, request.data) - mysql_controller_new.mysql_add_slave_scene() - return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/mysql_migrate_cluster.py b/dbm-ui/backend/flow/views/mysql_migrate_cluster.py deleted file mode 100644 index fc0ce938a1..0000000000 --- a/dbm-ui/backend/flow/views/mysql_migrate_cluster.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -""" -TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. -Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at https://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" -import logging - -from django.utils.translation import ugettext as _ -from rest_framework.response import Response - -from backend.flow.engine.controller.mysql import MySQLController -from backend.flow.views.base import FlowTestView -from backend.utils.basic import generate_root_id - -logger = logging.getLogger("root") - - -class MigrateMysqlClusterSceneApiView(FlowTestView): - """ - { - "uid":"2022051612120002", - "created_by":"xxxx", - "bk_biz_id":"152", - "module":1, - "ticket_type":"MYSQL_MIGRATE_CLUSTER", - "infos":[ - { - # 必须是同机器的clusterid - "cluster_ids":[ - 1,2,3,4 - ], - "new_master_ip":"xxx", - "new_slave_ip":xxx", - "backup_source":"local" - } - ] - } - """ - - def post(self, request): - logger.info(_("开始重建slave")) - root_id = generate_root_id() - logger.info("define root_id: {}".format(root_id)) - mysql_controller_new = MySQLController(root_id, request.data) - mysql_controller_new.mysql_migrate_cluster_scene() - return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/mysql_restore_local_slave.py b/dbm-ui/backend/flow/views/mysql_restore_local_slave.py deleted file mode 100644 index c92ea5b20c..0000000000 --- a/dbm-ui/backend/flow/views/mysql_restore_local_slave.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- -""" -TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. -Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at https://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" -import logging - -from django.utils.translation import ugettext as _ -from rest_framework.response import Response - -from backend.flow.engine.controller.mysql import MySQLController -from backend.flow.views.base import FlowTestView -from backend.utils.basic import generate_root_id - -logger = logging.getLogger("root") - - -class RestoreMysqlLocalSlaveSceneApiView(FlowTestView): - """ - { - "uid":"2022051612120002", - "created_by":"xxxx", - "bk_biz_id":"2005000194", - "module":1, - "ticket_type":"MYSQL_RESTORE_LOCAL_SLAVE", - "slaves":[ - { - "clusterid":3, - "slave_ip":"xxxx", - "slave_port":3306, - "backup_source":"master", - "force":false - } - ] - } - """ - - def post(self, request): - logger.info(_("开始原地重建slave")) - root_id = generate_root_id() - logger.info("define root_id: {}".format(root_id)) - mysql_controller_new = MySQLController(root_id, request.data) - mysql_controller_new.mysql_restore_local_slave_scene() - return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/mysql_restore_slave.py b/dbm-ui/backend/flow/views/mysql_restore_slave.py deleted file mode 100644 index 9a2f17e684..0000000000 --- a/dbm-ui/backend/flow/views/mysql_restore_slave.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -""" -TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. -Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at https://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" -import logging - -from django.utils.translation import ugettext as _ -from rest_framework.response import Response - -from backend.flow.engine.controller.mysql import MySQLController -from backend.flow.views.base import FlowTestView -from backend.utils.basic import generate_root_id - -logger = logging.getLogger("root") - - -class RestoreMysqlSlaveSceneApiView(FlowTestView): - """ - { - tenDB slave 恢复流程编排 - { - "uid":"2022051612120001", - "created_by":"xxxx", - "bk_biz_id":"152", - "module":1, - "ticket_type":"MYSQL_RESTORE_SLAVE", - "infos":[ - { - "cluster_ids":[ - 1,2,3,4 - ], - # 表示重建后是否强制卸载旧实例 - "force":false, - "old_slave_ip":"xxx", - "new_slave_ip":xxx", - "backup_source":"local" - } - ] - } - """ - - def post(self, request): - logger.info(_("开始重建slave")) - root_id = generate_root_id() - logger.info("define root_id: {}".format(root_id)) - request.data["add_slave_only"] = False - mysql_controller_new = MySQLController(root_id, request.data) - mysql_controller_new.mysql_restore_slave_scene() - return Response({"root_id": root_id})