Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: distributed requests synchronization #13993

Merged
merged 18 commits into from
Nov 8, 2024
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: 2 additions & 0 deletions backend/packagegroups/NuGet.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<PackageReference Update="MediatR" Version="12.4.1" />
<PackageReference Update="DotNetEnv" Version="3.1.1" />
<PackageReference Update="NuGet.Versioning" Version="6.11.1" />
<PackageReference Update="DistributedLock.Postgres" Version="1.2.0" />
</ItemGroup>

<ItemGroup Label="Packages used for testing">
Expand All @@ -60,5 +61,6 @@
<PackageReference Update="Microsoft.AspNetCore.SignalR.Client" Version="8.0.10" />
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
<PackageReference Update="WireMock.Net" Version="1.6.7" />
<PackageReference Update="DistributedLock.FileSystem" Version="1.0.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ namespace Altinn.Studio.Designer.Configuration.Extensions
{
public static class ServiceCollectionExtensions
{

/// <summary>
/// Registers all settings that implement or inherit from the marker type.
/// Settings configuration will be read from the configuration, and the settings section name will be the same as the class name.
/// It will register the settings as a scoped service.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
/// <param name="configuration">An <see cref="IConfiguration"/> holding the configuration of the app.</param>
/// <typeparam name="TMarker">The marker type used to identify the services or settings to be registered.</typeparam>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection RegisterSettingsByBaseType<TMarker>(this IServiceCollection services, IConfiguration configuration)
{
var typesToRegister = AltinnAssembliesScanner.GetTypesAssignedFrom<TMarker>()
Expand Down Expand Up @@ -81,5 +91,24 @@ private static void ConfigureSettingsTypeBySection<TOption>(this IServiceCollect
services.TryAddScoped(typeof(TOption), svc => ((IOptionsSnapshot<object>)svc.GetService(typeof(IOptionsSnapshot<TOption>)))!.Value);
}

/// <summary>
/// Register all the services that implement or inherit from the marker interface.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
/// <typeparam name="TMarker">The marker type used to identify the services or settings to be registered.</typeparam>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection RegisterSingletonServicesByBaseType<TMarker>(this IServiceCollection services)
{
var typesToRegister = AltinnAssembliesScanner.GetTypesAssignedFrom<TMarker>()
.Where(type => !type.IsInterface && !type.IsAbstract);

foreach (var serviceType in typesToRegister)
{
services.TryAddSingleton(typeof(TMarker), serviceType);
}

return services;
}

}
}

This file was deleted.

11 changes: 1 addition & 10 deletions backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class AppDevelopmentController : Controller
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private readonly ApplicationInsightsSettings _applicationInsightsSettings;
private readonly IMediator _mediator;
private readonly IUserRequestsSynchronizationService _userRequestsSynchronizationService;


/// <summary>
Expand All @@ -47,16 +46,14 @@ public class AppDevelopmentController : Controller
/// <param name="altinnGitRepositoryFactory"></param>
/// <param name="applicationInsightsSettings">An <see cref="ApplicationInsightsSettings"/></param>
/// <param name="mediator"></param>
/// <param name="userRequestsSynchronizationService">An <see cref="IUserRequestsSynchronizationService"/> used to control parallel execution of user requests.</param>
public AppDevelopmentController(IAppDevelopmentService appDevelopmentService, IRepository repositoryService, ISourceControl sourceControl, IAltinnGitRepositoryFactory altinnGitRepositoryFactory, ApplicationInsightsSettings applicationInsightsSettings, IMediator mediator, IUserRequestsSynchronizationService userRequestsSynchronizationService)
public AppDevelopmentController(IAppDevelopmentService appDevelopmentService, IRepository repositoryService, ISourceControl sourceControl, IAltinnGitRepositoryFactory altinnGitRepositoryFactory, ApplicationInsightsSettings applicationInsightsSettings, IMediator mediator)
{
_appDevelopmentService = appDevelopmentService;
_repository = repositoryService;
_sourceControl = sourceControl;
_altinnGitRepositoryFactory = altinnGitRepositoryFactory;
_applicationInsightsSettings = applicationInsightsSettings;
_mediator = mediator;
_userRequestsSynchronizationService = userRequestsSynchronizationService;
}

/// <summary>
Expand Down Expand Up @@ -218,8 +215,6 @@ public ActionResult UpdateFormLayoutName(string org, string app, [FromQuery] str
public async Task<ActionResult> SaveLayoutSettings(string org, string app, [FromQuery] string layoutSetName, [FromBody] JsonNode layoutSettings, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
SemaphoreSlim semaphore = _userRequestsSynchronizationService.GetRequestsSemaphore(org, app, developer);
await semaphore.WaitAsync();
try
{
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);
Expand All @@ -230,10 +225,6 @@ public async Task<ActionResult> SaveLayoutSettings(string org, string app, [From
{
return NotFound(exception.Message);
}
finally
{
semaphore.Release();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Models.App;
using Altinn.Studio.Designer.Services.Interfaces;
Expand All @@ -19,17 +18,15 @@ namespace Altinn.Studio.Designer.Controllers
public class ApplicationMetadataController : ControllerBase
{
private readonly IApplicationMetadataService _applicationMetadataService;
private readonly IUserRequestsSynchronizationService _userRequestsSynchronizationService;

/// <summary>
/// Initializes a new instance of the <see cref="ApplicationMetadataController"/> class.
/// </summary>
/// <param name="applicationMetadataService">The application metadata service</param>
/// <param name="userRequestsSynchronizationService">The user requests synchronization service</param>
public ApplicationMetadataController(IApplicationMetadataService applicationMetadataService, IUserRequestsSynchronizationService userRequestsSynchronizationService)
public ApplicationMetadataController(IApplicationMetadataService applicationMetadataService)
{
_applicationMetadataService = applicationMetadataService;
_userRequestsSynchronizationService = userRequestsSynchronizationService;
}

/// <summary>
Expand Down Expand Up @@ -145,8 +142,6 @@ public async Task<ActionResult> UpdateMetadataForAttachment([FromBody] dynamic a
[Route("attachment-component")]
public async Task<ActionResult> DeleteMetadataForAttachment(string org, string app, [FromBody] string id)
{
SemaphoreSlim semaphore = _userRequestsSynchronizationService.GetRequestsSemaphore(org, app, "");
await semaphore.WaitAsync();
try
{
await _applicationMetadataService.DeleteMetadataForAttachment(org, app, id);
Expand All @@ -156,10 +151,6 @@ public async Task<ActionResult> DeleteMetadataForAttachment(string org, string a
{
return BadRequest("Could not delete metadata");
}
finally
{
semaphore.Release();
}
}
}
}
Loading
Loading