Skip to content

Commit

Permalink
feat(backend): sqlserver 查询db模块为alwayson的集群列表 TencentBlueKing#5863
Browse files Browse the repository at this point in the history
  • Loading branch information
ygcyao committed Jul 30, 2024
1 parent 290780a commit 797c3da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_services/dbbase/resources/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ListRedisResourceSLZ(ListResourceSLZ):


class ListSQLServerResourceSLZ(ListResourceSLZ):
db_module_id = serializers.IntegerField(required=False)
pass


class ListMongoDBResourceSLZ(ListResourceSLZ):
Expand Down
20 changes: 20 additions & 0 deletions dbm-ui/backend/db_services/dbbase/resources/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from rest_framework.response import Response

from backend.bk_web.viewsets import SystemViewSet
from backend.db_meta.models.storage_set_dtl import SqlserverClusterSyncMode
from backend.iam_app.handlers.drf_perm.base import DBManagePermission
from backend.iam_app.handlers.drf_perm.cluster import ClusterDetailPermission
from backend.iam_app.handlers.permission import Permission
Expand Down Expand Up @@ -110,6 +111,25 @@ def list_machines(self, request, bk_biz_id: int):
data = self.paginator.paginate_list(request, bk_biz_id, self.query_class.list_machines, query_params)
return self.get_paginated_response(data)

@action(methods=["GET"], detail=False, url_path="list_alwayson")
@Permission.decorator_permission_field(
id_field=lambda d: d["id"],
data_field=lambda d: d["results"],
action_filed=lambda d: d["view_class"].list_perm_actions,
)
def list_alwayson(self, request, bk_biz_id: int):
"""查询alwayson模块集群列表"""
query_params = self.params_validate(self.query_serializer_class)
alwayson_ids = SqlserverClusterSyncMode.objects.filter(sync_mode="always_on").values_list(
"cluster_id", flat=True
)
# 如果不存在alwayson_ids 直接返回空列表
if not alwayson_ids.exists():
return Response([])
query_params["cluster_ids"] = list(alwayson_ids)
data = self.paginator.paginate_list(request, bk_biz_id, self.query_class.list_clusters, query_params)
return self.get_paginated_response(data)

@action(methods=["GET"], detail=False, url_path="get_table_fields")
def get_table_fields(self, request, bk_biz_id):
"""获取 table 信息"""
Expand Down

0 comments on commit 797c3da

Please sign in to comment.