Skip to content

Commit

Permalink
feature: 部署策略执行被抑制时,主抑制策略增加超链接 (closed TencentBlueKing#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
CohleRustW committed Sep 7, 2022
1 parent 0eb95f0 commit 600eeeb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
14 changes: 6 additions & 8 deletions apps/backend/subscription/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from functools import wraps
from typing import Any, Dict, List, Optional, Union

from django.conf import settings
from django.utils.translation import ugettext as _

from apps.backend.celery import app
Expand Down Expand Up @@ -314,6 +313,8 @@ def create_task(
is_suppressed = result["is_suppressed"]
if is_suppressed:
# 策略被抑制,跳过部署,记为已忽略
suppressed_by_id: int = result["suppressed_by"]["subscription_id"]
suppressed_by_name: str = result["suppressed_by"]["name"]
error_hosts.append(
{
"ip": host_info.get("bk_host_innerip") or host_info.get("bk_host_innerip_v6"),
Expand All @@ -322,14 +323,13 @@ def create_task(
"bk_host_id": host_info.get("bk_host_id"),
"bk_biz_id": host_info.get("bk_biz_id"),
"bk_cloud_id": host_info.get("bk_cloud_id"),
"suppressed_by_id": result["suppressed_by"]["subscription_id"],
"suppressed_by_name": result["suppressed_by"]["name"],
"suppressed_by_id": suppressed_by_id,
"suppressed_by_name": suppressed_by_name,
"os_type": node_man_tools.HostV2Tools.get_os_type(host_info),
"status": constants.JobStatusType.IGNORED,
"msg": _(
"当前{category_alias}({bk_obj_name} 级)"
"已被优先级更高的{suppressed_by_category_alias}【{suppressed_by_name}(ID: {suppressed_by_id})】"
'({suppressed_by_obj_name} 级)抑制, 点击跳转到 <a href="{link}" target="_blank">[策略页面]</a>'
).format(
category_alias=models.Subscription.CATEGORY_ALIAS_MAP[result["category"]],
bk_obj_name=constants.CmdbObjectId.OBJ_ID_ALIAS_MAP.get(
Expand All @@ -339,14 +339,12 @@ def create_task(
suppressed_by_category_alias=models.Subscription.CATEGORY_ALIAS_MAP[
result["suppressed_by"]["category"]
],
suppressed_by_name=result["suppressed_by"]["name"],
suppressed_by_id=result["suppressed_by"]["subscription_id"],
suppressed_by_name=suppressed_by_name,
suppressed_by_id=suppressed_by_id,
suppressed_by_obj_name=constants.CmdbObjectId.OBJ_ID_ALIAS_MAP.get(
result["suppressed_by"]["bk_obj_id"],
constants.CmdbObjectId.OBJ_ID_ALIAS_MAP[constants.CmdbObjectId.CUSTOM],
),
link=f"{settings.BK_NODEMAN_HOST}/#/plugin-manager/rule?name"
f"={result['suppressed_by']['name']}",
),
}
)
Expand Down
39 changes: 21 additions & 18 deletions apps/node_man/handlers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import copy
import logging
import re
from typing import Any, Dict, List, Optional, Set
from typing import Any, Dict, List, Optional, Set, Union

from django.conf import settings
from django.core.paginator import Paginator
Expand Down Expand Up @@ -888,23 +888,26 @@ def retrieve(self, params: Dict[str, Any]):
# conditions中无status或者筛选条件为空列表 视为全选,过滤不在筛选条件中的排除主机
if statuses_in_conditions and status not in statuses_in_conditions:
continue
filter_hosts.append(
{
"filter_host": True,
"bk_host_id": host.get("bk_host_id"),
"ip": host["ip"],
"inner_ip": host.get("inner_ip"),
"inner_ipv6": host.get("inner_ipv6"),
"bk_cloud_id": host.get("bk_cloud_id"),
"bk_cloud_name": host.get("bk_cloud_name"),
"bk_biz_id": host.get("bk_biz_id"),
"bk_biz_name": host.get("bk_biz_name"),
"job_id": host.get("job_id"),
"status": host.get("status") or constants.JobStatusType.FAILED,
"status_display": host.get("msg"),
"step": "",
}
)

filter_host_info: Dict[str, Union[bool, str, int]] = {
"filter_host": True,
"bk_host_id": host.get("bk_host_id"),
"ip": host["ip"],
"inner_ip": host.get("inner_ip"),
"inner_ipv6": host.get("inner_ipv6"),
"bk_cloud_id": host.get("bk_cloud_id"),
"bk_cloud_name": host.get("bk_cloud_name"),
"bk_biz_id": host.get("bk_biz_id"),
"bk_biz_name": host.get("bk_biz_name"),
"job_id": host.get("job_id"),
"status": host.get("status") or constants.JobStatusType.FAILED,
"status_display": host.get("msg"),
"step": "",
}
host_suppressed_by_id = host.get("suppressed_by_id", None)
if host_suppressed_by_id is not None:
filter_host_info.update({"suppressed_by_id": host_suppressed_by_id})
filter_hosts.append(filter_host_info)
host_execute_status_list.extend(filter_hosts)

# 补充业务名、云区域名称
Expand Down
3 changes: 3 additions & 0 deletions dev_log/2.2.22/xcwang_202209071547.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
feature:
- "部署策略执行被抑制时,主抑制策略增加超链接 (closed #889)"

0 comments on commit 600eeeb

Please sign in to comment.