Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to capture logs from Plebian and log them in Monarch #114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/fiskaltrust.Launcher/Commands/DoctorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public async Task<int> InvokeAsync(InvocationContext context)

await CheckAwait("Start monarch WebApplication", async () => await WithTimeout(async () => await monarchApp.StartAsync(_lifetime.ApplicationLifetime.ApplicationStopping), TimeSpan.FromSeconds(5)), throws: true);

var plebianConfiguration = new PlebianConfiguration
var plebeianConfiguration = new PlebeianConfiguration
{
PackageId = doctorId,
PackageType = Constants.PackageType.Queue
Expand All @@ -167,24 +167,24 @@ public async Task<int> InvokeAsync(InvocationContext context)
var packageConfiguration = new PackageConfiguration
{
Configuration = new(),
Id = plebianConfiguration.PackageId,
Id = plebeianConfiguration.PackageId,
Package = "none",
Url = Array.Empty<string>(),
Version = "1.0.0"
};

IProcessHostService? processHostService = Check("Start plebian processhostservice client", () => GrpcChannel.ForAddress($"http://localhost:{launcherConfiguration.LauncherPort}").CreateGrpcService<IProcessHostService>());
IProcessHostService? processHostService = Check("Start plebeian processhostservice client", () => GrpcChannel.ForAddress($"http://localhost:{launcherConfiguration.LauncherPort}").CreateGrpcService<IProcessHostService>());

var plebianBuilder = Host.CreateDefaultBuilder()
var plebeianBuilder = Host.CreateDefaultBuilder()
.UseSerilog(new LoggerConfiguration().CreateLogger())
.ConfigureServices(services =>
{
Check("Setup plebian services", () =>
Check("Setup plebeian services", () =>
{
services.Configure<HostOptions>(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30));
services.AddSingleton(_ => launcherConfiguration);
services.AddSingleton(_ => packageConfiguration);
services.AddSingleton(_ => plebianConfiguration);
services.AddSingleton(_ => plebeianConfiguration);

var pluginLoader = new PluginLoader();
services.AddSingleton(_ => pluginLoader);
Expand All @@ -195,7 +195,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
}

services.AddSingleton<HostingService>();
services.AddHostedService<ProcessHostPlebian>();
services.AddHostedService<ProcessHostPlebeian>();

services.AddSingleton<IClientFactory<IDESSCD>, DESSCDClientFactory>();
services.AddSingleton<IClientFactory<IPOS>, POSClientFactory>();
Expand All @@ -212,9 +212,9 @@ public async Task<int> InvokeAsync(InvocationContext context)
}, throws: true);
});

var plebianApp = Check("Build plebian Host", plebianBuilder.Build, throws: true)!;
var plebeianApp = Check("Build plebeian Host", plebeianBuilder.Build, throws: true)!;

await CheckAwait("Start plebian Host", async () => await WithTimeout(async () => await plebianApp.StartAsync(_lifetime.ApplicationLifetime.ApplicationStopping), TimeSpan.FromSeconds(5)));
await CheckAwait("Start plebeian Host", async () => await WithTimeout(async () => await plebeianApp.StartAsync(_lifetime.ApplicationLifetime.ApplicationStopping), TimeSpan.FromSeconds(5)));

await doctorProcessHostMonarch.IsStarted.Task;

Expand All @@ -225,8 +225,8 @@ await CheckAwait("Shutdown launcher gracefully", async () => await WithTimeout(a
await monarchApp.StopAsync();
await monarchApp.WaitForShutdownAsync();

await plebianApp.StopAsync();
await plebianApp.WaitForShutdownAsync();
await plebeianApp.StopAsync();
await plebeianApp.WaitForShutdownAsync();
}, TimeSpan.FromSeconds(5))
);
}
Expand Down Expand Up @@ -353,15 +353,17 @@ public Task Start(CancellationToken cancellationToken)
return Task.CompletedTask;
}

public void Started()
public void SetPlebeanStarted()
{
IsStarted.SetResult();
}

public Task Stopped()
public Task GetStopped()
{
return Task.CompletedTask;
}

public void SetStartupCompleted() { }
}

public class DoctorMiddlewareBootstrapper : IMiddlewareBootstrapper
Expand Down
22 changes: 13 additions & 9 deletions src/fiskaltrust.Launcher/Commands/HostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HostCommand : Command
{
public HostCommand() : base("host")
{
AddOption(new Option<string>("--plebian-configuration"));
AddOption(new Option<string>("--plebeian-configuration"));
AddOption(new Option<string>("--debugging"));
AddOption(new Option<string>("--launcher-configuration"));
AddOption(new Option<bool>("--no-process-host-service", getDefaultValue: () => false));
Expand All @@ -38,7 +38,7 @@ public HostCommand() : base("host")
public class HostCommandHandler : ICommandHandler
{
public string LauncherConfiguration { get; set; } = null!;
public string PlebianConfiguration { get; set; } = null!;
public string PlebeianConfiguration { get; set; } = null!;
public bool NoProcessHostService { get; set; }
public bool Debugging { get; set; }

Expand All @@ -63,19 +63,19 @@ public async Task<int> InvokeAsync(InvocationContext context)

var launcherConfiguration = Common.Configuration.LauncherConfiguration.Deserialize(System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(LauncherConfiguration)));

var plebianConfiguration = Configuration.PlebianConfiguration.Deserialize(System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(PlebianConfiguration)));
var plebeianConfiguration = Configuration.PlebeianConfiguration.Deserialize(System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(PlebeianConfiguration)));

