Cleaned up interfaces. Extracted server state machine trigger handler to seperated classes. Removed legacy code
This commit is contained in:
72
MoonlightServers.Daemon/ServerSystem/Interfaces/IConsole.cs
Normal file
72
MoonlightServers.Daemon/ServerSystem/Interfaces/IConsole.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IConsole : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes to the standard input of the console. If attached to the runtime when using docker for example this
|
||||
/// would write into the containers standard input.
|
||||
/// <remarks>This method does not add a newline separator at the end of the content. The caller needs to add this themselves if required</remarks>
|
||||
/// </summary>
|
||||
/// <param name="content">The content to write</param>
|
||||
/// <returns></returns>
|
||||
public Task WriteStdInAsync(string content);
|
||||
/// <summary>
|
||||
/// Writes to the standard output of the console. If attached to the runtime when using docker for example this
|
||||
/// would write into the containers standard output.
|
||||
/// <remarks>This method does not add a newline separator at the end of the content. The caller needs to add this themselves if required</remarks>
|
||||
/// </summary>
|
||||
/// <param name="content">The content to write</param>
|
||||
/// <returns></returns>
|
||||
public Task WriteStdOutAsync(string content);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a system message to the standard output with the moonlight console prefix
|
||||
/// <remarks>This method *does* add the newline separator at the end</remarks>
|
||||
/// </summary>
|
||||
/// <param name="content">The content to write into the standard output</param>
|
||||
/// <returns></returns>
|
||||
public Task WriteMoonlightAsync(string content);
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the console to the runtime environment
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task AttachRuntimeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the console to the installation environment
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task AttachInstallationAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all output from the runtime environment and write them into the cache without triggering any events
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task FetchRuntimeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all output from the installation environment and write them into the cache without triggering any events
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task FetchInstallationAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Clears the cache of the standard output received by the environments
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task ClearCacheAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content from the standard output cache
|
||||
/// </summary>
|
||||
/// <returns>The content from the cache</returns>
|
||||
public Task<IEnumerable<string>> GetCacheAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes to standard output receive events
|
||||
/// </summary>
|
||||
/// <param name="callback">Callback which will be invoked whenever a new line is received</param>
|
||||
/// <returns>Subscription disposable to unsubscribe from the event</returns>
|
||||
public Task<IAsyncDisposable> SubscribeStdOutAsync(Func<string, Task> callback);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IFileSystem : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the path of the file system on the host operating system to be reused by other components
|
||||
/// </summary>
|
||||
/// <returns>Path to the file systems storage location</returns>
|
||||
public Task<string> GetPathAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the file system exists
|
||||
/// </summary>
|
||||
/// <returns>True if it does exist. False if it doesn't exist</returns>
|
||||
public Task<bool> CheckExistsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the file system is mounted
|
||||
/// </summary>
|
||||
/// <returns>True if its mounted, False if it is not mounted</returns>
|
||||
public Task<bool> CheckMountedAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the file system. E.g. Creating a virtual disk, formatting it
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task CreateAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Performs checks and optimisations on the file system.
|
||||
/// E.g. checking for corrupted files, resizing a virtual disk or adjusting file permissions
|
||||
/// <remarks>Requires <see cref="MountAsync"/> to be called before or the file system to be in a mounted state</remarks>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task PerformChecksAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Mounts the file system
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task MountAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Unmounts the file system
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task UnmountAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the file system and its contents
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task DestroyAsync();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IInstallation : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the installation environment exists. It doesn't matter if it is currently running or not
|
||||
/// </summary>
|
||||
/// <returns>True if it exists, False if it doesn't</returns>
|
||||
public Task<bool> CheckExistsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the installation environment
|
||||
/// </summary>
|
||||
/// <param name="runtimePath">The host path of the runtime storage location</param>
|
||||
/// <param name="hostPath">The host path of the installation file system</param>
|
||||
/// <returns></returns>
|
||||
public Task CreateAsync(string runtimePath, string hostPath);
|
||||
|
||||
/// <summary>
|
||||
/// Starts the installation
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task StartAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Kills the current installation immediately
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task KillAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Removes the installation. E.g. removes the docker container
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task DestroyAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes to the event when the installation exists
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback to invoke whenever the installation exists</param>
|
||||
/// <returns>Subscription disposable to unsubscribe from the event</returns>
|
||||
public Task<IAsyncDisposable> SubscribeExited(Func<int, Task> callback);
|
||||
|
||||
/// <summary>
|
||||
/// Connects an existing installation to this abstraction in order to restore it.
|
||||
/// E.g. fetching the container id and using it for exit events
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task RestoreAsync();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IOnlineDetector : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the detection engine for the online state
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task CreateAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Handles the detection of the online state based on the received output
|
||||
/// </summary>
|
||||
/// <param name="line">The excerpt of the output</param>
|
||||
/// <returns>True if the detection showed that the server is online. False if the detection didnt find anything</returns>
|
||||
public Task<bool> HandleOutputAsync(string line);
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the detection engine for the online state
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task DestroyAsync();
|
||||
}
|
||||
18
MoonlightServers.Daemon/ServerSystem/Interfaces/IReporter.cs
Normal file
18
MoonlightServers.Daemon/ServerSystem/Interfaces/IReporter.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IReporter : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes both in the server logs as well in the server console the provided message as a status update
|
||||
/// </summary>
|
||||
/// <param name="message">The message to write</param>
|
||||
/// <returns></returns>
|
||||
public Task StatusAsync(string message);
|
||||
|
||||
/// <summary>
|
||||
/// Writes both in the server logs as well in the server console the provided message as an error
|
||||
/// </summary>
|
||||
/// <param name="message">The message to write</param>
|
||||
/// <returns></returns>
|
||||
public Task ErrorAsync(string message);
|
||||
}
|
||||
16
MoonlightServers.Daemon/ServerSystem/Interfaces/IRestorer.cs
Normal file
16
MoonlightServers.Daemon/ServerSystem/Interfaces/IRestorer.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IRestorer : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks for any running runtime environment from which the state can be restored from
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> HandleRuntimeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Checks for any running installation environment from which the state can be restored from
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> HandleInstallationAsync();
|
||||
}
|
||||
55
MoonlightServers.Daemon/ServerSystem/Interfaces/IRuntime.cs
Normal file
55
MoonlightServers.Daemon/ServerSystem/Interfaces/IRuntime.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IRuntime : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the runtime does exist. This includes already running instances
|
||||
/// </summary>
|
||||
/// <returns>True if it exists, False if it doesn't</returns>
|
||||
public Task<bool> CheckExistsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the runtime with the specified path as the storage path where the server files should be stored in
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public Task CreateAsync(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Starts the runtime. This requires <see cref="CreateAsync"/> to be called before this function
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task StartAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Performs a live update on the runtime. When this method is called the current server configuration has already been updated
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task UpdateAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Kills the current runtime immediately
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task KillAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the runtime. When implemented using docker this would remove the container used for hosting the runtime
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task DestroyAsync();
|
||||
|
||||
/// <summary>
|
||||
/// This subscribes to the exited event of the runtime
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback gets invoked whenever the runtime exites</param>
|
||||
/// <returns>Subscription disposable to unsubscribe from the event</returns>
|
||||
public Task<IAsyncDisposable> SubscribeExited(Func<int, Task> callback);
|
||||
|
||||
/// <summary>
|
||||
/// Connects an existing runtime to this abstraction in order to restore it.
|
||||
/// E.g. fetching the container id and using it for exit events
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task RestoreAsync();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IServerComponent : IAsyncDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the server component
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task InitializeAsync();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MoonlightServers.Daemon.ServerSystem.Enums;
|
||||
using Stateless;
|
||||
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IServerStateHandler : IAsyncDisposable
|
||||
{
|
||||
public Task ExecuteAsync(StateMachine<ServerState, ServerTrigger>.Transition transition);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using MoonlightServers.Daemon.ServerSystem.Models;
|
||||
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Interfaces;
|
||||
|
||||
public interface IStatistics : IServerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Attaches the statistics collector to the currently running runtime
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task AttachRuntimeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the statistics collector to the currently running installation
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task AttachInstallationAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Clears the statistics cache
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task ClearCacheAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the statistics data from the cache
|
||||
/// </summary>
|
||||
/// <returns>All data from the cache</returns>
|
||||
public Task<IEnumerable<StatisticsData>> GetCacheAsync();
|
||||
}
|
||||
Reference in New Issue
Block a user