using Microsoft.AspNetCore.Routing; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using ZB.MOM.WW.Health; using ZB.MOM.WW.Health.Akka; using ZB.MOM.WW.Health.EntityFrameworkCore; using ZB.MOM.WW.OtOpcUa.Configuration; namespace ZB.MOM.WW.OtOpcUa.Host.Health; public static class HealthEndpoints { /// /// Registers the shared ZB.MOM.WW health probes. Tier semantics preserved: configdb + akka on /// ready+active; admin-leader on active only. /// public static IServiceCollection AddOtOpcUaHealth(this IServiceCollection services) { services.AddHealthChecks() .AddTypeActivatedCheck>( "configdb", failureStatus: null, tags: new[] { ZbHealthTags.Ready, ZbHealthTags.Active }, args: new DatabaseHealthCheckOptions { ProbeQuery = static (db, ct) => db.Deployments.AsNoTracking().Take(1).ToListAsync(ct), }) .AddTypeActivatedCheck( "akka", failureStatus: null, tags: new[] { ZbHealthTags.Ready, ZbHealthTags.Active }, args: AkkaClusterStatusPolicy.OtOpcUaCompat) .AddTypeActivatedCheck( "admin-leader", failureStatus: null, tags: new[] { ZbHealthTags.Active }, args: "admin"); return services; } /// Maps the OtOpcUa health check endpoints to the route builder. /// The endpoint route builder. public static IEndpointRouteBuilder MapOtOpcUaHealth(this IEndpointRouteBuilder app) { app.MapZbHealth(); return app; } }