Skip to content

Commit be744ff

Browse files
committed
Refactor DB repositories for EF
Signed-off-by: Victor Chang <[email protected]>
1 parent 9a0a705 commit be744ff

File tree

82 files changed

+2984
-2234
lines changed

Some content is hidden

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

82 files changed

+2984
-2234
lines changed

src/Database/Api/IInformaticsGatewayRepository.cs

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

src/Database/Api/Log.9000.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 Microsoft.Extensions.Logging;
18+
19+
namespace Monai.Deploy.InformaticsGateway.Database.Api
20+
{
21+
public static partial class Log
22+
{
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+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Project Sdk="Microsoft.NET.Sdk">
1818

1919
<PropertyGroup>
20-
<RootNamespace>Monai.Deploy.InformaticsGateway.Database.Repositories</RootNamespace>
20+
<RootNamespace>Monai.Deploy.InformaticsGateway.Database.Api</RootNamespace>
2121
<TargetFramework>net6.0</TargetFramework>
2222
<ImplicitUsings>enable</ImplicitUsings>
2323
<Nullable>enable</Nullable>
@@ -31,10 +31,12 @@
3131

3232
<ItemGroup>
3333
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
34+
<PackageReference Include="Polly" Version="7.2.3" />
3435
</ItemGroup>
3536

3637
<ItemGroup>
3738
<ProjectReference Include="..\..\Api\Monai.Deploy.InformaticsGateway.Api.csproj" />
39+
<ProjectReference Include="..\..\Configuration\Monai.Deploy.InformaticsGateway.Configuration.csproj" />
3840
</ItemGroup>
3941

4042
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.Linq.Expressions;
18+
using Monai.Deploy.InformaticsGateway.Api;
19+
20+
namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
21+
{
22+
public interface IDestinationApplicationEntityRepository
23+
{
24+
Task<List<DestinationApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default);
25+
26+
Task<DestinationApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default);
27+
28+
Task<DestinationApplicationEntity> AddAsync(DestinationApplicationEntity item, CancellationToken cancellationToken = default);
29+
30+
Task<DestinationApplicationEntity> UpdateAsync(DestinationApplicationEntity entity, CancellationToken cancellationToken = default);
31+
32+
Task<DestinationApplicationEntity> RemoveAsync(DestinationApplicationEntity entity, CancellationToken cancellationToken = default);
33+
34+
Task<bool> ContainsAsync(Expression<Func<DestinationApplicationEntity, bool>> predicate, CancellationToken cancellationToken = default);
35+
}
36+
}

src/InformaticsGateway/Repositories/IInferenceRequestRepository.cs renamed to src/Database/Api/Repositories/IInferenceRequestRepository.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2021-2022 MONAI Consortium
33
* Copyright 2019-2021 NVIDIA Corporation
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* Licensed under the Apache License, Version 2.0 (the "License", CancellationToken cancellationToken = default);
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
*
@@ -15,12 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
using System;
19-
using System.Threading;
20-
using System.Threading.Tasks;
2118
using Monai.Deploy.InformaticsGateway.Api.Rest;
2219

