Skip to content

Commit

Permalink
[ADD] Extra logging to data seeds; fixes #302
Browse files Browse the repository at this point in the history
* [ADD] Extra logging to data seeds
* Count update for site rdls
  • Loading branch information
lxatstariongroup authored Dec 18, 2023
1 parent 594f5c7 commit 6559e22
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion CometServer/Modules/10-25/ExchangeFileImportyApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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<SiteReferenceDataLibrary>().Count();
var seededSiteRdlCount = 0;
var engineeringModelCount = items.OfType<EngineeringModelSetup>().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<Person>())
{
Expand Down Expand Up @@ -447,6 +457,7 @@ private bool InsertModelData(IRequestUtils requestUtils, ICdp4TransactionManager
serviceProvider.MapToPersitableService<SiteDirectoryService>("SiteDirectory");

result = siteDirectoryService.Insert(transaction, "SiteDirectory", topContainer);
seededSiteRdlCount = siteRdlCount;
}

if (result)
Expand All @@ -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<EngineeringModelSetup>()
.ToList();
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6559e22

Please sign in to comment.