-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): 补充dumper迁移透传 & 直接授权单据 #1827
- Loading branch information
Showing
13 changed files
with
230 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- 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 rest_framework import serializers | ||
|
||
from backend.db_proxy.views.serialiers import BaseProxyPassSerialier | ||
|
||
|
||
class DumperMigrateProxyPassSerializer(BaseProxyPassSerialier): | ||
class DumperSwitchInfoSerializer(serializers.Serializer): | ||
class SwitchInstanceSerializer(serializers.Serializer): | ||
host = serializers.CharField(help_text=_("主机IP")) | ||
port = serializers.IntegerField(help_text=_("主机端口")) | ||
repl_binlog_file = serializers.CharField(help_text=_("待切换后需要同步的binlog文件")) | ||
repl_binlog_pos = serializers.IntegerField(help_text=_("待切换后需要同步的binlog文件的为位点")) | ||
|
||
cluster_domain = serializers.IntegerField(help_text=_("集群域名")) | ||
switch_instances = serializers.ListSerializer(help_text=_("dumper切换信息"), child=SwitchInstanceSerializer()) | ||
|
||
infos = serializers.ListSerializer(child=DumperSwitchInfoSerializer()) | ||
bk_biz_id = serializers.IntegerField(help_text=_("业务ID")) | ||
is_safe = serializers.BooleanField(help_text=_("是否安全切换"), required=False, default=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- 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.decorators import action | ||
from rest_framework.response import Response | ||
|
||
from backend.bk_web.swagger import common_swagger_auto_schema | ||
from backend.components.hadb.client import HADBApi | ||
from backend.db_meta.models import Cluster | ||
from backend.db_proxy.constants import SWAGGER_TAG | ||
from backend.ticket.constants import TicketType | ||
from backend.ticket.models import Ticket | ||
|
||
from ..views import BaseProxyPassViewSet | ||
from .serializers import DumperMigrateProxyPassSerializer | ||
|
||
|
||
class DumperProxyPassViewSet(BaseProxyPassViewSet): | ||
""" | ||
Dumper服务接口的透传视图 | ||
""" | ||
|
||
@common_swagger_auto_schema( | ||
operation_summary=_("[dumper]迁移"), | ||
request_body=DumperMigrateProxyPassSerializer(), | ||
tags=[SWAGGER_TAG], | ||
) | ||
@action( | ||
methods=["POST"], detail=False, serializer_class=DumperMigrateProxyPassSerializer, url_path="dumper/switch" | ||
) | ||
def dumper_switch(self, request): | ||
data = self.params_validate(self.get_serializer_class()) | ||
# 获取集群ID | ||
cluster_domains = [info["cluster_domain"] for info in data["infos"]] | ||
domain__cluster = { | ||
cluster.immute_domain: cluster for cluster in Cluster.objects.filter(immute_domain__in=cluster_domains) | ||
} | ||
for info in data["infos"]: | ||
info["cluster_id"] = domain__cluster[info["cluster_domain"]] | ||
# 创建dumper迁移单据 | ||
Ticket.create_ticket( | ||
ticket_type=TicketType.TBINLOGDUMPER_SWITCH_NODES, | ||
creator=request.user.username, | ||
bk_biz_id=data.pop("bk_biz_id"), | ||
remark=_("透传接口dumper迁移创建的单据"), | ||
details=data, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- 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. | ||
""" | ||
|
||
DUMPER_INSTANCE_LIST_DATA = [ | ||
{ | ||
"id": 1, | ||
"creator": "xxx", | ||
"create_at": "2022-11-11 20:00:00", | ||
"updater": "xxx", | ||
"update_at": "2022-11-11 20:00:00", | ||
"bk_biz_id": 3, | ||
"cluster_id": 64, | ||
"bk_cloud_id": 0, | ||
"ip": "127.0.0.1", | ||
"proc_type": "tbinlogdumper", | ||
"version": "1.0", | ||
"listen_port": 10000, | ||
"need_transfer": True, | ||
"source_cluster": { | ||
"id": 64, | ||
"name": "fortest", | ||
"cluster_type": "tendbha", | ||
"immute_domain": "tendbha57db.xxx.dba.db", | ||
"major_version": "MySQL-5.7", | ||
"bk_cloud_id": 0, | ||
"region": " ", | ||
}, | ||
"dumper_config": { | ||
"id": 1, | ||
"creator": "admin", | ||
"updater": "admin", | ||
"bk_biz_id": 3, | ||
"name": "dumper-1", | ||
"receiver_type": "redis", | ||
"receiver": "redis.com:123", | ||
"subscribe": {"db_name": "db1", "table_names": ["table1"]}, | ||
}, | ||
"dumper_id": 1, | ||
"area_name": 1, | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters