From 51e2e8648e98520b7c615230fe5f6ef34b2a0cbf Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Wed, 20 Nov 2024 17:21:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E5=9F=9F=E5=90=8D=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91=20#8078?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db_services/dbbase/resources/query.py | 127 ++++++++++++++++++ .../dbbase/resources/serializers.py | 18 ++- .../db_services/dbbase/resources/viewsets.py | 9 ++ .../db_services/dbbase/resources/yasg_slz.py | 12 ++ .../db_services/mongodb/resources/views.py | 16 ++- .../db_services/mongodb/resources/yasg_slz.py | 8 -- .../mysql/resources/tendbcluster/views.py | 11 +- .../mysql/resources/tendbcluster/yasg_slz.py | 8 -- .../mysql/resources/tendbha/views.py | 11 +- .../mysql/resources/tendbha/yasg_slz.py | 8 -- .../mysql/resources/tendbsingle/views.py | 11 +- .../mysql/resources/tendbsingle/yasg_slz.py | 8 -- .../redis/resources/redis_cluster/views.py | 11 +- .../redis/resources/redis_cluster/yasg_slz.py | 8 -- .../sqlserver/resources/sqlserver_ha/views.py | 11 +- .../resources/sqlserver_ha/yasg_slz.py | 8 -- .../resources/sqlserver_single/views.py | 11 +- .../resources/sqlserver_single/yasg_slz.py | 8 -- dbm-ui/backend/flow/consts.py | 1 - 19 files changed, 239 insertions(+), 66 deletions(-) diff --git a/dbm-ui/backend/db_services/dbbase/resources/query.py b/dbm-ui/backend/db_services/dbbase/resources/query.py index 412796246d..f79ebdfb3e 100644 --- a/dbm-ui/backend/db_services/dbbase/resources/query.py +++ b/dbm-ui/backend/db_services/dbbase/resources/query.py @@ -309,6 +309,12 @@ def list_machines(cls, bk_biz_id: int, query_params: Dict, limit: int, offset: i resource_list = cls._list_machines(bk_biz_id, query_params, limit, offset) return resource_list + @classmethod + def list_cluster_entries(cls, bk_biz_id: int, query_params: Dict, limit: int, offset: int) -> ResourceList: + """查询域名列表""" + resource_list = cls._list_cluster_entries(bk_biz_id, query_params, limit, offset) + return resource_list + @classmethod @abc.abstractmethod def _list_machines( @@ -323,6 +329,20 @@ def _list_machines( """查询机器列表. 具体方法在子类中实现""" raise NotImplementedError + @classmethod + @abc.abstractmethod + def _list_cluster_entries( + cls, + bk_biz_id: int, + query_params: Dict, + limit: int, + offset: int, + filter_params_map: Dict[str, Q] = None, + **kwargs, + ) -> ResourceList: + """查询域名列表(适用于域名选择器),具体方法在子类中实现""" + raise NotImplementedError + @classmethod @abc.abstractmethod def get_topo_graph(cls, bk_biz_id: int, cluster_id: int) -> dict: @@ -901,3 +921,110 @@ def _get_machine_extra_info(cls, machine: Machine) -> dict: "related_instances": instances, "related_clusters": related_clusters_map.values(), } + + @classmethod + def _list_cluster_entries( + cls, + bk_biz_id: int, + query_params: Dict, + limit: int, + offset: int, + filter_params_map: Dict[str, Q] = None, + **kwargs, + ) -> ResourceList: + """ + 查询域名信息 + @param bk_biz_id: 业务 ID + @param query_params: 查询条件. 通过 .serializers.ListResourceSLZ 完成数据校验 + @param limit: 分页查询, 每页展示的数目 + @param offset: 分页查询, 当前页的偏移数 + @param filter_params_map: 过滤参数map + """ + query_filters = Q(cluster__bk_biz_id=bk_biz_id, cluster__cluster_type__in=cls.cluster_types) + + # 实例筛选 + def filter_instance_func(query_params): + """实例过滤ip:port 以及 ip 两种情况""" + f = build_q_for_instance_filter(query_params) & Q(bk_biz_id=bk_biz_id, cluster_type__in=cls.cluster_types) + inst_q = Q(cluster__storageinstance__in=StorageInstance.objects.filter(f)) | Q( + cluster__proxyinstance__in=ProxyInstance.objects.filter(f) + ) + return inst_q + + # 定义内置的过滤参数map + filter_params_map = filter_params_map or {} + inner_filter_params_map = { + "cluster_entry_type": Q(cluster_entry_type=query_params.get("cluster_entry_type")), + "role": Q(role=query_params.get("role")), + "domain": ( + Q(entry__icontains=query_params.get("domain")) | Q(entry__in=query_params.get("domain", "").split(",")) + ), + "cluster_name": Q(cluster__name=query_params.get("cluster_name")), + "instance": filter_instance_func(query_params), + } + filter_params_map = {**inner_filter_params_map, **filter_params_map} + + # 通过基础过滤参数进行cluster过滤 + for param in filter_params_map: + if query_params.get(param): + query_filters &= filter_params_map[param] + + entry_queryset = ClusterEntry.objects.filter(query_filters).distinct() + entry_infos = cls._filter_entry_hook(bk_biz_id, entry_queryset, limit, offset, **kwargs) + return entry_infos + + @classmethod + def _filter_entry_hook( + cls, + bk_biz_id, + entry_queryset: QuerySet, + limit: int, + offset: int, + **kwargs, + ) -> ResourceList: + """ + 为查询的域名填充额外信息, 子类可继承此方法实现其他回调 + @param bk_biz_id: 业务ID + @param machine_queryset: 过滤机器查询集 + @param limit: 分页限制 + @param offset: 分页起始 + """ + + count = entry_queryset.count() + limit = count if limit == -1 else limit + if count == 0: + return ResourceList(count=0, data=[]) + + # 预取proxy_queryset,storage_queryset,加块查询效率 + entry_queryset = entry_queryset.order_by("-create_at")[offset : limit + offset].prefetch_related( + "cluster__storageinstance_set__machine", "cluster__proxyinstance_set__machine" + ) + + # 将集群的查询结果序列化为集群字典信息 + entry_infos: List[Dict[str, Any]] = [] + for entry in entry_queryset: + entry_infos.append(cls._to_entry_representation(entry, **kwargs)) + + return ResourceList(count=count, data=entry_infos) + + @classmethod + def _to_entry_representation( + cls, + entry: ClusterEntry, + **kwargs, + ) -> Dict[str, Any]: + """ + 将域名对象转为可序列化的 dict 结构 + @param entry: model ClusterEntry 对象, 增加了 storages 和 proxies 属性 + """ + storage_list = [inst.ip_port for inst in entry.cluster.storageinstance_set.all()] + proxy_list = [inst.ip_port for inst in entry.cluster.proxyinstance_set.all()] + entry_info = { + "domain": entry.entry, + "role": entry.role, + "cluster_entry_type": entry.cluster_entry_type, + "cluster_name": entry.cluster.name, + "cluster_status": entry.cluster.status, + "instances": storage_list + proxy_list, + } + return entry_info diff --git a/dbm-ui/backend/db_services/dbbase/resources/serializers.py b/dbm-ui/backend/db_services/dbbase/resources/serializers.py index 9a7860af51..77d1d95e5a 100644 --- a/dbm-ui/backend/db_services/dbbase/resources/serializers.py +++ b/dbm-ui/backend/db_services/dbbase/resources/serializers.py @@ -11,7 +11,15 @@ from django.utils.translation import gettext_lazy as _ from rest_framework import serializers -from backend.db_meta.enums import ClusterStatus, ClusterType, InstanceStatus, MachineType, TenDBClusterSpiderRole +from backend.db_meta.enums import ( + ClusterEntryRole, + ClusterEntryType, + ClusterStatus, + ClusterType, + InstanceStatus, + MachineType, + TenDBClusterSpiderRole, +) from backend.db_meta.models.cluster import Cluster from backend.db_services.dbbase.constants import IP_PORT_DIVIDER from backend.flow.consts import SqlserverSyncMode @@ -155,3 +163,11 @@ class ListTendbClusterMachineResourceSLZ(ListMachineSLZ): spider_role = serializers.ChoiceField( help_text=_("spider角色"), choices=TenDBClusterSpiderRole.get_choices(), required=False ) + + +class ListClusterEntriesSLZ(serializers.Serializer): + instance = serializers.CharField(required=False) + domain = serializers.CharField(required=False) + role = serializers.ChoiceField(required=False, choices=ClusterEntryRole.get_choices()) + cluster_entry_type = serializers.ChoiceField(required=False, choices=ClusterEntryType.get_choices()) + cluster_name = serializers.CharField(required=False) diff --git a/dbm-ui/backend/db_services/dbbase/resources/viewsets.py b/dbm-ui/backend/db_services/dbbase/resources/viewsets.py index c695077b0f..2cec3208b1 100644 --- a/dbm-ui/backend/db_services/dbbase/resources/viewsets.py +++ b/dbm-ui/backend/db_services/dbbase/resources/viewsets.py @@ -40,6 +40,8 @@ class ResourceViewSet(SystemViewSet): retrieve_instances_slz = serializers.RetrieveInstancesSerializer # 机器列表serializer list_machine_slz = serializers.ListMachineSLZ + # 域名列表serializer + list_entry_slz = serializers.ListClusterEntriesSLZ # 分页 pagination_class = ResourceLimitOffsetPagination @@ -103,6 +105,13 @@ def retrieve_instance(self, request, bk_biz_id: int): self.query_class.retrieve_instance(bk_biz_id, query_params.get("cluster_id"), query_params["instance"]) ) + @action(methods=["GET"], detail=False, url_path="list_cluster_entries") + def list_cluster_entries(self, request, bk_biz_id: int): + """查询机器列表""" + query_params = self.params_validate(self.list_entry_slz) + data = self.paginator.paginate_list(request, bk_biz_id, self.query_class.list_cluster_entries, query_params) + return self.get_paginated_response(data) + @action(methods=["GET"], detail=False, url_path="list_machines") def list_machines(self, request, bk_biz_id: int): """查询机器列表""" diff --git a/dbm-ui/backend/db_services/dbbase/resources/yasg_slz.py b/dbm-ui/backend/db_services/dbbase/resources/yasg_slz.py index 277f45de97..f0996add01 100644 --- a/dbm-ui/backend/db_services/dbbase/resources/yasg_slz.py +++ b/dbm-ui/backend/db_services/dbbase/resources/yasg_slz.py @@ -76,3 +76,15 @@ class Meta: } ] } + + +class PaginatedMachineResourceSLZ(serializers.Serializer): + class Meta: + swagger_schema_fields = {"example": paginated_machine_resource_example} + ref_name = "PaginatedMachineResourceSLZ" + + +class PaginatedEntryResourceSLZ(serializers.Serializer): + class Meta: + swagger_schema_fields = {"example": paginated_machine_resource_example} + ref_name = "PaginatedEntryResourceSLZ" diff --git a/dbm-ui/backend/db_services/mongodb/resources/views.py b/dbm-ui/backend/db_services/mongodb/resources/views.py index e77d40bd30..31cc38c4d7 100644 --- a/dbm-ui/backend/db_services/mongodb/resources/views.py +++ b/dbm-ui/backend/db_services/mongodb/resources/views.py @@ -24,7 +24,11 @@ from backend.db_services.dbbase.resources.constants import ResourceNodeType from backend.db_services.dbbase.resources.serializers import SearchResourceTreeSLZ from backend.db_services.dbbase.resources.viewsets import ResourceViewSet -from backend.db_services.dbbase.resources.yasg_slz import ResourceTreeSLZ +from backend.db_services.dbbase.resources.yasg_slz import ( + PaginatedEntryResourceSLZ, + PaginatedMachineResourceSLZ, + ResourceTreeSLZ, +) from backend.db_services.mongodb.resources import constants, yasg_slz from backend.db_services.mongodb.resources.query import MongoDBListRetrieveResource from backend.iam_app.dataclass.actions import ActionEnum @@ -72,7 +76,15 @@ name="list_machines", decorator=common_swagger_auto_schema( query_serializer=serializers.ListMachineSLZ(), - responses={status.HTTP_200_OK: yasg_slz.PaginatedMachineResourceSLZ()}, + responses={status.HTTP_200_OK: PaginatedMachineResourceSLZ()}, + tags=[constants.RESOURCE_TAG], + ), +) +@method_decorator( + name="list_cluster_entries", + decorator=common_swagger_auto_schema( + query_serializer=serializers.ListClusterEntriesSLZ(), + responses={status.HTTP_200_OK: PaginatedEntryResourceSLZ()}, tags=[constants.RESOURCE_TAG], ), ) diff --git a/dbm-ui/backend/db_services/mongodb/resources/yasg_slz.py b/dbm-ui/backend/db_services/mongodb/resources/yasg_slz.py index 6b8f499bcb..5e993e32de 100644 --- a/dbm-ui/backend/db_services/mongodb/resources/yasg_slz.py +++ b/dbm-ui/backend/db_services/mongodb/resources/yasg_slz.py @@ -10,8 +10,6 @@ """ from rest_framework import serializers -from backend.db_services.dbbase.resources.yasg_slz import paginated_machine_resource_example - REF_NAME = "mongodb" paginated_resource_example = { @@ -142,12 +140,6 @@ class Meta: ref_name = f"{REF_NAME}_ResourceInstanceSLZ" -class PaginatedMachineResourceSLZ(serializers.Serializer): - class Meta: - swagger_schema_fields = {"example": paginated_machine_resource_example} - ref_name = f"{REF_NAME}_PaginatedMachineResourceSLZ" - - class ResourceTopoGraphSLZ(serializers.Serializer): class Meta: swagger_schema_fields = {"example": resource_topo_graph_example} diff --git a/dbm-ui/backend/db_services/mysql/resources/tendbcluster/views.py b/dbm-ui/backend/db_services/mysql/resources/tendbcluster/views.py index 42cfb74edd..e514b97c80 100644 --- a/dbm-ui/backend/db_services/mysql/resources/tendbcluster/views.py +++ b/dbm-ui/backend/db_services/mysql/resources/tendbcluster/views.py @@ -16,6 +16,7 @@ from backend.bk_web.swagger import common_swagger_auto_schema from backend.configuration.constants import DBType from backend.db_services.dbbase.resources import serializers, viewsets +from backend.db_services.dbbase.resources.yasg_slz import PaginatedEntryResourceSLZ, PaginatedMachineResourceSLZ from backend.db_services.mysql.resources import constants from backend.db_services.mysql.resources.tendbcluster import yasg_slz from backend.db_services.mysql.resources.tendbcluster.query import ListRetrieveResource @@ -58,7 +59,15 @@ name="list_machines", decorator=common_swagger_auto_schema( query_serializer=serializers.ListTendbClusterMachineResourceSLZ(), - responses={status.HTTP_200_OK: yasg_slz.PaginatedMachineResourceSLZ()}, + responses={status.HTTP_200_OK: PaginatedMachineResourceSLZ()}, + tags=[constants.RESOURCE_TAG], + ), +) +@method_decorator( + name="list_cluster_entries", + decorator=common_swagger_auto_schema( + query_serializer=serializers.ListClusterEntriesSLZ(), + responses={status.HTTP_200_OK: PaginatedEntryResourceSLZ()}, tags=[constants.RESOURCE_TAG], ), ) diff --git a/dbm-ui/backend/db_services/mysql/resources/tendbcluster/yasg_slz.py b/dbm-ui/backend/db_services/mysql/resources/tendbcluster/yasg_slz.py index f359daf13a..d444ec3254 100644 --- a/dbm-ui/backend/db_services/mysql/resources/tendbcluster/yasg_slz.py +++ b/dbm-ui/backend/db_services/mysql/resources/tendbcluster/yasg_slz.py @@ -10,8 +10,6 @@ """ from rest_framework import serializers -from backend.db_services.dbbase.resources.yasg_slz import paginated_machine_resource_example - from .query import ListRetrieveResource REF_NAME = "dbha" @@ -279,12 +277,6 @@ class Meta: ref_name = f"{REF_NAME}_ResourceInstanceSLZ" -class PaginatedMachineResourceSLZ(serializers.Serializer): - class Meta: - swagger_schema_fields = {"example": paginated_machine_resource_example} - ref_name = f"{REF_NAME}_PaginatedMachineResourceSLZ" - - class ResourceTopoGraphSLZ(serializers.Serializer): class Meta: swagger_schema_fields = {"example": resource_topo_graph_example} diff --git a/dbm-ui/backend/db_services/mysql/resources/tendbha/views.py b/dbm-ui/backend/db_services/mysql/resources/tendbha/views.py index f8e57bfa3c..97a4b0b7d3 100644 --- a/dbm-ui/backend/db_services/mysql/resources/tendbha/views.py +++ b/dbm-ui/backend/db_services/mysql/resources/tendbha/views.py @@ -14,6 +14,7 @@ from backend.bk_web.swagger import common_swagger_auto_schema from backend.configuration.constants import DBType from backend.db_services.dbbase.resources import serializers, viewsets +from backend.db_services.dbbase.resources.yasg_slz import PaginatedEntryResourceSLZ, PaginatedMachineResourceSLZ from backend.db_services.mysql.resources import constants from backend.db_services.mysql.resources.tendbha import yasg_slz from backend.db_services.mysql.resources.tendbha.query import ListRetrieveResource @@ -55,7 +56,15 @@ name="list_machines", decorator=common_swagger_auto_schema( query_serializer=serializers.ListMachineSLZ(), - responses={status.HTTP_200_OK: yasg_slz.PaginatedMachineResourceSLZ()}, + responses={status.HTTP_200_OK: PaginatedMachineResourceSLZ()}, + tags=[constants.RESOURCE_TAG], + ), +) +@method_decorator( + name="list_cluster_entries", + decorator=common_swagger_auto_schema( + query_serializer=serializers.ListClusterEntriesSLZ(), + responses={status.HTTP_200_OK: PaginatedEntryResourceSLZ()}, tags=[constants.RESOURCE_TAG], ), ) diff --git a/dbm-ui/backend/db_services/mysql/resources/tendbha/yasg_slz.py b/dbm-ui/backend/db_services/mysql/resources/tendbha/yasg_slz.py index 4e0b255583..be5d200bf4 100644 --- a/dbm-ui/backend/db_services/mysql/resources/tendbha/yasg_slz.py +++ b/dbm-ui/backend/db_services/mysql/resources/tendbha/yasg_slz.py @@ -10,8 +10,6 @@ """ from rest_framework import serializers -from backend.db_services.dbbase.resources.yasg_slz import paginated_machine_resource_example - from .query import ListRetrieveResource REF_NAME = "dbha" @@ -107,9 +105,3 @@ class ResourceTopoGraphSLZ(serializers.Serializer): class Meta: swagger_schema_fields = {"example": resource_topo_graph_example} ref_name = f"{REF_NAME}_ResourceTopoGraphSLZ" - - -class PaginatedMachineResourceSLZ(serializers.Serializer): - class Meta: - swagger_schema_fields = {"example": paginated_machine_resource_example} - ref_name = f"{REF_NAME}_PaginatedMachineResourceSLZ" diff --git a/dbm-ui/backend/db_services/mysql/resources/tendbsingle/views.py b/dbm-ui/backend/db_services/mysql/resources/tendbsingle/views.py index 2df4bbb6c0..0dc1461f7e 100644 --- a/dbm-ui/backend/db_services/mysql/resources/tendbsingle/views.py +++ b/dbm-ui/backend/db_services/mysql/resources/tendbsingle/views.py @@ -14,6 +14,7 @@ from backend.bk_web.swagger import common_swagger_auto_schema from backend.configuration.constants import DBType from backend.db_services.dbbase.resources import serializers, viewsets +from backend.db_services.dbbase.resources.yasg_slz import PaginatedEntryResourceSLZ, PaginatedMachineResourceSLZ from backend.db_services.mysql.resources import constants from backend.iam_app.dataclass import ResourceEnum from backend.iam_app.dataclass.actions import ActionEnum @@ -56,7 +57,15 @@ name="list_machines", decorator=common_swagger_auto_schema( query_serializer=serializers.ListMachineSLZ(), - responses={status.HTTP_200_OK: yasg_slz.PaginatedMachineResourceSLZ()}, + responses={status.HTTP_200_OK: PaginatedMachineResourceSLZ()}, + tags=[constants.RESOURCE_TAG], + ), +) +@method_decorator( + name="list_cluster_entries", + decorator=common_swagger_auto_schema( + query_serializer=serializers.ListClusterEntriesSLZ(), + responses={status.HTTP_200_OK: PaginatedEntryResourceSLZ()}, tags=[constants.RESOURCE_TAG], ), ) diff --git a/dbm-ui/backend/db_services/mysql/resources/tendbsingle/yasg_slz.py b/dbm-ui/backend/db_services/mysql/resources/tendbsingle/yasg_slz.py index 9e94fcd4c7..0de97149bd 100644 --- a/dbm-ui/backend/db_services/mysql/resources/tendbsingle/yasg_slz.py +++ b/dbm-ui/backend/db_services/mysql/resources/tendbsingle/yasg_slz.py @@ -10,8 +10,6 @@ """ from rest_framework import serializers -from backend.db_services.dbbase.resources.yasg_slz import paginated_machine_resource_example - from .query import ListRetrieveResource REF_NAME = "dbsingle" @@ -75,9 +73,3 @@ class ResourceTopoGraphSLZ(serializers.Serializer): class Meta: swagger_schema_fields = {"example": resource_topo_graph_example} ref_name = f"{REF_NAME}_ResourceTopoGraphSLZ" - - -class PaginatedMachineResourceSLZ(serializers.Serializer): - class Meta: - swagger_schema_fields = {"example": paginated_machine_resource_example} - ref_name = f"{REF_NAME}_PaginatedMachineResourceSLZ" diff --git a/dbm-ui/backend/db_services/redis/resources/redis_cluster/views.py b/dbm-ui/backend/db_services/redis/resources/redis_cluster/views.py index 690ac0b4bd..925c121f5e 100644 --- a/dbm-ui/backend/db_services/redis/resources/redis_cluster/views.py +++ b/dbm-ui/backend/db_services/redis/resources/redis_cluster/views.py @@ -19,6 +19,7 @@ from backend.configuration.constants import DBType from backend.db_meta.models import Cluster from backend.db_services.dbbase.resources import serializers, viewsets +from backend.db_services.dbbase.resources.yasg_slz import PaginatedEntryResourceSLZ, PaginatedMachineResourceSLZ from backend.db_services.redis.resources import constants from backend.flow.utils.base.payload_handler import PayloadHandler from backend.iam_app.dataclass import ResourceEnum @@ -79,7 +80,15 @@ name="list_machines", decorator=common_swagger_auto_schema( query_serializer=serializers.ListRedisMachineResourceSLZ(), - responses={status.HTTP_200_OK: yasg_slz.PaginatedMachineResourceSLZ()}, + responses={status.HTTP_200_OK: PaginatedMachineResourceSLZ()}, + tags=[constants.RESOURCE_TAG], + ), +) +@method_decorator( + name="list_cluster_entries", + decorator=common_swagger_auto_schema( + query_serializer=serializers.ListClusterEntriesSLZ(), + responses={status.HTTP_200_OK: PaginatedEntryResourceSLZ()}, tags=[constants.RESOURCE_TAG], ), ) diff --git a/dbm-ui/backend/db_services/redis/resources/redis_cluster/yasg_slz.py b/dbm-ui/backend/db_services/redis/resources/redis_cluster/yasg_slz.py index b000e855fc..5983204fe1 100644 --- a/dbm-ui/backend/db_services/redis/resources/redis_cluster/yasg_slz.py +++ b/dbm-ui/backend/db_services/redis/resources/redis_cluster/yasg_slz.py @@ -10,8 +10,6 @@ """ from rest_framework import serializers -from backend.db_services.dbbase.resources.yasg_slz import paginated_machine_resource_example - from .query import RedisListRetrieveResource REF_NAME = "tendiscache" @@ -115,9 +113,3 @@ class Meta: "example": {"cluster_name": "hs1", "domain": "cache.tendis.dd.abc.db", "password": "123456"} } ref_name = f"{REF_NAME}_PasswordResourceSLZ" - - -class PaginatedMachineResourceSLZ(serializers.Serializer): - class Meta: - swagger_schema_fields = {"example": paginated_machine_resource_example} - ref_name = f"{REF_NAME}_PaginatedMachineResourceSLZ" diff --git a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py index 5ebd9c59e0..9e372d3ee7 100644 --- a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py +++ b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py @@ -13,6 +13,7 @@ from backend.bk_web.swagger import common_swagger_auto_schema from backend.db_services.dbbase.resources import serializers +from backend.db_services.dbbase.resources.yasg_slz import PaginatedEntryResourceSLZ, PaginatedMachineResourceSLZ from backend.db_services.sqlserver.resources import constants from backend.db_services.sqlserver.resources.sqlserver_ha import yasg_slz from backend.db_services.sqlserver.resources.sqlserver_ha.query import ListRetrieveResource @@ -53,7 +54,15 @@ name="list_machines", decorator=common_swagger_auto_schema( query_serializer=serializers.ListMachineSLZ(), - responses={status.HTTP_200_OK: yasg_slz.PaginatedMachineResourceSLZ()}, + responses={status.HTTP_200_OK: PaginatedMachineResourceSLZ()}, + tags=[constants.RESOURCE_TAG], + ), +) +@method_decorator( + name="list_cluster_entries", + decorator=common_swagger_auto_schema( + query_serializer=serializers.ListClusterEntriesSLZ(), + responses={status.HTTP_200_OK: PaginatedEntryResourceSLZ()}, tags=[constants.RESOURCE_TAG], ), ) diff --git a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/yasg_slz.py b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/yasg_slz.py index 155f7cd82c..eccf55a085 100644 --- a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/yasg_slz.py +++ b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/yasg_slz.py @@ -10,8 +10,6 @@ """ from rest_framework import serializers -from backend.db_services.dbbase.resources.yasg_slz import paginated_machine_resource_example - from .query import ListRetrieveResource REF_NAME = "dbha" @@ -56,9 +54,3 @@ class ResourceTopoGraphSLZ(serializers.Serializer): class Meta: swagger_schema_fields = {"example": resource_topo_graph_example} ref_name = f"{REF_NAME}_ResourceTopoGraphSLZ" - - -class PaginatedMachineResourceSLZ(serializers.Serializer): - class Meta: - swagger_schema_fields = {"example": paginated_machine_resource_example} - ref_name = f"{REF_NAME}_PaginatedMachineResourceSLZ" diff --git a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py index 20642fbeb5..28d62a8757 100644 --- a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py +++ b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py @@ -13,6 +13,7 @@ from backend.bk_web.swagger import common_swagger_auto_schema from backend.db_services.dbbase.resources import serializers +from backend.db_services.dbbase.resources.yasg_slz import PaginatedEntryResourceSLZ, PaginatedMachineResourceSLZ from backend.db_services.sqlserver.resources import constants from backend.db_services.sqlserver.resources.sqlserver_single import yasg_slz from backend.db_services.sqlserver.resources.sqlserver_single.query import ListRetrieveResource @@ -53,7 +54,15 @@ name="list_machines", decorator=common_swagger_auto_schema( query_serializer=serializers.ListMachineSLZ(), - responses={status.HTTP_200_OK: yasg_slz.PaginatedMachineResourceSLZ()}, + responses={status.HTTP_200_OK: PaginatedMachineResourceSLZ()}, + tags=[constants.RESOURCE_TAG], + ), +) +@method_decorator( + name="list_cluster_entries", + decorator=common_swagger_auto_schema( + query_serializer=serializers.ListClusterEntriesSLZ(), + responses={status.HTTP_200_OK: PaginatedEntryResourceSLZ()}, tags=[constants.RESOURCE_TAG], ), ) diff --git a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/yasg_slz.py b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/yasg_slz.py index 5ad038b5a2..aa00feac7c 100644 --- a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/yasg_slz.py +++ b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/yasg_slz.py @@ -10,8 +10,6 @@ """ from rest_framework import serializers -from backend.db_services.dbbase.resources.yasg_slz import paginated_machine_resource_example - from .query import ListRetrieveResource REF_NAME = "dbha" @@ -55,9 +53,3 @@ class ResourceTopoGraphSLZ(serializers.Serializer): class Meta: swagger_schema_fields = {"example": resource_topo_graph_example} ref_name = f"{REF_NAME}_ResourceTopoGraphSLZ" - - -class PaginatedMachineResourceSLZ(serializers.Serializer): - class Meta: - swagger_schema_fields = {"example": paginated_machine_resource_example} - ref_name = f"{REF_NAME}_PaginatedMachineResourceSLZ" diff --git a/dbm-ui/backend/flow/consts.py b/dbm-ui/backend/flow/consts.py index 6792f47f8f..362a9e2d89 100644 --- a/dbm-ui/backend/flow/consts.py +++ b/dbm-ui/backend/flow/consts.py @@ -294,7 +294,6 @@ class MediumEnum(str, StructuredEnum): MongoDB = EnumField("mongodb", _("mongodb")) MongoToolKit = EnumField("mongo-toolkit", _("Mongo 工具集")) MongoMonitor = EnumField("mongo-monitor", _("Mongo 监控")) - DBTools = EnumField("dbtools", _("工具包")) Doris = EnumField("doris", _("doris")) Vm = EnumField("vm", _("vm"))