From c1060816fe71d15c92f881d12c7b7cf034d8bc31 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 30 Apr 2023 18:44:00 -0400 Subject: [PATCH 1/2] Move NativeMethods to System namespace --- src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs | 1 + .../Security/WindowsSystemIdentityFactory.cs | 1 + src/Tgstation.Server.Host/{ => System}/NativeMethods.cs | 2 +- src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) rename src/Tgstation.Server.Host/{ => System}/NativeMethods.cs (99%) diff --git a/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs b/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs index ae3a261c3d..2beddb0581 100644 --- a/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs +++ b/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using BetterWin32Errors; +using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.IO { diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs index 78f74eb434..3646d71cd1 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs @@ -10,6 +10,7 @@ using Microsoft.Win32.SafeHandles; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Models; +using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Security { diff --git a/src/Tgstation.Server.Host/NativeMethods.cs b/src/Tgstation.Server.Host/System/NativeMethods.cs similarity index 99% rename from src/Tgstation.Server.Host/NativeMethods.cs rename to src/Tgstation.Server.Host/System/NativeMethods.cs index 10d415f3de..60b97ca90c 100644 --- a/src/Tgstation.Server.Host/NativeMethods.cs +++ b/src/Tgstation.Server.Host/System/NativeMethods.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices; using System.Text; -namespace Tgstation.Server.Host +namespace Tgstation.Server.Host.System { /// /// Native Windows methods used by the code. diff --git a/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs b/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs index 5c635dd1ae..11aafe319c 100644 --- a/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs +++ b/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs @@ -13,6 +13,7 @@ using Microsoft.Extensions.Logging; using Tgstation.Server.Api.Models; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; +using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.System { From 2424de4c992cccb1377caea9eeeac79530830e06 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 30 Apr 2023 18:57:05 -0400 Subject: [PATCH 2/2] Cleaned up READMEs somewhat --- src/Tgstation.Server.Host/Components/README.md | 4 +--- src/Tgstation.Server.Host/Core/README.md | 13 +++++-------- src/Tgstation.Server.Host/README.md | 4 +++- src/Tgstation.Server.Host/Utils/README.md | 9 +++++++++ 4 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 src/Tgstation.Server.Host/Utils/README.md diff --git a/src/Tgstation.Server.Host/Components/README.md b/src/Tgstation.Server.Host/Components/README.md index b916892356..e13f2a3dfb 100644 --- a/src/Tgstation.Server.Host/Components/README.md +++ b/src/Tgstation.Server.Host/Components/README.md @@ -18,8 +18,6 @@ Each of these is tied under the roof of an [IInstance](./IInstance.cs) ([impleme While the database represents stored instance data, in component code an instance is online, or doesn't exist. -`IInstance`s are created via the [IInstanceFactory](./IInstanceFactory.cs) ([implementation](./InstanceFactory.cs)) and are generally controlled via the [IInstanceManager](./IInstanceManager.cs) ([implementation](./InstanceManager.cs)). +`IInstance`s ([implementation](./Instance.cs)) are created via the [IInstanceFactory](./IInstanceFactory.cs) ([implementation](./InstanceFactory.cs)) and are generally controlled via the [IInstanceOperations](./IInstanceOperations.cs) interface (implemented in the `InstanceManager`). Many classes in here implement [IHostedService](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-6.0&tabs=visual-studio), `InstanceManager` being the only one that is called by the ASP.NET runtime. In the case of instances `StartAsync()` is called when an `Instance` is being brought online (from server startup or user request). The `Instance` handles calling `StartAsync()` on its various subcomponents that need it. When an `Instance` is being brought offline (from server shutdown/restart/update or user request) the same pattern is followed calling `StopAsync()`. - -`IInstanceManager` is the sole point where the controllers talk to component code. It also dispatches bridge requests to their relevant instances. diff --git a/src/Tgstation.Server.Host/Core/README.md b/src/Tgstation.Server.Host/Core/README.md index b19f4b0a8f..ac19d11df1 100644 --- a/src/Tgstation.Server.Host/Core/README.md +++ b/src/Tgstation.Server.Host/Core/README.md @@ -1,13 +1,10 @@ # Core Services -This is a bag of classes used throughout TGS that don't quite belong anywhere else. - - [Application](./Application.cs) is our main [composition root](https://freecontent.manning.com/dependency-injection-in-net-2nd-edition-understanding-the-composition-root/). -- [IAsyncDelayer](./IAsyncDelayer.cs) and [implementation](./AsyncDelayer.cs) is a class used to sleep code. It's generally a no-op in test scenarios. -- [IGitHubClientFactory](./IGitHubClientFactory.cs) and [implementation](./GitHubClientFactory.cs) is a class used to create GitHub API clients using [ocktokit.net](https://github.com/octokit/octokit.net). - [IRestartHandler](./IRestartHandler.cs) and [IRestartRegistration](./IRestartRegistration.cs) are a set of interface services use when they want to be aware of a TGS restart/update (i.e. This is how the watchdog know to detach instead of shutdown). -- [IServerControl](./IServerControl.cs) is an interface used to initiate a restart or update the server. +- [IServerControl](./IServerControl.cs) is an interface used to initiate a restart, shutdown, or update the server. - [IServerPortProvider](./IServerPortProvider.cs) and [implementation](./ServerPortProvider.cs) is used by services to determine the local TGS API port. Used mainly for telling DreamDaemon where to make bridge requests. -- [OpenApiEnumVarNamesExtension](./OpenApiEnumVarNamesExtension) implements the [x-var-names OpenAPI 3.0 extension](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/templating.md#enum) in our generated API json. -- [SemaphoreSlimContext](./SemaphoreSlimContext.cs) is a helper class for working with [.NET asynchronous sempahores](https://docs.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim?view=netcore-6.0). -- [SwaggerConfiguration](./SwaggerConfiguration.cs) configures [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) to generate our OpenAPI specification. +- [IServerUpdater](./IServerUpdater.cs), [IServerUpdateExecutor](./IServerUpdateExecutor.cs) and their implementation [implementation](./ServerUpdater.cs) handles the process of downloading and unzipping update packages while respecting the Swarm protocol. +- [IServerUpdateInitiator](./IServerUpdateInitiator.cs) and [implementation](./ServerUpdateInitiator.cs) handles bridging the gap between the Controllers and the update process. +- [ServerUpdateOperation](./ServerUpdateOperation.cs) is a utility struct used by the update process. +- [ServerUpdateResult](./ServerUpdateOperation.cs) is an enumeration that indicates the result of trying to start an update operation. diff --git a/src/Tgstation.Server.Host/README.md b/src/Tgstation.Server.Host/README.md index 8730677035..ccb01971a6 100644 --- a/src/Tgstation.Server.Host/README.md +++ b/src/Tgstation.Server.Host/README.md @@ -27,7 +27,7 @@ Here's a breakdown of things in this directory - [Components](./Components) is where the bulk of the TGS implementation lives. - [Configuration](./Configuration) contains classes that partly make up the configuration yaml files (i.e. [appsettings.yml](./appsettings.yml)). - [Controllers](./Controllers) is where HTTP API code lives and bridges it with component code. -- [Core](./Core) contains [Application.cs](./Core/Application.cs) and other various helpers that don't belong anywhere else. +- [Core](./Core) contains [Application.cs](./Core/Application.cs) and other classes related to the overrarching server process. - [Database](./Database) contains all database related code. - [Extensions](./Extensions) contains helper functions implemented as C# extension methods. - [IO](./IO) contains classes related to interacting with the filesystem. @@ -36,6 +36,8 @@ Here's a breakdown of things in this directory - [Properties](./Properties) contains some assembly metadata, mainly used to expose internals to the testing suite. - [Security](./Security) contains all the security related classes. - [Setup](./Setup) contains code to initiate and run the setup wizard. +- [Swarm](./Swarm) contains code relating to grouping multiple TGS processes on different machines in a cohesive cluster. - [System](./System) contains various OS related functions. +- [Utils](./Utils) contains various helpers that don't belong anywhere else. As a final note, all project configuration is of course in the [Tgstation.Server.Host.csproj](./Tgstation.Server.Host.csproj) file. This contains package references that are pulled in on build, as well as other things like global warning supressions, and specialized build scripts. diff --git a/src/Tgstation.Server.Host/Utils/README.md b/src/Tgstation.Server.Host/Utils/README.md new file mode 100644 index 0000000000..bad6a54616 --- /dev/null +++ b/src/Tgstation.Server.Host/Utils/README.md @@ -0,0 +1,9 @@ +# Util classes + +This is a bag of classes used throughout TGS that don't quite belong anywhere else. + +- [IAsyncDelayer](./IAsyncDelayer.cs) and [implementation](./AsyncDelayer.cs) is a class used to sleep code. It's generally a no-op in test scenarios. +- [IGitHubClientFactory](./IGitHubClientFactory.cs) and [implementation](./GitHubClientFactory.cs) is a class used to create GitHub API clients using [ocktokit.net](https://github.com/octokit/octokit.net). +- [OpenApiEnumVarNamesExtension](./OpenApiEnumVarNamesExtension) implements the [x-var-names OpenAPI 3.0 extension](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/templating.md#enum) in our generated API json. +- [SemaphoreSlimContext](./SemaphoreSlimContext.cs) is a helper class for working with [.NET asynchronous sempahores](https://docs.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim?view=netcore-6.0). +- [SwaggerConfiguration](./SwaggerConfiguration.cs) configures [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) to generate our OpenAPI specification.