diff --git a/.dockerignore b/.dockerignore index 56500ba7ea..5c142e4a9a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,3 @@ .vscode tmp* -**/mod/ diff --git a/dbm-services/.gitignore b/dbm-services/.gitignore index 89b47fa0b4..020c32205b 100644 --- a/dbm-services/.gitignore +++ b/dbm-services/.gitignore @@ -1,6 +1,3 @@ .codecc .idea .vscode - -pkg/ - diff --git a/dbm-ui/backend/configuration/constants.py b/dbm-ui/backend/configuration/constants.py index 5af7ab448d..9dd10d1137 100644 --- a/dbm-ui/backend/configuration/constants.py +++ b/dbm-ui/backend/configuration/constants.py @@ -47,6 +47,7 @@ class SystemSettingsEnum(str, StructuredEnum): SPEC_OFFSET = EnumField("SPEC_OFFSET", _("默认的规格参数偏移量")) DEVICE_CLASSES = EnumField("DEVICE_CLASSES", _("机型列表")) BKM_DUTY_NOTICE = EnumField("BKM_DUTY_NOTICE", _("轮值通知设置")) + DBM_MIGRATE_USER = EnumField("DBM_MIGRATE_USER", _("具备迁移权限的人员名单")) class BizSettingsEnum(str, StructuredEnum): @@ -116,6 +117,9 @@ class BizSettingsEnum(str, StructuredEnum): }, } +# 默认具备迁移权限的人员 +DBM_DEFAULT_MIGRATE_USER = ["admin"] + DEFAULT_SETTINGS = [ # [key, 类型,初始值, 描述] [SystemSettingsEnum.BKM_DBM_TOKEN.value, "str", "", _("监控数据源token")], @@ -124,6 +128,7 @@ class BizSettingsEnum(str, StructuredEnum): [SystemSettingsEnum.INDEPENDENT_HOSTING_BIZS.value, "list", [], _("独立托管机器的业务列表")], [SystemSettingsEnum.SPEC_OFFSET.value, "dict", SPEC_OFFSET_VALUE, _("默认的规格参数偏移量")], [SystemSettingsEnum.BKM_DUTY_NOTICE.value, "dict", BKM_DUTY_NOTICE_VALUE, _("默认通知配置")], + [SystemSettingsEnum.DBM_MIGRATE_USER, "list", DBM_DEFAULT_MIGRATE_USER, _("具备迁移权限的人员名单")], ] # 环境配置项 是否支持DNS解析 pulsar flow used diff --git a/dbm-ui/backend/db_services/meta_import/views.py b/dbm-ui/backend/db_services/meta_import/views.py index 479bcd0e61..7b312de191 100644 --- a/dbm-ui/backend/db_services/meta_import/views.py +++ b/dbm-ui/backend/db_services/meta_import/views.py @@ -18,6 +18,8 @@ from backend.bk_web import viewsets from backend.bk_web.swagger import common_swagger_auto_schema +from backend.configuration.constants import SystemSettingsEnum +from backend.configuration.models import SystemSettings from backend.db_services.meta_import.constants import SWAGGER_TAG from backend.db_services.meta_import.serializers import MySQLHaMetadataImportSerializer from backend.iam_app.handlers.drf_perm import RejectPermission @@ -31,7 +33,8 @@ class DBMetadataImportViewSet(viewsets.SystemViewSet): pagination_class = None def _get_custom_permissions(self): - if not self.request.user.is_superuser: + migrate_users = SystemSettings.get_setting_value(key=SystemSettingsEnum.DBM_MIGRATE_USER, default=[]) + if not self.request.user.is_superuser and self.request.user.username not in migrate_users: return [RejectPermission()] return [] diff --git a/dbm-ui/backend/dbm_init/medium/Dockerfile b/dbm-ui/backend/dbm_init/medium/Dockerfile index 035fa771b3..16a41edffd 100644 --- a/dbm-ui/backend/dbm_init/medium/Dockerfile +++ b/dbm-ui/backend/dbm_init/medium/Dockerfile @@ -32,8 +32,8 @@ FROM go-mod-builder as redis-medium-builder ## 构建redis介质 RUN set -ex && \ - cd /blueking-dbm/dbm-services/redis/db-tools/dbactuator && make -j4 -# cd /blueking-dbm/dbm-services/redis/db-tools/dbmon/ && sh package.sh TODO: 该命令还有问题 + cd /blueking-dbm/dbm-services/redis/db-tools/dbactuator && make -j4 && \ + cd /blueking-dbm/dbm-services/redis/db-tools/dbmon && sh package.sh FROM go-mod-builder as bigdata-medium-builder diff --git a/dbm-ui/backend/dbm_init/medium/medium.lock b/dbm-ui/backend/dbm_init/medium/medium.lock index bd34ced07e..ec9614b5b5 100644 --- a/dbm-ui/backend/dbm_init/medium/medium.lock +++ b/dbm-ui/backend/dbm_init/medium/medium.lock @@ -65,3 +65,8 @@ redis: commitId: xxx name: dbactuator_redis version: 1.0.1 +- dbmon: + buildPath: /blueking-dbm/dbm-services/redis/db-tools/dbmon/build/bk-dbmon-*.tar.gz + commitId: xxx + name: dbmon + version: 1.0.1 diff --git a/dbm-ui/backend/dbm_init/medium/readme.md b/dbm-ui/backend/dbm_init/medium/readme.md index 21fe7bd92a..caee189f4a 100644 --- a/dbm-ui/backend/dbm_init/medium/readme.md +++ b/dbm-ui/backend/dbm_init/medium/readme.md @@ -1,5 +1,22 @@ # 版本文件初始化镜像 +## medium.lock文件 +lock文件记录了每种db类型打包的介质文件信息,以redis为例: +```yaml +redis: # dbtype +- actuator: + buildPath: /blueking-dbm/dbm-services/redis/db-tools/dbactuator/build/dbactuator_redis # 介质路径 + commitId: xxx # 最新编译代码的commit id,这个一般自动生成 + name: dbactuator_redis # 介质文件名称 + version: 1.0.1 # 介质文件版本 +- dbmon: + buildPath: /blueking-dbm/dbm-services/redis/db-tools/dbmon/build/bk-dbmon-*.tar.gz + commitId: xxx + name: dbmon + version: 1.0.1 +``` +如果我们有新加的打包文件,只需按照上面格式填写即可,commit id可以为xxx,version按照x.y.z格式填写 + ## 打包 在blueking目录下执行 diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/riak/riak_cluster_apply_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/riak/riak_cluster_apply_flow.py index c7fb7d8022..819568c983 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/riak/riak_cluster_apply_flow.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/riak/riak_cluster_apply_flow.py @@ -189,8 +189,8 @@ def _get_riak_config(self): "bk_biz_id": str(self.data["bk_biz_id"]), "level_name": LevelName.CLUSTER, "level_value": self.data["domain"], - "level_info": {"module": LevelInfoEnum.TendataModuleDefault}, - "conf_file": "riak-{}-{}".format(self.data["db_version"], self.data["module_name"]), + "level_info": {"module": "riak-{}-{}".format(self.data["db_version"], self.data["db_module_name"])}, + "conf_file": "riak-{}-{}".format(self.data["db_version"], self.data["db_module_name"]), "conf_type": ConfType.DBCONF, "namespace": NameSpaceEnum.Riak, "format": FormatType.MAP_LEVEL, diff --git a/dbm-ui/backend/flow/urls.py b/dbm-ui/backend/flow/urls.py index 233931213f..3991004a20 100644 --- a/dbm-ui/backend/flow/urls.py +++ b/dbm-ui/backend/flow/urls.py @@ -23,7 +23,6 @@ from backend.flow.views.es_destroy import DestroyEsSceneApiView from backend.flow.views.es_disable import DisableEsSceneApiView from backend.flow.views.es_enable import EnableEsSceneApiView -from backend.flow.views.es_fake_apply import FakeInstallEsSceneApiView from backend.flow.views.es_reboot import RebootEsSceneApiView from backend.flow.views.es_replace import ReplaceEsSceneApiView from backend.flow.views.es_scale_up import ScaleUpEsSceneApiView @@ -32,7 +31,6 @@ from backend.flow.views.hdfs_destroy import DestroyHdfsSceneApiView from backend.flow.views.hdfs_disable import DisableHdfsSceneApiView from backend.flow.views.hdfs_enable import EnableHdfsSceneApiView -from backend.flow.views.hdfs_fake_apply import FakeInstallHdfsSceneApiView from backend.flow.views.hdfs_reboot import RebootHdfsSceneApiView from backend.flow.views.hdfs_replace import ReplaceHdfsSceneApiView from backend.flow.views.hdfs_scale_up import ScaleUpHdfsSceneApiView @@ -43,18 +41,26 @@ from backend.flow.views.influxdb_destroy import DestroyInfluxdbSceneApiView from backend.flow.views.influxdb_disable import DisableInfluxdbSceneApiView from backend.flow.views.influxdb_enable import EnableInfluxdbSceneApiView -from backend.flow.views.influxdb_fake_apply import FakeInstallInfluxdbSceneApiView from backend.flow.views.influxdb_reboot import RebootInfluxdbSceneApiView from backend.flow.views.influxdb_replace import ReplaceInfluxdbSceneApiView from backend.flow.views.kafka_apply import InstallKafkaSceneApiView from backend.flow.views.kafka_destroy import DestroyKafkaSceneApiView from backend.flow.views.kafka_disable import DisableKafkaSceneApiView from backend.flow.views.kafka_enable import EnableKafkaSceneApiView -from backend.flow.views.kafka_fake_apply import FakeInstallKafkaSceneApiView from backend.flow.views.kafka_reboot import RebootKafkaSceneApiView from backend.flow.views.kafka_replace import ReplaceKafkaSceneApiView from backend.flow.views.kafka_scale_up import ScaleUpKafkaSceneApiView from backend.flow.views.kafka_shrink import ShrinkKafkaSceneApiView +from backend.flow.views.migrate_views.es_fake_apply import FakeInstallEsSceneApiView +from backend.flow.views.migrate_views.hdfs_fake_apply import FakeInstallHdfsSceneApiView +from backend.flow.views.migrate_views.influxdb_fake_apply import FakeInstallInfluxdbSceneApiView +from backend.flow.views.migrate_views.kafka_fake_apply import FakeInstallKafkaSceneApiView +from backend.flow.views.migrate_views.pulsar_fake_apply import FakeInstallPulsarSceneApiView +from backend.flow.views.migrate_views.redis_migrate import ( + RedisClusterMigrateCompair, + RedisClusterMigrateLoad, + RedisClusterMigratePrecheck, +) from backend.flow.views.mysql_add_slave import AddMysqlSlaveSceneApiView from backend.flow.views.mysql_add_slave_remote import AddMysqlSlaveRemoteSceneApiView from backend.flow.views.mysql_checksum import MysqlChecksumSceneApiView @@ -104,7 +110,6 @@ from backend.flow.views.pulsar_destroy import DestroyPulsarSceneApiView from backend.flow.views.pulsar_disable import DisablePulsarSceneApiView from backend.flow.views.pulsar_enable import EnablePulsarSceneApiView -from backend.flow.views.pulsar_fake_apply import FakeInstallPulsarSceneApiView from backend.flow.views.pulsar_reboot import RebootPulsarSceneApiView from backend.flow.views.pulsar_scale_up import ScaleUpPulsarSceneApiView from backend.flow.views.redis_cluster import ( @@ -116,9 +121,6 @@ RedisClusterBackupSceneApiView, RedisClusterDataCheckRepairApiView, RedisClusterDataCopySceneApiView, - RedisClusterMigrateCompair, - RedisClusterMigrateLoad, - RedisClusterMigratePrecheck, RedisClusterOpenCloseSceneApiView, RedisClusterShardNumUpdateSceneApiView, RedisClusterShutdownSceneApiView, diff --git a/dbm-ui/backend/flow/utils/riak/riak_db_meta.py b/dbm-ui/backend/flow/utils/riak/riak_db_meta.py index 9bf21a3385..3ffe9dbe7f 100644 --- a/dbm-ui/backend/flow/utils/riak/riak_db_meta.py +++ b/dbm-ui/backend/flow/utils/riak/riak_db_meta.py @@ -14,6 +14,7 @@ from backend.db_meta import api from backend.db_meta.enums import InstanceRole, MachineType +from backend.db_meta.models import Spec from backend.flow.consts import DEFAULT_DB_MODULE_ID, DEFAULT_RIAK_PORT logger = logging.getLogger("flow") @@ -35,8 +36,16 @@ def __init__(self, ticket_data: dict, cluster: dict): def riak_cluster_apply(self) -> bool: ips = self.cluster.nodes + spec_id = self.ticket_data["resource_spec"]["riak"]["spec_id"] + spec_config = Spec.objects.get(spec_id=spec_id).get_spec_info() machines = [ - {"ip": ip, "bk_biz_id": int(self.ticket_data["bk_biz_id"]), "machine_type": MachineType.RIAK.value} + { + "ip": ip, + "bk_biz_id": int(self.ticket_data["bk_biz_id"]), + "machine_type": MachineType.RIAK.value, + "spec_id": spec_id, + "spec_config": spec_config, + } for ip in ips ] instances = [ @@ -48,7 +57,7 @@ def riak_cluster_apply(self) -> bool: "name": self.ticket_data["cluster_name"], "alias": self.ticket_data["cluster_alias"], "immute_domain": self.ticket_data["domain"], - "db_module_id": DEFAULT_DB_MODULE_ID, + "db_module_id": self.ticket_data["db_module_id"], "storages": instances, "creator": self.ticket_data["created_by"], "major_version": self.ticket_data["db_version"], diff --git a/dbm-ui/backend/flow/views/base.py b/dbm-ui/backend/flow/views/base.py index 991093825e..ee4c206547 100644 --- a/dbm-ui/backend/flow/views/base.py +++ b/dbm-ui/backend/flow/views/base.py @@ -18,6 +18,9 @@ from rest_framework.permissions import AllowAny from rest_framework.views import APIView +from backend.configuration.constants import SystemSettingsEnum +from backend.configuration.models import SystemSettings + logger = logging.getLogger("root") @@ -35,3 +38,13 @@ def get_permissions(self): if not self.request.user.is_superuser and not settings.DEBUG: raise PermissionDenied(_("权限不足,无法访问!")) return [] + + +class MigrateFlowView(FlowTestView): + """迁移流程的view视图""" + + def get_permissions(self): + migrate_users = SystemSettings.get_setting_value(key=SystemSettingsEnum.DBM_MIGRATE_USER, default=[]) + if self.request.user.username in migrate_users: + return [] + return super().get_permissions() diff --git a/dbm-ui/backend/flow/views/es_fake_apply.py b/dbm-ui/backend/flow/views/migrate_views/es_fake_apply.py similarity index 95% rename from dbm-ui/backend/flow/views/es_fake_apply.py rename to dbm-ui/backend/flow/views/migrate_views/es_fake_apply.py index 041e2bc11a..b74376571c 100644 --- a/dbm-ui/backend/flow/views/es_fake_apply.py +++ b/dbm-ui/backend/flow/views/migrate_views/es_fake_apply.py @@ -15,12 +15,12 @@ from rest_framework.response import Response from backend.flow.engine.controller.es import EsController -from backend.flow.views.base import FlowTestView +from backend.flow.views.base import FlowTestView, MigrateFlowView logger = logging.getLogger("root") -class FakeInstallEsSceneApiView(FlowTestView): +class FakeInstallEsSceneApiView(MigrateFlowView): """ api: /apis/v1/flow/scene/fake_install_es params: diff --git a/dbm-ui/backend/flow/views/hdfs_fake_apply.py b/dbm-ui/backend/flow/views/migrate_views/hdfs_fake_apply.py similarity index 95% rename from dbm-ui/backend/flow/views/hdfs_fake_apply.py rename to dbm-ui/backend/flow/views/migrate_views/hdfs_fake_apply.py index c4011a57a4..46908698ed 100644 --- a/dbm-ui/backend/flow/views/hdfs_fake_apply.py +++ b/dbm-ui/backend/flow/views/migrate_views/hdfs_fake_apply.py @@ -15,12 +15,12 @@ from rest_framework.response import Response from backend.flow.engine.controller.hdfs import HdfsController -from backend.flow.views.base import FlowTestView +from backend.flow.views.base import FlowTestView, MigrateFlowView logger = logging.getLogger("root") -class FakeInstallHdfsSceneApiView(FlowTestView): +class FakeInstallHdfsSceneApiView(MigrateFlowView): """ api: /apis/v1/flow/scene/fake_install_hdfs params: diff --git a/dbm-ui/backend/flow/views/influxdb_fake_apply.py b/dbm-ui/backend/flow/views/migrate_views/influxdb_fake_apply.py similarity index 94% rename from dbm-ui/backend/flow/views/influxdb_fake_apply.py rename to dbm-ui/backend/flow/views/migrate_views/influxdb_fake_apply.py index 328a8872a6..cf0b7fb73c 100644 --- a/dbm-ui/backend/flow/views/influxdb_fake_apply.py +++ b/dbm-ui/backend/flow/views/migrate_views/influxdb_fake_apply.py @@ -15,12 +15,12 @@ from rest_framework.response import Response from backend.flow.engine.controller.influxdb import InfluxdbController -from backend.flow.views.base import FlowTestView +from backend.flow.views.base import FlowTestView, MigrateFlowView logger = logging.getLogger("root") -class FakeInstallInfluxdbSceneApiView(FlowTestView): +class FakeInstallInfluxdbSceneApiView(MigrateFlowView): """ api: /apis/v1/flow/scene/fake_install_influxdb params: diff --git a/dbm-ui/backend/flow/views/kafka_fake_apply.py b/dbm-ui/backend/flow/views/migrate_views/kafka_fake_apply.py similarity index 95% rename from dbm-ui/backend/flow/views/kafka_fake_apply.py rename to dbm-ui/backend/flow/views/migrate_views/kafka_fake_apply.py index 7cf894b66d..3b900303d6 100644 --- a/dbm-ui/backend/flow/views/kafka_fake_apply.py +++ b/dbm-ui/backend/flow/views/migrate_views/kafka_fake_apply.py @@ -15,12 +15,12 @@ from rest_framework.response import Response from backend.flow.engine.controller.kafka import KafkaController -from backend.flow.views.base import FlowTestView +from backend.flow.views.base import FlowTestView, MigrateFlowView logger = logging.getLogger("root") -class FakeInstallKafkaSceneApiView(FlowTestView): +class FakeInstallKafkaSceneApiView(MigrateFlowView): """ api: /apis/v1/flow/scene/fake_install_kafka params: diff --git a/dbm-ui/backend/flow/views/pulsar_fake_apply.py b/dbm-ui/backend/flow/views/migrate_views/pulsar_fake_apply.py similarity index 96% rename from dbm-ui/backend/flow/views/pulsar_fake_apply.py rename to dbm-ui/backend/flow/views/migrate_views/pulsar_fake_apply.py index 7c1d5925ce..21b9658dc0 100644 --- a/dbm-ui/backend/flow/views/pulsar_fake_apply.py +++ b/dbm-ui/backend/flow/views/migrate_views/pulsar_fake_apply.py @@ -14,12 +14,12 @@ from rest_framework.response import Response from backend.flow.engine.controller.pulsar import PulsarController -from backend.flow.views.base import FlowTestView +from backend.flow.views.base import FlowTestView, MigrateFlowView logger = logging.getLogger("root") -class FakeInstallPulsarSceneApiView(FlowTestView): +class FakeInstallPulsarSceneApiView(MigrateFlowView): """ api: /apis/v1/flow/scene/fake_install_pulsar params: diff --git a/dbm-ui/backend/flow/views/migrate_views/redis_migrate.py b/dbm-ui/backend/flow/views/migrate_views/redis_migrate.py new file mode 100644 index 0000000000..5940d684ca --- /dev/null +++ b/dbm-ui/backend/flow/views/migrate_views/redis_migrate.py @@ -0,0 +1,55 @@ +# -*- 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. +""" +import logging +import uuid + +from rest_framework.response import Response + +from backend.flow.engine.controller.redis import RedisController +from backend.flow.views.base import MigrateFlowView + +logger = logging.getLogger("root") + + +class RedisClusterMigratePrecheck(MigrateFlowView): + """ + 集群迁移前置检查 + """ + + @staticmethod + def post(request): + root_id = uuid.uuid1().hex + RedisController(root_id=root_id, ticket_data=request.data).redis_cluster_migrate_precheck() + return Response({"root_id": root_id}) + + +class RedisClusterMigrateLoad(MigrateFlowView): + """ + 集群迁移 + """ + + @staticmethod + def post(request): + root_id = uuid.uuid1().hex + RedisController(root_id=root_id, ticket_data=request.data).redis_cluster_migrate_load() + return Response({"root_id": root_id}) + + +class RedisClusterMigrateCompair(MigrateFlowView): + """ + 集群迁移数据对比 + """ + + @staticmethod + def post(request): + root_id = uuid.uuid1().hex + RedisController(root_id=root_id, ticket_data=request.data).redis_cluster_migrate_compair() + return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/redis_cluster.py b/dbm-ui/backend/flow/views/redis_cluster.py index d2eaa112f3..958b1c4c1f 100644 --- a/dbm-ui/backend/flow/views/redis_cluster.py +++ b/dbm-ui/backend/flow/views/redis_cluster.py @@ -564,39 +564,3 @@ def post(request): root_id = uuid.uuid1().hex RedisController(root_id=root_id, ticket_data=request.data).redis_cluster_version_update_online() return Response({"root_id": root_id}) - - -class RedisClusterMigratePrecheck(FlowTestView): - """ - 集群迁移前置检查 - """ - - @staticmethod - def post(request): - root_id = uuid.uuid1().hex - RedisController(root_id=root_id, ticket_data=request.data).redis_cluster_migrate_precheck() - return Response({"root_id": root_id}) - - -class RedisClusterMigrateLoad(FlowTestView): - """ - 集群迁移 - """ - - @staticmethod - def post(request): - root_id = uuid.uuid1().hex - RedisController(root_id=root_id, ticket_data=request.data).redis_cluster_migrate_load() - return Response({"root_id": root_id}) - - -class RedisClusterMigrateCompair(FlowTestView): - """ - 集群迁移数据对比 - """ - - @staticmethod - def post(request): - root_id = uuid.uuid1().hex - RedisController(root_id=root_id, ticket_data=request.data).redis_cluster_migrate_compair() - return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/ticket/builders/riak/base.py b/dbm-ui/backend/ticket/builders/riak/base.py new file mode 100644 index 0000000000..50d0c24ec2 --- /dev/null +++ b/dbm-ui/backend/ticket/builders/riak/base.py @@ -0,0 +1,17 @@ +# -*- 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 backend.configuration.constants import DBType +from backend.ticket.builders import TicketFlowBuilder + + +class BaseRiakTicketFlowBuilder(TicketFlowBuilder): + group = DBType.Riak.value diff --git a/dbm-ui/backend/ticket/builders/riak/riak_apply.py b/dbm-ui/backend/ticket/builders/riak/riak_apply.py new file mode 100644 index 0000000000..5e94592614 --- /dev/null +++ b/dbm-ui/backend/ticket/builders/riak/riak_apply.py @@ -0,0 +1,102 @@ +# -*- 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 ugettext_lazy as _ +from rest_framework import serializers + +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.riak.base import BaseRiakTicketFlowBuilder +from backend.ticket.constants import TicketType + + +class RiakApplyDetailSerializer(serializers.Serializer): + bk_cloud_id = serializers.IntegerField(help_text=_("云区域ID")) + db_app_abbr = serializers.CharField(help_text=_("业务英文缩写")) + cluster_name = serializers.CharField(help_text=_("集群名")) + cluster_alias = serializers.CharField(help_text=_("集群别名")) + city_code = serializers.CharField( + help_text=_("城市代码"), required=False, allow_blank=True, allow_null=True, default="" + ) + db_module_id = serializers.IntegerField(help_text=_("DB模块ID")) + ip_source = serializers.ChoiceField( + help_text=_("主机来源"), choices=IpSource.get_choices(), default=IpSource.RESOURCE_POOL.value + ) + db_version = serializers.CharField(help_text=_("riak数据库版本")) + resource_spec = serializers.JSONField(help_text=_("部署规格")) + + # display fields + bk_cloud_name = serializers.SerializerMethodField(help_text=_("云区域")) + db_module_name = serializers.SerializerMethodField(help_text=_("DB模块名")) + city_name = serializers.SerializerMethodField(help_text=_("城市名")) + + def get_bk_cloud_name(self, obj): + clouds = ResourceQueryHelper.search_cc_cloud(get_cache=True) + return clouds[str(obj["bk_cloud_id"])]["bk_cloud_name"] + + def get_db_module_name(self, obj): + db_module_id = obj["db_module_id"] + return self.context["ticket_ctx"].db_module_map.get(db_module_id) or f"db-module-{db_module_id}" + + def get_city_name(self, obj): + city_code = obj["city_code"] + return self.context["ticket_ctx"].city_map.get(city_code, city_code) + + def validate(self, attrs): + # 校验集群名是否重复 + CommonValidate.validate_duplicate_cluster_name( + self.context["bk_biz_id"], self.context["ticket_type"], attrs["cluster_name"] + ) + return attrs + + +class RiakApplyFlowParamBuilder(builders.FlowParamBuilder): + controller = RiakController.riak_cluster_apply_scene + + def format_ticket_data(self): + pass + + +class RiakApplyResourceParamBuilder(builders.ResourceApplyParamBuilder): + def post_callback(self): + next_flow = self.ticket.next_flow() + riak_nodes = next_flow.details["ticket_data"].pop("nodes")["riak"] + next_flow.details["ticket_data"].update(nodes=riak_nodes) + next_flow.save(update_fields=["details"]) + + +@builders.BuilderFactory.register(TicketType.RIAK_CLUSTER_APPLY, is_apply=True, cluster_type=ClusterType.Riak) +class RiakApplyFlowBuilder(BaseRiakTicketFlowBuilder): + serializer = RiakApplyDetailSerializer + inner_flow_builder = RiakApplyFlowParamBuilder + inner_flow_name = _("Riak 集群部署执行") + resource_apply_builder = RiakApplyResourceParamBuilder + + def patch_ticket_detail(self): + details = self.ticket.details + db_module_name = DBModule.objects.get(db_module_id=details["db_module_id"]).db_module_name + riak_cluster_name = riak_domain = f"{details['cluster_name']}.{db_module_name}" + + # TODO: 可能需要补充version等信息 + details.update( + db_module_name=db_module_name, + cluster_name=riak_cluster_name, + domain=riak_domain, + ) + self.ticket.save(update_fields=["details"]) + + @property + def need_itsm(self): + return True diff --git a/dbm-ui/backend/ticket/builders/riak/riak_destroy.py b/dbm-ui/backend/ticket/builders/riak/riak_destroy.py new file mode 100644 index 0000000000..7ec8a6330f --- /dev/null +++ b/dbm-ui/backend/ticket/builders/riak/riak_destroy.py @@ -0,0 +1,43 @@ +# -*- 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. +""" + +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 +from backend.flow.engine.controller.riak import RiakController +from backend.ticket import builders +from backend.ticket.builders.riak.base import BaseRiakTicketFlowBuilder +from backend.ticket.constants import TicketType + +logger = logging.getLogger("root") + + +class RiakDestroyDetailSerializer(serializers.Serializer): + cluster_id = serializers.Serializer(help_text=_("集群ID")) + + +class RiakDestroyFlowParamBuilder(builders.FlowParamBuilder): + controller = RiakController.riak_cluster_destroy_scene + + def format_ticket_data(self): + cluster = Cluster.objects.get(id=self.ticket_data["cluster_id"]) + self.ticket_data["bk_cloud_id"] = cluster.bk_cloud_id + + +@builders.BuilderFactory.register(TicketType.RIAK_CLUSTER_DESTROY, phase=ClusterPhase.DESTROY) +class RiakDestroyFlowBuilder(BaseRiakTicketFlowBuilder): + serializer = RiakDestroyDetailSerializer + inner_flow_builder = RiakDestroyFlowParamBuilder + inner_flow_name = _("Riak 集群销毁") diff --git a/dbm-ui/backend/ticket/builders/riak/riak_disable.py b/dbm-ui/backend/ticket/builders/riak/riak_disable.py new file mode 100644 index 0000000000..9d6554e79e --- /dev/null +++ b/dbm-ui/backend/ticket/builders/riak/riak_disable.py @@ -0,0 +1,43 @@ +# -*- 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. +""" + +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 +from backend.flow.engine.controller.riak import RiakController +from backend.ticket import builders +from backend.ticket.builders.riak.base import BaseRiakTicketFlowBuilder +from backend.ticket.constants import TicketType + +logger = logging.getLogger("root") + + +class RiakDisableDetailSerializer(serializers.Serializer): + cluster_id = serializers.Serializer(help_text=_("集群ID")) + + +class RiakDisableFlowParamBuilder(builders.FlowParamBuilder): + controller = RiakController.riak_cluster_disable_scene + + def format_ticket_data(self): + cluster = Cluster.objects.get(id=self.ticket_data["cluster_id"]) + self.ticket_data["bk_cloud_id"] = cluster.bk_cloud_id + + +@builders.BuilderFactory.register(TicketType.RIAK_CLUSTER_DISABLE, phase=ClusterPhase.OFFLINE) +class RiakEnableFlowBuilder(BaseRiakTicketFlowBuilder): + serializer = RiakDisableDetailSerializer + inner_flow_builder = RiakDisableFlowParamBuilder + inner_flow_name = _("Riak 集群禁用") diff --git a/dbm-ui/backend/ticket/builders/riak/riak_enable.py b/dbm-ui/backend/ticket/builders/riak/riak_enable.py new file mode 100644 index 0000000000..3c9b76d3d1 --- /dev/null +++ b/dbm-ui/backend/ticket/builders/riak/riak_enable.py @@ -0,0 +1,43 @@ +# -*- 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. +""" + +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 +from backend.flow.engine.controller.riak import RiakController +from backend.ticket import builders +from backend.ticket.builders.riak.base import BaseRiakTicketFlowBuilder +from backend.ticket.constants import TicketType + +logger = logging.getLogger("root") + + +class RiakEnableDetailSerializer(serializers.Serializer): + cluster_id = serializers.Serializer(help_text=_("集群ID")) + + +class RiakEnableFlowParamBuilder(builders.FlowParamBuilder): + controller = RiakController.riak_cluster_enable_scene + + def format_ticket_data(self): + cluster = Cluster.objects.get(id=self.ticket_data["cluster_id"]) + self.ticket_data["bk_cloud_id"] = cluster.bk_cloud_id + + +@builders.BuilderFactory.register(TicketType.RIAK_CLUSTER_ENABLE, phase=ClusterPhase.ONLINE) +class RiakEnableFlowBuilder(BaseRiakTicketFlowBuilder): + serializer = RiakEnableDetailSerializer + inner_flow_builder = RiakEnableFlowParamBuilder + inner_flow_name = _("Riak 集群启用") diff --git a/dbm-ui/backend/ticket/builders/riak/riak_scale_up.py b/dbm-ui/backend/ticket/builders/riak/riak_scale_up.py new file mode 100644 index 0000000000..b3c6d98217 --- /dev/null +++ b/dbm-ui/backend/ticket/builders/riak/riak_scale_up.py @@ -0,0 +1,57 @@ +# -*- 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. +""" + +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 +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 BaseKafkaTicketFlowBuilder +from backend.ticket.builders.riak.base import BaseRiakTicketFlowBuilder +from backend.ticket.constants import TicketType + +logger = logging.getLogger("root") + + +class RiakScaleUpDetailSerializer(serializers.Serializer): + cluster_id = serializers.Serializer(help_text=_("集群ID")) + ip_source = serializers.ChoiceField(help_text=_("主机来源"), choices=IpSource.get_choices()) + resource_spec = serializers.JSONField(help_text=_("资源池规格"), required=False) + + +class RiakScaleUpFlowParamBuilder(builders.FlowParamBuilder): + controller = RiakController.riak_cluster_scale_out_scene + + def format_ticket_data(self): + # TODO: 补充db version + cluster = Cluster.objects.get(id=self.ticket_data["cluster_id"]) + self.ticket_data["bk_cloud_id"] = cluster.bk_cloud_id + + +class RiakScaleUpResourceParamBuilder(builders.ResourceApplyParamBuilder): + def post_callback(self): + next_flow = self.ticket.next_flow() + riak_nodes = next_flow.details["ticket_data"].pop("nodes")["riak"] + next_flow.details["ticket_data"].update(nodes=riak_nodes) + next_flow.save(update_fields=["details"]) + + +@builders.BuilderFactory.register(TicketType.RIAK_CLUSTER_SCALE_OUT, is_apply=True) +class RiakScaleUpFlowBuilder(BaseRiakTicketFlowBuilder): + serializer = RiakScaleUpDetailSerializer + resource_apply_builder = RiakScaleUpResourceParamBuilder + inner_flow_builder = RiakScaleUpFlowParamBuilder + inner_flow_name = _("Riak 集群扩容") diff --git a/dbm-ui/backend/ticket/builders/riak/riak_shrink.py b/dbm-ui/backend/ticket/builders/riak/riak_shrink.py new file mode 100644 index 0000000000..6cd1b95f95 --- /dev/null +++ b/dbm-ui/backend/ticket/builders/riak/riak_shrink.py @@ -0,0 +1,45 @@ +# -*- 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. +""" + +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 +from backend.flow.engine.controller.riak import RiakController +from backend.ticket import builders +from backend.ticket.builders.common.base import HostInfoSerializer +from backend.ticket.builders.riak.base import BaseRiakTicketFlowBuilder +from backend.ticket.constants import TicketType + +logger = logging.getLogger("root") + + +class RiakShrinkDetailSerializer(serializers.Serializer): + cluster_id = serializers.Serializer(help_text=_("集群ID")) + nodes = serializers.ListSerializer(help_text=_("缩容节点"), child=HostInfoSerializer()) + + +class RiakShrinkFlowParamBuilder(builders.FlowParamBuilder): + controller = RiakController.riak_cluster_scale_in_scene + + def format_ticket_data(self): + cluster = Cluster.objects.get(id=self.ticket_data["cluster_id"]) + self.ticket_data["bk_cloud_id"] = cluster.bk_cloud_id + + +@builders.BuilderFactory.register(TicketType.RIAK_CLUSTER_DISABLE, phase=ClusterPhase.OFFLINE) +class RiakShrinkFlowBuilder(BaseRiakTicketFlowBuilder): + serializer = RiakShrinkDetailSerializer + inner_flow_builder = RiakShrinkFlowParamBuilder + inner_flow_name = _("Riak 集群缩容")