Skip to content

Commit 02023c1

Browse files
committed
feat(mysql): celery-task-disable-dbha-by-app #10087
1 parent 2b5194e commit 02023c1

File tree

6 files changed

+105
-1
lines changed

6 files changed

+105
-1
lines changed

dbm-ui/backend/configuration/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class SystemSettingsEnum(str, StructuredEnum):
132132
COST_ESTIMATE = EnumField("COST_ESTIMATE", _("COST_ESTIMATE"))
133133
# 主机属性配置
134134
MACHINE_PROPERTY = EnumField("MACHINE_PROPERTY", _("主机属性开关"))
135+
PADDING_PROXY_APPS = EnumField("PADDING_PROXY_APPS", _("补全proxy业务"))
136+
DISABLE_DBHA_APPS_CLUSTER_TYPE = EnumField("DISABLE_DBHA_APPS_CLUSTER_TYPE", _("禁用DBHA业务"))
135137

136138

137139
class BizSettingsEnum(str, StructuredEnum):
@@ -270,6 +272,8 @@ class BizSettingsEnum(str, StructuredEnum):
270272
[SystemSettingsEnum.PADDING_PROXY_CLUSTER_LIST, "list", [], _("补全proxy的集群域名列表")],
271273
[SystemSettingsEnum.VIRTUAL_USERS, "list", [], _("平台调用的虚拟账户列表")],
272274
[SystemSettingsEnum.MACHINE_PROPERTY, "dict", DEFAULT_MACHINE_PROPERTY, _("主机属性开关配置")],
275+
[SystemSettingsEnum.PADDING_PROXY_APPS, "list", [], _("补全proxy业务")],
276+
[SystemSettingsEnum.DISABLE_DBHA_APPS_CLUSTER_TYPE, "dict", {}, _("禁用DBHA业务")],
273277
]
274278

275279
# 环境配置项 是否支持DNS解析 pulsar flow used

dbm-ui/backend/db_meta/models/cluster.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,5 +493,7 @@ class ClusterDBHAExt(AuditedModel):
493493
"""
494494

495495
cluster = models.OneToOneField(Cluster, on_delete=models.PROTECT, unique=True)
496-
begin_time = models.DateTimeField(null=False, auto_now=True, help_text=_("屏蔽开始时间"), db_index=True)
496+
begin_time = models.DateTimeField(
497+
null=False, auto_now_add=True, auto_now=False, help_text=_("屏蔽开始时间"), db_index=True
498+
)
497499
end_time = models.DateTimeField(default=None, null=False, auto_now=False, help_text=_("屏蔽结束时间"), db_index=True)

dbm-ui/backend/db_periodic_task/local_tasks/disable_dbha/__init__.py

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
import datetime
12+
import logging
13+
14+
from celery.schedules import crontab
15+
16+
from backend.configuration.constants import SystemSettingsEnum
17+
from backend.configuration.models import SystemSettings
18+
from backend.db_meta.models import Cluster, ClusterDBHAExt
19+
from backend.db_periodic_task.local_tasks import register_periodic_task
20+
21+
logger = logging.getLogger("celery")
22+
23+
24+
@register_periodic_task(run_every=crontab(minute="*"))
25+
def update_disable_dbha_config():
26+
"""
27+
有的业务要整个禁用 dbha
28+
但是现在的设计是按集群来的, 这些业务有新集群会漏配置
29+
短时间内又没时间从头搞一遍设计
30+
先搞个 task 高频更新下禁用 dbha 的表
31+
"""
32+
disable_dbha_config = (
33+
SystemSettings.get_setting_value(SystemSettingsEnum.DISABLE_DBHA_APPS_CLUSTER_TYPE.value) or {}
34+
)
35+
# "bk_biz_id": ["cluster_types"]
36+
# {
37+
# "123": ["tendbha", "sqlsvr"],
38+
# "456": ["tendbcluster"],
39+
# }
40+
41+
now = datetime.datetime.now()
42+
for bk_biz_id, cluster_types in disable_dbha_config.items():
43+
for c in Cluster.objects.filter(bk_biz_id=int(bk_biz_id), cluster_type__in=cluster_types):
44+
ClusterDBHAExt.objects.update_or_create(
45+
defaults={
46+
"creator": "admin",
47+
"updater": "admin",
48+
"end_time": datetime.timedelta(days=3000) + now,
49+
},
50+
cluster_id=c.id,
51+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from celery.schedules import crontab
12+
13+
from backend.configuration.constants import SystemSettingsEnum
14+
from backend.configuration.models import SystemSettings
15+
from backend.db_meta.enums import ClusterType
16+
from backend.db_meta.models import Cluster
17+
from backend.db_periodic_task.local_tasks import register_periodic_task
18+
19+
20+
@register_periodic_task(run_every=crontab(minute="*"))
21+
def update_padding_proxy_clusters():
22+
"""
23+
有些db机器部署了业务进程的老业务, 还有新增集群的需求
24+
以前padding proxy是录入的域名
25+
搞个task动态更新下
26+
"""
27+
padding_proxy_bk_biz_ids = SystemSettings.get_setting_value(SystemSettingsEnum.PADDING_PROXY_APPS.value)
28+
29+
padding_proxy_clusters = SystemSettings.get_setting_value(SystemSettingsEnum.PADDING_PROXY_CLUSTER_LIST.value)
30+
for bk_biz_id in padding_proxy_bk_biz_ids:
31+
for c in Cluster.objects.filter(bk_biz_id=bk_biz_id, cluster_type=ClusterType.TenDBHA):
32+
if c.immute_domain not in padding_proxy_clusters:
33+
padding_proxy_clusters.append(c.immute_domain)
34+
35+
SystemSettings.objects.filter(key=SystemSettingsEnum.PADDING_PROXY_CLUSTER_LIST).update(
36+
value=padding_proxy_clusters
37+
)

0 commit comments

Comments
 (0)