PR 4.0 — Driver.Galaxy project skeleton + factory
New in-process .NET 10 driver project at src/ZB.MOM.WW.OtOpcUa.Driver.Galaxy/. The Tier-A replacement for Driver.Galaxy.Host + Driver.Galaxy.Proxy. PR 4.0 ships only the IDriver shape + factory + options; capability bodies (browse, read, write, subscribe, deploy-watch, host probes) land in PRs 4.1–4.7. Files: - Driver.Galaxy.csproj — net10 x64, AnyCPU+x64 platforms, references Core.Abstractions + Core. No MxGatewayClient ProjectReference yet — that comes in PR 4.2 once the gw NuGet package is wired (the user is shipping mxaccessgw on a parallel track). - Config/GalaxyDriverOptions.cs — nested record hierarchy (Gateway/MxAccess/Repository/Reconnect) mirroring the JSON shape spelled out in lmx_mxgw_impl.md PR 4.0 acceptance section. - GalaxyDriver.cs — minimal IDriver impl. Initialize/Shutdown toggle DriverHealth between Healthy/Unknown; Reinitialize bumps the timestamp; GetMemoryFootprint=0 (PR 4.4 wires SubscriptionRegistry size); FlushOptionalCachesAsync no-op. Logs intent on lifecycle calls so partial deployments are diagnosable. - GalaxyDriverFactoryExtensions.cs — JSON parser, default fill-ins, validation throw on missing required fields. Driver type name "GalaxyMxGateway" intentionally distinct from legacy "Galaxy" so both factories coexist during parity testing (Phase 5). PR 4.W's Galaxy:Backend switch picks one or the other. Tests: - 10 tests in Driver.Galaxy.Tests covering minimal-config defaults, full override path, three required-field error cases, factory registration via DriverFactoryRegistry.TryGet, lifecycle health transitions (Init → Shutdown → Reinit), Dispose idempotency, and post-disposal ObjectDisposedException. slnx: registers the new Driver.Galaxy + Driver.Galaxy.Tests projects. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Config;
|
||||
|
||||
/// <summary>
|
||||
/// Driver-instance options for the in-process .NET 10 Galaxy driver. Maps to the
|
||||
/// <c>DriverConfig</c> JSON column on the central config DB. Decomposed into nested
|
||||
/// records so the JSON structure mirrors the runtime shape and operators can target
|
||||
/// individual sections (gateway endpoint, mxaccess client identity, reconnect policy)
|
||||
/// without touching the rest.
|
||||
/// </summary>
|
||||
/// <param name="Gateway">Connection details for the MxAccess gateway (mxaccessgw repo).</param>
|
||||
/// <param name="MxAccess">MXAccess-specific knobs surfaced through gw — client name, publishing interval, write-user.</param>
|
||||
/// <param name="Repository">Galaxy Repository browse options consumed by the discoverer.</param>
|
||||
/// <param name="Reconnect">Backoff knobs for the in-driver reconnect supervisor (PR 4.5).</param>
|
||||
public sealed record GalaxyDriverOptions(
|
||||
GalaxyGatewayOptions Gateway,
|
||||
GalaxyMxAccessOptions MxAccess,
|
||||
GalaxyRepositoryOptions Repository,
|
||||
GalaxyReconnectOptions Reconnect);
|
||||
|
||||
/// <summary>
|
||||
/// Connection details for the MxAccess gateway. <see cref="ApiKeySecretRef"/> resolves
|
||||
/// through the server-side secret store (DPAPI for production, environment override for
|
||||
/// dev) — the API key never appears in cleartext config.
|
||||
/// </summary>
|
||||
public sealed record GalaxyGatewayOptions(
|
||||
string Endpoint,
|
||||
string ApiKeySecretRef,
|
||||
bool UseTls = true,
|
||||
string? CaCertificatePath = null,
|
||||
int ConnectTimeoutSeconds = 10,
|
||||
int DefaultCallTimeoutSeconds = 5,
|
||||
int StreamTimeoutSeconds = 0);
|
||||
|
||||
/// <summary>
|
||||
/// MXAccess-specific knobs the gateway forwards to the worker process.
|
||||
/// </summary>
|
||||
/// <param name="ClientName">
|
||||
/// Wonderware client identity. MUST be unique per OtOpcUa instance — when two instances
|
||||
/// share a name, the older session loses subscription state. Redundancy pairs (decision
|
||||
/// #149) enforce uniqueness via install scripts.
|
||||
/// </param>
|
||||
/// <param name="PublishingIntervalMs">
|
||||
/// Hint forwarded as <c>buffered_update_interval_ms</c> on subscribe; lets the worker
|
||||
/// coalesce updates at the OPC UA publishing cadence rather than every COM tick.
|
||||
/// </param>
|
||||
/// <param name="WriteUserId">
|
||||
/// Reserved for ArchestrA secured-write user mapping; PR 4.3 wires <c>WriteSecured</c>
|
||||
/// routing against this id. 0 = anonymous.
|
||||
/// </param>
|
||||
public sealed record GalaxyMxAccessOptions(
|
||||
string ClientName,
|
||||
int PublishingIntervalMs = 1000,
|
||||
int WriteUserId = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Galaxy Repository browse-side knobs consumed by PR 4.1's <c>GalaxyDiscoverer</c>.
|
||||
/// </summary>
|
||||
public sealed record GalaxyRepositoryOptions(
|
||||
int DiscoverPageSize = 5000,
|
||||
bool WatchDeployEvents = true);
|
||||
|
||||
/// <summary>
|
||||
/// Backoff knobs for the in-driver reconnect supervisor (PR 4.5). Replay-on-session-lost
|
||||
/// calls the gw's <c>ReplaySubscriptions</c> RPC after reconnect rather than re-issuing
|
||||
/// subscribe-bulk for every tag.
|
||||
/// </summary>
|
||||
public sealed record GalaxyReconnectOptions(
|
||||
int InitialBackoffMs = 500,
|
||||
int MaxBackoffMs = 30_000,
|
||||
bool ReplayOnSessionLost = true);
|
||||
102
src/ZB.MOM.WW.OtOpcUa.Driver.Galaxy/GalaxyDriver.cs
Normal file
102
src/ZB.MOM.WW.OtOpcUa.Driver.Galaxy/GalaxyDriver.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Config;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy;
|
||||
|
||||
/// <summary>
|
||||
/// In-process .NET 10 Galaxy driver — the v2 replacement for the Galaxy.Host /
|
||||
/// Galaxy.Proxy pair. PR 4.0 ships the project skeleton with <see cref="IDriver"/>
|
||||
/// bodies that wire to a future <c>IGalaxyGatewayClient</c> abstraction. Capability
|
||||
/// interfaces (browse, read, write, subscribe, history routing, host probes) land in
|
||||
/// PRs 4.1–4.7; the wiring sequence keeps every intermediate state buildable so the
|
||||
/// <c>Galaxy:Backend</c> flag (PR 4.W) can flip between legacy-host and mxgateway
|
||||
/// for parity testing.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This driver is registered as a Tier A in-process driver alongside Modbus / S7 / etc.
|
||||
/// The legacy <c>GalaxyProxyDriver</c> (Driver.Galaxy.Proxy) coexists until PR 7.2;
|
||||
/// <see cref="GalaxyDriverFactoryExtensions"/> registers under driver-type name
|
||||
/// "GalaxyMxGateway" so both paths can be live simultaneously during parity testing.
|
||||
/// </remarks>
|
||||
public sealed class GalaxyDriver : IDriver, IDisposable
|
||||
{
|
||||
private readonly string _driverInstanceId;
|
||||
private readonly GalaxyDriverOptions _options;
|
||||
private readonly ILogger<GalaxyDriver> _logger;
|
||||
|
||||
private DriverHealth _health = new(DriverState.Unknown, null, null);
|
||||
private bool _disposed;
|
||||
|
||||
public GalaxyDriver(
|
||||
string driverInstanceId,
|
||||
GalaxyDriverOptions options,
|
||||
ILogger<GalaxyDriver>? logger = null)
|
||||
{
|
||||
_driverInstanceId = !string.IsNullOrWhiteSpace(driverInstanceId)
|
||||
? driverInstanceId
|
||||
: throw new ArgumentException("Driver instance id required.", nameof(driverInstanceId));
|
||||
_options = options ?? throw new ArgumentNullException(nameof(options));
|
||||
_logger = logger ?? NullLogger<GalaxyDriver>.Instance;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DriverInstanceId => _driverInstanceId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DriverType => GalaxyDriverFactoryExtensions.DriverTypeName;
|
||||
|
||||
/// <summary>Test-visible options snapshot.</summary>
|
||||
internal GalaxyDriverOptions Options => _options;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task InitializeAsync(string driverConfigJson, CancellationToken cancellationToken)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
// PR 4.0 skeleton — capability bodies (PRs 4.1-4.7) replace this stub with real
|
||||
// MxGatewayClient session opening. The skeleton keeps the IDriver shape buildable
|
||||
// so the Galaxy:Backend flag (PR 4.W) can register the driver factory now.
|
||||
_logger.LogInformation(
|
||||
"GalaxyDriver {InstanceId} initializing — endpoint={Endpoint} clientName={ClientName} (skeleton; real gateway connect in PR 4.1+)",
|
||||
_driverInstanceId, _options.Gateway.Endpoint, _options.MxAccess.ClientName);
|
||||
_health = new DriverHealth(DriverState.Healthy, DateTime.UtcNow, null);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task ReinitializeAsync(string driverConfigJson, CancellationToken cancellationToken)
|
||||
{
|
||||
// In-place config reapply. PR 4.5's reconnect supervisor will swap the
|
||||
// gateway-client options under the lock; for the skeleton we just refresh health.
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
_health = new DriverHealth(DriverState.Healthy, DateTime.UtcNow, null);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task ShutdownAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_disposed) return Task.CompletedTask;
|
||||
_logger.LogInformation("GalaxyDriver {InstanceId} shutting down", _driverInstanceId);
|
||||
_health = new DriverHealth(DriverState.Unknown, _health.LastSuccessfulRead, null);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public DriverHealth GetHealth() => _health;
|
||||
|
||||
/// <inheritdoc />
|
||||
public long GetMemoryFootprint() => 0; // PR 4.4 sets this from SubscriptionRegistry size.
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task FlushOptionalCachesAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
// No owned IDisposables until PR 4.2's GalaxyMxSession lands.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Hosting;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Config;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy;
|
||||
|
||||
/// <summary>
|
||||
/// Static factory registration helper for <see cref="GalaxyDriver"/>. Mirrors
|
||||
/// <c>GalaxyProxyDriverFactoryExtensions</c> / <c>ModbusDriverFactoryExtensions</c>.
|
||||
/// Server's <c>Program.cs</c> calls <see cref="Register"/> once at startup; the driver
|
||||
/// bootstrap pipeline materialises DriverInstance rows whose <c>DriverType</c> matches
|
||||
/// <see cref="DriverTypeName"/> into live <see cref="GalaxyDriver"/> instances.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The driver-type name <c>"GalaxyMxGateway"</c> is intentionally distinct from the
|
||||
/// legacy proxy's <c>"Galaxy"</c> so both factories can be registered simultaneously
|
||||
/// during parity testing (Phase 5). PR 4.W will add a server-side <c>Galaxy:Backend</c>
|
||||
/// switch that materialises a Galaxy DriverInstance under one or the other type name.
|
||||
/// </remarks>
|
||||
public static class GalaxyDriverFactoryExtensions
|
||||
{
|
||||
public const string DriverTypeName = "GalaxyMxGateway";
|
||||
|
||||
public static void Register(DriverFactoryRegistry registry, ILoggerFactory? loggerFactory = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(registry);
|
||||
registry.Register(DriverTypeName, (id, json) => CreateInstance(id, json, loggerFactory));
|
||||
}
|
||||
|
||||
/// <summary>Convenience for tests + standalone callers.</summary>
|
||||
public static GalaxyDriver CreateInstance(string driverInstanceId, string driverConfigJson)
|
||||
=> CreateInstance(driverInstanceId, driverConfigJson, loggerFactory: null);
|
||||
|
||||
public static GalaxyDriver CreateInstance(
|
||||
string driverInstanceId, string driverConfigJson, ILoggerFactory? loggerFactory)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(driverInstanceId);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(driverConfigJson);
|
||||
|
||||
var dto = JsonSerializer.Deserialize<GalaxyDriverConfigDto>(driverConfigJson, JsonOptions)
|
||||
?? throw new InvalidOperationException(
|
||||
$"Galaxy driver config for '{driverInstanceId}' deserialised to null");
|
||||
|
||||
var options = new GalaxyDriverOptions(
|
||||
Gateway: new GalaxyGatewayOptions(
|
||||
Endpoint: dto.Gateway?.Endpoint
|
||||
?? throw new InvalidOperationException(
|
||||
$"Galaxy driver '{driverInstanceId}' missing required Gateway.Endpoint"),
|
||||
ApiKeySecretRef: dto.Gateway.ApiKeySecretRef
|
||||
?? throw new InvalidOperationException(
|
||||
$"Galaxy driver '{driverInstanceId}' missing required Gateway.ApiKeySecretRef"),
|
||||
UseTls: dto.Gateway.UseTls ?? true,
|
||||
CaCertificatePath: dto.Gateway.CaCertificatePath,
|
||||
ConnectTimeoutSeconds: dto.Gateway.ConnectTimeoutSeconds ?? 10,
|
||||
DefaultCallTimeoutSeconds: dto.Gateway.DefaultCallTimeoutSeconds ?? 5,
|
||||
StreamTimeoutSeconds: dto.Gateway.StreamTimeoutSeconds ?? 0),
|
||||
MxAccess: new GalaxyMxAccessOptions(
|
||||
ClientName: dto.MxAccess?.ClientName
|
||||
?? throw new InvalidOperationException(
|
||||
$"Galaxy driver '{driverInstanceId}' missing required MxAccess.ClientName"),
|
||||
PublishingIntervalMs: dto.MxAccess.PublishingIntervalMs ?? 1000,
|
||||
WriteUserId: dto.MxAccess.WriteUserId ?? 0),
|
||||
Repository: new GalaxyRepositoryOptions(
|
||||
DiscoverPageSize: dto.Repository?.DiscoverPageSize ?? 5000,
|
||||
WatchDeployEvents: dto.Repository?.WatchDeployEvents ?? true),
|
||||
Reconnect: new GalaxyReconnectOptions(
|
||||
InitialBackoffMs: dto.Reconnect?.InitialBackoffMs ?? 500,
|
||||
MaxBackoffMs: dto.Reconnect?.MaxBackoffMs ?? 30_000,
|
||||
ReplayOnSessionLost: dto.Reconnect?.ReplayOnSessionLost ?? true));
|
||||
|
||||
return new GalaxyDriver(driverInstanceId, options, loggerFactory?.CreateLogger<GalaxyDriver>());
|
||||
}
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
AllowTrailingCommas = true,
|
||||
};
|
||||
|
||||
internal sealed class GalaxyDriverConfigDto
|
||||
{
|
||||
public GatewayDto? Gateway { get; init; }
|
||||
public MxAccessDto? MxAccess { get; init; }
|
||||
public RepositoryDto? Repository { get; init; }
|
||||
public ReconnectDto? Reconnect { get; init; }
|
||||
}
|
||||
|
||||
internal sealed class GatewayDto
|
||||
{
|
||||
public string? Endpoint { get; init; }
|
||||
public string? ApiKeySecretRef { get; init; }
|
||||
public bool? UseTls { get; init; }
|
||||
public string? CaCertificatePath { get; init; }
|
||||
public int? ConnectTimeoutSeconds { get; init; }
|
||||
public int? DefaultCallTimeoutSeconds { get; init; }
|
||||
public int? StreamTimeoutSeconds { get; init; }
|
||||
}
|
||||
|
||||
internal sealed class MxAccessDto
|
||||
{
|
||||
public string? ClientName { get; init; }
|
||||
public int? PublishingIntervalMs { get; init; }
|
||||
public int? WriteUserId { get; init; }
|
||||
}
|
||||
|
||||
internal sealed class RepositoryDto
|
||||
{
|
||||
public int? DiscoverPageSize { get; init; }
|
||||
public bool? WatchDeployEvents { get; init; }
|
||||
}
|
||||
|
||||
internal sealed class ReconnectDto
|
||||
{
|
||||
public int? InitialBackoffMs { get; init; }
|
||||
public int? MaxBackoffMs { get; init; }
|
||||
public bool? ReplayOnSessionLost { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Driver.Galaxy</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ZB.MOM.WW.OtOpcUa.Core.Abstractions\ZB.MOM.WW.OtOpcUa.Core.Abstractions.csproj"/>
|
||||
<ProjectReference Include="..\ZB.MOM.WW.OtOpcUa.Core\ZB.MOM.WW.OtOpcUa.Core.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Tests"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-37gx-xxp4-5rgx"/>
|
||||
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-w3x6-4m5h-cxqf"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user