Refactored enterprise environments to use stable snapshots

This commit is contained in:
Thorsten Sommer 2026-03-23 13:33:34 +01:00
parent 1436ffd7e0
commit 5445c73b38
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 28 additions and 5 deletions

View File

@ -85,7 +85,7 @@
@T("AI Studio runs with an enterprise configuration and configuration servers. The configuration plugins are not yet available.") @T("AI Studio runs with an enterprise configuration and configuration servers. The configuration plugins are not yet available.")
</MudText> </MudText>
<MudCollapse Expanded="@this.showEnterpriseConfigDetails"> <MudCollapse Expanded="@this.showEnterpriseConfigDetails">
@foreach (var env in EnterpriseEnvironmentService.CURRENT_ENVIRONMENTS.Where(e => e.IsActive)) @foreach (var env in this.enterpriseEnvironments.Where(e => e.IsActive))
{ {
<ConfigPluginInfoCard HeaderIcon="@Icons.Material.Filled.HourglassBottom" <ConfigPluginInfoCard HeaderIcon="@Icons.Material.Filled.HourglassBottom"
HeaderText="@T("Waiting for the configuration plugin...")" HeaderText="@T("Waiting for the configuration plugin...")"
@ -123,7 +123,7 @@
</MudText> </MudText>
} }
<MudCollapse Expanded="@this.showEnterpriseConfigDetails"> <MudCollapse Expanded="@this.showEnterpriseConfigDetails">
@foreach (var env in EnterpriseEnvironmentService.CURRENT_ENVIRONMENTS.Where(e => e.IsActive)) @foreach (var env in this.enterpriseEnvironments.Where(e => e.IsActive))
{ {
var matchingPlugin = this.FindManagedConfigurationPlugin(env.ConfigurationId); var matchingPlugin = this.FindManagedConfigurationPlugin(env.ConfigurationId);
if (matchingPlugin is null) if (matchingPlugin is null)

View File

@ -75,14 +75,16 @@ public partial class Information : MSGComponentBase
.Where(x => x.Type is PluginType.CONFIGURATION) .Where(x => x.Type is PluginType.CONFIGURATION)
.OfType<IAvailablePlugin>() .OfType<IAvailablePlugin>()
.ToList(); .ToList();
private List<EnterpriseEnvironment> enterpriseEnvironments = EnterpriseEnvironmentService.CURRENT_ENVIRONMENTS.ToList();
private sealed record DatabaseDisplayInfo(string Label, string Value); private sealed record DatabaseDisplayInfo(string Label, string Value);
private readonly List<DatabaseDisplayInfo> databaseDisplayInfo = new(); private readonly List<DatabaseDisplayInfo> databaseDisplayInfo = new();
private static bool HasAnyActiveEnvironment => EnterpriseEnvironmentService.CURRENT_ENVIRONMENTS.Any(e => e.IsActive); private bool HasAnyActiveEnvironment => this.enterpriseEnvironments.Any(e => e.IsActive);
private bool HasAnyLoadedEnterpriseConfigurationPlugin => EnterpriseEnvironmentService.CURRENT_ENVIRONMENTS private bool HasAnyLoadedEnterpriseConfigurationPlugin => this.enterpriseEnvironments
.Where(e => e.IsActive) .Where(e => e.IsActive)
.Any(env => this.FindManagedConfigurationPlugin(env.ConfigurationId) is not null); .Any(env => this.FindManagedConfigurationPlugin(env.ConfigurationId) is not null);
@ -94,7 +96,7 @@ public partial class Information : MSGComponentBase
{ {
get get
{ {
return HasAnyActiveEnvironment switch return this.HasAnyActiveEnvironment switch
{ {
// Case 1: No enterprise config and no plugin - no details available // Case 1: No enterprise config and no plugin - no details available
false when this.configPlugins.Count == 0 => false, false when this.configPlugins.Count == 0 => false,

View File

@ -8,6 +8,8 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
public static bool HasValidEnterpriseSnapshot { get; private set; } public static bool HasValidEnterpriseSnapshot { get; private set; }
private readonly record struct EnterpriseEnvironmentSnapshot(Guid ConfigurationId, string ConfigurationServerUrl, string? ETag);
#if DEBUG #if DEBUG
private static readonly TimeSpan CHECK_INTERVAL = TimeSpan.FromMinutes(6); private static readonly TimeSpan CHECK_INTERVAL = TimeSpan.FromMinutes(6);
#else #else
@ -36,6 +38,7 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
{ {
logger.LogInformation("Start updating of the enterprise environment."); logger.LogInformation("Start updating of the enterprise environment.");
HasValidEnterpriseSnapshot = false; HasValidEnterpriseSnapshot = false;
var previousSnapshot = BuildNormalizedSnapshot(CURRENT_ENVIRONMENTS);
// //
// Step 1: Fetch all active configurations. // Step 1: Fetch all active configurations.
@ -165,6 +168,7 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
if (effectiveEnvironments.Count == 0) if (effectiveEnvironments.Count == 0)
logger.LogInformation("AI Studio runs without any enterprise configurations."); logger.LogInformation("AI Studio runs without any enterprise configurations.");
var effectiveSnapshot = BuildNormalizedSnapshot(effectiveEnvironments);
CURRENT_ENVIRONMENTS = effectiveEnvironments; CURRENT_ENVIRONMENTS = effectiveEnvironments;
HasValidEnterpriseSnapshot = true; HasValidEnterpriseSnapshot = true;
} }
@ -173,4 +177,21 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
logger.LogError(e, "An error occurred while updating the enterprise environment."); logger.LogError(e, "An error occurred while updating the enterprise environment.");
} }
} }
private static List<EnterpriseEnvironmentSnapshot> BuildNormalizedSnapshot(IEnumerable<EnterpriseEnvironment> environments)
{
return environments
.Where(environment => environment.IsActive)
.Select(environment => new EnterpriseEnvironmentSnapshot(
environment.ConfigurationId,
NormalizeServerUrl(environment.ConfigurationServerUrl),
environment.ETag?.ToString()))
.OrderBy(environment => environment.ConfigurationId)
.ToList();
}
private static string NormalizeServerUrl(string serverUrl)
{
return serverUrl.Trim().TrimEnd('/');
}
} }