Skip to content

Commit

Permalink
feat(backend): 转移模块兼容已转移的场景 #1786
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 committed Nov 14, 2023
1 parent 9e99d21 commit c8b364f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions dbm-ui/backend/components/cc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 21 additions & 4 deletions dbm-ui/backend/flow/utils/cc_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -241,24 +251,31 @@ 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(
{
"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,
)
Expand Down
4 changes: 2 additions & 2 deletions helm-charts/bk-dbm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion helm-charts/bk-dbm/charts/dbm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c8b364f

Please sign in to comment.