Skip to content

Commit 87d58c5

Browse files
committed
Add MongoDB support
Signed-off-by: Victor Chang <[email protected]>
1 parent be744ff commit 87d58c5

File tree

95 files changed

+2925
-400
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

+2925
-400
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ jobs:
235235
strategy:
236236
matrix:
237237
feature: [AcrApi, DicomDimseScp, DicomDimseScu, DicomWebExport, DicomWebStow, HealthLevel7, Fhir]
238+
database: [ef, mongodb]
238239
fail-fast: false
239240
env:
240241
TAG: ${{ needs.build.outputs.TAG }}
242+
DOTNET_TEST: ${{ matrix.database }}
241243
steps:
242244
- name: Checkout repository
243245
uses: actions/checkout@v3

docker-compose/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ services:
6868
networks:
6969
- monaideploy
7070
healthcheck:
71-
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/productiondb --quiet
71+
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/productiondb --quiet
7272
interval: 10s
7373
timeout: 10s
7474
retries: 5

src/Api/BaseApplicationEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Monai.Deploy.InformaticsGateway.Api
2323
/// <remarks>
2424
/// * [Application Entity](http://www.otpedia.com/entryDetails.cfm?id=137)
2525
/// </remarks>
26-
public class BaseApplicationEntity
26+
public class BaseApplicationEntity : MongoDBEntityBase
2727
{
2828
/// <summary>
2929
/// Gets or sets the unique name used to identify a DICOM application entity.

src/Api/Monai.Deploy.InformaticsGateway.Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</PackageReference>
3131
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
3232
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.10" />
33-
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.11" />
33+
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.17-rc0020" />
3434
<PackageReference Include="Monai.Deploy.Storage" Version="0.2.10" />
3535
</ItemGroup>
3636

src/Api/MonaiApplicationEntity.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
using System;
1819
using System.Collections.Generic;
1920
using System.ComponentModel.DataAnnotations;
2021
using System.ComponentModel.DataAnnotations.Schema;
@@ -44,7 +45,7 @@ namespace Monai.Deploy.InformaticsGateway.Api
4445
/// }
4546
/// </code>
4647
/// </example>
47-
public class MonaiApplicationEntity
48+
public class MonaiApplicationEntity : MongoDBEntityBase
4849
{
4950
/// <summary>
5051
/// Gets or sets the name of a MONAI DICOM application entity.
@@ -106,20 +107,11 @@ public void SetDefaultValues()
106107
Grouping = "0020,000D";
107108
}
108109

109-
if (Workflows is null)
110-
{
111-
Workflows = new List<string>();
112-
}
110+
Workflows ??= new List<string>();
113111

114-
if (IgnoredSopClasses is null)
115-
{
116-
IgnoredSopClasses = new List<string>();
117-
}
112+
IgnoredSopClasses ??= new List<string>();
118113

119-
if (AllowedSopClasses is null)
120-
{
121-
AllowedSopClasses = new List<string>();
122-
}
114+
AllowedSopClasses ??= new List<string>();
123115
}
124116
}
125117
}

src/Api/MongoDBEntityBase.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2022 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+
using System;
18+
19+
namespace Monai.Deploy.InformaticsGateway.Api
20+
{
21+
public abstract class MongoDBEntityBase
22+
{
23+
/// <summary>
24+
/// Gets or set the MongoDB associated identifier.
25+
/// </summary>
26+
public Guid Id { get; set; }
27+
28+
/// <summary>
29+
/// Gets or set the date and time the objects first created.
30+
/// </summary>
31+
public DateTime DateTimeCreated { get; set; }
32+
33+
protected MongoDBEntityBase()
34+
{
35+
Id = Guid.NewGuid();
36+
DateTimeCreated = DateTime.UtcNow;
37+
}
38+
}
39+
}

src/Api/Storage/Payload.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public enum PayloadState
4646
private readonly Stopwatch _lastReceived;
4747
private bool _disposedValue;
4848

49-
public Guid Id { get; }
49+
public Guid PayloadId { get; }
5050

5151
public uint Timeout { get; init; }
5252

@@ -66,22 +66,23 @@ public enum PayloadState
6666

6767
public bool HasTimedOut { get => ElapsedTime().TotalSeconds >= Timeout; }
6868

