Skip to content

Commit

Permalink
fix: 修复未写入db_module_id TencentBlueKing#7186
Browse files Browse the repository at this point in the history
fix: 修复未写入db_module_id TencentBlueKing#7186
  • Loading branch information
zfrendo committed Sep 30, 2024
1 parent 85fea48 commit be06271
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -65,6 +67,7 @@ def storage_create(
},
)
if slave_ip is not None:
machine_ips.append(slave_ip)
machines.append(
{
"ip": slave_ip,
Expand All @@ -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
)
Expand Down
11 changes: 10 additions & 1 deletion dbm-ui/backend/flow/utils/mysql/mysql_db_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
InstanceStatus,
MachineType,
)
from backend.db_meta.models import Cluster, ProxyInstance, StorageInstance, StorageInstanceTuple
from backend.db_meta.models import Cluster, Machine, ProxyInstance, StorageInstance, StorageInstanceTuple
from backend.db_meta.models.extra_process import ExtraProcessInstance
from backend.db_package.models import Package
from backend.db_services.mysql.dumper.models import DumperSubscribeConfig
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -846,6 +850,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"],
Expand Down

0 comments on commit be06271

Please sign in to comment.