diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 192599b36c..0887b94854 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,16 +16,9 @@ repos: - id: black args: [--config=./dbm-ui/pyproject.toml] language_version: "3.6" - exclude: > - (?x)^( - backend/packages/.* - )$ + - repo: https://github.com/PyCQA/flake8 - rev: 3.8.0 + rev: 5.0.4 hooks: - id: flake8 args: [--config=./dbm-ui/backend/.flake8] - exclude: > - (?x)^( - backend/packages/.* - )$ diff --git a/dbm-ui/backend/.flake8 b/dbm-ui/backend/.flake8 index 6db437076f..bac9429a33 100644 --- a/dbm-ui/backend/.flake8 +++ b/dbm-ui/backend/.flake8 @@ -1,5 +1,9 @@ [flake8] -ignore = W503,E203,W605,C901,F403,F405,F401 +# W504 and W503 conflict with each other in flake8 +# E203 is conflict with black +# see https://github.com/psf/black/blob/main/docs/guides/using_black_with_other_tools.md#flake8 +ignore = W503,E203 +# 排除检查的文件 exclude = *migrations*, *.pyc, @@ -10,10 +14,14 @@ exclude = */bin/*, */settings/*, scripts/*, - backend/packages/*, + +# 指定文件忽略规则 +per-file-ignores = + */__init__.py: F401,F403,F405 + nginx_template.py: W605 max-line-length=129 -max-complexity=12 +max-complexity=21 format=pylint show_source = True statistics = True -count = True \ No newline at end of file +count = True diff --git a/dbm-ui/backend/db_meta/api/cluster/riak/scale_in.py b/dbm-ui/backend/db_meta/api/cluster/riak/scale_in.py index 3566dfe826..3df3aa0d7f 100644 --- a/dbm-ui/backend/db_meta/api/cluster/riak/scale_in.py +++ b/dbm-ui/backend/db_meta/api/cluster/riak/scale_in.py @@ -13,8 +13,6 @@ from django.db import transaction -from backend import env -from backend.components import CCApi from backend.db_meta import request_validator from backend.db_meta.api import common from backend.db_meta.models import Cluster, ClusterEntry, StorageInstance diff --git a/dbm-ui/backend/db_meta/api/cluster/tendbcluster/handler.py b/dbm-ui/backend/db_meta/api/cluster/tendbcluster/handler.py index 7b613d71ab..e68037cc38 100644 --- a/dbm-ui/backend/db_meta/api/cluster/tendbcluster/handler.py +++ b/dbm-ui/backend/db_meta/api/cluster/tendbcluster/handler.py @@ -7,7 +7,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -import json from typing import List, Optional from django.db import transaction diff --git a/dbm-ui/backend/db_meta/api/cluster/tendbha/switch_proxy.py b/dbm-ui/backend/db_meta/api/cluster/tendbha/switch_proxy.py index cba2d8e81c..cb0c191a03 100644 --- a/dbm-ui/backend/db_meta/api/cluster/tendbha/switch_proxy.py +++ b/dbm-ui/backend/db_meta/api/cluster/tendbha/switch_proxy.py @@ -12,7 +12,7 @@ from django.db import transaction -from backend.db_meta.enums import ClusterEntryType, InstanceInnerRole, MachineType +from backend.db_meta.enums import ClusterEntryType, InstanceInnerRole from backend.db_meta.models import Cluster, ProxyInstance, StorageInstance from backend.flow.utils.cc_manage import CcManage from backend.flow.utils.mysql.mysql_module_operate import MysqlCCTopoOperator diff --git a/dbm-ui/backend/db_meta/api/dbha/apis.py b/dbm-ui/backend/db_meta/api/dbha/apis.py index ed9c5c535d..09a413e034 100644 --- a/dbm-ui/backend/db_meta/api/dbha/apis.py +++ b/dbm-ui/backend/db_meta/api/dbha/apis.py @@ -10,15 +10,16 @@ """ import logging from collections import defaultdict -from typing import Dict, List, Optional +from typing import Any, Dict, List, Optional +import validators from django.core.exceptions import ObjectDoesNotExist from django.db import transaction from django.db.models import Q from django.utils.translation import ugettext_lazy as _ from backend.constants import DEFAULT_BK_CLOUD_ID, IP_PORT_DIVIDER -from backend.db_meta import flatten, request_validator, validators +from backend.db_meta import flatten, meta_validator, request_validator from backend.db_meta.enums import ( ClusterEntryType, ClusterStatus, @@ -43,7 +44,7 @@ def cities(): return flatten.cities(BKCity.objects.all()) -def entry_detail(domains: List[str]) -> List[Dict]: +def entry_detail(domains: List[str]) -> Dict[str, Dict[Any, list]]: entries = {} for domain in domains: clusterentry_set = defaultdict(list) @@ -116,7 +117,7 @@ def instances( for ad in [ad for ad in addresses if len(ad.strip()) > 0]: if validators.ipv4(ad): queries |= Q(**{"machine__ip": ad}) - elif validators.instance(ad): + elif meta_validator.instance(ad): queries |= Q(**{"machine__ip": ad.split(IP_PORT_DIVIDER)[0], "port": ad.split(IP_PORT_DIVIDER)[1]}) elif validators.domain(ad): queries |= Q(**{"cluster__clusterentry__entry": ad}) diff --git a/dbm-ui/backend/db_meta/validators/impl.py b/dbm-ui/backend/db_meta/meta_validator.py similarity index 78% rename from dbm-ui/backend/db_meta/validators/impl.py rename to dbm-ui/backend/db_meta/meta_validator.py index b5d1fa7084..dc7a2fb751 100644 --- a/dbm-ui/backend/db_meta/validators/impl.py +++ b/dbm-ui/backend/db_meta/meta_validator.py @@ -8,18 +8,13 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -from validators import * # pylint: disable=wildcard-import +import validators -@validator +@validators.validator def instance(value): groups = value.split(":") if len(groups) != 2: return False - return (ipv4(groups[0]) or ipv6(groups[0])) and groups[1].isdigit() - - -@validator -def port(value): - return isinstance(value, int) and 0 < value < 65535 + return (validators.ipv4(groups[0]) or validators.ipv6(groups[0])) and groups[1].isdigit() diff --git a/dbm-ui/backend/db_meta/models/cluster_entry.py b/dbm-ui/backend/db_meta/models/cluster_entry.py index d45e1c19ae..5f5fdec2ca 100644 --- a/dbm-ui/backend/db_meta/models/cluster_entry.py +++ b/dbm-ui/backend/db_meta/models/cluster_entry.py @@ -17,7 +17,6 @@ from backend import env from backend.bk_web.models import AuditedModel -from backend.components import DnsApi from backend.db_meta.enums import ClusterEntryRole, ClusterEntryType from backend.db_meta.models import Cluster diff --git a/dbm-ui/backend/db_meta/models/extra_process.py b/dbm-ui/backend/db_meta/models/extra_process.py index 2ac4abe056..2c489adae8 100644 --- a/dbm-ui/backend/db_meta/models/extra_process.py +++ b/dbm-ui/backend/db_meta/models/extra_process.py @@ -11,7 +11,6 @@ import logging from django.db import models -from django.forms.models import model_to_dict from django.utils.translation import ugettext_lazy as _ from backend.bk_web.models import AuditedModel diff --git a/dbm-ui/backend/db_meta/models/instance.py b/dbm-ui/backend/db_meta/models/instance.py index f0652932a9..aff1175dfc 100644 --- a/dbm-ui/backend/db_meta/models/instance.py +++ b/dbm-ui/backend/db_meta/models/instance.py @@ -16,7 +16,6 @@ from django.db.models import Q, QuerySet from django.utils.translation import ugettext_lazy as _ -from backend import constants from backend.bk_web.models import AuditedModel from backend.db_meta.enums import ( AccessLayer, diff --git a/dbm-ui/backend/db_meta/models/machine.py b/dbm-ui/backend/db_meta/models/machine.py index e9f08dfa12..c85e7db69a 100644 --- a/dbm-ui/backend/db_meta/models/machine.py +++ b/dbm-ui/backend/db_meta/models/machine.py @@ -9,7 +9,6 @@ specific language governing permissions and limitations under the License. """ import copy - from dataclasses import asdict from django.db import models diff --git a/dbm-ui/backend/db_meta/request_validator/atom.py b/dbm-ui/backend/db_meta/request_validator/atom.py index e26130129d..f258457e26 100644 --- a/dbm-ui/backend/db_meta/request_validator/atom.py +++ b/dbm-ui/backend/db_meta/request_validator/atom.py @@ -11,10 +11,9 @@ import logging from typing import List +import validators from rest_framework import serializers -from backend.db_meta import validators - logger = logging.getLogger("root") @@ -31,33 +30,6 @@ def to_internal_value(self, data): return self.field.to_internal_value(data) -# def validated_integer(data, min_value=None, max_value=None, allow_null=False) -> int: -# field = serializers.IntegerField(min_value=min_value, max_value=max_value, allow_null=allow_null) -# slz = _AtomSerializer(data=data, field=field, allow_null=allow_null) -# slz.is_valid(raise_exception=True) -# return slz.validated_data - - -# def validated_str(data, min_length=None, max_length=None, allow_blank=False, trim_whitespace=True) -> str: -# field = serializers.CharField( -# min_length=min_length, max_length=max_length, allow_blank=allow_blank, trim_whitespace=trim_whitespace -# ) -# slz = _AtomSerializer(data=data, field=field) -# slz.is_valid(raise_exception=True) -# return slz.validated_data - - -# def validated_integer_list(data, min_value=None, max_value=None, allow_empty=True, allow_null=True) -> List[int]: -# slz = serializers.ListSerializer( -# child=serializers.IntegerField(min_value=min_value, max_value=max_value), -# data=data, -# allow_empty=allow_empty, -# allow_null=allow_null, -# ) -# slz.is_valid(raise_exception=True) -# return slz.validated_data - - def validated_str_list( data, min_length=None, max_length=None, allow_blank=False, trim_whitespace=True, allow_empty=True, allow_null=True ) -> List[str]: @@ -110,10 +82,3 @@ def validated_domain_list( ) slz.is_valid(raise_exception=True) return slz.validated_data - - -# def validated_ip(data) -> str: -# field = serializers.IPAddressField() -# slz = _AtomSerializer(data=data, field=field) -# slz.is_valid(raise_exception=True) -# return slz.validated_data diff --git a/dbm-ui/backend/db_meta/request_validator/common.py b/dbm-ui/backend/db_meta/request_validator/common.py index bdd206bdcc..f2dcc0d42d 100644 --- a/dbm-ui/backend/db_meta/request_validator/common.py +++ b/dbm-ui/backend/db_meta/request_validator/common.py @@ -10,10 +10,9 @@ """ import logging +import validators from rest_framework import serializers -from backend.db_meta import validators - from .serializers import CommonSerializer logger = logging.getLogger("root") diff --git a/dbm-ui/backend/db_meta/request_validator/dbha.py b/dbm-ui/backend/db_meta/request_validator/dbha.py index dc93e6845d..860500f0ad 100644 --- a/dbm-ui/backend/db_meta/request_validator/dbha.py +++ b/dbm-ui/backend/db_meta/request_validator/dbha.py @@ -8,15 +8,16 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ +import validators from rest_framework import serializers -from backend.db_meta import validators +from backend.db_meta import meta_validator class DBHAInstanceRequestSerializer(serializers.Serializer): class AddressField(serializers.CharField): def to_internal_value(self, data): - if not validators.ipv4(data) and not validators.instance(data): # and not validators.domain(data): + if not validators.ipv4(data) and not meta_validator.instance(data): raise serializers.ValidationError('"{}" is not a valid address'.format(data)) logical_city_ids = serializers.ListField( diff --git a/dbm-ui/backend/db_monitor/management/commands/export_template.py b/dbm-ui/backend/db_monitor/management/commands/export_template.py index 6d32818f36..8e64e95d53 100644 --- a/dbm-ui/backend/db_monitor/management/commands/export_template.py +++ b/dbm-ui/backend/db_monitor/management/commands/export_template.py @@ -8,7 +8,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -import base64 import json import logging import os diff --git a/dbm-ui/backend/db_monitor/models/alarm.py b/dbm-ui/backend/db_monitor/models/alarm.py index 302d84a083..df8131c263 100644 --- a/dbm-ui/backend/db_monitor/models/alarm.py +++ b/dbm-ui/backend/db_monitor/models/alarm.py @@ -23,7 +23,7 @@ from backend.components import BKMonitorV3Api from backend.configuration.constants import PLAT_BIZ_ID, DBType, SystemSettingsEnum from backend.configuration.models import SystemSettings -from backend.db_meta.models import AppMonitorTopo, DBModule +from backend.db_meta.models import DBModule from backend.db_monitor.constants import ( APP_PRIORITY, BK_MONITOR_SAVE_DISPATCH_GROUP_TEMPLATE, diff --git a/dbm-ui/backend/db_monitor/tasks.py b/dbm-ui/backend/db_monitor/tasks.py index 6409fc9fd1..cc20aa1ee3 100644 --- a/dbm-ui/backend/db_monitor/tasks.py +++ b/dbm-ui/backend/db_monitor/tasks.py @@ -13,8 +13,7 @@ from celery import shared_task -from .. import env -from ..configuration.constants import PLAT_BIZ_ID +from backend.configuration.constants import PLAT_BIZ_ID logger = logging.getLogger("celery") diff --git a/dbm-ui/backend/db_package/views.py b/dbm-ui/backend/db_package/views.py index 2383ec94d5..c2b24ae3fd 100644 --- a/dbm-ui/backend/db_package/views.py +++ b/dbm-ui/backend/db_package/views.py @@ -10,8 +10,6 @@ """ import os import re -from collections import defaultdict -from typing import Dict, List from django.core.files.uploadedfile import InMemoryUploadedFile from django.db.transaction import atomic diff --git a/dbm-ui/backend/db_periodic_task/local_tasks/dbmon_heartbeat/heartbeat_report.py b/dbm-ui/backend/db_periodic_task/local_tasks/dbmon_heartbeat/heartbeat_report.py index a093bc8f07..4f14fca19f 100644 --- a/dbm-ui/backend/db_periodic_task/local_tasks/dbmon_heartbeat/heartbeat_report.py +++ b/dbm-ui/backend/db_periodic_task/local_tasks/dbmon_heartbeat/heartbeat_report.py @@ -37,7 +37,6 @@ def check_dbmon_heart_beat(): def query_by_cluster_dimension(cluster_domain, cap_key="heartbeat", cluster_type="dbmon"): - logger.info("+===+++++=== cluster is: {} +++++===++++ ".format(cluster_domain)) query_template = QUERY_TEMPLATE.get(cluster_type) if not query_template: @@ -74,8 +73,29 @@ def query_by_cluster_dimension(cluster_domain, cap_key="heartbeat", cluster_type return dbmon_heartbeat_data -def _check_dbmon_heart_beat(): +def get_report_subtype_for_storage(cluster_type): + if cluster_type == ClusterType.TwemproxyTendisSSDInstance.value: + heart_beat_subtype = DbmonHeartbeatReportSubType.REDIS_SSD.value + elif cluster_type == ClusterType.TendisPredixyTendisplusCluster.value: + heart_beat_subtype = DbmonHeartbeatReportSubType.TENDISPLUS.value + elif cluster_type == ClusterType.TendisTwemproxyRedisInstance.value: + heart_beat_subtype = DbmonHeartbeatReportSubType.REDIS_CACHE.value + else: + raise NotImplementedError("Dbmon Not supported tendis type:{}".format(cluster_type)) + return heart_beat_subtype + + +def get_report_subtype_for_proxy(cluster_type): + if cluster_type in [ClusterType.TwemproxyTendisSSDInstance.value, ClusterType.TendisTwemproxyRedisInstance.value]: + heart_beat_subtype = DbmonHeartbeatReportSubType.TWEMPROXY.value + elif cluster_type == ClusterType.TendisPredixyTendisplusCluster.value: + heart_beat_subtype = DbmonHeartbeatReportSubType.PREDIXY.value + else: + raise NotImplementedError("Dbmon Not supported tendis type:{}".format(cluster_type)) + return heart_beat_subtype + +def _check_dbmon_heart_beat(): """ 获取dbmon心跳信息 """ @@ -122,14 +142,7 @@ def _check_dbmon_heart_beat(): for ip in missing_heartbeat_ips: # 如果是后端存储节点,再区分cache ,ssd ,tendisplus if ip in cluster_info["redis_master_ips_set"] or ip in cluster_info["redis_slave_ips_set"]: - if c.cluster_type == ClusterType.TwemproxyTendisSSDInstance.value: - cluster_type = DbmonHeartbeatReportSubType.REDIS_SSD.value - elif c.cluster_type == ClusterType.TendisPredixyTendisplusCluster.value: - cluster_type = DbmonHeartbeatReportSubType.TENDISPLUS.value - elif c.cluster_type == ClusterType.TendisTwemproxyRedisInstance.value: - cluster_type = DbmonHeartbeatReportSubType.REDIS_CACHE.value - else: - raise NotImplementedError("Dbmon Not supported tendis type:{}".format(c.cluster_type)) + heart_beat_subtype = get_report_subtype_for_storage(c.cluster_type) # 获取端口范围:30000-30010 port_ranges = [] if ip in cluster_info["redis_master_ips_set"]: @@ -163,28 +176,19 @@ def _check_dbmon_heart_beat(): elif ip in cluster_info["twemproxy_ips_set"]: twemproxy_ports = cluster_info.get("twemproxy_ports", []) instance = "{} {}".format(ip, twemproxy_ports[0]) - if ( - c.cluster_type == ClusterType.TwemproxyTendisSSDInstance.value - or c.cluster_type == ClusterType.TendisTwemproxyRedisInstance.value - ): - cluster_type = DbmonHeartbeatReportSubType.TWEMPROXY.value - elif c.cluster_type == ClusterType.TendisPredixyTendisplusCluster.value: - cluster_type = DbmonHeartbeatReportSubType.PREDIXY.value - else: - raise NotImplementedError("Dbmon Not supported tendis type: %s" % c.cluster_type) + heart_beat_subtype = get_report_subtype_for_proxy(c.cluster_type) else: raise NotImplementedError(" %s is not identified in Dbmon" % ip) msg = _("实例 {} dbmon 心跳超时").format(instance) try: - # create_at = models.DateTimeField(_("创建时间"), auto_now_add=True) - # 心跳超时的时间点就用这条记录的创建时间代替了,这里对时间要去不严格 + # 心跳超时的时间点就用这条记录的创建时间代替了,这里对时间要求不严格 DbmonHeartbeatReport.objects.create( creator=c.creator, bk_biz_id=c.bk_biz_id, bk_cloud_id=c.bk_cloud_id, status=False, msg=msg, - cluster_type=cluster_type, + cluster_type=heart_beat_subtype, cluster=c.immute_domain, instance=instance, app=app, diff --git a/dbm-ui/backend/db_periodic_task/local_tasks/ticket.py b/dbm-ui/backend/db_periodic_task/local_tasks/ticket.py index a65045a3ea..d210afa722 100644 --- a/dbm-ui/backend/db_periodic_task/local_tasks/ticket.py +++ b/dbm-ui/backend/db_periodic_task/local_tasks/ticket.py @@ -9,7 +9,6 @@ specific language governing permissions and limitations under the License. """ from celery.schedules import crontab -from celery.task import periodic_task from backend.db_periodic_task.local_tasks import register_periodic_task from backend.ticket.tasks.ticket_tasks import TicketTask diff --git a/dbm-ui/backend/db_proxy/views/db_remote_service/views.py b/dbm-ui/backend/db_proxy/views/db_remote_service/views.py index 89c46d361e..9015c2306a 100644 --- a/dbm-ui/backend/db_proxy/views/db_remote_service/views.py +++ b/dbm-ui/backend/db_proxy/views/db_remote_service/views.py @@ -12,7 +12,6 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import status from rest_framework.decorators import action -from rest_framework.permissions import AllowAny from rest_framework.response import Response from backend.bk_web.swagger import common_swagger_auto_schema diff --git a/dbm-ui/backend/db_proxy/views/dbconfig/views.py b/dbm-ui/backend/db_proxy/views/dbconfig/views.py index 30fd179942..916014a98f 100644 --- a/dbm-ui/backend/db_proxy/views/dbconfig/views.py +++ b/dbm-ui/backend/db_proxy/views/dbconfig/views.py @@ -11,7 +11,6 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import status from rest_framework.decorators import action -from rest_framework.permissions import AllowAny from rest_framework.response import Response from backend.bk_web.swagger import common_swagger_auto_schema diff --git a/dbm-ui/backend/db_proxy/views/dns/views.py b/dbm-ui/backend/db_proxy/views/dns/views.py index 18291c6c5b..1fc852de45 100644 --- a/dbm-ui/backend/db_proxy/views/dns/views.py +++ b/dbm-ui/backend/db_proxy/views/dns/views.py @@ -12,7 +12,6 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import status from rest_framework.decorators import action -from rest_framework.permissions import AllowAny from rest_framework.response import Response from backend.bk_web.swagger import common_swagger_auto_schema diff --git a/dbm-ui/backend/db_proxy/views/nameservice/views.py b/dbm-ui/backend/db_proxy/views/nameservice/views.py index 921f4710de..5df58e5f8d 100644 --- a/dbm-ui/backend/db_proxy/views/nameservice/views.py +++ b/dbm-ui/backend/db_proxy/views/nameservice/views.py @@ -10,7 +10,6 @@ """ from django.utils.translation import ugettext_lazy as _ from rest_framework.decorators import action -from rest_framework.permissions import AllowAny from rest_framework.response import Response from backend.bk_web.swagger import common_swagger_auto_schema diff --git a/dbm-ui/backend/db_report/admin.py b/dbm-ui/backend/db_report/admin.py index 8c38f3f3da..846f6b4061 100644 --- a/dbm-ui/backend/db_report/admin.py +++ b/dbm-ui/backend/db_report/admin.py @@ -1,3 +1 @@ -from django.contrib import admin - # Register your models here. diff --git a/dbm-ui/backend/db_report/report_baseview.py b/dbm-ui/backend/db_report/report_baseview.py index a52e847067..542f37f8a2 100644 --- a/dbm-ui/backend/db_report/report_baseview.py +++ b/dbm-ui/backend/db_report/report_baseview.py @@ -9,7 +9,6 @@ specific language governing permissions and limitations under the License. """ from rest_framework import mixins -from rest_framework.permissions import AllowAny from rest_framework.viewsets import GenericViewSet from backend.bk_web.pagination import AuditedLimitOffsetPagination diff --git a/dbm-ui/backend/db_services/dbbase/resources/serializers.py b/dbm-ui/backend/db_services/dbbase/resources/serializers.py index bcddb4e749..7567c717c3 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 ClusterEntryType, ClusterType +from backend.db_meta.enums import ClusterType from backend.db_meta.models.cluster import Cluster from backend.db_services.dbbase.constants import IP_PORT_DIVIDER diff --git a/dbm-ui/backend/db_services/mysql/dumper/views/dumper_instance.py b/dbm-ui/backend/db_services/mysql/dumper/views/dumper_instance.py index b728ed034f..6876dd9f71 100644 --- a/dbm-ui/backend/db_services/mysql/dumper/views/dumper_instance.py +++ b/dbm-ui/backend/db_services/mysql/dumper/views/dumper_instance.py @@ -8,24 +8,17 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -import itertools -from collections import defaultdict -from typing import Dict, List from django.utils.translation import ugettext as _ from backend.bk_web import viewsets from backend.bk_web.pagination import AuditedLimitOffsetPagination from backend.bk_web.swagger import common_swagger_auto_schema -from backend.db_meta.enums import InstanceInnerRole from backend.db_meta.enums.extra_process_type import ExtraProcessType -from backend.db_meta.models import Cluster from backend.db_meta.models.extra_process import ExtraProcessInstance from backend.db_services.mysql.dumper.filters import DumperInstanceListFilter from backend.db_services.mysql.dumper.handlers import DumperHandler from backend.db_services.mysql.dumper.serializers import DumperInstanceConfigSerializer -from backend.ticket.constants import TicketStatus, TicketType -from backend.ticket.models import Ticket SWAGGER_TAG = "dumper" diff --git a/dbm-ui/backend/db_services/mysql/remote_service/handlers.py b/dbm-ui/backend/db_services/mysql/remote_service/handlers.py index 05373b448b..9270f31ff1 100644 --- a/dbm-ui/backend/db_services/mysql/remote_service/handlers.py +++ b/dbm-ui/backend/db_services/mysql/remote_service/handlers.py @@ -142,7 +142,9 @@ def check_flashback_database(self, flashback_infos: List[Dict[str, Any]]): def _format_db_tb_name(_data_names): for index in range(len(_data_names)): # mysql模糊匹配单个字符,用_,原本字符串里带的_,要\_转义,如果是*,则转为%表示like % --> 永真 - _data_names[index] = _data_names[index].replace("_", "\_").replace("?", "_").replace("*", "%") + _data_names[index] = ( + _data_names[index].replace("_", "\_").replace("?", "_").replace("*", "%") # noqa: W605 + ) return _data_names def _get_db_tb_sts(_data_names, key, default): diff --git a/dbm-ui/backend/dbm_init/json_files/format.py b/dbm-ui/backend/dbm_init/json_files/format.py index 4ae881ff22..9a82038678 100644 --- a/dbm-ui/backend/dbm_init/json_files/format.py +++ b/dbm-ui/backend/dbm_init/json_files/format.py @@ -8,12 +8,9 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -import json -from typing import Any, Dict, Optional, Union +from typing import Dict from urllib.parse import urljoin -from jinja2 import Environment - from backend import env from backend.configuration.constants import DBType from backend.db_meta.models import AppMonitorTopo diff --git a/dbm-ui/backend/flow/apps.py b/dbm-ui/backend/flow/apps.py index 6c68acf37e..6c93951226 100644 --- a/dbm-ui/backend/flow/apps.py +++ b/dbm-ui/backend/flow/apps.py @@ -20,4 +20,8 @@ class FlowConfig(AppConfig): name = "backend.flow" def ready(self): - import backend.flow.signal.handlers # pylint: disable=unused-import + from pipeline.eri.signals import post_set_state + + from backend.flow.signal.handlers import post_set_state_signal_handler + + post_set_state.connect(post_set_state_signal_handler, dispatch_uid="_post_set_state_handler") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/common/machine_os_init.py b/dbm-ui/backend/flow/engine/bamboo/scene/common/machine_os_init.py index 2ba5a37df5..4e1c985c00 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/common/machine_os_init.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/common/machine_os_init.py @@ -23,7 +23,7 @@ from backend.flow.plugins.components.collections.common.sa_idle_check import CheckMachineIdleComponent from backend.flow.plugins.components.collections.common.sa_init import SaInitComponent from backend.flow.plugins.components.collections.common.transfer_host_service import TransferHostServiceComponent -from backend.flow.utils.mysql.mysql_act_dataclass import InitCheckForResourceKwargs, InitCheckKwargs +from backend.flow.utils.mysql.mysql_act_dataclass import InitCheckForResourceKwargs class ImportResourceInitStepFlow(object): diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_cluster_master_rep.py b/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_cluster_master_rep.py index 7e2755211f..112a252b2d 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_cluster_master_rep.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_cluster_master_rep.py @@ -24,7 +24,6 @@ SyncType, ) from backend.flow.engine.bamboo.scene.common.builder import SubBuilder -from backend.flow.plugins.components.collections.redis.exec_shell_script import ExecuteShellReloadMetaComponent from backend.flow.plugins.components.collections.redis.redis_db_meta import RedisDBMetaComponent from backend.flow.utils.redis.redis_context_dataclass import ActKwargs from backend.flow.utils.redis.redis_db_meta import RedisDBMeta diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_switch.py b/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_switch.py index 2a1fd9b435..2a8fcd7e30 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_switch.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/redis/atom_jobs/redis_switch.py @@ -15,7 +15,6 @@ from django.utils.translation import ugettext as _ from backend.configuration.constants import DBType -from backend.db_meta.api.cluster import nosqlcomm from backend.db_meta.enums import ClusterType from backend.flow.consts import SwitchType, SyncType from backend.flow.engine.bamboo.scene.common.builder import SubBuilder diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/redis/redis_data_structure.py b/dbm-ui/backend/flow/engine/bamboo/scene/redis/redis_data_structure.py index ce01a6bc54..cbfb57bb02 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/redis/redis_data_structure.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/redis/redis_data_structure.py @@ -13,7 +13,7 @@ from collections import defaultdict from copy import deepcopy from dataclasses import asdict -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional from django.utils.translation import ugettext as _ @@ -246,16 +246,7 @@ def redis_data_structure_flow(self): # ### 获取机器磁盘备份目录信息结束############################################################ # ### 数据构造下发actuator 检查备份文件是否存在,新机器磁盘空间是否够############################################## - # GetTendisType 获取redis类型 - if cluster_type == ClusterType.TendisTwemproxyRedisInstance.value: - tendis_type = ClusterType.RedisInstance.value - elif cluster_type == ClusterType.TendisPredixyTendisplusCluster.value: - tendis_type = ClusterType.TendisplusInstance.value - elif cluster_type == ClusterType.TwemproxyTendisSSDInstance.value: - tendis_type = ClusterType.TendisSSDInstance.value - else: - raise NotImplementedError("Not supported tendis type: %s" % cluster_type) - + tendis_type = self.get_tendis_type_by_cluster_type(cluster_type) # 目录设置为空,根据获取到的机器备份目录来设置 dest_dir = "" # 整理数据构造下发actuator 源节点和临时集群节点之间的对应关系,# 获取备份信息,用于磁盘空间是否足够的前置检查 @@ -264,37 +255,9 @@ def redis_data_structure_flow(self): ) # ### 检查新机器磁盘空间和内存是否够############################################## - acts_list_disk_check = [] - for index, new_master in enumerate([host["ip"] for host in info["redis"]]): - - # 计算待下载的备份文件大小和获取对应机器磁盘大小,这里是单个任务的时候,还有多个任务的时候 - multi_total_size = 0 - for act in acts_list: - data_params = act["kwargs"]["cluster"] - full_size = 0 - all_binlog_size = 0 - for full in data_params["full_file_list"]: - full_size += full["size"] - # ssd和tendisplus才有binlog文件 - if cluster_type in [ - ClusterType.TendisTwemproxyRedisInstance.value, - ClusterType.TwemproxyTendisSSDInstance.value, - ]: - for binlog in data_params["binlog_file_list"]: - all_binlog_size += binlog["size"] - total_size = full_size + all_binlog_size - if data_params["new_temp_ip"] == new_master: - multi_total_size += total_size - first_act_kwargs.cluster["multi_total_size"] = multi_total_size - first_act_kwargs.exec_ip = new_master - acts_list_disk_check.append( - { - "act_name": _("redis 数据构造前置磁盘检查").format(first_act_kwargs.exec_ip), - "act_component_code": RedisDataStructurePrecheckComponent.code, - "kwargs": asdict(first_act_kwargs), - "splice_payload_var": "disk_used", - } - ) + acts_list_disk_check = self.generate_acts_list_disk_check( + info["redis"], acts_list, cluster_type, first_act_kwargs + ) redis_pipeline.add_parallel_acts(acts_list=acts_list_disk_check) # 并发下载 节点维度的备份文件 @@ -448,6 +411,54 @@ def redis_data_structure_flow(self): redis_pipeline_all.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines_multi_cluster) redis_pipeline_all.run_pipeline() + @staticmethod + def generate_acts_list_disk_check( + redis_hosts: List[Dict], acts_list: List[Dict], cluster_type: str, first_act_kwargs: ActKwargs + ) -> List: + acts_list_disk_check = [] + for index, new_master in enumerate([host["ip"] for host in redis_hosts]): + # 计算待下载的备份文件大小和获取对应机器磁盘大小,这里是单个任务的时候,还有多个任务的时候 + multi_total_size = 0 + for act in acts_list: + data_params = act["kwargs"]["cluster"] + full_size = 0 + all_binlog_size = 0 + for full in data_params["full_file_list"]: + full_size += full["size"] + # ssd和tendisplus才有binlog文件 + if cluster_type in [ + ClusterType.TendisTwemproxyRedisInstance.value, + ClusterType.TwemproxyTendisSSDInstance.value, + ]: + for binlog in data_params["binlog_file_list"]: + all_binlog_size += binlog["size"] + total_size = full_size + all_binlog_size + if data_params["new_temp_ip"] == new_master: + multi_total_size += total_size + first_act_kwargs.cluster["multi_total_size"] = multi_total_size + first_act_kwargs.exec_ip = new_master + acts_list_disk_check.append( + { + "act_name": _("redis 数据构造前置磁盘检查").format(first_act_kwargs.exec_ip), + "act_component_code": RedisDataStructurePrecheckComponent.code, + "kwargs": asdict(first_act_kwargs), + "splice_payload_var": "disk_used", + } + ) + return acts_list_disk_check + + @staticmethod + def get_tendis_type_by_cluster_type(cluster_type: str) -> str: + if cluster_type == ClusterType.TendisTwemproxyRedisInstance.value: + tendis_type = ClusterType.RedisInstance.value + elif cluster_type == ClusterType.TendisPredixyTendisplusCluster.value: + tendis_type = ClusterType.TendisplusInstance.value + elif cluster_type == ClusterType.TwemproxyTendisSSDInstance.value: + tendis_type = ClusterType.TendisSSDInstance.value + else: + raise NotImplementedError("Not supported tendis type: %s" % cluster_type) + return tendis_type + @staticmethod def __get_cluster_info(bk_biz_id: int, cluster_id: int) -> dict: """获取集群现有信息 diff --git a/dbm-ui/backend/flow/plugins/components/collections/common/base_service.py b/dbm-ui/backend/flow/plugins/components/collections/common/base_service.py index 9ceb2c6552..001a311f53 100644 --- a/dbm-ui/backend/flow/plugins/components/collections/common/base_service.py +++ b/dbm-ui/backend/flow/plugins/components/collections/common/base_service.py @@ -8,7 +8,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -import base64 import copy import json import logging diff --git a/dbm-ui/backend/flow/plugins/components/collections/mysql/filter_database_table_by_flashback_input.py b/dbm-ui/backend/flow/plugins/components/collections/mysql/filter_database_table_by_flashback_input.py index d04e840b64..01250b6146 100644 --- a/dbm-ui/backend/flow/plugins/components/collections/mysql/filter_database_table_by_flashback_input.py +++ b/dbm-ui/backend/flow/plugins/components/collections/mysql/filter_database_table_by_flashback_input.py @@ -32,10 +32,14 @@ def _execute(self, data, parent_data) -> bool: tables = global_data["tables"] tables_ignore = global_data["tables_ignore"] - databases = [ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in databases] - databases_ignore = [ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in databases_ignore] - tables = [ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in tables] - tables_ignore = [ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in tables_ignore] + databases = [ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in databases] # noqa: W605 + databases_ignore = [ + ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in databases_ignore # noqa: W605 + ] # noqa: W605 + tables = [ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in tables] # noqa: W605 + tables_ignore = [ + ele.replace("_", "\_").replace("*", "%").replace("?", "_") for ele in tables_ignore # noqa: W605 + ] db_filter_sql = "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE ({}) AND ({})".format( " OR ".join(["SCHEMA_NAME LIKE '{}'".format(ele) for ele in databases]), diff --git a/dbm-ui/backend/flow/signal/handlers.py b/dbm-ui/backend/flow/signal/handlers.py index 5cbe01fc5e..5f6fd991ae 100644 --- a/dbm-ui/backend/flow/signal/handlers.py +++ b/dbm-ui/backend/flow/signal/handlers.py @@ -11,12 +11,9 @@ import logging from celery.task import task -from django.dispatch import receiver from django.utils import timezone from django.utils.translation import ugettext as _ -from pipeline.eri.signals import post_set_state -from backend import env from backend.components import CmsiApi from backend.configuration.constants import SystemSettingsEnum from backend.configuration.models import SystemSettings @@ -33,7 +30,6 @@ logger = logging.getLogger("flow") -@receiver(post_set_state, dispatch_uid="_post_set_state_handler") def post_set_state_signal_handler(sender, node_id, to_state, version, root_id, *args, **kwargs): engine = BambooEngine(root_id=root_id) pipeline_states = engine.get_pipeline_states().data diff --git a/dbm-ui/backend/flow/utils/cloud/script_template/nginx_template.py b/dbm-ui/backend/flow/utils/cloud/script_template/nginx_template.py index b549bcd16f..70c40ac17c 100644 --- a/dbm-ui/backend/flow/utils/cloud/script_template/nginx_template.py +++ b/dbm-ui/backend/flow/utils/cloud/script_template/nginx_template.py @@ -140,7 +140,11 @@ } echo "nginx-pid: $(cat $path/nginx-portable/logs/nginx.pid)"; is_port_listen_by_pid 80; -exit $? +exit_status=$? +if [ $exit_status -ne 0 ]; then + echo "Failed to start nginx service!" + exit $exit_status +fi # 增加对nginx日志文件的定时清理 clear_script_path="$path/nginx-portable/cron-clear-logs.sh"; @@ -152,12 +156,12 @@ # 目前主要清理access_log和err_log access_log_size=\$(stat -c%s "$path/nginx-portable/logs/access.log") if [ "\$access_log_size" -gt "\$max_log_size" ]; then - echo > $nginx_log_path/access.log; + echo > \$nginx_log_path/access.log; fi err_log_size=\$(stat -c%s "$path/nginx-portable/logs/error.log") if [ "\$err_log_size" -gt "\$max_log_size" ]; then - echo > $nginx_log_path/err_log_size.log; + echo > \$nginx_log_path/err_log_size.log; fi " > $clear_script_path; diff --git a/dbm-ui/backend/ticket/builders/mysql/base.py b/dbm-ui/backend/ticket/builders/mysql/base.py index cdfd91e7bb..321ae71a40 100644 --- a/dbm-ui/backend/ticket/builders/mysql/base.py +++ b/dbm-ui/backend/ticket/builders/mysql/base.py @@ -191,7 +191,7 @@ class DBTableField(serializers.CharField): """ # 库表匹配正则 - db_tb_pattern = re.compile("^[-_a-zA-Z0-9\*\?%]{0,35}$") + db_tb_pattern = re.compile("^[-_a-zA-Z0-9\*\?%]{0,35}$") # noqa: W605 # 是否为库 db_field = False diff --git a/dbm-ui/backend/ticket/builders/mysql/mysql_ha_destroy.py b/dbm-ui/backend/ticket/builders/mysql/mysql_ha_destroy.py index 369554acdf..6623b431ef 100644 --- a/dbm-ui/backend/ticket/builders/mysql/mysql_ha_destroy.py +++ b/dbm-ui/backend/ticket/builders/mysql/mysql_ha_destroy.py @@ -9,9 +9,6 @@ specific language governing permissions and limitations under the License. """ -from collections import defaultdict -from typing import Dict, List - from django.utils.translation import ugettext_lazy as _ from backend.db_meta.enums import ClusterPhase diff --git a/dbm-ui/backend/ticket/builders/mysql/mysql_master_fail_over.py b/dbm-ui/backend/ticket/builders/mysql/mysql_master_fail_over.py index c15c6e7057..76799f2a80 100644 --- a/dbm-ui/backend/ticket/builders/mysql/mysql_master_fail_over.py +++ b/dbm-ui/backend/ticket/builders/mysql/mysql_master_fail_over.py @@ -17,7 +17,6 @@ from backend.ticket.builders.mysql.mysql_master_slave_switch import ( MysqlDumperMigrateParamBuilder, MysqlMasterSlaveSwitchDetailSerializer, - MysqlMasterSlaveSwitchFlowBuilder, MysqlMasterSlaveSwitchParamBuilder, ) from backend.ticket.constants import FlowRetryType, TicketType diff --git a/dbm-ui/backend/ticket/builders/mysql/mysql_master_slave_switch.py b/dbm-ui/backend/ticket/builders/mysql/mysql_master_slave_switch.py index 93696bdb6b..aacad1619b 100644 --- a/dbm-ui/backend/ticket/builders/mysql/mysql_master_slave_switch.py +++ b/dbm-ui/backend/ticket/builders/mysql/mysql_master_slave_switch.py @@ -9,8 +9,6 @@ specific language governing permissions and limitations under the License. """ import itertools -from collections import defaultdict -from typing import Dict, List from django.db.models import Q from django.utils.translation import gettext_lazy as _ diff --git a/dbm-ui/backend/ticket/builders/redis/redis_toolbox_autofix.py b/dbm-ui/backend/ticket/builders/redis/redis_toolbox_autofix.py index bfc7ba38fe..3643cd0a35 100644 --- a/dbm-ui/backend/ticket/builders/redis/redis_toolbox_autofix.py +++ b/dbm-ui/backend/ticket/builders/redis/redis_toolbox_autofix.py @@ -12,7 +12,6 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers -from backend.configuration.constants import AffinityEnum from backend.db_meta.enums import InstanceRole from backend.db_meta.models import Cluster, StorageInstance from backend.db_services.dbbase.constants import IpSource diff --git a/dbm-ui/backend/ticket/builders/redis/redis_toolbox_cut_off.py b/dbm-ui/backend/ticket/builders/redis/redis_toolbox_cut_off.py index f06477f254..48f65740f6 100644 --- a/dbm-ui/backend/ticket/builders/redis/redis_toolbox_cut_off.py +++ b/dbm-ui/backend/ticket/builders/redis/redis_toolbox_cut_off.py @@ -12,8 +12,6 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers -from backend.configuration.constants import AffinityEnum -from backend.db_meta.enums import InstanceRole from backend.db_meta.models import Cluster, StorageInstance from backend.db_services.dbbase.constants import IpSource from backend.flow.engine.controller.redis import RedisController diff --git a/dbm-ui/backend/ticket/builders/riak/riak_apply.py b/dbm-ui/backend/ticket/builders/riak/riak_apply.py index 2feced79bc..3ec22aaca4 100644 --- a/dbm-ui/backend/ticket/builders/riak/riak_apply.py +++ b/dbm-ui/backend/ticket/builders/riak/riak_apply.py @@ -11,16 +11,14 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers -from backend.configuration.constants import AffinityEnum from backend.db_meta.enums import ClusterType from backend.db_meta.models import DBModule -from backend.db_services.dbbase.constants import IpSource from backend.db_services.ipchooser.query.resource import ResourceQueryHelper from backend.flow.engine.controller.riak import RiakController from backend.ticket import builders from backend.ticket.builders.common.base import CommonValidate from backend.ticket.builders.common.bigdata import BigDataApplyDetailsSerializer -from backend.ticket.builders.riak.base import RIAK_VERSION, BaseRiakTicketFlowBuilder +from backend.ticket.builders.riak.base import BaseRiakTicketFlowBuilder from backend.ticket.constants import TicketType diff --git a/dbm-ui/backend/ticket/builders/riak/riak_destroy.py b/dbm-ui/backend/ticket/builders/riak/riak_destroy.py index b0d22ba771..cbce5ed70c 100644 --- a/dbm-ui/backend/ticket/builders/riak/riak_destroy.py +++ b/dbm-ui/backend/ticket/builders/riak/riak_destroy.py @@ -12,7 +12,6 @@ import logging from django.utils.translation import ugettext as _ -from rest_framework import serializers from backend.db_meta.enums import ClusterPhase from backend.db_meta.models import Cluster diff --git a/dbm-ui/backend/ticket/builders/riak/riak_disable.py b/dbm-ui/backend/ticket/builders/riak/riak_disable.py index 1c7280b922..c7a2e92efd 100644 --- a/dbm-ui/backend/ticket/builders/riak/riak_disable.py +++ b/dbm-ui/backend/ticket/builders/riak/riak_disable.py @@ -12,7 +12,6 @@ import logging from django.utils.translation import ugettext as _ -from rest_framework import serializers from backend.db_meta.enums import ClusterPhase from backend.db_meta.models import Cluster diff --git a/dbm-ui/backend/ticket/builders/riak/riak_enable.py b/dbm-ui/backend/ticket/builders/riak/riak_enable.py index 40eaeae1ae..9757b7c41a 100644 --- a/dbm-ui/backend/ticket/builders/riak/riak_enable.py +++ b/dbm-ui/backend/ticket/builders/riak/riak_enable.py @@ -12,7 +12,6 @@ import logging from django.utils.translation import ugettext as _ -from rest_framework import serializers from backend.db_meta.enums import ClusterPhase from backend.db_meta.models import Cluster diff --git a/dbm-ui/backend/ticket/builders/riak/riak_scale_up.py b/dbm-ui/backend/ticket/builders/riak/riak_scale_up.py index 22c68e66ed..0d9e773c39 100644 --- a/dbm-ui/backend/ticket/builders/riak/riak_scale_up.py +++ b/dbm-ui/backend/ticket/builders/riak/riak_scale_up.py @@ -12,10 +12,8 @@ import logging from django.utils.translation import ugettext as _ -from rest_framework import serializers from backend.db_meta.models import Cluster -from backend.db_services.dbbase.constants import IpSource from backend.flow.engine.controller.riak import RiakController from backend.ticket import builders from backend.ticket.builders.common.bigdata import BigDataScaleDetailSerializer diff --git a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_apply.py b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_apply.py index 518a52eaf4..448d36a2e1 100644 --- a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_apply.py +++ b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_apply.py @@ -23,7 +23,7 @@ from backend.flow.engine.controller.tbinlogdumper import TBinlogDumperController from backend.ticket import builders from backend.ticket.builders.common.constants import DumperProtocolType -from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder, BaseTendbTicketFlowBuilder +from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder from backend.ticket.constants import TicketType diff --git a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_disable.py b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_disable.py index 9ef9335da9..7faf5b83d3 100644 --- a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_disable.py +++ b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_disable.py @@ -8,18 +8,14 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -import functools -import operator -from django.db.models import Q from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers -from backend.db_services.mysql.dumper.models import DumperSubscribeConfig from backend.flow.engine.controller.tbinlogdumper import TBinlogDumperController from backend.ticket import builders from backend.ticket.builders.common.base import SkipToRepresentationMixin -from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder, BaseTendbTicketFlowBuilder +from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder from backend.ticket.constants import TicketType diff --git a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_enable.py b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_enable.py index e82c33017e..78fcbc692d 100644 --- a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_enable.py +++ b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_enable.py @@ -8,18 +8,14 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -import functools -import operator -from django.db.models import Q from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers -from backend.db_services.mysql.dumper.models import DumperSubscribeConfig from backend.flow.engine.controller.tbinlogdumper import TBinlogDumperController from backend.ticket import builders from backend.ticket.builders.common.base import SkipToRepresentationMixin -from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder, BaseTendbTicketFlowBuilder +from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder from backend.ticket.constants import TicketType diff --git a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_reduce_nodes.py b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_reduce_nodes.py index a080478dc4..430860ec15 100644 --- a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_reduce_nodes.py +++ b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_reduce_nodes.py @@ -22,7 +22,7 @@ from backend.flow.engine.controller.tbinlogdumper import TBinlogDumperController from backend.ticket import builders from backend.ticket.builders.common.base import SkipToRepresentationMixin -from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder, BaseTendbTicketFlowBuilder +from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder from backend.ticket.constants import TicketFlowStatus, TicketType diff --git a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_switch.py b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_switch.py index c27c66ad9f..c1d19c1830 100644 --- a/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_switch.py +++ b/dbm-ui/backend/ticket/builders/tbinlogdumper/dumper_switch.py @@ -15,7 +15,7 @@ from backend.flow.engine.controller.tbinlogdumper import TBinlogDumperController from backend.ticket import builders from backend.ticket.builders.common.base import SkipToRepresentationMixin -from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder, BaseTendbTicketFlowBuilder +from backend.ticket.builders.tendbcluster.base import BaseDumperTicketFlowBuilder from backend.ticket.constants import TicketType diff --git a/dbm-ui/backend/ticket/flow_manager/base.py b/dbm-ui/backend/ticket/flow_manager/base.py index 1040d612af..5a4a83f919 100644 --- a/dbm-ui/backend/ticket/flow_manager/base.py +++ b/dbm-ui/backend/ticket/flow_manager/base.py @@ -22,7 +22,6 @@ from backend.ticket.builders.common.base import fetch_cluster_ids, fetch_instance_ids from backend.ticket.constants import FLOW_FINISHED_STATUS, FLOW_NOT_EXECUTE_STATUS, FlowErrCode, TicketFlowStatus from backend.ticket.models import ClusterOperateRecord, Flow, InstanceOperateRecord -from backend.utils.basic import get_target_items_from_details logger = logging.getLogger("root") diff --git a/dbm-ui/backend/ticket/flow_manager/inner.py b/dbm-ui/backend/ticket/flow_manager/inner.py index ead750ae1a..a06167fdaa 100644 --- a/dbm-ui/backend/ticket/flow_manager/inner.py +++ b/dbm-ui/backend/ticket/flow_manager/inner.py @@ -27,7 +27,6 @@ from backend.ticket.constants import BAMBOO_STATE__TICKET_STATE_MAP, FlowCallbackType from backend.ticket.flow_manager.base import BaseTicketFlow from backend.ticket.models import Flow -from backend.utils.basic import get_target_items_from_details from backend.utils.time import datetime2str logger = logging.getLogger("root") diff --git a/dbm-ui/backend/db_meta/validators/__init__.py b/dbm-ui/blue_krill/__init__.py similarity index 94% rename from dbm-ui/backend/db_meta/validators/__init__.py rename to dbm-ui/blue_krill/__init__.py index 8edb227544..aa5085c628 100644 --- a/dbm-ui/backend/db_meta/validators/__init__.py +++ b/dbm-ui/blue_krill/__init__.py @@ -8,4 +8,3 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -from backend.db_meta.validators.impl import * diff --git a/dbm-ui/blue_krill/data_types/__init__.py b/dbm-ui/blue_krill/data_types/__init__.py index 2f8bd00271..fd53038fc0 100644 --- a/dbm-ui/blue_krill/data_types/__init__.py +++ b/dbm-ui/blue_krill/data_types/__init__.py @@ -8,4 +8,4 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. """ -# 因为 peotry 包兼容问题,临时把此包放到项目中,并且 blue_krill 只使用了 data_types, 后续考虑移除 +# 因为 poetry 包兼容问题,临时把此包放到项目中,并且 blue_krill 只使用了 data_types, 后续考虑移除 diff --git a/dbm-ui/blueking/__init__.py b/dbm-ui/blueking/__init__.py new file mode 100644 index 0000000000..aa5085c628 --- /dev/null +++ b/dbm-ui/blueking/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" diff --git a/dbm-ui/scripts/ci/code_quality.sh b/dbm-ui/scripts/ci/code_quality.sh index 4403e246be..f3dd2a21ff 100755 --- a/dbm-ui/scripts/ci/code_quality.sh +++ b/dbm-ui/scripts/ci/code_quality.sh @@ -57,7 +57,7 @@ echo "未通过数: $TEST_NOT_SUCCESS_COUNT" if [[ $TEST_NOT_SUCCESS_COUNT -ne 0 ]]; then - echo -e $TEST_LOGS + echo -e "$TEST_LOGS" exit 1 fi