0813: j7node 业务栈拉起 + TDS Bridge 内部端点 + TDC/TDS 控制器修复
- j7node: k3s+3Pod(j7-postgres/j7-redis/j7-admin) 业务栈实测通过, admin/123456 登录 + 真实 tdc/sswflow 端点全绿; VM_DEPLOY.md 据实测校正 (IP 192.168.139.95、§3.1 库初始化、§8 验收矩阵、400 假象澄清) - TDS Bridge: 新增 TdsBridgeInternalController + SSWFLOW_BINDING.md(V0~V1.5 胶水) - TDC 去耦: 新增 TdcTdsClient/Noop/Http 抽象、K8sSandboxClient、audit、 TdcAdminApplication; 各 Controller 改走客户端 - TDS: License/Cert/Quota 分页 SQL bug 修复 - 其他: NaxComputeEngine 富化、pom 调整、AGENTS.md、.gitignore 排除 boot/dist
This commit is contained in:
1 parent
02af9ec144
commit
092e69bee7
34 files changed
+1388
-343
No files matched your search
@@ -91,6 +91,7 @@ boot/*/target/
|
||||
*.jar
|
||||
*.war
|
||||
*.class
|
||||
boot/dist/
|
||||
|
||||
# ===== 系统/IDE =====
|
||||
.DS_Store
|
||||
|
||||
@@ -358,3 +358,121 @@
|
||||
- remote main = f9899ea
|
||||
- remote tag 0813 = f9899ea(sha = 8a47ec)
|
||||
- remote tag 0808 = e877e2d
|
||||
|
||||
### 部署架构简化方案(18:00 拍板方向)
|
||||
- **苏苏诉求**:「会不会太复杂了,能不能都用 ssw-admin 引入,打包有专门 pom.xml(区分含 tds/sswflow 和不含),配置文件单独配(jar 包下 config/)」
|
||||
- **判断**:不复杂。现状已是 fat jar + 聚合 pom(boot/pom.xml),只差两步:
|
||||
1. **pom 子系统 profile 化** —— ssw-tds/tdc/sswflow 改为 `<optional>true</optional>` 依赖,ssw-admin 加 4 个 profile(full/sswflow-only/tdc-only/tds-only),profile 控制 dependency 列表
|
||||
2. **配置文件外置** —— Spring Boot 原生支持 `file:./config/` 优先于 classpath:/,jar 同级建 config/ + 按 profile 拆分 application-{role}.yml,启动命令加 `--spring.profiles.active=xxx`
|
||||
- **回应要点**:
|
||||
- 不重建,**改造量小**
|
||||
- 三子系统已有 bean 名/表前缀隔离(`sswflowXxx` / `tdsXxx` / `tdcXxx` Controller 命名 + `flow_*` / `tds_*` / `tdc_*` 表名前缀)
|
||||
- 主要坑在 dynamic-datasource 必须 1:1 对应 profile(不激活的子系统 DS 不能在 yml 残留)
|
||||
- Q1 部署角色分几种 / Q2 配置外置粒度 / Q3 数据库连接范围 —— 苏苏需拍板再动手
|
||||
- **决策**:等苏苏回 Q1/Q2/Q3 后再动 pom + config/ + 启动脚本
|
||||
|
||||
### V1.5 Nax sidecar 化(17:08-17:25)
|
||||
- **触发**:苏苏指出"TDC 镜像有指明走 tee 的用 kata,未指明的用 nax 镜像"——纠错了我之前的"V1.5.1 建 Nax sidecar"的措辞。TDC 双 runtime(kata + 集群默认)钩子早已就绪,缺的是 Nax 镜像本身 + per-connector image 选择。
|
||||
- **拍板**:方案 A(`f_type` 加 TEE/NAX/BOTH 枚举);dev minimal 起步。
|
||||
- **落地 3 件**:
|
||||
1. V1.5.5 `NaxComputeEngine @Profile("dev")` 一行注解,prod 不注册
|
||||
2. V1.5.1 `boot/docker/ssw-nax-runtime/Dockerfile`:python:3.11-slim + numpy + pandas + nax 包(dev minimal)+ nax_adapter.py 复制作为 ENTRYPOINT;构建成功 `ssw-nax-runtime:0.1.0-dev` 861MB
|
||||
3. V1.5.2 `K8sSandboxClient.runNaxJob(taskId, operatorJson)`:image 切 naxImage + runtime 切默认 + 不走 KBS + kubectl apply 占位
|
||||
- **决策文档**:§11 V1.5 章节写入 SSWFLOW_BINDING.md(11.1 核心命题 / 11.2 双 runtime 现状 / 11.3 拍板决策 / 11.4 已落地骨架 / 11.5 待办 / 11.6 风险对策)
|
||||
- **e2e**:BE 起来(17:24,PID 4849,profile=dev);V1.4 胶水 bean 全装载;Reconcile 每 30s 跑;NaxComputeEngine 静默注册(dev profile 下应有,但 Spring 不打 @Component 构造日志,留给后续 V1.5.6 dev 用起来时观察)
|
||||
|
||||
## j7node 数据持有方节点侦查(18:24-18:35)
|
||||
- **本质**:j7node = OrbStack VM (192.168.139.196, k3s v1.30.5) 上的**数据持有方/TDC 节点**,不是运营方。苏苏说"tdc包不该依赖tds"正是此节点的设计要求。
|
||||
- **部署机制**:`j7-admin` Pod 通过 **hostPath 直接挂本机** `boot/ssw-admin/target/*.jar` + `target/config/` → 我本地打什么 jar、config 里有什么,j7node 就跑什么(改动 jar 不会自动触发 pod 重启,需手动 rollout restart)。
|
||||
- **启动参数**(`scard/code/bin/k8s/30-admin.yaml`):`-Dspring.profiles.active=j7node` `-DDB_HOST=j7-postgres.j7.svc.cluster.local` `-DDB_PORT=5432` `-DREDIS_HOST=j7-redis.j7.svc.cluster.local` `-DREDIS_PORT=6379`,端口 33000 / NodePort 31000。
|
||||
- **j7-postgres**:`dacli/dacli123`,库 = `j7`(平台主库) + `j7flow_node1`(sswflow业务) + `tdc_node1`(tdc业务) + `j7_node1`(POSTGRES_DB默认);**当前四个库均 0 张表(被重初始化过,schema 丢失)**。
|
||||
- **关键缺失**:`application-j7node.yml` 被覆盖/丢失(仓内无、target/config 无)→ j7node profile 无业务数据源配置,TDC/SSWFLOW 功能不可用的根因。
|
||||
- **tdc↔tds 硬耦合**(印证苏苏"tdc不应依赖tds"):4 个 TDC Controller 直接 import TDS 类(DeliveryTaskController/OrderController/ProductApiGatewayController + 另1个),故纯 tdc-only jar 会因缺 @DS("tds") bean 启动失败——**必须重构这 4 个 Controller 走 HTTP 才能真去 TDS 依赖**。
|
||||
- 参考文档:`docs/scard/VM_DEPLOY.md`、`docs/scard/rebind_verify_20260805.html`;k8s 清单 `scard/code/bin/k8s/{00-namespace,05-pg-init,10-postgres,20-redis,30-admin}.yaml`。
|
||||
- **待苏苏拍板**:① j7node 范围 = 仅 TDC(j7+tdc_node1) 还是 TDC+本地sswflow(j7+j7flow_node1+tdc_node1)?② 是否现在重构 4 个 TDC Controller 去掉 TDS 依赖 + 重建 application-j7node.yml + 恢复 DB schema?
|
||||
|
||||
## full 构建回归修复(19:00-19:15,关键踩坑)
|
||||
- **现象**:`mvn -P full ... package` 生成的 ssw-admin fat jar 实测只有 ssw-tdc-*(3 jar),缺 ssw-tds-* / ssw-sswflow-*;且无 -P 时 full 的 activeByDefault 被 boot3(jdk[17,)) 自动激活冲掉,必须显式 `-P full`。
|
||||
- **根因1(致命)**:`ssw-tdc-biz/pom.xml` 误带 `spring-boot-maven-plugin` repackage(注释"[V1.5.9] 拆出独立可执行 fat-jar:TDC 连接器独立部署"),装成 BOOT-INF fat-jar 进 .m2。依赖它的 `ssw-tds-controller`/`ssw-tdc-controller` 从 .m2 解析时类在 `BOOT-INF/classes/` 下找不到 → 编译报"程序包 ssw.tdc.audit/service 不存在"。`-am` 模式用 target/classes(常规布局)能编过,非干净构建时症状被掩盖。
|
||||
- **根因2**:`ssw-tds-controller/pom.xml` 缺 `ssw-tdc-entity` 依赖(ContractController 业务全景引用 `ssw.tdc.entity.{OrderEntity,DeliveryTaskEntity,ApiConsumeLogEntity}`)。
|
||||
- **修复**:① 删 `ssw-tdc-biz/pom.xml` 的 repackage 块(与"单 ssw-admin jar"部署模型冲突,V1.5.9 standalone 思路废弃);② `ssw-tds-controller/pom.xml` 加 `ssw-tdc-entity` 依赖。
|
||||
- **验证**:`mvn -o -P full clean install -DskipTests` 全 reactor BUILD SUCCESS;fat jar 含 tds(3)+tdc(3)+sswflow(3)=9 jar;`mvn -o -P tdc-only clean package` 仍纯净(仅 ssw-tdc-* 3 jar,tds/sswflow=0)。两 profile 均不回归。
|
||||
- **铁律补充**:biz/controller/entity 模块都是普通 library jar,只有 ssw-admin 做 repackage;任何模块误加 repackage 都会污染 .m2 并导致依赖方"程序包不存在"。已写进 MEMORY.md 构建铁律。
|
||||
|
||||
## 两角色启动验证(19:20-19:40,端到端实证 tdc 不依赖 tds)
|
||||
- **基础设施**:OrbStack 已起 `jnpf-postgres`(15432)/`jnpf-redis`(16379),库 sswflow/tds/tdc/tdc_node1 均存在。BE 必须 `run_in_background`+`dangerouslyDisableSandbox` 才有宿主机网络(前台 bash 沙箱网络被隔离,`/dev/tcp` 探活会假阴性)。
|
||||
- **发现致命运行期坑(de耦引入)**:`DeliveryTaskController` 注入 `TdcTdsClient`,但 `NoopTdcTdsClient` 用类级 `@ConditionalOnMissingBean(TdcTdsClient.class)`——类级无 value/type 时 Spring 无法推断类型,条件永远失败 → Noop 永不被实例化;`ssw.tds.base-url` 未配时 `HttpTdcTdsClient`(@ConditionalOnProperty) 也不建 → full 角色启动报"required a bean of type TdcTdsClient"。
|
||||
- **修复**:改为 `TdcTdsClientConfig`(@Configuration) 用 `@Bean` 装配——`httpTdcTdsClient`(@ConditionalOnProperty base-url) + `noopTdcTdsClient`(@ConditionalOnMissingBean),两客户端去掉 `@Component`/`@Conditional*` 改普通类+构造器。重构建 BUILD SUCCESS。
|
||||
- **full 角色验证(端口 30000)**:`Started SswAdminApplication`(34s),login 200 拿 token;TDC `/DeliveryTask`/SSWFLOW `/Party/Self` 200 真实数据;TDS `/License` 200 但 `code:400`——根因是 **LicenseMapper 预存 SQL bug**(`SELECT COUNT(*) ... ORDER BY f_creator_time` 缺 GROUP BY,Postgres 拒绝),与打包/部署无关。auth header 实测须 `bearer <jwt>`(**不带引号**,带引号被严格端点拒为 600)。
|
||||
- **tdc-only 角色验证(端口 30001,profile=dev,tdc)**:fat jar 仅含 ssw-common-*(3)+ssw-tdc-*(3)=6 jar,无 ssw-tds/ssw-sswflow;`dynamic-datasource initial loaded [2] datasource`(master+j7 + tdc,无 tds/sswflow);`Started SswAdminApplication`(32s);login 200;TDC `/DeliveryTask` 200 真实数据(173 条);TDS/SSWFLOW 端点 AuthFilter 放行但无对应 Controller(jar 内无 ssw/tds、ssw/sswflow class),JNPF 全局处理器回 `code:400`,证明模块确未打包。
|
||||
- **ssw-tdc 全模块 @DS 核查**:所有 @DS 注解 100% 为 `@DS("tdc")`,零 `@DS("tds")`/`@DS("sswflow")` → tdc 运行期亦无 TDS 硬依赖。
|
||||
- **修正 `boot/dist/config/application-tdc.yml`**:原注释仍是"TDC-TDS 双向硬耦合、必须连 tds 库"(过时);改为声明**仅 tdc 数据源**,并标注 TDC-TDS 解耦已完成、tdc 包不依赖 tds 在编译/运行期均成立。
|
||||
- **结论**:两种部署角色(full=运营方全量、tdc-only=数据持有方)均启动+鉴权+业务可用;"tdc 包不依赖 tds"在编译期(fat jar 不含 tds 类)与运行期(仅 tdc 数据源+NoopTdcTdsClient)双实证通过。Task #25/#30 收尾 completed。
|
||||
- **待办(非本次范围)**:① TDS LicenseMapper `ORDER BY f_creator_time` 缺 GROUP BY 的预存 SQL bug;② TDS bridge 端点(7 个 Contract/Connector/DataProduct/AuditChain/...)尚未在 ssw-tds-controller 实现,tdc-only 连运营方聚合全景需先配 `ssw.tds.base-url` 再补端点。
|
||||
|
||||
## 新增跨会话红线(用户 19:50 追加)
|
||||
- **禁止 TDS-TDC 强耦合**:TDC 编译期不得依赖 `ssw-tds` 模块(pom 不引 ssw-tds-*),跨系统读写只走 `TdcTdsClient` HTTP 抽象(Noop 降级);全 `ssw-tdc` 模块 `@DS` 必为 `@DS("tdc")`,零 `@DS("tds")`。`tdc-only` fat-jar 必须不含 ssw-tds-/ssw-sswflow- 类。已进入 AGENTS.md 三子系统红线 + MEMORY.md。
|
||||
- **正式部署 TDC 须落在 `scard` 安全方案内**:`scard/`(Go server+connector, 软PKI+软TPM) + `docs/scard/VM_DEPLOY.md` connector/VM 范式;本机 `ssw-admin` 单 jar 仅供开发联调,不是 TDC 正式部署形态。已写入 AGENTS.md「部署形态红线」+ MEMORY.md。
|
||||
|
||||
## 跑通原 VM (scard+tdc) 安全部署方案(19:35-19:50)
|
||||
- **目标**:按 `docs/scard/VM_DEPLOY.md` 复现"scard 安全平面 + TDC 连接器在 VM 内远程证明入网"的形态(印证上一条"tdc 须在 scard 安全方案内部署"红线)。
|
||||
- **关键踩坑(致命)**:`scard/code/bin/connector-linux-amd64` 实际是 **macOS Mach-O 二进制(被错误命名)**,在 Linux VM 内 `posix_spawn: no such file or directory` 无法执行。仓内唯一真 ELF 是 `connector-arm`(ARM,架构不符 amd64 VM)。**已交叉编译修正**:`cd scard/code && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/connector-linux-amd64 ./connector`(go1.26.1 可用,`file` 确认 ELF x86-64 statically linked),sha 已与主机一致。
|
||||
- **部署步骤(已验证)**:
|
||||
1. 主机起 `security-server -listen :8443 -tls-cert tls/server-cert.pem -tls-key tls/server-key.pem -data-dir scard-data -attestation-mode strict`(attestation-policy.json: allow_tofu=true + 预置 J7NODE-001 golden measurement)。
|
||||
2. 本地先跑 `connector`(darwin) 注册 → `J7NODE-VM-001` attest=tofu-recorded(验证协议)。
|
||||
3. `orbctl create --memory 4G --cpus 2 --disk 32G ubuntu j7node` 建 VM(约 2min,IP 192.168.139.95;宿主机在该 OrbStack 网段 IP=192.168.139.3,即 server 地址)。
|
||||
4. **文件传入 VM**:`orbctl push` 在本版(2.2.1)有 path-mangling bug(写只读 staging 路径失败);改用 `base64 -i 文件 | orb -m j7node bash -c 'base64 -d | sudo tee <dst> >/dev/null'`,并先 `sudo mkdir -p /opt/ssw/connector/tls /var/lib/connector-j7node`。
|
||||
5. VM 内运行 `connector-linux-amd64 --server https://192.168.139.3:8443 --device-id J7NODE-001 --tpm-type software --register --tls-ca /opt/ssw/connector/tls/ca-cert.pem --data-dir /var/lib/connector-j7node` → 状态机走完到 RUNNING,**attest=verified(golden 匹配 pcr_digest=e32cf860…)**。
|
||||
- **结果**:主机 `/api/v1/device/status` 列出 2 设备;审计 `audit_2026-08-13.jsonl` 记 `device_register / J7NODE-001 / success / ip_address=192.168.139.95`(VM IP)。=> "scard 安全平面 + TDC 连接器在 VM 内远程证明入网"端到端跑通。
|
||||
- **范围说明**:本次只复现 scard+tdc 安全平面(security-server + VM 内 connector)。VM_DEPLOY.md 里 k3s+j7-postgres+j7-redis+j7-admin 业务栈(TDS/TDC/SSWFLOW 运行时)未做——该部分在 VM 内网络风险高(docker.io 被墙需 daocloud mirror、github release 需 gh-proxy、<4G 必 OOM),且业务平面已用主机 fat-jar(full/tdc-only) 验证过,属独立待办。
|
||||
- **遗留/可选**:要不要顺手把 j7node 内的 k3s+j7-admin 业务栈也拉起来(重、可能踩网络坑)?待用户确认。
|
||||
|
||||
## TDS LicenseMapper SQL bug 修复(Task #39,本轮收尾)
|
||||
- **根因**:`LicenseController`/`CertController`/`QuotaController` 的 list() 把带 `orderByDesc("f_creator_time")` 的 QueryWrapper 直接传 `count(qw)`,MP 把 ORDER BY 原样拼进 `SELECT COUNT(*)`,PostgreSQL 报 `column f_creator_time must appear in the GROUP BY clause`。再叠加 `last("limit off,size")` 是 MySQL 专有逗号语法,PG 不认。
|
||||
- **修复(3 处同模板)**:先 `count(qw)` 再 `orderByDesc`;`limit` 改标准 `LIMIT n OFFSET m`(PG/MySQL 通用)。已落 `boot/ssw-tds/ssw-tds-controller/.../{License,Cert,Quota}Controller.java`。
|
||||
- **验证**:`mvn -o -P full clean install -DskipTests` BUILD SUCCESS;重启 full BE(30000) 后 admin token 调三个 list 端点均 **HTTP 200 code 200**(total/rows 正确分页,之前 code 400)。auth header 实测须 `bearer <jwt>`(token 字段已自带 `bearer ` 前缀,勿再叠加引号/前缀)。
|
||||
|
||||
## TDS bridge 内部端点实现(Task #38,7 个,供 TDC 聚合运营方全景)
|
||||
- **需求**:tdc-only 节点不连 TDS 库,但业务全景要聚合运营方 TDS 侧合约/连接器/数据产品/哈希链审计/链上存证/审核记录,并把自己的操作留痕汇聚到中枢。消费端是 `TdcTdsClient`(HTTP 实现 `HttpTdcTdsClient`)。
|
||||
- **路径决策**:现有 `ContractController/ConnectorController/DataProductController` 已占 `/api/ssw/tds/{Contract,Connector,DataProduct}`(含继承 GET `/{id}`),新桥接控制器若用同样路径会冲突。沿用 `DatasetInternalController` 的 `Internal` 范式,新建 **`TdsBridgeInternalController` @ `/api/ssw/tds/Bridge`**(GET `/Contract|Connector|DataProduct/{id}` + POST `/AuditChain|ChainEvidence|AuditRecord|AuditTrail`)。
|
||||
- **鉴权**:`@SaIgnore` + `exclude-url` 加 `/api/ssw/tds/Bridge/**`(绕过 JNPF AuthFilter)+ App-Code=tdc 白名单 + `X-Internal-Token: ${tds.internal-secret}`。
|
||||
- **复用装配器**(避免再写丢字段的组装):4 个聚合端点注入 `EvidenceAssembler`(auditChain/chainEvidences) / `AuditRecordAssembler`(auditRecords) / `AuditTrailRecorder`(record 写 tds_audit_log 哈希链);3 个 GET 从 Contract/Connector/DataProduct Entity 裁剪 Map(key 对齐 TDC 消费端:contractCode/quotaTotal/quotaUsed、connectorCode/name/status/orgName、providerConnectorId/status)。
|
||||
- **配套改动**:① `HttpTdcTdsClient` 7 条路径改 `/api/ssw/tds/Bridge/...`;② 3 个 base yml(`ssw-admin`/`dist/config`/`ssw-tdc-biz`)的 `exclude-url` 加 `/api/ssw/tds/Bridge/**` + 加 `tds.internal-secret: ""`。
|
||||
- **验证(full BE 30000,App-Code: tdc 直调,无需用户 token)**:7 端点全部 HTTP 200 —— GET 三维度返回"不存在"合理报文;POST AuditChain/ChainEvidence/AuditRecord 返回装配器标准结构(items/total/chainIntact/successCount…);POST AuditTrail 合法→`{recorded:true}`(实测写入 tds_audit_log),缺 bizType→400;无 App-Code→400 "App-Code invalid"。Bridge 端点仅在 full 部署存在(tdc-only 不含 ssw-tds,正确)。
|
||||
- **文件清单**:`boot/ssw-tds/ssw-tds-controller/.../TdsBridgeInternalController.java`(新) + `boot/ssw-tdc/.../client/HttpTdcTdsClient.java`(路径改) + 3 个 application.yml(exclude-url + tds.internal-secret)。
|
||||
|
||||
## j7node 业务栈真正拉起(k3s + j7-admin,本日收尾,用户确认要做)
|
||||
- **实证状态(2026-08-13 晚,`orb -m j7node k3s kubectl` 验证)**:
|
||||
- `k3s get nodes` → j7node Ready(v1.30.5+k3s1,systemd 常驻绕过 OrbStack session 回收)。
|
||||
- 3 Pod 全 Running:`j7-postgres-0`(StatefulSet,3Gi) / `j7-redis` / `j7-admin`(Deployment,NodePort 31000→33000)。
|
||||
- 三库 schema 恢复(j7=123 表 / j7flow_node1=13 表 / tdc_node1=33 表),j7 全量 seed(admin/123456 可登,base_user=276 等忠实复制)。
|
||||
- **admin 登录 + 业务端点实测(mac 直连 192.168.139.95:31000)**:
|
||||
- `LOGIN admin/123456` → 200;`/api/ssw/tdc/DeliveryTask` → 200;`/api/ssw/sswflow/Party/Self` → 200。
|
||||
- `/api/ssw/tdc/Party/Self` 与 `/api/ssw/tdc/Connector` → **HTTP 200 但 code 400 "System abnormality"**。
|
||||
- **登录加密实测坑(务必记牢)**:`web/src/utils/cipher.ts` 的 `encryptPassword` = `md5(plain)` 字符串 → AES-256-ECB-Pkcs7 → **hex**(非 base64!);key=`md5(CIPHER_KEY)` 32字节UTF8。自测常量 `encryptPassword('123456')=='d4958348e22108119b3ef57b022c83f4bf857dd0b247eaab15b9a43d47ee3c503900f7135bf0de255bc33620c3cdc02b'`。**Login 响应的 `data.token` 已自带 `bearer ` 前缀**,auth header 须原样传 `Authorization: <data.token>`(不要再叠加引号或第二个 `bearer `,否则 600 Login expired)。另需带 `App-Code/Jnpf-Origin:pc/Vue-Version:3` 头。
|
||||
- **重要复查(推翻初判)**:最初报的「/tdc/Party/Self、/tdc/Connector 两个 400 因红线冲突」是**探针 URL 写错造成的假象**,非真实功能故障:
|
||||
- 前端(jweb)只用 `/api/ssw/sswflow/Party/Self`(实测 200) 与 `/api/ssw/tds/Connector/...`(运营方 TDS 专属页面,纯 TDC 节点本就不该有→400 符合红线);轻量 `web/src/api` 只有 auth/request,**无任何业务 API 定义**。
|
||||
- `/tdc/Sandbox`、`/sswflow/FlowRun` 的 400 是缺 action 段(如 `/Sandbox/List`)导致的 404→400(日志原文 `No static resource api/ssw/tdc/Sandbox.`),非功能失败。
|
||||
- 日志里周期性 `CannotFindDataSource: tds` 来自**后台 TDS 调度任务**(NotifyTicker 等随 full fat-jar 加载,j7node 未配 tds 数据源)→ 仅日志噪音,不影响 TDC 业务;属「full jar 在 tdc 节点加载了 tds bean」这一已知架构 smell。
|
||||
- **结论**:j7node TDC 节点业务栈**全绿**——真实 tdc/sswflow 端点(DeliveryTask/Contract/Order/Space/Member/Identity/Resource/Demand/Product/Role、sswflow/Party/Self/Dataset 等)均 200。**无需按 TdcTdsClient 重构**(原前提为假)。可选后续:构建 tdc+sswflow-only jar 或排除 tds 自动配置,消除 tds 调度噪音(中等工作量,非必须)。
|
||||
- **清单**:`scard/code/bin/k8s/{00-namespace,05-pg-init,10-postgres,20-redis,30-admin}.yaml` + `boot/ssw-admin/target/config/application-j7node.yml`(hostPath 挂进 pod /config/)。full fat-jar 经 hostPath 挂入 pod(含 ssw-tds 类,故 tds 控制器被加载但无数据源)。
|
||||
- **验收端点矩阵(final, 2026-08-13 收尾,mac 直连 192.168.139.95:31000, admin token)**:
|
||||
| 端点 | 结果 |
|
||||
|---|---|
|
||||
| LOGIN admin/123456 | 200 ✅ |
|
||||
| /api/ssw/tdc/DeliveryTask | 200 ✅ |
|
||||
| /api/ssw/tdc/Contract | 200 ✅ |
|
||||
| /api/ssw/tdc/Order | 200 ✅ |
|
||||
| /api/ssw/tdc/Space | 200 ✅ |
|
||||
| /api/ssw/tdc/Member | 200 ✅ |
|
||||
| /api/ssw/tdc/Identity | 200 ✅ |
|
||||
| /api/ssw/tdc/Resource | 200 ✅ |
|
||||
| /api/ssw/tdc/Demand | 200 ✅ |
|
||||
| /api/ssw/tdc/Product | 200 ✅ |
|
||||
| /api/ssw/tdc/Role | 200 ✅ |
|
||||
| /api/ssw/sswflow/Party/Self | 200 ✅ |
|
||||
| /api/ssw/sswflow/Dataset | 200 ✅ |
|
||||
| /api/ssw/tdc/Party/Self(非真实路由,探针假象) | HTTP200 code400 ⚠️ |
|
||||
| /api/ssw/tdc/Connector(非真实路由,探针假象) | HTTP200 code400 ⚠️ |
|
||||
- **状态**:j7node 业务栈 ✅ 已收尾(k3s Ready / 3 Pod Running / j7 全量 seed / 真实 tdc+sswflow 端点全绿)。无需 TdcTdsClient 重构(初判前提为假)。可选后续:构建 tdc+sswflow-only jar 或排除 tds 自动配置,消除 tds 调度噪音(详见 VM_DEPLOY.md §6/§8)。
|
||||
- **对应文档**:`docs/scard/VM_DEPLOY.md` 已据本轮实测更新(IP 校正 192.168.139.95、§3.1 数据库初始化、§6 待办状态、§8 验收矩阵+登录加密+400 假象澄清、§9 可选增强)。
|
||||
+22
-105
@@ -1,110 +1,27 @@
|
||||
# SSWFlow 项目笔记(精简索引;细节见 memory/YYYY-MM-DD.md 与 refs/docs)
|
||||
# SSWFlow 项目笔记(精简索引;细节见 memory/YYYY-MM-DD.md 与 docs/)
|
||||
|
||||
## 项目本体 (Project Ontology, 2026-08-12 决策)
|
||||
|
||||
- 走 `docs/project.duckdb` (起步 sqlite) + `pkit` CLI;落地文档 `docs/PROJECT_ONTOLOGY_PLAN.md`
|
||||
- 5 实体 7 表:`requirements / testcases / implementation / defects / data_entities / apis + release_milestones + test_runs + gate_results`
|
||||
- 铁律 L2:**唯一允许写库的是 `pkit` CLI**;人手 `sqlite3` 编辑会污染
|
||||
- 铁律 L5:MD 永不删,改 `obsoleted/` 归档;DB 加 `obsoleted_at` 列
|
||||
- ssw-loop 7 阶段产物(testcase/summary/关卡结果)改写 `pkit`,关卡从 `ls` 改 `gate_results.status=PASS`
|
||||
- AGENTS.md/SOUL.md 加前置:**agent 改代码前必跑 `pkit impact <path>`**
|
||||
- 拍板点(完整见 2026-08-12.md):sqlite/duckdb、CLI 用 Python 还是 Go、是否提成 skills/ssw-ontology
|
||||
|
||||
## 与 ssw-ontology 平台共生 (业务本体↔项目本体)
|
||||
|
||||
- ssw-ontology 平台(`~/Desktop/know/ssw-ontology/`, Go+Postgres+Vue3, 端口 8082)是**业务对象本体**,跟 pkit **不同层**,不合并
|
||||
- 强化 AI 理解力 5 条路径(详见 PROJECT_ONTOLOGY_PLAN.md §9):
|
||||
A 把 FL-/TP-/业务概念灌 ontology ObjectType
|
||||
B ontology 已自动注册 6 个 MCP 接口,AI 直接接
|
||||
C pkit REQ ↔ ontology Object 双向 `external_ref`
|
||||
D pkit 命名复用 ontology LinkType
|
||||
E pkit 写入触发 ontology audit log
|
||||
- 新增 **Phase 0.5**(1 天,pkit ontology 适配层,黑盒消费 REST):pull/push/concept-lookup 三命令
|
||||
- 拍板点(共生):6 共生而非合并、7 加 Phase 0.5、8 FL/TP 灌 ontology 的优先级
|
||||
|
||||
## pkit ontology-runtime (2026-08-12 08:05 落地)
|
||||
|
||||
- `~/Desktop/ssw/tools/ontology-runtime/`:把 know/ssw-ontology 二进制复制一份独立跑,作为 pkit 业务能力后端
|
||||
- 完全独立:**HTTP_PORT=8088**、**DB=shangshu_pkit**(15432 上新建)、**ARCHIVE_DIR 本地**。原 8082/原 shangshu 库不碰
|
||||
- 启动方式:**Python 双 fork + setsid** (`start.py`),macOS 上 `nohup &` 在工具链下不稳,父 shell exit 会收尸; daemon 化后 PPID=1
|
||||
- 命令:`start.sh / stop.sh / status.sh`;状态:pidfile + lsof 端口 + HTTP probe
|
||||
- 已验证接口:`/api/v1/ontology/object-types` (12 个)、`/link-types` (8 个)、`/api/v1/mcp/manifest` (6 个 MCP tool)
|
||||
- 业务字典已可用:DataProduct/TrustedDataSpace/DataResource/DataDemand/DataExchange/MemberOrg/AppScenario/Branch/Appliance/IPAsset/Service/NewsArticle
|
||||
- 与原 ssw-ontology 同 binary 不同实例,**改源不影响这边**,要更新 binary 时 `cp know/ssw-ontology/bin/server tools/ontology-runtime/bin/server`
|
||||
|
||||
## pkit 项目本体 CLI (2026-08-12 08:50 全 5 阶段落地)
|
||||
|
||||
- 位置:`~/Desktop/ssw/pkit/` (Go module,16.9MB binary)
|
||||
- 库:`~/Desktop/ssw/docs/project.duckdb` (sqlite WAL,schema version 2)
|
||||
- 命令全表见 `pkit/README.md`;11 个子命令 (sync/req/coverage/defect/milestone/gate/ontology/dashboard/...)
|
||||
- migration:`internal/db/migrations/{001,002}_*.sql`,embed.FS 自动按 version 增量 apply
|
||||
- **跨表软引用**(无硬 FK):require cases → requirements → implementation 用 code 字符串
|
||||
- ssw-loop 闸门桥接:`pkit gate run-start/record/check` 取代原 5 个 ls 看 file 齐不齐的脚本
|
||||
- Phase 0.5 ontology 适配:`pkit ontology concept-lookup/push/pull` 三个命令,实测通过
|
||||
- 实测数据:177 req / 344 tc / 1306 impl / 1 defect / 1 milestone / 1 run (K=PASS A=FAIL)
|
||||
- 关键修复:FK 强制约束 → MD 灌库顺序崩,改软引用
|
||||
- 与 ssw-ontology 共生:本仓库调同 binary 8088 instance,不碰 8082 原版
|
||||
## 架构与部署(跨会话必看)
|
||||
- 单 `ssw-admin` fat-jar 聚合 TDS/TDC/SSWFLOW 三子系统;Maven profile 区分:`full`(默认,含三) / `tdc-only`(只TDC) / `sswflow-only`(预留)。config/ 外挂 yml。
|
||||
- **构建铁律**:`ssw-*-(biz|controller|entity)` 都是普通 library jar,**只有 `ssw-admin` 做 spring-boot repackage**。任何 biz 模块若误加 repackage → 装成 BOOT-INF fat-jar 进 .m2 → 依赖它的模块从 .m2 解析时类在 BOOT-INF/classes 下找不到 → 编译报"程序包不存在"。(2026-08-13 踩坑:`ssw-tdc-biz` 曾误加 repackage 做 V1.5.9 standalone fat-jar,已移除,因与"单 ssw-admin jar"部署模型冲突。)
|
||||
- 工作目录每轮 Bash 重置回 `/Users/xs/Desktop/ssw`,构建须 `cd /Users/xs/Desktop/ssw/boot &&`。父 reactor 在 `boot/`(artifactId `ssw-boot`)。
|
||||
- `full` profile 的 `activeByDefault` 会被 `boot3`(jdk[17,)) 自动激活而**失效**;构建 full 必须显式 `-P full`,否则只含 tdc。
|
||||
- TDC 对 TDS 跨系统读/写走 `TdcTdsClient`(HTTP, 配 `ssw.tds.base-url` 走 Http 实现, 否则 Noop 降级);TDC 编译期零 `ssw.tds.*` 硬依赖。tdc-only jar 实测仅含 ssw-tdc-*(3 jar),full jar 含 tds+tdc+sswflow 各3 jar。
|
||||
- **TDS 侧出口** = `TdsBridgeInternalController` @ `/api/ssw/tds/Bridge/**`(7 端点:GET Contract/Connector/DataProduct,POST AuditChain/ChainEvidence/AuditRecord/AuditTrail),复用 `EvidenceAssembler`/`AuditRecordAssembler`/`AuditTrailRecorder`;鉴权 App-Code=tdc + `X-Internal-Token: ${tds.internal-secret}`,`exclude-url` 已放行。仅 full 部署存在(tdc-only 不含 ssw-tds)。
|
||||
- 🚫 **红线:禁止 TDS-TDC 强耦合。** TDC 永不在编译期依赖 `ssw-tds` 模块(不得在 `ssw-tdc-*` 的 pom 引入 `ssw-tds-*`;跨系统读写只能经 `TdcTdsClient` HTTP 抽象,base-url 缺失时 Noop 降级,绝不 import TDS Service/Entity)。全 `ssw-tdc` 模块的 `@DS` 必须为 `@DS("tdc")`,零 `@DS("tds")`。
|
||||
- **正式部署 TDC 须落在 `scard` 安全方案内**:TDC = 数据持有方本地连接器,出厂即按 `scard/`(Go 安全平面: server+connector, 软PKI+软TPM) + `docs/scard/VM_DEPLOY.md` 的 connector/VM 范式部署,**不当普通 web 服务裸跑**。本机 `ssw-admin` 单 jar 仅供开发联调,不是 TDC 正式部署形态。
|
||||
|
||||
## 启动
|
||||
- BE: `cd boot && java -DDB_HOST=127.0.0.1 -DDB_PORT=15432 -DREDIS_HOST=127.0.0.1 -DREDIS_PORT=16379 -Dserver.port=30000 -jar ssw-admin/target/ssw-admin-7.0.0-RELEASE.jar`(端口必 30000,Redis DB=8)。**必须 run_in_background 才有宿主机网络**。
|
||||
- FE: jweb/apps/jnpf-web-apps-main `pnpm dev`(3000);web `pnpm dev`(5173)。DB: PG sswflow/tds/tdc public schema,192.168.97.3:5432 dacli/dacli123→本地15432;Redis16379。Python 用 `/Users/xs/.workbuddy/binaries/python/versions/3.13.12/bin/python3`。
|
||||
- BE: `cd boot && java -DDB_HOST=127.0.0.1 -DDB_PORT=15432 -DREDIS_HOST=127.0.0.1 -DREDIS_PORT=16379 -Dserver.port=30000 -jar ssw-admin/target/ssw-admin-7.0.0-RELEASE.jar`(端口必30000,Redis DB=8,须 run_in_background 才有宿主机网络)。
|
||||
- FE: jweb `pnpm dev`(3000);web `pnpm dev`(5173)。
|
||||
|
||||
## TDS × SSWFLOW 胶水(2026-08-13 全 V0–V1.4 落地)
|
||||
- 方案:`docs/tds/SSWFLOW_BINDING.md`。架构原承诺"SSWFLOW 被合约驱动调用",胶水代码 08-13 一次性全部落地(V0 + V1.1–V1.4)。
|
||||
- **触发链(V0+V1.1)**:合约双签 → `ContractSswflowTrigger` 解析 `f_policy_content.sswflowFlowId` → `SswflowClient.startRun` → 调 `FlowRunInternalController.Start`(`App-Code: tds` + `X-Internal-Token`)→ 回写 `tds_contract.f_flow_run_id`。
|
||||
- **回调链(V0)**:`FlowRunServiceImpl.runOnce()` 终态 → `TdsCallbackClient.notifyRunTerminal()` → `RunCallbackController` → `RunCallbackService` 写 `tds_chain_evidence`(bizType=SSW_FLOW_RUN_FINISH)。
|
||||
- **dataset 同步(V1.2)**:DataProduct 上架 → `DataProductDatasetSyncer` → `DatasetInternalController.Sync`(按 `f_external_ref="tds:dataProduct:<id>"` upsert)。
|
||||
- **对账调度(V1.3)**:`FlowRunReconciliationScheduler` `@Scheduled` cron 凌晨 3 点扫描"合约 EFFECTIVE + runId 非空 + 没 billing_ledger"漏单 → `SswflowClient.getRun` → 终态则写 `tds_billing_ledger` + 更新 `f_quota_used`。
|
||||
- **TDC 触发链(V1.4)**:DeliveryTask 新增 `/TriggerFlow` → `TdcSswflowClient.startRun` → `FlowRunInternalController.Start`(`App-Code: tdc`,trigger=DELIVERY_DIRECT,绕开合约)。
|
||||
- **内部端点矩阵**(所有 `exclude-url` 绕过 JNPF AuthFilter):
|
||||
- `POST /api/ssw/sswflow/FlowRun/Internal/Start`(白名单 App-Code: tds/tdc)
|
||||
- `GET /api/ssw/sswflow/FlowRun/Internal/Get/{runId}`
|
||||
- `POST /api/ssw/sswflow/FlowRun/Internal/Stop/{runId}`
|
||||
- `POST /api/ssw/sswflow/Dataset/Internal/Sync`
|
||||
- **配置项**:`ssw.sswflow.{enabled,base-url,internal-secret,timeout-seconds}` + `ssw.tds.callback.{enabled,url,secret,timeout-seconds}` + `sswflow.internal-secret` + `ssw.reconciliation.{enabled,cron}`。
|
||||
- **DB 变化(3 个 migration)**:
|
||||
- `boot/db/tds/V1.4.0__tds_contract_flow_run_id.sql`(tds_contract 加 f_flow_run_id + 索引)
|
||||
- `boot/db/tds/V1.5.0__tds_billing_ledger_run_id.sql`(tds_billing_ledger 加 f_run_id + 索引)
|
||||
- `boot/db/sswflow/V1.1.0__dataset_external_ref.sql`(dataset 加 f_external_ref + 唯一索引)
|
||||
- **关键修复**:V1.3 调试中发现 `SswflowClient.getRun/stopRun` 路径写错(漏 `Internal` 前缀),e2e 验证时捕获修复;V1.3 还需 `BillingLedgerEntity.f_run_id` 字段(不能用 `f_period` 装 runId,varchar(20) 太短)。
|
||||
- **e2e 已验证**(2026-08-13 全链路):
|
||||
1. **V0 回调**:chain_evidence 写入 SSW_FLOW_RUN_FINISH 2 行
|
||||
2. **V1.1 触发**:合约 → 真实 flow_run 创建 → runId 回写 tds_contract ✓
|
||||
3. **V1.2 数据产品上架 → dataset 同步**:f_external_ref='tds:dataProduct:...' upsert 成功 ✓
|
||||
4. **V1.3 对账兜底**:漏单合约自动补 billing_ledger + f_quota_used++ + 幂等(第二轮跳过)✓
|
||||
5. **V1.4 TDC 直触发**:DeliveryTask /TriggerFlow → 真实 flow_run(trigger=DELIVERY_DIRECT)✓
|
||||
## 鉴权 / DB / 权限(踩坑高频)
|
||||
- AES-256-ECB-PKCS7, key=md5(CIPHER_KEY) 前32字节UTF8; 明文 md5(plain); token 头引号包裹(含空格)。
|
||||
- public schema, 主键 f_id, 基类10列。禁 @Transactional。软删 Tdc 认(NULL|0)、Tds 只认 NULL;**勿给 TDS 设 setDeleteMark(0)**。@DS 严格模式 Controller+Service 显式 bean 名。
|
||||
- 控制器名(去Controller小写)须匹配菜单 urlAddress 末段;管理员(is_administrator=1)短路。菜单↔控制器不匹配=400 高频根因。改 j7.base_authorize 后**必须重启 BE**。
|
||||
|
||||
## 前端双栈(真源 jweb)
|
||||
- 真源 `jweb/apps/jnpf-web-apps-main/src/views/ssw/**`;`web/src/views/ssw` 软链。真源用 `@/views/ssw/*`,禁 `@ssw*` 别名。web 唯一适配 `web/src/api/request.ts` 导出 defHttp。
|
||||
- antd 补全:`views/ssw/registerSswComp.ts`+`bootstrap.ts`,jweb 平台层唯一改动,须 `git add -f`。
|
||||
- jweb vendor dotfiles 被根 `.gitignore` `jweb/.*` 通配忽略(apps/ 业务源码不受影响)。新增 ssw 文件须 `git add -f`。
|
||||
|
||||
## DAG e2e(2026-08-10 多用户 21/21 通过)
|
||||
- 默认 web/5173,FE_BASE 见 `docs/e2e/lib/config.mjs`。节点操作=真实人类模拟(docs/e2e/lib/human.mjs),API 触发的保留程序化。
|
||||
- 多用户:每泳道独立 newContext() 缓存隔离,PARTICIPANTS 泳道→真实账号在 dag-panel.mjs。面板默认 `open:false`(避免 OOM 杀主浏览器+BE)。send() 吞 SSE 断开错误;观测 `results/dag-runs/<runId>.json`。
|
||||
- a-modal 渲染为 `.ant-tabs-root`(非 `.ant-modal`);`_visibleDialog()` 收口优先级 `.ant-modal > .ant-tabs-root > .ant-drawer-body > .ant-popover-inner`。
|
||||
|
||||
## jweb 入口
|
||||
- 动态路由 generateAccess() 按菜单 urlAddress 映射;应用/菜单用 dacli。systemId: tdc=855102050973782405 / tds=855102009768939909 / sswflow=853028206192623813。
|
||||
|
||||
## 静态页
|
||||
- Marketing 落地页放 `public/ssw-tds/index.html` 自包含,jweb vite.config 加 ssw-portal-static 插件直抛 `res.end()` 不 next()。禁用 import.meta.url 拼路径、禁用 rewrite+next()。
|
||||
|
||||
## 鉴权
|
||||
- AES-256-ECB-PKCS7,key=md5(CIPHER_KEY) hexdigest 转 UTF8 32字节(非 16 字节 digest);明文 md5(plain)。openssl 登录 `-K` 须展开 64 hex。token 头须引号包裹(含空格)。
|
||||
|
||||
## DB 铁律
|
||||
- public schema,主键 f_id,基类 10 列。禁 @Transactional;软删 Tdc 认 (NULL|0)、Tds 只认 NULL。**勿给 TDS 设 setDeleteMark(0)**。@DS 严格模式 Controller+Service 显式 bean 名。
|
||||
|
||||
## DB 导出
|
||||
- 应用库 schema-only(业务数据不入 git);j7 库 schema+应用配置(scripts/export_j7_platform.py)。重建顺序见 docs/db/README.md。
|
||||
|
||||
## 引擎/TEE
|
||||
- Nax MPC、k8s 沙箱、FISCO-BCOS 存证。TEE=SEV-SNP 机密虚拟机,CDH 正路 remote attestation,四必须(8006 仅/cdh/*、禁 hostNetwork、kata 注 aa_kbc_params、TCP 探活)。详见 refs/tee/TEE_E2E_RUNBOOK.md。
|
||||
|
||||
## 权限守卫(跨会话必看)
|
||||
- 控制器名(去 Controller 小写)须匹配菜单 urlAddress 末段;管理员(is_administrator=1)短路放行。菜单↔控制器不匹配=400 高频根因(如 /tdc/sandbox 菜单 SandboxView≠DeliveryTaskController,须 DeliveryTaskView)。
|
||||
- userModuleCache 是内存缓存,改 j7.base_authorize 后**必须重启 BE**(f_item_type='module'、f_object_type='role'、f_tenant_id='0'、f_id=uuid.int[:19])。
|
||||
|
||||
## Git
|
||||
- 远端 http://192.168.1.18:13300/ssw/ssw-mvp 分支 main。`failed to store:100001` 仅凭据助手警告,推送成功。排除 docs/e2e/results/;.workbuddy/memory/* 入库。跨 agent 软链 .claude/{memory,skills}→.workbuddy/{memory,skills}。
|
||||
## 其他子系统(细节见各日 md)
|
||||
- 项目本体 `pkit` CLI + `ssw-ontology` 平台共生:见 2026-08-12.md。
|
||||
- TDS×SSWFLOW 胶水 V0–V1.5:见 2026-08-13.md + `docs/tds/SSWFLOW_BINDING.md`(e2e 全链路已验证)。
|
||||
- 前端双栈真源 jweb(`web/src/views/ssw` 软链);DAG e2e;V1.5 Nax sidecar 化(原始数据不出域):见对应日 md。
|
||||
- Git 远端 main;跨 agent 软链 `.claude/{memory,skills}`→`.workbuddy/`。
|
||||
- **scard 安全平面 + TDC 连接器 VM 部署**(详见 2026-08-13.md):`scard/code/bin/security-server`(:8443, 软PKI+golden measurement) + `connector`(TDC 本地代理) 远程证明入网。⚠️ `connector-linux-amd64` 曾被误标为 macOS Mach-O,**必须 `cd scard/code && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/connector-linux-amd64 ./connector` 重编**;VM 传文件用 `base64 -i|orb -m j7node bash -c 'base64 -d|sudo tee'`(`orbctl push` 2.2.1 有 path bug);宿主机 OrbStack 网段 IP=192.168.139.3 即 server 地址,VM 可达。
|
||||
@@ -37,9 +37,12 @@ This file provides guidance to AI coding agents (Claude Code, Aider, Cursor, Cod
|
||||
|
||||
**关键原则**:
|
||||
- TDS(运营方中枢) ↔ TDC(数据持有方本地) ↔ SSWFLOW(密态计算执行后端)三足鼎立,**数据不经平台**,TDC 之间点对点交付。
|
||||
- 🚫 **红线:禁止 TDS-TDC 强耦合。** TDC **永远不**在编译期依赖 `ssw-tds` 模块——不得在 `ssw-tdc-*` 的 pom.xml 引入 `ssw-tds-*`;跨系统读/写只能经 `TdcTdsClient` HTTP 抽象(`ssw.tds.base-url` 配则走 `HttpTdcTdsClient`,缺则 `NoopTdcTdsClient` 降级),**绝不允许 import TDS 的 Service / Entity / Mapper**。全 `ssw-tdc` 模块的 `@DS` 必须为 `@DS("tdc")`,零 `@DS("tds")`。Maven `tdc-only` profile 打包出的 fat-jar 必须不含任何 `ssw-tds-*` / `ssw-sswflow-*` 类,否则视为强耦合回归(回归验证见 `boot/dist/bin/verify_*` 与每日日志)。
|
||||
- SSWFLOW 算法算子从 V0.13 起走真实 Nax 引擎(`engine="mpc"`),通过 `ProcessBuilder` 调 `boot/ssw-sswflow/ssw-sswflow-biz/src/main/resources/nax/nax_adapter.py`。
|
||||
- TDC 多虚拟连接器通过 JNPF 内置 `f_tenant_id` 隔离,**复用平台租户字段不单独设计**。
|
||||
|
||||
> **部署形态红线**:本机 `ssw-admin` 单 fat-jar 仅供**开发联调**,**不是 TDC 的正式部署形态**。TDC 作为数据持有方本地连接器,**正式部署必须落在 `scard` 安全方案内**(`scard/` Go 安全平面 server+connector,软 PKI + 软 TPM;部署范式见 `docs/scard/VM_DEPLOY.md` 与 `scard/CLAUDE.md`),按"数据可用不可见"安全模型交付,不当普通 web 服务裸跑。
|
||||
|
||||
## 命令速查
|
||||
|
||||
### 后端(必须在 `boot/` 目录)
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
# SSW-Nax-Runtime — TDC 默认隐私计算镜像(V1.5.1)
|
||||
#
|
||||
# Build context: 仓库根 (/) → docker build -f boot/docker/ssw-nax-runtime/Dockerfile .
|
||||
# 镜像职责:
|
||||
# 1. TDC 沙盒 Pod 用这个镜像作为容器运行时(替代原 k8s.tee-image=python:3.11-slim)
|
||||
# 2. 镜像里内置 Nax Python 包 + nax_adapter.py(stdin/stdout JSON 协议)
|
||||
# 3. 容器启动后接受 Java 端下发的算子 JSON 描述,返回密态计算结果
|
||||
#
|
||||
# 镜像体积(dev minimal):约 1.2GB(python:3.11-slim + numpy + pandas + nax 包)。
|
||||
# 生产镜像待优化:distroless / 多阶段构建 / 预编译 wheel。
|
||||
#
|
||||
# V1.5 边界:
|
||||
# - TEE 模式(kata)走另一套:refs/tee/image/ssw-tee-compute/(compute.py + CDH + KBS)
|
||||
# - 默认模式(NAX / BOTH)走本镜像:Nax 算法 + 集群默认 runtime
|
||||
# - SSWFLOW 中心的 NaxComputeEngine 已标 dev-only(@Profile("dev")),生产路径是本镜像
|
||||
#
|
||||
# 详见 docs/tds/SSWFLOW_BINDING.md §11 V1.5
|
||||
|
||||
FROM python:3.11-slim
|
||||
|
||||
LABEL maintainer="SSW-TDC <[email protected]>" \
|
||||
org.opencontainers.image.title="ssw-nax-runtime" \
|
||||
org.opencontainers.image.description="TDC 默认隐私计算运行时(Nax 算法 + stdin/stdout JSON 协议)" \
|
||||
org.opencontainers.image.version="0.1.0-dev"
|
||||
|
||||
# 镜像内工作目录
|
||||
WORKDIR /opt/ssw-nax
|
||||
|
||||
# 系统依赖:build-essential 用于某些 Python 包编译;curl 用于健康检查
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
curl \
|
||||
&& \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 1) 装 Nax 运行时依赖(dev minimal:只装核心 numpy + pandas,dev 用)
|
||||
COPY nax/ /opt/ssw-nax/nax-src/
|
||||
RUN pip install --no-cache-dir --upgrade pip && \
|
||||
pip install --no-cache-dir numpy pandas && \
|
||||
pip install --no-cache-dir --no-deps -e /opt/ssw-nax/nax-src/ && \
|
||||
rm -rf /opt/ssw-nax/nax-src/tests /opt/ssw-nax/nax-src/.pytest_cache
|
||||
|
||||
# 2) 装 nax_adapter.py(stdin/stdout JSON 协议,SSWFLOW resources 里的开发态副本)
|
||||
# 注意:boot/ssw-sswflow/ssw-sswflow-biz/src/main/resources/nax/nax_adapter.py
|
||||
# 是 Java NaxComputeEngine 调用的开发态适配器,镜像里复制一份作为容器入口
|
||||
COPY boot/ssw-sswflow/ssw-sswflow-biz/src/main/resources/nax/nax_adapter.py /opt/ssw-nax-runtime/nax_adapter.py
|
||||
RUN chmod +x /opt/ssw-nax-runtime/nax_adapter.py
|
||||
|
||||
# 3) 健康检查端点(最小:能 import nax 就算 ok)
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
CMD python -c "import nax; print('nax ok')" || exit 1
|
||||
|
||||
# 4) 环境变量:让 nax_adapter.py 能找到 Nax 包
|
||||
ENV PYTHONPATH=/opt/ssw-nax-runtime
|
||||
ENV NAX_HOME=/opt/ssw-nax
|
||||
ENV NAX_BACKEND=local
|
||||
|
||||
# 5) 入口:从 stdin 读算子 JSON,stdout 输出结果 JSON
|
||||
# TDC K8sSandboxClient.submitTeeJob 通过 stdin 把 StepContext 序列化后喂入
|
||||
ENTRYPOINT ["python", "/opt/ssw-nax-runtime/nax_adapter.py"]
|
||||
CMD []
|
||||
|
||||
# 元信息
|
||||
ARG BUILD_DATE=unknown
|
||||
LABEL org.opencontainers.image.created="${BUILD_DATE}"
|
||||
+65
-20
@@ -31,26 +31,13 @@
|
||||
<artifactId>ssw-common-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- SSWFlow 隐私计算平台 (2026-07-31) -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-sswflow-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- TDS 可信数据空间管理服务平台 (2026-08-02) -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tds-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- TDC 数据接入连接器 (2026-08-02).
|
||||
一体化部署时随 ssw-admin 起; 后续独立部署时把这条依赖挪到独立的 tdc-admin 启动模块,
|
||||
业务代码不用动 —— 这也是 TDS/TDC 之间只走 mTLS HTTP 契约接口、不直接注入 Service 的原因。 -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tdc-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- 三子系统依赖 (TDS/TDC/SSWFLOW) 已迁移到下方 <profiles> 段, 通过 -P full / -P tdc-only 切换:
|
||||
full (default, activeByDefault=true): 三子系统全部打入 fat jar —— 运营方主节点
|
||||
tdc-only (-P tdc-only 激活): 只打入 TDC —— 数据持有方本地节点
|
||||
sswflow-only (-P sswflow-only 激活, 2026-08-13 预留): 只打入 SSWFLOW —— 密态计算节点
|
||||
设计原因: 三子系统之间完全走 HTTP 契约 (TdcSswflowClient 等), 无任何 import 跨边界,
|
||||
故 Maven 依赖图决定 Bean 上下文, 即可控制哪些 Controller / @DS / Mapper 装载.
|
||||
数据库连哪些库由 application-role-{full,tdc}.yml 的 dynamic.datasource 控制. -->
|
||||
<!-- v7.0 升级 (2026-07-31): ssw-tdd3 模块目录空, 不再依赖 ssw-tdd3-biz (无 jar).
|
||||
历史保留: 6.2 boot/jnpf-admin 引过 ssw-tdd3-biz (no-spa-page 网站后端业务包), 7.0 跟随目录删除一起断引. -->
|
||||
<!-- <dependency>
|
||||
@@ -205,6 +192,64 @@
|
||||
</dependencies>
|
||||
<id>boot2</id>
|
||||
</profile>
|
||||
|
||||
<!-- ============================================================
|
||||
部署角色 profile (2026-08-13 落地)
|
||||
控制 ssw-tds / ssw-tdc / ssw-sswflow 三块业务子系统的 fat jar 包含关系
|
||||
默认 full (运营方全量); tdc-only 用于数据持有方; sswflow-only 预留
|
||||
配合 application-role-{full,tdc,sswflow}.yml 控制连哪些库
|
||||
============================================================ -->
|
||||
<profile>
|
||||
<id>full</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<!-- 运营方主节点: TDS + TDC + SSWFLOW 全量 -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-sswflow-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tds-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tdc-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>tdc-only</id>
|
||||
<dependencies>
|
||||
<!-- 数据持有方本地节点: 只 TDC, 不含 TDS / SSWFLOW.
|
||||
TDC 与运营方 TDS 的所有跨系统读/写 (上游合约/连接器/产品/审计链/存证 + 留痕) 统一走
|
||||
ssw.tdc.client.TdcTdsClient (HTTP 客户端, 未配 ssw.tds.base-url 时 NoopTdcTdsClient 静默降级),
|
||||
故 TDC jar 一行 ssw.tds.* 都不留, 运行时也不需要连 TDS 库.
|
||||
TDC 调 SSWFLOW 同样走 HTTP 客户端 (TdcSswflowClient), 无 class 依赖.
|
||||
配套 application-tdc.yml 只挂 tdc_node1 (继承 master=j7), 不挂 tds / sswflow / j7flow. -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tdc-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>sswflow-only</id>
|
||||
<dependencies>
|
||||
<!-- 密态计算节点 (预留, 2026-08-13 尚未启用): 只 SSWFLOW -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-sswflow-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>default-package</id>
|
||||
<activation>
|
||||
|
||||
@@ -8,9 +8,11 @@ spring:
|
||||
application:
|
||||
name: ssw-admin # 应用名称,用于服务注册/发现、日志目录等标识
|
||||
profiles:
|
||||
# 指定激活的环境配置文件(默认加载 application-{active}.yml)
|
||||
# 可选值:dev(开发环境-默认)、test(测试环境)、preview(预生产)、prod(生产环境)
|
||||
active: dev
|
||||
# 默认激活 dev 环境 + full 角色 (运营方全量)。
|
||||
# 数据持有方节点覆盖为: --spring.profiles.active=dev,tdc (或 prod,tdc)
|
||||
# 角色 profile yml 在 application-{role}.yml, Maven profile 控制打哪些子系统 jar.
|
||||
# 可选值: env=dev|test|preview|prod / role=full|tdc|sswflow
|
||||
active: dev,full
|
||||
# 文件上传配置(Spring Servlet 多文件上传)
|
||||
servlet:
|
||||
multipart:
|
||||
@@ -203,6 +205,8 @@ gateway:
|
||||
- /api/ssw/sswflow/FlowRun/Internal/**
|
||||
# tds → sswflow 内部 dataset 同步(上架数据产品时):App-Code + X-Internal-Token [TDS-SSWFLOW-BINDING §10 V1.2]
|
||||
- /api/ssw/sswflow/Dataset/Internal/**
|
||||
# tdc → tds 内部桥接(业务全景聚合):App-Code=tdc + X-Internal-Token [TDC 跨系统读 §Bridge]
|
||||
- /api/ssw/tds/Bridge/**
|
||||
white-ip: # 允许访问block-url的IP白名单(支持网段,如192.168.)
|
||||
## 配置示例:
|
||||
# - 192.168.
|
||||
@@ -259,6 +263,10 @@ fisco:
|
||||
tdc:
|
||||
internal-secret: ""
|
||||
|
||||
# tds 内部桥接密钥(TDC 经内部网络调 /api/ssw/tds/Bridge/** 时校验 X-Internal-Token;本地可空)
|
||||
tds:
|
||||
internal-secret: ""
|
||||
|
||||
k8s:
|
||||
enabled: true
|
||||
namespace: data-space
|
||||
|
||||
+6
@@ -37,8 +37,14 @@ import java.util.concurrent.TimeUnit;
|
||||
* 适配器返回 {@code status="FALLBACK"},本类直接转发到兜底引擎。
|
||||
*
|
||||
* @author SSWFlow
|
||||
*
|
||||
* <p><b>[V1.5 边界]</b> 本类是 dev-only fallback:{@code @Profile("dev")} 限流,prod 环境不注册。
|
||||
* 生产路径走 TDC Nax 镜像({@code boot/docker/ssw-nax-runtime}),由 TDC 沙盒 runtime
|
||||
* 执行真实 Nax 算法——保证"原始数据不出域"。
|
||||
* 详见 {@code docs/tds/SSWFLOW_BINDING.md §11 V1.5}。
|
||||
*/
|
||||
@Slf4j
|
||||
@org.springframework.context.annotation.Profile("dev")
|
||||
@Component
|
||||
public class NaxComputeEngine implements ComputeEngine {
|
||||
|
||||
|
||||
@@ -36,5 +36,58 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- [V1.5.9] 全接入 JNPF 平台(苏苏指示:不要计较包大小,全接入)
|
||||
与 ssw-admin 引的 jnpf-* 模块一一对齐,让独立 TDC 实例能自闭环跑起来。
|
||||
jnpf-permission-controller 会传递性拉 jnpf-permission-biz(含 UserServiceImpl)。 -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-extend-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-system-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-scheduletask-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-message-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-permission-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-exception</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-oauth-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-app-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-flowable-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-common-i18n</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
</project>
|
||||
@@ -0,0 +1,46 @@
|
||||
package ssw.tdc;
|
||||
|
||||
import jnpf.util.context.SpringContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.spring.EnableFileStorage;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* TDC 连接器(数据持有方本地代理)独立可执行入口 [V1.5.9]。
|
||||
* <p>
|
||||
* 与 {@link ssw.SswAdminApplication}(中央 SSWFlow 平台聚合入口)的关键差异:
|
||||
* <ul>
|
||||
* <li>只跑 TDC 业务({@code ssw.tdc.*} 子树),不打包 TDS / SSWFLOW 业务类——VM 内体积小;</li>
|
||||
* <li>不依赖 JNPF 主库 {@code j7}(独立 TDC 只连自己的 {@code tdc_node1} / {@code tdc} 库);</li>
|
||||
* <li>对外暴露的端点与中央 SSWFlow 的 TDC 端点一致({@code /api/ssw/tdc/*}),
|
||||
* 上游 SSWFLOW/TDS 通过 HTTP 调用无差异(App-Code + X-Internal-Token 鉴权);</li>
|
||||
* <li>{@code @EnableScheduling + @EnableAsync} 由本主类显式声明,不再依赖
|
||||
* {@code HostingJobTicker} 的隐式 enable(兼容 standalone 模式)。</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 部署形态参考 {@code docs/scard/VM_DEPLOY.md}:VM 内跑本 jar + Go scard connector,
|
||||
* 对接本机 SSWFLOW 平台。详见 {@code docs/tds/SSWFLOW_BINDING.md §12 V1.5.9}。
|
||||
*
|
||||
* @author SSW-TDC
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootApplication(scanBasePackages = {"jnpf", "ssw.common", "ssw.tdc"}, exclude = {DataSourceAutoConfiguration.class})
|
||||
@EnableFileStorage
|
||||
@EnableScheduling
|
||||
@EnableAsync
|
||||
public class TdcAdminApplication extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication springApplication = new SpringApplication(TdcAdminApplication.class);
|
||||
// [V1.5.9] 复用 ssw-admin 的修复:repackage fat-jar 后 META-INF/spring 被提到根目录,
|
||||
// LaunchedClassLoader 读不到——必须代码注册 SpringContext initializer。
|
||||
springApplication.addInitializers(new SpringContext());
|
||||
springApplication.run(args);
|
||||
log.error("TDC connector standalone 启动完成(V1.5.9)");
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,15 @@ public class K8sSandboxClient {
|
||||
@Value("${k8s.jupyter-image:jupyter/datascience-notebook:latest}")
|
||||
private String jupyterImage;
|
||||
|
||||
/** [V1.5] TEE 模式专用镜像(被 kata 机密容器使用,含 compute.py + CDH + KBS 链路) */
|
||||
@Value("${k8s.tee-image:python:3.11-slim}")
|
||||
private String teeImage;
|
||||
|
||||
/** [V1.5] 默认模式(NAX / BOTH)专用镜像——TDC Nax sidecar,含 nax 包 + nax_adapter.py
|
||||
* (详见 boot/docker/ssw-nax-runtime/Dockerfile) */
|
||||
@Value("${k8s.nax-image:ssw-nax-runtime:latest}")
|
||||
private String naxImage;
|
||||
|
||||
@Value("${k8s.kubeconfig:}")
|
||||
private String kubeconfig;
|
||||
|
||||
@@ -328,8 +334,53 @@ public class K8sSandboxClient {
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- Nax 运行时(V1.5 默认 runtime)
|
||||
|
||||
/**
|
||||
* 从 Job 的 pod 日志里取出 compute.py 打的结果载荷。
|
||||
* 提交一次 Nax 运行时 Job(默认模式:NAX / BOTH connector)。
|
||||
* <p>
|
||||
* 与 {@link #runTeeJob} 的关键差异:
|
||||
* <ul>
|
||||
* <li>镜像用 {@code naxImage}(TDC Nax sidecar,{@code boot/docker/ssw-nax-runtime}),
|
||||
* 入口是 {@code nax_adapter.py}(stdin/stdout JSON 协议);</li>
|
||||
* <li>runtimeClass 留空,走集群默认 runtime(不要求 kata / SEV-SNP);</li>
|
||||
* <li>不走 KBS / CDH 链路(kbsEngaged=false),pod 直接以环境变量 / stdin 喂算子 JSON。</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* V1.5.2 dev 起步:仅做"镜像切换 + runtime 切换"骨架;stdin 喂数据协议留 V1.5.6 跨方 Nax 协议补。
|
||||
* 当前实现:起 pod 立刻退出(nax_adapter.py 收到无效 stdin 报错退出),返回 SUCCESS 占位——只验证镜像可拉起 + runtime 选对。
|
||||
* <p>
|
||||
* 详见 {@code docs/tds/SSWFLOW_BINDING.md §11 V1.5.2}。
|
||||
*
|
||||
* @param taskId 算子 ID
|
||||
* @param operatorJson nax_adapter.py 要吃的算子 JSON(dev 起步先用环境变量,未来切 stdin)
|
||||
*/
|
||||
public K8sResult runNaxJob(String taskId, String operatorJson) {
|
||||
if (!enabled) return null;
|
||||
final String k8sId = sanitizeTaskId(taskId);
|
||||
try {
|
||||
Map<String, String> sub = new LinkedHashMap<>();
|
||||
sub.put("TASK_ID", k8sId);
|
||||
sub.put("NAMESPACE", namespace);
|
||||
sub.put("RUNTIME_CLASS", ""); // 集群默认 runtime
|
||||
sub.put("IMAGE", naxImage);
|
||||
sub.put("OPERATOR_JSON", operatorJson == null ? "{}" : operatorJson);
|
||||
File tf = render("k8s/tee-job.yaml", sub);
|
||||
int code = kubectl("apply", "-f", tf.getAbsolutePath());
|
||||
log.info("[K8S] Nax Job 提交 taskId={} image={} runtime=default kubectl exit={}",
|
||||
taskId, naxImage, code);
|
||||
K8sResult r = new K8sResult();
|
||||
r.status = code == 0 ? "SUCCESS" : "FAIL";
|
||||
r.resultUri = null;
|
||||
r.runLog = "[V1.5.2 dev] Nax Job 镜像切换骨架已就绪,跨方协议留 V1.5.6";
|
||||
return r;
|
||||
} catch (Exception e) {
|
||||
log.warn("[K8S] Nax Job 失败(回退) taskId={}", taskId, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 从 Job 的 pod 日志里取出 compute.py 打的结果载荷。
|
||||
* <p>载荷被包在 {@code SSW_TEE_RESULT_BEGIN} / {@code SSW_TEE_RESULT_END} 之间,
|
||||
* 前后还有 {@code [TEE] ...} 进度行,这里只取中间那段 JSON。
|
||||
*/
|
||||
|
||||
@@ -17,11 +17,6 @@
|
||||
<artifactId>ssw-tdc-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tds-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-common-all</artifactId>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package ssw.tdc.audit;
|
||||
|
||||
/**
|
||||
* 审计动作常量 —— 统一口径,避免各处自由发挥导致日志无法聚合分析。
|
||||
*
|
||||
* <p>可信数据空间关注的六类关键行为,对应国标里「合规 / 授权 / 控制 / 安全 / 分配 / 存证」。
|
||||
* 从 {@code ssw.tds.audit.AuditAction} 下沉到 TDC 本地:TDC 节点是独立部署(不依赖 TDS 模块),
|
||||
* 审计动作常量属于跨系统通用词汇,放 TDC 本地避免引入 ssw.tds 编译依赖。
|
||||
*
|
||||
* @author SSW-TDC
|
||||
*/
|
||||
public final class AuditAction {
|
||||
|
||||
private AuditAction() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 录入
|
||||
public static final String CREATE = "CREATE";
|
||||
public static final String UPDATE = "UPDATE";
|
||||
public static final String DELETE = "DELETE";
|
||||
|
||||
// ---------------------------------------------------------------- 审核
|
||||
public static final String SUBMIT_AUDIT = "SUBMIT_AUDIT";
|
||||
public static final String APPROVE = "APPROVE";
|
||||
public static final String REJECT = "REJECT";
|
||||
|
||||
// ---------------------------------------------------------------- 授权
|
||||
public static final String GRANT = "GRANT";
|
||||
public static final String REVOKE = "REVOKE";
|
||||
public static final String SIGN = "SIGN";
|
||||
|
||||
// ---------------------------------------------------------------- 控制
|
||||
public static final String POLICY_CHECK = "POLICY_CHECK";
|
||||
public static final String POLICY_DENY = "POLICY_DENY";
|
||||
|
||||
// ---------------------------------------------------------------- 执行
|
||||
public static final String EXECUTE = "EXECUTE";
|
||||
public static final String CALL = "CALL";
|
||||
public static final String PUBLISH = "PUBLISH";
|
||||
public static final String OFFLINE = "OFFLINE";
|
||||
|
||||
// ---------------------------------------------------------------- 结算
|
||||
public static final String SETTLE = "SETTLE";
|
||||
|
||||
// ---------------------------------------------------------------- 销毁
|
||||
public static final String DESTROY = "DESTROY";
|
||||
|
||||
// ---------------------------------------------------------------- 存证
|
||||
public static final String CHAIN_WRITE = "CHAIN_WRITE";
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package ssw.tdc.client;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link TdcTdsClient} 的 HTTP 实现:配置了 {@code ssw.tds.base-url} 时生效。
|
||||
*
|
||||
* <p>通过内部端点调运营方 TDS(与 {@link TdcSswflowClient} 同一信任模型:App-Code=tdc +
|
||||
* X-Internal-Token,端点走 exclude-url 绕过 JNPF AuthFilter)。所有调用<b>失败即降级</b>,
|
||||
* 不让跨系统故障拖垮 TDC 本地业务。
|
||||
*
|
||||
* <p>依赖的 TDS 侧端点(运营方 {@code ssw-tds-controller} 需暴露,见 SSWFLOW_BINDING §TDC 跨系统读):
|
||||
* <pre>
|
||||
* GET /api/ssw/tds/Bridge/Contract/{id} -> 合约概览 Map
|
||||
* GET /api/ssw/tds/Bridge/Connector/{id} -> 连接器概览 Map
|
||||
* GET /api/ssw/tds/Bridge/DataProduct/{id} -> 数据产品概览 Map
|
||||
* POST /api/ssw/tds/Bridge/AuditChain body: {bizIds:[..]} -> 审计哈希链 Map
|
||||
* POST /api/ssw/tds/Bridge/ChainEvidence body: {bizIds:[..]} -> 链上存证 Map
|
||||
* POST /api/ssw/tds/Bridge/AuditRecord body: {bizIds:[..]} -> 审计记录 Map
|
||||
* POST /api/ssw/tds/Bridge/AuditTrail body: 留痕 JSON -> void
|
||||
* </pre>
|
||||
*
|
||||
* @author SSW-TDC
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpTdcTdsClient implements TdcTdsClient {
|
||||
|
||||
private final RestTemplate rest = new RestTemplate();
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final String baseUrl;
|
||||
private final String internalToken;
|
||||
|
||||
public HttpTdcTdsClient(String baseUrl, String internalToken) {
|
||||
this.baseUrl = baseUrl;
|
||||
this.internalToken = internalToken == null ? "" : internalToken;
|
||||
}
|
||||
|
||||
private HttpHeaders headers() {
|
||||
HttpHeaders h = new HttpHeaders();
|
||||
h.setContentType(MediaType.APPLICATION_JSON);
|
||||
if (internalToken != null && !internalToken.isBlank()) {
|
||||
h.set("X-Internal-Token", internalToken);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
private String url(String path) {
|
||||
return baseUrl.replaceAll("/+$", "") + path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getContract(String contractId) {
|
||||
return get("/api/ssw/tds/Bridge/Contract/" + contractId, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConnector(String connectorId) {
|
||||
return get("/api/ssw/tds/Bridge/Connector/" + connectorId, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getProduct(String productId) {
|
||||
return get("/api/ssw/tds/Bridge/DataProduct/" + productId, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAuditChain(Collection<String> bizIds) {
|
||||
return post("/api/ssw/tds/Bridge/AuditChain", bizIds, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getChainEvidences(Collection<String> bizIds) {
|
||||
return post("/api/ssw/tds/Bridge/ChainEvidence", bizIds, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAuditRecords(Collection<String> bizIds) {
|
||||
return post("/api/ssw/tds/Bridge/AuditRecord", bizIds, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAudit(String bizType, String bizId, String action, String target) {
|
||||
recordAudit(bizType, bizId, action, target, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAudit(String bizType, String bizId, String action, String target,
|
||||
String result, String failReason, String detail) {
|
||||
try {
|
||||
Map<String, Object> body = new java.util.LinkedHashMap<>(8);
|
||||
body.put("bizType", bizType);
|
||||
body.put("bizId", bizId);
|
||||
body.put("action", action);
|
||||
body.put("target", target);
|
||||
body.put("result", result);
|
||||
body.put("failReason", failReason);
|
||||
body.put("detail", detail);
|
||||
rest.postForEntity(url("/api/ssw/tds/Bridge/AuditTrail"),
|
||||
new HttpEntity<>(body, headers()), Void.class);
|
||||
} catch (RestClientException e) {
|
||||
log.warn("[TDC-AUDIT] 留痕上报 TDS 失败(降级忽略) bizType={} bizId={} action={} err={}",
|
||||
bizType, bizId, action, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T get(String path, Class<T> type) {
|
||||
try {
|
||||
return rest.getForObject(url(path), type);
|
||||
} catch (RestClientException e) {
|
||||
log.warn("[TDC-TDS] GET {} 失败(降级返回空) err={}", path, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T post(String path, Object body, Class<T> type) {
|
||||
try {
|
||||
String json = mapper.writeValueAsString(java.util.Collections.singletonMap("bizIds", body));
|
||||
return rest.postForObject(url(path), new HttpEntity<>(json, headers()), type);
|
||||
} catch (RestClientException | com.fasterxml.jackson.core.JsonProcessingException e) {
|
||||
log.warn("[TDC-TDS] POST {} 失败(降级返回空) err={}", path, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package ssw.tdc.client;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link TdcTdsClient} 的默认实现:未配置 {@code ssw.tds.base-url} 时生效。
|
||||
*
|
||||
* <p>纯 TDC 节点不连运营方 TDS,所有跨系统读取返回 null/空、写入静默丢弃,
|
||||
* 业务全景只展示 TDC 本地数据。这是「tdc 包不依赖 tds」在运行期的优雅降级形态。
|
||||
*
|
||||
* @author SSW-TDC
|
||||
*/
|
||||
@Slf4j
|
||||
public class NoopTdcTdsClient implements TdcTdsClient {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getContract(String contractId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConnector(String connectorId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getProduct(String productId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAuditChain(Collection<String> bizIds) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getChainEvidences(Collection<String> bizIds) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAuditRecords(Collection<String> bizIds) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAudit(String bizType, String bizId, String action, String target) {
|
||||
log.debug("[TDC-AUDIT-noop] {} {} {} {}", bizType, bizId, action, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAudit(String bizType, String bizId, String action, String target,
|
||||
String result, String failReason, String detail) {
|
||||
log.debug("[TDC-AUDIT-noop] {} {} {} {} {} | {}", bizType, bizId, action, target, result, detail);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package ssw.tdc.client;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TDC 与运营方 TDS 的跨系统读/写客户端。
|
||||
*
|
||||
* <h3>为什么需要它</h3>
|
||||
* TDC 节点是<b>独立部署</b>的数据持有方(不依赖 TDS 模块、不连 TDS 库)。
|
||||
* 但「业务全景 / 信任一屏」需要聚合运营方 TDS 侧的数据(上游合约、连接器、数据产品、
|
||||
* 哈希链审计留痕、链上存证),且 TDC 自身的操作留痕要汇聚到运营方中枢。
|
||||
* 这些跨系统交互统一走本客户端,<b>绝不在 TDC 包里直接 import ssw.tds.*</b>。
|
||||
*
|
||||
* <h3>两种实现</h3>
|
||||
* <ul>
|
||||
* <li>{@link NoopTdcTdsClient}:默认实现(未配置 {@code ssw.tds.base-url} 时生效),
|
||||
* 所有读取返回 null/空、写入静默丢弃 —— 纯 TDC 节点不连 TDS 时优雅降级,
|
||||
* 业务全景只显示 TDC 本地数据。</li>
|
||||
* <li>{@link HttpTdcTdsClient}:配置了 {@code ssw.tds.base-url} 时生效,
|
||||
* 通过 mTLS/内部 Token 调运营方 TDS 暴露的只读/留痕端点。</li>
|
||||
* </ul>
|
||||
*
|
||||
* <h3>约定</h3>
|
||||
* 读取方法返回<b>已按前端字段名裁剪好的 Map</b>(键名与历史上 TDC 从 TDS Entity getter
|
||||
* 拼出的字段一致),调用方拿到后直接 {@code data.put(key, map)} 即可,无需逐字段转译。
|
||||
*
|
||||
* @author SSW-TDC
|
||||
*/
|
||||
public interface TdcTdsClient {
|
||||
|
||||
/** 上游合约概览(含双签人/连接器名称等,运营方 TDS 侧聚合好返回) */
|
||||
Map<String, Object> getContract(String contractId);
|
||||
|
||||
/** 连接器概览(id/name/connectorCode/status/orgName) */
|
||||
Map<String, Object> getConnector(String connectorId);
|
||||
|
||||
/** 数据产品概览(含 providerConnectorId 等) */
|
||||
Map<String, Object> getProduct(String productId);
|
||||
|
||||
/** 可信审计哈希链(含逐条 hashValid/linked/chainIntact 校验) */
|
||||
Map<String, Object> getAuditChain(Collection<String> bizIds);
|
||||
|
||||
/** 链上存证(含 status/verifyResult 等,能区分成功/失败/待确认) */
|
||||
Map<String, Object> getChainEvidences(Collection<String> bizIds);
|
||||
|
||||
/** 授权/策略/审核记录(业务全景「授权」区块) */
|
||||
Map<String, Object> getAuditRecords(Collection<String> bizIds);
|
||||
|
||||
/** 写一条业务留痕(TDC 操作痕迹汇聚到运营方中枢) */
|
||||
void recordAudit(String bizType, String bizId, String action, String target);
|
||||
|
||||
/** 写一条带结果与明细的业务留痕 */
|
||||
void recordAudit(String bizType, String bizId, String action, String target,
|
||||
String result, String failReason, String detail);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package ssw.tdc.client;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* {@link TdcTdsClient} 的 Bean 装配(TDC↔TDS 解耦核心)。
|
||||
*
|
||||
* <p>规则:配置了 {@code ssw.tds.base-url} 才注册 {@link HttpTdcTdsClient}(走 HTTP 调运营方 TDS);
|
||||
* 否则注册 {@link NoopTdcTdsClient}(纯 TDC 节点优雅降级)。两者互斥、保证恰好一个 Bean,
|
||||
* 避免类级 {@code @ConditionalOnMissingBean} 无法推断类型的坑(会导致 Noop 永不被实例化)。
|
||||
*
|
||||
* <p>这是「tdc 包不依赖 tds」运行期落地的关键:TDC 的 Controller 永远只依赖 {@code TdcTdsClient}
|
||||
* 接口,具体实现由本配置按部署角色注入。
|
||||
*/
|
||||
@Configuration
|
||||
public class TdcTdsClientConfig {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "ssw.tds", name = "base-url")
|
||||
public TdcTdsClient httpTdcTdsClient(
|
||||
@Value("${ssw.tds.base-url}") String baseUrl,
|
||||
@Value("${ssw.tds.internal-token:}") String internalToken) {
|
||||
return new HttpTdcTdsClient(baseUrl, internalToken);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(TdcTdsClient.class)
|
||||
public TdcTdsClient noopTdcTdsClient() {
|
||||
return new NoopTdcTdsClient();
|
||||
}
|
||||
}
|
||||
+35
-97
@@ -24,11 +24,8 @@ import ssw.tdc.notify.NotifyDispatcher;
|
||||
import ssw.tdc.entity.ApiConsumeLogEntity;
|
||||
import ssw.tdc.entity.OrderEntity;
|
||||
import ssw.tdc.service.OrderService;
|
||||
import ssw.tds.entity.ChainEvidenceEntity;
|
||||
import ssw.tds.entity.ContractEntity;
|
||||
import ssw.tds.service.ChainEvidenceService;
|
||||
import ssw.tds.service.ContractService;
|
||||
// 注:合约存证是 tds 库,跨 schema 用 ssw.tds.* 防止 @DS("tdc") 路由把查询打回 tdc 库(会查不到)
|
||||
import ssw.tdc.audit.AuditAction;
|
||||
import ssw.tdc.client.TdcTdsClient;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -37,11 +34,6 @@ import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import ssw.common.permission.UserNameResolver;
|
||||
import ssw.tds.entity.AuditLogEntity;
|
||||
import ssw.tds.entity.ConnectorEntity;
|
||||
import ssw.tds.service.AuditLogService;
|
||||
import ssw.tds.service.ConnectorService;
|
||||
import ssw.tds.service.DataProductService;
|
||||
|
||||
/**
|
||||
* 数据交付任务控制器
|
||||
@@ -74,20 +66,12 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
@Autowired
|
||||
private NotifyDispatcher notifyDispatcher;
|
||||
|
||||
@Autowired private ssw.tds.service.ContractService contractService;
|
||||
@Autowired private TdcTdsClient tdcTdsClient;
|
||||
@Autowired private OrderService orderService;
|
||||
@Autowired private ApiConsumeLogService apiConsumeLogService;
|
||||
@Autowired(required = false) private ssw.tds.service.ChainEvidenceService chainEvidenceService;
|
||||
@Autowired(required = false) private ssw.tds.service.DataProductService dataProductService;
|
||||
@Autowired(required = false) private ssw.tds.service.ConnectorService connectorService;
|
||||
@Autowired(required = false) private ssw.tds.service.AuditLogService auditLogService;
|
||||
@Autowired(required = false) private ssw.common.permission.UserNameResolver userNameResolver;
|
||||
@Autowired(required = false)
|
||||
private ssw.tds.audit.EvidenceAssembler evidenceAssembler;
|
||||
@Autowired(required = false)
|
||||
private ssw.tdc.audit.TrustLinkAssembler trustLinkAssembler;
|
||||
@Autowired(required = false)
|
||||
private ssw.tds.audit.AuditRecordAssembler auditRecordAssembler;
|
||||
|
||||
/** [TDS-SSWFLOW-BINDING §10 V1.4] TDC 交付任务直接触发 SSWFLOW */
|
||||
@Autowired(required = false)
|
||||
@@ -218,10 +202,10 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
// 只记成功不记拒绝,等于把最能体现管控有效性的证据丢掉了 ——
|
||||
// 供方要靠这些 DENY 记录确认自己的限制条款真的被执行了。
|
||||
if ("DENY".equals(result)) {
|
||||
audit(ssw.tds.audit.AuditAction.POLICY_DENY, id, exists.getTaskNo(),
|
||||
audit(AuditAction.POLICY_DENY, id, exists.getTaskNo(),
|
||||
"DENY", denyReason, "策略判定拒绝,任务终止为 DENIED");
|
||||
} else {
|
||||
audit(ssw.tds.audit.AuditAction.POLICY_CHECK, id, exists.getTaskNo(),
|
||||
audit(AuditAction.POLICY_CHECK, id, exists.getTaskNo(),
|
||||
"SUCCESS", null, "策略判定 " + result + ",任务转入 RUNNING");
|
||||
}
|
||||
|
||||
@@ -298,7 +282,7 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
if (update.getDurationMs() != null) {
|
||||
detail.append(";耗时=").append(update.getDurationMs()).append("ms");
|
||||
}
|
||||
audit(ssw.tds.audit.AuditAction.EXECUTE, id, exists.getTaskNo(),
|
||||
audit(AuditAction.EXECUTE, id, exists.getTaskNo(),
|
||||
success ? "SUCCESS" : "FAIL",
|
||||
success ? null : (update.getErrorMsg() == null ? "交付执行失败" : update.getErrorMsg()),
|
||||
detail.toString());
|
||||
@@ -332,7 +316,7 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
}
|
||||
deliveryTaskService.updateById(update);
|
||||
// 回执上报 = TDC 向 TDS 记账的凭据,失败要能看到第几次重试
|
||||
audit(ssw.tds.audit.AuditAction.CALL, id, exists.getTaskNo(), status,
|
||||
audit(AuditAction.CALL, id, exists.getTaskNo(), status,
|
||||
"FAIL".equals(status) ? "回执上报失败,待重试任务兜底" : null,
|
||||
"回执上报 TDS 记账,状态=" + status
|
||||
+ ("FAIL".equals(status) ? ";重试次数=" + update.getRetryCount() : ""));
|
||||
@@ -354,7 +338,7 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
update.setStatus("CANCELLED");
|
||||
update.setEndTime(new Date());
|
||||
deliveryTaskService.updateById(update);
|
||||
audit(ssw.tds.audit.AuditAction.UPDATE, id, exists.getTaskNo(), "SUCCESS", null,
|
||||
audit(AuditAction.UPDATE, id, exists.getTaskNo(), "SUCCESS", null,
|
||||
"任务取消:" + exists.getStatus() + " -> CANCELLED");
|
||||
return ActionResult.success("任务已取消", id);
|
||||
}
|
||||
@@ -388,7 +372,7 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
deliveryTaskService.updateById(update);
|
||||
// 重新交付会清空上一轮运行产物与审核态 —— 这是一次"证据重置",必须留痕,
|
||||
// 否则审计侧看到审核记录凭空消失会认为被篡改。
|
||||
audit(ssw.tds.audit.AuditAction.UPDATE, id, exists.getTaskNo(), "SUCCESS", null,
|
||||
audit(AuditAction.UPDATE, id, exists.getTaskNo(), "SUCCESS", null,
|
||||
"重新交付:状态 " + exists.getStatus() + "/" + exists.getRunStatus()
|
||||
+ " -> PENDING/PENDING_DELIVER;审核态由 "
|
||||
+ (exists.getAuditStatus() == null ? "NONE" : exists.getAuditStatus())
|
||||
@@ -414,11 +398,11 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
destroyLogService.destroyTask(id, reason == null ? "手动销毁" : reason, safeUserId(), method);
|
||||
} catch (RuntimeException ex) {
|
||||
// 销毁失败必须留痕:参与方最关心"我的数据到底销没销掉"
|
||||
audit(ssw.tds.audit.AuditAction.DESTROY, id, exists.getTaskNo(), "FAIL",
|
||||
audit(AuditAction.DESTROY, id, exists.getTaskNo(), "FAIL",
|
||||
ex.getMessage(), "数据销毁失败,落地物可能仍存在,需人工核查");
|
||||
throw ex;
|
||||
}
|
||||
audit(ssw.tds.audit.AuditAction.DESTROY, id, exists.getTaskNo(), "SUCCESS", null,
|
||||
audit(AuditAction.DESTROY, id, exists.getTaskNo(), "SUCCESS", null,
|
||||
"数据销毁完成;原因=" + (reason == null ? "手动销毁" : reason)
|
||||
+ ";方式=" + (method == null ? "LOGICAL" : method)
|
||||
+ ";已清空 resultUri/runLog/programUri/codeUri 落地物");
|
||||
@@ -509,59 +493,11 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
auditTrail.put("tenantId", task.getTenantId());
|
||||
data.put("auditTrail", auditTrail);
|
||||
|
||||
// 2. 上游合约 (跨 schema - ContractEntity 是 tds schema)
|
||||
// 2. 上游合约(跨系统:运营方 TDS 持有,经 TdcTdsClient 拉取;TDS 端点已聚合连接器名称等)
|
||||
if (task.getContractId() != null && !task.getContractId().isBlank()) {
|
||||
ContractEntity contract = safeGet(contractService, task.getContractId());
|
||||
Map<String, Object> contract = tdcTdsClient.getContract(task.getContractId());
|
||||
if (contract != null) {
|
||||
Map<String, Object> contractMap = new LinkedHashMap<>();
|
||||
contractMap.put("contractCode", contract.getContractCode());
|
||||
contractMap.put("name", contract.getName());
|
||||
contractMap.put("providerConnectorId", contract.getProviderConnectorId());
|
||||
contractMap.put("providerOrgId", contract.getProviderOrgId());
|
||||
contractMap.put("providerOrgName", contract.getProviderOrgName());
|
||||
contractMap.put("consumerConnectorId", contract.getConsumerConnectorId());
|
||||
contractMap.put("consumerOrgId", contract.getConsumerOrgId());
|
||||
contractMap.put("consumerOrgName", contract.getConsumerOrgName());
|
||||
contractMap.put("purpose", contract.getPurpose());
|
||||
contractMap.put("deliveryType", contract.getDeliveryType());
|
||||
contractMap.put("priceMode", contract.getPriceMode());
|
||||
contractMap.put("amount", contract.getAmount());
|
||||
contractMap.put("quotaTotal", contract.getQuotaTotal());
|
||||
contractMap.put("quotaUsed", contract.getQuotaUsed());
|
||||
contractMap.put("effectiveTime", contract.getEffectiveTime());
|
||||
contractMap.put("expireTime", contract.getExpireTime());
|
||||
contractMap.put("providerSignature", contract.getProviderSignature());
|
||||
contractMap.put("providerSignTime", contract.getProviderSignTime());
|
||||
contractMap.put("consumerSignature", contract.getConsumerSignature());
|
||||
contractMap.put("consumerSignTime", contract.getConsumerSignTime());
|
||||
contractMap.put("signTime", contract.getSignTime());
|
||||
contractMap.put("signCostMs", contract.getSignCostMs());
|
||||
contractMap.put("status", contract.getStatus());
|
||||
contractMap.put("contentHash", contract.getContentHash());
|
||||
contractMap.put("chainTxHash", contract.getChainTxHash());
|
||||
contractMap.put("chainBlockNo", contract.getChainBlockNo());
|
||||
contractMap.put("chainTime", contract.getChainTime());
|
||||
contractMap.put("policyContent", contract.getPolicyContent());
|
||||
// 供方/使用方连接器名称解析(「供方经连接器接入数据」在全景可见)
|
||||
if (connectorService != null) {
|
||||
if (contract.getProviderConnectorId() != null) {
|
||||
ConnectorEntity pc = safeGet(connectorService, contract.getProviderConnectorId());
|
||||
if (pc != null) {
|
||||
contractMap.put("providerConnectorName", pc.getName());
|
||||
contractMap.put("providerConnectorCode", pc.getConnectorCode());
|
||||
contractMap.put("providerConnectorOnline", "ONLINE".equals(pc.getStatus()));
|
||||
}
|
||||
}
|
||||
if (contract.getConsumerConnectorId() != null) {
|
||||
ConnectorEntity cc = safeGet(connectorService, contract.getConsumerConnectorId());
|
||||
if (cc != null) {
|
||||
contractMap.put("consumerConnectorName", cc.getName());
|
||||
contractMap.put("consumerConnectorCode", cc.getConnectorCode());
|
||||
contractMap.put("consumerConnectorOnline", "ONLINE".equals(cc.getStatus()));
|
||||
}
|
||||
}
|
||||
}
|
||||
data.put("contract", contractMap);
|
||||
data.put("contract", contract);
|
||||
}
|
||||
}
|
||||
// 4. 参与方(从 task 已有 consumerOrg 字段 + 用 connectorService 反查 provider 提供方)
|
||||
@@ -637,18 +573,19 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
}
|
||||
data.put("attestation", attestation);
|
||||
|
||||
// 11. 配额使用
|
||||
// 11. 配额使用(跨系统:运营方 TDS 持有)
|
||||
if (task.getContractId() != null) {
|
||||
ContractEntity contract = safeGet(contractService, task.getContractId());
|
||||
if (contract != null && contract.getQuotaTotal() != null) {
|
||||
Map<String, Object> contract = tdcTdsClient.getContract(task.getContractId());
|
||||
if (contract != null && contract.get("quotaTotal") != null) {
|
||||
Map<String, Object> quota = new LinkedHashMap<>();
|
||||
quota.put("total", contract.getQuotaTotal());
|
||||
quota.put("used", contract.getQuotaUsed());
|
||||
if (contract.getQuotaTotal() != null && contract.getQuotaTotal() > 0) {
|
||||
long used = contract.getQuotaUsed() == null ? 0 : contract.getQuotaUsed();
|
||||
quota.put("remaining", contract.getQuotaTotal() - used);
|
||||
quota.put("usagePercent",
|
||||
Math.round(10000.0 * used / contract.getQuotaTotal()) / 100.0);
|
||||
long total = ((Number) contract.get("quotaTotal")).longValue();
|
||||
long used = contract.get("quotaUsed") == null ? 0
|
||||
: ((Number) contract.get("quotaUsed")).longValue();
|
||||
quota.put("total", total);
|
||||
quota.put("used", used);
|
||||
if (total > 0) {
|
||||
quota.put("remaining", total - used);
|
||||
quota.put("usagePercent", Math.round(10000.0 * used / total) / 100.0);
|
||||
}
|
||||
data.put("quota", quota);
|
||||
}
|
||||
@@ -690,16 +627,16 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
if (task.getTaskCode() != null) evidenceBizIds.add(task.getTaskCode());
|
||||
if (task.getContractId() != null) evidenceBizIds.add(task.getContractId());
|
||||
if (task.getContractCode() != null) evidenceBizIds.add(task.getContractCode());
|
||||
if (evidenceAssembler != null) {
|
||||
data.put("chainEvidences", evidenceAssembler.chainEvidences(evidenceBizIds));
|
||||
Map<String, Object> chainEvidences = tdcTdsClient.getChainEvidences(evidenceBizIds);
|
||||
if (chainEvidences != null) {
|
||||
data.put("chainEvidences", chainEvidences);
|
||||
}
|
||||
|
||||
// ---------------- 可信证据链(统一口径) ----------------
|
||||
// 审计留痕由 EvidenceAssembler 统一组装:返回 seqNo/prevHash/hash 三件套
|
||||
// ---------------- 可信证据链(统一口径,跨系统自运营方 TDS 拉取) ----------------
|
||||
// 审计留痕由运营方 TDS 的 EvidenceAssembler 统一组装:返回 seqNo/prevHash/hash 三件套
|
||||
// 以及逐条重算得出的 hashValid/linked,前端才能标"已验证"而不是干印一串哈希。
|
||||
// 7 个业务全景页共用这一份实现,杜绝各写一遍、各丢一批字段。
|
||||
if (evidenceAssembler != null) {
|
||||
Map<String, Object> chain = evidenceAssembler.auditChain(evidenceBizIds);
|
||||
Map<String, Object> chain = tdcTdsClient.getAuditChain(evidenceBizIds);
|
||||
if (chain != null) {
|
||||
data.put("auditChain", chain);
|
||||
// auditLog 保留为兼容字段,内容是 auditChain.items(字段为旧结构的超集)
|
||||
data.put("auditLog", chain.get("items"));
|
||||
@@ -727,8 +664,9 @@ public class DeliveryTaskController extends TdcCrudController<DeliveryTaskEntity
|
||||
data.put("authorizations", trustLinkAssembler.authorizations(productIds));
|
||||
data.put("policyChecks", trustLinkAssembler.policyChecks(authBizIds));
|
||||
}
|
||||
if (auditRecordAssembler != null) {
|
||||
data.put("auditRecords", auditRecordAssembler.auditRecords(authBizIds));
|
||||
Map<String, Object> auditRecords = tdcTdsClient.getAuditRecords(authBizIds);
|
||||
if (auditRecords != null) {
|
||||
data.put("auditRecords", auditRecords);
|
||||
}
|
||||
|
||||
return ActionResult.success(data);
|
||||
|
||||
+13
-14
@@ -19,6 +19,8 @@ import ssw.tdc.entity.DemandEntity;
|
||||
import ssw.tdc.entity.OrderEntity;
|
||||
import ssw.tdc.service.DemandService;
|
||||
import ssw.tdc.service.OrderService;
|
||||
import ssw.tdc.audit.AuditAction;
|
||||
import ssw.tdc.client.TdcTdsClient;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -42,14 +44,10 @@ public class DemandController extends TdcCrudController<DemandEntity> {
|
||||
private DemandService demandService;
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
@Autowired(required = false) private ssw.tds.service.AuditLogService auditLogService;
|
||||
@Autowired private TdcTdsClient tdcTdsClient;
|
||||
@Autowired(required = false) private ssw.common.permission.UserNameResolver userNameResolver;
|
||||
@Autowired(required = false)
|
||||
private ssw.tds.audit.EvidenceAssembler evidenceAssembler;
|
||||
@Autowired(required = false)
|
||||
private ssw.tdc.audit.TrustLinkAssembler trustLinkAssembler;
|
||||
@Autowired(required = false)
|
||||
private ssw.tds.audit.AuditRecordAssembler auditRecordAssembler;
|
||||
|
||||
@Override
|
||||
protected SuperService<DemandEntity> service() { return demandService; }
|
||||
@@ -89,7 +87,7 @@ public class DemandController extends TdcCrudController<DemandEntity> {
|
||||
d.setPublishUserId(UserProvider.getLoginUserId());
|
||||
boolean ok = demandService.updateById(d);
|
||||
if (ok) {
|
||||
audit(ssw.tds.audit.AuditAction.PUBLISH, id, d.getDemandCode(), "SUCCESS", null,
|
||||
audit(AuditAction.PUBLISH, id, d.getDemandCode(), "SUCCESS", null,
|
||||
"需求发布到需求广场:DRAFT -> PUBLISHED;标题=" + d.getTitle()
|
||||
+ ";提出方=" + (d.getMemberName() == null ? d.getMemberId() : d.getMemberName()));
|
||||
}
|
||||
@@ -108,7 +106,7 @@ public class DemandController extends TdcCrudController<DemandEntity> {
|
||||
d.setStatus("CLOSED");
|
||||
boolean ok = demandService.updateById(d);
|
||||
if (ok) {
|
||||
audit(ssw.tds.audit.AuditAction.OFFLINE, id, d.getDemandCode(), "SUCCESS", null,
|
||||
audit(AuditAction.OFFLINE, id, d.getDemandCode(), "SUCCESS", null,
|
||||
"需求关闭:" + from + " -> CLOSED;不再接受新的响应");
|
||||
}
|
||||
return ok ? ActionResult.success("已关闭", d.getId()) : ActionResult.fail("操作失败");
|
||||
@@ -158,7 +156,7 @@ public class DemandController extends TdcCrudController<DemandEntity> {
|
||||
boolean ok = orderService.save(o);
|
||||
if (ok) {
|
||||
// 撮合成交是供需双方建立关系的起点,买卖双方是谁、走什么交付方式,必须锁死在链上
|
||||
audit(ssw.tds.audit.AuditAction.CREATE, id, d.getDemandCode(), "SUCCESS", null,
|
||||
audit(AuditAction.CREATE, id, d.getDemandCode(), "SUCCESS", null,
|
||||
"需求撮合响应:生成订单 " + o.getOrderCode() + "(" + o.getId() + ")"
|
||||
+ ";买方(需求方)=" + buyerName + "(" + buyerId + ")"
|
||||
+ ";卖方(响应方)=" + responderId
|
||||
@@ -224,12 +222,12 @@ public class DemandController extends TdcCrudController<DemandEntity> {
|
||||
java.util.List<String> evidenceBizIds = new java.util.ArrayList<>();
|
||||
evidenceBizIds.add(demand.getId());
|
||||
if (demand.getDemandCode() != null) evidenceBizIds.add(demand.getDemandCode());
|
||||
// ---------------- 可信证据链(统一口径) ----------------
|
||||
// 审计留痕由 EvidenceAssembler 统一组装:返回 seqNo/prevHash/hash 三件套
|
||||
// ---------------- 可信证据链(统一口径,跨系统自运营方 TDS 拉取) ----------------
|
||||
// 审计留痕由运营方 TDS 的 EvidenceAssembler 统一组装:返回 seqNo/prevHash/hash 三件套
|
||||
// 以及逐条重算得出的 hashValid/linked,前端才能标"已验证"而不是干印一串哈希。
|
||||
// 7 个业务全景页共用这一份实现,杜绝各写一遍、各丢一批字段。
|
||||
if (evidenceAssembler != null) {
|
||||
Map<String, Object> chain = evidenceAssembler.auditChain(evidenceBizIds);
|
||||
Map<String, Object> chain = tdcTdsClient.getAuditChain(evidenceBizIds);
|
||||
if (chain != null) {
|
||||
data.put("auditChain", chain);
|
||||
// auditLog 保留为兼容字段,内容是 auditChain.items(字段为旧结构的超集)
|
||||
data.put("auditLog", chain.get("items"));
|
||||
@@ -252,8 +250,9 @@ public class DemandController extends TdcCrudController<DemandEntity> {
|
||||
data.put("authorizations", trustLinkAssembler.authorizations(java.util.Collections.emptyList()));
|
||||
data.put("policyChecks", trustLinkAssembler.policyChecks(authBizIds));
|
||||
}
|
||||
if (auditRecordAssembler != null) {
|
||||
data.put("auditRecords", auditRecordAssembler.auditRecords(authBizIds));
|
||||
Map<String, Object> auditRecords = tdcTdsClient.getAuditRecords(authBizIds);
|
||||
if (auditRecords != null) {
|
||||
data.put("auditRecords", auditRecords);
|
||||
}
|
||||
|
||||
return ActionResult.success(data);
|
||||
|
||||
+20
-50
@@ -24,8 +24,8 @@ import ssw.tdc.service.OrderService;
|
||||
import ssw.tdc.service.ProductService;
|
||||
import ssw.tdc.entity.DemandEntity;
|
||||
import ssw.tdc.service.DemandService;
|
||||
import ssw.tds.entity.ContractEntity;
|
||||
import ssw.tds.service.ContractService;
|
||||
import ssw.tdc.audit.AuditAction;
|
||||
import ssw.tdc.client.TdcTdsClient;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -33,12 +33,6 @@ import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import ssw.common.permission.UserNameResolver;
|
||||
import ssw.tds.entity.AuditLogEntity;
|
||||
import ssw.tds.entity.ConnectorEntity;
|
||||
import ssw.tds.entity.DataProductEntity;
|
||||
import ssw.tds.service.AuditLogService;
|
||||
import ssw.tds.service.ConnectorService;
|
||||
import ssw.tds.service.DataProductService;
|
||||
|
||||
/**
|
||||
* 订单控制器(V0.12 B1:TC_OP_005 ~ TC_OP_010)
|
||||
@@ -82,17 +76,10 @@ public class OrderController extends TdcCrudController<OrderEntity> {
|
||||
@Autowired
|
||||
private DeliveryTaskService deliveryTaskService;
|
||||
@Autowired private DemandService demandService;
|
||||
@Autowired private ssw.tds.service.ContractService contractService;
|
||||
@Autowired(required = false) private ssw.tds.service.DataProductService dataProductService;
|
||||
@Autowired(required = false) private ssw.tds.service.ConnectorService connectorService;
|
||||
@Autowired(required = false) private ssw.tds.service.AuditLogService auditLogService;
|
||||
@Autowired private TdcTdsClient tdcTdsClient;
|
||||
@Autowired(required = false) private ssw.common.permission.UserNameResolver userNameResolver;
|
||||
@Autowired(required = false)
|
||||
private ssw.tds.audit.EvidenceAssembler evidenceAssembler;
|
||||
@Autowired(required = false)
|
||||
private ssw.tdc.audit.TrustLinkAssembler trustLinkAssembler;
|
||||
@Autowired(required = false)
|
||||
private ssw.tds.audit.AuditRecordAssembler auditRecordAssembler;
|
||||
|
||||
@Override
|
||||
protected SuperService<OrderEntity> service() {
|
||||
@@ -389,26 +376,13 @@ public class OrderController extends TdcCrudController<OrderEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 上游合约(跨 schema: tds)
|
||||
// 5. 上游合约(跨系统:运营方 TDS 持有,经 TdcTdsClient 拉取)
|
||||
if (order.getDeliveryTaskId() != null && !order.getDeliveryTaskId().isBlank()) {
|
||||
DeliveryTaskEntity dt = safeGet(deliveryTaskService, order.getDeliveryTaskId());
|
||||
if (dt != null && dt.getContractId() != null && !dt.getContractId().isBlank()) {
|
||||
ContractEntity contract = safeGet(contractService, dt.getContractId());
|
||||
Map<String, Object> contract = tdcTdsClient.getContract(dt.getContractId());
|
||||
if (contract != null) {
|
||||
Map<String, Object> c = new LinkedHashMap<>();
|
||||
c.put("contractCode", contract.getContractCode());
|
||||
c.put("name", contract.getName());
|
||||
c.put("providerOrgName", contract.getProviderOrgName());
|
||||
c.put("consumerOrgName", contract.getConsumerOrgName());
|
||||
c.put("purpose", contract.getPurpose());
|
||||
c.put("priceMode", contract.getPriceMode());
|
||||
c.put("amount", contract.getAmount());
|
||||
c.put("quotaTotal", contract.getQuotaTotal());
|
||||
c.put("quotaUsed", contract.getQuotaUsed());
|
||||
c.put("status", contract.getStatus());
|
||||
c.put("chainTxHash", contract.getChainTxHash());
|
||||
c.put("chainBlockNo", contract.getChainBlockNo());
|
||||
data.put("contract", c);
|
||||
data.put("contract", contract);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -422,20 +396,15 @@ public class OrderController extends TdcCrudController<OrderEntity> {
|
||||
data.put("parties", parties);
|
||||
|
||||
// 7. 供方连接器(order -> product -> provider connector),让「供方经连接器接入数据」在全景可见
|
||||
// product / connector 均由运营方 TDS 持有,经 TdcTdsClient 拉取
|
||||
try {
|
||||
if (order.getProductId() != null && dataProductService != null) {
|
||||
DataProductEntity prod = safeGet(dataProductService, order.getProductId());
|
||||
if (prod != null && prod.getProviderConnectorId() != null && connectorService != null) {
|
||||
ConnectorEntity prov = safeGet(connectorService, prod.getProviderConnectorId());
|
||||
if (order.getProductId() != null) {
|
||||
Map<String, Object> prod = tdcTdsClient.getProduct(order.getProductId());
|
||||
if (prod != null && prod.get("providerConnectorId") != null) {
|
||||
Map<String, Object> prov = tdcTdsClient.getConnector(
|
||||
String.valueOf(prod.get("providerConnectorId")));
|
||||
if (prov != null) {
|
||||
Map<String, Object> pc = new LinkedHashMap<>();
|
||||
pc.put("id", prov.getId());
|
||||
pc.put("name", prov.getName());
|
||||
pc.put("connectorCode", prov.getConnectorCode());
|
||||
pc.put("status", prov.getStatus());
|
||||
pc.put("online", "ONLINE".equals(prov.getStatus()));
|
||||
pc.put("orgName", prov.getOrgName());
|
||||
data.put("providerConnector", pc);
|
||||
data.put("providerConnector", prov);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -444,12 +413,12 @@ public class OrderController extends TdcCrudController<OrderEntity> {
|
||||
java.util.List<String> evidenceBizIds = new java.util.ArrayList<>();
|
||||
evidenceBizIds.add(order.getId());
|
||||
if (order.getOrderCode() != null) evidenceBizIds.add(order.getOrderCode());
|
||||
// ---------------- 可信证据链(统一口径) ----------------
|
||||
// 审计留痕由 EvidenceAssembler 统一组装:返回 seqNo/prevHash/hash 三件套
|
||||
// ---------------- 可信证据链(统一口径,跨系统自运营方 TDS 拉取) ----------------
|
||||
// 审计留痕由运营方 TDS 的 EvidenceAssembler 统一组装:返回 seqNo/prevHash/hash 三件套
|
||||
// 以及逐条重算得出的 hashValid/linked,前端才能标"已验证"而不是干印一串哈希。
|
||||
// 7 个业务全景页共用这一份实现,杜绝各写一遍、各丢一批字段。
|
||||
if (evidenceAssembler != null) {
|
||||
Map<String, Object> chain = evidenceAssembler.auditChain(evidenceBizIds);
|
||||
Map<String, Object> chain = tdcTdsClient.getAuditChain(evidenceBizIds);
|
||||
if (chain != null) {
|
||||
data.put("auditChain", chain);
|
||||
// auditLog 保留为兼容字段,内容是 auditChain.items(字段为旧结构的超集)
|
||||
data.put("auditLog", chain.get("items"));
|
||||
@@ -475,8 +444,9 @@ public class OrderController extends TdcCrudController<OrderEntity> {
|
||||
data.put("authorizations", trustLinkAssembler.authorizations(productIds));
|
||||
data.put("policyChecks", trustLinkAssembler.policyChecks(authBizIds));
|
||||
}
|
||||
if (auditRecordAssembler != null) {
|
||||
data.put("auditRecords", auditRecordAssembler.auditRecords(authBizIds));
|
||||
Map<String, Object> auditRecords = tdcTdsClient.getAuditRecords(authBizIds);
|
||||
if (auditRecords != null) {
|
||||
data.put("auditRecords", auditRecords);
|
||||
}
|
||||
|
||||
return ActionResult.success(data);
|
||||
|
||||
+7
-8
@@ -16,8 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import ssw.tdc.entity.ApiConsumeLogEntity;
|
||||
import ssw.tdc.service.ApiConsumeLogService;
|
||||
import ssw.tds.entity.DataProductEntity;
|
||||
import ssw.tds.service.DataProductService;
|
||||
import ssw.tdc.client.TdcTdsClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -41,7 +40,7 @@ import java.util.Map;
|
||||
public class ProductApiGatewayController {
|
||||
|
||||
@Autowired
|
||||
private DataProductService productService;
|
||||
private TdcTdsClient tdcTdsClient;
|
||||
|
||||
@Autowired
|
||||
private ApiConsumeLogService apiConsumeLogService;
|
||||
@@ -58,18 +57,18 @@ public class ProductApiGatewayController {
|
||||
return ActionResult.fail("产品标识不能为空");
|
||||
}
|
||||
|
||||
DataProductEntity product = productService.getById(productId);
|
||||
Map<String, Object> product = tdcTdsClient.getProduct(productId);
|
||||
// TC-PRODUCT_API-018:不存在的产品被拒
|
||||
if (product == null) {
|
||||
return ActionResult.fail("数据产品不存在");
|
||||
}
|
||||
// TC-PRODUCT_API-018:未上架(OFFLINE / DRAFT)产品不可用
|
||||
if (!"ONLINE".equals(product.getStatus())) {
|
||||
if (!"ONLINE".equals(String.valueOf(product.get("status")))) {
|
||||
return ActionResult.fail("产品未上架,暂不可用");
|
||||
}
|
||||
|
||||
// 落一条 SUCCESS 消费留痕(TC-PRODUCT_API-017 / SECURITY-006 校验日志增长)
|
||||
writeLog(product, request, "SUCCESS", null);
|
||||
writeLog(productId, request, "SUCCESS", null);
|
||||
|
||||
// 返回骨架数据(真实数据集由数据资源 → 业务库接入后产出)
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
@@ -93,14 +92,14 @@ public class ProductApiGatewayController {
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
private void writeLog(DataProductEntity product, HttpServletRequest request, String status, String err) {
|
||||
private void writeLog(String productId, HttpServletRequest request, String status, String err) {
|
||||
try {
|
||||
ApiConsumeLogEntity log = new ApiConsumeLogEntity();
|
||||
log.setId(RandomUtil.uuId());
|
||||
log.setAppId("product-direct");
|
||||
log.setOrderCode(null);
|
||||
log.setDeliveryTaskId(null);
|
||||
log.setProductId(product.getId());
|
||||
log.setProductId(productId);
|
||||
log.setCallTime(new Date());
|
||||
log.setIp(request == null ? null : request.getRemoteAddr());
|
||||
log.setStatus(status);
|
||||
|
||||
+6
-5
@@ -21,6 +21,7 @@ import ssw.tdc.entity.ResourceEntity;
|
||||
import ssw.tdc.entity.ResourceGrantEntity;
|
||||
import ssw.tdc.service.ResourceGrantService;
|
||||
import ssw.tdc.service.ResourceService;
|
||||
import ssw.tdc.audit.AuditAction;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -138,7 +139,7 @@ public class ResourceGrantController extends TdcCrudController<ResourceGrantEnti
|
||||
resourceGrantService.updateById(g);
|
||||
reason = "已过期";
|
||||
// 授权自动失效是状态变更,必须留痕,否则参与方看到权限突然没了无从解释
|
||||
audit(ssw.tds.audit.AuditAction.REVOKE, g.getId(), resourceId, "SUCCESS", null,
|
||||
audit(AuditAction.REVOKE, g.getId(), resourceId, "SUCCESS", null,
|
||||
"授权到期自动失效:ACTIVE -> EXPIRED;到期时间=" + g.getExpireTime()
|
||||
+ ";被授权方=" + granteeType + ":" + granteeId);
|
||||
continue;
|
||||
@@ -166,7 +167,7 @@ public class ResourceGrantController extends TdcCrudController<ResourceGrantEnti
|
||||
// 只记录「拒绝」:命中放行是高频路径,由 API 调用日志承接;被拒是最需要解释的一类事件,
|
||||
// 参与方追问"为什么我访问不了"时必须能给出带哈希链的证据。
|
||||
if (!allow) {
|
||||
audit(ssw.tds.audit.AuditAction.POLICY_DENY, resourceId, res.getName(), "DENY",
|
||||
audit(AuditAction.POLICY_DENY, resourceId, res.getName(), "DENY",
|
||||
reason, "授权校验拒绝:被授权方=" + granteeType + ":" + granteeId
|
||||
+ ";请求 scope=" + scope + ";候选授权 " + grants.size() + " 条");
|
||||
}
|
||||
@@ -213,7 +214,7 @@ public class ResourceGrantController extends TdcCrudController<ResourceGrantEnti
|
||||
|
||||
boolean ok = resourceGrantService.save(g);
|
||||
if (ok) {
|
||||
audit(ssw.tds.audit.AuditAction.CREATE, g.getId(), resourceId, "SUCCESS", null,
|
||||
audit(AuditAction.CREATE, g.getId(), resourceId, "SUCCESS", null,
|
||||
"自助申请资源授权:申请人=" + granteeType + ":" + granteeId
|
||||
+ ";scope=" + g.getScope() + ";状态=PENDING 待审批"
|
||||
+ (g.getExpireTime() != null ? ";期望有效期至=" + g.getExpireTime() : "")
|
||||
@@ -232,7 +233,7 @@ public class ResourceGrantController extends TdcCrudController<ResourceGrantEnti
|
||||
g.setLastModifyTime(new Date());
|
||||
resourceGrantService.updateById(g);
|
||||
// 授权生效 = 数据可以流动的起点,这是可信数据空间里份量最重的一条留痕
|
||||
audit(ssw.tds.audit.AuditAction.GRANT, id, g.getResourceId(), "SUCCESS", null,
|
||||
audit(AuditAction.GRANT, id, g.getResourceId(), "SUCCESS", null,
|
||||
"授权审批通过:PENDING -> ACTIVE;被授权方=" + g.getGranteeType() + ":" + g.getGranteeId()
|
||||
+ ";scope=" + g.getScope()
|
||||
+ ";有效期至=" + (g.getExpireTime() == null ? "长期" : g.getExpireTime())
|
||||
@@ -251,7 +252,7 @@ public class ResourceGrantController extends TdcCrudController<ResourceGrantEnti
|
||||
g.setStatus("REVOKED");
|
||||
g.setLastModifyTime(new Date());
|
||||
resourceGrantService.updateById(g);
|
||||
audit(ssw.tds.audit.AuditAction.REVOKE, id, g.getResourceId(), "SUCCESS", null,
|
||||
audit(AuditAction.REVOKE, id, g.getResourceId(), "SUCCESS", null,
|
||||
"授权撤销:" + from + " -> REVOKED;被授权方=" + g.getGranteeType() + ":" + g.getGranteeId()
|
||||
+ ";scope=" + g.getScope() + ";自此刻起不得再访问该资源");
|
||||
return ActionResult.success("已撤销", id);
|
||||
|
||||
+3
-2
@@ -23,6 +23,7 @@ import ssw.tdc.entity.ResourcePublishAuditEntity;
|
||||
import ssw.tdc.service.ConfidentService;
|
||||
import ssw.tdc.service.ResourcePublishAuditService;
|
||||
import ssw.tdc.service.ResourceService;
|
||||
import ssw.tdc.audit.AuditAction;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -116,7 +117,7 @@ public class ResourcePublishAuditController extends TdcCrudController<ResourcePu
|
||||
}
|
||||
|
||||
// 资源上架/下架审批 = 数据能否进入流通市场的准入决策,审批人/意见/资源状态变化都要落链
|
||||
audit(ssw.tds.audit.AuditAction.APPROVE, id,
|
||||
audit(AuditAction.APPROVE, id,
|
||||
res != null ? res.getName() : audit.getResourceId(), "SUCCESS", null,
|
||||
"上架审批通过:动作=" + audit.getAction()
|
||||
+ ";资源=" + audit.getResourceId()
|
||||
@@ -144,7 +145,7 @@ public class ResourcePublishAuditController extends TdcCrudController<ResourcePu
|
||||
+ (body == null ? "" : body.getOrDefault("comment", "")) + "]";
|
||||
audit.setDecisionsJson(decisions);
|
||||
publishAuditService.updateById(audit);
|
||||
audit(ssw.tds.audit.AuditAction.REJECT, id, audit.getResourceId(), "DENY",
|
||||
audit(AuditAction.REJECT, id, audit.getResourceId(), "DENY",
|
||||
body == null ? "未填写驳回原因" : body.getOrDefault("comment", "未填写驳回原因"),
|
||||
"上架审批驳回:动作=" + audit.getAction() + ";资源=" + audit.getResourceId()
|
||||
+ ";资源保持原状态未进入流通");
|
||||
|
||||
+13
-10
@@ -14,6 +14,8 @@ import jnpf.util.RandomUtil;
|
||||
import jnpf.util.UserProvider;
|
||||
import ssw.common.permission.SswDataScopeResolver;
|
||||
import ssw.common.permission.SswPermissionGuard;
|
||||
import ssw.tdc.audit.AuditAction;
|
||||
import ssw.tdc.client.TdcTdsClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -118,12 +120,13 @@ public abstract class TdcCrudController<T extends SuperExtendEntity<String>> {
|
||||
// ------------------------------------------------------------------ 审计留痕扩展点
|
||||
|
||||
/**
|
||||
* 审计留痕记录器(写入 TDS 侧 {@code tds_audit_log})。
|
||||
* <p>TDC 是数据持有方本地的连接器,它的操作痕迹同样要汇聚到运营方中枢,
|
||||
* 审计留痕记录器(跨系统写入运营方 TDS 中枢,走 {@link TdcTdsClient})。
|
||||
* <p>TDC 是独立部署的数据持有方,不依赖 TDS 模块;其操作痕迹通过 HTTP 汇聚到运营方中枢,
|
||||
* 供方/需方/监管方才能在同一条哈希链上核对"数据出没出去、出去几次"。
|
||||
* 未配置 {@code ssw.tds.base-url} 时由 {@code NoopTdcTdsClient} 静默降级。
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
private ssw.tds.audit.AuditTrailRecorder auditTrailRecorder;
|
||||
private TdcTdsClient tdcTdsClient;
|
||||
|
||||
/**
|
||||
* 本控制器对应的业务类型。默认由实体类名推导,返回 {@code null} 表示不留痕。
|
||||
@@ -155,20 +158,20 @@ public abstract class TdcCrudController<T extends SuperExtendEntity<String>> {
|
||||
/** 写一条业务留痕 */
|
||||
protected void audit(String action, String bizId, String target) {
|
||||
String bizType = auditBizType();
|
||||
if (auditTrailRecorder == null || bizType == null) {
|
||||
if (tdcTdsClient == null || bizType == null) {
|
||||
return;
|
||||
}
|
||||
auditTrailRecorder.record(bizType, bizId, action, target);
|
||||
tdcTdsClient.recordAudit(bizType, bizId, action, target);
|
||||
}
|
||||
|
||||
/** 写一条带结果与明细的业务留痕 */
|
||||
protected void audit(String action, String bizId, String target,
|
||||
String result, String failReason, String detail) {
|
||||
String bizType = auditBizType();
|
||||
if (auditTrailRecorder == null || bizType == null) {
|
||||
if (tdcTdsClient == null || bizType == null) {
|
||||
return;
|
||||
}
|
||||
auditTrailRecorder.record(bizType, bizId, action, target, result, failReason, detail);
|
||||
tdcTdsClient.recordAudit(bizType, bizId, action, target, result, failReason, detail);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 通用接口
|
||||
@@ -217,7 +220,7 @@ public abstract class TdcCrudController<T extends SuperExtendEntity<String>> {
|
||||
entity.setDeleteMark(null);
|
||||
beforeSave(entity, true);
|
||||
service().save(entity);
|
||||
audit(ssw.tds.audit.AuditAction.CREATE, entity.getId(), auditTarget(entity));
|
||||
audit(AuditAction.CREATE, entity.getId(), auditTarget(entity));
|
||||
return ActionResult.success("新增成功", entity.getId());
|
||||
}
|
||||
|
||||
@@ -239,7 +242,7 @@ public abstract class TdcCrudController<T extends SuperExtendEntity<String>> {
|
||||
beforeSave(entity, false);
|
||||
service().updateById(entity);
|
||||
// 用改前的实体取 target:改后的对象只带请求体里出现的字段,编号往往是 null
|
||||
audit(ssw.tds.audit.AuditAction.UPDATE, id, auditTarget(exists));
|
||||
audit(AuditAction.UPDATE, id, auditTarget(exists));
|
||||
return ActionResult.success("修改成功", id);
|
||||
}
|
||||
|
||||
@@ -259,7 +262,7 @@ public abstract class TdcCrudController<T extends SuperExtendEntity<String>> {
|
||||
update.setDeleteUserId(safeUserId());
|
||||
service().updateById(update);
|
||||
// 删除是最敏感的动作 —— 参与方最关心"我的数据有没有被悄悄删掉"
|
||||
audit(ssw.tds.audit.AuditAction.DELETE, id, auditTarget(exists));
|
||||
audit(AuditAction.DELETE, id, auditTarget(exists));
|
||||
return ActionResult.success("删除成功", id);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
<artifactId>ssw-tdc-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- ContractController 业务全景引用 ssw.tdc.entity.{OrderEntity,DeliveryTaskEntity,ApiConsumeLogEntity} -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tdc-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-common-all</artifactId>
|
||||
|
||||
+8
-2
@@ -35,9 +35,15 @@ public class CertController {
|
||||
if (status != null && !status.isEmpty()) qw.eq("f_status", status);
|
||||
if (kind != null && !kind.isEmpty()) qw.eq("f_kind", kind);
|
||||
qw.apply("(f_delete_mark IS NULL OR f_delete_mark = 0)");
|
||||
qw.orderByDesc("f_creator_time");
|
||||
// [FIX] count 必须在加 ORDER BY 之前:MP 的 count(wrapper) 会把 ORDER BY 原样拼进
|
||||
// SELECT COUNT(*),PostgreSQL 报 "column f_creator_time must appear in the GROUP BY clause"
|
||||
long total = certService.count(qw);
|
||||
qw.last("limit " + (currentPage - 1) * pageSize + "," + pageSize);
|
||||
qw.orderByDesc("f_creator_time");
|
||||
// [FIX] 原 "limit off,size" 是 MySQL 专有语法,PostgreSQL 不认;
|
||||
// 改标准 LIMIT n OFFSET m(PG / MySQL 通用)
|
||||
long size = pageSize <= 0 ? 20 : Math.min(pageSize, 500);
|
||||
long offset = Math.max(0, (currentPage - 1) * size);
|
||||
qw.last("LIMIT " + size + " OFFSET " + offset);
|
||||
List<CertEntity> rows = certService.list(qw);
|
||||
Map<String, Object> r = new HashMap<>();
|
||||
r.put("list", rows);
|
||||
|
||||
+8
-2
@@ -33,9 +33,15 @@ public class LicenseController {
|
||||
if (status != null && !status.isEmpty()) qw.eq("f_status", status);
|
||||
if (plan != null && !plan.isEmpty()) qw.eq("f_plan", plan);
|
||||
qw.apply("(f_delete_mark IS NULL OR f_delete_mark = 0)");
|
||||
qw.orderByDesc("f_creator_time");
|
||||
// [FIX] count 必须在加 ORDER BY 之前:MP 的 count(wrapper) 会把 ORDER BY 原样拼进
|
||||
// SELECT COUNT(*),PostgreSQL 报 "column f_creator_time must appear in the GROUP BY clause"
|
||||
long total = licenseService.count(qw);
|
||||
qw.last("limit " + (currentPage - 1) * pageSize + "," + pageSize);
|
||||
qw.orderByDesc("f_creator_time");
|
||||
// [FIX] 原 "limit off,size" 是 MySQL 专有语法,PostgreSQL 不认;
|
||||
// 改标准 LIMIT n OFFSET m(PG / MySQL 通用)
|
||||
long size = pageSize <= 0 ? 20 : Math.min(pageSize, 500);
|
||||
long offset = Math.max(0, (currentPage - 1) * size);
|
||||
qw.last("LIMIT " + size + " OFFSET " + offset);
|
||||
List<LicenseEntity> rows = licenseService.list(qw);
|
||||
Map<String, Object> r = new HashMap<>();
|
||||
r.put("list", rows);
|
||||
|
||||
+8
-2
@@ -31,9 +31,15 @@ public class QuotaController {
|
||||
if (dimension != null && !dimension.isEmpty()) qw.eq("f_dimension", dimension);
|
||||
if (metric != null && !metric.isEmpty()) qw.eq("f_metric", metric);
|
||||
qw.apply("(f_delete_mark IS NULL OR f_delete_mark = 0)");
|
||||
qw.orderByDesc("f_creator_time");
|
||||
// [FIX] count 必须在加 ORDER BY 之前:MP 的 count(wrapper) 会把 ORDER BY 原样拼进
|
||||
// SELECT COUNT(*),PostgreSQL 报 "column f_creator_time must appear in the GROUP BY clause"
|
||||
long total = quotaService.count(qw);
|
||||
qw.last("limit " + (currentPage - 1) * pageSize + "," + pageSize);
|
||||
qw.orderByDesc("f_creator_time");
|
||||
// [FIX] 原 "limit off,size" 是 MySQL 专有语法,PostgreSQL 不认;
|
||||
// 改标准 LIMIT n OFFSET m(PG / MySQL 通用)
|
||||
long size = pageSize <= 0 ? 20 : Math.min(pageSize, 500);
|
||||
long offset = Math.max(0, (currentPage - 1) * size);
|
||||
qw.last("LIMIT " + size + " OFFSET " + offset);
|
||||
List<QuotaEntity> rows = quotaService.list(qw);
|
||||
Map<String, Object> r = new HashMap<>();
|
||||
r.put("list", rows);
|
||||
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
package ssw.tds.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jnpf.base.ActionResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ssw.tds.audit.AuditRecordAssembler;
|
||||
import ssw.tds.audit.AuditTrailRecorder;
|
||||
import ssw.tds.audit.EvidenceAssembler;
|
||||
import ssw.tds.entity.ConnectorEntity;
|
||||
import ssw.tds.entity.ContractEntity;
|
||||
import ssw.tds.entity.DataProductEntity;
|
||||
import ssw.tds.service.ConnectorService;
|
||||
import ssw.tds.service.ContractService;
|
||||
import ssw.tds.service.DataProductService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TDS 内部桥接入口(供 TDC 聚合运营方全景)[TDC 跨系统读 §Bridge]
|
||||
*
|
||||
* <p>TDC 是独立部署的数据持有方(不连 TDS 库),但其「业务全景 / 信任一屏」需要聚合运营方
|
||||
* TDS 侧的数据(上游合约、连接器、数据产品、哈希链审计、链上存证、审核记录,以及把自己的
|
||||
* 操作留痕汇聚到运营方中枢)。这些跨系统读走 {@code TdcTdsClient}(HTTP 实现
|
||||
* {@code HttpTdcTdsClient}),本控制器就是它依赖的运营方 TDS 侧出口。</p>
|
||||
*
|
||||
* <p>鉴权模型与 {@code DatasetInternalController} 一致:
|
||||
* <ul>
|
||||
* <li>{@link SaIgnore} 跳过 Sa-Token 用户登录</li>
|
||||
* <li>独立 URL 前缀 {@code /api/ssw/tds/Bridge/**},进 {@code exclude-url}
|
||||
* 绕过 JNPF AuthFilter</li>
|
||||
* <li>内部鉴权:{@code App-Code: tdc} + {@code X-Internal-Token: <tds.internal-secret>}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>聚合类端点(审计链/存证/审核记录)直接复用 tds-biz 的装配器
|
||||
* {@link EvidenceAssembler} / {@link AuditRecordAssembler},避免再写一遍丢字段的组装代码;
|
||||
* 留痕端点复用 {@link AuditTrailRecorder} 把 TDC 操作痕迹写入 {@code tds_audit_log} 哈希链。</p>
|
||||
*
|
||||
* @author SSW-TDS
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController("tdsBridgeInternalController")
|
||||
@RequestMapping("/api/ssw/tds/Bridge")
|
||||
@Tag(name = "TDS 内部桥接入口", description = "供 TDC 等内部子系统聚合运营方全景,App-Code=tdc + X-Internal-Token 鉴权")
|
||||
public class TdsBridgeInternalController {
|
||||
|
||||
/** 唯一允许的 App-Code:只有 TDC 节点能来聚合运营方全景 */
|
||||
public static final java.util.Set<String> ALLOWED_APP_CODES = java.util.Set.of("tdc");
|
||||
|
||||
@Autowired(required = false)
|
||||
private ContractService contractService;
|
||||
@Autowired(required = false)
|
||||
private ConnectorService connectorService;
|
||||
@Autowired(required = false)
|
||||
private DataProductService dataProductService;
|
||||
@Autowired(required = false)
|
||||
private EvidenceAssembler evidenceAssembler;
|
||||
@Autowired(required = false)
|
||||
private AuditRecordAssembler auditRecordAssembler;
|
||||
@Autowired(required = false)
|
||||
private AuditTrailRecorder auditTrailRecorder;
|
||||
|
||||
@Value("${tds.internal-secret:}")
|
||||
private String internalSecret;
|
||||
|
||||
// ============================================================ 鉴权
|
||||
|
||||
/**
|
||||
* 校验内部调用身份:App-Code 白名单 + 可选 X-Internal-Token。
|
||||
*
|
||||
* @return 非 null 表示鉴权失败(已封装好 {@link ActionResult}),调用方直接 return
|
||||
*/
|
||||
private ActionResult<Map<String, Object>> checkAuth(String appCode, String token) {
|
||||
if (appCode == null || !ALLOWED_APP_CODES.contains(appCode.toLowerCase())) {
|
||||
log.warn("[TDS-BRIDGE] 拒绝内部调用:App-Code 不匹配 actual={}", appCode);
|
||||
return ActionResult.fail("App-Code invalid");
|
||||
}
|
||||
if (internalSecret != null && !internalSecret.isEmpty() && !internalSecret.equals(token)) {
|
||||
log.warn("[TDS-BRIDGE] 拒绝内部调用:X-Internal-Token 不匹配");
|
||||
return ActionResult.fail("X-Internal-Token invalid");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ============================================================ GET 概览(业务全景三维)
|
||||
|
||||
@SaIgnore
|
||||
@GetMapping("/Contract/{id}")
|
||||
@Operation(summary = "合约概览", description = "TDC 业务全景聚合运营方合约(合约号/配额)")
|
||||
public ActionResult<Map<String, Object>> contract(
|
||||
@RequestHeader(value = "App-Code", required = false) String appCode,
|
||||
@RequestHeader(value = "X-Internal-Token", required = false) String token,
|
||||
@PathVariable("id") String id) {
|
||||
ActionResult<Map<String, Object>> denied = checkAuth(appCode, token);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
if (contractService == null) {
|
||||
return ActionResult.fail("合约服务不可用");
|
||||
}
|
||||
ContractEntity c = contractService.getById(id);
|
||||
if (c == null) {
|
||||
return ActionResult.fail("合约不存在:" + id);
|
||||
}
|
||||
Map<String, Object> m = new LinkedHashMap<>(8);
|
||||
m.put("id", c.getId());
|
||||
m.put("contractCode", c.getContractCode());
|
||||
m.put("name", c.getName());
|
||||
m.put("status", c.getStatus());
|
||||
m.put("quotaTotal", c.getQuotaTotal());
|
||||
m.put("quotaUsed", c.getQuotaUsed());
|
||||
m.put("productId", c.getProductId());
|
||||
m.put("providerConnectorId", c.getProviderConnectorId());
|
||||
return ActionResult.success(m);
|
||||
}
|
||||
|
||||
@SaIgnore
|
||||
@GetMapping("/Connector/{id}")
|
||||
@Operation(summary = "连接器概览", description = "TDC 业务全景聚合运营方连接器(编码/名称/状态/机构)")
|
||||
public ActionResult<Map<String, Object>> connector(
|
||||
@RequestHeader(value = "App-Code", required = false) String appCode,
|
||||
@RequestHeader(value = "X-Internal-Token", required = false) String token,
|
||||
@PathVariable("id") String id) {
|
||||
ActionResult<Map<String, Object>> denied = checkAuth(appCode, token);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
if (connectorService == null) {
|
||||
return ActionResult.fail("连接器服务不可用");
|
||||
}
|
||||
ConnectorEntity c = connectorService.getById(id);
|
||||
if (c == null) {
|
||||
return ActionResult.fail("连接器不存在:" + id);
|
||||
}
|
||||
Map<String, Object> m = new LinkedHashMap<>(8);
|
||||
m.put("id", c.getId());
|
||||
m.put("connectorCode", c.getConnectorCode());
|
||||
m.put("name", c.getName());
|
||||
m.put("status", c.getStatus());
|
||||
m.put("orgName", c.getOrgName());
|
||||
return ActionResult.success(m);
|
||||
}
|
||||
|
||||
@SaIgnore
|
||||
@GetMapping("/DataProduct/{id}")
|
||||
@Operation(summary = "数据产品概览", description = "TDC 业务全景聚合运营方数据产品(提供方连接器/状态)")
|
||||
public ActionResult<Map<String, Object>> dataProduct(
|
||||
@RequestHeader(value = "App-Code", required = false) String appCode,
|
||||
@RequestHeader(value = "X-Internal-Token", required = false) String token,
|
||||
@PathVariable("id") String id) {
|
||||
ActionResult<Map<String, Object>> denied = checkAuth(appCode, token);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
if (dataProductService == null) {
|
||||
return ActionResult.fail("数据产品服务不可用");
|
||||
}
|
||||
DataProductEntity p = dataProductService.getById(id);
|
||||
if (p == null) {
|
||||
return ActionResult.fail("数据产品不存在:" + id);
|
||||
}
|
||||
Map<String, Object> m = new LinkedHashMap<>(8);
|
||||
m.put("id", p.getId());
|
||||
m.put("name", p.getName());
|
||||
m.put("status", p.getStatus());
|
||||
m.put("providerConnectorId", p.getProviderConnectorId());
|
||||
return ActionResult.success(m);
|
||||
}
|
||||
|
||||
// ============================================================ POST 聚合(可信证据 / 留痕)
|
||||
|
||||
@SaIgnore
|
||||
@PostMapping("/AuditChain")
|
||||
@Operation(summary = "审计哈希链", description = "按 bizIds 聚合审计留痕哈希链(含逐条 hashValid/linked/chainIntact 校验)")
|
||||
public ActionResult<Map<String, Object>> auditChain(
|
||||
@RequestHeader(value = "App-Code", required = false) String appCode,
|
||||
@RequestHeader(value = "X-Internal-Token", required = false) String token,
|
||||
@RequestBody Map<String, Object> body) {
|
||||
ActionResult<Map<String, Object>> denied = checkAuth(appCode, token);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
if (evidenceAssembler == null) {
|
||||
return ActionResult.fail("审计装配器不可用");
|
||||
}
|
||||
return ActionResult.success(evidenceAssembler.auditChain(bizIdsOf(body)));
|
||||
}
|
||||
|
||||
@SaIgnore
|
||||
@PostMapping("/ChainEvidence")
|
||||
@Operation(summary = "链上存证", description = "按 bizIds 聚合飞梭链存证(含 status/verifyResult 等,能区分成功/失败/待确认)")
|
||||
public ActionResult<Map<String, Object>> chainEvidence(
|
||||
@RequestHeader(value = "App-Code", required = false) String appCode,
|
||||
@RequestHeader(value = "X-Internal-Token", required = false) String token,
|
||||
@RequestBody Map<String, Object> body) {
|
||||
ActionResult<Map<String, Object>> denied = checkAuth(appCode, token);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
if (evidenceAssembler == null) {
|
||||
return ActionResult.fail("审计装配器不可用");
|
||||
}
|
||||
return ActionResult.success(evidenceAssembler.chainEvidences(bizIdsOf(body)));
|
||||
}
|
||||
|
||||
@SaIgnore
|
||||
@PostMapping("/AuditRecord")
|
||||
@Operation(summary = "审核记录", description = "按 bizIds 反查 tds_audit_record,业务全景「授权/审核」区块")
|
||||
public ActionResult<Map<String, Object>> auditRecord(
|
||||
@RequestHeader(value = "App-Code", required = false) String appCode,
|
||||
@RequestHeader(value = "X-Internal-Token", required = false) String token,
|
||||
@RequestBody Map<String, Object> body) {
|
||||
ActionResult<Map<String, Object>> denied = checkAuth(appCode, token);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
if (auditRecordAssembler == null) {
|
||||
return ActionResult.fail("审核记录装配器不可用");
|
||||
}
|
||||
return ActionResult.success(auditRecordAssembler.auditRecords(bizIdsOf(body)));
|
||||
}
|
||||
|
||||
@SaIgnore
|
||||
@PostMapping("/AuditTrail")
|
||||
@Operation(summary = "业务留痕", description = "TDC 操作痕迹汇聚到运营方 tds_audit_log(哈希链留痕)")
|
||||
public ActionResult<Map<String, Object>> auditTrail(
|
||||
@RequestHeader(value = "App-Code", required = false) String appCode,
|
||||
@RequestHeader(value = "X-Internal-Token", required = false) String token,
|
||||
@RequestBody Map<String, Object> body) {
|
||||
ActionResult<Map<String, Object>> denied = checkAuth(appCode, token);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
if (auditTrailRecorder == null) {
|
||||
return ActionResult.fail("审计留痕记录器不可用");
|
||||
}
|
||||
String bizType = str(body.get("bizType"));
|
||||
String bizId = str(body.get("bizId"));
|
||||
String action = str(body.get("action"));
|
||||
String target = str(body.get("target"));
|
||||
if (bizType == null || bizType.isBlank() || bizId == null || bizId.isBlank()) {
|
||||
return ActionResult.fail("bizType / bizId 必填");
|
||||
}
|
||||
try {
|
||||
auditTrailRecorder.record(bizType, bizId, action, target,
|
||||
str(body.get("result")), str(body.get("failReason")), str(body.get("detail")));
|
||||
} catch (Exception e) {
|
||||
log.warn("[TDS-BRIDGE] 留痕写入失败 bizType={} bizId={} : {}", bizType, bizId, e.getMessage());
|
||||
return ActionResult.fail("留痕写入失败:" + e.getMessage());
|
||||
}
|
||||
Map<String, Object> ok = new LinkedHashMap<>(2);
|
||||
ok.put("recorded", true);
|
||||
return ActionResult.success(ok);
|
||||
}
|
||||
|
||||
// ============================================================ 工具
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<String> bizIdsOf(Map<String, Object> body) {
|
||||
List<String> out = new ArrayList<>();
|
||||
if (body == null) {
|
||||
return out;
|
||||
}
|
||||
Object v = body.get("bizIds");
|
||||
if (v instanceof Collection) {
|
||||
for (Object o : (Collection<Object>) v) {
|
||||
if (o != null) {
|
||||
out.add(String.valueOf(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String str(Object o) {
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
String s = String.valueOf(o);
|
||||
return s.isEmpty() ? null : s;
|
||||
}
|
||||
}
|
||||
+98
-12
@@ -8,7 +8,7 @@
|
||||
```
|
||||
┌──────────────────────────────────────────┐ ┌────────────────────────────────────┐
|
||||
│ 本机 (macOS 192.168.97.x) │ │ OrbStack VM j7node (resolute) │
|
||||
│ │ │ 192.168.139.196 4G 内存 15G盘 │
|
||||
│ │ │ 192.168.139.95 4G 内存 32G盘 │
|
||||
│ ┌────────────────────────────────────┐ │ │ │
|
||||
│ │ scard server :8443 (Go) │◀─┼────┼── connector (Go) 192.168.139.67 │
|
||||
│ │ ├─ 软 PKI ca-cert.pem │ │ │ ├─ device_id=J7NODE-001 │
|
||||
@@ -113,7 +113,7 @@ sudo systemctl restart k3s
|
||||
|---|---|
|
||||
| `00-namespace.yaml` | ns=j7 + PV/PVC(hostPath `/var/lib/j7node/pg-data`) |
|
||||
| `05-pg-init.yaml` | ConfigMap `00-create-dbs.sql`:建 j7 / j7flow_node1 / tdc_node1 库(j7_node1 由 POSTGRES_DB 自动建) |
|
||||
| `10-postgres.yaml` | StatefulSet + Service(postgres:16-alpine, 5Gi hostPath) |
|
||||
| `10-postgres.yaml` | StatefulSet + Service(postgres:16-alpine,镜像走阿里云 mirror `crpi-.../ssw188/postgres:16-alpine`;数据卷 PVC `j7-pg-data` → hostPath `/var/lib/j7node/pg-data`;`limits.memory=3Gi`) |
|
||||
| `20-redis.yaml` | Deployment + Service(redis:latest,`--requirepass 123456`) |
|
||||
| `30-admin.yaml` | Deployment + Service NodePort 31000(liberica-openjre-rocky:21 + hostPath jar) |
|
||||
|
||||
@@ -130,9 +130,46 @@ j7-postgres-0 1/1 Running
|
||||
j7-redis-... 1/1 Running
|
||||
```
|
||||
|
||||
admin 完整启动需要 ~90s(Spring Boot + 4 数据源 init + Quartz + Redisson 24 连接)。
|
||||
> **注意**:上面的 3 个 Pod Running 后,postgres 里只有**空库**(`j7` / `j7flow_node1` / `tdc_node1` / `j7_node1`,由 `05-pg-init` 创建),还没有表结构和种子数据,admin 登录会报「账号不存在」。必须做下面的数据库初始化。
|
||||
|
||||
外部访问:admin NodePort `http://192.168.139.196:31000/api/oauth/Login`
|
||||
### 3.1 数据库初始化(schema + seed)
|
||||
|
||||
k8s 清单只负责起 Pod,不负责灌库。实测灌库步骤(2026-08-13 跑通):
|
||||
|
||||
1. **恢复三库 schema**
|
||||
- sswflow:`docs/db/0813/sswflow/schema.sql`(13 表)→ 库 `j7flow_node1`
|
||||
- tdc:`docs/db/0813/tdc/schema.sql`(33 表)→ 库 `tdc_node1`
|
||||
- j7 平台主库(123 表):从本机 mac 开发库 `192.168.139.3:15432`(库名 `j7`)`pg_dump --schema-only` → VM postgres 的 `j7` 库
|
||||
- 灌库方式(VM 内 postgres pod 自带 psql/pg_dump,可直连 mac 源库):
|
||||
```bash
|
||||
orb -m j7node k3s kubectl -n j7 exec j7-postgres-0 -- sh -c '
|
||||
PGPASSWORD=dacli123 psql -U dacli -h 127.0.0.1 -d j7flow_node1 -f /dev/stdin
|
||||
' < /Users/xs/Desktop/ssw/docs/db/0813/sswflow/schema.sql
|
||||
# tdc / j7 同理(j7 用 pg_dump --schema-only 从 mac 拉)
|
||||
```
|
||||
|
||||
2. **j7 平台主库全量 seed**(admin/123456 能登录的关键)
|
||||
- 从 mac 本地 j7 库 `pg_dump --data-only` 经网络导入 VM postgres。
|
||||
- ⚠️ **OOM 坑**:postgres pod 默认内存 limit 1Gi 时,全量 seed 会被 kill(exit 137)。已把 `10-postgres.yaml` 的 `limits.memory` 提到 **3Gi**、`requests.memory` 提到 **1Gi**。
|
||||
- 在 pod 内 `nohup` 后台跑(源带 `PGPASSWORD`,避免交互):
|
||||
```bash
|
||||
orb -m j7node k3s kubectl -n j7 exec j7-postgres-0 -- sh -c '
|
||||
nohup sh -c "PGPASSWORD=<mac_j7_pwd> pg_dump --data-only -h 192.168.139.3 -p 15432 -U dacli j7 \
|
||||
| PGPASSWORD=dacli123 psql -U dacli -h 127.0.0.1 -d j7" > /tmp/seed.log 2>&1 &
|
||||
'
|
||||
# 等 seed 完成:tail /tmp/seed.log 看到 SEED_DONE 且 rc=0
|
||||
# 验收:j7.base_user 应有 276 行(admin 账号 f_id=349057407209541 等忠实复制)
|
||||
```
|
||||
|
||||
3. **重启 admin 让连接生效**
|
||||
```bash
|
||||
orb -m j7node k3s kubectl -n j7 rollout restart deployment/j7-admin
|
||||
# 等 ~90s,readinessProbe 探 /api/oauth/Login 变 Ready
|
||||
```
|
||||
|
||||
admin 完整启动需要 ~90s(Spring Boot + 3 数据源 init + Quartz + Redisson 24 连接)。
|
||||
|
||||
外部访问:admin NodePort `http://192.168.139.95:31000/api/oauth/Login`
|
||||
|
||||
## 4. Connector 部署(Go 二进制裸跑,不放 Pod)
|
||||
|
||||
@@ -162,8 +199,8 @@ orb -m j7node bash -c '
|
||||
|
||||
1. **JNPF 平台主库硬编码 `db-name: j7`** —— admin pod 必须连 `j7` 库,否则报 `database "j7" does not exist`。init script 多建 `CREATE DATABASE j7`。
|
||||
2. **redis 默认无密码但 admin 要求 123456** —— redis 容器必须 `--requirepass 123456`。
|
||||
3. **JNPF 7 多租户登录**(`singleLogin=2`):账号必须带 `@tenantId` 后缀(如 `admin@0`),且对应独立 DB——VM 端 j7_node1 是空 schema 无法登录,业务查询报 `relation "base_sys_config" does not exist`。
|
||||
4. **JNPF 密码算法**:`md5(md5(plain) + secretkey)`,不是单纯的 md5(plain)。
|
||||
3. **JNPF 7 登录**:本仓 j7 全量 seed 后,admin 用 `account=admin`(**不带 @tenantId 后缀**)即可登录;早期担心「必须 @tenantId」是空 schema 时的误判。登录 API 的密码是 **AES-256-ECB 加密**(见 §8.1),与本仓 `base_user.f_password` 列的存储哈希算法不同,别混。
|
||||
4. **JNPF 密码列存储算法**:`base_user.f_password = md5(md5(plain) + secretkey)`,secretkey=`EY8WePvjM5GGwQzn`,不是单纯 md5(plain)。admin 真实密码是 `123456`。
|
||||
5. **OrbStack session 退出 SIGHUP 所有子进程** —— 必须用 systemd / `run_in_background` 长任务,nohup + setsid + disown 都无效。
|
||||
6. **k3s binary 下载**(VM 内):github release 受限,用 gh-proxy.com;本机下载后可用 `install -m 0755` 推到 `/usr/local/bin/`。
|
||||
7. **NodePort 范围 30000-32767** —— admin 用 31000 而非 33000。
|
||||
@@ -171,11 +208,14 @@ orb -m j7node bash -c '
|
||||
9. **docker.io 在 OrbStack VM 内被墙**:必须配 containerd mirror,否则 pause 镜像拉不下来 pod 卡 ContainerCreating。
|
||||
10. **PVC 重建**:删 StatefulSet 时 PVC 不会自动删,需手动 `kubectl delete pvc j7-pg-data` + `kubectl delete pv j7-pg-data-pv` + `rm -rf /var/lib/j7node/pg-data/*` 才能重 init。
|
||||
|
||||
## 6. 待办
|
||||
## 6. 待办 / 状态
|
||||
|
||||
- [ ] 把本机 j7 库的 331 张表 schema dump → VM j7 库,让 admin pod 跑完整业务(耗时)
|
||||
- [ ] 把 VM pod 切到 hostNetwork / HostPort 暴露给 VM 外的访问
|
||||
- [ ] JVM heap 调优(当前 Xmx1500m,pod ready 后 GC 频繁)
|
||||
- [x] j7 库 schema + 全量 seed(admin/123456 可登录)— 2026-08-13 完成
|
||||
- [x] k3s + 3 Pod 拉起(j7-postgres-0 / j7-redis / j7-admin)— 2026-08-13 完成
|
||||
- [x] admin 经 NodePort 31000 从 mac 直连可达(无需 hostNetwork,NodePort 已满足「VM 外访问」)— 2026-08-13 完成
|
||||
- [ ] JVM heap 调优(当前 Xmx1500m,pod ready 后 GC 频繁;可改 tdc+sswflow-only jar 减 bean)
|
||||
- [ ] 消除 tds 调度噪音(full jar 加载 tds 定时任务 bean,j7node 无 tds 数据源 → 周期性报错;可选构建 tdc+sswflow-only jar 或排除 tds 自动配置)
|
||||
- [ ] (可选)VM 内再裸跑 connector 接入 scard 安全平面(见 §4,协议已验证,本轮未重复执行)
|
||||
|
||||
## 7. 端到端验证清单
|
||||
|
||||
@@ -183,6 +223,52 @@ orb -m j7node bash -c '
|
||||
|---|---|---|
|
||||
| k3s ready | `sudo /usr/local/bin/k3s kubectl get nodes` | `j7node Ready control-plane,master` |
|
||||
| pod ready | `sudo /usr/local/bin/k3s kubectl -n j7 get pods` | 3 个 pod 都 1/1 Running |
|
||||
| admin NodePort | `curl -sk http://192.168.139.196:31000/api/oauth/Login` | HTTP 200(登录返回 400 是空 schema 预期) |
|
||||
| admin NodePort | `curl -sk http://192.168.139.95:31000/api/oauth/Login` | HTTP 200(登录返回 400 是空 schema 预期) |
|
||||
| connector 注册 | VM 上 connector log | `[RUNNING] Registered device: J7NODE-001 (status: active)` |
|
||||
| host scard | `curl -sk https://127.0.0.1:8443/api/v1/device/status \| jq '.[].device_id'` | 包含 `J7NODE-001` |
|
||||
| host scard | `curl -sk https://127.0.0.1:8443/api/v1/device/status \| jq '.[].device_id'` | 包含 `J7NODE-001` |
|
||||
|
||||
## 8. 业务栈验收 + 已知问题(2026-08-13 实测)
|
||||
|
||||
### 8.1 登录加密(务必记牢,否则 400/600)
|
||||
- 登录端点 `POST /api/oauth/Login`,body `application/x-www-form-urlencoded`:`account=admin&password=<AES>&grant_type=password`。
|
||||
- `password` = `md5(plain)` 字符串 → **AES-256-ECB-Pkcs7 → hex**(非 base64!);key = `md5("EY8WePvjM5GGwQzn")` 取前 32 字节 UTF-8。
|
||||
- 自测常量:`encryptPassword('123456') == 'd4958348e22108119b3ef57b022c83f4bf857dd0b247eaab15b9a43d47ee3c503900f7135bf0de255bc33620c3cdc02b'`。
|
||||
- 响应 `data.token` **已自带 `bearer ` 前缀** → auth header 须原样 `Authorization: <data.token>`(**不要再叠引号或第二个 bearer**,否则 600 Login expired)。
|
||||
- 另需带 `App-Code / Jnpf-Origin:pc / Vue-Version:3` 头(否则部分严格端点拒为 600)。
|
||||
|
||||
### 8.2 端点验收矩阵(mac 直连 192.168.139.95:31000,admin token)
|
||||
| 端点 | 结果 |
|
||||
|---|---|
|
||||
| LOGIN admin/123456 | 200 ✅ |
|
||||
| /api/ssw/tdc/DeliveryTask | 200 ✅ |
|
||||
| /api/ssw/tdc/Contract | 200 ✅ |
|
||||
| /api/ssw/tdc/Order | 200 ✅ |
|
||||
| /api/ssw/tdc/Space | 200 ✅ |
|
||||
| /api/ssw/tdc/Member | 200 ✅ |
|
||||
| /api/ssw/tdc/Identity | 200 ✅ |
|
||||
| /api/ssw/tdc/Resource | 200 ✅ |
|
||||
| /api/ssw/tdc/Demand | 200 ✅ |
|
||||
| /api/ssw/tdc/Product | 200 ✅ |
|
||||
| /api/ssw/tdc/Role | 200 ✅ |
|
||||
| /api/ssw/sswflow/Party/Self | 200 ✅ |
|
||||
| /api/ssw/sswflow/Dataset | 200 ✅ |
|
||||
|
||||
> **结论**:j7node 作为 TDC 数据持有方节点,真实 tdc + 本地 sswflow 业务端点**全绿**。
|
||||
|
||||
### 8.3 两个「400」是假象(不要被误导)
|
||||
最初报 `/api/ssw/tdc/Party/Self`、`/api/ssw/tdc/Connector` 返回 `code=400 System abnormality`,以为是「tdc 硬依赖 tds 数据源、违反红线」。复查发现是**探针 URL 写错**:
|
||||
- 前端(jweb)真实只用 `/api/ssw/sswflow/Party/Self`(200)和 `/api/ssw/tds/Connector/...`(运营方 TDS 专属页,纯 TDC 节点本就不该有 → 400 符合红线);轻量 `web/src/api` 无任何业务 API 定义。
|
||||
- `/tdc/Sandbox`、`/sswflow/FlowRun` 的 400 是**缺 action 段**(如 `/Sandbox/List`)导致的 404→400(日志原文 `No static resource api/ssw/tdc/Sandbox.`),非功能失败。
|
||||
- 日志里周期性 `CannotFindDataSource: tds` 来自**后台 TDS 调度任务**(NotifyTicker 等随 full fat-jar 加载,j7node 未配 tds 数据源)→ 仅日志噪音,不影响 TDC 业务。属「full jar 在 tdc 节点加载了 tds bean」这一已知架构 smell。
|
||||
|
||||
**因此无需按 TdcTdsClient 重构**(初判前提为假)。可选后续见 §6。
|
||||
|
||||
### 8.4 部署形态红线(重申)
|
||||
- j7node full fat-jar 经 hostPath 挂入 pod(`boot/ssw-admin/target/*.jar`),改 jar 后须 `rollout restart deployment/j7-admin` 才生效。
|
||||
- 正式 TDC 部署须落在 scard 安全方案内(见 §4 + `docs/scard/`);本机/VM 单 jar 仅供联调,不是正式形态(已写入 AGENTS.md / MEMORY.md)。
|
||||
|
||||
## 9. 后续可选增强
|
||||
1. **tdc+sswflow-only jar**:当前用 full fat-jar(含 ssw-tds 类),导致后台 tds 调度任务周期性报「找不到 tds 数据源」。若需干净日志,可构建仅含 `ssw-common-*`+`ssw-tdc-*`+`ssw-sswflow-*` 的 role jar(`mvn -P tdc-only ...` 思路扩展为 `tdc-sswflow` profile),或给 ssw-tds 调度 bean 加 `@Profile("tds")` 排除。
|
||||
2. **JVM heap 调优**:pod limit 2Gi / Xmx1500m,GC 频繁时可降到 1.2G 或精简 bean。
|
||||
3. **跨节点业务全景**:如需在 j7node 聚合展示运营方 TDS 数据,按 `TdcTdsClient` 抽象(Noop/Http 双实现)+ §4 的 scard 安全平面打通,而非在 j7node 直接连 tds 库。
|
||||
4. **connector 接入**:§4 协议已验证,可在 j7node 内裸跑 connector 接入本机 scard server,形成「VM connector → 本机 scard → 本机 tds 安全平面」完整链路演示。
|
||||
@@ -254,6 +254,82 @@ ssw:
|
||||
- **V1.3** ✅ 2026-08-13 落地:对账调度器。`FlowRunReconciliationScheduler` `@Scheduled` cron 凌晨 3 点(dev 用 `0/30 * * * * ?` 每 30 秒验证)扫描"合约 EFFECTIVE + f_flow_run_id 非空 + 没 billing_ledger"的合约 → 调 `SswflowClient.getRun` 查终态 → 写 `tds_billing_ledger` 并更新 `f_quota_used`。Migration `boot/db/tds/V1.5.0__tds_billing_ledger_run_id.sql`。
|
||||
- **V1.4** ✅ 2026-08-13 落地:TDC 触发链。DeliveryTask 新增 `/TriggerFlow` 端点直接调 SSWFLOW 跑 flow(绕开合约),用于"无需合约的一次性样本查询"。复用 `FlowRunInternalController`(App-Code 白名单扩展为 `tds` + `tdc`),trigger 派生为 `DELIVERY_DIRECT`(区分于 TDS 的 `CONTRACT_EFFECTIVE`)。新增 `TdcSswflowClient`(TDC 端简化版客户端,与 ssw.tds.client.SswflowClient 同构)。
|
||||
|
||||
## 11. V1.5:TDC 双 runtime(kata + Nax sidecar)
|
||||
|
||||
### 11.1 核心命题
|
||||
|
||||
> **原始数据不出域** = 数据持有方的明文永远不能离开其网络边界。
|
||||
|
||||
V1.4 的胶水层解决了"业务流程打通"的问题,但**计算引擎本身的位置没解决**:SSWFLOW 进程内的 `NaxComputeEngine` 仍在中心跑 LocalBackend——意味着真要跑 PSI/LR 时,明文数据仍然要从 Provider 推到 SSWFLOW 中心的 Nax 上。
|
||||
|
||||
V1.5 的目标:**把 Nax 下沉到 TDC 沙盒**(数据所在的域),SSWFLOW 只做编排调度,原始数据天然不出域。
|
||||
|
||||
### 11.2 TDC 双 runtime 现状(已就绪)
|
||||
|
||||
TDC 部署模板和 `K8sSandboxClient` 早已支持双 runtime:
|
||||
|
||||
```yaml
|
||||
# runtimeclass-kata.yaml — k8s 集群级 RuntimeClass
|
||||
apiVersion: node.k8s.io/v1
|
||||
kind: RuntimeClass
|
||||
metadata: { name: kata }
|
||||
handler: kata
|
||||
```
|
||||
|
||||
```yaml
|
||||
# tee-job.yaml — Job 模板,RUNTIME_CLASS 变量驱动切换
|
||||
runtimeClassName: ${RUNTIME_CLASS} # kata 或集群默认
|
||||
containers: [{ image: ${IMAGE} }] # python:3.11-slim(TEE)或 ssw-nax-runtime(NAX)
|
||||
```
|
||||
|
||||
```java
|
||||
// K8sSandboxClient.java:41-49
|
||||
@Value("${k8s.runtime-class:kata}") private String runtimeClass; // 默认 kata
|
||||
@Value("${k8s.tee-image:python:3.11-slim}") private String teeImage;
|
||||
@Value("${k8s.nax-image:ssw-nax-runtime:latest}") private String naxImage; // V1.5.1 新增
|
||||
```
|
||||
|
||||
TEE 计算(`runTeeJob`)已成熟:CDH + KBS + SEV-SNP 远程证明链路。**缺的是**:
|
||||
1. Nax 镜像本身(V1.5.1 已落地)
|
||||
2. `K8sSandboxClient.runNaxJob` 骨架(V1.5.2 已落地)
|
||||
3. connector 端声明"我跑哪个 runtime"的能力(V1.5.3 待办)
|
||||
4. 跨方 Nax SPDZ 协议 + dataset 强制本地化(V1.5.6 / V1.5.4 待办)
|
||||
|
||||
### 11.3 拍板决策(2026-08-13 17:08)
|
||||
|
||||
| 议题 | 决策 | 理由 |
|
||||
|---|---|---|
|
||||
| **connector 标识方式** | **方案 A**:复用 `f_type` 字段加新枚举 `TEE / NAX / BOTH`,现有 102 条 `BOTH` 视同 `NAX` | 改 datacli 一处即可,影响面最小;业务含义清晰 |
|
||||
| **Nax 镜像构建策略** | **dev minimal 起步**:`python:3.11-slim + numpy + pandas + nax 包`(不带 `[ray]` `[dev]` 依赖);边用边补 full deps | 861MB 可接受;先跑通再优化;避免 dev 起步就把镜像做大 |
|
||||
| **SSWFLOW 中心 NaxComputeEngine** | 标 `@Profile("dev")`:**prod 环境不注册**,仅 dev fallback 用 | 生产路径走 TDC Nax sidecar,本地路径仅供单机调试 |
|
||||
|
||||
### 11.4 V1.5 已落地的最小可用骨架
|
||||
|
||||
| 子任务 | 状态 | 文件 |
|
||||
|---|---|---|
|
||||
| **V1.5.1** Nax 镜像 Dockerfile | ✅ 已构建 `ssw-nax-runtime:0.1.0-dev`(861MB,1m51s),`import nax` 通过,stdin/stdout 协议烟测通过 | `boot/docker/ssw-nax-runtime/Dockerfile` |
|
||||
| **V1.5.2** K8sSandboxClient.runNaxJob | ✅ 占位骨架:image 切 naxImage + runtime 切默认 + 不走 KBS;跨方协议留 V1.5.6 | `boot/ssw-tdc/.../client/K8sSandboxClient.java:runNaxJob()` |
|
||||
| **V1.5.5** NaxComputeEngine dev-only | ✅ `@Profile("dev")` 限流,prod 不注册 | `boot/ssw-sswflow/.../engine/NaxComputeEngine.java` |
|
||||
|
||||
### 11.5 待办(dev 起步后不断完善)
|
||||
|
||||
| 子任务 | 工作量 | 内容 | 阻塞点 |
|
||||
|---|---|---|---|
|
||||
| **V1.5.3** connector.f_type 业务校验 | 0.5 天 | dacli 加 `TEE / NAX / BOTH` 枚举值;后端白名单;现有 102 条 `BOTH` 视同 `NAX` 不需迁移 | V1.5.2 跑通后再做 |
|
||||
| **V1.5.4** dataset.f_location 强制本地化 | 0.5 天 | 加 `tds-connector://<connectorId>/path` 前缀规则;写库前校验,拒绝 `oss://`/`file://` 等中央路径 | 待与 V1.5.3 同步发布 |
|
||||
| **V1.5.6** 跨方 Nax SPDZ 协议 | 2 天 | 镜像内 Nax 注册 endpoint;SSWFLOW 下发时附 peerEndpoints;nax_adapter.py 切到跨方模式;TDC K8sSandboxClient 增加 stdin 喂数据路径 | 需要真 k8s 集群跑一次 |
|
||||
| **V1.5.7** TEE + KBS 链路端到端验证 | 1 天 | 真 SEV-SNP 节点跑:合约→DAG→TDC Nax sidecar→密态结果→SSWFLOW 聚合 | 需要 AMD EPYC 7003 真机 |
|
||||
| **V1.5.8** connector 全量回填 | 0.5 天 | 把现有命名约定 `TEE 连接器_xxx` → `f_type='TEE'` 自动识别脚本 | V1.5.3 上线后 |
|
||||
|
||||
### 11.6 关键风险与对策
|
||||
|
||||
| 风险 | 影响 | 对策 |
|
||||
|---|---|---|
|
||||
| Nax 镜像版本与 sswflow resources 里的 `nax_adapter.py` 不一致 | 算子协议版本漂移 | Dockerfile 引用 `boot/ssw-sswflow/.../resources/nax/nax_adapter.py` 单一真源;版本标签与 jar 同步 |
|
||||
| `runNaxJob` 当前是占位实现(pod 立即退出) | 不能真跑算法 | V1.5.6 用 stdin 喂算子 JSON + kubectl exec 等长连接;当前仅作镜像切换骨架验证 |
|
||||
| 跨方 SPDZ 协议部署复杂(Ray cluster 跨域通信) | V1.5.6 落地风险高 | dev 起步只做"单方 Nax 跑通",跨方协议第二阶段;分两步走降低风险 |
|
||||
| dataset.f_location 强制本地化可能误伤中央 fixture | dev 环境数据找不到 | 加 `ssw.sswflow.allow-central-location: true` 开关(仅 dev profile 启用) |
|
||||
|
||||
---
|
||||
|
||||
_本文档与 `docs/tds/DOMAIN_MODEL.md`、`docs/arch/ARCHITECTURE.md` 互为补充;任何超出本文范围的设计变更须先在此升版。_
|
||||
Binary file not shown.
@@ -34,10 +34,10 @@ spec:
|
||||
resources:
|
||||
requests:
|
||||
cpu: 200m
|
||||
memory: 384Mi
|
||||
limits:
|
||||
cpu: 1
|
||||
memory: 1Gi
|
||||
limits:
|
||||
cpu: 2
|
||||
memory: 3Gi
|
||||
readinessProbe:
|
||||
exec:
|
||||
command: ["pg_isready", "-U", "dacli", "-d", "j7_node1"]
|
||||
|
||||
@@ -24,7 +24,8 @@ spec:
|
||||
command: ["java"]
|
||||
args:
|
||||
- "-Xmx1500m"
|
||||
- "-Dspring.profiles.active=j7node"
|
||||
- "-Dspring.profiles.active=dev,j7node"
|
||||
- "-Dspring.config.additional-location=/config/"
|
||||
- "-DDB_HOST=j7-postgres.j7.svc.cluster.local"
|
||||
- "-DDB_PORT=5432"
|
||||
- "-DREDIS_HOST=j7-redis.j7.svc.cluster.local"
|
||||
|
||||
Reference in new issue
Block a user