Skip to content

Commit

Permalink
fix(backend): 校验flashback库表接口改造 #1011
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud authored and zhangzhw8 committed Sep 11, 2023
1 parent b70c0bf commit eb03ea6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
10 changes: 8 additions & 2 deletions dbm-ui/backend/db_services/mysql/remote_service/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def _get_db_table_list(_bk_cloud_id, _address, _cmds, key):
)
databases = set(query_dbs_list[query_schema_dbs_sql]) - set(query_dbs_list[query_ignore_schema_dbs_sql])
if not databases:
raise RemoteServiceBaseException(_("不存在可用于闪回的库"))
info.update(message=_("不存在可用于闪回的库"))
continue

# 构造查询表的sql语句
db_list = "(" + ",".join([f"'{db}'" for db in databases]) + ")"
Expand All @@ -170,4 +171,9 @@ def _get_db_table_list(_bk_cloud_id, _address, _cmds, key):
query_tbs_list[query_ignore_schema_tables_sql]
)
if not databases:
raise RemoteServiceBaseException(_("不存在可用于闪回的表"))
info.update(message=_("不存在可用于闪回的表"))
continue

info.update(message="")

return flashback_infos
20 changes: 20 additions & 0 deletions dbm-ui/backend/db_services/mysql/remote_service/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,23 @@
CHECK_CLUSTER_DATABASE_RESPONSE_DATA = [
{"cluster_id": 63, "db_names": ["db1", "db2"], "check_info": {"db1": False, "db2": True}}
]

FLASHBACK_CHECK_DATA = [
{
"cluster_id": 63,
"databases": ["kkjj"],
"databases_ignore": [],
"tables": [],
"tables_ignore": [],
"message": "不存在可用于闪回的库",
},
{
"cluster_id": 63,
"databases": [],
"databases_ignore": [],
"tables": ["iijkk"],
"tables_ignore": [],
"message": "不存在可用于闪回的表",
},
{"cluster_id": 63, "databases": [], "databases_ignore": [], "tables": [], "tables_ignore": [], "message": ""},
]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from backend.db_services.mysql.remote_service.mock_data import (
CHECK_CLUSTER_DATABASE_REQUEST_DATA,
CHECK_CLUSTER_DATABASE_RESPONSE_DATA,
FLASHBACK_CHECK_DATA,
SHOW_DATABASES_REQUEST_DATA,
SHOW_DATABASES_RESPONSE_DATA,
)
Expand Down Expand Up @@ -68,3 +69,8 @@ class FlashbackSerializer(serializers.Serializer):
tables_ignore = serializers.ListField(help_text=_("忽略table列表"), child=serializers.CharField())

infos = serializers.ListSerializer(help_text=_("flashback信息"), child=FlashbackSerializer(), allow_empty=False)


class CheckFlashbackInfoResponseSerializer(serializers.Serializer):
class Meta:
swagger_schema_fields = {"example": FLASHBACK_CHECK_DATA}
2 changes: 2 additions & 0 deletions dbm-ui/backend/db_services/mysql/remote_service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from backend.db_services.mysql.remote_service.serializers import (
CheckClusterDatabaseResponseSerializer,
CheckClusterDatabaseSerializer,
CheckFlashbackInfoResponseSerializer,
CheckFlashbackInfoSerializer,
ShowDatabasesRequestSerializer,
ShowDatabasesResponseSerializer,
Expand Down Expand Up @@ -74,6 +75,7 @@ def check_cluster_database(self, request, bk_biz_id):
@common_swagger_auto_schema(
operation_summary=_("校验flashback信息是否合法"),
request_body=CheckFlashbackInfoSerializer(),
responses={status.HTTP_200_OK: CheckFlashbackInfoResponseSerializer()},
tags=[SWAGGER_TAG],
)
@action(methods=["POST"], detail=False, serializer_class=CheckFlashbackInfoSerializer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def validate(self, attrs):

for cluster in attrs["infos"]["clusters"]:
if cluster["backup_local"] == TenDBBackUpLocation.SPIDER_MNT and "spider_mnt_address" not in cluster:
raise serializers.ValidationError(_("备份位置选择spider_mnt时,请提供临时节点的地址"))
raise serializers.ValidationError(_("备份位置选择spider_mnt时,请提供运维节点的地址"))

return attrs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class TendbMNTApplyDetailSerializer(TendbBaseOperateDetailSerializer):
class MNTApplySerializer(serializers.Serializer):
cluster_id = serializers.IntegerField(help_text=_("集群ID"))
bk_cloud_id = serializers.IntegerField(help_text=_("云区域ID"))
spider_ip_list = serializers.ListField(help_text=_("临时节点信息"), child=serializers.DictField())
spider_ip_list = serializers.ListField(help_text=_("运维节点信息"), child=serializers.DictField())

infos = serializers.ListField(help_text=_("添加spider临时节点信息"), child=MNTApplySerializer())
infos = serializers.ListField(help_text=_("添加spider运维节点信息"), child=MNTApplySerializer())

def validate(self, attrs):
super().validate(attrs)
Expand All @@ -49,4 +49,4 @@ def format_ticket_data(self):
class TendbMNTApplyFlowBuilder(BaseTendbTicketFlowBuilder):
serializer = TendbMNTApplyDetailSerializer
inner_flow_builder = TendbMNTApplyParamBuilder
inner_flow_name = _("TendbCluster 添加临时节点")
inner_flow_name = _("TendbCluster 添加运维节点")
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
class TendbMNTDestroyDetailSerializer(TendbBaseOperateDetailSerializer):
class MNTDestroySerializer(serializers.Serializer):
cluster_id = serializers.IntegerField(help_text=_("集群ID"))
spider_ip_list = serializers.ListField(help_text=_("临时节点信息"), child=serializers.DictField())
spider_ip_list = serializers.ListField(help_text=_("运维节点信息"), child=serializers.DictField())

infos = serializers.ListField(help_text=_("下架spider临时节点信息"), child=MNTDestroySerializer())
infos = serializers.ListField(help_text=_("下架spider运维节点信息"), child=MNTDestroySerializer())
is_safe = serializers.BooleanField(help_text=_("是否安全模式执行"), required=False, default=True)

def validate(self, attrs):
Expand All @@ -40,4 +40,4 @@ class TendbMNTDestroyParamBuilder(builders.FlowParamBuilder):
class TendbMNTDestroyFlowBuilder(BaseTendbTicketFlowBuilder):
serializer = TendbMNTDestroyDetailSerializer
inner_flow_builder = TendbMNTDestroyParamBuilder
inner_flow_name = _("TendbCluster 下架临时节点")
inner_flow_name = _("TendbCluster 下架运维节点")

0 comments on commit eb03ea6

Please sign in to comment.