From c4ef52ba6782cd2e1196c1795d93ac63e19a44db Mon Sep 17 00:00:00 2001 From: zfrendo <842557664@qq.com> Date: Sun, 29 Sep 2024 16:08:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=AA=E5=86=99?= =?UTF-8?q?=E5=85=A5db=5Fmodule=5Fid=20#7186?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/cluster/tendbcluster/remotedb_node_migrate.py | 7 ++++++- dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dbm-ui/backend/db_meta/api/cluster/tendbcluster/remotedb_node_migrate.py b/dbm-ui/backend/db_meta/api/cluster/tendbcluster/remotedb_node_migrate.py index 54d76dc451..a7d1c524f2 100644 --- a/dbm-ui/backend/db_meta/api/cluster/tendbcluster/remotedb_node_migrate.py +++ b/dbm-ui/backend/db_meta/api/cluster/tendbcluster/remotedb_node_migrate.py @@ -14,7 +14,7 @@ from backend.db_meta import api, request_validator from backend.db_meta.api import common from backend.db_meta.enums import ClusterType, InstanceRole, InstanceStatus, MachineType -from backend.db_meta.models import Cluster, StorageInstance, StorageInstanceTuple, TenDBClusterStorageSet +from backend.db_meta.models import Cluster, Machine, StorageInstance, StorageInstanceTuple, TenDBClusterStorageSet from backend.db_package.models import Package from backend.flow.consts import MediumEnum from backend.flow.engine.bamboo.scene.common.get_real_version import get_mysql_real_version @@ -44,7 +44,9 @@ def storage_create( mysql_pkg = Package.get_latest_package(version=mysql_version, pkg_type=MediumEnum.MySQL, db_type=DBType.MySQL) machines = [] storages = [] + machine_ips = [] if master_ip is not None: + machine_ips.append(master_ip) machines.append( { "ip": master_ip, @@ -65,6 +67,7 @@ def storage_create( }, ) if slave_ip is not None: + machine_ips.append(slave_ip) machines.append( { "ip": slave_ip, @@ -86,6 +89,8 @@ def storage_create( ) api.machine.create(machines=machines, creator=creator, bk_cloud_id=bk_cloud_id) + machine_objs = Machine.objects.filter(bk_cloud_id=bk_cloud_id, ip__in=machine_ips) + machine_objs.update(db_module_id=cluster.db_module_id) api.storage_instance.create( instances=storages, creator=creator, time_zone=time_zone, status=InstanceStatus.RESTORING ) diff --git a/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py b/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py index 27fe96ad1d..e8ae300f37 100644 --- a/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py +++ b/dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py @@ -728,6 +728,10 @@ def slave_recover_add_instance(self): bk_cloud_id=int(self.ticket_data["bk_cloud_id"]), creator=self.ticket_data["created_by"], ) + machine_objs = Machine.objects.filter( + bk_cloud_id=self.ticket_data["bk_cloud_id"], ip=self.cluster["install_ip"] + ) + machine_objs.update(db_module_id=self.ticket_data["db_module_id"]) storage_objs = api.storage_instance.create( instances=storage_instances, creator=self.ticket_data["created_by"], @@ -939,6 +943,11 @@ def migrate_cluster_add_instance(self): api.machine.create( bk_cloud_id=self.ticket_data["bk_cloud_id"], machines=machines, creator=self.ticket_data["created_by"] ) + machines_objs = Machine.objects.filter( + bk_cloud_id=self.ticket_data["bk_cloud_id"], + ip__in=[self.cluster["new_slave_ip"], self.cluster["new_master_ip"]], + ) + machines_objs.update(db_module_id=self.ticket_data["db_module_id"]) storage_objs = api.storage_instance.create( instances=storage_instances, creator=self.ticket_data["created_by"],