diff --git a/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddAttachment.cs b/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddAttachment.cs index 0a213d826f..5292038143 100644 --- a/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddAttachment.cs +++ b/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddAttachment.cs @@ -51,28 +51,30 @@ async Task Add() viewModel.InProgress = true; - var serviceControlNewInstance = viewModel.InstallErrorInstance ? new ServiceControlNewInstance + var serviceControlNewInstance = viewModel.InstallErrorInstance ? ServiceControlNewInstance.CreateWithDefaultPersistence() : null; + + if (viewModel.InstallAuditInstance) { - DisplayName = viewModel.ServiceControl.InstanceName, - Name = viewModel.ServiceControl.InstanceName.Replace(' ', '.'), - ServiceDescription = viewModel.ServiceControl.Description, - DBPath = viewModel.ServiceControl.DatabasePath, - LogPath = viewModel.ServiceControl.LogPath, - InstallPath = viewModel.ServiceControl.DestinationPath, - HostName = viewModel.ServiceControl.HostName, - Port = Convert.ToInt32(viewModel.ServiceControl.PortNumber), - DatabaseMaintenancePort = Convert.ToInt32(viewModel.ServiceControl.DatabaseMaintenancePortNumber), - VirtualDirectory = null, - ErrorQueue = viewModel.ServiceControl.ErrorQueueName, - ErrorLogQueue = viewModel.ServiceControl.ErrorForwarding.Value ? viewModel.ServiceControl.ErrorForwardingQueueName : null, - ForwardErrorMessages = viewModel.ServiceControl.ErrorForwarding.Value, - TransportPackage = viewModel.SelectedTransport, - ConnectionString = viewModel.ConnectionString, - ErrorRetentionPeriod = viewModel.ServiceControl.ErrorRetentionPeriod, - ServiceAccount = viewModel.ServiceControl.ServiceAccount, - ServiceAccountPwd = viewModel.ServiceControl.Password, - EnableFullTextSearchOnBodies = viewModel.ServiceControl.EnableFullTextSearchOnBodies.Value - } : null; + serviceControlNewInstance.DisplayName = viewModel.ServiceControl.InstanceName; + serviceControlNewInstance.Name = viewModel.ServiceControl.InstanceName.Replace(' ', '.'); + serviceControlNewInstance.ServiceDescription = viewModel.ServiceControl.Description; + serviceControlNewInstance.DBPath = viewModel.ServiceControl.DatabasePath; + serviceControlNewInstance.LogPath = viewModel.ServiceControl.LogPath; + serviceControlNewInstance.InstallPath = viewModel.ServiceControl.DestinationPath; + serviceControlNewInstance.HostName = viewModel.ServiceControl.HostName; + serviceControlNewInstance.Port = Convert.ToInt32(viewModel.ServiceControl.PortNumber); + serviceControlNewInstance.DatabaseMaintenancePort = Convert.ToInt32(viewModel.ServiceControl.DatabaseMaintenancePortNumber); + serviceControlNewInstance.VirtualDirectory = null; + serviceControlNewInstance.ErrorQueue = viewModel.ServiceControl.ErrorQueueName; + serviceControlNewInstance.ErrorLogQueue = viewModel.ServiceControl.ErrorForwarding.Value ? viewModel.ServiceControl.ErrorForwardingQueueName : null; + serviceControlNewInstance.ForwardErrorMessages = viewModel.ServiceControl.ErrorForwarding.Value; + serviceControlNewInstance.TransportPackage = viewModel.SelectedTransport; + serviceControlNewInstance.ConnectionString = viewModel.ConnectionString; + serviceControlNewInstance.ErrorRetentionPeriod = viewModel.ServiceControl.ErrorRetentionPeriod; + serviceControlNewInstance.ServiceAccount = viewModel.ServiceControl.ServiceAccount; + serviceControlNewInstance.ServiceAccountPwd = viewModel.ServiceControl.Password; + serviceControlNewInstance.EnableFullTextSearchOnBodies = viewModel.ServiceControl.EnableFullTextSearchOnBodies.Value; + } var auditNewInstance = viewModel.InstallAuditInstance ? ServiceControlAuditNewInstance.CreateWithDefaultPersistence() : null; if (viewModel.InstallAuditInstance) diff --git a/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/NewServiceControlInstance.cs b/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/NewServiceControlInstance.cs index d783e69d88..d9c1b968fc 100644 --- a/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/NewServiceControlInstance.cs +++ b/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/NewServiceControlInstance.cs @@ -147,29 +147,28 @@ protected override void BeginProcessing() protected override void ProcessRecord() { - var details = new ServiceControlNewInstance - { - InstallPath = InstallPath, - LogPath = LogPath, - DBPath = DBPath, - Name = Name, - DisplayName = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName, - ServiceDescription = Description, - ServiceAccount = ServiceAccount, - ServiceAccountPwd = ServiceAccountPassword, - HostName = HostName, - Port = Port, - DatabaseMaintenancePort = DatabaseMaintenancePort, - VirtualDirectory = VirtualDirectory, - ErrorQueue = ErrorQueue, - ErrorLogQueue = string.IsNullOrWhiteSpace(ErrorLogQueue) ? null : ErrorLogQueue, - ForwardErrorMessages = ForwardErrorMessages.ToBool(), - ErrorRetentionPeriod = ErrorRetentionPeriod, - ConnectionString = ConnectionString, - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Matches(Transport)), - SkipQueueCreation = SkipQueueCreation, - EnableFullTextSearchOnBodies = EnableFullTextSearchOnBodies, - }; + var details = ServiceControlNewInstance.CreateWithDefaultPersistence(); + + details.InstallPath = InstallPath; + details.LogPath = LogPath; + details.DBPath = DBPath; + details.Name = Name; + details.DisplayName = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName; + details.ServiceDescription = Description; + details.ServiceAccount = ServiceAccount; + details.ServiceAccountPwd = ServiceAccountPassword; + details.HostName = HostName; + details.Port = Port; + details.DatabaseMaintenancePort = DatabaseMaintenancePort; + details.VirtualDirectory = VirtualDirectory; + details.ErrorQueue = ErrorQueue; + details.ErrorLogQueue = string.IsNullOrWhiteSpace(ErrorLogQueue) ? null : ErrorLogQueue; + details.ForwardErrorMessages = ForwardErrorMessages.ToBool(); + details.ErrorRetentionPeriod = ErrorRetentionPeriod; + details.ConnectionString = ConnectionString; + details.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Matches(Transport)); + details.SkipQueueCreation = SkipQueueCreation; + details.EnableFullTextSearchOnBodies = EnableFullTextSearchOnBodies; var modulePath = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path); var zipfolder = ZipPath.Get(this); diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Configuration/AuditInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Configuration/AuditInstanceTests.cs index 09db3f4fc6..e9d9d109d4 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Configuration/AuditInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Configuration/AuditInstanceTests.cs @@ -7,7 +7,6 @@ using System.Xml; using NUnit.Framework; using ServiceControlInstaller.Engine.Configuration.ServiceControl; - using ServiceControlInstaller.Engine.FileSystem; using ServiceControlInstaller.Engine.Instances; using ServiceControlInstaller.Engine.Services; diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Configuration/NewAuditInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Configuration/NewAuditInstanceTests.cs index 5144b116c7..c384906100 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Configuration/NewAuditInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Configuration/NewAuditInstanceTests.cs @@ -38,7 +38,7 @@ public void Should_parse_all_persister_manifests() var zipFile = zipFiles.Single(f => f.Name.StartsWith("Particular.ServiceControl.Audit")); - var allManifests = ServiceControlAuditPersisters.LoadAllManifests(zipFile.FullName); + var allManifests = ServiceControlPersisters.LoadAllManifests(zipFile.FullName); CollectionAssert.IsNotEmpty(allManifests); } diff --git a/src/ServiceControlInstaller.Engine.UnitTests/RunEngineTasksExplicitly.cs b/src/ServiceControlInstaller.Engine.UnitTests/RunEngineTasksExplicitly.cs index f8d9af214f..3024ef0aa4 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/RunEngineTasksExplicitly.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/RunEngineTasksExplicitly.cs @@ -49,30 +49,29 @@ public async Task CreateInstanceMSMQ() var installer = new UnattendServiceControlInstaller(new TestLogger(), DeploymentCache); var instanceName = "Test.ServiceControl.Msmq"; var root = Path.Combine(@"c:\Test", instanceName); - var details = new ServiceControlNewInstance - { - DisplayName = instanceName.Replace(".", " "), - Name = instanceName, - ServiceDescription = "Test SC Instance", - DBPath = Path.Combine(root, "Database"), - LogPath = Path.Combine(root, "Logs"), - InstallPath = Path.Combine(root, "Binaries"), - HostName = "localhost", - Port = 33335, - DatabaseMaintenancePort = 33336, - VirtualDirectory = null, - AuditQueue = "audittest", - ForwardAuditMessages = false, - ForwardErrorMessages = false, - AuditRetentionPeriod = TimeSpan.FromDays(SettingConstants.AuditRetentionPeriodDefaultInDaysForUI), - ErrorRetentionPeriod = TimeSpan.FromDays(SettingConstants.ErrorRetentionPeriodDefaultInDaysForUI), - ErrorQueue = "testerror", - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ), - ReportCard = new ReportCard(), - // but this fails for unit tests as the deploymentCache path is not used - // constructer of ServiceControlInstanceMetadata extracts version from zip - Version = installer.ZipInfo.Version - }; + var details = ServiceControlNewInstance.CreateWithDefaultPersistence(DeploymentCache); + + details.DisplayName = instanceName.Replace(".", " "); + details.Name = instanceName; + details.ServiceDescription = "Test SC Instance"; + details.DBPath = Path.Combine(root, "Database"); + details.LogPath = Path.Combine(root, "Logs"); + details.InstallPath = Path.Combine(root, "Binaries"); + details.HostName = "localhost"; + details.Port = 33335; + details.DatabaseMaintenancePort = 33336; + details.VirtualDirectory = null; + details.AuditQueue = "audittest"; + details.ForwardAuditMessages = false; + details.ForwardErrorMessages = false; + details.AuditRetentionPeriod = TimeSpan.FromDays(SettingConstants.AuditRetentionPeriodDefaultInDaysForUI); + details.ErrorRetentionPeriod = TimeSpan.FromDays(SettingConstants.ErrorRetentionPeriodDefaultInDaysForUI); + details.ErrorQueue = "testerror"; + details.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ); + details.ReportCard = new ReportCard(); + // but this fails for unit tests as the deploymentCache path is not used + // constructer of ServiceControlInstanceMetadata extracts version from zip + details.Version = installer.ZipInfo.Version; await details.Validate(s => Task.FromResult(false)).ConfigureAwait(false); if (details.ReportCard.HasErrors) diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Validation/PathsValidationTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Validation/PathsValidationTests.cs index dabcaffb6b..dd25273aa2 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Validation/PathsValidationTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Validation/PathsValidationTests.cs @@ -12,12 +12,11 @@ public class PathsValidationTests [Test] public void CheckPathsAreUnique_ShouldThrow() { - var newInstance = new ServiceControlNewInstance - { - InstallPath = @"c:\test\1\bin", - LogPath = @"c:\test\1\bin", - DBPath = @"c:\test\1\bin" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(); + + newInstance.InstallPath = @"c:\test\1\bin"; + newInstance.LogPath = @"c:\test\1\bin"; + newInstance.DBPath = @"c:\test\1\bin"; var p = new PathsValidator(newInstance); @@ -28,12 +27,11 @@ public void CheckPathsAreUnique_ShouldThrow() [Test] public void CheckPathsAreUnique_ShouldSucceed() { - var newInstance = new ServiceControlNewInstance - { - InstallPath = @"c:\test\1\bin", - LogPath = @"c:\test\1\log", - DBPath = @"c:\test\1\db" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(); + + newInstance.InstallPath = @"c:\test\1\bin"; + newInstance.LogPath = @"c:\test\1\log"; + newInstance.DBPath = @"c:\test\1\db"; var p = new PathsValidator(newInstance); Assert.DoesNotThrow(() => p.CheckPathsAreUnique()); @@ -43,12 +41,11 @@ public void CheckPathsAreUnique_ShouldSucceed() [Test] public void CheckPathsAreValid_ShouldSucceed() { - var newInstance = new ServiceControlNewInstance - { - InstallPath = @"c:\test\1\bin", - LogPath = @"c:\test\1\bin", - DBPath = @"c:\test\1\bin" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(); + + newInstance.InstallPath = @"c:\test\1\bin"; + newInstance.LogPath = @"c:\test\1\bin"; + newInstance.DBPath = @"c:\test\1\bin"; var p = new PathsValidator(newInstance); Assert.DoesNotThrow(() => p.CheckPathsAreValid()); @@ -58,22 +55,24 @@ public void CheckPathsAreValid_ShouldSucceed() public void CheckPathsAreValid_ShouldThrow() { //Invalid path - var p = new PathsValidator(new ServiceControlNewInstance { InstallPath = @"?>c:\test\1\bin" }); + var instance = ServiceControlNewInstance.CreateWithDefaultPersistence(); + instance.InstallPath = @"?>c:\test\1\bin"; + var p = new PathsValidator(instance); var ex = Assert.Throws(() => p.CheckPathsAreValid()); Assert.That(ex.Message, Is.EqualTo("The install path is set to an invalid path")); + instance.InstallPath = @"\test\1\bin"; + //Partial path - p = new PathsValidator(new ServiceControlNewInstance - { - InstallPath = @"\test\1\bin" - }); + p = new PathsValidator(instance); ex = Assert.Throws(() => p.CheckPathsAreValid()); Assert.That(ex.Message, Is.EqualTo("The install path is set to an invalid path")); //No Drive - p = new PathsValidator(new ServiceControlNewInstance { InstallPath = $@"{GetAnUnsedDriveLetter()}:\test\1\bin" }); + instance.InstallPath = $@"{GetAnUnsedDriveLetter()}:\test\1\bin"; + p = new PathsValidator(instance); ex = Assert.Throws(() => p.CheckPathsAreValid()); Assert.That(ex.Message, Is.EqualTo("The install path does not go to a supported drive")); } @@ -81,12 +80,11 @@ public void CheckPathsAreValid_ShouldThrow() [Test] public void CheckNoNestedPaths_ShouldThrow() { - var newInstance = new ServiceControlNewInstance - { - InstallPath = @"c:\test\1", - LogPath = @"c:\test\1\log", - DBPath = @"c:\test\1\db" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(); + + newInstance.InstallPath = @"c:\test\1"; + newInstance.LogPath = @"c:\test\1\log"; + newInstance.DBPath = @"c:\test\1\db"; var p = new PathsValidator(newInstance); var ex = Assert.Throws(() => p.CheckNoNestedPaths()); @@ -96,12 +94,11 @@ public void CheckNoNestedPaths_ShouldThrow() [Test] public void CheckNoNestedSiblingPaths_ShouldSucceed() { - var newInstance = new ServiceControlNewInstance - { - InstallPath = @"c:\test\1\servicecontrol", - LogPath = @"c:\test\1\servicecontrollog", - DBPath = @"c:\test\1\servicecontroldb" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(); + + newInstance.InstallPath = @"c:\test\1\servicecontrol"; + newInstance.LogPath = @"c:\test\1\servicecontrollog"; + newInstance.DBPath = @"c:\test\1\servicecontroldb"; var p = new PathsValidator(newInstance); Assert.DoesNotThrow(() => p.CheckNoNestedPaths()); @@ -110,12 +107,11 @@ public void CheckNoNestedSiblingPaths_ShouldSucceed() [Test] public void CheckNoNestedPaths_ShouldSucceed() { - var newInstance = new ServiceControlNewInstance - { - InstallPath = @"c:\test\1\bin", - LogPath = @"c:\test\1\log", - DBPath = @"c:\test\1\db" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(); + + newInstance.InstallPath = @"c:\test\1\bin"; + newInstance.LogPath = @"c:\test\1\log"; + newInstance.DBPath = @"c:\test\1\db"; var p = new PathsValidator(newInstance); diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Validation/QueueValidationTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Validation/QueueValidationTests.cs index 5048cd0e87..4b175e972f 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Validation/QueueValidationTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Validation/QueueValidationTests.cs @@ -56,6 +56,8 @@ class FakeServiceControlInstance : IServiceControlInstance public TransportInfo TransportPackage { get; set; } + public PersistenceManifest PersistenceManifest { get; set; } + public string ConnectionString { get; set; } public string Url { get; set; } @@ -140,12 +142,11 @@ public void Init() [Test] public void CheckQueueNamesAreUniqueShouldSucceed() { - var newInstance = new ServiceControlNewInstance - { - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ), - ErrorLogQueue = "errorlog", - ErrorQueue = "error" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); + + newInstance.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ); + newInstance.ErrorLogQueue = "errorlog"; + newInstance.ErrorQueue = "error"; var p = new QueueNameValidator(newInstance) { @@ -179,13 +180,12 @@ public void CheckChainingOfAuditQueues_ShouldSucceed() [Test] public void CheckQueueNamesAreUniqueShouldThrow() { - var newInstance = new ServiceControlNewInstance - { - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ), - ErrorLogQueue = "error", - ErrorQueue = "error", - ForwardErrorMessages = true - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); + + newInstance.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ); + newInstance.ErrorLogQueue = "error"; + newInstance.ErrorQueue = "error"; + newInstance.ForwardErrorMessages = true; var p = new QueueNameValidator(newInstance) { @@ -199,12 +199,11 @@ public void CheckQueueNamesAreUniqueShouldThrow() [Test] public void CheckQueueNamesAreNotTakenByAnotherInstance_ShouldSucceed() { - var newInstance = new ServiceControlNewInstance - { - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ), - ErrorLogQueue = "errorlog2", - ErrorQueue = "error2" - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); + + newInstance.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ); + newInstance.ErrorLogQueue = "errorlog2"; + newInstance.ErrorQueue = "error2"; var p = new QueueNameValidator(newInstance) { @@ -217,12 +216,12 @@ public void CheckQueueNamesAreNotTakenByAnotherInstance_ShouldSucceed() public void CheckQueueNamesAreNotTakenByAnotherInstance_ShouldThrow() { var expectedError = "Some queue names specified are already assigned to another ServiceControl instance - Correct the values for ErrorLogQueue, ErrorQueue"; - var newInstance = new ServiceControlNewInstance + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); { - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ), - ErrorLogQueue = "errorlog", - ErrorQueue = "error", - ForwardErrorMessages = true + newInstance.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ); + newInstance.ErrorLogQueue = "errorlog"; + newInstance.ErrorQueue = "error"; + newInstance.ForwardErrorMessages = true; }; var p = new QueueNameValidator(newInstance) @@ -235,10 +234,8 @@ public void CheckQueueNamesAreNotTakenByAnotherInstance_ShouldThrow() expectedError = "The queue name for ErrorQueue is already assigned to another ServiceControl instance"; // with default names - var defaultInstance = new ServiceControlNewInstance - { - ErrorQueue = "Error" - }; + var defaultInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); + defaultInstance.ErrorQueue = "Error"; p = new QueueNameValidator(defaultInstance) { @@ -254,13 +251,12 @@ public void DuplicateQueueNamesAreAllowedOnDifferentTransports_ShouldNotThrow() { var expectedError = "Some queue names specified are already assigned to another ServiceControl instance - Correct the values for ErrorLogQueue, ErrorQueue"; - var newInstance = new ServiceControlNewInstance - { - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.RabbitMQQuorumConventionalRoutingTopology), - ErrorLogQueue = "errorlog", - ErrorQueue = "error", - ForwardErrorMessages = true - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); + + newInstance.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.RabbitMQQuorumConventionalRoutingTopology); + newInstance.ErrorLogQueue = "errorlog"; + newInstance.ErrorQueue = "error"; + newInstance.ForwardErrorMessages = true; var p = new QueueNameValidator(newInstance) { @@ -272,10 +268,10 @@ public void DuplicateQueueNamesAreAllowedOnDifferentTransports_ShouldNotThrow() expectedError = "The queue name for ErrorQueue is already assigned to another ServiceControl instance"; // with default names - var defaultInstance = new ServiceControlNewInstance - { - ErrorQueue = "Error" - }; + var defaultInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); + + defaultInstance.ErrorQueue = "Error"; + p = new QueueNameValidator(defaultInstance) { SCInstances = instances @@ -288,14 +284,13 @@ public void DuplicateQueueNamesAreAllowedOnDifferentTransports_ShouldNotThrow() [Test] public void EnsureDuplicateQueueNamesAreAllowedOnSameTransportWithDifferentConnectionString() { - var newInstance = new ServiceControlNewInstance - { - TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.RabbitMQQuorumConventionalRoutingTopology), - ErrorQueue = "RMQerror", - ErrorLogQueue = "RMQerrorlog", - ConnectionString = "afakeconnectionstring", - ForwardErrorMessages = true - }; + var newInstance = ServiceControlNewInstance.CreateWithDefaultPersistence(GetZipFolder().FullName); + + newInstance.TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.RabbitMQQuorumConventionalRoutingTopology); + newInstance.ErrorQueue = "RMQerror"; + newInstance.ErrorLogQueue = "RMQerrorlog"; + newInstance.ConnectionString = "afakeconnectionstring"; + newInstance.ForwardErrorMessages = true; var p = new QueueNameValidator(newInstance) { diff --git a/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/ServiceControlAppConfig.cs b/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/ServiceControlAppConfig.cs index d64d73fa3c..a181d86e3c 100644 --- a/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/ServiceControlAppConfig.cs +++ b/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/ServiceControlAppConfig.cs @@ -25,6 +25,7 @@ protected override void UpdateSettings() settings.Set(ServiceControlSettings.DBPath, details.DBPath); settings.Set(ServiceControlSettings.ForwardErrorMessages, details.ForwardErrorMessages.ToString(), version); settings.Set(ServiceControlSettings.TransportType, details.TransportPackage.TypeName, version); + settings.Set(ServiceControlSettings.PersistenceType, details.PersistenceManifest.TypeName); settings.Set(ServiceControlSettings.ErrorQueue, details.ErrorQueue); settings.Set(ServiceControlSettings.ErrorLogQueue, details.ForwardErrorMessages ? details.ErrorLogQueue : null); settings.Set(ServiceControlSettings.AuditRetentionPeriod, details.AuditRetentionPeriod.ToString(), version); diff --git a/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/SettingsList.cs b/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/SettingsList.cs index 013cb88991..67c11f324a 100644 --- a/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/SettingsList.cs +++ b/src/ServiceControlInstaller.Engine/Configuration/ServiceControl/SettingsList.cs @@ -28,6 +28,7 @@ public static class ServiceControlSettings }; public static readonly SettingInfo TransportType = new SettingInfo { Name = "ServiceControl/TransportType" }; + public static readonly SettingInfo PersistenceType = new SettingInfo { Name = "ServiceControl/PersistenceType" }; public static readonly SettingInfo AuditQueue = new SettingInfo { Name = "ServiceBus/AuditQueue", diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs index ab81a735f3..026f946e29 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditInstance.cs @@ -82,7 +82,7 @@ public override void Reload() var zipInfo = ServiceControlAuditZipInfo.Find(deploymentCachePath); - var manifests = ServiceControlAuditPersisters.LoadAllManifests(zipInfo.FilePath); + var manifests = ServiceControlPersisters.LoadAllManifests(zipInfo.FilePath); var persistenceType = AppConfig.Read(AuditInstanceSettingsList.PersistenceType, null); diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs index 900512dbb0..5671205b98 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditNewInstance.cs @@ -27,7 +27,7 @@ public static ServiceControlAuditNewInstance CreateWithDefaultPersistence(string public static ServiceControlAuditNewInstance CreateWithPersistence(string deploymentCachePath, string persistence) { var zipInfo = ServiceControlAuditZipInfo.Find(deploymentCachePath); - var persistenceManifest = ServiceControlAuditPersisters.LoadAllManifests(zipInfo.FilePath) + var persistenceManifest = ServiceControlPersisters.LoadAllManifests(zipInfo.FilePath) .Single(manifest => manifest.Name == persistence); return new ServiceControlAuditNewInstance(zipInfo.Version, persistenceManifest); diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs index 233dd84ac6..9697a9cb7b 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs @@ -5,6 +5,7 @@ namespace ServiceControlInstaller.Engine.Instances using System.Configuration; using System.IO; using System.Linq; + using System.Reflection; using System.Threading.Tasks; using Configuration; using Configuration.ServiceControl; @@ -15,8 +16,15 @@ namespace ServiceControlInstaller.Engine.Instances public class ServiceControlInstance : ServiceControlBaseService, IServiceControlInstance { - public ServiceControlInstance(WindowsServiceController service) : base(service) + public ServiceControlInstance(IWindowsServiceController service) + : this(service, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) { + } + + public ServiceControlInstance(IWindowsServiceController service, string deploymentCachePath) : base(service) + { + this.deploymentCachePath = deploymentCachePath; + Reload(); } @@ -26,6 +34,8 @@ public ServiceControlInstance(WindowsServiceController service) : base(service) public List RemoteInstances { get; set; } = new List(); + public PersistenceManifest PersistenceManifest { get; set; } + public void AddRemoteInstance(string apiUri) { if (RemoteInstances.All(x => string.Compare(x.ApiUri, apiUri, StringComparison.InvariantCultureIgnoreCase) != 0)) @@ -111,6 +121,19 @@ public override void Reload() Description = GetDescription(); ServiceAccount = Service.Account; + var zipInfo = ServiceControlZipInfo.Find(deploymentCachePath); + var manifests = ServiceControlPersisters.LoadAllManifests(zipInfo.FilePath); + var persistenceType = AppConfig.Read(ServiceControlSettings.PersistenceType, null); + + if (string.IsNullOrEmpty(persistenceType)) + { + PersistenceManifest = manifests.Single(m => m.Name == ServiceControlNewInstance.DefaultPersister); + } + else + { + PersistenceManifest = manifests.Single(m => m.TypeName == persistenceType); + } + ForwardErrorMessages = AppConfig.Read(ServiceControlSettings.ForwardErrorMessages, false); if (ForwardErrorMessages) { @@ -168,6 +191,7 @@ protected override void ApplySettingsChanges(KeyValueConfigurationCollection set settings.Set(ServiceControlSettings.AuditLogQueue, AuditLogQueue, Version); settings.Set(ServiceControlSettings.ErrorLogQueue, ErrorLogQueue, Version); settings.Set(ServiceControlSettings.EnableFullTextSearchOnBodies, EnableFullTextSearchOnBodies.ToString(), Version); + settings.Set(ServiceControlSettings.PersistenceType, PersistenceManifest.TypeName); if (RemoteInstances != null) { @@ -188,6 +212,7 @@ public override void UpgradeFiles(string zipFilePath) FileUtils.DeleteDirectory(InstallPath, true, true, "license", $"{Constants.ServiceControlExe}.config"); FileUtils.UnzipToSubdirectory(zipFilePath, InstallPath, "ServiceControl"); FileUtils.UnzipToSubdirectory(zipFilePath, InstallPath, $@"Transports\{TransportPackage.ZipName}"); + FileUtils.UnzipToSubdirectory(zipFilePath, InstallPath, $@"Persisters\{PersistenceManifest.Name}"); } protected override IEnumerable GetPersistencePathsToCleanUp() @@ -214,5 +239,7 @@ protected override IEnumerable GetPersistencePathsToCleanUp() : folderpath; } } + + readonly string deploymentCachePath; } } \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs index cd809b4c4c..d117c41ef4 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlNewInstance.cs @@ -15,11 +15,29 @@ namespace ServiceControlInstaller.Engine.Instances public class ServiceControlNewInstance : ServiceControlInstallableBase, IServiceControlInstance { - public ServiceControlNewInstance() + public static ServiceControlNewInstance CreateWithDefaultPersistence() { - var appDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - var zipInfo = ServiceControlZipInfo.Find(appDirectory); - Version = zipInfo.Version; + return CreateWithDefaultPersistence(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); + } + + public static ServiceControlNewInstance CreateWithDefaultPersistence(string deploymentCachePath) + { + return CreateWithPersistence(deploymentCachePath, DefaultPersister); + } + + public static ServiceControlNewInstance CreateWithPersistence(string deploymentCachePath, string persistence) + { + var zipInfo = ServiceControlZipInfo.Find(deploymentCachePath); + var persistenceManifest = ServiceControlPersisters.LoadAllManifests(zipInfo.FilePath) + .Single(manifest => manifest.Name == persistence); + + return new ServiceControlNewInstance(zipInfo.Version, persistenceManifest); + } + + public ServiceControlNewInstance(Version version, PersistenceManifest persistenceManifest) + { + Version = version; + PersistenceManifest = persistenceManifest; } public override void WriteConfigurationFile() @@ -28,6 +46,7 @@ public override void WriteConfigurationFile() appConfig.Save(); } + public PersistenceManifest PersistenceManifest { get; } public override string DirectoryName => "ServiceControl"; public List RemoteInstances { get; set; } = new List(); @@ -98,6 +117,13 @@ protected override void ValidateConnectionString() ConnectionStringValidator.Validate(this); } + public override void CopyFiles(string zipFilePath) + { + base.CopyFiles(zipFilePath); + + FileUtils.UnzipToSubdirectory(zipFilePath, InstallPath, $@"Persisters\{PersistenceManifest.Name}"); + } + public static ServiceControlNewInstance Load(string path) { ServiceControlNewInstance instanceData; @@ -126,5 +152,8 @@ public static ServiceControlNewInstance Load(string path) return instanceData; } + + // TODO: Change after Raven5 introduced + public const string DefaultPersister = "RavenDB35"; } } \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditPersisters.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlPersisters.cs similarity index 96% rename from src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditPersisters.cs rename to src/ServiceControlInstaller.Engine/Instances/ServiceControlPersisters.cs index 2fc576cca0..7dc9683ac2 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlAuditPersisters.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlPersisters.cs @@ -6,7 +6,7 @@ using System.Linq; using Newtonsoft.Json; - public class ServiceControlAuditPersisters + public class ServiceControlPersisters { public static IReadOnlyList LoadAllManifests(string zipFilePath) { diff --git a/src/ServiceControlInstaller.Engine/Interfaces.cs b/src/ServiceControlInstaller.Engine/Interfaces.cs index ac2f975753..c941303819 100644 --- a/src/ServiceControlInstaller.Engine/Interfaces.cs +++ b/src/ServiceControlInstaller.Engine/Interfaces.cs @@ -103,5 +103,6 @@ public interface IServiceControlInstance : IServiceControlBaseInstance, IURLInfo TimeSpan ErrorRetentionPeriod { get; } TimeSpan? AuditRetentionPeriod { get; set; } List RemoteInstances { get; } + PersistenceManifest PersistenceManifest { get; } } } \ No newline at end of file diff --git a/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj b/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj index 07661c18eb..887f2c404e 100644 --- a/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj +++ b/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj @@ -16,6 +16,10 @@ + + + +