var cashboxConfiguration = CashBoxConfigurationExt.Deserialize(await File.ReadAllTextAsync(launcherConfiguration.CashboxConfigurationFile!));

cashboxConfiguration.Decrypt(launcherConfiguration, await CommonCommandHandler.LoadCurve(launcherConfiguration.AccessToken!, launcherConfiguration.UseLegacyDataProtection!.Value));

var packageConfiguration = (plebianConfiguration.PackageType switch
var packageConfiguration = (plebeianConfiguration.PackageType switch
{
PackageType.Queue => cashboxConfiguration.ftQueues,
PackageType.SCU => cashboxConfiguration.ftSignaturCreationDevices,
PackageType.Helper => cashboxConfiguration.helpers,
var unknown => throw new Exception($"Unknown PackageType {unknown}")
}).First(p => p.Id == plebianConfiguration.PackageId);
}).First(p => p.Id == plebeianConfiguration.PackageId);

packageConfiguration.Configuration = ProcessPackageConfiguration(packageConfiguration.Configuration, launcherConfiguration, cashboxConfiguration);

Expand All @@ -96,10 +96,14 @@ public async Task<int> InvokeAsync(InvocationContext context)
.UseSerilog()
.ConfigureServices(services =>
{
services.Configure<HostOptions>(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30));
services.Configure<HostOptions>(opts =>
{
opts.ShutdownTimeout = TimeSpan.FromSeconds(30);
opts.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.StopHost;
});
services.AddSingleton(_ => launcherConfiguration);
services.AddSingleton(_ => packageConfiguration);
services.AddSingleton(_ => plebianConfiguration);
services.AddSingleton(_ => plebeianConfiguration);

var pluginLoader = new PluginLoader();
services.AddSingleton(_ => pluginLoader);
Expand All @@ -110,7 +114,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
}

services.AddSingleton<HostingService>();
services.AddHostedService<ProcessHostPlebian>();
services.AddHostedService<ProcessHostPlebeian>();

services.AddSingleton<IClientFactory<IDESSCD>, DESSCDClientFactory>();
services.AddSingleton<IClientFactory<IITSSCD>, ITSSCDClientFactory>();
Expand Down Expand Up @@ -162,7 +166,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
catch (Exception e)
{
Log.Error(e, "An unhandled exception occured.");
return 1;
throw;
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace fiskaltrust.Launcher.Configuration
{
public record PlebianConfiguration
public record PlebeianConfiguration
{
public PackageType PackageType { get; set; }
public Guid PackageId { get; set; }

public static PlebianConfiguration Deserialize(string text) => JsonSerializer.Deserialize(text, typeof(PlebianConfiguration), Helpers.Serialization.SerializerContext.Default) as PlebianConfiguration ?? throw new Exception($"Could not deserialize {nameof(PlebianConfiguration)}");
public static PlebeianConfiguration Deserialize(string text) => JsonSerializer.Deserialize(text, typeof(PlebeianConfiguration), Helpers.Serialization.SerializerContext.Default) as PlebeianConfiguration ?? throw new Exception($"Could not deserialize {nameof(PlebeianConfiguration)}");

public string Serialize() => JsonSerializer.Serialize(this, typeof(PlebianConfiguration), Helpers.Serialization.SerializerContext.Default);
public string Serialize() => JsonSerializer.Serialize(this, typeof(PlebeianConfiguration), Helpers.Serialization.SerializerContext.Default);
}
}
2 changes: 1 addition & 1 deletion src/fiskaltrust.Launcher/Helpers/SerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace fiskaltrust.Launcher.Helpers.Serialization
{
[JsonSerializable(typeof(PlebianConfiguration))]
[JsonSerializable(typeof(PlebeianConfiguration))]
public partial class SerializerContext : JsonSerializerContext { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,23 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
await new TaskCompletionSource().Task;
}

foreach (var host in _hosts)
{
host.Value.SetStartupCompleted();
}

try
{
await Task.WhenAll(_hosts.Select(h => h.Value.Stopped()));
await Task.WhenAll(_hosts.Select(h => h.Value.GetStopped()));
}
catch
{
foreach (var failed in _hosts.Where(h => !h.Value.Stopped().IsCompletedSuccessfully).Select(h => (h.Key, h.Value.Stopped().Exception)))
foreach (var failed in _hosts.Where(h => !h.Value.GetStopped().IsCompletedSuccessfully).Select(h => (h.Key, h.Value.GetStopped().Exception)))
{
_logger.LogWarning(failed.Exception, "ProcessHost {Id} had crashed.", failed.Key);
}
}
_lifetime.ApplicationLifetime.StopApplication();
}

private async Task StartProcessHostMonarch(PackageConfiguration configuration, PackageType packageType, CancellationToken cancellationToken)
Expand Down
Loading
Loading