Skip to content

Commit

Permalink
fix(backend): 补充关联ip数量 #7747
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Dec 9, 2024
1 parent a4a32a2 commit fbd1f38
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/dbresource/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self):
method="POST", url="/statistic/summary", description=_("按照条件聚合资源统计")
)
self.resource_label_count = self.generate_data_api(
method="POST", url="/groupby/label/count", description=_("按照标签统计资源数量")
method="POST", url="/resource/groupby/label/count", description=_("按照标签统计资源数量")
)


Expand Down
6 changes: 4 additions & 2 deletions dbm-ui/backend/db_services/dbresource/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ def _format_resource_fields(data, _cloud_info, _biz_infos, _tag_infos):
"bk_biz_id": data["dedicated_biz"],
"bk_biz_name": _biz_infos.get(data["dedicated_biz"]),
},
"agent_status": int((data.pop("gse_agent_status_code") == GseApi.Constants.GSE_AGENT_RUNNING_CODE)),
"agent_status": int(
(data.pop("gse_agent_status_code") == GseApi.Constants.GSE_AGENT_RUNNING_CODE)
),
"labels": [{"id": _tag, "name": _tag_infos.get(int(_tag))} for _tag in data.pop("labels") or []],
}
)
Expand Down Expand Up @@ -467,7 +469,7 @@ def _format_resource_fields(data, _cloud_info, _biz_infos, _tag_infos):
def standardized_resource_host(cls, hosts, bk_biz_id=None):
"""标准化主机信息,将cc字段统一成资源池字段"""
host_ids = [host["bk_host_id"] for host in hosts]
hosts = ResourceQueryHelper.search_cc_hosts(role_host_ids=host_ids, bk_biz_id=bk_biz_id)
hosts = ResourceQueryHelper.search_cc_hosts(role_host_ids=host_ids)
for host in hosts:
host.update(
bk_biz_id=bk_biz_id,
Expand Down
2 changes: 2 additions & 0 deletions dbm-ui/backend/db_services/dbresource/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def validate(self, attrs):
if exist_hosts:
raise serializers.ValidationError(_("导入主机{}存在元数据,请检查后重新导入").format(exist_hosts))

return attrs


class ResourceApplySerializer(serializers.Serializer):
class HostDetailSerializer(serializers.Serializer):
Expand Down
4 changes: 3 additions & 1 deletion dbm-ui/backend/db_services/tag/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from django.db.models import ManyToManyRel
from django.utils.translation import gettext_lazy as _

from backend.components.dbresource.client import DBResourceApi
from backend.db_meta.models import Tag
from backend.db_services.tag.constants import TAG_RELATED_RESOURCE_DISPLAY_FIELD, TagResourceType
from backend.exceptions import ValidationError
Expand Down Expand Up @@ -79,7 +80,8 @@ def query_related_resources(cls, ids: List[int], resource_type: str = None):

if resource_type == TagResourceType.DB_RESOURCE.value:
# 资源池根据标签聚合数量
data = [{"id": tag_id, "ip_count": 0} for tag_id in ids]
label_count_map = DBResourceApi.resource_label_count()
data = [{"id": tag_id, "ip_count": label_count_map.get(str(tag_id), 0)} for tag_id in ids]

return data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ def format(self):
bk_host_id__in=master_hosts
)
}
for info in self.ticket.details["infos"]:
for info in self.ticket_data["infos"]:
# 申请新的slave, 需要和当前集群中的master处于不同机房;
master_machine = id__machine[formatted_dict[info["old_slave_host"]["bk_host_id"]]]
old_slave_host = info["old_nodes"]["old_slave_host"][0]
master_machine = id__machine[formatted_dict[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],
"include_or_exclue": False,
}
self.ticket.save(update_fields=["details"])
info.update(bk_cloud_id=master_machine.bk_cloud_id)

def post_callback(self):
next_flow = self.ticket.next_flow()
Expand Down

0 comments on commit fbd1f38

Please sign in to comment.