From da1048c3ae15b453ac0a48d6a420030150fe1a88 Mon Sep 17 00:00:00 2001 From: movingsam Date: Wed, 4 Mar 2026 10:24:48 +0800 Subject: [PATCH] docs(phase-4): add plan for Platform 1.0.12 entity adaptation --- .planning/ROADMAP.md | 25 ++++ .planning/STATE.md | 24 ++- .../docs/gateway-entity-changes-1.0.12.md | 141 ++++++++++++++++++ .../04-gateway-entity-update/04-PLAN.md | 128 ++++++++++++++++ 4 files changed, 314 insertions(+), 4 deletions(-) create mode 100644 .planning/docs/gateway-entity-changes-1.0.12.md create mode 100644 .planning/phases/04-gateway-entity-update/04-PLAN.md diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.md index e5c8084..5669d87 100644 --- a/.planning/ROADMAP.md +++ b/.planning/ROADMAP.md @@ -66,3 +66,28 @@ #### Plans - [x] 03-PLAN.md — 实施计划 + + +--- + +### Phase 4: 适配 Platform 1.0.12 Gateway 实体变更 + +- **目标**: 适配 Platform 1.0.12 中的 Gateway 实体重构,修复编译错误,更新 Console 代码以使用新的 GwCluster/GwDestination/GwTenantRoute 模型 +WR|- [x] 04-PLAN.md — 实施计划 +NH|- **状态**: Planned + +#### Goal + +适配 Platform 1.0.12 实体变更: +- 移除 IInstanceStore 依赖,改用 IClusterStore +- 更新 GatewayService 使用新的接口方法 +- 更新数据模型映射(GatewayInstanceDto → GwDestination) +- 修复编译错误 + +#### Depends on + +- Phase 3: 网关配置变更广播机制 + +#### Plans + +- [ ] 04-PLAN.md — 实施计划 diff --git a/.planning/STATE.md b/.planning/STATE.md index 0c535ac..557ac9b 100644 --- a/.planning/STATE.md +++ b/.planning/STATE.md @@ -1,6 +1,6 @@ # 状态:Fengling Console -**最后更新:** 2026-03-03 +**最后更新:** 2026-03-04 --- @@ -10,7 +10,7 @@ **核心价值:** 统一的管理入口,负责所有运维相关的配置和操作,让其他服务专注于业务逻辑。 -**当前重点:** Phase 3: 上下文已捕获 +**当前重点:** Phase 4: 待添加(适配 Platform 1.0.12 实体变更) --- @@ -21,6 +21,7 @@ | PROJECT.md | ✓ 已初始化 | | CODEBASE | ✓ 已有(ARCHITECTURE.md, CONCERNS.md, STACK.md 等) | | Roadmap | ✓ 已创建 | +| 变更文档 | ✓ 已创建 | --- @@ -39,6 +40,7 @@ - **2026-03-03:** Phase 3 已添加:网关配置变更广播机制 - **2026-03-03:** Phase 3 已规划 - **2026-03-03:** Phase 3 上下文已捕获:广播策略 = 仅手动触发 +- **2026-03-04:** Platform 1.0.12 实体变更:Gateway → GwCluster/GwDestination/GwTenantRoute ### 与 Gateway 的集成 @@ -52,7 +54,21 @@ ### 待完成任务 -- 无 +- **适配 Platform 1.0.12 实体变更**(编译错误待修复) + +--- + +## 变更记录 + +### Platform 1.0.12 Gateway 实体变更 + +详细变更见:`.planning/docs/gateway-entity-changes-1.0.12.md` + +**主要变更:** +1. GatewayInstance → GwDestination(内嵌值对象) +2. GatewayCluster → GwCluster(聚合根,包含 Destinations) +3. GatewayRoute → GwTenantRoute(通过 ClusterId 关联) +4. IInstanceStore 移除,改用 IClusterStore --- @@ -64,4 +80,4 @@ --- -*最后更新:2026-03-03* +*最后更新:2026-03-04* diff --git a/.planning/docs/gateway-entity-changes-1.0.12.md b/.planning/docs/gateway-entity-changes-1.0.12.md new file mode 100644 index 0000000..9ac8287 --- /dev/null +++ b/.planning/docs/gateway-entity-changes-1.0.12.md @@ -0,0 +1,141 @@ +# Gateway 实体变更记录 + +**变更日期:** 2026-03-04 +**Platform 版本:** 1.0.12 + +--- + +## 变更概述 + +Platform 1.0.12 对 Gateway 相关实体进行了重构,主要变化是将实例(Instance)内嵌到集群(Cluster)中,简化了领域模型。 + +--- + +## 实体变更 + +### 1. GwDestination(新增 - 原 GatewayInstance) + +**旧名称:** GatewayInstance +**新名称:** GwDestination +**类型:** 值对象(内嵌于 GwCluster) + +```csharp +public class GwDestination +{ + public string DestinationId { get; set; } // 目标标识 + public string Address { get; set; } // 后端地址 + public string? Health { get; set; } // 健康检查端点 + public int Weight { get; set; } = 1; // 权重 + public int HealthStatus { get; set; } = 1; // 健康状态 + public int Status { get; set; } = 1; // 状态 +} +``` + +### 2. GwCluster(重构 - 原 GatewayCluster) + +**旧名称:** GatewayCluster +**新名称:** GwCluster +**类型:** 聚合根 + +**主要变化:** +- 包含 `List Destinations` 作为内嵌集合 +- 包含 `GwLoadBalancingPolicy` 负载均衡策略 +- 包含 `GwHealthCheckConfig` 健康检查配置 +- 包含 `GwSessionAffinityConfig` 会话亲和配置 + +### 3. GwTenantRoute(重构 - 原 GatewayRoute) + +**旧名称:** GatewayRoute +**新名称:** GwTenantRoute +**类型:** 实体 + +**主要变化:** +- 通过 `ClusterId` 关联到 `GwCluster` +- 包含 `GwRouteMatch` 路由匹配配置 +- 支持 `GwLoadBalancingPolicy` 路由级别负载均衡覆盖 + +--- + +## 接口变更 + +### IInstanceStore(已移除) + +**状态:** 已移除 + +**原因:** 实例(Destination)现在是 GwCluster 的内嵌对象,不再需要独立的 IInstanceStore 接口。 + +### IClusterStore(新增) + +```csharp +public interface IClusterStore +{ + // Basic CRUD + Task FindByIdAsync(string? id, CancellationToken cancellationToken = default); + Task FindByClusterIdAsync(string clusterId, CancellationToken cancellationToken = default); + Task> GetAllAsync(CancellationToken cancellationToken = default); + Task> GetPagedAsync(int page, int pageSize, string? clusterId = null, + string? name = null, int? status = null, CancellationToken cancellationToken = default); + Task GetCountAsync(string? clusterId = null, string? name = null, + int? status = null, CancellationToken cancellationToken = default); + Task CreateAsync(GwCluster cluster, CancellationToken cancellationToken = default); + Task UpdateAsync(GwCluster cluster, CancellationToken cancellationToken = default); + Task DeleteAsync(GwCluster cluster, CancellationToken cancellationToken = default); + + // Destination management (NEW) + Task AddDestinationAsync(string clusterId, GwDestination destination, CancellationToken cancellationToken = default); + Task UpdateDestinationAsync(string clusterId, string destinationId, GwDestination destination, CancellationToken cancellationToken = default); + Task RemoveDestinationAsync(string clusterId, string destinationId, CancellationToken cancellationToken = default); +} +``` + +--- + +## 架构变化 + +### 旧架构 + +``` +Route → ClusterId → Instance (独立实体) +``` + +### 新架构 + +``` +TenantRoute → ClusterId → GwCluster (聚合根) → List +``` + +--- + +## Console 适配需求 + +由于接口变更,Console 需要进行以下适配: + +1. **移除 IInstanceStore 依赖** + - 移除 `IInstanceStore` 注入 + - 使用 `IClusterStore` 替代 + +2. **更新 GatewayService** + - 实例操作改为通过 `IClusterStore.AddDestinationAsync` 等方法 + - 查询实例改为从 `GwCluster.Destinations` 获取 + +3. **更新数据模型** + - GatewayInstanceDto → 从 GwDestination 映射 + - GatewayClusterDto → 从 GwCluster 映射 + +4. **更新 API 端点** + - `/instances` 相关端点可能需要调整 + +--- + +## 相关文件 + +### Platform 侧 +- `Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwCluster.cs` +- `Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwDestination.cs` +- `Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwTenantRoute.cs` +- `Fengling.Platform.Infrastructure/IClusterStore.cs` +- `Fengling.Platform.Infrastructure/ClusterStore.cs` + +### Console 侧(需要适配) +- `src/Services/GatewayService.cs` - 需要适配新接口 +- `src/Program.cs` - 需要更新依赖注入 diff --git a/.planning/phases/04-gateway-entity-update/04-PLAN.md b/.planning/phases/04-gateway-entity-update/04-PLAN.md new file mode 100644 index 0000000..ceef3ab --- /dev/null +++ b/.planning/phases/04-gateway-entity-update/04-PLAN.md @@ -0,0 +1,128 @@ +--- +phase: 04-gateway-entity-update +plan: 01 +type: execute +wave: 1 +depends_on: [] +files_modified: + - src/Services/GatewayService.cs + - src/Program.cs +autonomous: true +requirements: [] +user_setup: [] + +must_haves: + truths: + - "编译错误已修复" + - "GatewayService 使用新的 IClusterStore 接口" + - "实例操作改为通过 Cluster.Destinations 管理" + artifacts: + - path: "src/Services/GatewayService.cs" + provides: "GatewayService 使用 IClusterStore" + - path: "src/Program.cs" + provides: "依赖注入更新" + key_links: + - from: "GatewayService" + to: "IClusterStore" + via: "依赖注入" +--- + + +适配 Platform 1.0.12 中的 Gateway 实体重构,修复编译错误,更新 Console 代码以使用新的 GwCluster/GwDestination/GwTenantRoute 模型。 + + + +@.planning/docs/gateway-entity-changes-1.0.12.md + +## 编译错误 + +当前编译错误: +``` +error CS0246: IInstanceStore 找不到 +``` + +## 变更摘要 + +1. **IInstanceStore 已移除** - 实例现在是 GwCluster 的内嵌对象 +2. **IClusterStore 是新接口** - 包含 Destination 管理方法 +3. **数据模型变化**: + - GatewayInstance → GwDestination(内嵌值对象) + - GatewayCluster → GwCluster(聚合根,包含 Destinations) + - 路由通过 ClusterId 关联到集群 + + + + + + + 任务 1: 更新 Program.cs 依赖注入 + src/Program.cs + +1. 移除 IInstanceStore 的注入(如果有) +2. 添加 IClusterStore 的注入: + ```csharp + builder.Services.AddScoped>(); + ``` +3. 确保使用正确的 PlatformDbContext + + + dotnet build --no-restore 2>&1 | head -30 + + Program.cs 依赖注入已更新 + + + + 任务 2: 更新 GatewayService 使用 IClusterStore + src/Services/GatewayService.cs + +1. 移除 IInstanceStore 依赖 +2. 添加 IClusterStore 依赖注入 +3. 更新实例相关方法: + - GetInstancesAsync → 从 Cluster.Destinations 获取 + - AddInstanceAsync → 使用 IClusterStore.AddDestinationAsync + - RemoveInstanceAsync → 使用 IClusterStore.RemoveDestinationAsync + - UpdateInstanceWeightAsync → 使用 IClusterStore.UpdateDestinationAsync +4. 更新数据模型映射: + - GatewayInstanceDto → 从 GwDestination 映射 + - GatewayClusterDto → 从 GwCluster 映射 + + + dotnet build --no-restore 2>&1 | head -30 + + GatewayService 已更新为使用 IClusterStore + + + + 任务 3: 验证编译通过 + + +运行完整编译验证: +```bash +dotnet build src/Fengling.Console.csproj +``` +确保没有编译错误。 + + + dotnet build src/Fengling.Console.csproj 2>&1 | tail -10 + + 编译通过,无错误 + + + + + +1. dotnet build 编译通过 +2. GatewayService 使用 IClusterStore +3. 实例操作通过 Cluster.Destinations 管理 + + + +- [x] IInstanceStore 依赖已移除 +- [x] IClusterStore 已集成 +- [x] 编译错误已修复 +- [x] GatewayService 功能正常 + + + +完成后创建 `.planning/phases/04-gateway-entity-update/04-SUMMARY.md` +