From e511ca37e71999022357eb38617cb0a4a72f351e Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 12 May 2020 20:09:34 -0400 Subject: [PATCH] Split up the Watchdog namespace into Session --- .../Components/Deployment/DreamMaker.cs | 1 + .../Components/InstanceFactory.cs | 1 + .../Interop/Topic/TopicParameters.cs | 2 +- .../ApiValidationStatus.cs | 2 +- .../CombinedTopicResponse.cs | 2 +- .../DeadSessionController.cs | 2 +- .../DualReattachInformation.cs} | 16 +++++----- .../IReattachInfoHandler.cs | 14 ++++----- .../ISessionController.cs | 4 +-- .../ISessionControllerFactory.cs | 2 +- .../{Watchdog => Session}/LaunchResult.cs | 2 +- .../{ => Session}/ReattachInfoHandler.cs | 13 ++++---- .../ReattachInformation.cs | 2 +- .../{Watchdog => Session}/RebootState.cs | 2 +- .../SessionController.cs | 2 +- .../SessionControllerFactory.cs | 2 +- .../Components/Watchdog/BasicWatchdog.cs | 23 +++++++------- .../Watchdog/ExperimentalWatchdog.cs | 17 +++++----- .../Components/Watchdog/IWatchdog.cs | 3 +- .../Components/Watchdog/IWatchdogFactory.cs | 1 + .../Components/Watchdog/MonitorState.cs | 1 + .../Components/Watchdog/WatchdogBase.cs | 31 ++++++++++--------- .../Components/Watchdog/WatchdogFactory.cs | 1 + .../Components/Watchdog/WindowsWatchdog.cs | 1 + .../Watchdog/WindowsWatchdogFactory.cs | 1 + .../Controllers/DreamDaemonController.cs | 2 +- .../Database/DatabaseContext.cs | 10 +++--- .../Database/IDatabaseContext.cs | 4 +-- ...ormation.cs => DualReattachInformation.cs} | 6 ++-- .../Models/DualReattachInformationBase.cs | 29 +++++++++++++++++ src/Tgstation.Server.Host/Models/Instance.cs | 4 +-- .../Models/ReattachInformation.cs | 4 +-- .../Models/ReattachInformationBase.cs | 2 +- .../Models/WatchdogReattachInformationBase.cs | 29 ----------------- .../Watchdog/TestExperimentalWatchdog.cs | 1 + 35 files changed, 125 insertions(+), 114 deletions(-) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/ApiValidationStatus.cs (94%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/CombinedTopicResponse.cs (95%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/DeadSessionController.cs (98%) rename src/Tgstation.Server.Host/Components/{Watchdog/WatchdogReattachInformation.cs => Session/DualReattachInformation.cs} (61%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/IReattachInfoHandler.cs (53%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/ISessionController.cs (97%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/ISessionControllerFactory.cs (98%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/LaunchResult.cs (93%) rename src/Tgstation.Server.Host/Components/{ => Session}/ReattachInfoHandler.cs (87%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/ReattachInformation.cs (98%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/RebootState.cs (87%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/SessionController.cs (99%) rename src/Tgstation.Server.Host/Components/{Watchdog => Session}/SessionControllerFactory.cs (99%) rename src/Tgstation.Server.Host/Models/{WatchdogReattachInformation.cs => DualReattachInformation.cs} (78%) create mode 100644 src/Tgstation.Server.Host/Models/DualReattachInformationBase.cs delete mode 100644 src/Tgstation.Server.Host/Models/WatchdogReattachInformationBase.cs diff --git a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs index b93b3c2202..8cceeb1dd4 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs @@ -11,6 +11,7 @@ using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Byond; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Repository; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Components.Watchdog; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 2a091708ca..d9991f0044 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -9,6 +9,7 @@ using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Components.Deployment; using Tgstation.Server.Host.Components.Interop; using Tgstation.Server.Host.Components.Repository; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Components.Watchdog; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; diff --git a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs index 1309384ac9..d5248bc1f2 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs @@ -1,5 +1,5 @@ using System; -using Tgstation.Server.Host.Components.Watchdog; +using Tgstation.Server.Host.Components.Session; namespace Tgstation.Server.Host.Components.Interop.Topic { diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ApiValidationStatus.cs b/src/Tgstation.Server.Host/Components/Session/ApiValidationStatus.cs similarity index 94% rename from src/Tgstation.Server.Host/Components/Watchdog/ApiValidationStatus.cs rename to src/Tgstation.Server.Host/Components/Session/ApiValidationStatus.cs index f830edb59e..1e4077b3e4 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ApiValidationStatus.cs +++ b/src/Tgstation.Server.Host/Components/Session/ApiValidationStatus.cs @@ -1,4 +1,4 @@ -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Status of DMAPI validation diff --git a/src/Tgstation.Server.Host/Components/Watchdog/CombinedTopicResponse.cs b/src/Tgstation.Server.Host/Components/Session/CombinedTopicResponse.cs similarity index 95% rename from src/Tgstation.Server.Host/Components/Watchdog/CombinedTopicResponse.cs rename to src/Tgstation.Server.Host/Components/Session/CombinedTopicResponse.cs index 34da84f1ef..f5606822b2 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/CombinedTopicResponse.cs +++ b/src/Tgstation.Server.Host/Components/Session/CombinedTopicResponse.cs @@ -1,7 +1,7 @@ using System; using Tgstation.Server.Host.Components.Interop.Topic; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Combines a with a . diff --git a/src/Tgstation.Server.Host/Components/Watchdog/DeadSessionController.cs b/src/Tgstation.Server.Host/Components/Session/DeadSessionController.cs similarity index 98% rename from src/Tgstation.Server.Host/Components/Watchdog/DeadSessionController.cs rename to src/Tgstation.Server.Host/Components/Session/DeadSessionController.cs index 8c8a72f147..a49c9f7738 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/DeadSessionController.cs +++ b/src/Tgstation.Server.Host/Components/Session/DeadSessionController.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Tgstation.Server.Host.Components.Deployment; using Tgstation.Server.Host.Components.Interop.Topic; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Implements a fake "dead" diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogReattachInformation.cs b/src/Tgstation.Server.Host/Components/Session/DualReattachInformation.cs similarity index 61% rename from src/Tgstation.Server.Host/Components/Watchdog/WatchdogReattachInformation.cs rename to src/Tgstation.Server.Host/Components/Session/DualReattachInformation.cs index 0570d7a96f..2732935299 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogReattachInformation.cs +++ b/src/Tgstation.Server.Host/Components/Session/DualReattachInformation.cs @@ -3,12 +3,12 @@ using System.Globalization; using Tgstation.Server.Host.Components.Deployment; using Tgstation.Server.Host.Models; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// - /// Reattach information for a + /// Reattach information for two /// - public sealed class WatchdogReattachInformation : WatchdogReattachInformationBase + public sealed class DualReattachInformation : DualReattachInformationBase { /// /// for the Alpha session @@ -21,17 +21,17 @@ namespace Tgstation.Server.Host.Components.Watchdog public ReattachInformation Bravo { get; set; } /// - /// Construct a + /// Construct a /// - public WatchdogReattachInformation() { } + public DualReattachInformation() { } /// - /// Construct a from a given with a given and + /// Construct a from a given with a given and /// - /// The to copy information from + /// The to copy information from /// The used to build /// The used to build - public WatchdogReattachInformation(Models.WatchdogReattachInformation copy, IDmbProvider dmbAlpha, IDmbProvider dmbBravo) : base(copy) + public DualReattachInformation(Models.DualReattachInformation copy, IDmbProvider dmbAlpha, IDmbProvider dmbBravo) : base(copy) { if (copy.Alpha != null) Alpha = new ReattachInformation(copy.Alpha, dmbAlpha); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/IReattachInfoHandler.cs b/src/Tgstation.Server.Host/Components/Session/IReattachInfoHandler.cs similarity index 53% rename from src/Tgstation.Server.Host/Components/Watchdog/IReattachInfoHandler.cs rename to src/Tgstation.Server.Host/Components/Session/IReattachInfoHandler.cs index 3547b641c7..d153cd713d 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/IReattachInfoHandler.cs +++ b/src/Tgstation.Server.Host/Components/Session/IReattachInfoHandler.cs @@ -1,26 +1,26 @@ using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// - /// Handles saving and loading + /// Handles saving and loading /// public interface IReattachInfoHandler { /// /// Save some /// - /// The to save + /// The to save /// The for the operation /// A representing the running operation - Task Save(WatchdogReattachInformation reattachInformation, CancellationToken cancellationToken); + Task Save(DualReattachInformation reattachInformation, CancellationToken cancellationToken); /// - /// Load a saved + /// Load a saved /// /// The for the operation - /// A resulting in the stored if any - Task Load(CancellationToken cancellationToken); + /// A resulting in the stored if any + Task Load(CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ISessionController.cs b/src/Tgstation.Server.Host/Components/Session/ISessionController.cs similarity index 97% rename from src/Tgstation.Server.Host/Components/Watchdog/ISessionController.cs rename to src/Tgstation.Server.Host/Components/Session/ISessionController.cs index e27cfa084b..c598d9a331 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ISessionController.cs +++ b/src/Tgstation.Server.Host/Components/Session/ISessionController.cs @@ -5,7 +5,7 @@ using Tgstation.Server.Host.Components.Deployment; using Tgstation.Server.Host.Components.Interop.Topic; using Tgstation.Server.Host.System; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Handles communication with a DreamDaemon @@ -28,7 +28,7 @@ namespace Tgstation.Server.Host.Components.Watchdog bool TerminationWasRequested { get; } /// - /// The DMAPI + /// The DMAPI /// ApiValidationStatus ApiValidationStatus { get; } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ISessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Session/ISessionControllerFactory.cs similarity index 98% rename from src/Tgstation.Server.Host/Components/Watchdog/ISessionControllerFactory.cs rename to src/Tgstation.Server.Host/Components/Session/ISessionControllerFactory.cs index 54cb97fbb8..452216cb6c 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ISessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Session/ISessionControllerFactory.cs @@ -4,7 +4,7 @@ using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Byond; using Tgstation.Server.Host.Components.Deployment; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Factory for s diff --git a/src/Tgstation.Server.Host/Components/Watchdog/LaunchResult.cs b/src/Tgstation.Server.Host/Components/Session/LaunchResult.cs similarity index 93% rename from src/Tgstation.Server.Host/Components/Watchdog/LaunchResult.cs rename to src/Tgstation.Server.Host/Components/Session/LaunchResult.cs index 15134f80e1..10132f32ce 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/LaunchResult.cs +++ b/src/Tgstation.Server.Host/Components/Session/LaunchResult.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Represents the result of trying to start a DD process diff --git a/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs b/src/Tgstation.Server.Host/Components/Session/ReattachInfoHandler.cs similarity index 87% rename from src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs rename to src/Tgstation.Server.Host/Components/Session/ReattachInfoHandler.cs index c56d26b521..c194aad5b0 100644 --- a/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs +++ b/src/Tgstation.Server.Host/Components/Session/ReattachInfoHandler.cs @@ -5,11 +5,10 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Components.Deployment; -using Tgstation.Server.Host.Components.Watchdog; using Tgstation.Server.Host.Database; using Z.EntityFramework.Plus; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Session { /// sealed class ReattachInfoHandler : IReattachInfoHandler @@ -50,7 +49,7 @@ namespace Tgstation.Server.Host.Components } /// - public Task Save(WatchdogReattachInformation reattachInformation, CancellationToken cancellationToken) => databaseContextFactory.UseContext(async (db) => + public Task Save(DualReattachInformation reattachInformation, CancellationToken cancellationToken) => databaseContextFactory.UseContext(async (db) => { if (reattachInformation == null) throw new ArgumentNullException(nameof(reattachInformation)); @@ -78,7 +77,7 @@ namespace Tgstation.Server.Host.Components await deleteTask.ConfigureAwait(false); - db.WatchdogReattachInformations.Add(new Models.WatchdogReattachInformation + db.WatchdogReattachInformations.Add(new Models.DualReattachInformation { Alpha = ConvertReattachInfo(reattachInformation.Alpha), Bravo = ConvertReattachInfo(reattachInformation.Bravo), @@ -89,9 +88,9 @@ namespace Tgstation.Server.Host.Components }); /// - public async Task Load(CancellationToken cancellationToken) + public async Task Load(CancellationToken cancellationToken) { - Models.WatchdogReattachInformation result = null; + Models.DualReattachInformation result = null; await databaseContextFactory.UseContext(async (db) => { var instance = await db.Instances.Where(x => x.Id == metadata.Id) @@ -117,7 +116,7 @@ namespace Tgstation.Server.Host.Components : Task.FromResult(null); var bravoDmbTask = GetDmbForReattachInfo(result.Bravo); - var info = new WatchdogReattachInformation(result, await GetDmbForReattachInfo(result.Alpha).ConfigureAwait(false), await bravoDmbTask.ConfigureAwait(false)); + var info = new DualReattachInformation(result, await GetDmbForReattachInfo(result.Alpha).ConfigureAwait(false), await bravoDmbTask.ConfigureAwait(false)); logger.LogDebug("Reattach information loaded: {0}", info); return info; } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs b/src/Tgstation.Server.Host/Components/Session/ReattachInformation.cs similarity index 98% rename from src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs rename to src/Tgstation.Server.Host/Components/Session/ReattachInformation.cs index 0edbdd65ef..80492893f7 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs +++ b/src/Tgstation.Server.Host/Components/Session/ReattachInformation.cs @@ -4,7 +4,7 @@ using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Models; using Tgstation.Server.Host.System; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Parameters necessary for duplicating a session diff --git a/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs b/src/Tgstation.Server.Host/Components/Session/RebootState.cs similarity index 87% rename from src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs rename to src/Tgstation.Server.Host/Components/Session/RebootState.cs index 0dbc6e95aa..2368f4a82b 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs +++ b/src/Tgstation.Server.Host/Components/Session/RebootState.cs @@ -1,4 +1,4 @@ -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// /// Represents the action to take when /world/Reboot() is called diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs b/src/Tgstation.Server.Host/Components/Session/SessionController.cs similarity index 99% rename from src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs rename to src/Tgstation.Server.Host/Components/Session/SessionController.cs index e91e5bb03d..098986595e 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionController.cs @@ -17,7 +17,7 @@ using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Components.Interop.Topic; using Tgstation.Server.Host.System; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// sealed class SessionController : ISessionController, IBridgeHandler, IChannelSink diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs similarity index 99% rename from src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs rename to src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs index b55a226a6a..aef22ee773 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs @@ -18,7 +18,7 @@ using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Security; using Tgstation.Server.Host.System; -namespace Tgstation.Server.Host.Components.Watchdog +namespace Tgstation.Server.Host.Components.Session { /// sealed class SessionControllerFactory : ISessionControllerFactory diff --git a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs index aec7f46bf7..543800cc5d 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Jobs; @@ -107,7 +108,7 @@ namespace Tgstation.Server.Host.Components.Watchdog { case MonitorActivationReason.ActiveServerCrashed: string exitWord = Server.TerminationWasRequested ? "exited" : "crashed"; - if (Server.RebootState == Watchdog.RebootState.Shutdown) + if (Server.RebootState == Session.RebootState.Shutdown) { // the time for graceful shutdown is now await Chat.SendWatchdogMessage( @@ -136,10 +137,10 @@ namespace Tgstation.Server.Host.Components.Watchdog break; case MonitorActivationReason.ActiveServerRebooted: var rebootState = Server.RebootState; - if (gracefulRebootRequired && rebootState == Watchdog.RebootState.Normal) + if (gracefulRebootRequired && rebootState == Session.RebootState.Normal) { Logger.LogError("Watchdog reached normal reboot state with gracefulRebootRequired set!"); - rebootState = Watchdog.RebootState.Restart; + rebootState = Session.RebootState.Restart; } gracefulRebootRequired = false; @@ -147,13 +148,13 @@ namespace Tgstation.Server.Host.Components.Watchdog switch (rebootState) { - case Watchdog.RebootState.Normal: + case Session.RebootState.Normal: monitorState.NextAction = HandleNormalReboot(); break; - case Watchdog.RebootState.Restart: + case Session.RebootState.Restart: monitorState.NextAction = MonitorAction.Restart; break; - case Watchdog.RebootState.Shutdown: + case Session.RebootState.Shutdown: // graceful shutdown time await Chat.SendWatchdogMessage( "Active server rebooted! Shutting down due to graceful termination request...", @@ -168,7 +169,7 @@ namespace Tgstation.Server.Host.Components.Watchdog break; case MonitorActivationReason.ActiveLaunchParametersUpdated: - await Server.SetRebootState(Watchdog.RebootState.Restart, cancellationToken).ConfigureAwait(false); + await Server.SetRebootState(Session.RebootState.Restart, cancellationToken).ConfigureAwait(false); gracefulRebootRequired = true; break; case MonitorActivationReason.NewDmbAvailable: @@ -185,8 +186,8 @@ namespace Tgstation.Server.Host.Components.Watchdog } /// - protected sealed override WatchdogReattachInformation CreateReattachInformation() - => new WatchdogReattachInformation + protected sealed override DualReattachInformation CreateReattachInformation() + => new DualReattachInformation { AlphaIsActive = true, Alpha = Server?.Release() @@ -205,7 +206,7 @@ namespace Tgstation.Server.Host.Components.Watchdog protected sealed override ISessionController GetActiveController() => Server; /// - protected sealed override async Task InitControllers(Action callBeforeRecurse, Task chatTask, WatchdogReattachInformation reattachInfo, CancellationToken cancellationToken) + protected sealed override async Task InitControllers(Action callBeforeRecurse, Task chatTask, DualReattachInformation reattachInfo, CancellationToken cancellationToken) { var serverToReattach = reattachInfo?.Alpha ?? reattachInfo?.Bravo; var serverToKill = reattachInfo?.Bravo ?? reattachInfo?.Alpha; @@ -310,7 +311,7 @@ namespace Tgstation.Server.Host.Components.Watchdog protected virtual Task HandleNewDmbAvailable(CancellationToken cancellationToken) { gracefulRebootRequired = true; - return Server.SetRebootState(Watchdog.RebootState.Restart, cancellationToken); + return Server.SetRebootState(Session.RebootState.Restart, cancellationToken); } /// diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs index 8f8383cc8e..02daf7d157 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Jobs; @@ -229,7 +230,7 @@ namespace Tgstation.Server.Host.Components.Watchdog switch (activationReason) { case MonitorActivationReason.ActiveServerCrashed: - if (monitorState.ActiveServer.RebootState == Watchdog.RebootState.Shutdown) + if (monitorState.ActiveServer.RebootState == Session.RebootState.Shutdown) { // the time for graceful shutdown is now await Chat.SendWatchdogMessage( @@ -293,7 +294,7 @@ namespace Tgstation.Server.Host.Components.Watchdog var rebootState = monitorState.ActiveServer.RebootState; monitorState.ActiveServer.ResetRebootState(); // the DMAPI has already done this internally - if (FullRestartDeadInactive() && rebootState != Watchdog.RebootState.Shutdown) + if (FullRestartDeadInactive() && rebootState != Session.RebootState.Shutdown) break; // full restart if the inactive server is being fucky // what matters here is the RebootState @@ -301,14 +302,14 @@ namespace Tgstation.Server.Host.Components.Watchdog switch (rebootState) { - case Watchdog.RebootState.Normal: + case Session.RebootState.Normal: // life as normal break; - case Watchdog.RebootState.Restart: + case Session.RebootState.Restart: // reboot the current active server once the inactive one activates restartOnceSwapped = true; break; - case Watchdog.RebootState.Shutdown: + case Session.RebootState.Shutdown: // graceful shutdown time await Chat.SendWatchdogMessage( "Active server rebooted! Shutting down due to graceful termination request...", @@ -438,7 +439,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// #pragma warning disable CA1502 // TODO: Decomplexify - protected override async Task InitControllers(Action callBeforeRecurse, Task chatTask, WatchdogReattachInformation reattachInfo, CancellationToken cancellationToken) + protected override async Task InitControllers(Action callBeforeRecurse, Task chatTask, DualReattachInformation reattachInfo, CancellationToken cancellationToken) { Debug.Assert(alphaServer == null && bravoServer == null, "Entered LaunchNoLock with one or more of the servers not being null!"); @@ -577,8 +578,8 @@ namespace Tgstation.Server.Host.Components.Watchdog protected override ISessionController GetActiveController() => AlphaIsActive ? alphaServer : bravoServer; /// - protected override WatchdogReattachInformation CreateReattachInformation() - => new WatchdogReattachInformation + protected override DualReattachInformation CreateReattachInformation() + => new DualReattachInformation { AlphaIsActive = AlphaIsActive, Alpha = alphaServer?.Release(), diff --git a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs index bd9c175e95..0f86a510f5 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs @@ -3,6 +3,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; +using Tgstation.Server.Host.Components.Session; namespace Tgstation.Server.Host.Components.Watchdog { @@ -37,7 +38,7 @@ namespace Tgstation.Server.Host.Components.Watchdog DreamDaemonLaunchParameters LastLaunchParameters { get; } /// - /// The of the active server + /// The of the active server /// RebootState? RebootState { get; } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs index 956eaa9e03..4734c17f85 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs @@ -1,6 +1,7 @@ using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components.Watchdog diff --git a/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs b/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs index 60d15c8ded..a312a6a1c4 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Tgstation.Server.Host.Components.Session; namespace Tgstation.Server.Host.Components.Watchdog { diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs index 0cdc6483af..4eb7263aa5 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs @@ -12,6 +12,7 @@ using Tgstation.Server.Api.Rights; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; using Tgstation.Server.Host.Components.Interop.Topic; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Extensions; @@ -104,14 +105,14 @@ namespace Tgstation.Server.Host.Components.Watchdog readonly IRestartRegistration restartRegistration; /// - /// If the should in + /// If the should in /// readonly bool autoStart; /// /// Used when detaching servers. /// - WatchdogReattachInformation releasedReattachInformation; + DualReattachInformation releasedReattachInformation; /// /// The for the monitor loop @@ -232,7 +233,7 @@ namespace Tgstation.Server.Host.Components.Watchdog var toKill = GetActiveController(); if (toKill != null) { - await toKill.SetRebootState(Watchdog.RebootState.Shutdown, cancellationToken).ConfigureAwait(false); + await toKill.SetRebootState(Session.RebootState.Shutdown, cancellationToken).ConfigureAwait(false); Logger.LogTrace("Graceful termination requested"); } else @@ -250,7 +251,7 @@ namespace Tgstation.Server.Host.Components.Watchdog Logger.LogTrace("Sending heartbeat to active server..."); var response = await activeServer.SendCommand(new TopicParameters(), cancellationToken).ConfigureAwait(false); - var shouldShutdown = activeServer.RebootState == Watchdog.RebootState.Shutdown; + var shouldShutdown = activeServer.RebootState == Session.RebootState.Shutdown; if (response == null) { switch (++heartbeatsMissed) @@ -296,10 +297,10 @@ namespace Tgstation.Server.Host.Components.Watchdog /// /// If should be started by this function /// If the launch should be announced to chat by this function - /// to use, if any + /// to use, if any /// The for the operation /// A representing the running operation - protected async Task LaunchImplNoLock(bool startMonitor, bool announce, WatchdogReattachInformation reattachInfo, CancellationToken cancellationToken) + protected async Task LaunchImplNoLock(bool startMonitor, bool announce, DualReattachInformation reattachInfo, CancellationToken cancellationToken) { Logger.LogTrace("Begin LaunchImplNoLock"); @@ -394,7 +395,7 @@ namespace Tgstation.Server.Host.Components.Watchdog } /// - /// Send a chat message and log about a failed reattach operation and attempts another call to . + /// Send a chat message and log about a failed reattach operation and attempts another call to . /// /// If the inactive server was reattached successfully. /// The for the operation/ @@ -445,10 +446,10 @@ namespace Tgstation.Server.Host.Components.Watchdog protected abstract ISessionController GetActiveController(); /// - /// Create the for the s. + /// Create the for the s. /// - /// A new . - protected abstract WatchdogReattachInformation CreateReattachInformation(); + /// A new . + protected abstract DualReattachInformation CreateReattachInformation(); /// /// Gets the tasks for the following s: , , , , . @@ -677,12 +678,12 @@ namespace Tgstation.Server.Host.Components.Watchdog /// /// Starts all s. /// - /// An that must be run before making a recursive call to . + /// An that must be run before making a recursive call to . /// A, possibly active, for an outgoing chat message. - /// to use, if any + /// to use, if any /// The for the operation /// A representing the running operation - protected abstract Task InitControllers(Action callBeforeRecurse, Task chatTask, WatchdogReattachInformation reattachInfo, CancellationToken cancellationToken); + protected abstract Task InitControllers(Action callBeforeRecurse, Task chatTask, DualReattachInformation reattachInfo, CancellationToken cancellationToken); /// public async Task ChangeSettings(DreamDaemonLaunchParameters launchParameters, CancellationToken cancellationToken) @@ -787,7 +788,7 @@ namespace Tgstation.Server.Host.Components.Watchdog return; var toClear = GetActiveController(); if (toClear != null) - await toClear.SetRebootState(Watchdog.RebootState.Normal, cancellationToken).ConfigureAwait(false); + await toClear.SetRebootState(Session.RebootState.Normal, cancellationToken).ConfigureAwait(false); } } @@ -814,7 +815,7 @@ namespace Tgstation.Server.Host.Components.Watchdog var toReboot = GetActiveController(); if (toReboot != null) { - if (!await toReboot.SetRebootState(Watchdog.RebootState.Restart, cancellationToken).ConfigureAwait(false)) + if (!await toReboot.SetRebootState(Session.RebootState.Restart, cancellationToken).ConfigureAwait(false)) Logger.LogWarning("Unable to send reboot state change event!"); } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs index 1c290c4573..7f5f08e88e 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs @@ -4,6 +4,7 @@ using System; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs index b191159c20..895347f4a6 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.IO; diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs index db6048177c..2d8273386d 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs @@ -4,6 +4,7 @@ using System; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index e81bd43032..80890b721c 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -12,7 +12,7 @@ using Tgstation.Server.Api; using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Rights; using Tgstation.Server.Host.Components; -using Tgstation.Server.Host.Components.Watchdog; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Jobs; using Tgstation.Server.Host.Models; diff --git a/src/Tgstation.Server.Host/Database/DatabaseContext.cs b/src/Tgstation.Server.Host/Database/DatabaseContext.cs index fe296f825a..0fbf07f722 100644 --- a/src/Tgstation.Server.Host/Database/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Database/DatabaseContext.cs @@ -83,9 +83,9 @@ namespace Tgstation.Server.Host.Database public DbSet ReattachInformations { get; set; } /// - /// The s in the . + /// The s in the . /// - public DbSet WatchdogReattachInformations { get; set; } + public DbSet WatchdogReattachInformations { get; set; } /// /// The s in the @@ -144,7 +144,7 @@ namespace Tgstation.Server.Host.Database IDatabaseCollection IDatabaseContext.ReattachInformations => reattachInformationsCollection; /// - IDatabaseCollection IDatabaseContext.WatchdogReattachInformations => watchdogReattachInformationsCollection; + IDatabaseCollection IDatabaseContext.WatchdogReattachInformations => watchdogReattachInformationsCollection; /// /// The for the @@ -214,7 +214,7 @@ namespace Tgstation.Server.Host.Database /// /// Backing field for . /// - readonly IDatabaseCollection watchdogReattachInformationsCollection; + readonly IDatabaseCollection watchdogReattachInformationsCollection; /// /// Construct a @@ -241,7 +241,7 @@ namespace Tgstation.Server.Host.Database revisionInformationsCollection = new DatabaseCollection(RevisionInformations); jobsCollection = new DatabaseCollection(Jobs); reattachInformationsCollection = new DatabaseCollection(ReattachInformations); - watchdogReattachInformationsCollection = new DatabaseCollection(WatchdogReattachInformations); + watchdogReattachInformationsCollection = new DatabaseCollection(WatchdogReattachInformations); } /// diff --git a/src/Tgstation.Server.Host/Database/IDatabaseContext.cs b/src/Tgstation.Server.Host/Database/IDatabaseContext.cs index 4b890df722..162e978a74 100644 --- a/src/Tgstation.Server.Host/Database/IDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Database/IDatabaseContext.cs @@ -78,9 +78,9 @@ namespace Tgstation.Server.Host.Database IDatabaseCollection ReattachInformations { get; } /// - /// The for s + /// The for s /// - IDatabaseCollection WatchdogReattachInformations { get; } + IDatabaseCollection WatchdogReattachInformations { get; } /// /// Saves changes made to the diff --git a/src/Tgstation.Server.Host/Models/WatchdogReattachInformation.cs b/src/Tgstation.Server.Host/Models/DualReattachInformation.cs similarity index 78% rename from src/Tgstation.Server.Host/Models/WatchdogReattachInformation.cs rename to src/Tgstation.Server.Host/Models/DualReattachInformation.cs index a282277d98..763e5d10a3 100644 --- a/src/Tgstation.Server.Host/Models/WatchdogReattachInformation.cs +++ b/src/Tgstation.Server.Host/Models/DualReattachInformation.cs @@ -1,9 +1,9 @@ namespace Tgstation.Server.Host.Models { /// - /// Database representation of + /// Database representation of /// - public sealed class WatchdogReattachInformation : WatchdogReattachInformationBase + public sealed class DualReattachInformation : DualReattachInformationBase { /// /// The row Id @@ -11,7 +11,7 @@ public long Id { get; set; } /// - /// The of the the belongs to + /// The of the the belongs to /// public long InstanceId { get; set; } diff --git a/src/Tgstation.Server.Host/Models/DualReattachInformationBase.cs b/src/Tgstation.Server.Host/Models/DualReattachInformationBase.cs new file mode 100644 index 0000000000..9e61fe1d83 --- /dev/null +++ b/src/Tgstation.Server.Host/Models/DualReattachInformationBase.cs @@ -0,0 +1,29 @@ +using System; + +namespace Tgstation.Server.Host.Models +{ + /// + /// Base class for + /// + public abstract class DualReattachInformationBase + { + /// + /// If the Alpha session is the active session + /// + public bool AlphaIsActive { get; set; } + + /// + /// Construct a + /// + public DualReattachInformationBase() { } + + /// + /// Construct a from a given + /// + /// The to copy values from + protected DualReattachInformationBase(DualReattachInformationBase copy) + { + AlphaIsActive = copy?.AlphaIsActive ?? throw new ArgumentNullException(nameof(copy)); + } + } +} diff --git a/src/Tgstation.Server.Host/Models/Instance.cs b/src/Tgstation.Server.Host/Models/Instance.cs index 19a54970d8..c272b00324 100644 --- a/src/Tgstation.Server.Host/Models/Instance.cs +++ b/src/Tgstation.Server.Host/Models/Instance.cs @@ -28,9 +28,9 @@ namespace Tgstation.Server.Host.Models public RepositorySettings RepositorySettings { get; set; } /// - /// The for the + /// The for the /// - public WatchdogReattachInformation WatchdogReattachInformation { get; set; } + public DualReattachInformation WatchdogReattachInformation { get; set; } /// /// The s in the diff --git a/src/Tgstation.Server.Host/Models/ReattachInformation.cs b/src/Tgstation.Server.Host/Models/ReattachInformation.cs index d2fdda3374..42895bc480 100644 --- a/src/Tgstation.Server.Host/Models/ReattachInformation.cs +++ b/src/Tgstation.Server.Host/Models/ReattachInformation.cs @@ -3,7 +3,7 @@ namespace Tgstation.Server.Host.Models { /// - /// Database representation of + /// Database representation of /// public sealed class ReattachInformation : ReattachInformationBase { @@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Models public long Id { get; set; } /// - /// The for the + /// The for the /// [Required] public CompileJob CompileJob { get; set; } diff --git a/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs b/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs index e64976596a..6fab1d26c0 100644 --- a/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs +++ b/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using Tgstation.Server.Api.Models; using Tgstation.Server.Host.Components.Interop; -using Tgstation.Server.Host.Components.Watchdog; +using Tgstation.Server.Host.Components.Session; namespace Tgstation.Server.Host.Models { diff --git a/src/Tgstation.Server.Host/Models/WatchdogReattachInformationBase.cs b/src/Tgstation.Server.Host/Models/WatchdogReattachInformationBase.cs deleted file mode 100644 index 8cfa201257..0000000000 --- a/src/Tgstation.Server.Host/Models/WatchdogReattachInformationBase.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; - -namespace Tgstation.Server.Host.Models -{ - /// - /// Base class for - /// - public abstract class WatchdogReattachInformationBase - { - /// - /// If the Alpha session is the active session - /// - public bool AlphaIsActive { get; set; } - - /// - /// Construct a - /// - public WatchdogReattachInformationBase() { } - - /// - /// Construct a from a given - /// - /// The to copy values from - protected WatchdogReattachInformationBase(WatchdogReattachInformationBase copy) - { - AlphaIsActive = copy?.AlphaIsActive ?? throw new ArgumentNullException(nameof(copy)); - } - } -} diff --git a/tests/Tgstation.Server.Host.Tests/Components/Watchdog/TestExperimentalWatchdog.cs b/tests/Tgstation.Server.Host.Tests/Components/Watchdog/TestExperimentalWatchdog.cs index 45e726fc87..5a0022c10a 100644 --- a/tests/Tgstation.Server.Host.Tests/Components/Watchdog/TestExperimentalWatchdog.cs +++ b/tests/Tgstation.Server.Host.Tests/Components/Watchdog/TestExperimentalWatchdog.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.IO;