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

Feature/rdmp 13 removable default logging server #1589

Merged
merged 16 commits into from
Aug 9, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Test_ExampleDatasetsCreation()

//create the pipelines
var pipes = new CataloguePipelinesAndReferencesCreation(RepositoryLocator,null,null);
pipes.CreatePipelines();
pipes.CreatePipelines(new PlatformDatabaseCreationOptions {});

//create all the stuff
var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void TestLoadingFileWithTrailingDotsInHeader()
// Create the 'out of the box' RDMP pipelines (which includes an excel bulk importer pipeline)
var creator = new CataloguePipelinesAndReferencesCreation(
RepositoryLocator, UnitTestLoggingConnectionString, DataQualityEngineConnectionString);
creator.CreatePipelines();
creator.CreatePipelines(new PlatformDatabaseCreationOptions {});

// find the excel loading pipeline
var pipe = CatalogueRepository.GetAllObjects<Pipeline>().OrderByDescending(p => p.ID).FirstOrDefault(p => p.Name.Contains("BULK INSERT: Excel File"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,27 @@ private void DoStartup()
var startup = new Startup.Startup(new EnvironmentInfo(),_repositoryLocator);
startup.DoStartup(new IgnoreAllErrorsCheckNotifier());
}
private void CreateServers()
private void CreateServers(PlatformDatabaseCreationOptions options)
{
var defaults = _repositoryLocator.CatalogueRepository;

_edsLogging = new ExternalDatabaseServer(_repositoryLocator.CatalogueRepository, "Logging",new LoggingDatabasePatcher())
if(!options.SkipLoggingServer){
_edsLogging = new ExternalDatabaseServer(_repositoryLocator.CatalogueRepository, "Logging",new LoggingDatabasePatcher())
{
Server = _logging?.DataSource ?? throw new InvalidOperationException("Null logging database provided"),
Database = _logging.InitialCatalog
};

if(_logging.UserID != null)
{
Server = _logging.DataSource,
Database = _logging.InitialCatalog
};
_edsLogging.Username = _logging.UserID;
_edsLogging.Password = _logging.Password;
}

if(_logging.UserID != null)
{
_edsLogging.Username = _logging.UserID;
_edsLogging.Password = _logging.Password;
_edsLogging.SaveToDatabase();
defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID, _edsLogging);
Console.WriteLine("Successfully configured default logging server");
}

_edsLogging.SaveToDatabase();
defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID, _edsLogging);
Console.WriteLine("Successfully configured default logging server");

var edsDQE = new ExternalDatabaseServer(_repositoryLocator.CatalogueRepository, "DQE", new DataQualityEnginePatcher())
{
Server = _dqe.DataSource,
Expand All @@ -90,7 +91,8 @@ private void CreateServers()
};

//We are expecting a single username/password for everything here, so just use the dqe one
if (_dqe.UserID != null)
bool hasLoggingDB = _logging != null && _logging.UserID != null;
if (_dqe.UserID != null && hasLoggingDB)
{
if (_logging.UserID != _dqe.UserID || _logging.Password != _dqe.Password)
throw new Exception("DQE uses sql authentication but the credentials are not the same as the logging db. Could not pick a single set of credentials to use for the RAW server entry");
Expand All @@ -104,7 +106,7 @@ private void CreateServers()
Console.WriteLine("Successfully configured RAW server");
}

