Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet sonarscanner begin /k:"Project-MONAI_monai-deploy-workflow-manager" /o:"project-monai" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="../**/coverage.opencover.xml" /d:sonar.coverage.exclusions="src/WorkflowManager/Database/Repositories/**/*,src/TaskManager/Database/TaskDispatchEventRepository.cs"
run: dotnet sonarscanner begin /k:"Project-MONAI_monai-deploy-workflow-manager" /o:"project-monai" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="../**/coverage.opencover.xml" /d:sonar.coverage.exclusions="src/WorkflowManager/Database/Repositories/**/*,src/TaskManager/Database/TaskDispatchEventRepository.cs,**/Migrations/M0*.cs"
working-directory: ./src

- name: Restore Solution
Expand Down
30 changes: 30 additions & 0 deletions doc/dependency_decisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2506,3 +2506,33 @@
:versions:
- 4.3.0
:when: 2023-02-02 15:35:00.000000000 Z

- - :approve
- System.IO.Pipelines
- :who: neildsouth
:why: MIT (https://github.com/dotnet/runtime/raw/main/LICENSE.TXT)
:versions:
- 6.0.3
:when: 2023-04-11 13:37:00.000000000 Z
- - :approve
- Microsoft.Extensions.DependencyModel
- :who: neildsouth
:why: MIT (https://github.com/dotnet/runtime/raw/main/LICENSE.TXT)
:versions:
- 6.0.0
:when: 2023-04-11 13:37:00.000000000 Z
- - :approve
- Microsoft.AspNetCore.TestHost
- :who: neildsouth
:why: MIT (https://github.com/dotnet/runtime/raw/main/LICENSE.TXT)
:versions:
- 6.0.15
:when: 2023-04-11 13:37:00.000000000 Z
- - :approve
- Microsoft.AspNetCore.Mvc.Testing
- :who: neildsouth
:why: MIT (https://github.com/dotnet/runtime/raw/main/LICENSE.TXT)
:versions:
- 6.0.15
:when: 2023-04-11 13:37:00.000000000 Z

2 changes: 1 addition & 1 deletion src/.sonarlint/sonar.settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sonar.exclusions":[],"sonar.global.exclusions":["**/build-wrapper-dump.json"],"sonar.inclusions":[]}
{"sonar.exclusions":[],"sonar.global.exclusions":["**/build-wrapper-dump.json","**/Migrations/*.cs"],"sonar.inclusions":[]}
28 changes: 28 additions & 0 deletions src/Shared/Configuration/PagedOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Microsoft.Extensions.Configuration;

namespace Monai.Deploy.WorkflowManager.Configuration
{
public class PagedOptions
{
/// <summary>
/// Represents the <c>endpointSettings</c> section of the configuration file.
/// </summary>
[ConfigurationKeyName("endpointSettings")]
public EndpointSettings EndpointSettings { get; set; }
}
}
8 changes: 1 addition & 7 deletions src/Shared/Configuration/WorkflowManagerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Monai.Deploy.WorkflowManager.Configuration
{
public class WorkflowManagerOptions
public class WorkflowManagerOptions : PagedOptions
{
/// <summary>
/// Name of the key for retrieve database connection string.
Expand All @@ -44,12 +44,6 @@ public class WorkflowManagerOptions
[ConfigurationKeyName("taskManager")]
public TaskManagerConfiguration TaskManager { get; set; }

/// <summary>
/// Represents the <c>endpointSettings</c> section of the configuration file.
/// </summary>
[ConfigurationKeyName("endpointSettings")]
public EndpointSettings EndpointSettings { get; set; }

[ConfigurationKeyName("taskTimeoutMinutes")]
public double TaskTimeoutMinutes { get; set; } = 60;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,33 @@
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Net;
using Ardalis.GuardClauses;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Monai.Deploy.WorkflowManager.Configuration;
using Monai.Deploy.WorkflowManager.Filter;
using Monai.Deploy.WorkflowManager.Services;
using Monai.Deploy.WorkflowManager.Wrappers;
using Monai.Deploy.WorkflowManager.Shared.Filter;
using Monai.Deploy.WorkflowManager.Shared.Wrappers;
using Monai.Deploy.WorkflowManager.Shared.Services;
using Microsoft.AspNetCore.Routing;

namespace Monai.Deploy.WorkflowManager.Controllers
namespace Monai.Deploy.WorkflowManager.ControllersShared
{
/// <summary>
/// Base Api Controller.
/// </summary>
[ApiController]
public class ApiControllerBase : ControllerBase
{
private readonly IOptions<WorkflowManagerOptions> _options;
public IOptions<WorkflowManagerOptions> Options { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ApiControllerBase"/> class.
/// </summary>
/// <param name="options">Workflow manager options.</param>
public ApiControllerBase(IOptions<WorkflowManagerOptions> options)
public ApiControllerBase(IOptions<WorkflowManagerOptions> Options)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
this.Options = Options ?? throw new ArgumentNullException(nameof(Options));
}

/// <summary>
Expand Down Expand Up @@ -69,34 +68,26 @@ public ApiControllerBase(IOptions<WorkflowManagerOptions> options)
/// <param name="uriService">Uri service.</param>
/// <param name="route">Route.</param>
/// <returns>Returns <see cref="PagedResponse{T}"/>.</returns>
public PagedResponse<List<T>> CreatePagedReponse<T>(List<T> pagedData, PaginationFilter validFilter, long totalRecords, IUriService uriService, string route)
public PagedResponse<IEnumerable<T>> CreatePagedReponse<T>(IEnumerable<T> pagedData, PaginationFilter validFilter, long totalRecords, IUriService uriService, string route)
{
Guard.Against.Null(pagedData);
Guard.Against.Null(validFilter);
Guard.Against.Null(route);
Guard.Against.Null(uriService);

var pageSize = validFilter.PageSize ?? _options.Value.EndpointSettings.DefaultPageSize;
var respose = new PagedResponse<List<T>>(pagedData, validFilter.PageNumber, pageSize);
var totalPages = (double)totalRecords / pageSize;
var roundedTotalPages = Convert.ToInt32(Math.Ceiling(totalPages));
var pageSize = validFilter.PageSize ?? Options.Value.EndpointSettings.DefaultPageSize;
var respose = new PagedResponse<IEnumerable<T>>(pagedData, validFilter.PageNumber, pageSize);

respose.NextPage =
validFilter.PageNumber >= 1 && validFilter.PageNumber < roundedTotalPages
? uriService.GetPageUriString(new PaginationFilter(validFilter.PageNumber + 1, pageSize), route)
: null;

respose.PreviousPage =
validFilter.PageNumber - 1 >= 1 && validFilter.PageNumber <= roundedTotalPages
? uriService.GetPageUriString(new PaginationFilter(validFilter.PageNumber - 1, pageSize), route)
: null;
respose.SetUp(validFilter, totalRecords, uriService, route);
return respose;
}

respose.FirstPage = uriService.GetPageUriString(new PaginationFilter(1, pageSize), route);
respose.LastPage = uriService.GetPageUriString(new PaginationFilter(roundedTotalPages, pageSize), route);
respose.TotalPages = roundedTotalPages;
respose.TotalRecords = totalRecords;

return respose;
public StatsPagedResponse<IEnumerable<T>> CreateStatsPagedReponse<T>(IEnumerable<T> pagedData, PaginationFilter validFilter, long totalRecords, IUriService uriService, string route)
{
var response = new StatsPagedResponse<IEnumerable<T>>(pagedData, validFilter.PageNumber, validFilter.PageSize.Value);
response.SetUp(validFilter, totalRecords, uriService, route);
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

namespace Monai.Deploy.WorkflowManager.Filter
namespace Monai.Deploy.WorkflowManager.Shared.Filter
{
/// <summary>
/// Pagination Filter class.
Expand Down
4 changes: 4 additions & 0 deletions src/Shared/Shared/Monai.Deploy.WorkflowManager.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="6.0.15" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Configuration\Monai.Deploy.WorkflowManager.Configuration.csproj" />
</ItemGroup>

<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,9 +14,9 @@
* limitations under the License.
*/

using Monai.Deploy.WorkflowManager.Filter;
using Monai.Deploy.WorkflowManager.Shared.Filter;

namespace Monai.Deploy.WorkflowManager.Services
namespace Monai.Deploy.WorkflowManager.Shared.Services
{
/// <summary>
/// Uri Serivce.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,11 +14,10 @@
* limitations under the License.
*/

using System;
using Microsoft.AspNetCore.WebUtilities;
using Monai.Deploy.WorkflowManager.Filter;
using Monai.Deploy.WorkflowManager.Shared.Filter;

namespace Monai.Deploy.WorkflowManager.Services
namespace Monai.Deploy.WorkflowManager.Shared.Services
{
/// <summary>
/// Uri Service.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,10 @@
* limitations under the License.
*/

namespace Monai.Deploy.WorkflowManager.Wrappers
using Monai.Deploy.WorkflowManager.Shared.Filter;
using Monai.Deploy.WorkflowManager.Shared.Services;

namespace Monai.Deploy.WorkflowManager.Shared.Wrappers
{
/// <summary>
/// Paged Response for use with paginations.
Expand Down Expand Up @@ -77,5 +80,26 @@ public PagedResponse(T data, int pageNumber, int pageSize)
/// Gets or sets previousPage.
/// </summary>
public string PreviousPage { get; set; }

public void SetUp(PaginationFilter validFilter, long totalRecords, IUriService uriService, string route)
{
var totalPages = (double)totalRecords / PageSize;
var roundedTotalPages = Convert.ToInt32(Math.Ceiling(totalPages));

NextPage =
validFilter.PageNumber >= 1 && validFilter.PageNumber < roundedTotalPages
? uriService.GetPageUriString(new PaginationFilter(validFilter.PageNumber + 1, PageSize), route)
: null;

PreviousPage =
validFilter.PageNumber - 1 >= 1 && validFilter.PageNumber <= roundedTotalPages
? uriService.GetPageUriString(new PaginationFilter(validFilter.PageNumber - 1, PageSize), route)
: null;

FirstPage = uriService.GetPageUriString(new PaginationFilter(1, PageSize), route);
LastPage = uriService.GetPageUriString(new PaginationFilter(roundedTotalPages, PageSize), route);
TotalPages = roundedTotalPages;
TotalRecords = totalRecords;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

namespace Monai.Deploy.WorkflowManager.Wrappers
namespace Monai.Deploy.WorkflowManager.Shared.Wrappers
{
/// <summary>
/// Response object.
Expand All @@ -37,7 +37,7 @@ public Response(T data)
{
Succeeded = true;
Message = string.Empty;
Errors = null;
Errors = Array.Empty<string>();
Data = data;
}

Expand Down
36 changes: 36 additions & 0 deletions src/Shared/Shared/Wrappers/StatsPagedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Monai.Deploy.WorkflowManager.Shared.Wrappers
{
public class StatsPagedResponse<T> : PagedResponse<T>
{
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
public long TotalExecutions { get; set; }
public long TotalFailures { get; set; }
public double AverageTotalExecutionSeconds { get; set; }
public double AverageArgoExecutionSeconds { get; set; }

public StatsPagedResponse(T data, int pageNumber, int pageSize) : base(data, pageNumber, pageSize)
{

}
//public StatsPagedResponse(PagedResponse<T> paged) : base(paged.Data, paged.PageNumber, paged.PageSize)
//{
// int re = 0;
//}
}
}
Loading