69-
public TimeSpan Elapsed { get { return DateTime.UtcNow.Subtract(DateTimeCreated); } }
69+
public TimeSpan Elapsed
70+
{ get { return DateTime.UtcNow.Subtract(DateTimeCreated); } }
7071

7172
public string CallingAeTitle { get => Files.OfType<DicomFileStorageMetadata>().Select(p => p.CallingAeTitle).FirstOrDefault(); }
7273

7374
public string CalledAeTitle { get => Files.OfType<DicomFileStorageMetadata>().Select(p => p.CalledAeTitle).FirstOrDefault(); }
7475

7576
public Payload(string key, string correlationId, uint timeout)
7677
{
77-
Guard.Against.NullOrWhiteSpace(key, nameof(key));
78+
Guard.Against.NullOrWhiteSpace(key);
7879

7980
Files = new List<FileStorageMetadata>();
8081
_lastReceived = new Stopwatch();
8182

8283
CorrelationId = correlationId;
8384
DateTimeCreated = DateTime.UtcNow;
84-
Id = Guid.NewGuid();
85+
PayloadId = Guid.NewGuid();
8586
Key = key;
8687
State = PayloadState.Created;
8788
RetryCount = 0;
@@ -90,7 +91,7 @@ public Payload(string key, string correlationId, uint timeout)
9091

9192
public void Add(FileStorageMetadata value)
9293
{
93-
Guard.Against.Null(value, nameof(value));
94+
Guard.Against.Null(value);
9495

9596
Files.Add(value);
9697
_lastReceived.Reset();

src/Client.Common/ProblemException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
4242
{
4343
if (info == null)
4444
{
45-
throw new ArgumentNullException("info");
45+
throw new ArgumentNullException(nameof(info));
4646
}
4747

4848
info.AddValue(nameof(ProblemDetails), ProblemDetails, typeof(ProblemDetails));

src/Common/ExtensionMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static string RemoveInvalidPathChars(this string input)
7373
/// <returns></returns>
7474
public static async Task<bool> Post<TInput>(this ActionBlock<TInput> actionBlock, TInput input, TimeSpan delay)
7575
{
76-
await Task.Delay(delay);
76+
await Task.Delay(delay).ConfigureAwait(false);
7777
return actionBlock.Post(input);
7878
}
7979
}

src/Common/Test/ExtensionMethodsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async Task GivenAnActionBlock_WhenPostWIithDelayIsCalled_ExpectADelayBefo
9090
});
9191

9292
stopwatch.Start();
93-
await actionBlock.Post(input, delay);
93+
await actionBlock.Post(input, delay).ConfigureAwait(false);
9494
}
9595
}
9696
}

src/Configuration/Monai.Deploy.InformaticsGateway.Configuration.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</PackageReference>
3131
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
3232
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
33-
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.11" />
33+
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.17-rc0020" />
3434
<PackageReference Include="Monai.Deploy.Storage" Version="0.2.10" />
3535
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
3636
</ItemGroup>

src/Database/Api/DatabaseException.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2022 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+
using System.Runtime.Serialization;
18+
19+
namespace Monai.Deploy.InformaticsGateway.Database.Api
20+
{
21+
[Serializable]
22+
public class DatabaseException : Exception
23+
{
24+
public DatabaseException()
25+
{
26+
}
27+
28+
public DatabaseException(string? message) : base(message)
29+
{
30+
}
31+
32+
public DatabaseException(string? message, Exception? innerException) : base(message, innerException)
33+
{
34+
}
35+
36+
protected DatabaseException(SerializationInfo info, StreamingContext context) : base(info, context)
37+
{
38+
}
39+
}
40+
}

src/Database/Api/Log.9000.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright 2022 MONAI Consortium
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,35 +16,44 @@
1616

1717
using Microsoft.Extensions.Logging;
1818

