- 新增 docs/ONTOLOGY_IMPORT.md:本体 schema 导入的硬约束(fail-fast 闸门、整事务、 幂等键、IRI 双空间映射、不做范围对账删除),并记录实现落点与逐条偏差 - 新增 docs/auto-ontology-benchmark-20261106.md:NVIDIA auto-ontology 对标分析与 Top-8 路线图,本版已落地项逐条标注 - docs/README.md 同步 API 清单与 MCP 工具表(54 个:只读 27 / 写入 27) - 项目 CLAUDE.md 补「本体 schema 导入」小节:闸门顺序、事务与串行理由、幂等表、 RDF Schema 命名空间年份坑 - README.md 镜像标签更新到 1.8.0,本地构建镜像补上 Linux 静态二进制交叉编译步骤, 健康检查端点改回 /api/v1/version - scripts/ 收拢本体 v2 迁移与分级校正脚本(一次性运维工具,不参与构建) Co-Authored-By: Claude Code <[email protected]>
117 lines
5.0 KiB
Python
117 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
对比两个版本(导入前 vs 导入后)的数据与表现。
|
|
- 导入前:backups_1 快照(X-Snapshot-Id:1),v1.5.1 部署后、v2 蓝图落地前的全库态
|
|
- 导入后:当前生产(/api/v1/... manager 主体)
|
|
维度:object-types / link-types / 实例分布 / 数据分级 / principals / 版本与可用端点
|
|
"""
|
|
import json
|
|
import scripts.import_ontology_v2 as m # 复用其清代理 env 的 api()
|
|
|
|
|
|
def get_types(kind, snap=False):
|
|
headers = {"X-Snapshot-Id": "1"} if snap else None
|
|
code, resp = m.api("GET", f"/ontology/{kind}", headers=headers)
|
|
assert code == 200, f"{kind} {code}: {resp}"
|
|
return resp if isinstance(resp, list) else []
|
|
|
|
|
|
def get(path, snap=False):
|
|
headers = {"X-Snapshot-Id": "1"} if snap else None
|
|
code, resp = m.api("GET", path, headers=headers)
|
|
return code, resp
|
|
|
|
|
|
def main():
|
|
print("=" * 70)
|
|
print("版本对比:导入前(backups_1 快照) vs 导入后(当前生产)")
|
|
print("=" * 70)
|
|
|
|
# ---- 0. 版本与可用端点 ----
|
|
c_v, v = get("/version")
|
|
print(f"\n[0] 服务端版本 (导入后): {v.get('version')} / commit {v.get('commit')} / {v.get('build_time')}")
|
|
|
|
# ---- 1. object-types ----
|
|
cur_ot = {t["api_name"]: t for t in get_types("object-types", snap=False)}
|
|
snap_ot = {t["api_name"]: t for t in get_types("object-types", snap=True)}
|
|
cur_names, snap_names = set(cur_ot), set(snap_ot)
|
|
added = sorted(cur_names - snap_names)
|
|
removed = sorted(snap_names - cur_names)
|
|
kept = sorted(cur_names & snap_names)
|
|
print(f"\n[1] OBJECT-TYPES 导入前={len(snap_ot)} 导入后={len(cur_ot)}")
|
|
print(f" 新增({len(added)}): {added}")
|
|
print(f" 移除({len(removed)}): {removed}")
|
|
print(f" 保留({len(kept)})")
|
|
|
|
# ---- 2. link-types ----
|
|
cur_lt = {l["api_name"]: l for l in get_types("link-types", snap=False)}
|
|
snap_lt = {l["api_name"]: l for l in get_types("link-types", snap=True)}
|
|
cur_ln, snap_ln = set(cur_lt), set(snap_lt)
|
|
added_l = sorted(cur_ln - snap_ln)
|
|
removed_l = sorted(snap_ln - cur_ln)
|
|
retargeted = [n for n in (cur_ln & snap_ln)
|
|
if (cur_lt[n].get("source_type"), cur_lt[n].get("target_type"))
|
|
!= (snap_lt[n].get("source_type"), snap_lt[n].get("target_type"))]
|
|
print(f"\n[2] LINK-TYPES 导入前={len(snap_lt)} 导入后={len(cur_lt)}")
|
|
print(f" 新增({len(added_l)}): {added_l}")
|
|
print(f" 移除({len(removed_l)}): {removed_l}")
|
|
print(f" 同名但端点改写({len(retargeted)}): {retargeted}")
|
|
for n in retargeted:
|
|
print(f" {n}: {snap_lt[n].get('source_type')}->{snap_lt[n].get('target_type')}"
|
|
f" => {cur_lt[n].get('source_type')}->{cur_lt[n].get('target_type')}")
|
|
|
|
# ---- 3. 实例分布与总量 ----
|
|
def inst_total(tbl):
|
|
return sum(int(t.get("instance_count", 0) or 0) for t in tbl.values())
|
|
print(f"\n[3] 实例总量(按 object-types.instance_count 求和)")
|
|
print(f" 导入前={inst_total(snap_ot)} 导入后={inst_total(cur_ot)}")
|
|
|
|
# ComplianceStandard 拆分专项
|
|
c_c, r_c = get("/objects?type=ComplianceStandard&limit=1")
|
|
c_s, r_s = get("/objects?type=Standard&limit=1")
|
|
c_p, r_p = get("/objects?type=PolicyDocument&limit=1")
|
|
cs_now = r_c.get("total") if isinstance(r_c, dict) else "?"
|
|
st_now = r_s.get("total") if isinstance(r_s, dict) else "?"
|
|
pd_now = r_p.get("total") if isinstance(r_p, dict) else "?"
|
|
print(f" ComplianceStandard: 原261(全墓碑) -> 现{cs_now}(类型已删)")
|
|
print(f" Standard: 现{st_now} (原10 + 合并10 + 新建38)")
|
|
print(f" PolicyDocument: 现{pd_now} (新建223)")
|
|
|
|
# ---- 4. 数据分级 L0-L4 表现 ----
|
|
c_cf, cfg = get("/ontology/classification/config")
|
|
levels = set()
|
|
n_types = 0
|
|
items = cfg.get("items", []) if isinstance(cfg, dict) else (cfg if isinstance(cfg, list) else [])
|
|
for it in items:
|
|
n_types += 1
|
|
for lv in (it.get("classification_levels") or []):
|
|
levels.add(lv)
|
|
print(f"\n[4] 数据分级 L0-L4 配置覆盖类型数={n_types} 实际出现的层级={sorted(levels)}")
|
|
print(f" 统一词汇={ 'OK' if levels == {'L0','L1','L2','L3','L4'} else '不一致' }")
|
|
|
|
# ---- 5. principals 用户 ----
|
|
c_p, pr = get("/access/principals")
|
|
prs = pr.get("principals", []) if isinstance(pr, dict) else []
|
|
names = [p.get("name") for p in prs]
|
|
print(f"\n[5] principals(用户主体) 总数={len(names)}")
|
|
print(f" 含 manager={ 'manager' in names } 含 rong={ 'rong' in names }")
|
|
# 角色分布
|
|
from collections import Counter
|
|
roles = Counter()
|
|
for p in prs:
|
|
r = p.get("roles") or p.get("role")
|
|
if isinstance(r, list):
|
|
for x in r:
|
|
roles[x] += 1
|
|
elif r:
|
|
roles[r] += 1
|
|
print(f" 角色分布(前8): {roles.most_common(8)}")
|
|
|
|
print("\n" + "=" * 70)
|
|
print("对比完成。")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|