From 43093763375b93a4b8b8f98b5244f2e7a7e4fbcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Mon, 24 Feb 2025 09:07:14 +0100 Subject: [PATCH 1/4] Use correct name for the instance setup phase --- .../Framework/Modules/InstallerModule.cs | 4 +- .../Instances/MonitoringInstance.cs | 18 ++--- .../Instances/MonitoringNewInstance.cs | 10 +-- .../Instances/ServiceControlAuditInstance.cs | 10 +-- .../ServiceControlAuditNewInstance.cs | 7 +- .../Instances/ServiceControlBaseService.cs | 11 +-- .../ServiceControlInstallableBase.cs | 11 +-- .../Instances/ServiceControlInstance.cs | 6 +- .../Instances/ServiceControlNewInstance.cs | 6 +- .../Queues/QueueCreation.cs | 77 ------------------- .../Queues/QueueCreationException.cs | 15 ---- .../Queues/QueueCreationTimeoutException.cs | 15 ---- ...iceControlQueueCreationTimeoutException.cs | 15 ---- .../Setup/InstanceSetup.cs | 70 +++++++++++++++++ 14 files changed, 100 insertions(+), 175 deletions(-) delete mode 100644 src/ServiceControlInstaller.Engine/Queues/QueueCreation.cs delete mode 100644 src/ServiceControlInstaller.Engine/Queues/QueueCreationException.cs delete mode 100644 src/ServiceControlInstaller.Engine/Queues/QueueCreationTimeoutException.cs delete mode 100644 src/ServiceControlInstaller.Engine/Queues/ServiceControlQueueCreationTimeoutException.cs create mode 100644 src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs diff --git a/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs b/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs index cc83c0147a..c426d855dc 100644 --- a/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs +++ b/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs @@ -67,7 +67,7 @@ internal async Task Add(ServiceControlInstallableBase details, IProg { progress.Report(5, 9, "Registering URL ACLs..."); instanceInstaller.RegisterUrlAcl(); - progress.Report(6, 9, "Creating queues..."); + progress.Report(6, 9, "Running instance setup..."); instanceInstaller.SetupInstance(); } catch (Exception ex) @@ -141,7 +141,7 @@ internal ReportCard Upgrade(ServiceControlBaseService instance, ServiceControlUp UpgradeOptions(upgradeOptions, instance); - progress.Report(++currentStep, totalSteps, "Running Queue Creation..."); + progress.Report(++currentStep, totalSteps, "Running instance setup..."); instance.SetupInstance(); instance.ReportCard.SetStatus(); diff --git a/src/ServiceControlInstaller.Engine/Instances/MonitoringInstance.cs b/src/ServiceControlInstaller.Engine/Instances/MonitoringInstance.cs index aaef5a93af..7a1be79145 100644 --- a/src/ServiceControlInstaller.Engine/Instances/MonitoringInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/MonitoringInstance.cs @@ -11,9 +11,9 @@ using Configuration; using Configuration.Monitoring; using FileSystem; - using Queues; using ReportCard; using Services; + using Setup; using UrlAcl; using Validation; @@ -188,13 +188,9 @@ public void ApplyConfigChange() { try { - QueueCreation.RunQueueCreation(this); + InstanceSetup.Run(this); } - catch (QueueCreationFailedException ex) - { - ReportCard.Errors.Add(ex.Message); - } - catch (QueueCreationTimeoutException ex) + catch (Exception ex) { ReportCard.Errors.Add(ex.Message); } @@ -278,13 +274,9 @@ public void SetupInstance() { try { - QueueCreation.RunQueueCreation(this); - } - catch (QueueCreationFailedException ex) - { - ReportCard.Errors.Add(ex.Message); + InstanceSetup.Run(this); } - catch (QueueCreationTimeoutException ex) + catch (Exception ex) { ReportCard.Errors.Add(ex.Message); } diff --git a/src/ServiceControlInstaller.Engine/Instances/MonitoringNewInstance.cs b/src/ServiceControlInstaller.Engine/Instances/MonitoringNewInstance.cs index 3edd9c0b53..6af1986df6 100644 --- a/src/ServiceControlInstaller.Engine/Instances/MonitoringNewInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/MonitoringNewInstance.cs @@ -11,7 +11,7 @@ using Configuration.Monitoring; using FileSystem; using NuGet.Versioning; - using Queues; + using Setup; using ReportCard; using Services; using UrlAcl; @@ -148,13 +148,9 @@ public void SetupInstance() { try { - QueueCreation.RunQueueCreation(this); + InstanceSetup.Run(this); } - catch (QueueCreationFailedException ex) - { - ReportCard.Errors.Add(ex.Message); - } - catch (QueueCreationTimeoutException ex) + catch (Exception ex) { ReportCard.Errors.Add(ex.Message); } diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs index 3608e16cf2..d0b908b2a9 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs @@ -8,8 +8,8 @@ namespace ServiceControlInstaller.Engine.Instances using Configuration; using Configuration.ServiceControl; using FileSystem; - using Queues; - using ServiceControlInstaller.Engine.Validation; + using Setup; + using Validation; using Services; public class ServiceControlAuditInstance : ServiceControlBaseService, IServiceControlAuditInstance @@ -57,7 +57,7 @@ protected override AppConfig CreateAppConfig() protected override TransportInfo DetermineTransportPackage() { var transportAppSetting = (AppConfig.Read(AuditInstanceSettingsList.TransportType, null)?.Trim()) - ?? throw new Exception($"{AuditInstanceSettingsList.TransportType.Name} setting not found in app.config."); + ?? throw new Exception($"{AuditInstanceSettingsList.TransportType.Name} setting not found in app.config."); var transport = ServiceControlCoreTransports.Find(transportAppSetting); @@ -102,9 +102,9 @@ public override void Reload() EnableFullTextSearchOnBodies = AppConfig.Read(AuditInstanceSettingsList.EnableFullTextSearchOnBodies, true); } - public override void RunQueueCreation() + public override void RunSetup() { - QueueCreation.RunQueueCreation(this); + InstanceSetup.Run(this); } protected override void Prepare(string zipResourceName, string destDir) diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs index 46c9150364..ff192d4cca 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs @@ -2,10 +2,9 @@ { using System; using System.IO; - using System.Xml; using System.Xml.Serialization; using Configuration.ServiceControl; - using Queues; + using Setup; using Services; using Validation; @@ -58,9 +57,9 @@ internal override WindowsServiceDetails GetWindowsServiceDetails() }; } - protected override void RunQueueCreation() + protected override void RunSetup() { - QueueCreation.RunQueueCreation(this); + InstanceSetup.Run(this); } protected override void ValidateMaintenancePort() diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs index 1b659e3a84..b15aa10c8f 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs @@ -12,7 +12,6 @@ namespace ServiceControlInstaller.Engine.Instances using Configuration; using FileSystem; using NuGet.Versioning; - using Queues; using ReportCard; using Services; using UrlAcl; @@ -383,19 +382,15 @@ public void RestoreAppConfig(string sourcePath) AppConfig.Save(); } - public abstract void RunQueueCreation(); + public abstract void RunSetup(); public void SetupInstance() { try { - RunQueueCreation(); + RunSetup(); } - catch (QueueCreationFailedException ex) - { - ReportCard.Errors.Add(ex.Message); - } - catch (QueueCreationTimeoutException ex) + catch (Exception ex) { ReportCard.Errors.Add(ex.Message); } diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstallableBase.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstallableBase.cs index a6adb14a70..be5ebb7775 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstallableBase.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstallableBase.cs @@ -11,7 +11,6 @@ using Accounts; using FileSystem; using NuGet.Versioning; - using Queues; using ReportCard; using Services; using UrlAcl; @@ -197,7 +196,7 @@ protected List GetServiceDependencies() internal abstract WindowsServiceDetails GetWindowsServiceDetails(); - protected abstract void RunQueueCreation(); + protected abstract void RunSetup(); public void RegisterUrlAcl() { @@ -221,13 +220,9 @@ public void SetupInstance() { try { - RunQueueCreation(); + RunSetup(); } - catch (QueueCreationFailedException ex) - { - ReportCard.Errors.Add(ex.Message); - } - catch (QueueCreationTimeoutException ex) + catch (Exception ex) { ReportCard.Errors.Add(ex.Message); } diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs index 688fe5a5ea..f500a82545 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs @@ -9,8 +9,8 @@ namespace ServiceControlInstaller.Engine.Instances using Configuration; using Configuration.ServiceControl; using FileSystem; - using Queues; using Services; + using Setup; using Validation; using AppConfig = Configuration.ServiceControl.AppConfig; @@ -56,9 +56,9 @@ protected override AppConfig CreateAppConfig() return new ServiceControlAppConfig(this); } - public override void RunQueueCreation() + public override void RunSetup() { - QueueCreation.RunQueueCreation(this); + InstanceSetup.Run(this); } protected override void ValidateQueueNames() diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs index b46343780f..62fded61dd 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs @@ -7,8 +7,8 @@ namespace ServiceControlInstaller.Engine.Instances using System.Xml; using System.Xml.Serialization; using Configuration.ServiceControl; - using Queues; using Services; + using Setup; using Validation; public class ServiceControlNewInstance : ServiceControlInstallableBase, IServiceControlInstance @@ -85,9 +85,9 @@ internal override WindowsServiceDetails GetWindowsServiceDetails() }; } - protected override void RunQueueCreation() + protected override void RunSetup() { - QueueCreation.RunQueueCreation(this); + InstanceSetup.Run(this); } protected override void ValidateMaintenancePort() diff --git a/src/ServiceControlInstaller.Engine/Queues/QueueCreation.cs b/src/ServiceControlInstaller.Engine/Queues/QueueCreation.cs deleted file mode 100644 index 7ed3f6425a..0000000000 --- a/src/ServiceControlInstaller.Engine/Queues/QueueCreation.cs +++ /dev/null @@ -1,77 +0,0 @@ -namespace ServiceControlInstaller.Engine.Queues -{ - using System; - using System.Diagnostics; - using System.IO; - using Instances; - - static class QueueCreation - { - public static void RunQueueCreation(IServiceControlInstance instance) - { - RunQueueCreation(instance.InstallPath, - Constants.ServiceControlExe, - instance.Name, - instance.SkipQueueCreation); - } - - public static void RunQueueCreation(IServiceControlAuditInstance instance) - { - RunQueueCreation(instance.InstallPath, - Constants.ServiceControlAuditExe, - instance.Name, - instance.SkipQueueCreation); - } - - public static void RunQueueCreation(IMonitoringInstance instance) - { - RunQueueCreation(instance.InstallPath, - Constants.MonitoringExe, - instance.Name, - instance.SkipQueueCreation); - } - - static void RunQueueCreation(string installPath, string exeName, string instanceName, bool skipQueueCreation = false) - { - var args = $"--setup"; - - if (skipQueueCreation) - { - args += " --skip-queue-creation"; - } - - var processStartupInfo = new ProcessStartInfo - { - CreateNoWindow = true, - UseShellExecute = false, - FileName = Path.Combine(installPath, exeName), - Arguments = args, - WorkingDirectory = installPath, - RedirectStandardError = true - }; - - processStartupInfo.EnvironmentVariables.Add("INSTANCE_NAME", instanceName); - - var p = Process.Start(processStartupInfo); - if (p != null) - { - var error = p.StandardError.ReadToEnd(); - p.WaitForExit((int)TimeSpan.FromMinutes(1).TotalMilliseconds); - if (!p.HasExited) - { - p.Kill(); - throw new QueueCreationTimeoutException($"Timed out waiting for {exeName} to created queues. This usually indicates a configuration error."); - } - - if (p.ExitCode != 0) - { - throw new QueueCreationFailedException($"{exeName} threw an error when creating queues. This typically indicates a configuration error. The error output from {exeName} was:\r\n {error}"); - } - } - else - { - throw new Exception($"Attempt to launch {exeName} failed."); - } - } - } -} \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Queues/QueueCreationException.cs b/src/ServiceControlInstaller.Engine/Queues/QueueCreationException.cs deleted file mode 100644 index 805a1ebcd4..0000000000 --- a/src/ServiceControlInstaller.Engine/Queues/QueueCreationException.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace ServiceControlInstaller.Engine.Queues -{ - using System; - - public class QueueCreationFailedException : Exception - { - public QueueCreationFailedException(string message) : base(message) - { - } - - public QueueCreationFailedException(string message, Exception inner) : base(message, inner) - { - } - } -} \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Queues/QueueCreationTimeoutException.cs b/src/ServiceControlInstaller.Engine/Queues/QueueCreationTimeoutException.cs deleted file mode 100644 index c54f2f53b7..0000000000 --- a/src/ServiceControlInstaller.Engine/Queues/QueueCreationTimeoutException.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace ServiceControlInstaller.Engine.Queues -{ - using System; - - public class QueueCreationTimeoutException : Exception - { - public QueueCreationTimeoutException(string message) : base(message) - { - } - - public QueueCreationTimeoutException(string message, Exception inner) : base(message, inner) - { - } - } -} \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Queues/ServiceControlQueueCreationTimeoutException.cs b/src/ServiceControlInstaller.Engine/Queues/ServiceControlQueueCreationTimeoutException.cs deleted file mode 100644 index c726ec68cf..0000000000 --- a/src/ServiceControlInstaller.Engine/Queues/ServiceControlQueueCreationTimeoutException.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace ServiceControlInstaller.Engine.Queues -{ - using System; - - public class ServiceControlQueueCreationTimeoutException : Exception - { - public ServiceControlQueueCreationTimeoutException(string message) : base(message) - { - } - - public ServiceControlQueueCreationTimeoutException(string message, Exception inner) : base(message, inner) - { - } - } -} \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs new file mode 100644 index 0000000000..e43cc5d26f --- /dev/null +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -0,0 +1,70 @@ +namespace ServiceControlInstaller.Engine.Setup; + +using System; +using System.Diagnostics; +using System.IO; +using Instances; + +static class InstanceSetup +{ + public static void Run(IServiceControlInstance instance) => + Run(instance.InstallPath, + Constants.ServiceControlExe, + instance.Name, + instance.SkipQueueCreation); + + public static void Run(IServiceControlAuditInstance instance) => + Run(instance.InstallPath, + Constants.ServiceControlAuditExe, + instance.Name, + instance.SkipQueueCreation); + + public static void Run(IMonitoringInstance instance) => + Run(instance.InstallPath, + Constants.MonitoringExe, + instance.Name, + instance.SkipQueueCreation); + + static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation = false) + { + var args = $"--setup"; + + if (skipQueueCreation) + { + args += " --skip-queue-creation"; + } + + var processStartupInfo = new ProcessStartInfo + { + CreateNoWindow = true, + UseShellExecute = false, + FileName = Path.Combine(installPath, exeName), + Arguments = args, + WorkingDirectory = installPath, + RedirectStandardError = true + }; + + processStartupInfo.EnvironmentVariables.Add("INSTANCE_NAME", instanceName); + + var p = Process.Start(processStartupInfo); + if (p != null) + { + var error = p.StandardError.ReadToEnd(); + p.WaitForExit((int)TimeSpan.FromMinutes(1).TotalMilliseconds); + if (!p.HasExited) + { + p.Kill(); + throw new TimeoutException($"Timed out waiting for {exeName} to perform setup. This usually indicates a configuration error."); + } + + if (p.ExitCode != 0) + { + throw new Exception($"{exeName} threw an error when performing setup. This typically indicates a configuration error. The error output from {exeName} was:\r\n {error}"); + } + } + else + { + throw new Exception($"Attempt to launch {exeName} failed."); + } + } +} \ No newline at end of file From 36b7e38fac188f9dfc06c3ff735160398fc601c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Mon, 24 Feb 2025 09:29:23 +0100 Subject: [PATCH 2/4] Cleanup --- src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs index e43cc5d26f..a97f456465 100644 --- a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -25,7 +25,7 @@ public static void Run(IMonitoringInstance instance) => instance.Name, instance.SkipQueueCreation); - static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation = false) + static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation) { var args = $"--setup"; From 340f688fb178d378d7077f61b56b2a665e8f790d Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 25 Feb 2025 09:59:38 +0100 Subject: [PATCH 3/4] Added 'can take a very long time' --- .../Framework/Modules/InstallerModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs b/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs index c426d855dc..d8128d87fe 100644 --- a/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs +++ b/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs @@ -67,7 +67,7 @@ internal async Task Add(ServiceControlInstallableBase details, IProg { progress.Report(5, 9, "Registering URL ACLs..."); instanceInstaller.RegisterUrlAcl(); - progress.Report(6, 9, "Running instance setup..."); + progress.Report(6, 9, "Running instance setup (can take a very long time)..."); instanceInstaller.SetupInstance(); } catch (Exception ex) @@ -141,7 +141,7 @@ internal ReportCard Upgrade(ServiceControlBaseService instance, ServiceControlUp UpgradeOptions(upgradeOptions, instance); - progress.Report(++currentStep, totalSteps, "Running instance setup..."); + progress.Report(++currentStep, totalSteps, "Running instance setup (can take a very long time)..."); instance.SetupInstance(); instance.ReportCard.SetStatus(); From 59702e956630e97b824e479d7f0ca51c837cba0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Tue, 25 Feb 2025 10:07:06 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Mauro Servienti --- .../Framework/Modules/InstallerModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs b/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs index d8128d87fe..fed25576ef 100644 --- a/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs +++ b/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs @@ -67,7 +67,7 @@ internal async Task Add(ServiceControlInstallableBase details, IProg { progress.Report(5, 9, "Registering URL ACLs..."); instanceInstaller.RegisterUrlAcl(); - progress.Report(6, 9, "Running instance setup (can take a very long time)..."); + progress.Report(6, 9, "Instance setup in progress, this could take several minutes..."); instanceInstaller.SetupInstance(); } catch (Exception ex) @@ -141,7 +141,7 @@ internal ReportCard Upgrade(ServiceControlBaseService instance, ServiceControlUp UpgradeOptions(upgradeOptions, instance); - progress.Report(++currentStep, totalSteps, "Running instance setup (can take a very long time)..."); + progress.Report(++currentStep, totalSteps, "Instance setup in progress, this could take several minutes..."); instance.SetupInstance(); instance.ReportCard.SetStatus();