编写CDC 、api采集

这个提交包含在:
apple
2026-11-30 08:38:40 +08:00
父节点 c252f40172
当前提交 2e2910ce2e
共修改 1796 个文件,包含 14249 行新增和 208 行删除
+41
查看文件
@@ -0,0 +1,41 @@
import java.sql.*;
import java.util.*;
/** Installs separate API and file collection navigation while retaining existing grants. */
class ApiIngestionMenu {
public static void main(String[] args) throws Exception {
String schema = System.getenv("DATAGOV_DM_SCHEMA");
if (schema == null || !schema.matches("AIXUN_DATAGOV_[A-Z0-9_]+")) throw new IllegalArgumentException("Dedicated schema required");
Properties properties = new Properties();
properties.setProperty("user", System.getenv("DATAGOV_DM_USERNAME"));
properties.setProperty("password", System.getenv("DATAGOV_DM_PASSWORD"));
properties.setProperty("connectTimeout", "6000"); properties.setProperty("socketTimeout", "30000");
try (Connection connection = DriverManager.getConnection("jdbc:dm://" + System.getenv("DATAGOV_DM_HOST") + ":" + System.getenv("DATAGOV_DM_PORT"), properties)) {
connection.setSchema(schema); connection.setAutoCommit(false);
long api = 1761490000000002820L, file = 1761490000000000090L, offline = 1761490000000000080L;
if (args.length == 1 && "--apply".equals(args[0])) {
try (PreparedStatement check = connection.prepareStatement("SELECT path,perms FROM sys_menu WHERE menu_id=?")) {
check.setLong(1, api);
try (ResultSet rows = check.executeQuery()) {
if (rows.next() && (!"/api-ingestion".equals(rows.getString(1)) || !"aixun:dataops:file-ingestion:view".equals(rows.getString(2)))) throw new IllegalStateException("API menu identity conflict");
}
}
try (PreparedStatement update = connection.prepareStatement("UPDATE sys_menu SET menu_name=CASE WHEN menu_id=? THEN '离线采集' ELSE '文件采集' END, order_num=CASE WHEN menu_id=? THEN order_num ELSE 7 END WHERE (menu_id=? AND path='/unified-ingestion') OR (menu_id=? AND path='/file-ingestion')")) {
update.setLong(1, offline); update.setLong(2, offline); update.setLong(3, offline); update.setLong(4, file);
if (update.executeUpdate() != 2) throw new IllegalStateException("Existing menu identity mismatch");
}
try (PreparedStatement insert = connection.prepareStatement("INSERT INTO sys_menu(menu_id,menu_name,parent_id,order_num,path,component,is_frame,is_cache,menu_type,visible,status,perms,icon,create_time) SELECT ?, 'API采集', parent_id, 6, '/api-ingestion', 'datagov/dataops/api-ingestion/index', 'N','N','C','0','0',perms,'link',CURRENT_TIMESTAMP FROM sys_menu WHERE menu_id=? AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE menu_id=?)")) {
insert.setLong(1, api); insert.setLong(2, file); insert.setLong(3, api); insert.executeUpdate();
}
try (PreparedStatement grants = connection.prepareStatement("INSERT INTO sys_role_menu(role_id,menu_id) SELECT role_id,? FROM sys_role_menu old_menu WHERE menu_id=? AND NOT EXISTS (SELECT 1 FROM sys_role_menu new_menu WHERE new_menu.role_id=old_menu.role_id AND new_menu.menu_id=?)")) {
grants.setLong(1, api); grants.setLong(2, file); grants.setLong(3, api); grants.executeUpdate();
}
connection.commit();
}
try (PreparedStatement query = connection.prepareStatement("SELECT menu_name,path FROM sys_menu WHERE menu_id IN (?,?,?) ORDER BY order_num")) {
query.setLong(1, offline); query.setLong(2, api); query.setLong(3, file);
try (ResultSet rows = query.executeQuery()) { int count = 0; while (rows.next()) { count++; System.out.println(rows.getString(1) + " " + rows.getString(2)); } if (count != 3) throw new IllegalStateException("Menu installation incomplete"); }
}
}
}
}
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
"""Install or inspect the API and file collection menus."""
import argparse
import json
import os
import stat
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--config', required=True, type=Path)
parser.add_argument('--apply', action='store_true')
args = parser.parse_args()
config = args.config.resolve()
if not config.is_relative_to(ROOT / 'runtime/dev-private') or stat.S_IMODE(config.stat().st_mode) & 0o077:
parser.error('private configuration required')
values = json.loads(config.read_text())
environment = os.environ.copy()
for key in ('host', 'port', 'username', 'password', 'schema'):
environment['DATAGOV_DM_' + key.upper()] = str(values[key])
raise SystemExit(subprocess.run(['java', '--class-path', str(ROOT / 'script/datagov/m2/seatunnel/local/artifacts/DmJdbcDriver18-8.1.3.62.jar'), str(ROOT / 'script/database/ApiIngestionMenu.java'), *(['--apply'] if args.apply else [])], env=environment).returncode)