From 01633c612aeaed30158b81c4e667538481c5103d Mon Sep 17 00:00:00 2001 From: yksitu <1297650644@qq.com> Date: Fri, 6 Sep 2024 15:44:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20sqlserver=E6=B7=BB=E5=8A=A0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=AE=9E=E4=BE=8B=E5=85=BC=E5=AE=B9=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=A2=E5=A4=AB=E7=9A=84=E5=9C=BA=E6=99=AF=20#6659?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/cluster/sqlserverha/handler.py | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py b/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py index 7f8bdcb888..e072cad148 100644 --- a/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py +++ b/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py @@ -10,6 +10,7 @@ from django.db import transaction +from backend.configuration.constants import DBType from backend.db_meta import api from backend.db_meta.api.cluster.base.handler import ClusterHandler from backend.db_meta.enums import ( @@ -23,6 +24,7 @@ MachineType, ) from backend.db_meta.models import Cluster, ClusterEntry, ClusterMonitorTopo, StorageInstance, StorageInstanceTuple +from backend.db_meta.models.cluster_monitor import INSTANCE_MONITOR_PLUGINS from backend.flow.utils.cc_manage import CcManage from backend.flow.utils.sqlserver.sqlserver_host import Host from backend.flow.utils.sqlserver.sqlserver_module_operate import SqlserverCCTopoOperator @@ -186,17 +188,40 @@ def switch_role(cls, cluster_ids: list, old_master: Host, new_master: Host, is_f slave_entry.storageinstance_set.add(old_master_storage_objs) cc_manage = CcManage(cluster.bk_biz_id, cluster.cluster_type) + bk_module_id = ClusterMonitorTopo.objects.get( + bk_biz_id=cluster.bk_biz_id, cluster_id=cluster.id, machine_type=new_master_storage_objs.machine_type + ).bk_module_id + func_name = INSTANCE_MONITOR_PLUGINS[DBType.Sqlserver.value][new_master_storage_objs.machine_type][ + "func_name" + ] + # 切换新master服务实例角色标签 - cc_manage.add_label_for_service_instance( - bk_instance_ids=[new_master_storage_objs.bk_instance_id], + bk_instance_id = cc_manage.add_service_instance( + bk_module_id=bk_module_id, + bk_host_id=new_master_storage_objs.machine.bk_host_id, + listen_ip=new_master_storage_objs.machine.ip, + listen_port=new_master_storage_objs.port, + func_name=func_name, + bk_process_name=f"{DBType.Sqlserver.value}-{new_master_storage_objs.machine_type}", labels_dict={"instance_role": InstanceRole.BACKEND_MASTER.value}, ) + # 保存到数据库 + new_master_storage_objs.bk_instance_id = bk_instance_id + new_master_storage_objs.save(update_fields=["bk_instance_id"]) # 切换新slave服务实例角色标签 - cc_manage.add_label_for_service_instance( - bk_instance_ids=[old_master_storage_objs.bk_instance_id], + bk_instance_id = cc_manage.add_service_instance( + bk_module_id=bk_module_id, + bk_host_id=old_master_storage_objs.machine.bk_host_id, + listen_ip=old_master_storage_objs.machine.ip, + listen_port=old_master_storage_objs.port, + func_name=func_name, + bk_process_name=f"{DBType.Sqlserver.value}-{old_master_storage_objs.machine_type}", labels_dict={"instance_role": InstanceRole.BACKEND_SLAVE.value}, ) + # 保存到数据库 + old_master_storage_objs.bk_instance_id = bk_instance_id + old_master_storage_objs.save(update_fields=["bk_instance_id"]) @classmethod @transaction.atomic