Skip to content

Commit

Permalink
fix(backend): 资源申请同城同园区问题 TencentBlueKing#9165
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 29722
  • Loading branch information
ygcyao committed Jan 21, 2025
1 parent ec50f84 commit 4322682
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 11 additions & 3 deletions dbm-ui/backend/ticket/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from rest_framework import serializers

from backend import env
from backend.configuration.constants import SystemSettingsEnum
from backend.configuration.constants import AffinityEnum, SystemSettingsEnum
from backend.configuration.models import DBAdministrator, SystemSettings
from backend.db_meta.models import AppCache, Cluster
from backend.db_meta.models import AppCache, Cluster, Machine
from backend.db_services.dbbase.constants import IpSource
from backend.iam_app.dataclass.actions import ActionEnum
from backend.ticket.constants import TICKET_EXPIRE_DEFAULT_CONFIG, FlowRetryType, FlowType, TicketType
Expand Down Expand Up @@ -243,10 +243,18 @@ def patch_affinity_location(cls, cluster, resource_spec, roles=None):
"""
节点变更的时候,补充亲和性和位置参数
"""
bk_sub_zone_id = None
# 同城同园区集群的园区id处理
if cluster.disaster_tolerance_level in [AffinityEnum.SAME_SUBZONE, AffinityEnum.SAME_SUBZONE_CROSS_SWTICH]:
bk_sub_zone_id = cluster.storageinstance_set.first().machine.bk_sub_zone_id

resource_role = roles or resource_spec.keys()
for role in resource_role:
resource_spec[role]["affinity"] = cluster.disaster_tolerance_level
resource_spec[role]["location_spec"] = {"city": cluster.region, "sub_zone_ids": []}
resource_spec[role]["location_spec"] = {
"city": cluster.region,
"sub_zone_ids": [bk_sub_zone_id] if bk_sub_zone_id else [],
}


class TicketFlowBuilder:
Expand Down
14 changes: 13 additions & 1 deletion dbm-ui/backend/ticket/builders/redis/redis_toolbox_cut_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from backend.configuration.constants import AffinityEnum
from backend.db_meta.enums import InstanceRole
from backend.db_meta.models import Cluster, StorageInstance
from backend.db_services.dbbase.constants import IpSource
Expand Down Expand Up @@ -118,12 +119,23 @@ def patch_ticket_detail(self):
continue

if role in [InstanceRole.REDIS_MASTER.value, InstanceRole.REDIS_PROXY.value]:
# 同城同园区集群的园区id处理
bk_sub_zone_id = None
if cluster.disaster_tolerance_level in [
AffinityEnum.SAME_SUBZONE,
AffinityEnum.SAME_SUBZONE_CROSS_SWTICH,
]:
bk_sub_zone_id = cluster.storageinstance_set.first().machine.bk_sub_zone_id

# 如果替换角色是master,则是master/slave成对替换
resource_role = "backend_group" if role == InstanceRole.REDIS_MASTER.value else role
resource_spec[resource_role] = {
"spec_id": info[role][0]["spec_id"],
"count": len(role_hosts),
"location_spec": {"city": cluster.region, "sub_zone_ids": []},
"location_spec": {
"city": cluster.region,
"sub_zone_ids": [bk_sub_zone_id] if bk_sub_zone_id else [],
},
"affinity": cluster.disaster_tolerance_level,
}
# 如果是proxy,则至少跨两个机房
Expand Down

0 comments on commit 4322682

Please sign in to comment.