Added a reason for why deleting a plugin

This commit is contained in:
Thorsten Sommer 2026-02-17 14:47:55 +01:00
parent 142ed9ab18
commit 99e985cb3a
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 14 additions and 12 deletions

View File

@ -5,10 +5,10 @@ namespace AIStudio.Tools.PluginSystem;
public static partial class PluginFactory
{
public static async Task<(bool Success, EntityTagHeaderValue? ETag)> DetermineConfigPluginETagAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
public static async Task<(bool Success, EntityTagHeaderValue? ETag, string? Issue)> DetermineConfigPluginETagAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
{
if(configPlugId == Guid.Empty || string.IsNullOrWhiteSpace(configServerUrl))
return (false, null);
return (false, null, "Configuration ID or server URL is missing.");
try
{
@ -21,15 +21,15 @@ public static partial class PluginFactory
if (!response.IsSuccessStatusCode)
{
LOG.LogError($"Failed to determine the ETag for configuration plugin '{configPlugId}'. HTTP Status: {response.StatusCode}");
return (false, null);
return (false, null, $"HTTP status: {response.StatusCode}");
}
return (true, response.Headers.ETag);
return (true, response.Headers.ETag, null);
}
catch (Exception e)
{
LOG.LogError(e, "An error occurred while determining the ETag for the configuration plugin.");
return (false, null);
return (false, null, e.Message);
}
}

View File

@ -4,6 +4,8 @@ namespace AIStudio.Tools.PluginSystem;
public static partial class PluginFactory
{
private const string REASON_NO_LONGER_REFERENCED = "no longer referenced by active enterprise environments";
public static void RemoveUnreferencedManagedConfigurationPlugins(ISet<Guid> activeConfigurationIds)
{
if (!IsInitialized)
@ -42,15 +44,15 @@ public static partial class PluginFactory
}
foreach (var pluginId in pluginIdsToRemove)
RemovePluginAsync(pluginId);
RemovePluginAsync(pluginId, REASON_NO_LONGER_REFERENCED);
}
private static void RemovePluginAsync(Guid pluginId)
private static void RemovePluginAsync(Guid pluginId, string reason)
{
if (!IsInitialized)
return;
LOG.LogWarning("Try to remove plugin with ID: '{PluginId}'.", pluginId);
LOG.LogWarning("Removing plugin with ID '{PluginId}'. Reason: {Reason}.", pluginId, reason);
//
// Remove the plugin from the available plugins list:
@ -59,14 +61,14 @@ public static partial class PluginFactory
if (availablePluginToRemove != null)
AVAILABLE_PLUGINS.Remove(availablePluginToRemove);
else
LOG.LogWarning("No available plugin found with ID: '{PluginId}'.", pluginId);
LOG.LogWarning("No available plugin found with ID '{PluginId}' while removing plugin. Reason: {Reason}.", pluginId, reason);
//
// Remove the plugin from the running plugins list:
//
var runningPluginToRemove = RUNNING_PLUGINS.FirstOrDefault(p => p.Id == pluginId);
if (runningPluginToRemove == null)
LOG.LogWarning("No running plugin found with ID: '{PluginId}'.", pluginId);
LOG.LogWarning("No running plugin found with ID '{PluginId}' while removing plugin. Reason: {Reason}.", pluginId, reason);
else
RUNNING_PLUGINS.Remove(runningPluginToRemove);
@ -75,7 +77,7 @@ public static partial class PluginFactory
//
DeleteConfigurationPluginDirectory(pluginId);
LOG.LogInformation("Plugin with ID='{PluginId}' removed successfully.", pluginId);
LOG.LogInformation("Plugin with ID '{PluginId}' removed successfully. Reason: {Reason}.", pluginId, reason);
}
private static bool? ReadDeployFlagFromPluginFile(string pluginDirectory)

View File

@ -79,7 +79,7 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
if (!etagResponse.Success)
{
failedConfigIds.Add(config.ConfigurationId);
logger.LogWarning("Failed to read enterprise config metadata for '{ConfigId}'. Keeping the current plugin state for this configuration.", config.ConfigurationId);
logger.LogWarning("Failed to read enterprise config metadata for '{ConfigId}' from '{ServerUrl}': {Issue}. Keeping the current plugin state for this configuration.", config.ConfigurationId, config.ConfigurationServerUrl, etagResponse.Issue ?? "Unknown issue");
continue;
}