From e72ebb95c53016249846f7d05aec71924e100069 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sat, 22 Apr 2023 10:59:39 -0400 Subject: [PATCH] Split the start/stop functionality of ISwarmService into its own interface --- .../Components/InstanceManager.cs | 14 +++++------ src/Tgstation.Server.Host/Core/Application.cs | 1 + .../Swarm/ISwarmService.cs | 14 ----------- .../Swarm/ISwarmServiceController.cs | 25 +++++++++++++++++++ .../Swarm/SwarmService.cs | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 src/Tgstation.Server.Host/Swarm/ISwarmServiceController.cs diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index 44d112ca94..699aef0c47 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -82,9 +82,9 @@ namespace Tgstation.Server.Host.Components readonly IServerPortProvider serverPortProvider; /// - /// The for the . + /// The for the . /// - readonly ISwarmService swarmService; + readonly ISwarmServiceController swarmServiceController; /// /// The for the . @@ -138,7 +138,7 @@ namespace Tgstation.Server.Host.Components /// The value of . /// The value of . /// The value of . - /// The value of . + /// The value of . /// The containing the value of . /// The containing the value of . /// The value of . @@ -152,7 +152,7 @@ namespace Tgstation.Server.Host.Components ISystemIdentityFactory systemIdentityFactory, IAsyncDelayer asyncDelayer, IServerPortProvider serverPortProvider, - ISwarmService swarmService, + ISwarmServiceController swarmServiceController, IOptions generalConfigurationOptions, IOptions swarmConfigurationOptions, ILogger logger) @@ -166,7 +166,7 @@ namespace Tgstation.Server.Host.Components this.systemIdentityFactory = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory)); this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); this.serverPortProvider = serverPortProvider ?? throw new ArgumentNullException(nameof(serverPortProvider)); - this.swarmService = swarmService ?? throw new ArgumentNullException(nameof(swarmService)); + this.swarmServiceController = swarmServiceController ?? throw new ArgumentNullException(nameof(swarmServiceController)); generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); swarmConfiguration = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -481,7 +481,7 @@ namespace Tgstation.Server.Host.Components await Task.WhenAll(instances.Select(x => OfflineInstanceImmediate(x.Value.Instance, cancellationToken))); await instanceFactoryStopTask; - await swarmService.Shutdown(cancellationToken); + await swarmServiceController.Shutdown(cancellationToken); } catch (Exception ex) { @@ -578,7 +578,7 @@ namespace Tgstation.Server.Host.Components SwarmRegistrationResult registrationResult; do { - registrationResult = await swarmService.Initialize(cancellationToken); + registrationResult = await swarmServiceController.Initialize(cancellationToken); if (registrationResult == SwarmRegistrationResult.Unauthorized) throw new InvalidOperationException("Swarm private key does not match the swarm controller's!"); diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index be4b8e1a83..7dc98d518d 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -358,6 +358,7 @@ namespace Tgstation.Server.Host.Core services.AddSingleton(); services.AddSingleton(x => x.GetRequiredService()); services.AddSingleton(x => x.GetRequiredService()); + services.AddSingleton(x => x.GetRequiredService()); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Tgstation.Server.Host/Swarm/ISwarmService.cs b/src/Tgstation.Server.Host/Swarm/ISwarmService.cs index b0bb3c69b7..a498374195 100644 --- a/src/Tgstation.Server.Host/Swarm/ISwarmService.cs +++ b/src/Tgstation.Server.Host/Swarm/ISwarmService.cs @@ -12,20 +12,6 @@ namespace Tgstation.Server.Host.Swarm /// public interface ISwarmService { - /// - /// Attempt to register with the swarm controller if not one, sets up the database otherwise. - /// - /// The for the operation. - /// A resulting in the . - Task Initialize(CancellationToken cancellationToken); - - /// - /// Deregister with the swarm controller or put clients into querying state. - /// - /// The for the operation. - /// A representing the running operation. - Task Shutdown(CancellationToken cancellationToken); - /// /// Signal to the swarm that an update is requested. /// diff --git a/src/Tgstation.Server.Host/Swarm/ISwarmServiceController.cs b/src/Tgstation.Server.Host/Swarm/ISwarmServiceController.cs new file mode 100644 index 0000000000..5912232e04 --- /dev/null +++ b/src/Tgstation.Server.Host/Swarm/ISwarmServiceController.cs @@ -0,0 +1,25 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Tgstation.Server.Host.Swarm +{ + /// + /// Start and stop controllers for a swarm service. + /// + interface ISwarmServiceController + { + /// + /// Attempt to register with the swarm controller if not one, sets up the database otherwise. + /// + /// The for the operation. + /// A resulting in the . + Task Initialize(CancellationToken cancellationToken); + + /// + /// Deregister with the swarm controller or put clients into querying state. + /// + /// The for the operation. + /// A representing the running operation. + Task Shutdown(CancellationToken cancellationToken); + } +} diff --git a/src/Tgstation.Server.Host/Swarm/SwarmService.cs b/src/Tgstation.Server.Host/Swarm/SwarmService.cs index 282a95df32..d67c6b854e 100644 --- a/src/Tgstation.Server.Host/Swarm/SwarmService.cs +++ b/src/Tgstation.Server.Host/Swarm/SwarmService.cs @@ -27,7 +27,7 @@ namespace Tgstation.Server.Host.Swarm /// /// Helps keep servers connected to the same database in sync by coordinating updates. /// - sealed class SwarmService : ISwarmService, ISwarmOperations, IDisposable + sealed class SwarmService : ISwarmService, ISwarmServiceController, ISwarmOperations, IDisposable { /// /// Interval at which the swarm controller makes health checks on nodes.