19-
namespace Monai.Deploy.InformaticsGateway.Database.EntityFramework.Logging
19+
namespace Monai.Deploy.InformaticsGateway.Database.Api.Logging
2020
{
2121
public static partial class Log
2222
{
23-
[LoggerMessage(EventId = 9100, Level = LogLevel.Error, Message = "Error performing database action. Waiting {timespan} before next retry. Retry attempt {retryCount}...")]
23+
[LoggerMessage(EventId = 9000, Level = LogLevel.Error, Message = "Error adding item {type} to the database.")]
24+
public static partial void ErrorAddItem(this ILogger logger, string @type, Exception ex);
25+
26+
[LoggerMessage(EventId = 9001, Level = LogLevel.Error, Message = "Error updating item {type} in the database.")]
27+
public static partial void ErrorUpdateItem(this ILogger logger, string @type, Exception ex);
28+
29+
[LoggerMessage(EventId = 9002, Level = LogLevel.Error, Message = "Error deleting item {type} from the database.")]
30+
public static partial void ErrorDeleteItem(this ILogger logger, string @type, Exception ex);
31+
32+
[LoggerMessage(EventId = 9003, Level = LogLevel.Error, Message = "Error performing database action. Waiting {timespan} before next retry. Retry attempt {retryCount}...")]
2433
public static partial void DatabaseErrorRetry(this ILogger logger, TimeSpan timespan, int retryCount, Exception ex);
2534

26-
[LoggerMessage(EventId = 9101, Level = LogLevel.Debug, Message = "Storage metadata saved to the database.")]
35+
[LoggerMessage(EventId = 9004, Level = LogLevel.Debug, Message = "Storage metadata saved to the database.")]
2736
public static partial void StorageMetadataSaved(this ILogger logger);
2837

29-
[LoggerMessage(EventId = 9102, Level = LogLevel.Error, Message = "Error querying pending inference request.")]
38+
[LoggerMessage(EventId = 9005, Level = LogLevel.Error, Message = "Error querying pending inference request.")]
3039
public static partial void ErrorQueryingForPendingInferenceRequest(this ILogger logger, Exception ex);
3140

32-
[LoggerMessage(EventId = 9103, Level = LogLevel.Debug, Message = "Inference request saved.")]
41+
[LoggerMessage(EventId = 9006, Level = LogLevel.Debug, Message = "Inference request saved.")]
3342
public static partial void InferenceRequestSaved(this ILogger logger);
3443

35-
[LoggerMessage(EventId = 9104, Level = LogLevel.Warning, Message = "Exceeded maximum retries.")]
44+
[LoggerMessage(EventId = 9007, Level = LogLevel.Warning, Message = "Exceeded maximum retries.")]
3645
public static partial void InferenceRequestUpdateExceededMaximumRetries(this ILogger logger);
3746

38-
[LoggerMessage(EventId = 9105, Level = LogLevel.Information, Message = "Failed to process inference request, will retry later.")]
47+
[LoggerMessage(EventId = 9008, Level = LogLevel.Information, Message = "Failed to process inference request, will retry later.")]
3948
public static partial void InferenceRequestUpdateRetryLater(this ILogger logger);
4049

41-
[LoggerMessage(EventId = 9106, Level = LogLevel.Debug, Message = "Updating request {transactionId} to InProgress.")]
50+
[LoggerMessage(EventId = 9009, Level = LogLevel.Debug, Message = "Updating request {transactionId} to InProgress.")]
4251
public static partial void InferenceRequestSetToInProgress(this ILogger logger, string transactionId);
4352

44-
[LoggerMessage(EventId = 9107, Level = LogLevel.Debug, Message = "Updating inference request.")]
53+
[LoggerMessage(EventId = 9010, Level = LogLevel.Debug, Message = "Updating inference request.")]
4554
public static partial void InferenceRequestUpdateState(this ILogger logger);
4655

47-
[LoggerMessage(EventId = 9108, Level = LogLevel.Information, Message = "Inference request updated.")]
56+
[LoggerMessage(EventId = 9011, Level = LogLevel.Information, Message = "Inference request updated.")]
4857
public static partial void InferenceRequestUpdated(this ILogger logger);
4958
}
5059
}

src/Database/Api/Repositories/IStorageMetadataRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface IStorageMetadataRepository
4646
/// Gets all storage metadata objects associated with the correlation ID.
4747
/// </summary>
4848
/// <param name="correlationId">Correlation ID</param>
49-
Task<IList<FileStorageMetadata?>> GetFileStorageMetdadataAsync(string correlationId, CancellationToken cancellationToken = default);
49+
Task<IList<FileStorageMetadata>> GetFileStorageMetdadataAsync(string correlationId, CancellationToken cancellationToken = default);
5050

5151
/// <summary>
5252
/// Gets the specified storage metadata object.

0 commit comments

Comments
 (0)