Skip to content

Commit

Permalink
feat: 调整mysql单据碰到一些问题 #3699
Browse files Browse the repository at this point in the history
  • Loading branch information
yksitu committed Mar 27, 2024
1 parent 7d2a97b commit e3eebbd
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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实例的公共子流
Expand All @@ -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服务去获取对应的
Expand Down Expand Up @@ -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,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]],
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class MySQLProxyClusterSwitchFlow(object):
构建mysql集群替换proxy实例申请流程抽象类
替换proxy 是属于整机替换,新的机器必须不在dbm系统记录上线过
兼容跨云区域的场景支持
todo 后续需要优化实例下架逻辑,避免误报
"""

def __init__(self, root_id: str, data: Optional[Dict]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down Expand Up @@ -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=_("部署子流程"))
2 changes: 1 addition & 1 deletion dbm-ui/backend/flow/engine/controller/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand All @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e3eebbd

Please sign in to comment.