public void CreatePipelines()
public void CreatePipelines(PlatformDatabaseCreationOptions options)
{
var bulkInsertCsvPipe =
CreatePipeline("BULK INSERT: CSV Import File (manual column-type editing)", typeof(DelimitedFlatFileDataFlowSource), typeof(DataTableUploadDestination));
Expand All @@ -117,9 +119,10 @@ public void CreatePipelines()
SetComponentProperties(bulkInsertCsvPipewithAdjuster.Source, "Separator", ",");
SetComponentProperties(bulkInsertCsvPipewithAdjuster.Source, "StronglyTypeInput", false);

SetComponentProperties(bulkInsertCsvPipe.Destination, "LoggingServer", _edsLogging);
SetComponentProperties(bulkInsertCsvPipewithAdjuster.Destination, "LoggingServer", _edsLogging);

if(!options.SkipLoggingServer){
SetComponentProperties(bulkInsertCsvPipe.Destination, "LoggingServer", _edsLogging);
SetComponentProperties(bulkInsertCsvPipewithAdjuster.Destination, "LoggingServer", _edsLogging);
}
var createCohortFromCSV = CreatePipeline("CREATE COHORT:From CSV File",typeof (DelimitedFlatFileDataFlowSource), typeof (BasicCohortDestination));
SetComponentProperties(createCohortFromCSV.Source, "Separator", ",");

Expand Down Expand Up @@ -184,11 +187,11 @@ private Pipeline CreatePipeline(string nameOfPipe, Type sourceType, Type destina
return pipe;
}

public void Create()
public void Create(PlatformDatabaseCreationOptions options)
{

DoStartup();
CreateServers();
CreatePipelines();
CreateServers(options);
CreatePipelines(options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ public static void CreatePlatformDatabases(PlatformDatabaseCreationOptions optio
Create(DefaultDataExportDatabaseName, new DataExportPatcher(), options);

var dqe = Create(DefaultDQEDatabaseName, new DataQualityEnginePatcher(), options);
var logging = Create(DefaultLoggingDatabaseName, new LoggingDatabasePatcher(), options);


SqlConnectionStringBuilder logging = null;
if(!options.SkipLoggingServer){
logging = Create(DefaultLoggingDatabaseName, new LoggingDatabasePatcher(), options);
}
CatalogueRepository.SuppressHelpLoading = true;

var repo = new PlatformDatabaseCreationRepositoryFinder(options);

if (!options.SkipPipelines)
{
var creator = new CataloguePipelinesAndReferencesCreation(repo, logging, dqe);
creator.Create();
creator.Create(options);
}

if(options.ExampleDatasets || options.Nightmare)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class PlatformDatabaseCreationOptions

[Option('k', "Skip Pipelines", Default = false, HelpText = "Skips creating the default Pipelines and Managed Server References in the Catalogue database once created.")]
public bool SkipPipelines { get; set; }

[Option('l', "Skip Logging Server", Default = false, HelpText = "Skips creating the default logging server in the Catalogue database once created. Is superseeded by 'Skip Pipelines'")]
public bool SkipLoggingServer { get; set; }

[Option('e', "ExampleDatasets", Default = false, HelpText = "Create example datasets, projects, extraction configurations and cohort queries")]
public bool ExampleDatasets{get;set;}
Expand Down Expand Up @@ -65,6 +68,7 @@ public class PlatformDatabaseCreationOptions
[Option(Required = false, HelpText = "Optional connection string keywords to use e.g. \"Key1=Value1; Key2=Value2\". When using this option you must manually specify IntegratedSecurity if required.")]
public string OtherKeywords { get; set; }


[Usage]
public static IEnumerable<Example> Examples
{
Expand Down
15 changes: 11 additions & 4 deletions Rdmp.Core/Curation/Data/Catalogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,17 @@ public LoadMetadata LoadMetadata

/// <inheritdoc/>
[NoMappingToDatabase]
public ExternalDatabaseServer LiveLoggingServer =>
LiveLoggingServer_ID == null
? null
: Repository.GetObjectByID<ExternalDatabaseServer>((int)LiveLoggingServer_ID);
public ExternalDatabaseServer LiveLoggingServer {
get{
if(LiveLoggingServer_ID != null){
ExternalDatabaseServer[] dbs = Repository.GetAllObjectsWhere<ExternalDatabaseServer>("id",(int)LiveLoggingServer_ID);
if(dbs.Length > 0){
return dbs.First();
}
}
return null;
}
}

/// <inheritdoc/>
[NoMappingToDatabase]
Expand Down
9 changes: 9 additions & 0 deletions Rdmp.Core/Curation/Data/ExternalDatabaseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ public bool DiscoverExistence(DataAccessContext context,out string reason)

public override void DeleteInDatabase()
{

if (WasCreatedBy(new LoggingDatabasePatcher())){
//If you're trying to delete a logging server, remove all references to it first
Catalogue[] catalogues = Repository.GetAllObjectsWhere<Catalogue>("LiveLoggingServer_ID",base.ID);
foreach(Catalogue catalogue in catalogues){
catalogue.LiveLoggingServer_ID = null;
catalogue.SaveToDatabase();
}
}
base.DeleteInDatabase();

// normally in database schema deleting an ExternalDatabaseServer will cascade to clear defaults
Expand Down
6 changes: 6 additions & 0 deletions Rdmp.Core/GlobalStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rdmp.Core/GlobalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@
<data name="FromFile" xml:space="preserve">
<value>Catalogue from File...</value>
</data>
<data name="CreateALoggingServer" xml:space="preserve">
<value>Create a logging server</value>
</data>
</root>
17 changes: 16 additions & 1 deletion Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Rdmp.UI/LocationsMenu/ChoosePlatformDatabasesUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ private void btnCreateSuite_Click(object sender, EventArgs e)
Username = tbUsername.Text,
Password = tbPassword.Text,
ExampleDatasets = cbCreateExampleDatasets.Checked,
SkipLoggingServer = !cbSkipLoggingServer.Checked,
JFriel marked this conversation as resolved.
Show resolved Hide resolved
Seed = _seed,
NumberOfPeople = _peopleCount,
NumberOfRowsPerDataset = _rowCount,
Expand Down Expand Up @@ -447,5 +448,4 @@ private void cbCreateExampleDatasets_CheckedChanged(object sender, EventArgs e)
{
gbExampleDatasets.Enabled = cbCreateExampleDatasets.Checked;
}

}