From dc9578c632230719118153a05abf067584547ffc Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Fri, 18 Oct 2024 20:09:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20tendbcluster=E9=87=8D=E5=BB=BAs?= =?UTF-8?q?lave=E8=A1=A5=E5=85=85=E4=BA=B2=E5=92=8C=E6=80=A7=20#7431?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/ticket/builders/common/base.py | 7 ----- .../sqlserver/sqlserver_restore_slave.py | 1 + .../tendbcluster/tendb_restore_slave.py | 27 +++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/dbm-ui/backend/ticket/builders/common/base.py b/dbm-ui/backend/ticket/builders/common/base.py index cd05dce1ed..d085963533 100644 --- a/dbm-ui/backend/ticket/builders/common/base.py +++ b/dbm-ui/backend/ticket/builders/common/base.py @@ -23,7 +23,6 @@ from backend.db_meta.enums import AccessLayer, ClusterPhase, ClusterType, InstanceInnerRole, InstanceStatus from backend.db_meta.enums.comm import SystemTagEnum from backend.db_meta.models import Cluster, ExtraProcessInstance, Machine, ProxyInstance, Spec, StorageInstance -from backend.db_services.ipchooser.constants import BkOsType from backend.db_services.ipchooser.query.resource import ResourceQueryHelper from backend.db_services.mysql.cluster.handlers import ClusterServiceHandler from backend.db_services.mysql.dumper.handlers import DumperHandler @@ -533,12 +532,6 @@ def format(self): if info.get("bk_cloud_id") and info.get("bk_biz_id"): continue - # 获取系统版本跟类型 - os_names = info.get("system_version") - os_type = BkOsType.db_type_to_os_type(TicketType.get_db_type_by_ticket(self.ticket.ticket_type)) - # 增加os_names和os_type过滤 - info["resource_params"] = {"os_names": os_names, "os_type": os_type} - # 默认从集群中获取云区域ID和业务ID cluster_id = info.get("cluster_id") or info.get("src_cluster") or info.get("cluster_ids")[0] bk_cloud_id = id__clusters[cluster_id].bk_cloud_id diff --git a/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py b/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py index 472b8d01d6..8c44d59d78 100644 --- a/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py +++ b/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py @@ -94,6 +94,7 @@ def format(self): for info in self.ticket.details["infos"]: # 申请新的slave, 需要和当前集群中的master处于不同机房; master_machine = id__machine[formatted_dict[info["old_slave_host"]["bk_host_id"]]] + # TODO: 还有补充操作系统 info["resource_spec"]["sqlserver_ha"]["location_spec"] = { "city": master_machine.bk_city.logical_city.name, "sub_zone_ids": [master_machine.bk_sub_zone_id], diff --git a/dbm-ui/backend/ticket/builders/tendbcluster/tendb_restore_slave.py b/dbm-ui/backend/ticket/builders/tendbcluster/tendb_restore_slave.py index 556f6b68ff..0660bd8b5e 100644 --- a/dbm-ui/backend/ticket/builders/tendbcluster/tendb_restore_slave.py +++ b/dbm-ui/backend/ticket/builders/tendbcluster/tendb_restore_slave.py @@ -12,7 +12,9 @@ from django.utils.translation import gettext_lazy as _ from rest_framework import serializers +from backend.configuration.constants import AffinityEnum from backend.db_meta.enums import ClusterType +from backend.db_meta.models import StorageInstance from backend.db_services.dbbase.constants import IpSource from backend.flow.engine.controller.spider import SpiderController from backend.ticket import builders @@ -21,6 +23,7 @@ from backend.ticket.builders.mysql.mysql_restore_slave import MysqlRestoreSlaveDetailSerializer from backend.ticket.builders.tendbcluster.base import BaseTendbTicketFlowBuilder from backend.ticket.constants import TicketType +from backend.utils.basic import get_target_items_from_details class TendbClusterRestoreSlaveDetailSerializer(MysqlRestoreSlaveDetailSerializer): @@ -63,6 +66,30 @@ def format_ticket_data(self): class TendbClusterRestoreSlaveResourceParamBuilder(BaseOperateResourceParamBuilder): + def patch_slave_subzone(self): + # 对于亲和性为跨园区的,slave和master需要在不同园区 + slave_host_ids = get_target_items_from_details(self.ticket.details, match_keys=["bk_host_id"]) + slaves = StorageInstance.objects.prefetch_related("as_receiver__ejector__machine", "machine").filter( + machine__bk_host_id__in=slave_host_ids, cluster_type=ClusterType.TenDBCluster + ) + slave_host_map = {slave.machine.bk_host_id: slave for slave in slaves} + for info in self.ticket_data["infos"]: + resource_spec = info["resource_spec"]["new_slave"] + slave = slave_host_map[info["old_slave"]["bk_host_id"]] + master_subzone_id = slave.as_receiver.get().ejector.machine.bk_sub_zone_id + # 同城跨园区,要求slave和master在不同subzone + if resource_spec["affinity"] == AffinityEnum.CROS_SUBZONE: + resource_spec["location_spec"].update(sub_zone_ids=[master_subzone_id], include_or_exclue=False) + # 同城同园区,要求slave和master在一个subzone + elif resource_spec["affinity"] in [AffinityEnum.SAME_SUBZONE, AffinityEnum.SAME_SUBZONE_CROSS_SWTICH]: + resource_spec["location_spec"].update(sub_zone_ids=[master_subzone_id], include_or_exclue=True) + + def format(self): + # 补充亲和性和城市信息 + super().patch_info_affinity_location(roles=["new_slave"]) + # 补充slave园区申请 + self.patch_slave_subzone() + def post_callback(self): next_flow = self.ticket.next_flow() ticket_data = next_flow.details["ticket_data"]