Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 插件包历史优化 (closed #2538) #2539

Open
wants to merge 1 commit into
base: v2.4.8-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions apps/node_man/tools/plugin_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,28 @@ def get_packages_node_numbers(cls, projects: List[str], keys: List[str]) -> Dict
name__in=projects,
source_type=models.ProcessStatus.SourceType.DEFAULT,
is_latest=True,
).values("bk_host_id", "name", "version")
)
.extra(
tables=[f"{models.Host._meta.db_table}"],
where=[f"{models.Host._meta.db_table}.bk_host_id = {models.ProcessStatus._meta.db_table}.bk_host_id"],
select={
"os_type": f"{models.Host._meta.db_table}.os_type",
"cpu_arch": f"{models.Host._meta.db_table}.cpu_arch",
},
)
.values("bk_host_id", "name", "version", "os_type", "cpu_arch")
)

# proc_list有重复的情况会在此步骤构建映射时自动去重
proj_host_id_proc_map = {f"{proc['name']}_{proc['bk_host_id']}": proc for proc in proc_list}

host_list = models.Host.objects.filter(bk_host_id__in={proc["bk_host_id"] for proc in proc_list}).values(
"bk_host_id", "os_type", "cpu_arch"
)

proj_deploy_infos = []
for host in host_list:
host.update({"os": host["os_type"].lower()})
for proc in proc_list:
proj_deploy_infos.extend(
[
{**host, **proj_host_id_proc_map[f"{project}_{host['bk_host_id']}"], "project": project}
{**proc, "project": project, "os": proc["os_type"].lower()}
for project in projects
if f"{project}_{host['bk_host_id']}" in proj_host_id_proc_map
if f"{project}_{proc['bk_host_id']}" in proj_host_id_proc_map
]
)
deploy_infos_group_by_keys = groupby(
Expand Down