fengling-console/.planning/docs/gateway-entity-changes-1.0.12.md

4.4 KiB
Raw Blame History

Gateway 实体变更记录

变更日期: 2026-03-04 Platform 版本: 1.0.12


变更概述

Platform 1.0.12 对 Gateway 相关实体进行了重构,主要变化是将实例(Instance)内嵌到集群(Cluster)中,简化了领域模型。


实体变更

1. GwDestination新增 - 原 GatewayInstance

旧名称: GatewayInstance 新名称: GwDestination 类型: 值对象(内嵌于 GwCluster

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<GwDestination> Destinations 作为内嵌集合
  • 包含 GwLoadBalancingPolicy 负载均衡策略
  • 包含 GwHealthCheckConfig 健康检查配置
  • 包含 GwSessionAffinityConfig 会话亲和配置

3. GwTenantRoute重构 - 原 GatewayRoute

旧名称: GatewayRoute 新名称: GwTenantRoute 类型: 实体

主要变化:

  • 通过 ClusterId 关联到 GwCluster
  • 包含 GwRouteMatch 路由匹配配置
  • 支持 GwLoadBalancingPolicy 路由级别负载均衡覆盖

接口变更

IInstanceStore已移除

状态: 已移除

原因: 实例(Destination)现在是 GwCluster 的内嵌对象,不再需要独立的 IInstanceStore 接口。

IClusterStore新增

public interface IClusterStore
{
    // Basic CRUD
    Task<GwCluster?> FindByIdAsync(string? id, CancellationToken cancellationToken = default);
    Task<GwCluster?> FindByClusterIdAsync(string clusterId, CancellationToken cancellationToken = default);
    Task<IList<GwCluster>> GetAllAsync(CancellationToken cancellationToken = default);
    Task<IList<GwCluster>> GetPagedAsync(int page, int pageSize, string? clusterId = null, 
        string? name = null, int? status = null, CancellationToken cancellationToken = default);
    Task<int> GetCountAsync(string? clusterId = null, string? name = null, 
        int? status = null, CancellationToken cancellationToken = default);
    Task<IdentityResult> CreateAsync(GwCluster cluster, CancellationToken cancellationToken = default);
    Task<IdentityResult> UpdateAsync(GwCluster cluster, CancellationToken cancellationToken = default);
    Task<IdentityResult> DeleteAsync(GwCluster cluster, CancellationToken cancellationToken = default);

    // Destination management (NEW)
    Task<GwCluster?> AddDestinationAsync(string clusterId, GwDestination destination, CancellationToken cancellationToken = default);
    Task<GwCluster?> UpdateDestinationAsync(string clusterId, string destinationId, GwDestination destination, CancellationToken cancellationToken = default);
    Task<GwCluster?> RemoveDestinationAsync(string clusterId, string destinationId, CancellationToken cancellationToken = default);
}

架构变化

旧架构

Route → ClusterId → Instance (独立实体)

新架构

TenantRoute → ClusterId → GwCluster (聚合根) → List<GwDestination>

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 - 需要更新依赖注入