From c8b364fec95f103be206e6f33ff02c10a6b75814 Mon Sep 17 00:00:00 2001 From: durant <826035498@qq.com> Date: Tue, 14 Nov 2023 20:16:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E8=BD=AC=E7=A7=BB=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=85=BC=E5=AE=B9=E5=B7=B2=E8=BD=AC=E7=A7=BB=E7=9A=84?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=20#1786?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/components/cc/client.py | 4 ++++ dbm-ui/backend/flow/utils/cc_manage.py | 25 ++++++++++++++++++++---- helm-charts/bk-dbm/Chart.yaml | 4 ++-- helm-charts/bk-dbm/charts/dbm/Chart.yaml | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/dbm-ui/backend/components/cc/client.py b/dbm-ui/backend/components/cc/client.py index a3df39e272..322eff2c5c 100644 --- a/dbm-ui/backend/components/cc/client.py +++ b/dbm-ui/backend/components/cc/client.py @@ -18,6 +18,10 @@ class _CCApi(object): MODULE = _("配置平台") + class ErrorCode: + HOST_NOT_BELONG_BIZ = 1113002 + HOST_NOT_BELONG_MODULE = 1110056 + def __init__(self): self.list_hosts_without_biz = DataAPI( method="POST", diff --git a/dbm-ui/backend/flow/utils/cc_manage.py b/dbm-ui/backend/flow/utils/cc_manage.py index 724c1b832c..f031b7caa0 100644 --- a/dbm-ui/backend/flow/utils/cc_manage.py +++ b/dbm-ui/backend/flow/utils/cc_manage.py @@ -22,6 +22,7 @@ from backend.db_meta.models.cluster_monitor import INSTANCE_MONITOR_PLUGINS, SET_NAME_TEMPLATE from backend.db_services.ipchooser.constants import IDLE_HOST_MODULE from backend.db_services.ipchooser.query.resource import ResourceQueryHelper +from backend.exceptions import ApiError logger = logging.getLogger("flow") @@ -198,7 +199,16 @@ def transfer_host_to_idlemodule( host_id for host_id in bk_host_ids if host__idle_module[host_id] != biz_idle_module ] if transfer_host_ids: - CCApi.transfer_host_to_idlemodule({"bk_biz_id": bk_biz_id, "bk_host_id": transfer_host_ids}) + resp = CCApi.transfer_host_to_idlemodule( + {"bk_biz_id": bk_biz_id, "bk_host_id": transfer_host_ids}, raw=True + ) + if resp.get("result"): + return + # 针对主机已经转移过的场景,直接忽略即可 + if resp.get("bk_error_code") == CCApi.ErrorCode.HOST_NOT_BELONG_BIZ: + logger.warning(f"transfer_host_to_idlemodule, resp:{resp}") + else: + raise ApiError(f"transfer_host_to_idlemodule error, resp:{resp}") def transfer_host_module(self, bk_host_ids: list, target_module_ids: list): """ @@ -241,16 +251,23 @@ def transfer_host_module(self, bk_host_ids: list, target_module_ids: list): self.transfer_host_to_idlemodule( bk_biz_id=src_bk_biz_id, bk_host_ids=need_across_biz_host_ids, host_topo=hosts ) - CCApi.transfer_host_across_biz( + resp = CCApi.transfer_host_across_biz( { "src_bk_biz_id": src_bk_biz_id, "dst_bk_biz_id": self.hosting_biz_id, "bk_host_id": need_across_biz_host_ids, "bk_module_id": free_bk_module_id, - "is_increment": False, }, use_admin=True, + raw=True, ) + if resp.get("result"): + return + # 针对主机已经转移过的场景,直接忽略即可 + if resp.get("bk_error_code") == CCApi.ErrorCode.HOST_NOT_BELONG_MODULE: + logger.warning(f"transfer_host_across_biz, resp:{resp}") + else: + raise ApiError(f"transfer_host_across_biz error, resp:{resp}") # 主机转移到对应的模块下,机器可能对应多个集群,所有主机转移到多个模块下是合理的 CCApi.transfer_host_module( @@ -258,7 +275,7 @@ def transfer_host_module(self, bk_host_ids: list, target_module_ids: list): "bk_biz_id": self.hosting_biz_id, "bk_host_id": bk_host_ids, "bk_module_id": target_module_ids, - "is_increment": False, + "is_increment": True, }, use_admin=True, ) diff --git a/helm-charts/bk-dbm/Chart.yaml b/helm-charts/bk-dbm/Chart.yaml index 2be78786ab..f7e7827b04 100644 --- a/helm-charts/bk-dbm/Chart.yaml +++ b/helm-charts/bk-dbm/Chart.yaml @@ -79,5 +79,5 @@ dependencies: description: A Helm chart for bkdbm name: bk-dbm type: application -version: 1.2.0-alpha.83 -appVersion: 1.2.0-alpha.83 +version: 1.2.0-alpha.84 +appVersion: 1.2.0-alpha.84 diff --git a/helm-charts/bk-dbm/charts/dbm/Chart.yaml b/helm-charts/bk-dbm/charts/dbm/Chart.yaml index a7092167a7..6a4e42dc37 100644 --- a/helm-charts/bk-dbm/charts/dbm/Chart.yaml +++ b/helm-charts/bk-dbm/charts/dbm/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 -appVersion: 1.2.0-alpha.464 +appVersion: 1.2.0-alpha.466 description: A Helm chart for dbm name: dbm type: application