Skip to content

Commit 4633527

Browse files
committed
Refactor storage layer (#75)
* Refactor messaging broker layer Signed-off-by: Victor Chang <[email protected]> * Refactor storage layer Signed-off-by: Victor Chang <[email protected]> * Fix default storage service assembly name Signed-off-by: Victor Chang <[email protected]> * Fix integration test configs Signed-off-by: Victor Chang <[email protected]>
1 parent 2242031 commit 4633527

34 files changed

+200
-116
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Please refer to the latest [user guide](./docs/setup/setup.md) for installation
4343
During development, change any settings inside the `appsettings.Development.json` file.
4444
First, export the following environment variable before executing `dotnet run`:
4545

46-
#### Linux
46+
#### Bash
4747

4848
```bash
4949
export DOTNET_ENVIRONMENT=Development

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SPDX-License-Identifier: Apache License 2.0
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>
2323
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
24-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.47" />
24+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.25" />
2525
<PackageReference Include="xRetry" Version="1.8.0" />
2626
<PackageReference Include="xunit" Version="2.4.1" />
2727
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">

src/CLI/Monai.Deploy.InformaticsGateway.CLI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ SPDX-License-Identifier: Apache License 2.0
5151
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
5252
<PackageReference Include="System.CommandLine.Hosting" Version="0.3.0-alpha.21216.1" />
5353
<PackageReference Include="System.CommandLine.Rendering" Version="0.3.0-alpha.21216.1" />
54-
<PackageReference Include="System.IO.Abstractions" Version="16.1.23" />
54+
<PackageReference Include="System.IO.Abstractions" Version="16.1.25" />
5555
</ItemGroup>
5656
</Project>

src/CLI/Test/Monai.Deploy.InformaticsGateway.CLI.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
2424
<PackageReference Include="Moq" Version="4.17.2" />
2525
<PackageReference Include="System.CommandLine.Hosting" Version="0.3.0-alpha.21216.1" />
26-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.23" />
26+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.25" />
2727
<PackageReference Include="xRetry" Version="1.8.0" />
2828
<PackageReference Include="xunit" Version="2.4.1" />
2929
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">

src/Common/Monai.Deploy.InformaticsGateway.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PackageReference Include="GitVersion.MsBuild" Version="5.9.0">
2121
<PrivateAssets>All</PrivateAssets>
2222
</PackageReference>
23-
<PackageReference Include="System.IO.Abstractions" Version="16.1.23" />
23+
<PackageReference Include="System.IO.Abstractions" Version="16.1.25" />
2424
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="6.0.0" />
2525
</ItemGroup>
2626

src/Common/Test/Monai.Deploy.InformaticsGateway.Common.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SPDX-License-Identifier: Apache License 2.0
1919
</PackageReference>
2020
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
2121
<PackageReference Include="Moq" Version="4.17.2" />
22-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.23" />
22+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.25" />
2323
<PackageReference Include="xunit" Version="2.4.1" />
2424
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2525
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Configuration/ConfigurationException.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ namespace Monai.Deploy.InformaticsGateway.Configuration
1313
[Serializable]
1414
public class ConfigurationException : Exception
1515
{
16+
public ConfigurationException()
17+
{
18+
}
19+
1620
public ConfigurationException(string message) : base(message)
1721
{
1822
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SPDX-License-Identifier: Apache License 2.0
2020
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
2121
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
2222
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
23-
<PackageReference Include="System.IO.Abstractions" Version="16.1.23" />
23+
<PackageReference Include="System.IO.Abstractions" Version="16.1.25" />
2424
</ItemGroup>
2525

2626
<ItemGroup>
@@ -37,5 +37,6 @@ SPDX-License-Identifier: Apache License 2.0
3737
<ProjectReference Include="..\Api\Monai.Deploy.InformaticsGateway.Api.csproj" />
3838
<ProjectReference Include="..\Common\Monai.Deploy.InformaticsGateway.Common.csproj" />
3939
<ProjectReference Include="..\MessageBroker\RabbitMq\Monai.Deploy.MessageBroker.csproj" />
40+
<ProjectReference Include="..\Storage\MinIo\Monai.Deploy.Storage.csproj" />
4041
</ItemGroup>
4142
</Project>

src/Configuration/ServiceCredentials.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Configuration/StorageConfiguration.cs

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
// SPDX-License-Identifier: Apache License 2.0
44

55
using System.IO.Abstractions;
6+
using Microsoft.Extensions.Configuration;
7+
using Monai.Deploy.Storage.Common;
68
using Newtonsoft.Json;
79

810
namespace Monai.Deploy.InformaticsGateway.Configuration
911
{
10-
public class StorageConfiguration
12+
public class StorageConfiguration : StorageServiceConfiguration
1113
{
1214
private readonly IFileSystem _fileSystem;
1315

1416
public StorageConfiguration() : this(new FileSystem())
15-
{
16-
}
17+
{ }
1718

18-
public StorageConfiguration(IFileSystem fileSystem)
19-
=> _fileSystem = fileSystem ?? throw new System.ArgumentNullException(nameof(fileSystem));
19+
public StorageConfiguration(IFileSystem fileSystem) => _fileSystem = fileSystem ?? throw new System.ArgumentNullException(nameof(fileSystem));
2020

2121
/// <summary>
2222
/// Gets or sets temporary storage path.
2323
/// This is used to store all instances received to a temporary folder.
2424
/// </summary>
2525
/// <value></value>
26-
[JsonProperty(PropertyName = "temporary")]
26+
[ConfigurationKeyName("temporary")]
2727
public string Temporary { get; set; } = "./payloads";
2828

2929
/// <summary>
@@ -33,7 +33,7 @@ public StorageConfiguration(IFileSystem fileSystem)
3333
/// is above the watermark.
3434
/// </summary>
3535
/// <value></value>
36-
[JsonProperty(PropertyName = "watermarkPercent")]
36+
[ConfigurationKeyName("watermarkPercent")]
3737
public uint Watermark { get; set; } = 75;
3838

3939
/// <summary>
@@ -43,36 +43,15 @@ public StorageConfiguration(IFileSystem fileSystem)
4343
/// is less than the value.
4444
/// </summary>
4545
/// <value></value>
46-
[JsonProperty(PropertyName = "reserveSpaceGB")]
46+
[ConfigurationKeyName("reserveSpaceGB")]
4747
public uint ReserveSpaceGB { get; set; } = 5;
4848

49-
/// <summary>
50-
/// Gets or sets the a fully qualified type name of the storage service.
51-
/// The spcified type must implement <typeparam name="Monai.Deploy.InformaticsGateway.Api.Storage.IStorageService">IStorageService</typeparam> interface.
52-
/// The default storage service configured is MinIO.
53-
/// </summary>
54-
55-
[JsonProperty(PropertyName = "storageService")]
56-
public string StorageService { get; set; } = "Monai.Deploy.InformaticsGateway.Storage.MinIoStorageService, Monai.Deploy.InformaticsGateway.Storage.MinIo";
57-
58-
/// <summary>
59-
/// Gets or sets credentials used to access the storage service.
60-
/// </summary>
61-
[JsonProperty(PropertyName = "storageServiceCredentials")]
62-
public ServiceCredentials StorageServiceCredentials { get; set; }
63-
6449
/// <summary>
6550
/// Gets or sets retry options relate to saving files to temporary storage, processing payloads and uploading payloads to the storage service.
6651
/// </summary>
67-
[JsonProperty(PropertyName = "reties")]
52+
[ConfigurationKeyName("reties")]
6853
public RetryConfiguration Retries { get; set; } = new RetryConfiguration();
6954

70-
/// <summary>
71-
/// Gets or set whether to use secured connection to the storage service. Default is true.
72-
/// </summary>
73-
[JsonProperty(PropertyName = "securedConnection")]
74-
public bool SecuredConnection { get; set; } = true;
75-
7655
/// <summary>
7756
/// Gets or set number of threads used for payload upload. Default is 1;
7857
/// </summary>
@@ -90,7 +69,7 @@ public string TemporaryDataDirFullPath
9069
/// <summary>
9170
/// Gets or sets the name of the bucket where payloads are uploaded to.
9271
/// </summary>
93-
[JsonProperty(PropertyName = "storageServiceBucketName")]
94-
public string StorageServiceBucketName { get; set; }
72+
[ConfigurationKeyName("bucketName")]
73+
public string StorageServiceBucketName { get; set; } = string.Empty;
9574
}
9675
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SPDX-License-Identifier: Apache License 2.0
2424
</PackageReference>
2525
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
2626
<PackageReference Include="Moq" Version="4.17.2" />
27-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.23" />
27+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.25" />
2828
<PackageReference Include="xunit" Version="2.4.1" />
2929
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
3030
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/InformaticsGateway/Monai.Deploy.InformaticsGateway.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<ProjectReference Include="..\Database\Monai.Deploy.InformaticsGateway.Database.csproj" />
5656
<ProjectReference Include="..\DicomWebClient\Monai.Deploy.InformaticsGateway.DicomWeb.Client.csproj" />
5757
<ProjectReference Include="..\MessageBroker\RabbitMq\Monai.Deploy.MessageBroker.csproj" />
58-
<ProjectReference Include="..\Storage\MinIo\Monai.Deploy.InformaticsGateway.Storage.MinIo.csproj" />
58+
<ProjectReference Include="..\Storage\MinIo\Monai.Deploy.Storage.csproj" />
5959
</ItemGroup>
6060

6161
<ItemGroup>

src/InformaticsGateway/Program.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using Microsoft.Extensions.Hosting;
1414
using Microsoft.Extensions.Logging;
1515
using Microsoft.Extensions.Options;
16-
using Monai.Deploy.InformaticsGateway.Api.Storage;
1716
using Monai.Deploy.InformaticsGateway.Common;
1817
using Monai.Deploy.InformaticsGateway.Configuration;
1918
using Monai.Deploy.InformaticsGateway.Database;
@@ -23,9 +22,12 @@
2322
using Monai.Deploy.InformaticsGateway.Services.Http;
2423
using Monai.Deploy.InformaticsGateway.Services.Scp;
2524
using Monai.Deploy.InformaticsGateway.Services.Storage;
26-
using Monai.Deploy.InformaticsGateway.Storage;
2725
using Monai.Deploy.MessageBroker;
26+
using Monai.Deploy.MessageBroker.Common;
2827
using Monai.Deploy.MessageBroker.RabbitMq;
28+
using Monai.Deploy.Storage;
29+
using Monai.Deploy.Storage.Common;
30+
using Monai.Deploy.Storage.MinIo;
2931

3032
namespace Monai.Deploy.InformaticsGateway
3133
{
@@ -76,6 +78,17 @@ internal static IHostBuilder CreateHostBuilder(string[] args) =>
7678
.PostConfigure(options =>
7779
{
7880
});
81+
services.AddOptions<MessageBrokerServiceConfiguration>()
82+
.Bind(hostContext.Configuration.GetSection("InformaticsGateway:messaging"))
83+
.PostConfigure(options =>
84+
{
85+
});
86+
services.AddOptions<StorageServiceConfiguration>()
87+
.Bind(hostContext.Configuration.GetSection("InformaticsGateway:storage"))
88+
.PostConfigure(options =>
89+
{
90+
});
91+
7992
services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<InformaticsGatewayConfiguration>, ConfigurationValidator>());
8093

8194
services.AddDbContext<InformaticsGatewayContext>(
@@ -99,7 +112,7 @@ internal static IHostBuilder CreateHostBuilder(string[] args) =>
99112
var options = implementationFactory.GetService<IOptions<InformaticsGatewayConfiguration>>();
100113
var serviceProvider = implementationFactory.GetService<IServiceProvider>();
101114
var logger = implementationFactory.GetService<ILogger<Program>>();
102-
return serviceProvider.LocateService<IStorageService>(logger, options.Value.Storage.StorageService);
115+
return serviceProvider.LocateService<IStorageService>(logger, options.Value.Storage.ServiceAssemblyName);
103116
});
104117

105118
services.AddSingleton<RabbitMqMessagePublisherService>();

src/InformaticsGateway/Services/Connectors/PayloadNotificationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Monai.Deploy.InformaticsGateway.Services.Storage;
2626
using Monai.Deploy.MessageBroker;
2727
using Monai.Deploy.MessageBroker.Messages;
28+
using Monai.Deploy.Storage;
2829

2930
namespace Monai.Deploy.InformaticsGateway.Services.Connectors
3031
{

src/InformaticsGateway/Services/Export/ExportServiceBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Microsoft.Extensions.Options;
1717
using Monai.Deploy.InformaticsGateway.Api;
1818
using Monai.Deploy.InformaticsGateway.Api.Rest;
19-
using Monai.Deploy.InformaticsGateway.Api.Storage;
2019
using Monai.Deploy.InformaticsGateway.Common;
2120
using Monai.Deploy.InformaticsGateway.Configuration;
2221
using Monai.Deploy.InformaticsGateway.Logging;
@@ -25,6 +24,7 @@
2524
using Monai.Deploy.MessageBroker;
2625
using Monai.Deploy.MessageBroker.Common;
2726
using Monai.Deploy.MessageBroker.Messages;
27+
using Monai.Deploy.Storage;
2828
using Polly;
2929

3030
namespace Monai.Deploy.InformaticsGateway.Services.Export

src/InformaticsGateway/Test/Monai.Deploy.InformaticsGateway.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.3" />
2626
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
2727
<PackageReference Include="Moq" Version="4.17.2" />
28-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.23" />
28+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.25" />
2929
<PackageReference Include="xRetry" Version="1.8.0" />
3030
<PackageReference Include="xunit" Version="2.4.1" />
3131
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">

src/InformaticsGateway/Test/Services/Connectors/PayloadNotificationServiceTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Monai.Deploy.InformaticsGateway.SharedTest;
2020
using Monai.Deploy.MessageBroker;
2121
using Monai.Deploy.MessageBroker.Messages;
22+
using Monai.Deploy.Storage;
2223
using Moq;
2324
using xRetry;
2425
using Xunit;

src/InformaticsGateway/Test/Services/Export/DicomWebExportServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using Microsoft.Extensions.Logging;
1515
using Microsoft.Extensions.Options;
1616
using Monai.Deploy.InformaticsGateway.Api.Rest;
17-
using Monai.Deploy.InformaticsGateway.Api.Storage;
1817
using Monai.Deploy.InformaticsGateway.Common;
1918
using Monai.Deploy.InformaticsGateway.Configuration;
2019
using Monai.Deploy.InformaticsGateway.DicomWeb.Client;
@@ -25,6 +24,7 @@
2524
using Monai.Deploy.MessageBroker;
2625
using Monai.Deploy.MessageBroker.Common;
2726
using Monai.Deploy.MessageBroker.Messages;
27+
using Monai.Deploy.Storage;
2828
using Moq;
2929
using Moq.Protected;
3030
using xRetry;

src/InformaticsGateway/Test/Services/Export/ExportServiceBaseTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Logging;
1111
using Microsoft.Extensions.Options;
12-
using Monai.Deploy.InformaticsGateway.Api.Storage;
1312
using Monai.Deploy.InformaticsGateway.Configuration;
1413
using Monai.Deploy.InformaticsGateway.Services.Export;
1514
using Monai.Deploy.InformaticsGateway.Services.Storage;
1615
using Monai.Deploy.InformaticsGateway.SharedTest;
1716
using Monai.Deploy.MessageBroker;
1817
using Monai.Deploy.MessageBroker.Common;
1918
using Monai.Deploy.MessageBroker.Messages;
19+
using Monai.Deploy.Storage;
2020
using Moq;
2121
using xRetry;
2222
using Xunit;

src/InformaticsGateway/Test/Services/Export/ScuExportServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.Extensions.Logging;
1313
using Microsoft.Extensions.Options;
1414
using Monai.Deploy.InformaticsGateway.Api;
15-
using Monai.Deploy.InformaticsGateway.Api.Storage;
1615
using Monai.Deploy.InformaticsGateway.Common;
1716
using Monai.Deploy.InformaticsGateway.Configuration;
1817
using Monai.Deploy.InformaticsGateway.Repositories;
@@ -22,6 +21,7 @@
2221
using Monai.Deploy.MessageBroker;
2322
using Monai.Deploy.MessageBroker.Common;
2423
using Monai.Deploy.MessageBroker.Messages;
24+
using Monai.Deploy.Storage;
2525
using Moq;
2626
using xRetry;
2727
using Xunit;

src/InformaticsGateway/appsettings.Development.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
},
1212
"messaging": {
1313
"publisherSettings": {
14-
"endpoint": "192.168.20.156",
14+
"endpoint": "localhost",
1515
"username": "mdig",
1616
"password": "helloworld",
1717
"virtualHost": "monaideploy",
1818
"exchange": "monaideploy"
1919
},
2020
"subscriberSettings": {
21-
"endpoint": "192.168.20.156",
21+
"endpoint": "localhost",
2222
"username": "mdig",
2323
"password": "helloworld",
2424
"virtualHost": "monaideploy",
@@ -28,13 +28,13 @@
2828
},
2929
"storage": {
3030
"temporary": "./payloads",
31-
"storageServiceCredentials": {
32-
"endpoint": "192.168.20.156:9000",
31+
"bucketName": "igbucket",
32+
"settings": {
33+
"endpoint": "localhost:9000",
3334
"accessKey": "admin",
34-
"accessToken": "password"
35-
},
36-
"securedConnection": false,
37-
"storageServiceBucketName": "igbucket"
35+
"accessToken": "password",
36+
"securedConnection": false
37+
}
3838
}
3939
},
4040
"Logging": {

src/MessageBroker/RabbitMq/Common/MessageBrokerServiceConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Monai.Deploy.MessageBroker.Common
77
{
8-
public abstract class MessageBrokerServiceConfiguration
8+
public class MessageBrokerServiceConfiguration
99
{
1010
/// <summary>
1111
/// Gets or sets the a fully qualified type name of the message publisher service.

0 commit comments

Comments
 (0)