Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align bootstrappers and move things into commands (#3992)
* Align bootstrappers and move things into commands * Namespace cleanup
- Loading branch information
1 parent
f5db181
commit 7c2e3ab
Showing
25 changed files
with
277 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
src/ServiceControl.Audit/Infrastructure/Hosting/Commands/MaintCommand.cs
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
...Infrastructure/MaintenanceBootstrapper.cs → ...osting/Commands/MaintenanceModeCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 83 additions & 1 deletion
84
src/ServiceControl.Audit/Infrastructure/Hosting/Commands/SetupCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,97 @@ | ||
namespace ServiceControl.Audit.Infrastructure.Hosting.Commands | ||
{ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using LicenseManagement; | ||
using NServiceBus.Logging; | ||
using Persistence; | ||
using Settings; | ||
using Transports; | ||
|
||
class SetupCommand : AbstractCommand | ||
{ | ||
public override async Task Execute(HostArguments args, Settings settings) | ||
{ | ||
settings.SkipQueueCreation = args.SkipQueueCreation; | ||
|
||
await new SetupBootstrapper(settings).Run(); | ||
// Validate license: | ||
if (!ValidateLicense(settings)) | ||
{ | ||
return; | ||
} | ||
|
||
var transportSettings = MapSettings(settings); | ||
var transportCustomization = settings.LoadTransportCustomization(); | ||
|
||
if (settings.IngestAuditMessages) | ||
{ | ||
if (settings.SkipQueueCreation) | ||
{ | ||
Logger.Info("Skipping queue creation"); | ||
} | ||
else | ||
{ | ||
var additionalQueues = new List<string> { settings.AuditQueue }; | ||
|
||
if (settings.ForwardAuditMessages && settings.AuditLogQueue != null) | ||
{ | ||
additionalQueues.Add(settings.AuditLogQueue); | ||
} | ||
|
||
await transportCustomization.ProvisionQueues(transportSettings, additionalQueues); | ||
} | ||
} | ||
|
||
EventSource.Create(); | ||
|
||
var persistenceConfiguration = PersistenceConfigurationFactory.LoadPersistenceConfiguration(settings.PersistenceType); | ||
var persistenceSettings = persistenceConfiguration.BuildPersistenceSettings(settings); | ||
var persistence = persistenceConfiguration.Create(persistenceSettings); | ||
var installer = persistence.CreateInstaller(); | ||
|
||
await installer.Install(); | ||
} | ||
|
||
bool ValidateLicense(Settings settings) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(settings.LicenseFileText)) | ||
{ | ||
if (!LicenseManager.IsLicenseValidForServiceControlInit(settings.LicenseFileText, out var errorMessageForLicenseText)) | ||
{ | ||
Logger.Error(errorMessageForLicenseText); | ||
return false; | ||
} | ||
|
||
if (!LicenseManager.TryImportLicenseFromText(settings.LicenseFileText, out var importErrorMessage)) | ||
{ | ||
Logger.Error(importErrorMessage); | ||
return false; | ||
} | ||
} | ||
else | ||
{ | ||
var license = LicenseManager.FindLicense(); | ||
if (!LicenseManager.IsLicenseValidForServiceControlInit(license, out var errorMessageForFoundLicense)) | ||
{ | ||
Logger.Error(errorMessageForFoundLicense); | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
static TransportSettings MapSettings(Settings settings) | ||
{ | ||
var transportSettings = new TransportSettings | ||
{ | ||
EndpointName = settings.ServiceName, | ||
ConnectionString = settings.TransportConnectionString, | ||
MaxConcurrency = settings.MaximumConcurrencyLevel | ||
}; | ||
return transportSettings; | ||
} | ||
|
||
static readonly ILog Logger = LogManager.GetLogger<SetupCommand>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 0 additions & 94 deletions
94
src/ServiceControl.Audit/Infrastructure/SetupBootstrapper.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.