fengling-platform/.planning/phases/03-/03-gateway-cluster-entities-PLAN.md

207 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
phase: 03-
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
- Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwCluster.cs
- Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwDestination.cs
- Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwHealthCheckConfig.cs
- Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwSessionAffinityConfig.cs
autonomous: true
requirements:
- GATEWAY-RESTRUCTURE-01
- GATEWAY-RESTRUCTURE-02
must_haves:
truths:
- "GwCluster 使用 string Id (GUID)"
- "GwDestination 作为 Owned Entity 内嵌"
- "值对象使用 Owned Entity 配置"
artifacts:
- path: "Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwCluster.cs"
provides: "集群聚合根"
min_lines: 50
- path: "Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwDestination.cs"
provides: "目标端点值对象"
min_lines: 30
- path: "Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwHealthCheckConfig.cs"
provides: "健康检查配置值对象"
min_lines: 20
- path: "Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwSessionAffinityConfig.cs"
provides: "会话亲和配置值对象"
min_lines: 20
---
# 计划 01: 创建 GwCluster 聚合根和值对象
## 目标
创建新的 GwCluster 聚合根及相关值对象,替代原有的 GwServiceInstance 实体设计。
**目的:** 将服务实例管理改为集群聚合根模式,内嵌 Destinations 列表,符合 YARP ClusterConfig 结构。
**输出:** GwCluster 聚合根、GwDestination 值对象、GwHealthCheckConfig 值对象、GwSessionAffinityConfig 值对象。
## 上下文
@.planning/phases/03-/03-CONTEXT.md
@.planning/phases/03-/03-RESEARCH.md
@Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwTenantRoute.cs (现有实体参考)
@Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GatewayEnums.cs (枚举)
## 任务
<task type="auto">
<name>任务 1: 创建 GwHealthCheckConfig 值对象</name>
<files>Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwHealthCheckConfig.cs</files>
<action>
创建健康检查配置值对象:
```csharp
namespace Fengling.Platform.Domain.AggregatesModel.GatewayAggregate;
/// <summary>
/// 健康检查配置(值对象)
/// </summary>
public class GwHealthCheckConfig
{
/// <summary>
/// 是否启用健康检查
/// </summary>
public bool Enabled { get; set; }
/// <summary>
/// 健康检查路径
/// </summary>
public string? Path { get; set; }
/// <summary>
/// 检查间隔(秒)
/// </summary>
public int IntervalSeconds { get; set; } = 30;
/// <summary>
/// 超时时间(秒)
/// </summary>
public int TimeoutSeconds { get; set; } = 10;
}
```
</action>
<verify>文件可编译</verify>
<done>GwHealthCheckConfig 值对象已创建</done>
</task>
<task type="auto">
<name>任务 2: 创建 GwSessionAffinityConfig 值对象</name>
<files>Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwSessionAffinityConfig.cs</files>
<action>
创建会话亲和配置值对象:
```csharp
namespace Fengling.Platform.Domain.AggregatesModel.GatewayAggregate;
/// <summary>
/// 会话亲和配置(值对象)
/// </summary>
public class GwSessionAffinityConfig
{
/// <summary>
/// 是否启用会话亲和
/// </summary>
public bool Enabled { get; set; }
/// <summary>
/// 策略Header, Cookie
/// </summary>
public string Policy { get; set; } = "Header";
/// <summary>
/// 亲和键名称
/// </summary>
public string AffinityKeyName { get; set; } = "X-Session-Key";
}
```
</action>
<verify>文件可编译</verify>
<done>GwSessionAffinityConfig 值对象已创建</done>
</task>
<task type="auto">
<name>任务 3: 创建 GwDestination 值对象</name>
<files>Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwDestination.cs</files>
<action>
创建目标端点值对象:
```csharp
namespace Fengling.Platform.Domain.AggregatesModel.GatewayAggregate;
/// <summary>
/// 目标端点(值对象,内嵌于 GwCluster
/// </summary>
public class GwDestination
{
/// <summary>
/// 目标标识
/// </summary>
public string DestinationId { get; set; } = string.Empty;
/// <summary>
/// 后端地址
/// </summary>
public string Address { get; set; } = string.Empty;
/// <summary>
/// 健康检查端点
/// </summary>
public string? Health { get; set; }
/// <summary>
/// 权重(用于加权负载均衡)
/// </summary>
public int Weight { get; set; } = 1;
/// <summary>
/// 健康状态
/// </summary>
public int HealthStatus { get; set; } = 1;
/// <summary>
/// 状态
/// </summary>
public int Status { get; set; } = 1;
}
```
</action>
<verify>文件可编译</verify>
<done>GwDestination 值对象已创建</done>
</task>
<task type="auto">
<name>任务 4: 创建 GwCluster 聚合根</name>
<files>Fengling.Platform.Domain/AggregatesModel/GatewayAggregate/GwCluster.cs</files>
<action>
创建 GwCluster 聚合根:
- Id: string (GUID)
- ClusterId: string (业务标识)
- Name: string
- Description: string?
- Destinations: List&lt;GwDestination&gt; (内嵌)
- LoadBalancingPolicy: string
- HealthCheck: GwHealthCheckConfig?
- SessionAffinity: GwSessionAffinityConfig?
- Status: int
- 审计字段
参考现有 GwTenantRoute 的结构风格。
</action>
<verify>dotnet build Fengling.Platform.Domain 通过</verify>
<done>GwCluster 聚合根已创建,包含所有字段</done>
</task>
## 验证
- [ ] 所有 4 个文件已创建
- [ ] Build 无错误通过
- [ ] 值对象结构符合 YARP 配置模型
## 成功标准
Domain 实体准备好进行 Infrastructure 层更新。