Skip to content

Commit 59b76b2

Browse files
authored
Update Monai.Deploy.Messaging & Monai.Deploy.Storage to 0.1 official … (#96)
* Update Monai.Deploy.Messaging & Monai.Deploy.Storage to 0.1 official builds * Update storage GetObjectAsync call Signed-off-by: Victor Chang <[email protected]>
1 parent 4f43589 commit 59b76b2

16 files changed

+51
-102
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ SPDX-License-Identifier: Apache License 2.0
1919
</PackageReference>
2020
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
2121
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.6" />
22-
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.0-rc0046" />
23-
<PackageReference Include="Monai.Deploy.Storage" Version="0.1.0-rc0058" />
22+
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.2" />
23+
<PackageReference Include="Monai.Deploy.Storage" Version="0.1.1" />
2424
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
2525
</ItemGroup>
2626

src/CLI/Commands/DestinationCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.CommandLine;
7-
using System.CommandLine.Invocation;
87
using System.CommandLine.NamingConventionBinder;
98
using System.CommandLine.Rendering;
109
using System.CommandLine.Rendering.Views;
@@ -131,7 +130,7 @@ private async Task<int> ListDestinationHandlerAsync(DestinationApplicationEntity
131130
table.AddColumn(p => p.HostIp, new ContentView("Host/IP Address".Underline()));
132131
table.AddColumn(p => p.Port, new ContentView("Port".Underline()));
133132
table.Render(consoleRenderer, consoleRegion.GetDefaultConsoleRegion());
134-
133+
135134
logger.ListedNItems(items.Count);
136135
}
137136
return ExitCodes.Success;

src/CLI/Commands/SourceCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.CommandLine;
7-
using System.CommandLine.Invocation;
87
using System.CommandLine.NamingConventionBinder;
98
using System.CommandLine.Rendering;
109
using System.CommandLine.Rendering.Views;
@@ -127,7 +126,7 @@ private async Task<int> ListSourceHandlerAsync(SourceApplicationEntity entity, I
127126
table.AddColumn(p => p.AeTitle, new ContentView("AE Title".Underline()));
128127
table.AddColumn(p => p.HostIp, new ContentView("Host/IP Address".Underline()));
129128
table.Render(consoleRenderer, consoleRegion.GetDefaultConsoleRegion());
130-
129+
131130
logger.ListedNItems(items.Count);
132131
}
133132
return ExitCodes.Success;

src/CLI/Commands/StartCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache License 2.0
33

44
using System;
5-
using System.CommandLine.Invocation;
65
using System.CommandLine.NamingConventionBinder;
76
using System.Threading;
87
using System.Threading.Tasks;

src/CLI/Commands/StatusCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache License 2.0
33

44
using System;
5-
using System.CommandLine.Invocation;
65
using System.CommandLine.NamingConventionBinder;
76
using System.Threading;
87
using System.Threading.Tasks;

src/CLI/Commands/StopCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache License 2.0
33

44
using System;
5-
using System.CommandLine.Invocation;
65
using System.CommandLine.NamingConventionBinder;
76
using System.Threading;
87
using System.Threading.Tasks;

src/Client/Services/HealthService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache License 2.0
33

44
using System.Net.Http;
5-
using System.Net.Http.Json;
65
using System.Threading;
76
using System.Threading.Tasks;
87
using Ardalis.GuardClauses;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ SPDX-License-Identifier: Apache License 2.0
1919
</PackageReference>
2020
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
2121
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
22-
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.0-rc0046" />
23-
<PackageReference Include="Monai.Deploy.Storage" Version="0.1.0-rc0058" />
22+
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.2" />
23+
<PackageReference Include="Monai.Deploy.Storage" Version="0.1.1" />
2424
<PackageReference Include="System.IO.Abstractions" Version="17.0.18" />
2525
</ItemGroup>
2626

src/InformaticsGateway/Monai.Deploy.InformaticsGateway.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
3434
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
3535
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
36-
<PackageReference Include="Monai.Deploy.Storage" Version="0.1.0-rc0058" />
36+
<PackageReference Include="Monai.Deploy.Storage" Version="0.1.1" />
3737
<PackageReference Include="Polly" Version="7.2.3" />
3838
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
3939
</ItemGroup>

src/InformaticsGateway/Services/Export/ExportServiceBase.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private void OnMessageReceivedCallback(MessageReceivedEventArgs eventArgs)
128128
};
129129