23-
namespace Monai.Deploy.InformaticsGateway.Repositories
20+
namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
2421
{
2522
/// <summary>
2623
/// Interface for access stored inference requests.
@@ -31,7 +28,7 @@ public interface IInferenceRequestRepository
3128
/// Adds new inference request to the repository.
3229
/// </summary>
3330
/// <param name="inferenceRequest">The inference request to be added.</param>
34-
Task Add(InferenceRequest inferenceRequest);
31+
Task AddAsync(InferenceRequest inferenceRequest, CancellationToken cancellationToken = default);
3532

3633
/// <summary>
3734
/// Updates an inference request's status.
@@ -40,39 +37,39 @@ public interface IInferenceRequestRepository
4037
/// </summary>
4138
/// <param name="inferenceRequest">The inference request to be updated.</param>
4239
/// <param name="status">Current status of the inference request.</param>
43-
Task Update(InferenceRequest inferenceRequest, InferenceRequestStatus status);
40+
Task UpdateAsync(InferenceRequest inferenceRequest, InferenceRequestStatus status, CancellationToken cancellationToken = default);
4441

4542
/// <summary>
4643
/// <c>Take</c> returns the next pending inference request for data retrieval.
4744
/// The default implementation blocks the call until a pending inference request is available for process.
4845
/// </summary>
4946
/// <param name="cancellationToken">cancellation token used to cancel the action.</param>
5047
/// <returns><see cref="InferenceRequest"/></returns>
51-
Task<InferenceRequest> Take(CancellationToken cancellationToken);
48+
Task<InferenceRequest> TakeAsync(CancellationToken cancellationToken = default);
5249

5350
/// <summary>
5451
/// <c>Get</c> returns the specified inference request.
5552
/// </summary>
5653
/// <param name="transactionId">The transactionId of the request.</param>
57-
InferenceRequest GetInferenceRequest(string transactionId);
54+
Task<InferenceRequest?> GetInferenceRequestAsync(string transactionId, CancellationToken cancellationToken = default);
5855

5956
/// <summary>
6057
/// <c>Get</c> returns the specified inference request.
6158
/// </summary>
6259
/// <param name="inferenceRequestId">The internal ID of the request.</param>
63-
Task<InferenceRequest> GetInferenceRequest(Guid inferenceRequestId);
60+
Task<InferenceRequest?> GetInferenceRequestAsync(Guid inferenceRequestId, CancellationToken cancellationToken = default);
6461

6562
/// <summary>
6663
/// <c>Exists</c> checks whether if an existing request with the same transaction ID exists.
6764
/// </summary>
6865
/// <param name="transactionId"></param>
6966
/// <returns></returns>
70-
bool Exists(string transactionId);
67+
Task<bool> ExistsAsync(string transactionId, CancellationToken cancellationToken = default);
7168

7269
/// <summary>
7370
/// <c>GetStatus</c> returns the status of the specified inference request.
7471
/// </summary>
7572
/// <param name="transactionId">The transactionId from the original request.</param>
76-
Task<InferenceStatusResponse> GetStatus(string transactionId);
73+
Task<InferenceStatusResponse?> GetStatusAsync(string transactionId, CancellationToken cancellationToken = default);
7774
}
7875
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.Linq.Expressions;
18+
using Monai.Deploy.InformaticsGateway.Api;
19+
20+
namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
21+
{
22+
public interface IMonaiApplicationEntityRepository
23+
{
24+
Task<List<MonaiApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default);
25+
26+
Task<MonaiApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default);
27+
28+
Task<MonaiApplicationEntity> AddAsync(MonaiApplicationEntity item, CancellationToken cancellationToken = default);
29+
30+
Task<MonaiApplicationEntity> UpdateAsync(MonaiApplicationEntity entity, CancellationToken cancellationToken = default);
31+
32+
Task<MonaiApplicationEntity> RemoveAsync(MonaiApplicationEntity entity, CancellationToken cancellationToken = default);
33+
34+
Task<bool> ContainsAsync(Expression<Func<MonaiApplicationEntity, bool>> predicate, CancellationToken cancellationToken = default);
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.Linq.Expressions;
18+
using Monai.Deploy.InformaticsGateway.Api.Storage;
19+
20+
namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
21+
{
22+
public interface IPayloadRepository
23+
{
24+
Task<List<Payload>> ToListAsync(CancellationToken cancellationToken = default);
25+
26+
Task<Payload> AddAsync(Payload item, CancellationToken cancellationToken = default);
27+
28+
Task<Payload> UpdateAsync(Payload entity, CancellationToken cancellationToken = default);
29+
30+
Task<Payload> RemoveAsync(Payload entity, CancellationToken cancellationToken = default);
31+
32+
Task<bool> ContainsAsync(Expression<Func<Payload, bool>> predicate, CancellationToken cancellationToken = default);
33+
34+
Task<int> RemovePendingPayloadsAsync(CancellationToken cancellationToken = default);
35+
36+
Task<List<Payload>> GetPayloadsInStateAsync(CancellationToken cancellationToken = default, params Payload.PayloadState[] states);
37+
}
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.Linq.Expressions;
18+
using Monai.Deploy.InformaticsGateway.Api;
19+
20+
namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
21+
{
22+
public interface ISourceApplicationEntityRepository
23+
{
24+
Task<List<SourceApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default);
25+
26+
Task<SourceApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default);
27+
28+
Task<SourceApplicationEntity> AddAsync(SourceApplicationEntity item, CancellationToken cancellationToken = default);
29+
30+
Task<SourceApplicationEntity> UpdateAsync(SourceApplicationEntity entity, CancellationToken cancellationToken = default);
31+
32+
Task<SourceApplicationEntity> RemoveAsync(SourceApplicationEntity entity, CancellationToken cancellationToken = default);
33+
34+
Task<bool> ContainsAsync(Expression<Func<SourceApplicationEntity, bool>> predicate, CancellationToken cancellationToken = default);
35+
}
36+
}

0 commit comments

Comments
 (0)