diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/common_sub_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/common_sub_flow.py index e9991d80cb..9d054501c5 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/common_sub_flow.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/common_sub_flow.py @@ -456,7 +456,12 @@ def build_repl_by_manual_input_sub_flow( def install_mysql_in_cluster_sub_flow( - uid: str, root_id: str, cluster: Cluster, new_mysql_list: list, install_ports: list + uid: str, + root_id: str, + cluster: Cluster, + new_mysql_list: list, + install_ports: list, + bk_host_ids: list = None, ): """ 设计基于某个cluster,以及计算好的实例安装端口列表,对新机器安装mysql实例的公共子流 @@ -466,6 +471,7 @@ def install_mysql_in_cluster_sub_flow( @param cluster: 关联的cluster对象 @param new_mysql_list: 新机器列表,每个元素是ip @param install_ports: 每台机器按照的实例端口列表 + @param bk_host_ids: 新机器列表,每个元素是bk_host_id """ # 目前先根据cluster对应,请求bk-config服务去获取对应的 @@ -516,6 +522,7 @@ def install_mysql_in_cluster_sub_flow( sys_init_ips=new_mysql_list, init_check_ips=new_mysql_list, yum_install_perl_ips=new_mysql_list, + bk_host_ids=bk_host_ids, ) ) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_master_fail_over.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_master_fail_over.py index 12ddb21cf2..3de8b9cc80 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_master_fail_over.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_master_fail_over.py @@ -84,6 +84,9 @@ def master_fail_over_flow(self): sub_flow_context = copy.deepcopy(self.data) sub_flow_context.pop("infos") + # 做个标记位,代表切换后旧master的statues标记为unavailable + sub_flow_context["is_unavailable"] = True + sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(sub_flow_context)) sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_add.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_add.py index a4930a3446..c6d7df0041 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_add.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_add.py @@ -137,6 +137,7 @@ def add_mysql_cluster_proxy_flow(self): sys_init_ips=[info["proxy_ip"]["ip"]], init_check_ips=[info["proxy_ip"]["ip"]], yum_install_perl_ips=[info["proxy_ip"]["ip"]], + bk_host_ids=[info["proxy_ip"]["bk_host_id"]], ) ) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_switch.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_switch.py index 0d460b8a98..56f3fb29c2 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_switch.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_proxy_cluster_switch.py @@ -45,7 +45,6 @@ class MySQLProxyClusterSwitchFlow(object): 构建mysql集群替换proxy实例申请流程抽象类 替换proxy 是属于整机替换,新的机器必须不在dbm系统记录上线过 兼容跨云区域的场景支持 - todo 后续需要优化实例下架逻辑,避免误报 """ def __init__(self, root_id: str, data: Optional[Dict]): diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_single_apply_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_single_apply_flow.py index 27fdbe5e35..c2238ccf95 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_single_apply_flow.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/mysql_single_apply_flow.py @@ -65,13 +65,22 @@ def __calc_install_ports(self, inst_sum: int = 0) -> list: return install_mysql_ports - def deploy_mysql_single_flow_with_manual(self): + def deploy_flow(self): + """ + 父流程 + """ + pipeline = Builder(root_id=self.root_id, data=self.data) + pipeline.add_sub_pipeline(sub_flow=self.deploy_mysql_single_flow()) + pipeline.run_pipeline(init_trans_data_class=SingleApplyManualContext()) + + def deploy_mysql_single_flow(self): """ 定义部署单节点集群的流程,资源是通过手动录入方式,兼容单机多实例的部署 目前资源池已经在saas层适配,目前flow统一为手动模式即可 + 更新为子流程,方便别的流程调用 """ - mysql_single_pipeline = Builder(root_id=self.root_id, data=self.data) + mysql_single_pipeline = SubBuilder(root_id=self.root_id, data=self.data) sub_pipelines = [] for info in self.data["apply_infos"]: @@ -196,4 +205,4 @@ def deploy_mysql_single_flow_with_manual(self): sub_pipelines.append(sub_pipeline.build_sub_process(sub_name=_("部署单节点集群"))) mysql_single_pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines) - mysql_single_pipeline.run_pipeline(init_trans_data_class=SingleApplyManualContext()) + return mysql_single_pipeline.build_sub_process(sub_name=_("部署子流程")) diff --git a/dbm-ui/backend/flow/engine/controller/mysql.py b/dbm-ui/backend/flow/engine/controller/mysql.py index 221486359f..1692bb7db4 100644 --- a/dbm-ui/backend/flow/engine/controller/mysql.py +++ b/dbm-ui/backend/flow/engine/controller/mysql.py @@ -59,7 +59,7 @@ def mysql_single_apply_scene(self): 部署tenDB(mysql)单实例场景(新flow编排) """ flow = MySQLSingleApplyFlow(root_id=self.root_id, data=self.ticket_data) - flow.deploy_mysql_single_flow_with_manual() + flow.deploy_flow() def mysql_restore_slave_scene(self): """ diff --git a/dbm-ui/backend/flow/plugins/components/collections/common/download_backup_client.py b/dbm-ui/backend/flow/plugins/components/collections/common/download_backup_client.py index 08684842cd..e028bdb410 100644 --- a/dbm-ui/backend/flow/plugins/components/collections/common/download_backup_client.py +++ b/dbm-ui/backend/flow/plugins/components/collections/common/download_backup_client.py @@ -12,6 +12,8 @@ from pipeline.component_framework.component import Component +from backend.components import DBConfigApi +from backend.components.dbconfig.constants import FormatType from backend.components.mysql_backup.client import MysqlBackupApi from backend.flow.consts import BACKUP_TAG from backend.flow.plugins.components.collections.common.base_service import BaseService @@ -29,8 +31,31 @@ class DownloadBackupClientService(BaseService): } """ + @staticmethod + def _get_download_config(bk_biz_id: int, bk_cloud_id: int) -> dict: + """ + 获取安装backup_client获取配置 + """ + + data = DBConfigApi.query_conf_item( + { + "bk_biz_id": str(bk_biz_id), + "level_name": "bk_cloud_id", + "level_value": str(bk_cloud_id), + "conf_file": "backup_client", + "conf_type": "backup", + "namespace": "tendbcomm", + "format": FormatType.MAP_LEVEL, + } + )["content"] + + return data + def _execute(self, data, parent_data) -> bool: kwargs = data.get_one_of_inputs("kwargs") + backup_config = self._get_download_config( + bk_cloud_id=int(kwargs["bk_cloud_id"]), bk_biz_id=int(kwargs["bk_biz_id"]) + ) self.log_info("download and install backup_client receive ips: {}".format(kwargs["download_host_list"])) params = { @@ -44,6 +69,7 @@ def _execute(self, data, parent_data) -> bool: "os_user": kwargs["backup_os_user"], "auth_path_overwrite": True, }, + "default_storage_type": backup_config["default_storage_type"], } MysqlBackupApi.download_backup_client(params=params) diff --git a/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py b/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py index fdaf859c5e..f215f9ecfb 100644 --- a/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py +++ b/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py @@ -422,11 +422,16 @@ def mysql_ha_switch(self): # 对换主从实例的角色信息 slave_storage_objs.instance_role = InstanceRole.BACKEND_MASTER slave_storage_objs.instance_inner_role = InstanceInnerRole.MASTER - slave_storage_objs.save(update_fields=["instance_role", "instance_inner_role"]) + slave_storage_objs.save() master_storage_objs.instance_role = InstanceRole.BACKEND_SLAVE master_storage_objs.instance_inner_role = InstanceInnerRole.SLAVE - master_storage_objs.save(update_fields=["instance_role", "instance_inner_role"]) + + # 如果是主故障切换,旧master的状态设置为UNAVAILABLE + if self.ticket_data.get("is_unavailable", False): + master_storage_objs.status = InstanceStatus.UNAVAILABLE + + master_storage_objs.save() # 修改db-meta主从的映射关系 StorageInstanceTuple.objects.filter(ejector=master_storage_objs, receiver=slave_storage_objs).update(