130130
var exportFlow = new TransformManyBlock<ExportRequestEventDetails, ExportRequestDataMessage>(
131-
(exportRequest) => DownloadPayloadActionCallback(exportRequest, _cancellationTokenSource.Token),
131+
exportRequest => DownloadPayloadActionCallback(exportRequest, _cancellationTokenSource.Token),
132132
executionOptions);
133133

134134
var exportActionBlock = new TransformBlock<ExportRequestDataMessage, ExportRequestDataMessage>(
@@ -180,6 +180,8 @@ private void OnMessageReceivedCallback(MessageReceivedEventArgs eventArgs)
180180
}
181181
}
182182

183+
// TPL doesn't yet support IAsyncEnumerable
184+
// https://github.com/dotnet/runtime/issues/30863
183185
private IEnumerable<ExportRequestDataMessage> DownloadPayloadActionCallback(ExportRequestEventDetails exportRequest, CancellationToken cancellationToken)
184186
{
185187
Guard.Against.Null(exportRequest, nameof(exportRequest));
@@ -193,27 +195,23 @@ private IEnumerable<ExportRequestDataMessage> DownloadPayloadActionCallback(Expo
193195
try
194196
{
195197
_logger.DownloadingFile(file);
196-
Policy
198+
var task = Policy
197199
.Handle<Exception>()
198-
.WaitAndRetry(
200+
.WaitAndRetryAsync(
199201
_configuration.Export.Retries.RetryDelays,
200202
(exception, timeSpan, retryCount, context) =>
201203
{
202204
_logger.ErrorDownloadingPayloadWithRetry(exception, timeSpan, retryCount);
203205
})
204-
.Execute(() =>
206+
.ExecuteAsync(async () =>
205207
{
206208
_logger.DownloadingFile(file);
207-
var task = storageService.GetObjectAsync(_configuration.Storage.StorageServiceBucketName, file, (stream) =>
208-
{
209-
using var memoryStream = new MemoryStream();
210-
stream.CopyTo(memoryStream);
211-
exportRequestData.SetData(memoryStream.ToArray());
212-
}, cancellationToken);
213-
214-
task.Wait();
209+
var stream = await storageService.GetObjectAsync(_configuration.Storage.StorageServiceBucketName, file, cancellationToken).ConfigureAwait(false) as MemoryStream;
210+
exportRequestData.SetData(stream.ToArray());
215211
_logger.FileReadyForExport(file);
216212
});
213+
214+
task.Wait();
217215
}
218216
catch (Exception ex)
219217
{

src/InformaticsGateway/Test/DummyStorageService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ internal class DummyStorageService : IStorageService
3636

3737
public Task<Credentials> CreateTemporaryCredentialsAsync(string bucketName, string folderName, int durationSeconds = 3600, CancellationToken cancellationToken = default) => throw new NotImplementedException();
3838

39-
public Task GetObjectAsync(string bucketName, string objectName, Action<Stream> callback, CancellationToken cancellationToken = default) => throw new NotImplementedException();
39+
public Task<Stream> GetObjectAsync(string bucketName, string objectName, CancellationToken cancellationToken = default) => throw new NotImplementedException();
4040

41-
public Task GetObjectWithCredentialsAsync(string bucketName, string objectName, Credentials credentials, Action<Stream> callback, CancellationToken cancellationToken = default) => throw new NotImplementedException();
41+
public Task<Stream> GetObjectWithCredentialsAsync(string bucketName, string objectName, Credentials credentials, CancellationToken cancellationToken = default) => throw new NotImplementedException();
4242

4343
public Task<IList<VirtualFileInfo>> ListObjectsAsync(string bucketName, string prefix = "", bool recursive = false, CancellationToken cancellationToken = default) => throw new NotImplementedException();
4444

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,8 @@ public async Task ExportDataBlockCallback_ReturnsNullIfInferenceRequestCannotBeF
122122
messageReceivedCallback(CreateMessageReceivedEventArgs(transactionId));
123123
});
124124

125-
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<Stream>>(), It.IsAny<CancellationToken>()))
126-
.Callback<string, string, Action<Stream>, CancellationToken>((bucketName, objectName, callback, cancellationToken) =>
127-
{
128-
callback(new MemoryStream(Encoding.UTF8.GetBytes("test")));
129-
});
125+
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
126+
.ReturnsAsync(new MemoryStream(Encoding.UTF8.GetBytes("test")));
130127

131128
_inferenceRequestStore.Setup(p => p.GetInferenceRequest(It.IsAny<string>())).Returns((InferenceRequest)null);
132129

@@ -182,11 +179,8 @@ public async Task ExportDataBlockCallback_ReturnsNullIfInferenceRequestContainsN
182179
messageReceivedCallback(CreateMessageReceivedEventArgs(transactionId));
183180
});
184181

