Skip to content

Commit

Permalink
feature: 支持 AIX 操作系统区分版本 (closed TencentBlueKing#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
CohleRustW committed Jun 9, 2022
1 parent 928987b commit 8ca5abf
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 22 deletions.
8 changes: 7 additions & 1 deletion apps/backend/components/collections/agent_new/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ def get_agent_upgrade_pkg_name(cls, host: models.Host) -> str:
:return:
"""
package_type = ("client", "proxy")[host.node_type == constants.NodeType.PROXY]
agent_upgrade_package_name = f"gse_{package_type}-{host.os_type.lower()}-{host.cpu_arch}_upgrade.tgz"
if host.os_version is not None:
agent_upgrade_package_name = (
f"gse_{package_type}-{host.os_type.lower()}{host.os_version}-{host.cpu_arch}_upgrade.tgz"
)
else:
agent_upgrade_package_name = f"gse_{package_type}-{host.os_type.lower()}-{host.cpu_arch}_upgrade.tgz"

return agent_upgrade_package_name

@staticmethod
Expand Down
22 changes: 21 additions & 1 deletion apps/backend/components/collections/agent_new/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def handle_report_data(self, sub_inst_id: int, success_callback_step: str) -> Di
REDIS_INST.ltrim(name, 0, -report_data_len - 1)
report_data.reverse()
cpu_arch = None
os_version = None
is_finished = False
error_log = ""
logs = []
Expand All @@ -532,6 +533,9 @@ def handle_report_data(self, sub_inst_id: int, success_callback_step: str) -> Di
logs.append(log)
if step == "report_cpu_arch":
cpu_arch = data["log"]

if step == "report_os_version":
os_version = data["log"]
# 只要匹配到成功返回步骤完成,则认为是执行完成了
if step == success_callback_step and status == "DONE":
is_finished = True
Expand All @@ -540,7 +544,15 @@ def handle_report_data(self, sub_inst_id: int, success_callback_step: str) -> Di
self.log_info(sub_inst_ids=sub_inst_id, log_content="\n".join(logs))
if error_log:
self.move_insts_to_failed([sub_inst_id], log_content=error_log)
return {"sub_inst_id": sub_inst_id, "is_finished": is_finished, "cpu_arch": cpu_arch}
if os_version is not None:
return {
"sub_inst_id": sub_inst_id,
"is_finished": is_finished,
"cpu_arch": cpu_arch,
"os_version": os_version,
}
else:
return {"sub_inst_id": sub_inst_id, "is_finished": is_finished, "cpu_arch": cpu_arch}

def _schedule(self, data, parent_data, callback_data=None):
"""通过轮询redis的方式来处理,避免使用callback的方式频繁调用schedule"""
Expand All @@ -561,18 +573,26 @@ def _schedule(self, data, parent_data, callback_data=None):
results = concurrent.batch_call(func=self.handle_report_data, params_list=params_list)
left_scheduling_sub_inst_ids = []
cpu_arch__host_id_map = defaultdict(list)
os_version__host_id_map = defaultdict(list)
for result in results:
# 对于未完成的实例,记录下来到下一次schedule中继续检查
if not result["is_finished"]:
left_scheduling_sub_inst_ids.append(result["sub_inst_id"])
# 按CPU架构对主机进行分组
bk_host_id = common_data.sub_inst_id__host_id_map.get(result["sub_inst_id"])
cpu_arch__host_id_map[result["cpu_arch"]].append(bk_host_id)
# 按操作系统版本对主机进行分组
os_version__host_id_map[result["os_version"]].append(bk_host_id)
# 批量更新CPU架构
for cpu_arch, bk_host_ids in cpu_arch__host_id_map.items():
if cpu_arch:
models.Host.objects.filter(bk_host_id__in=bk_host_ids).update(cpu_arch=cpu_arch)

# 批量更新主机操作系统版本号
for os_version, bk_host_ids in os_version__host_id_map.items():
if os_version:
models.Host.objects.filter(bk_host_id__in=bk_host_ids).update(os_version=os_version)

data.outputs.scheduling_sub_inst_ids = left_scheduling_sub_inst_ids
if not left_scheduling_sub_inst_ids:
self.finish_schedule()
Expand Down
23 changes: 16 additions & 7 deletions apps/node_man/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,22 @@ class PolicyRollBackType:
ROLLBACK_TYPE__ALIAS_MAP = {SUPPRESSED: "已被其他策略管控", LOSE_CONTROL: "脱离策略管控", TRANSFER_TO_ANOTHER: "转移到优先级最高的策略"}


GSE_CLIENT_PACKAGES: List[str] = [
"gse_client-windows-x86.tgz",
"gse_client-windows-x86_64.tgz",
"gse_client-aix-powerpc.tgz",
"gse_client-linux-x86.tgz",
"gse_client-linux-x86_64.tgz",
]
class GseClientSpecialPackage:
DESERTED = "gse_client-aix-powerpc.tgz"
APPEND: List[str] = ["gse_client-aix6-powerpc.tgz", "gse_client-aix7-powerpc.tgz"]


GSE_CLIENT_PACKAGES: List[str] = list(
set(
[
"gse_client-windows-x86.tgz",
"gse_client-windows-x86_64.tgz",
"gse_client-linux-x86.tgz",
"gse_client-linux-x86_64.tgz",
]
+ GseClientSpecialPackage.APPEND
)
)

FILES_TO_PUSH_TO_PROXY = [
{"files": ["py36.tgz"], "name": _("检测 BT 分发策略(下发Py36包)")},
Expand Down
3 changes: 1 addition & 2 deletions apps/node_man/handlers/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ def fetch_plugin_host_condition(self):
os_dict = {"name": _("操作系统"), "id": "os_type", "children": []}

for os_type in constants.OS_TUPLE:
special_os_type = [constants.OsType.AIX, constants.OsType.SOLARIS]
if os_type in special_os_type and settings.BKAPP_RUN_ENV == constants.BkappRunEnvType.CE.value:
if os_type == constants.OsType.SOLARIS and settings.BKAPP_RUN_ENV == constants.BkappRunEnvType.CE.value:
continue
os_dict["children"].append({"id": os_type, "name": constants.OS_CHN.get(os_type, os_type)})

Expand Down
11 changes: 1 addition & 10 deletions apps/node_man/migrations/0023_init_proxy_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,9 @@


def init_proxy_package(apps, schema_editor):
packages = [
"gse_client-windows-x86.tgz",
"gse_client-windows-x86_64.tgz",
"gse_client-linux-x86.tgz",
"gse_client-linux-x86_64.tgz",
]

if settings.BKAPP_RUN_ENV != constants.BkappRunEnvType.CE.value:
packages.append("gse_client-aix-powerpc.tgz")

AccessPoint = apps.get_model("node_man", "AccessPoint")
AccessPoint.objects.update(proxy_package=packages)
AccessPoint.objects.update(proxy_package=constants.GSE_CLIENT_PACKAGES)


class Migration(migrations.Migration):
Expand Down
38 changes: 38 additions & 0 deletions apps/node_man/migrations/0060_update_ap_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-节点管理(BlueKing-BK-NODEMAN) available.
Copyright (C) 2017-2022 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
# -*- coding: utf-8 -*-

from typing import List

from django.db import migrations

from apps.node_man import constants


def update_aix_package(apps, schema_editor):
AccessPoint = apps.get_model("node_man", "AccessPoint")
aps = AccessPoint.objects.all()
for ap in aps:
ap.proxy_package: List[str] = list(set(ap.proxy_package + constants.GseClientSpecialPackage.APPEND))
if constants.GseClientSpecialPackage.DESERTED in ap.proxy_package:
ap.proxy_package.remove(constants.GseClientSpecialPackage.DESERTED)
ap.save()


class Migration(migrations.Migration):

dependencies = [
("node_man", "0059_auto_20220415_2150"),
]

operations = [
migrations.RunPython(update_aix_package),
]
18 changes: 18 additions & 0 deletions apps/node_man/migrations/0061_host_os_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2022-06-09 08:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("node_man", "0060_update_ap_package"),
]

operations = [
migrations.AddField(
model_name="host",
name="os_version",
field=models.CharField(blank=True, default="", max_length=16, null=True, verbose_name="操作系统版本"),
),
]
1 change: 1 addition & 0 deletions apps/node_man/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class Host(models.Model):
cpu_arch = models.CharField(
_("操作系统"), max_length=16, choices=constants.CPU_CHOICES, default=constants.CpuType.x86_64, db_index=True
)
os_version = models.CharField(_("操作系统版本"), max_length=16, blank=True, null=True, default="")
node_type = models.CharField(_("节点类型"), max_length=16, choices=constants.NODE_CHOICES, db_index=True)
node_from = models.CharField(_("节点来源"), max_length=45, choices=constants.NODE_FROM_CHOICES, default="NODE_MAN")
is_manual = models.BooleanField(_("是否手动安装"), default=False)
Expand Down
3 changes: 3 additions & 0 deletions dev_log/2.2.17/xcwang_202206091632.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
feature:
- "支持 AIX 操作系统区分版本 (closed #815)"
21 changes: 20 additions & 1 deletion script_tools/setup_agent.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

# DEFAULT DEFINITION
NODE_TYPE=agent
PKG_NAME=gse_client-aix-powerpc.tgz
# PKG_NAME=gse_client-aix-powerpc.tgz
PKG_NAME=""
OS_VERISON=""

GSE_AGENT_RUN_DIR=/var/run/gse
GSE_AGENT_DATA_DIR=/var/lib/gse
Expand Down Expand Up @@ -56,6 +58,19 @@ warn () { local L=WARN D; D="$(date +%F\ %T)"; echo "$D $L $*" | tee -a "$LOG_F
err () { local L=ERROR D; D="$(date +%F\ %T)"; echo "$D $L $*" | tee -a "$LOG_FILE"; report_step_status "$D" "$L" "$@"; return 1; }
fail () { local L=ERROR D; D="$(date +%F\ %T)"; echo "$D $L $*" | tee -a "$LOG_FILE"; report_step_status "$D" "$L" "$@"; exit 1; }

divide_version () {
local version
result=$(oslevel)
if [[ "${result}" =~ ^6.* ]]; then
OS_VERISON=6
elif [[ "${result}" =~ ^7.* ]]; then
OS_VERISON=7
else
fail check_env FAILED "Unsupported OS version: ${result}"
fi
PKG_NAME=gse_client-aix"${OS_VERISON}"-powerpc.tgz
}

get_cpu_arch () {
local cmd=$1
CPU_ARCH=$($cmd)
Expand Down Expand Up @@ -503,6 +518,9 @@ start_basic_gse_plugin () {
download_pkg () {
local f http_status

# 区分下载版本
divide_version

log download_pkg START "download gse agent package from $DOWNLOAD_URL/$PKG_NAME)."
cd "$TMP_DIR" && rm -f "$PKG_NAME" "agent.conf.$LAN_ETH_IP"

Expand All @@ -517,6 +535,7 @@ download_pkg () {

log download_pkg DONE "gse_agent package download succeded"
log report_cpu_arch DONE "${CPU_ARCH}"
log report_os_version DONE "${OS_VERSION}"
}

check_deploy_result () {
Expand Down

0 comments on commit 8ca5abf

Please sign in to comment.