Skip to content

Commit bbaad93

Browse files
committed
change around config and fixs for plugins
Signed-off-by: Neil South <[email protected]>
1 parent 8ceee8a commit bbaad93

File tree

95 files changed

+1594
-369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1594
-369
lines changed

.github/workflows/package-cleanup.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
name: Cleanup Pre-release Packages
1818

1919
on:
20-
schedule:
21-
- cron: "0 0 * * *"
20+
# schedule:
21+
# - cron: "0 0 * * *"
2222
workflow_dispatch:
2323

2424
jobs:

Dockerfile

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

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

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

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

3131
# Enable elastic client compatibility mode
3232
ENV ELASTIC_CLIENT_APIVERSIONING=true

docs/api/rest/dicom-association.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!--
2+
~ Copyright 2021-2023 MONAI Consortium
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
# DICOM Association information
18+
19+
The `/dicom-associations' endpoint is for retrieving a list of information regarding dicom
20+
associations.
21+
22+
## GET /dicom-associations/
23+
24+
#### Query Parameters
25+
26+
| Name | Type | Description |
27+
|------------|----------|---------------------------------------------|
28+
| startTime | DateTime | (Optional) Start date to query from. |
29+
| endTime | DateTime | (Optional) End date to query from. |
30+
| pageNumber | Number | (Optional) Page number to query.(default 0) |
31+
| pageSize | Number | (Optional) Page size of query. |
32+
33+
Max & Defaults for PageSize can be set in appSettings.
34+
35+
```json
36+
"endpointSettings": {
37+
"defaultPageSize": number,
38+
"maxPageSize": number
39+
}
40+
```
41+
42+
Endpoint returns a paged result for example
43+
44+
```json
45+
{
46+
"PageNumber": 1,
47+
"PageSize": 10,
48+
"FirstPage": "/payload?pageNumber=1&pageSize=10",
49+
"LastPage": "/payload?pageNumber=1&pageSize=10",
50+
"TotalPages": 1,
51+
"TotalRecords": 3,
52+
"NextPage": null,
53+
"PreviousPage": null,
54+
"Data": [...]
55+
"Succeeded": true,
56+
"Errors": null,
57+
"Message": null
58+
}
59+
```

src/Client/Test/packages.lock.json

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@
19211921
"Microsoft.Extensions.Configuration": "[6.0.1, )",
19221922
"Microsoft.Extensions.Configuration.FileExtensions": "[6.0.0, )",
19231923
"Microsoft.Extensions.Configuration.Json": "[6.0.0, )",
1924+
"Microsoft.Extensions.Options.ConfigurationExtensions": "[6.0.0, )",
19241925
"Monai.Deploy.InformaticsGateway.Api": "[0.4.1, )",
19251926
"Monai.Deploy.InformaticsGateway.Configuration": "[1.0.0, )",
19261927
"Monai.Deploy.InformaticsGateway.Database.Api": "[1.0.0, )",

src/Configuration/DatabaseConfiguration.cs renamed to src/Configuration/HttpEndpointSettings.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright 2021-2022 MONAI Consortium
2+
* Copyright 2021-2023 MONAI Consortium
3+
* Copyright 2019-2021 NVIDIA Corporation
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
@@ -18,12 +19,12 @@
1819

1920
namespace Monai.Deploy.InformaticsGateway.Configuration
2021
{
21-
public class DatabaseConfiguration
22+
public class HttpEndpointSettings
2223
{
23-
/// <summary>
24-
/// Gets or sets retry options relate to reading/writing to the database.
25-
/// </summary>
26-
[ConfigurationKeyName("retries")]
27-
public RetryConfiguration Retries { get; set; } = new RetryConfiguration();
24+
[ConfigurationKeyName("defaultPageSize")]
25+
public int DefaultPageSize { get; set; } = 10;
26+
27+
[ConfigurationKeyName("maxPageSize")]
28+
public int MaxPageSize { get; set; } = 10;
2829
}
2930
}

src/Configuration/InformaticsGatewayConfiguration.cs

100644100755
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@ public class InformaticsGatewayConfiguration
7070
[ConfigurationKeyName("messaging")]
7171
public MessageBrokerConfiguration Messaging { get; set; }
7272

73-
/// <summary>
74-
/// Represents the <c>database</c> section of the configuration file.
75-
/// </summary>
76-
[ConfigurationKeyName("database")]
77-
public DatabaseConfiguration Database { get; set; }
78-
79-
/// <summary>
80-
/// Represents the <c>pluginConfiguration</c> section of the configuration file.
81-
/// </summary>
82-
[ConfigurationKeyName("plugins")]
83-
public PlugInConfiguration PlugInConfigurations { get; set; }
84-
8573
public InformaticsGatewayConfiguration()
8674
{
8775
Dicom = new DicomConfiguration();
@@ -90,9 +78,7 @@ public InformaticsGatewayConfiguration()
9078
Fhir = new FhirConfiguration();
9179
Export = new DataExportConfiguration();
9280
Messaging = new MessageBrokerConfiguration();
93-
Database = new DatabaseConfiguration();
9481
Hl7 = new Hl7Configuration();
95-
PlugInConfigurations = new PlugInConfiguration();
9682
}
9783
}
9884
}

src/Configuration/RetryConfiguration.cs

100644100755
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class RetryConfiguration
2929
/// Default is 250, 500, 1000.
3030
/// </summary>
3131
[ConfigurationKeyName("delays")]
32-
public int[] DelaysMilliseconds { get; set; } = new[] { 750, 1200, 2500 };
32+
public int[] DelaysMilliseconds { get; set; }
3333

3434
// Gets the delays in TimeSpan objects
3535
public IEnumerable<TimeSpan> RetryDelays
@@ -42,5 +42,12 @@ public IEnumerable<TimeSpan> RetryDelays
4242
}
4343
}
4444
}
45+
public RetryConfiguration()
46+
{
47+
if (DelaysMilliseconds is null || DelaysMilliseconds.Length == 0)
48+
{
49+
DelaysMilliseconds = new[] { 250, 500, 1000 };
50+
}
51+
}
4552
}
4653
}

src/Database/Api/DatabaseOptions.cs

100644100755
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@
1515
*/
1616

1717
using Microsoft.Extensions.Configuration;
18+
using Monai.Deploy.InformaticsGateway.Configuration;
1819

1920
namespace Monai.Deploy.InformaticsGateway.Database.Api
2021
{
2122
public class DatabaseOptions
2223
{
2324
[ConfigurationKeyName("DatabaseName")]
2425
public string DatabaseName { get; set; } = string.Empty;
26+
27+
/// <summary>
28+
/// Gets or sets retry options relate to reading/writing to the database.
29+
/// </summary>
30+
[ConfigurationKeyName("retries")]
31+
public RetryConfiguration Retries { get; set; } = new RetryConfiguration();
2532
}
2633
}

src/Database/Api/DatabaseRegistrationBase.cs

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17+
using Microsoft.Extensions.Configuration;
1718
using Microsoft.Extensions.DependencyInjection;
1819
using Microsoft.Extensions.Logging;
1920

2021
namespace Monai.Deploy.InformaticsGateway.Database.Api
2122
{
2223
public abstract class DatabaseRegistrationBase
2324
{
24-
public abstract IServiceCollection Configure(IServiceCollection services, DatabaseType databaseType, string? connectionString, ILogger logger);
25+
public abstract IServiceCollection Configure(IServiceCollection services, DatabaseType databaseType, IConfigurationSection? connectionstringConfigurationSection, IConfigurationSection? pluginsConfigurationSection, ILoggerFactory loggerFactory);
2526
}
2627
}

src/Database/Api/Repositories/IDicomAssociationInfoRepository.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,20 @@ public interface IDicomAssociationInfoRepository
2323
Task<List<DicomAssociationInfo>> ToListAsync(CancellationToken cancellationToken = default);
2424

2525
Task<DicomAssociationInfo> AddAsync(DicomAssociationInfo item, CancellationToken cancellationToken = default);
26+
27+
/// <summary>
28+
/// Retrieves a list of DicomAssociationInfo in the database.
29+
/// </summary>
30+
Task<IList<DicomAssociationInfo>> GetAllAsync(int skip,
31+
int? limit,
32+
DateTime startTime,
33+
DateTime endTime,
34+
CancellationToken cancellationToken);
35+
36+
/// <summary>
37+
/// Gets count of objects
38+
/// </summary>
39+
/// <returns>Count of objects.</returns>
40+
Task<long> CountAsync();
2641
}
2742
}

src/Database/Api/Repositories/InferenceRequestRepositoryBase.cs

100644100755
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@
1919
using Microsoft.Extensions.Options;
2020
using Monai.Deploy.InformaticsGateway.Api;
2121
using Monai.Deploy.InformaticsGateway.Api.Rest;
22-
using Monai.Deploy.InformaticsGateway.Configuration;
2322
using Monai.Deploy.InformaticsGateway.Database.Api.Logging;
2423

2524
namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
2625
{
2726
public abstract class InferenceRequestRepositoryBase : IInferenceRequestRepository
2827
{
2928
private readonly ILogger _logger;
30-
private readonly IOptions<InformaticsGatewayConfiguration> _options;
29+
private readonly IOptions<DatabaseOptions> _options;
3130

3231
protected InferenceRequestRepositoryBase(
3332
ILogger logger,
34-
IOptions<InformaticsGatewayConfiguration> options)
33+
IOptions<DatabaseOptions> options)
3534
{
3635
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
3736
_options = options ?? throw new ArgumentNullException(nameof(options));
@@ -72,7 +71,7 @@ public async Task UpdateAsync(InferenceRequest inferenceRequest, InferenceReques
7271
}
7372
else
7473
{
75-
if (++inferenceRequest.TryCount > _options.Value.Database.Retries.DelaysMilliseconds.Length)
74+
if (++inferenceRequest.TryCount > _options.Value.Retries.DelaysMilliseconds.Length)
7675
{
7776
_logger.InferenceRequestUpdateExceededMaximumRetries();
7877
inferenceRequest.State = InferenceRequestState.Completed;

src/Database/Api/StorageMetadataWrapper.cs

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Monai.Deploy.InformaticsGateway.Database.Api
2727
/// </summary>
2828
public class StorageMetadataWrapper : MongoDBEntityBase
2929
{
30-
private readonly JsonSerializerOptions _options;
30+
//private readonly JsonSerializerOptions _options;
3131

3232
[JsonPropertyName("correlationId")]
3333
public string CorrelationId { get; set; } = string.Empty;
@@ -92,4 +92,4 @@ public override string ToString()
9292
return $"Identity: {Identity}";
9393
}
9494
}
95-
}
95+
}

src/Database/DatabaseManager.cs

100644100755
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ public static IHealthChecksBuilder AddDatabaseHealthCheck(this IHealthChecksBuil
6363
}
6464
}
6565

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

69-
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection, IFileSystem fileSystem, ILogger logger)
69+
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection, IConfigurationSection? pluginsConfigurationSection, IFileSystem fileSystem, ILoggerFactory loggerFactory)
7070
{
71+
var logger = loggerFactory.CreateLogger("DatabaseManager");
72+
7173
if (connectionStringConfigurationSection is null)
7274
{
7375
throw new ConfigurationException("No database connections found in configuration section 'ConnectionStrings'.");
7476
}
75-
77+
services.Configure<DatabaseOptions>(connectionStringConfigurationSection.GetSection("DatabaseOptions"));
7678
var databaseType = connectionStringConfigurationSection["Type"].ToLowerInvariant();
7779
switch (databaseType)
7880
{
@@ -90,13 +92,12 @@ public static IServiceCollection ConfigureDatabase(this IServiceCollection servi
9092
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(EntityFramework.Repositories.DicomAssociationInfoRepository));
9193
services.AddScoped(typeof(IVirtualApplicationEntityRepository), typeof(EntityFramework.Repositories.VirtualApplicationEntityRepository));
9294

93-
services.ConfigureDatabaseFromPlugIns(DatabaseType.EntityFramework, fileSystem, connectionStringConfigurationSection, logger);
95+
services.ConfigureDatabaseFromPlugIns(DatabaseType.EntityFramework, fileSystem, connectionStringConfigurationSection, pluginsConfigurationSection, loggerFactory);
9496
return services;
9597

9698
case DbType_MongoDb:
99+
var terst = connectionStringConfigurationSection[SR.DatabaseConnectionStringKey];
97100
services.AddSingleton<IMongoClient, MongoClient>(s => new MongoClient(connectionStringConfigurationSection[SR.DatabaseConnectionStringKey]));
98-
services.Configure<DatabaseOptions>(connectionStringConfigurationSection);
99-
100101
services.AddScoped<IDatabaseMigrationManager, MongoDatabaseMigrationManager>();
101102
services.AddScoped(typeof(IDestinationApplicationEntityRepository), typeof(MongoDB.Repositories.DestinationApplicationEntityRepository));
102103
services.AddScoped(typeof(IInferenceRequestRepository), typeof(MongoDB.Repositories.InferenceRequestRepository));
@@ -107,7 +108,7 @@ public static IServiceCollection ConfigureDatabase(this IServiceCollection servi
107108
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(MongoDB.Repositories.DicomAssociationInfoRepository));
108109
services.AddScoped(typeof(IVirtualApplicationEntityRepository), typeof(MongoDB.Repositories.VirtualApplicationEntityRepository));
109110

110-
services.ConfigureDatabaseFromPlugIns(DatabaseType.MongoDb, fileSystem, connectionStringConfigurationSection, logger);
111+
services.ConfigureDatabaseFromPlugIns(DatabaseType.MongoDb, fileSystem, connectionStringConfigurationSection, pluginsConfigurationSection, loggerFactory);
111112

112113
return services;
113114

@@ -120,7 +121,8 @@ public static IServiceCollection ConfigureDatabaseFromPlugIns(this IServiceColle
120121
DatabaseType databaseType,
121122
IFileSystem fileSystem,
122123
IConfigurationSection? connectionStringConfigurationSection,
123-
ILogger logger)
124+
IConfigurationSection? pluginsConfigurationSection,
125+
ILoggerFactory loggerFactory)
124126
{
125127
Guard.Against.Null(fileSystem, nameof(fileSystem));
126128

@@ -133,7 +135,7 @@ public static IServiceCollection ConfigureDatabaseFromPlugIns(this IServiceColle
133135
{
134136
throw new ConfigurationException($"Error activating database registration from type '{type.FullName}'.");
135137
}
136-
registrar.Configure(services, databaseType, connectionStringConfigurationSection?[SR.DatabaseConnectionStringKey], logger);
138+
registrar.Configure(services, databaseType, connectionStringConfigurationSection, pluginsConfigurationSection, loggerFactory);
137139
}
138140
return services;
139141
}
@@ -167,8 +169,7 @@ internal static Assembly[] LoadAssemblyFromPlugInsDirectory(IFileSystem fileSyst
167169

168170
foreach (var plugin in plugins)
169171
{
170-
var asesmblyeData = fileSystem.File.ReadAllBytes(plugin);
171-
assemblies.Add(Assembly.Load(asesmblyeData));
172+
assemblies.Add(Assembly.LoadFrom(plugin));
172173
}
173174
return assemblies.ToArray();
174175
}

src/Database/EntityFramework/Configuration/DicomAssociationInfoConfiguration.cs

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal class DicomAssociationInfoConfiguration : IEntityTypeConfiguration<Dico
2929
public void Configure(EntityTypeBuilder<DicomAssociationInfo> builder)
3030
{
3131
var comparer = new ValueComparer<HashSet<string>>(
32-
(c1, c2) => c1.SequenceEqual(c2),
32+
(c1, c2) => c1!.SequenceEqual(c2!),
3333
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
3434
c => c.ToHashSet());
3535

@@ -50,7 +50,7 @@ public void Configure(EntityTypeBuilder<DicomAssociationInfo> builder)
5050
builder.Property(j => j.PayloadIds).IsRequired()
5151
.HasConversion(
5252
v => JsonSerializer.Serialize(v, jsonSerializerSettings),
53-
v => JsonSerializer.Deserialize<HashSet<string>>(v, jsonSerializerSettings))
53+
v => JsonSerializer.Deserialize<HashSet<string>>(v, jsonSerializerSettings) ?? new HashSet<string>())
5454
.Metadata.SetValueComparer(comparer);
5555
}
5656
}

0 commit comments

Comments
 (0)