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

[ADD] Extra logging to data seeds; fixes #302 #304

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading