Skip to content

Commit

Permalink
feat(backend): standby slaves upgrade subflow TencentBlueKing#6804
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Sep 27, 2024
1 parent 737ea5b commit a10f954
Show file tree
Hide file tree
Showing 14 changed files with 758 additions and 54 deletions.
15 changes: 15 additions & 0 deletions dbm-ui/backend/db_services/mysql/toolbox/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ class TendbhaTransferToOtherBizFlowBuilder(BaseTendbTicketFlowBuilder):
inner_flow_builder = TendbhaTransferToOtherBizFlowParamBuilder
inner_flow_name = _("TenDBHa集群迁移到其他业务")
retry_type = FlowRetryType.MANUAL_RETRY


class TendbhaAddSlaveDomainSerializer(serializers.Serializer):
cluster_id = serializers.IntegerField(help_text=_("集群id"))
slave_ip = serializers.CharField(help_text=_("slave ip"))
slave_port = serializers.IntegerField(help_text=_("slave port"))
domain_name = serializers.CharField(help_text=_("slave domain"))

class Meta:
swagger_schema_fields = {
"bk_biz_id": 11,
"slave_ip": "1.1.1.1",
"slave_port": 3306,
"domain_name": "",
}
7 changes: 6 additions & 1 deletion dbm-ui/backend/db_services/mysql/toolbox/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@

from rest_framework.routers import DefaultRouter

from backend.db_services.mysql.toolbox.views import TendbhaTransferToOtherBizViewSet, ToolboxViewSet
from backend.db_services.mysql.toolbox.views import (
TendbHaSlaveInstanceAddDomainSet,
TendbhaTransferToOtherBizViewSet,
ToolboxViewSet,
)

router = DefaultRouter(trailing_slash=True)
router.register(r"toolbox", ToolboxViewSet, basename="toolbox")
router.register(r"toolbox", TendbhaTransferToOtherBizViewSet, basename="toolbox")
router.register(r"toolbox", TendbHaSlaveInstanceAddDomainSet, basename="toolbox")

urlpatterns = []
urlpatterns += router.urls
45 changes: 43 additions & 2 deletions dbm-ui/backend/db_services/mysql/toolbox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
specific language governing permissions and limitations under the License.
"""
import logging
import traceback
from typing import Any

from django.utils.translation import ugettext_lazy as _
Expand All @@ -19,13 +20,15 @@
from backend.bk_web.swagger import common_swagger_auto_schema
from backend.components import DBConfigApi
from backend.components.dbconfig.constants import FormatType, LevelName
from backend.db_meta.enums import ClusterType
from backend.db_meta.models import Cluster, DBModule
from backend.db_meta.enums import ClusterEntryRole, ClusterEntryType, ClusterType, InstanceInnerRole
from backend.db_meta.models import Cluster, ClusterEntry, DBModule
from backend.db_services.mysql.toolbox.handlers import ToolboxHandler
from backend.db_services.mysql.toolbox.serializers import (
QueryPkgListByCompareVersionSerializer,
TendbhaAddSlaveDomainSerializer,
TendbhaTransferToOtherBizSerializer,
)
from backend.flow.utils.dns_manage import DnsManage
from backend.iam_app.handlers.drf_perm.base import DBManagePermission
from backend.ticket.constants import TicketType
from backend.ticket.models import Ticket
Expand All @@ -52,6 +55,44 @@ def query_higher_version_pkg_list(self, request, **kwargs):
return Response(ToolboxHandler().query_higher_version_pkg_list(cluster_id, higher_major_version))


class TendbHaSlaveInstanceAddDomainSet(viewsets.SystemViewSet):
action_permission_map = {}
default_permission_class = [DBManagePermission()]

@common_swagger_auto_schema(
operation_summary=_("给从库添加域名"),
request_body=TendbhaAddSlaveDomainSerializer(),
tags=[SWAGGER_TAG],
)
@action(methods=["POST"], detail=False, serializer_class=TendbhaAddSlaveDomainSerializer)
def slave_ins_add_domain(self, request, **kwargs):
data = self.params_validate(self.get_serializer_class())
cluster_id = data["cluster_id"]
domain = data["domain_name"]
slave_ip = data["slave_ip"]
slave_port = data["slave_port"]
if ClusterEntry.objects.filter(cluster_entry_type=ClusterEntryType.DNS.value, entry=domain).exists():
return Response({"result": False, "message": _("{}域名已经存在".format(domain))})
cluster_obj = Cluster.objects.get(id=cluster_id)
cluster_entry = ClusterEntry.objects.create(
cluster=cluster_obj,
cluster_entry_type=ClusterEntryType.DNS.value,
entry=domain,
role=ClusterEntryRole.SLAVE_ENTRY.value,
)
dns_manage = DnsManage(bk_biz_id=cluster_obj.bk_biz_id, bk_cloud_id=cluster_obj.bk_cloud_id)
slave_ins = cluster_obj.storageinstance_set.filter(
instance_inner_role=InstanceInnerRole.SLAVE.value, machine__ip=slave_ip, port=slave_port
)
cluster_entry.storageinstance_set.add(*slave_ins)
try:
dns_manage.create_domain(instance_list=["{}#{}".format(slave_ip, str(slave_port))], add_domain_name=domain)
except Exception as e:
logger.error(traceback.format_exc())
return Response({"result": False, "message": _("添加dns记录失败{}".format(e))})
return Response({"result": True, "message": _("success")})


class TendbhaTransferToOtherBizViewSet(viewsets.SystemViewSet):
action_permission_map = {}
default_permission_class = [DBManagePermission()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ def install_mysql_in_cluster_sub_flow(
# 阶段3 并发安装mysql实例(一个活动节点部署多实例)
acts_list = []
if db_config is not None:
exec_act_kwargs.cluster["pkg_id"] = pkg_id
exec_act_kwargs.cluster["old_instance_configs"] = db_config
logger.debug("instance dbconfig", db_config)
for mysql_ip in new_mysql_list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def migrate_cluster_flow(self, use_for_upgrade=False):
uninstall_svr_sub_pipeline_list.append(
uninstall_svr_sub_pipeline.build_sub_process(sub_name=_("卸载remote节点{}".format(ip)))
)

# 安装实例
tendb_migrate_pipeline.add_parallel_sub_pipeline(sub_flow_list=install_sub_pipeline_list)
# 同步配置
Expand Down
Loading

0 comments on commit a10f954

Please sign in to comment.