|
|
@@ -810,6 +810,16 @@ def finalize_assets(direct_count: int | None = None, derived_count: int | None =
|
|
|
log(f"资源暂存完成:暂存 {file_count} 个文件,缺失 {missing_count},双节点哈希一致")
|
|
|
|
|
|
|
|
|
+def stage_legacy_code() -> None:
|
|
|
+ paths = {
|
|
|
+ "/WEB-INF/classes/space/apps/moudules/website/template",
|
|
|
+ "/web/subassembly",
|
|
|
+ }
|
|
|
+ log("复制旧生产自定义模板类、页面和模板配置")
|
|
|
+ tar_paths_from_source(paths, STAGE_WEBAPP)
|
|
|
+ finalize_assets()
|
|
|
+
|
|
|
+
|
|
|
def verify_database() -> dict:
|
|
|
pre = json.loads((REPORT_DIR / "preflight.json").read_text(encoding="utf-8"))
|
|
|
protected_ids = pre["protected_websites"]
|
|
|
@@ -839,11 +849,11 @@ def verify_database() -> dict:
|
|
|
("NOT (d.articleid <=> COALESCE(article_map.new_id,s.articleid))" if c == "articleid"
|
|
|
else f"NOT (d.`{c}` <=> s.`{c}`)") for c in common)
|
|
|
missing = int(mysql(
|
|
|
- f"SELECT COUNT(*) FROM `{LEGACY_APPS}`.article s LEFT JOIN `{SWITCH_APPS}`.article d "
|
|
|
- f"ON {join}{extra_join} WHERE d.articleid IS NULL;").strip() or "0")
|
|
|
+ f"SELECT COUNT(*) FROM `{LEGACY_APPS}`.article s{extra_join} "
|
|
|
+ f"LEFT JOIN `{SWITCH_APPS}`.article d ON {join} WHERE d.articleid IS NULL;").strip() or "0")
|
|
|
different = int(mysql(
|
|
|
- f"SELECT COUNT(*) FROM `{LEGACY_APPS}`.article s JOIN `{SWITCH_APPS}`.article d "
|
|
|
- f"ON {join}{extra_join} WHERE {compare};").strip() or "0")
|
|
|
+ f"SELECT COUNT(*) FROM `{LEGACY_APPS}`.article s{extra_join} "
|
|
|
+ f"JOIN `{SWITCH_APPS}`.article d ON {join} WHERE {compare};").strip() or "0")
|
|
|
elif table == "article_copy":
|
|
|
join = ("d.dcode=s.dcode AND d.articleid=COALESCE(article_map.new_id,s.articleid) "
|
|
|
"AND d.navigationid=s.navigationid AND d.create_time=s.create_time")
|
|
|
@@ -852,12 +862,12 @@ def verify_database() -> dict:
|
|
|
("NOT (d.articleid <=> COALESCE(article_map.new_id,s.articleid))" if c == "articleid"
|
|
|
else f"NOT (d.`{c}` <=> s.`{c}`)") for c in common if c != "article_copyid")
|
|
|
missing = int(mysql(
|
|
|
- f"SELECT COUNT(DISTINCT s.article_copyid) FROM `{LEGACY_APPS}`.article_copy s "
|
|
|
- f"LEFT JOIN `{SWITCH_APPS}`.article_copy d ON {join}{extra_join} "
|
|
|
+ f"SELECT COUNT(DISTINCT s.article_copyid) FROM `{LEGACY_APPS}`.article_copy s{extra_join} "
|
|
|
+ f"LEFT JOIN `{SWITCH_APPS}`.article_copy d ON {join} "
|
|
|
"WHERE d.article_copyid IS NULL;").strip() or "0")
|
|
|
different = int(mysql(
|
|
|
- f"SELECT COUNT(DISTINCT s.article_copyid) FROM `{LEGACY_APPS}`.article_copy s "
|
|
|
- f"JOIN `{SWITCH_APPS}`.article_copy d ON {join}{extra_join} "
|
|
|
+ f"SELECT COUNT(DISTINCT s.article_copyid) FROM `{LEGACY_APPS}`.article_copy s{extra_join} "
|
|
|
+ f"JOIN `{SWITCH_APPS}`.article_copy d ON {join} "
|
|
|
f"WHERE {compare};").strip() or "0")
|
|
|
else:
|
|
|
extra_join = ""
|
|
|
@@ -892,17 +902,30 @@ def verify_database() -> dict:
|
|
|
"SELECT COUNT(*) FROM article a LEFT JOIN website_navigation n ON n.navigationid=a.navigationid "
|
|
|
"WHERE a.websiteid IN (SELECT id FROM _legacy_scope_website) "
|
|
|
"AND (n.navigationid IS NULL OR n.websiteid<>a.websiteid);", SWITCH_APPS).strip())
|
|
|
+ orphan_article_nav_legacy = int(mysql(
|
|
|
+ "SELECT COUNT(*) FROM article a LEFT JOIN website_navigation n ON n.navigationid=a.navigationid "
|
|
|
+ "WHERE a.websiteid IN (SELECT websiteid FROM website) "
|
|
|
+ "AND (n.navigationid IS NULL OR n.websiteid<>a.websiteid);", LEGACY_APPS).strip())
|
|
|
orphan_nav_parent = int(mysql(
|
|
|
"SELECT COUNT(*) FROM website_navigation n LEFT JOIN website_navigation p "
|
|
|
"ON p.navigationid=n.parent_nid WHERE n.parent_nid IS NOT NULL "
|
|
|
"AND (n.websiteid IN (SELECT id FROM _legacy_scope_website) "
|
|
|
"OR n.wtid IN (SELECT id FROM _legacy_scope_template)) "
|
|
|
"AND p.navigationid IS NULL;", SWITCH_APPS).strip())
|
|
|
+ orphan_nav_parent_legacy = int(mysql(
|
|
|
+ "SELECT COUNT(*) FROM website_navigation n LEFT JOIN website_navigation p "
|
|
|
+ "ON p.navigationid=n.parent_nid WHERE n.parent_nid IS NOT NULL "
|
|
|
+ "AND (n.websiteid IN (SELECT websiteid FROM website) OR n.wtid IN (SELECT wtid FROM website_template)) "
|
|
|
+ "AND p.navigationid IS NULL;", LEGACY_APPS).strip())
|
|
|
result = {"table_counts": counts, "mismatches": mismatches,
|
|
|
- "orphan_article_nav": orphan_article_nav, "orphan_nav_parent": orphan_nav_parent,
|
|
|
+ "orphan_article_nav": orphan_article_nav,
|
|
|
+ "orphan_article_nav_legacy": orphan_article_nav_legacy,
|
|
|
+ "orphan_nav_parent": orphan_nav_parent,
|
|
|
+ "orphan_nav_parent_legacy": orphan_nav_parent_legacy,
|
|
|
"protected": after}
|
|
|
atomic_json(VERIFY_REPORT, result)
|
|
|
- if mismatches or orphan_article_nav or orphan_nav_parent:
|
|
|
+ if (mismatches or orphan_article_nav > orphan_article_nav_legacy
|
|
|
+ or orphan_nav_parent > orphan_nav_parent_legacy):
|
|
|
raise JobError("数据库复核失败,详见 verify-report.json")
|
|
|
return result
|
|
|
|
|
|
@@ -911,11 +934,20 @@ def prepare_verify_webapp() -> None:
|
|
|
live = Path("/home/hxxy/zq/apps/internal/webapp")
|
|
|
if not live.is_dir():
|
|
|
raise JobError("找不到 hxcs 内网 webapp")
|
|
|
- if VERIFY_WEBAPP.exists():
|
|
|
- shutil.rmtree(VERIFY_WEBAPP)
|
|
|
- log("复制临时验证 webapp")
|
|
|
- subprocess.run(["cp", "-a", str(live), str(VERIFY_WEBAPP)], check=True)
|
|
|
- subprocess.run(["cp", "-a", str(STAGE_WEBAPP) + "/.", str(VERIFY_WEBAPP)], check=True)
|
|
|
+ log("使用容器权限复制临时验证 webapp,并以硬链接叠加暂存资源")
|
|
|
+ uid = os.getuid()
|
|
|
+ gid = os.getgid()
|
|
|
+ copy_script = (
|
|
|
+ "set -e; rm -rf /run-root/verify-webapp; mkdir -p /run-root/verify-webapp; "
|
|
|
+ "tar -C /src --exclude='./web/upload' --exclude='./main' -cf - . | "
|
|
|
+ "tar -C /run-root/verify-webapp -xf -; "
|
|
|
+ "cp -alf /run-root/webapp/. /run-root/verify-webapp/; "
|
|
|
+ f"chown -R {uid}:{gid} /run-root/verify-webapp"
|
|
|
+ )
|
|
|
+ subprocess.run([
|
|
|
+ "docker", "run", "--rm", "-v", f"{live}:/src:ro",
|
|
|
+ "-v", f"{RUN_ROOT}:/run-root", "tomcat:8.5-jdk8", "sh", "-c", copy_script,
|
|
|
+ ], check=True)
|
|
|
replacements = {
|
|
|
"WEB-INF/config/druid/base.jdbc.properties": TARGET_CORE,
|
|
|
"WEB-INF/config/druid/apps.jdbc.properties": TARGET_APPS,
|
|
|
@@ -956,7 +988,8 @@ def run_verify_tomcat(pre: dict) -> list[dict]:
|
|
|
urls = ["/"]
|
|
|
for url in mysql_values(
|
|
|
f"SELECT url FROM `{LEGACY_APPS}`.article WHERE websiteid={site['websiteid']} "
|
|
|
- "AND dcode=61 ORDER BY release_time DESC LIMIT 8;"):
|
|
|
+ "AND dcode=61 AND ascode=10010 AND `release`=1 AND ajtcode=10000 "
|
|
|
+ "AND url LIKE '/%' ORDER BY release_time DESC LIMIT 8;"):
|
|
|
path = normalize_path(url)
|
|
|
if path:
|
|
|
urls.append(path)
|
|
|
@@ -1061,11 +1094,17 @@ def run_mode(mode: str) -> None:
|
|
|
update_status(stage="verify")
|
|
|
verify()
|
|
|
update_status(stage="complete", state="complete", finished_at=now())
|
|
|
+ elif mode == "stage-code":
|
|
|
+ update_status(stage="stage-assets", continued_at=now())
|
|
|
+ stage_legacy_code()
|
|
|
+ update_status(stage="verify")
|
|
|
+ verify()
|
|
|
+ update_status(stage="complete", state="complete", finished_at=now())
|
|
|
elif mode == "refresh-delta":
|
|
|
raise JobError("refresh-delta 需要在正式切换前的停写窗口另行授权后实现/执行")
|
|
|
else:
|
|
|
raise JobError(f"未知模式:{mode}")
|
|
|
- if mode not in {"all", "resume", "continue-merge", "continue-assets", "continue-mirror"}:
|
|
|
+ if mode not in {"all", "resume", "continue-merge", "continue-assets", "continue-mirror", "stage-code"}:
|
|
|
update_status(state="complete", stage=mode, finished_at=now())
|
|
|
except Exception as exc:
|
|
|
log("任务失败:" + str(exc))
|