185-
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<Stream>>(), It.IsAny<CancellationToken>()))
186-
.Callback<string, string, Action<Stream>, CancellationToken>((bucketName, objectName, callback, cancellationToken) =>
187-
{
188-
callback(new MemoryStream(Encoding.UTF8.GetBytes("test")));
189-
});
182+
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
183+
.ReturnsAsync(new MemoryStream(Encoding.UTF8.GetBytes("test")));
190184

191185
_inferenceRequestStore.Setup(p => p.GetInferenceRequest(It.IsAny<string>())).Returns(inferenceRequest);
192186

@@ -254,11 +248,8 @@ public async Task ExportDataBlockCallback_RecordsStowFailuresAndReportFailure()
254248
messageReceivedCallback(CreateMessageReceivedEventArgs(transactionId));
255249
});
256250

257-
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<Stream>>(), It.IsAny<CancellationToken>()))
258-
.Callback<string, string, Action<Stream>, CancellationToken>((bucketName, objectName, callback, cancellationToken) =>
259-
{
260-
callback(new MemoryStream(Encoding.UTF8.GetBytes("test")));
261-
});
251+
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
252+
.ReturnsAsync(new MemoryStream(Encoding.UTF8.GetBytes("test")));
262253

263254
_inferenceRequestStore.Setup(p => p.GetInferenceRequest(It.IsAny<string>())).Returns(inferenceRequest);
264255
_dicomToolkit.Setup(p => p.Load(It.IsAny<byte[]>())).Returns(InstanceGenerator.GenerateDicomFile(sopInstanceUid: sopInstanceUid));
@@ -343,11 +334,8 @@ public async Task CompletesDataflow(HttpStatusCode httpStatusCode)
343334
messageReceivedCallback(CreateMessageReceivedEventArgs(transactionId));
344335
});
345336

346-
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<Stream>>(), It.IsAny<CancellationToken>()))
347-
.Callback<string, string, Action<Stream>, CancellationToken>((bucketName, objectName, callback, cancellationToken) =>
348-
{
349-
callback(new MemoryStream(Encoding.UTF8.GetBytes("test")));
350-
});
337+
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
338+
.ReturnsAsync(new MemoryStream(Encoding.UTF8.GetBytes("test")));
351339

352340
_inferenceRequestStore.Setup(p => p.GetInferenceRequest(It.IsAny<string>())).Returns(inferenceRequest);
353341
_dicomToolkit.Setup(p => p.Load(It.IsAny<byte[]>())).Returns(InstanceGenerator.GenerateDicomFile());

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using Monai.Deploy.Messaging.Common;
1818
using Monai.Deploy.Messaging.Events;
1919
using Monai.Deploy.Messaging.Messages;
20-
using Monai.Deploy.Storage;
2120
using Monai.Deploy.Storage.API;
2221
using Moq;
2322
using xRetry;
@@ -156,12 +155,9 @@ public async Task DataflowTest_PayloadDownlaodFailure()
156155
messageReceivedCallback(CreateMessageReceivedEventArgs());
157156
});
158157

159-
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<Stream>>(), It.IsAny<CancellationToken>()))
160-
.Callback<string, string, Action<Stream>, CancellationToken>((bucketName, objectName, callback, cancellationToken) =>
161-
{
162-
callback(Stream.Null);
163-
throw new Exception("storage error");
164-
});
158+
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
159+
.ThrowsAsync(new Exception("storage error"));
160+
165161
var countdownEvent = new CountdownEvent(1);
166162
var service = new TestExportService(_logger.Object, _configuration, _serviceScopeFactory.Object, _storageInfoProvider.Object);
167163
service.ReportActionCompleted += (sender, e) =>
@@ -206,11 +202,8 @@ public async Task DataflowTest_EndToEnd()
206202
}
207203
});
208204

209-
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<Stream>>(), It.IsAny<CancellationToken>()))
210-
.Callback<string, string, Action<Stream>, CancellationToken>((bucketName, objectName, callback, cancellationToken) =>
211-
{
212-
callback(new MemoryStream(Encoding.UTF8.GetBytes(testData)));
213-
});
205+
_storageService.Setup(p => p.GetObjectAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
206+
.ReturnsAsync(new MemoryStream(Encoding.UTF8.GetBytes(testData)));
214207

215208
var countdownEvent = new CountdownEvent(5 * 3);
216209
var service = new TestExportService(_logger.Object, _configuration, _serviceScopeFactory.Object, _storageInfoProvider.Object);

0 commit comments

Comments
 (0)