Skip to content

Commit

Permalink
feat(backend): cmdb 创建自定义字段支持并发容错 #3647
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 committed Mar 21, 2024
1 parent 0e6b44e commit ac3d0bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions dbm-ui/backend/components/cc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class _CCApi(BaseApi):
class ErrorCode:
HOST_NOT_BELONG_BIZ = 1113002
HOST_NOT_BELONG_MODULE = 1110056
CUSTOM_FIELD_ALREADY_EXISTS = 1101107

def __init__(self):
self.list_hosts_without_biz = self.generate_data_api(
Expand Down
12 changes: 9 additions & 3 deletions dbm-ui/backend/dbm_init/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def init_cc_dbm_meta(bk_biz_id=env.DBA_APP_BK_BIZ_ID):
if exist_dbm_attr:
logger.info("skip exist dbm attr in host model")
return True

CCApi.create_biz_custom_field(
resp = CCApi.create_biz_custom_field(
{
"bk_biz_id": bk_biz_id,
"bk_obj_id": "host",
Expand All @@ -217,9 +216,16 @@ def init_cc_dbm_meta(bk_biz_id=env.DBA_APP_BK_BIZ_ID):
"option": "",
},
use_admin=True,
raw=True,
)
if resp.get("result"):
return

logger.info("init cc db_app_abbr for english app")
# 已经存在,忽略即可
if resp.get("code") == CCApi.ErrorCode.CUSTOM_FIELD_ALREADY_EXISTS:
logger.warning(f"create_biz_custom_field({CC_HOST_DBM_ATTR}), resp:{resp}")
else:
raise ApiError(f"create_biz_custom_field({CC_HOST_DBM_ATTR}) error, resp:{resp}")

@staticmethod
def auto_create_bkcc_service() -> bool:
Expand Down
3 changes: 2 additions & 1 deletion dbm-ui/backend/tests/mock_data/components/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
import copy

from backend.components import CCApi
from backend.tests.mock_data import constant

MOCK_SEARCH_BUSINESS_RETURN = {"info": [{"bk_biz_id": constant.BK_BIZ_ID, "bk_biz_name": "蓝鲸"}], "count": 1}
Expand Down Expand Up @@ -147,7 +148,7 @@
]


class CCApiMock(object):
class CCApiMock(CCApi):
"""
cc的mock接口
"""
Expand Down

0 comments on commit ac3d0bf

Please sign in to comment.