Skip to content

Commit

Permalink
feat: sqlserver添加服务实例兼容信息丢夫的场景 TencentBlueKing#6659
Browse files Browse the repository at this point in the history
  • Loading branch information
yksitu committed Sep 6, 2024
1 parent 3799cbb commit 01633c6
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01633c6

Please sign in to comment.