From 4f06d3f142656d48eb35490fd449f253803df5f8 Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Thu, 25 Jul 2024 10:39:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E4=BF=AE=E5=A4=8Dsend=20msg?= =?UTF-8?q?=E8=B6=85=E9=A2=91=E7=9A=84=E9=97=AE=E9=A2=98=20#5840?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/components/cmsi/client.py | 2 ++ dbm-ui/backend/db_services/dbbase/resources/query.py | 4 ++++ dbm-ui/backend/db_services/dbbase/resources/serializers.py | 5 ++++- .../db_services/mysql/permission/authorize/handlers.py | 3 +++ .../db_services/mysql/resources/tendbcluster/query.py | 7 +++---- dbm-ui/backend/flow/consts.py | 6 ++++-- .../flow/engine/bamboo/scene/spider/import_sqlfile_flow.py | 2 +- dbm-ui/backend/ticket/models/ticket.py | 4 ++++ 8 files changed, 25 insertions(+), 8 deletions(-) diff --git a/dbm-ui/backend/components/cmsi/client.py b/dbm-ui/backend/components/cmsi/client.py index 60fde99066..a81e5077c6 100644 --- a/dbm-ui/backend/components/cmsi/client.py +++ b/dbm-ui/backend/components/cmsi/client.py @@ -28,6 +28,8 @@ class MsgType(str, StructuredEnum): VOICE = EnumField("voice", _("语音")) RTX = EnumField("rtx", _("企业微信")) WECOM_ROBOT = EnumField("wecom_robot", _("企业微信机器人")) + # 未知发送类型,配置此type一般用于跳过消息发送 + UNKNOWN = EnumField("unknown", _("未知")) def __init__(self): self.send_msg = self.generate_data_api( diff --git a/dbm-ui/backend/db_services/dbbase/resources/query.py b/dbm-ui/backend/db_services/dbbase/resources/query.py index 2500b6bfb6..d930d7a10c 100644 --- a/dbm-ui/backend/db_services/dbbase/resources/query.py +++ b/dbm-ui/backend/db_services/dbbase/resources/query.py @@ -766,6 +766,10 @@ def _list_machines( Q(storageinstance__instance_role=query_params.get("instance_role")) | Q(proxyinstance__access_layer=query_params.get("instance_role")) ), + "instance_status": ( + Q(storageinstance__status=query_params.get("instance_status")) + | Q(proxyinstance__status=query_params.get("instance_status")) + ), "cluster_ids": ( Q(storageinstance__cluster__in=query_params.get("cluster_ids", "").split(",")) | Q(proxyinstance__cluster__in=query_params.get("cluster_ids", "").split(",")) diff --git a/dbm-ui/backend/db_services/dbbase/resources/serializers.py b/dbm-ui/backend/db_services/dbbase/resources/serializers.py index 077f865288..56d7167fc3 100644 --- a/dbm-ui/backend/db_services/dbbase/resources/serializers.py +++ b/dbm-ui/backend/db_services/dbbase/resources/serializers.py @@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _ from rest_framework import serializers -from backend.db_meta.enums import ClusterStatus, ClusterType, MachineType +from backend.db_meta.enums import ClusterStatus, ClusterType, InstanceStatus, MachineType from backend.db_meta.models.cluster import Cluster from backend.db_services.dbbase.constants import IP_PORT_DIVIDER @@ -132,6 +132,9 @@ class ListMachineSLZ(serializers.Serializer): bk_cloud_id = serializers.IntegerField(help_text=_("云区域ID"), required=False) bk_agent_id = serializers.CharField(help_text=_("agent id"), required=False) instance_role = serializers.CharField(help_text=_("机器部署的实例角色"), required=False) + instance_status = serializers.ChoiceField( + help_text=_("集群状态"), choices=InstanceStatus.get_choices(), required=False + ) creator = serializers.CharField(help_text=_("创建者"), required=False) diff --git a/dbm-ui/backend/db_services/mysql/permission/authorize/handlers.py b/dbm-ui/backend/db_services/mysql/permission/authorize/handlers.py index 4b0b6040f9..fc6642dd96 100644 --- a/dbm-ui/backend/db_services/mysql/permission/authorize/handlers.py +++ b/dbm-ui/backend/db_services/mysql/permission/authorize/handlers.py @@ -16,6 +16,7 @@ from django.utils.translation import ugettext_lazy as _ from backend import env +from backend.components import CmsiApi from backend.components.gcs.client import GcsApi, GcsDirectApi from backend.components.mysql_priv_manager.client import DBPrivManagerApi from backend.components.scr.client import ScrApi @@ -199,6 +200,8 @@ def parse_domain(raw_domain): creator=operator or self.operator, remark=_("第三方请求授权"), details=authorize_info_slz.validated_data, + # 自动授权单,不发送通知 + send_msg_config={"msg_type": [CmsiApi.MsgType.UNKNOWN.value]}, ) task_id = str(ticket.id) return {"task_id": task_id, "platform": "dbm", "job_id": task_id} diff --git a/dbm-ui/backend/db_services/mysql/resources/tendbcluster/query.py b/dbm-ui/backend/db_services/mysql/resources/tendbcluster/query.py index 8a1426f8eb..92a5defe72 100644 --- a/dbm-ui/backend/db_services/mysql/resources/tendbcluster/query.py +++ b/dbm-ui/backend/db_services/mysql/resources/tendbcluster/query.py @@ -140,15 +140,14 @@ def get_remote_infos(insts: List[StorageInstance]): machine_pair_cnt = len(machine_list) / 2 # 获取集群规格 spec_id = cluster.storages[0].machine.spec_id - cluster_spec = kwargs["remote_spec_map"].get(spec_id) + spec = kwargs["remote_spec_map"].get(spec_id) cluster_extra_info = { - "cluster_spec": model_to_dict(cluster_spec), - "cluster_capacity": cluster_spec.capacity * machine_pair_cnt, + "cluster_spec": model_to_dict(spec) if spec else {}, + "cluster_capacity": spec.capacity * machine_pair_cnt if spec else 0, "spider_master": spider[TenDBClusterSpiderRole.SPIDER_MASTER], "spider_slave": spider[TenDBClusterSpiderRole.SPIDER_SLAVE], "spider_mnt": spider[TenDBClusterSpiderRole.SPIDER_MNT], - # TODO: 待补充当前集群使用容量,需要监控采集的支持 "cluster_shard_num": len(remote_db), "remote_shard_num": len(remote_db) / machine_pair_cnt, "machine_pair_cnt": machine_pair_cnt, diff --git a/dbm-ui/backend/flow/consts.py b/dbm-ui/backend/flow/consts.py index 34e95d92d7..e9783dac6c 100644 --- a/dbm-ui/backend/flow/consts.py +++ b/dbm-ui/backend/flow/consts.py @@ -872,8 +872,10 @@ class MySQLBackupTypeEnum(str, StructuredEnum): class MySQLBackupFileTagEnum(str, StructuredEnum): - MYSQL_FULL_BACKUP = EnumField("MYSQL_FULL_BACKUP", _("全备-保留25天")) - LONGDAY_DBFILE_3Y = EnumField("LONGDAY_DBFILE_3Y", _("长久存储-保留三年")) + DBFILE1M = EnumField("DBFILE1M", _("备份1个月")) + DBFILE6M = EnumField("DBFILE6M", _("备份6个月")) + DBFILE1Y = EnumField("DBFILE1Y", _("备份1年")) + DBFILE3Y = EnumField("DBFILE3Y", _("备份3年")) class MongoDBBackupFileTagEnum(str, StructuredEnum): diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/spider/import_sqlfile_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/spider/import_sqlfile_flow.py index fd46b74b3c..dd7f7e4a1f 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/spider/import_sqlfile_flow.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/spider/import_sqlfile_flow.py @@ -273,4 +273,4 @@ def __get_sql_file_name_list(self) -> list: file_list = [] for obj in self.data["execute_objects"]: file_list.append(obj["sql_file"]) - return file_list + return list(set(file_list)) diff --git a/dbm-ui/backend/ticket/models/ticket.py b/dbm-ui/backend/ticket/models/ticket.py index 2fe8a2e9be..4685c25735 100644 --- a/dbm-ui/backend/ticket/models/ticket.py +++ b/dbm-ui/backend/ticket/models/ticket.py @@ -166,6 +166,7 @@ def create_ticket( remark: str, details: Dict[str, Any], auto_execute: bool = True, + send_msg_config: dict = None, ) -> "Ticket": """ 自动创建单据 @@ -175,11 +176,13 @@ def create_ticket( :param remark: 备注 :param details: 单据参数details :param auto_execute: 是否自动初始化执行单据 + :param send_msg_config: 消息发送类配置 """ from backend.ticket.builders import BuilderFactory with transaction.atomic(): + send_msg_config = send_msg_config or {} ticket = Ticket.objects.create( group=BuilderFactory.get_builder_cls(ticket_type).group, creator=creator, @@ -188,6 +191,7 @@ def create_ticket( ticket_type=ticket_type, remark=remark, details=details, + send_msg_config=send_msg_config, ) logger.info(_("正在自动创建单据,单据详情: {}").format(ticket.__dict__)) builder = BuilderFactory.create_builder(ticket)