From a3cbd7d90303a2f97c649cc299f996b0e498b9e9 Mon Sep 17 00:00:00 2001 From: yuanruji Date: Mon, 16 Dec 2024 15:32:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E8=BF=81=E7=A7=BB=E9=9B=86?= =?UTF-8?q?=E7=BE=A4=E5=88=B0=E5=85=B6=E4=BB=96=E4=B8=9A=E5=8A=A1=E6=97=B6?= =?UTF-8?q?=E5=80=99=EF=BC=8C=E6=A3=80=E6=9F=A5=E5=BE=85=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E7=9A=84=E9=9B=86=E7=BE=A4=E7=9A=84=E6=89=80=E6=9C=89=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E5=BF=85=E9=A1=BB=E5=88=86=E5=B8=83=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E4=B8=9A=E5=8A=A1=E4=B8=8B=20#8636?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/transfer_cluster_to_other_biz.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/common/transfer_cluster_to_other_biz.py b/dbm-ui/backend/flow/engine/bamboo/scene/common/transfer_cluster_to_other_biz.py index 1cd11cc7cf..749dba368f 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/common/transfer_cluster_to_other_biz.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/common/transfer_cluster_to_other_biz.py @@ -9,7 +9,7 @@ specific language governing permissions and limitations under the License. """ -from typing import Dict, Optional +from typing import Dict, List, Optional, Set from django.utils.translation import ugettext as _ @@ -26,6 +26,24 @@ ) +def find_other_relation_domains(immute_domains: List[str]) -> List[str]: + qs_cluster = Cluster.objects.filter(immute_domain__in=immute_domains) + fetch_cluster_ids: Set[int] = set() + for c in qs_cluster.all(): + for s in c.storageinstance_set.all(): + fetch_cluster_ids |= set(list(s.machine.storageinstance_set.values_list("cluster", flat=True))) + + for p in c.proxyinstance_set.all(): + fetch_cluster_ids |= set(list(p.machine.proxyinstance_set.values_list("cluster", flat=True))) + + input_cluster_ids = list(qs_cluster.values_list("id", flat=True)) + if input_cluster_ids != list(fetch_cluster_ids): + res = [] + for cluster_id in list(fetch_cluster_ids.difference(set(input_cluster_ids))): + res.append(Cluster.objects.get(id=cluster_id).immute_domain) + return res + + class TransferMySQLClusterToOtherBizFlow(object): """ 将MySQL集群转移到其他业务 @@ -41,7 +59,9 @@ def __init__(self, root_id: str, data: Optional[Dict]) -> None: self.need_clone_priv_rules = data.get("need_clone_priv_rules") def transfer_to_other_biz_flow(self): - + other_domains = find_other_relation_domains(self.cluster_domain_list) + if len(other_domains) > 0: + raise Exception(_("以下域名与当前业务存在关联,请先处理关联关系:{}".format(other_domains))) clusters = Cluster.objects.filter(bk_biz_id=self.bk_biz_id, immute_domain__in=self.cluster_domain_list).all() bk_cloud_ids = [] source_bk_biz_ids = [] @@ -63,10 +83,8 @@ def transfer_to_other_biz_flow(self): raise Exception(_("迁移的集群必须在同一个云区域")) if len(uniq_source_bk_biz_ids) != 1: raise Exception(_("迁移的集群必须在同一个业务")) - bk_cloud_id = uniq_bk_cloud_ids[0] source_bk_biz_id = uniq_source_bk_biz_ids[0] - p = Builder(root_id=self.root_id, data=self.data) if self.need_clone_priv_rules: