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

Nds changeplugin config #479

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy as build
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal as build

# Install the tools
RUN dotnet tool install --tool-path /tools dotnet-trace
Expand All @@ -26,7 +26,7 @@ RUN echo "Building MONAI Deploy Informatics Gateway..."
RUN dotnet publish -c Release -o out --nologo src/InformaticsGateway/Monai.Deploy.InformaticsGateway.csproj

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy
FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal

# Enable elastic client compatibility mode
ENV ELASTIC_CLIENT_APIVERSIONING=true
Expand Down
1 change: 1 addition & 0 deletions src/Client/Test/packages.lock.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@
"Microsoft.Extensions.Configuration": "[6.0.1, )",
"Microsoft.Extensions.Configuration.FileExtensions": "[6.0.0, )",
"Microsoft.Extensions.Configuration.Json": "[6.0.0, )",
"Microsoft.Extensions.Options.ConfigurationExtensions": "[6.0.0, )",
"Monai.Deploy.InformaticsGateway.Api": "[0.4.1, )",
"Monai.Deploy.InformaticsGateway.Configuration": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database.Api": "[1.0.0, )",
Expand Down
9 changes: 6 additions & 3 deletions src/Configuration/DatabaseConfiguration.cs → src/Configuration/DatabaseOptions.cs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 MONAI Consortium
/*
* Copyright 2022 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,8 +18,11 @@

namespace Monai.Deploy.InformaticsGateway.Configuration
{
public class DatabaseConfiguration
public class DatabaseOptions
{
[ConfigurationKeyName("DatabaseName")]
public string DatabaseName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets retry options relate to reading/writing to the database.
/// </summary>
Expand Down
15 changes: 0 additions & 15 deletions src/Configuration/InformaticsGatewayConfiguration.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ public class InformaticsGatewayConfiguration
[ConfigurationKeyName("messaging")]
public MessageBrokerConfiguration Messaging { get; set; }

/// <summary>
/// Represents the <c>database</c> section of the configuration file.
/// </summary>
[ConfigurationKeyName("database")]
public DatabaseConfiguration Database { get; set; }

/// <summary>
/// Represents the <c>pluginConfiguration</c> section of the configuration file.
/// </summary>
[ConfigurationKeyName("plugins")]
public PlugInConfiguration PlugInConfigurations { get; set; }


public InformaticsGatewayConfiguration()
{
Dicom = new DicomConfiguration();
Expand All @@ -91,9 +78,7 @@ public InformaticsGatewayConfiguration()
Fhir = new FhirConfiguration();
Export = new DataExportConfiguration();
Messaging = new MessageBrokerConfiguration();
Database = new DatabaseConfiguration();
Hl7 = new Hl7Configuration();
PlugInConfigurations = new PlugInConfiguration();
}
}
}
9 changes: 8 additions & 1 deletion src/Configuration/RetryConfiguration.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class RetryConfiguration
/// Default is 250, 500, 1000.
/// </summary>
[ConfigurationKeyName("delays")]
public int[] DelaysMilliseconds { get; set; } = new[] { 750, 1200, 2500 };
mocsharp marked this conversation as resolved.
Show resolved Hide resolved
public int[] DelaysMilliseconds { get; set; }

// Gets the delays in TimeSpan objects
public IEnumerable<TimeSpan> RetryDelays
Expand All @@ -42,5 +42,12 @@ public IEnumerable<TimeSpan> RetryDelays
}
}
}
public RetryConfiguration()
{
if (DelaysMilliseconds is null || DelaysMilliseconds.Length == 0)
{
DelaysMilliseconds = new[] { 250, 500, 1000 };
}
}
}
}
26 changes: 0 additions & 26 deletions src/Database/Api/DatabaseOptions.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/Database/Api/DatabaseRegistrationBase.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Monai.Deploy.InformaticsGateway.Database.Api
{
public abstract class DatabaseRegistrationBase
{
public abstract IServiceCollection Configure(IServiceCollection services, DatabaseType databaseType, string? connectionString, ILogger logger);
public abstract IServiceCollection Configure(IServiceCollection services, DatabaseType databaseType, IConfigurationSection? connectionstringConfigurationSection, IConfigurationSection? pluginsConfigurationSection, ILoggerFactory loggerFactory);
}
}
6 changes: 3 additions & 3 deletions src/Database/Api/Repositories/InferenceRequestRepositoryBase.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
public abstract class InferenceRequestRepositoryBase : IInferenceRequestRepository
{
private readonly ILogger _logger;
private readonly IOptions<InformaticsGatewayConfiguration> _options;
private readonly IOptions<DatabaseOptions> _options;

protected InferenceRequestRepositoryBase(
ILogger logger,
IOptions<InformaticsGatewayConfiguration> options)
IOptions<DatabaseOptions> options)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_options = options ?? throw new ArgumentNullException(nameof(options));
Expand Down Expand Up @@ -72,7 +72,7 @@ public async Task UpdateAsync(InferenceRequest inferenceRequest, InferenceReques
}
else
{
if (++inferenceRequest.TryCount > _options.Value.Database.Retries.DelaysMilliseconds.Length)
if (++inferenceRequest.TryCount > _options.Value.Retries.DelaysMilliseconds.Length)
{
_logger.InferenceRequestUpdateExceededMaximumRetries();
inferenceRequest.State = InferenceRequestState.Completed;
Expand Down
3 changes: 1 addition & 2 deletions src/Database/Api/StorageMetadataWrapper.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace Monai.Deploy.InformaticsGateway.Database.Api
/// </summary>
public class StorageMetadataWrapper : MongoDBEntityBase
{
private readonly JsonSerializerOptions _options;

[JsonPropertyName("correlationId")]
public string CorrelationId { get; set; } = string.Empty;
Expand Down Expand Up @@ -92,4 +91,4 @@ public override string ToString()
return $"Identity: {Identity}";
}
}
}
}
26 changes: 14 additions & 12 deletions src/Database/DatabaseManager.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Monai.Deploy.InformaticsGateway.Configuration;
using Monai.Deploy.InformaticsGateway.Database.Api;
using Monai.Deploy.InformaticsGateway.Database.Api.Repositories;
using Monai.Deploy.InformaticsGateway.Database.EntityFramework;
Expand Down Expand Up @@ -63,16 +64,17 @@
}
}

public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection, ILogger logger)
=> services.ConfigureDatabase(connectionStringConfigurationSection, new FileSystem(), logger);
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection, IConfigurationSection? pluginsConfigurationSection, ILoggerFactory loggerFactory)
=> services.ConfigureDatabase(connectionStringConfigurationSection, pluginsConfigurationSection, new FileSystem(), loggerFactory);

public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection, IFileSystem fileSystem, ILogger logger)
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection, IConfigurationSection? pluginsConfigurationSection, IFileSystem fileSystem, ILoggerFactory loggerFactory)
{

if (connectionStringConfigurationSection is null)
{
throw new ConfigurationException("No database connections found in configuration section 'ConnectionStrings'.");
}

services.Configure<DatabaseOptions>(connectionStringConfigurationSection.GetSection("DatabaseOptions"));
var databaseType = connectionStringConfigurationSection["Type"].ToLowerInvariant();
switch (databaseType)
{
Expand All @@ -90,13 +92,11 @@
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(EntityFramework.Repositories.DicomAssociationInfoRepository));
services.AddScoped(typeof(IVirtualApplicationEntityRepository), typeof(EntityFramework.Repositories.VirtualApplicationEntityRepository));

services.ConfigureDatabaseFromPlugIns(DatabaseType.EntityFramework, fileSystem, connectionStringConfigurationSection, logger);
services.ConfigureDatabaseFromPlugIns(DatabaseType.EntityFramework, fileSystem, connectionStringConfigurationSection, pluginsConfigurationSection, loggerFactory);
return services;

case DbType_MongoDb:
services.AddSingleton<IMongoClient, MongoClient>(s => new MongoClient(connectionStringConfigurationSection[SR.DatabaseConnectionStringKey]));
services.Configure<DatabaseOptions>(connectionStringConfigurationSection);

services.AddScoped<IDatabaseMigrationManager, MongoDatabaseMigrationManager>();
services.AddScoped(typeof(IDestinationApplicationEntityRepository), typeof(MongoDB.Repositories.DestinationApplicationEntityRepository));
services.AddScoped(typeof(IInferenceRequestRepository), typeof(MongoDB.Repositories.InferenceRequestRepository));
Expand All @@ -107,7 +107,7 @@
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(MongoDB.Repositories.DicomAssociationInfoRepository));
services.AddScoped(typeof(IVirtualApplicationEntityRepository), typeof(MongoDB.Repositories.VirtualApplicationEntityRepository));

services.ConfigureDatabaseFromPlugIns(DatabaseType.MongoDb, fileSystem, connectionStringConfigurationSection, logger);
services.ConfigureDatabaseFromPlugIns(DatabaseType.MongoDb, fileSystem, connectionStringConfigurationSection, pluginsConfigurationSection, loggerFactory);

Check warning on line 110 in src/Database/DatabaseManager.cs

View check run for this annotation

Codecov / codecov/patch

src/Database/DatabaseManager.cs#L110

Added line #L110 was not covered by tests

return services;

Expand All @@ -120,7 +120,8 @@
DatabaseType databaseType,
IFileSystem fileSystem,
IConfigurationSection? connectionStringConfigurationSection,
ILogger logger)
IConfigurationSection? pluginsConfigurationSection,
ILoggerFactory loggerFactory)
{
Guard.Against.Null(fileSystem, nameof(fileSystem));

Expand All @@ -133,7 +134,7 @@
{
throw new ConfigurationException($"Error activating database registration from type '{type.FullName}'.");
}
registrar.Configure(services, databaseType, connectionStringConfigurationSection?[SR.DatabaseConnectionStringKey], logger);
registrar.Configure(services, databaseType, connectionStringConfigurationSection, pluginsConfigurationSection, loggerFactory);
}
return services;
}
Expand All @@ -153,6 +154,7 @@
return matchingTypes.ToArray();
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("SonarLint", "S3885", Justification = "assembly.Load does not full register the contents, but assembly.LoadFrom does, this is need to load .dlls from the plug-ins folder that plugins use")]
internal static Assembly[] LoadAssemblyFromPlugInsDirectory(IFileSystem fileSystem)
{
Guard.Against.Null(fileSystem, nameof(fileSystem));
Expand All @@ -167,8 +169,8 @@

foreach (var plugin in plugins)
{
var asesmblyeData = fileSystem.File.ReadAllBytes(plugin);
assemblies.Add(Assembly.Load(asesmblyeData));

assemblies.Add(Assembly.LoadFrom(plugin));
neildsouth marked this conversation as resolved.
Show resolved Hide resolved
}
return assemblies.ToArray();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/EntityFramework/Configuration/DicomAssociationInfoConfiguration.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class DicomAssociationInfoConfiguration : IEntityTypeConfiguration<Dico
public void Configure(EntityTypeBuilder<DicomAssociationInfo> builder)
{
var comparer = new ValueComparer<HashSet<string>>(
(c1, c2) => c1.SequenceEqual(c2),
(c1, c2) => c1!.SequenceEqual(c2!),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => c.ToHashSet());

Expand All @@ -50,7 +50,7 @@ public void Configure(EntityTypeBuilder<DicomAssociationInfo> builder)
builder.Property(j => j.PayloadIds).IsRequired()
.HasConversion(
v => JsonSerializer.Serialize(v, jsonSerializerSettings),
v => JsonSerializer.Deserialize<HashSet<string>>(v, jsonSerializerSettings))
v => JsonSerializer.Deserialize<HashSet<string>>(v, jsonSerializerSettings) ?? new HashSet<string>())
.Metadata.SetValueComparer(comparer);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/EntityFramework/Repositories/DestinationApplicationEntityRepository.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DestinationApplicationEntityRepository : IDestinationApplicationEnt
public DestinationApplicationEntityRepository(
IServiceScopeFactory serviceScopeFactory,
ILogger<DestinationApplicationEntityRepository> logger,
IOptions<InformaticsGatewayConfiguration> options)
IOptions<DatabaseOptions> options)
{
Guard.Against.Null(serviceScopeFactory, nameof(serviceScopeFactory));
Guard.Against.Null(options, nameof(options));
Expand All @@ -51,7 +51,7 @@ public DestinationApplicationEntityRepository(
_scope = serviceScopeFactory.CreateScope();
_informaticsGatewayContext = _scope.ServiceProvider.GetRequiredService<InformaticsGatewayContext>();
_retryPolicy = Policy.Handle<Exception>().WaitAndRetryAsync(
options.Value.Database.Retries.RetryDelays,
options.Value.Retries.RetryDelays,
(exception, timespan, count, context) => _logger.DatabaseErrorRetry(timespan, count, exception));
_dataset = _informaticsGatewayContext.Set<DestinationApplicationEntity>();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/EntityFramework/Repositories/DicomAssociationInfoRepository.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DicomAssociationInfoRepository : IDicomAssociationInfoRepository, I
public DicomAssociationInfoRepository(
IServiceScopeFactory serviceScopeFactory,
ILogger<DicomAssociationInfoRepository> logger,
IOptions<InformaticsGatewayConfiguration> options)
IOptions<DatabaseOptions> options)
{
Guard.Against.Null(serviceScopeFactory, nameof(serviceScopeFactory));
Guard.Against.Null(options, nameof(options));
Expand All @@ -50,7 +50,7 @@ public DicomAssociationInfoRepository(
_scope = serviceScopeFactory.CreateScope();
_informaticsGatewayContext = _scope.ServiceProvider.GetRequiredService<InformaticsGatewayContext>();
_retryPolicy = Policy.Handle<Exception>().WaitAndRetryAsync(
options.Value.Database.Retries.RetryDelays,
options.Value.Retries.RetryDelays,
(exception, timespan, count, context) => _logger.DatabaseErrorRetry(timespan, count, exception));
_dataset = _informaticsGatewayContext.Set<DicomAssociationInfo>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public class InferenceRequestRepository : InferenceRequestRepositoryBase, IDispo
public InferenceRequestRepository(
IServiceScopeFactory serviceScopeFactory,
ILogger<InferenceRequestRepository> logger,
IOptions<InformaticsGatewayConfiguration> options) : base(logger, options)
IOptions<DatabaseOptions> options) : base(logger, options)
{
Guard.Against.Null(serviceScopeFactory, nameof(serviceScopeFactory));

_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_scope = serviceScopeFactory.CreateScope();
_informaticsGatewayContext = _scope.ServiceProvider.GetRequiredService<InformaticsGatewayContext>();
_retryPolicy = Policy.Handle<Exception>().WaitAndRetryAsync(
options.Value.Database.Retries.RetryDelays,
options.Value.Retries.RetryDelays,
(exception, timespan, count, context) => _logger.DatabaseErrorRetry(timespan, count, exception));
_dataset = _informaticsGatewayContext.Set<InferenceRequest>();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/EntityFramework/Repositories/MonaiApplicationEntityRepository.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class MonaiApplicationEntityRepository : IMonaiApplicationEntityRepositor
public MonaiApplicationEntityRepository(
IServiceScopeFactory serviceScopeFactory,
ILogger<MonaiApplicationEntityRepository> logger,
IOptions<InformaticsGatewayConfiguration> options)
IOptions<DatabaseOptions> options)
{
Guard.Against.Null(serviceScopeFactory, nameof(serviceScopeFactory));
Guard.Against.Null(options, nameof(options));
Expand All @@ -51,7 +51,7 @@ public MonaiApplicationEntityRepository(
_scope = serviceScopeFactory.CreateScope();
_informaticsGatewayContext = _scope.ServiceProvider.GetRequiredService<InformaticsGatewayContext>();
_retryPolicy = Policy.Handle<Exception>().WaitAndRetryAsync(
options.Value.Database.Retries.RetryDelays,
options.Value.Retries.RetryDelays,
(exception, timespan, count, context) => _logger.DatabaseErrorRetry(timespan, count, exception));
_dataset = _informaticsGatewayContext.Set<MonaiApplicationEntity>();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/EntityFramework/Repositories/PayloadRepository.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PayloadRepository : IPayloadRepository, IDisposable
public PayloadRepository(
IServiceScopeFactory serviceScopeFactory,
ILogger<PayloadRepository> logger,
IOptions<InformaticsGatewayConfiguration> options)
IOptions<DatabaseOptions> options)
{
Guard.Against.Null(serviceScopeFactory, nameof(serviceScopeFactory));
Guard.Against.Null(options, nameof(options));
Expand All @@ -50,7 +50,7 @@ public PayloadRepository(
_scope = serviceScopeFactory.CreateScope();
_informaticsGatewayContext = _scope.ServiceProvider.GetRequiredService<InformaticsGatewayContext>();
_retryPolicy = Policy.Handle<Exception>().WaitAndRetryAsync(
options.Value.Database.Retries.RetryDelays,
options.Value.Retries.RetryDelays,
(exception, timespan, count, context) => _logger.DatabaseErrorRetry(timespan, count, exception));
_dataset = _informaticsGatewayContext.Set<Payload>();
}
Expand Down
Loading
Loading