Skip to content

Commit

Permalink
feat(backend): 规格层级调整 #7527
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Nov 6, 2024
1 parent 1ee43ba commit 3ce63ee
Show file tree
Hide file tree
Showing 21 changed files with 1,236 additions and 1,188 deletions.
1 change: 1 addition & 0 deletions dbm-ui/backend/components/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
MYSQL_SIMULATION_DOMAIN = env.MYSQL_SIMULATION_DOMAIN or ESB_DOMAIN_TPL.format("db_simulation")
NAMESERVICE_APIGW_DOMAIN = env.NAMESERVICE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("nameservice")
HADB_APIGW_DOMAIN = env.HADB_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("hadb")
HCM_APIGW_DOMAIN = env.HCM_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("hcm")
DBRESOURCE_APIGW_DOMAIN = env.DBRESOURCE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("dbresource")
BACKUP_APIGW_DOMAIN = env.BACKUP_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("backup")
CELERY_SERVICE_APIGW_DOMAIN = env.CELERY_SERVICE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("celery_service")
Expand Down
10 changes: 10 additions & 0 deletions dbm-ui/backend/components/hcm/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
"""
30 changes: 30 additions & 0 deletions dbm-ui/backend/components/hcm/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2021 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.
"""

from django.utils.translation import ugettext_lazy as _

from ..base import BaseApi
from ..domains import HADB_APIGW_DOMAIN


class _HCMApi(BaseApi):
MODULE = _("HCM海垒 服务")
BASE = HADB_APIGW_DOMAIN

def __init__(self):
self.list_cvm_device = self.generate_data_api(
method="POST",
url="/api/v1/woa/config/findmany/config/cvm/device/detail/",
description=_("获取可用的CVM机型"),
)


HCMApi = _HCMApi()
3 changes: 2 additions & 1 deletion dbm-ui/backend/db_meta/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def init_db_meta(sender, **kwargs):

# 初始化规格配置
try:
Spec.init_spec()
if not Spec.objects.count():
Spec.init_spec()
except (IntegrityError, Exception) as err: # pylint: disable=broad-except:
logger.warning(f"Spec init occur error: {err}, maybe already init, ignore...")

Expand Down
119 changes: 119 additions & 0 deletions dbm-ui/backend/db_meta/enums/spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# -*- 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.
"""
from django.utils.translation import gettext_lazy as _

from backend.configuration.constants import DBType
from blue_krill.data_types.enum import EnumField, StructuredEnum

# 兼容原来的字段,spec_cluster_type就是db_type
SpecClusterType = DBType


class SpecMachineType(str, StructuredEnum):
PROXY = EnumField("proxy", _("proxy"))
BACKEND = EnumField("backend", _("backend"))

# redis主从、redis集群的后端规格同tendis cache一致
TendisTwemproxyRedisInstance = EnumField("TwemproxyRedisInstance", _("TendisCache集群"))
TendisPredixyTendisplusCluster = EnumField("PredixyTendisplusCluster", _("Tendisplus存储版集群"))
TwemproxyTendisSSDInstance = EnumField("TwemproxyTendisSSDInstance", _("TendisSSD集群"))

# RedisCluster这个Key不参与规格过滤,只在部署方案的时候生效
TendisPredixyRedisCluster = EnumField("PredixyRedisCluster", _("RedisCluster集群"))

ES_DATANODE = EnumField("es_datanode", _("es_datanode"))
ES_MASTER = EnumField("es_master", _("es_master"))
ES_CLIENT = EnumField("es_client", _("es_client"))

BROKER = EnumField("broker", _("broker"))
ZOOKEEPER = EnumField("zookeeper", _("zookeeper"))

HDFS_MASTER = EnumField("hdfs_master", _("hdfs_master"))
HDFS_DATANODE = EnumField("hdfs_datanode", _("hdfs_datanode"))

PULSAR_ZOOKEEPER = EnumField("pulsar_zookeeper", _("pulsar_zookeeper"))
PULSAR_BOOKKEEPER = EnumField("pulsar_bookkeeper", _("pulsar_bookkeeper"))
PULSAR_BROKER = EnumField("pulsar_broker", _("pulsar_broker"))

RIAK = EnumField("riak", _("riak"))

SQLSERVER = EnumField("sqlserver", _("sqlserver"))

MONGOS = EnumField("mongos", _("mongos"))
MONGODB = EnumField("mongodb", _("mongodb"))
MONOG_CONFIG = EnumField("mongo_config", _("mongo_config"))


# TODO: 规格迁移脚本函数,迁移完成后删除
def migrate_spec():
from django.db import transaction

from backend.configuration.constants import DBType
from backend.db_meta.enums import ClusterType, MachineType
from backend.db_meta.models.spec import Spec

# 原规格层级和新规格层级的映射
MIGRATE_SPEC_MACHINE_MAP = {
MachineType.SINGLE: SpecMachineType.BACKEND,
MachineType.BACKEND: SpecMachineType.BACKEND,
MachineType.PROXY: SpecMachineType.PROXY,
MachineType.SPIDER: SpecMachineType.PROXY,
MachineType.REMOTE: SpecMachineType.BACKEND,
ClusterType.TendisTwemproxyRedisInstance: {
MachineType.TENDISCACHE: SpecMachineType.TendisTwemproxyRedisInstance,
MachineType.TWEMPROXY: SpecMachineType.PROXY,
},
ClusterType.TwemproxyTendisSSDInstance: {
MachineType.TENDISSSD: SpecMachineType.TwemproxyTendisSSDInstance,
MachineType.TWEMPROXY: SpecMachineType.PROXY,
},
ClusterType.TendisPredixyTendisplusCluster: {
MachineType.TENDISPLUS: SpecMachineType.TendisPredixyTendisplusCluster,
MachineType.PREDIXY: SpecMachineType.PROXY,
},
ClusterType.TendisPredixyRedisCluster: {
MachineType.TENDISCACHE: SpecMachineType.TendisTwemproxyRedisInstance,
MachineType.PREDIXY: SpecMachineType.PROXY,
},
ClusterType.TendisRedisInstance: {
MachineType.TENDISCACHE: SpecMachineType.TendisTwemproxyRedisInstance,
},
MachineType.SQLSERVER_HA: SpecMachineType.SQLSERVER,
MachineType.SQLSERVER_SINGLE: SpecMachineType.SQLSERVER,
MachineType.MONGOS: SpecMachineType.MONGOS,
MachineType.MONGODB: SpecMachineType.MONGODB,
MachineType.MONOG_CONFIG: SpecMachineType.MONOG_CONFIG,
}

specs = Spec.objects.all()
with transaction.atomic():
for spec in specs:
db_type = ClusterType.cluster_type_to_db_type(spec.spec_cluster_type)
if db_type in [
DBType.Es,
DBType.Kafka,
DBType.Hdfs,
DBType.InfluxDB,
DBType.Pulsar,
DBType.Vm,
DBType.Doris,
DBType.Riak,
]:
continue

if db_type == DBType.Redis:
spec.spec_machine_type = MIGRATE_SPEC_MACHINE_MAP[spec.spec_cluster_type][spec.spec_machine_type]
spec.spec_cluster_type = db_type
spec.save()
else:
spec.spec_machine_type = MIGRATE_SPEC_MACHINE_MAP[spec.spec_machine_type]
spec.spec_cluster_type = db_type
spec.save()
Loading

0 comments on commit 3ce63ee

Please sign in to comment.