Skip to content

Commit

Permalink
fix(sqlserver): sqlserver资源池协议联调 TencentBlueKing#9461
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 31699
  • Loading branch information
ygcyao committed Feb 27, 2025
1 parent 4b18b65 commit 62b7978
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def format_ticket_data(self):

class SQLServerRestoreSlaveResourceParamBuilder(SQLServerBaseOperateResourceParamBuilder):
def format(self):
slave_hosts = get_target_items_from_details(self.ticket.details, match_keys=["bk_host_id"])
slave_hosts = get_target_items_from_details(self.ticket_data, match_keys=["bk_host_id"])
# 根据从库host_id获取对应主库的host_id
slave_master_mapping = (
Machine.objects.prefetch_related(
Expand All @@ -96,12 +96,14 @@ def format(self):

id__machine = {
machine.bk_host_id: machine
for machine in Machine.objects.prefetch_related("bk_city__logical_city").filter(bk_host_id__in=master_hosts)
for machine in Machine.objects.prefetch_related("bk_city__logical_city").filter(
bk_host_id__in=master_hosts
)
}
cluster_ids = list(itertools.chain(*[infos["cluster_ids"] for infos in self.ticket.details["infos"]]))
cluster_ids = list(itertools.chain(*[infos["cluster_ids"] for infos in self.ticket_data["infos"]]))
id__cluster = {cluster.id: cluster for cluster in Cluster.objects.filter(id__in=cluster_ids)}

for info in self.ticket.details["infos"]:
for info in self.ticket_data["infos"]:
cluster = id__cluster[info["cluster_ids"][0]]

# 申请新的slave, 需要和当前集群中的master处于不同机房;
Expand All @@ -113,21 +115,22 @@ def format(self):
info["resource_params"] = {"os_type": BkOsType.WINDOWS.value}
info["resource_spec"]["sqlserver_ha"].update(
affinity=cluster.disaster_tolerance_level,
location_spec={"city": master_machine.bk_city.logical_city.name, "sub_zone_ids": []}
location_spec={"city": master_machine.bk_city.logical_city.name, "sub_zone_ids": []},
)

# 根据亲和性补充园区信息
if cluster.disaster_tolerance_level == AffinityEnum.CROS_SUBZONE:
info["resource_spec"]["sqlserver_ha"]["location_spec"].update(
sub_zone_ids=[master_machine.bk_sub_zone_id], include_or_exclue=False
)
elif cluster.disaster_tolerance_level in [AffinityEnum.SAME_SUBZONE, AffinityEnum.SAME_SUBZONE_CROSS_SWTICH]:
elif cluster.disaster_tolerance_level in [
AffinityEnum.SAME_SUBZONE,
AffinityEnum.SAME_SUBZONE_CROSS_SWTICH,
]:
info["resource_spec"]["sqlserver_ha"]["location_spec"].update(
sub_zone_ids=[master_machine.bk_sub_zone_id], include_or_exclue=True
)

self.ticket.save(update_fields=["details"])

def post_callback(self):
next_flow = self.ticket.next_flow()
for info in next_flow.details["ticket_data"]["infos"]:
Expand Down

0 comments on commit 62b7978

Please sign in to comment.