From 6559e2221c72e81ab099900d34834e097a9bd7f6 Mon Sep 17 00:00:00 2001 From: Alexander van Delft <56023674+lxatrhea@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:30:04 +0100 Subject: [PATCH] [ADD] Extra logging to data seeds; fixes #302 * [ADD] Extra logging to data seeds * Count update for site rdls --- .../Modules/10-25/ExchangeFileImportyApi.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CometServer/Modules/10-25/ExchangeFileImportyApi.cs b/CometServer/Modules/10-25/ExchangeFileImportyApi.cs index f68d715c..a9b38bf2 100644 --- a/CometServer/Modules/10-25/ExchangeFileImportyApi.cs +++ b/CometServer/Modules/10-25/ExchangeFileImportyApi.cs @@ -233,6 +233,7 @@ internal async Task ImportDataStore(HttpRequest request, HttpResponse response, { response.StatusCode = (int)HttpStatusCode.BadRequest; await response.AsJson("invalid seed file"); + return; } // Remove the exchange file after processing (saving space) @@ -304,6 +305,8 @@ internal async Task SeedDataStore(HttpRequest request, HttpResponse response, IR var version = request.QueryDataModelVersion(); + this.logger.LogInformation("Seeding version {version.ToString()}"); + // handle exchange processing if (!this.InsertModelData(requestUtils, transactionManager, jsonExchangeFileReader, migrationService, engineeringModelDao, serviceProvider, personService, personRoleService, personPermissionService, defaultPermissionProvider, participantRoleService, participantPermissionService, version, temporarysSeedFilePath, null, this.AppConfigService.AppConfig.Backtier.IsDbSeedEnabled)) { @@ -409,6 +412,13 @@ private bool InsertModelData(IRequestUtils requestUtils, ICdp4TransactionManager // get sitedirectory data var items = jsonExchangeFileReader.ReadSiteDirectoryFromfile(version, fileName, password).ToList(); + var siteRdlCount = items.OfType().Count(); + var seededSiteRdlCount = 0; + var engineeringModelCount = items.OfType().Count(); + var seededEngineeringModelCount = 0; + + this.logger.LogInformation($"{siteRdlCount} Site Reference Data Libraries and {engineeringModelCount} Engineering Models will be seeded"); + // assign default password to all imported persons. foreach (var person in items.OfType()) { @@ -447,6 +457,7 @@ private bool InsertModelData(IRequestUtils requestUtils, ICdp4TransactionManager serviceProvider.MapToPersitableService("SiteDirectory"); result = siteDirectoryService.Insert(transaction, "SiteDirectory", topContainer); + seededSiteRdlCount = siteRdlCount; } if (result) @@ -468,6 +479,8 @@ private bool InsertModelData(IRequestUtils requestUtils, ICdp4TransactionManager // Add missing Person permissions this.CreateMissingPersonPermissions(transaction, personRoleService, personPermissionService, defaultPermissionProvider); + this.logger.LogInformation($"{seededSiteRdlCount}/{siteRdlCount} Site Reference Data Libraries and {seededEngineeringModelCount}/{engineeringModelCount} Engineering Models seeded"); + var engineeringModelSetups = items.OfType() .ToList(); @@ -477,7 +490,7 @@ private bool InsertModelData(IRequestUtils requestUtils, ICdp4TransactionManager foreach (var engineeringModelSetup in engineeringModelSetups) { - this.logger.LogInformation("Inserting data for EngineeringModelSetuo {shortname}:{name}", engineeringModelSetup.ShortName, engineeringModelSetup.Name); + this.logger.LogInformation("Inserting data for EngineeringModelSetup {shortname}:{name}", engineeringModelSetup.ShortName, engineeringModelSetup.Name); // cleanup before handling TopContainer requestUtils.Cache.Clear(); @@ -555,10 +568,20 @@ private bool InsertModelData(IRequestUtils requestUtils, ICdp4TransactionManager // extract any referenced file data to disk if not already present PersistFileBinaryData(requestUtils, jsonExchangeFileReader, fileName, password); + + seededEngineeringModelCount++; + + this.logger.LogInformation($"{seededSiteRdlCount}/{siteRdlCount} Site Reference Data Libraries and {seededEngineeringModelCount}/{engineeringModelCount} Engineering Models seeded"); + } } + var commitSw = new Stopwatch(); + commitSw.Start(); + this.logger.LogInformation("Committing transaction..."); transaction.Commit(); + commitSw.Stop(); + this.logger.LogInformation("Transaction committed in {commitSw} [ms]", commitSw.ElapsedMilliseconds); sw.Stop(); this.logger.LogInformation("Finished seeding the data store in {sw} [ms]", sw.ElapsedMilliseconds);