From 9259f91a3c7c8361f063ac2492ba544b41b2a2c5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 May 2026 10:18:37 +0000 Subject: [PATCH 1/2] Initial plan From 30b105b207cb8c15b4344e5f6c7f4465730c1232 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 May 2026 10:26:51 +0000 Subject: [PATCH 2/2] Remove precomputed flow from DataEngine Agent-Logs-Url: https://github.com/AAS-TwinEngine/AAS.TwinEngine.DataEngine/sessions/aced755e-92ca-4a7b-beda-9494058053f0 Co-authored-by: mm-spr <108080048+mm-spr@users.noreply.github.com> --- .../ShellDescriptorServiceTests.cs | 225 +----------- .../AasRegistryProviderTests.cs | 338 ------------------ .../ShellDescriptorSyncHostedTests.cs | 113 ------ .../AAS.TwinEngine.DataEngine.csproj | 1 - .../AasRegistry/IShellDescriptorService.cs | 2 - .../Providers/IAasRegistryProvider.cs | 16 - .../AasRegistry/ShellDescriptorService.cs | 106 +----- .../Config/AasRegistryPreComputed.cs | 10 - .../Services/AasRegistryProvider.cs | 158 -------- .../Services/ShellDescriptorSyncHosted.cs | 76 ---- ...astructureDependencyInjectionExtensions.cs | 6 - .../appsettings.development.json | 4 - .../appsettings.json | 4 - 13 files changed, 3 insertions(+), 1056 deletions(-) delete mode 100644 source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/AasRegistryProviderTests.cs delete mode 100644 source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/ShellDescriptorSyncHostedTests.cs delete mode 100644 source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/Providers/IAasRegistryProvider.cs delete mode 100644 source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Config/AasRegistryPreComputed.cs delete mode 100644 source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/AasRegistryProvider.cs delete mode 100644 source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/ShellDescriptorSyncHosted.cs diff --git a/source/AAS.TwinEngine.DataEngine.UnitTests/ApplicationLogic/Services/AasRegistry/ShellDescriptorServiceTests.cs b/source/AAS.TwinEngine.DataEngine.UnitTests/ApplicationLogic/Services/AasRegistry/ShellDescriptorServiceTests.cs index 4de2a882..0f7b8e8b 100644 --- a/source/AAS.TwinEngine.DataEngine.UnitTests/ApplicationLogic/Services/AasRegistry/ShellDescriptorServiceTests.cs +++ b/source/AAS.TwinEngine.DataEngine.UnitTests/ApplicationLogic/Services/AasRegistry/ShellDescriptorServiceTests.cs @@ -1,8 +1,7 @@ -using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Application; +using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Application; using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Infrastructure; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasEnvironment.Providers; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry.Providers; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin; using AAS.TwinEngine.DataEngine.DomainModel.AasRegistry; using AAS.TwinEngine.DataEngine.DomainModel.Plugin; @@ -22,12 +21,10 @@ public class ShellDescriptorServiceTests private readonly ITemplateProvider _templateProvider = Substitute.For(); private readonly IPluginDataHandler _pluginDataHandler = Substitute.For(); private readonly IShellDescriptorDataHandler _dataHandler = Substitute.For(); - private readonly IAasRegistryProvider _aasRegistryProvider = Substitute.For(); - private readonly ILogger _logger = Substitute.For>(); private readonly IPluginManifestConflictHandler _pluginManifestConflictHandler = Substitute.For(); private readonly ShellDescriptorService _sut; - public ShellDescriptorServiceTests() => _sut = new ShellDescriptorService(_templateProvider, _dataHandler, _pluginDataHandler, _aasRegistryProvider, _logger, _pluginManifestConflictHandler); + public ShellDescriptorServiceTests() => _sut = new ShellDescriptorService(_templateProvider, _dataHandler, _pluginDataHandler, _pluginManifestConflictHandler); [Fact] public async Task GetAllShellDescriptorsAsync_ReturnsFilledShellDescriptors() @@ -124,224 +121,6 @@ public async Task GetShellDescriptorByIdAsync_ReturnsFilledShellDescriptor() Assert.Equal(expected, result); } - [Fact] - public async Task SyncShellDescriptorsAsync_ShouldUpdate_ExistingDescriptors() - { - var filled = new List - { - new() { Id = "1" } - }; - var existing = new ShellDescriptor { Id = "1" }; - var metaData = new ShellDescriptorsMetaData - { - PagingMetaData = new PagingMetaData { Cursor = "nextCursor" }, - ShellDescriptors = [new ShellDescriptorMetaData { Id = "1" }] - }; - - _aasRegistryProvider.GetAllAsync(Arg.Any()).Returns([existing]); - var manifests = new List - { - new() - { - PluginName = "TestPlugin", - PluginUrl = new Uri("http://test-plugin"), - SupportedSemanticIds = new List(), - Capabilities = new Capabilities { HasShellDescriptor = true } - } - }; - _pluginManifestConflictHandler.Manifests.Returns(manifests); - _pluginDataHandler.GetDataForAllShellDescriptorsAsync(null, null, manifests, Arg.Any()).Returns(metaData); - _dataHandler.FillOut(existing, metaData.ShellDescriptors).Returns(filled); - - await _sut.SyncShellDescriptorsAsync(CancellationToken.None); - - await _aasRegistryProvider.Received(1).PutAsync("1", null, Arg.Any()); - await _aasRegistryProvider.DidNotReceive().CreateAsync(Arg.Any(), Arg.Any()); - await _aasRegistryProvider.DidNotReceive().DeleteByIdAsync(Arg.Any(), Arg.Any()); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_ShouldCreate_NewDescriptors() - { - // Arrange - var metaData = new ShellDescriptorsMetaData - { - PagingMetaData = new PagingMetaData { Cursor = "nextCursor" }, - ShellDescriptors = [new ShellDescriptorMetaData { Id = "2" }] - }; - var template = new ShellDescriptor { Id = "template" }; - var filled = new List - { - new() { Id = "2" } - }; - - _aasRegistryProvider.GetAllAsync(Arg.Any()).Returns([]); - var manifests = new List - { - new() - { - PluginName = "TestPlugin", - PluginUrl = new Uri("http://test-plugin"), - SupportedSemanticIds = new List(), - Capabilities = new Capabilities { HasShellDescriptor = true } - } - }; - _pluginManifestConflictHandler.Manifests.Returns(manifests); - _pluginDataHandler.GetDataForAllShellDescriptorsAsync(null, null, manifests, Arg.Any()).Returns(metaData); - _templateProvider.GetShellDescriptorsTemplateAsync(Arg.Any()).Returns(template); - _dataHandler.FillOut(template, metaData.ShellDescriptors).Returns(filled); - - // Act - await _sut.SyncShellDescriptorsAsync(CancellationToken.None); - - // Assert - await _aasRegistryProvider.Received(1).CreateAsync(Arg.Any(), Arg.Any()); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_ShouldDelete_MissingDescriptors() - { - // Arrange - var existing = new ShellDescriptor { Id = "1" }; - var metaData = new ShellDescriptorsMetaData - { - PagingMetaData = new PagingMetaData { Cursor = "nextCursor" }, - ShellDescriptors = [] - }; - _aasRegistryProvider.GetAllAsync(Arg.Any()).Returns([existing]); - var manifests = new List - { - new() - { - PluginName = "TestPlugin", - PluginUrl = new Uri("http://test-plugin"), - SupportedSemanticIds = new List(), - Capabilities = new Capabilities { HasShellDescriptor = true } - } - }; - _pluginManifestConflictHandler.Manifests.Returns(manifests); - _pluginDataHandler.GetDataForAllShellDescriptorsAsync(null, null, manifests, Arg.Any()).Returns(metaData); - - // Act - await _sut.SyncShellDescriptorsAsync(CancellationToken.None); - - // Assert - await _aasRegistryProvider.Received(1).DeleteByIdAsync("1", Arg.Any()); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_ShouldHandle_EmptyListsGracefully() - { - // Arrange - var metaData = new ShellDescriptorsMetaData - { - PagingMetaData = new PagingMetaData { Cursor = "nextCursor" }, - ShellDescriptors = [] - }; - _aasRegistryProvider.GetAllAsync(Arg.Any()) - .Returns([]); - - _pluginDataHandler.GetDataForAllShellDescriptorsAsync(null, null, Arg.Any>(), Arg.Any()).Returns(metaData); - - // Act - var ex = await Record.ExceptionAsync(() => _sut.SyncShellDescriptorsAsync(CancellationToken.None)); - - // Assert - Assert.Null(ex); - await _aasRegistryProvider.DidNotReceive().CreateAsync(Arg.Any(), Arg.Any()); - await _aasRegistryProvider.DidNotReceive().DeleteByIdAsync(Arg.Any(), Arg.Any()); - await _aasRegistryProvider.DidNotReceive().PutAsync(Arg.Any(), Arg.Any(), Arg.Any()); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_WhenRegistryDescriptorHasNoId_ShouldLogAndReturn() - { - var metaData = new ShellDescriptorsMetaData - { - PagingMetaData = new PagingMetaData(), - ShellDescriptors = [new ShellDescriptorMetaData { Id = "valid" }] - }; - - _aasRegistryProvider - .GetAllAsync(Arg.Any()) - .Returns([new ShellDescriptor { Id = "" }]); - - _pluginDataHandler - .GetDataForAllShellDescriptorsAsync(null, null, Arg.Any>(), Arg.Any()) - .Returns(metaData); - - var exception = await Record.ExceptionAsync( - () => _sut.SyncShellDescriptorsAsync(CancellationToken.None)); - - Assert.Null(exception); - - await _aasRegistryProvider - .DidNotReceive() - .CreateAsync(Arg.Any(), Arg.Any()); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_WhenRegistryThrowsResourceNotFoundException_ShouldNotThrow() - { - _aasRegistryProvider - .GetAllAsync(Arg.Any()) - .Throws(new ResourceNotFoundException()); - - var exception = await Record.ExceptionAsync( - () => _sut.SyncShellDescriptorsAsync(CancellationToken.None)); - - Assert.Null(exception); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_WhenRegistryThrowsResponseParsingException_ShouldNotThrow() - { - _aasRegistryProvider - .GetAllAsync(Arg.Any()) - .Throws(new ResponseParsingException()); - - var exception = await Record.ExceptionAsync( - () => _sut.SyncShellDescriptorsAsync(CancellationToken.None)); - - Assert.Null(exception); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_WhenRegistryThrowsRequestTimeoutException_ShouldNotThrow() - { - _aasRegistryProvider - .GetAllAsync(Arg.Any()) - .Throws(new RequestTimeoutException()); - - var exception = await Record.ExceptionAsync( - () => _sut.SyncShellDescriptorsAsync(CancellationToken.None)); - - Assert.Null(exception); - } - - [Fact] - public async Task SyncShellDescriptorsAsync_WhenPluginMetadataHasNoId_ShouldLogAndReturn() - { - var metaData = new ShellDescriptorsMetaData - { - PagingMetaData = new PagingMetaData(), - ShellDescriptors = [new ShellDescriptorMetaData { Id = "" }] - }; - - _aasRegistryProvider - .GetAllAsync(Arg.Any()) - .Returns([new ShellDescriptor { Id = "1" }]); - - _pluginDataHandler - .GetDataForAllShellDescriptorsAsync(null, null, Arg.Any>(), Arg.Any()) - .Returns(metaData); - - var exception = await Record.ExceptionAsync( - () => _sut.SyncShellDescriptorsAsync(CancellationToken.None)); - - Assert.Null(exception); - } - [Fact] public async Task GetShellDescriptorByIdAsync_ShouldThrowException_WhenManifestConflict() { diff --git a/source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/AasRegistryProviderTests.cs b/source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/AasRegistryProviderTests.cs deleted file mode 100644 index 2ca31d67..00000000 --- a/source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/AasRegistryProviderTests.cs +++ /dev/null @@ -1,338 +0,0 @@ -using System.Net; -using System.Text; -using System.Text.Json; - -using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Infrastructure; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Extensions; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin.Config; -using AAS.TwinEngine.DataEngine.DomainModel.AasRegistry; -using AAS.TwinEngine.DataEngine.Infrastructure.Http.Clients; - -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; - -using NSubstitute; - -using AasRegistryProviderRepo = AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Services; - -namespace AAS.TwinEngine.DataEngine.UnitTests.Infrastructure.Providers.AasRegistryProvider; - -public class AasRegistryProviderTests -{ - private readonly ILogger _logger = Substitute.For>(); - private readonly ICreateClient _clientFactory = Substitute.For(); - private readonly IOptions _options = Substitute.For>(); - private readonly AasRegistryProviderRepo.AasRegistryProvider _sut; - private const string AasRegistryPath = "shell-descriptors"; - - private const string JsonResponseForShells = """ - { - "paging_metadata": { - "cursor": null - }, - "result": [ - { - "globalAssetId": "ContactInformation", - "idShort": "ContactInformationAAS", - "id": "ContactInformation" - } - ] - } - """; - - public AasRegistryProviderTests() - { - _options.Value.Returns(new AasEnvironmentConfig { AasRegistryPath = AasRegistryPath }); - _sut = new AasRegistryProviderRepo.AasRegistryProvider(_logger, _clientFactory, _options); - } - - [Fact] - public async Task GetAllAsync_ReturnsShellDescriptors_WhenSuccessful() - { - var expectedResponse = new List() - { - new() - { - GlobalAssetId = "ContactInformation", - Id = "ContactInformation", - IdShort = "ContactInformationAAS" - } - }; - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(JsonResponseForShells, Encoding.UTF8, "application/json") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - var result = await _sut.GetAllAsync(CancellationToken.None); - - Assert.NotNull(result); - Assert.Equal(JsonSerializer.Serialize(expectedResponse), JsonSerializer.Serialize(result)); - } - - [Fact] - public async Task GetAllAsync_ThrowsResourceResourceNotFoundException_WhenHttpFails() - { - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.NotFound) - { - Content = new StringContent("Not Found", Encoding.UTF8, "application/json") - }); - - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.GetAllAsync(CancellationToken.None)); - } - - [Fact] - public async Task GetAllAsync_ThrowsResponseParsingException_WhenJsonIsInvalid() - { - const string InvalidJson = " {\r\n \"paging_metadata\": {\r\n \"cursor\": null\r\n }}"; - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(InvalidJson, Encoding.UTF8, "application/json") - }); - - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.GetAllAsync(CancellationToken.None)); - } - - [Fact] - public async Task GetAllAsync_ReturnsEmptyList_WhenResultIsNullInJson() - { - const string NullResultJson = """ - { - "paging_metadata": { "cursor": null }, - "result": null - } - """; - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(NullResultJson, Encoding.UTF8, "application/json") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - var list = await _sut.GetAllAsync(CancellationToken.None); - - Assert.NotNull(list); - Assert.Empty(list); - } - - [Fact] - public async Task GetByIdAsync_ThrowsResponseParsingException_WhenDeserializedObjectIsNull() - { - const string NullContent = "null"; - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(NullContent, Encoding.UTF8, "application/json") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.GetByIdAsync("anything", CancellationToken.None)); - } - - [Fact] - public async Task GetByIdAsync_ReturnsShellDescriptor_WhenSuccessful() - { - var expectedDescriptor = new ShellDescriptor - { - Id = "ContactInformation", - IdShort = "ContactInformationAAS", - GlobalAssetId = "ContactInformation" - }; - var jsonResponse = JsonSerializer.Serialize(expectedDescriptor); - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(jsonResponse, Encoding.UTF8, "application/json") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - var result = await _sut.GetByIdAsync("ContactInformation", CancellationToken.None); - - Assert.NotNull(result); - Assert.Equal(jsonResponse, JsonSerializer.Serialize(result)); - } - - [Fact] - public async Task GetByIdAsync_ThrowsResourceNotFoundException_WhenHttpFails() - { - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.NotFound) - { - Content = new StringContent("Not Found", Encoding.UTF8, "application/json") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.GetByIdAsync("InvalidId", CancellationToken.None)); - } - - [Fact] - public async Task GetByIdAsync_ThrowsResponseParsingException_WhenJsonIsInvalid() - { - const string InvalidJson = "{ invalid json }"; - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(InvalidJson, Encoding.UTF8, "application/json") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.GetByIdAsync("ContactInformation", CancellationToken.None)); - } - - [Fact] - public async Task PutAsync_Succeeds_WhenRequestIsValid() - { - var shellDescriptor = new ShellDescriptor - { - Id = "ContactInformation", - IdShort = "ContactInformationAAS", - GlobalAssetId = "ContactInformation" - }; - var encodedId = "ContactInformation".EncodeBase64Url(); - using var handler = new FakeHttpMessageHandler(request => - { - Assert.Equal(HttpMethod.Put, request.Method); - Assert.Contains(encodedId, request!.RequestUri!.ToString(), StringComparison.OrdinalIgnoreCase); - return new HttpResponseMessage(HttpStatusCode.OK); - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - var exception = await Record.ExceptionAsync(() => _sut.PutAsync("ContactInformation", shellDescriptor, CancellationToken.None)); - - Assert.Null(exception); - } - - [Fact] - public async Task PutAsync_ThrowsRequestTimeoutException_WhenRequestFails() - { - var shellDescriptor = new ShellDescriptor - { - Id = "ContactInformation", - IdShort = "ContactInformationAAS", - GlobalAssetId = "ContactInformation" - }; - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.InternalServerError) - { - Content = new StringContent("Internal Server Error") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.PutAsync("ContactInformation", shellDescriptor, CancellationToken.None)); - } - - [Fact] - public async Task DeleteByIdAsync_Succeeds_WhenRequestIsValid() - { - var encodedId = "ContactInformation".EncodeBase64Url(); - using var handler = new FakeHttpMessageHandler(request => - { - Assert.Equal(HttpMethod.Delete, request.Method); - Assert.Contains(encodedId, request!.RequestUri!.ToString(), StringComparison.OrdinalIgnoreCase); - return new HttpResponseMessage(HttpStatusCode.OK); - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - var exception = await Record.ExceptionAsync(() => _sut.DeleteByIdAsync("ContactInformation", CancellationToken.None)); - - Assert.Null(exception); - } - - [Fact] - public async Task DeleteByIdAsync_ThrowsRequestTimeoutException_WhenRequestFails() - { - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.InternalServerError) - { - Content = new StringContent("Server error") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.DeleteByIdAsync("ContactInformation", CancellationToken.None)); - } - - [Fact] - public async Task CreateAsync_Succeeds_WhenRequestIsValid() - { - var shellDescriptor = new ShellDescriptor - { - Id = "ContactInformation", - IdShort = "ContactInformationAAS", - GlobalAssetId = "ContactInformation" - }; - using var handler = new FakeHttpMessageHandler(request => - { - Assert.Equal(HttpMethod.Post, request.Method); - Assert.Equal("https://www.mm-software.com/shell-descriptors", request!.RequestUri!.ToString()); - return new HttpResponseMessage(HttpStatusCode.OK); - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - var exception = await Record.ExceptionAsync(() => _sut.CreateAsync(shellDescriptor, CancellationToken.None)); - - Assert.Null(exception); - } - - [Fact] - public async Task CreateAsync_ThrowsValidationFailedException_WhenRequestFails() - { - var shellDescriptor = new ShellDescriptor - { - Id = "ContactInformation", - IdShort = "ContactInformationAAS", - GlobalAssetId = "ContactInformation" - }; - using var handler = new FakeHttpMessageHandler(_ => - new HttpResponseMessage(HttpStatusCode.BadRequest) - { - Content = new StringContent("Bad request") - }); - using var httpClient = new HttpClient(handler); - httpClient.BaseAddress = new Uri("https://www.mm-software.com/fakeurl"); - _clientFactory.CreateClient(Arg.Any()).Returns(httpClient); - - await Assert.ThrowsAsync(() => _sut.CreateAsync(shellDescriptor, CancellationToken.None)); - } - - public class FakeHttpMessageHandler(Func responseGenerator) : HttpMessageHandler - { - protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - var response = responseGenerator(request); - return Task.FromResult(response); - } - } -} diff --git a/source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/ShellDescriptorSyncHostedTests.cs b/source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/ShellDescriptorSyncHostedTests.cs deleted file mode 100644 index 6a38872b..00000000 --- a/source/AAS.TwinEngine.DataEngine.UnitTests/Infrastructure/Providers/AasRegistryProvider/ShellDescriptorSyncHostedTests.cs +++ /dev/null @@ -1,113 +0,0 @@ -using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Infrastructure; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry; -using AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Config; -using AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Services; - -using Cronos; - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; - -using NSubstitute; - -namespace AAS.TwinEngine.DataEngine.UnitTests.Infrastructure.Providers.AasRegistryProvider; - -public class ShellDescriptorSyncHostedTests -{ - private readonly IShellDescriptorService _syncService = Substitute.For(); - private readonly ILogger _logger = Substitute.For>(); - private readonly IServiceScopeFactory _scopeFactory = Substitute.For(); - private const string ValidCron = "0/1 * * * * ?"; - - private ShellDescriptorSyncHosted CreateService(string? cron = null) - { - var serviceProvider = Substitute.For(); - serviceProvider.GetService(typeof(IShellDescriptorService)).Returns(_syncService); - serviceProvider.GetRequiredService().Returns(_syncService); - - var scope = Substitute.For(); - scope.ServiceProvider.Returns(serviceProvider); - _scopeFactory.CreateScope().Returns(scope); - - var config = Options.Create(new AasRegistryPreComputed { ShellDescriptorCron = cron ?? ValidCron, IsPreComputed = true }); - - return new ShellDescriptorSyncHosted(_scopeFactory, config, _logger); - } - - [Fact] - public async Task RunOnceAsync_Should_Invoke_SyncShellDescriptorsAsync() - { - // Arrange - using var service = CreateService(); - - // Act - await service.RunOnceAsync(CancellationToken.None); - - // Assert - await _syncService.Received(1).SyncShellDescriptorsAsync(Arg.Any()); - } - - [Fact] - public async Task RunOnceAsync_Should_Log_And_Throw_ResourceNotFoundException_When_Exception_Occurs() - { - // Arrange - _syncService.When(x => x.SyncShellDescriptorsAsync(Arg.Any())) - .Do(_ => throw new ResourceNotFoundException()); - - using var service = CreateService(); - - // Act & Assert - var exception = await Assert.ThrowsAsync(() => service.RunOnceAsync(CancellationToken.None)); - } - - [Theory] - [InlineData("* * *", typeof(CronFormatException))] - [InlineData("* * * * * ?", null)] // Valid cron - public void Should_Throw_When_Cron_Is_Invalid(string cron, Type? expectedExceptionType) - { - // Arrange - var config = Options.Create(new AasRegistryPreComputed { ShellDescriptorCron = cron, IsPreComputed = true }); - - // Act & Assert - if (expectedExceptionType == null) - { - using var instance = new ShellDescriptorSyncHosted(_scopeFactory, config, _logger); - } - else - { - Assert.Throws(expectedExceptionType, () => - { - using var instance = new ShellDescriptorSyncHosted(_scopeFactory, config, _logger); - }); - } - } - - [Fact] - public async Task RunOnceAsync_Should_Not_Invoke_SyncShellDescriptorsAsync_When_PreComputed_Is_False() - { - // Arrange - var config = Options.Create(new AasRegistryPreComputed - { - ShellDescriptorCron = ValidCron, - IsPreComputed = false - }); - - var service = new ShellDescriptorSyncHosted(_scopeFactory, config, _logger); - - // Act - await service.RunOnceAsync(CancellationToken.None); - - // Assert - await _syncService.DidNotReceive().SyncShellDescriptorsAsync(Arg.Any()); - - _logger.Received().Log( - LogLevel.Information, - Arg.Any(), - Arg.Is(o => o.ToString()!.Contains("Skipping ShellDescriptor sync as Pre-Computed set to false.")), - Arg.Any(), - Arg.Any>() - ); - } - -} diff --git a/source/AAS.TwinEngine.DataEngine/AAS.TwinEngine.DataEngine.csproj b/source/AAS.TwinEngine.DataEngine/AAS.TwinEngine.DataEngine.csproj index 398019d7..5d00e2f9 100644 --- a/source/AAS.TwinEngine.DataEngine/AAS.TwinEngine.DataEngine.csproj +++ b/source/AAS.TwinEngine.DataEngine/AAS.TwinEngine.DataEngine.csproj @@ -22,7 +22,6 @@ - diff --git a/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/IShellDescriptorService.cs b/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/IShellDescriptorService.cs index 217e1e59..143996de 100644 --- a/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/IShellDescriptorService.cs +++ b/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/IShellDescriptorService.cs @@ -7,6 +7,4 @@ public interface IShellDescriptorService Task GetAllShellDescriptorsAsync(int? limit, string? cursor, CancellationToken cancellationToken); Task GetShellDescriptorByIdAsync(string id, CancellationToken cancellationToken); - - Task SyncShellDescriptorsAsync(CancellationToken cancellationToken); } diff --git a/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/Providers/IAasRegistryProvider.cs b/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/Providers/IAasRegistryProvider.cs deleted file mode 100644 index 49621e3d..00000000 --- a/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/Providers/IAasRegistryProvider.cs +++ /dev/null @@ -1,16 +0,0 @@ -using AAS.TwinEngine.DataEngine.DomainModel.AasRegistry; - -namespace AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry.Providers; - -public interface IAasRegistryProvider -{ - Task> GetAllAsync(CancellationToken cancellationToken); - - Task GetByIdAsync(string aasIdentifier, CancellationToken cancellationToken); - - Task PutAsync(string aasIdentifier, ShellDescriptor shellDescriptorData, CancellationToken cancellationToken); - - Task DeleteByIdAsync(string aasIdentifier, CancellationToken cancellationToken); - - Task CreateAsync(ShellDescriptor shellDescriptorData, CancellationToken cancellationToken); -} diff --git a/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/ShellDescriptorService.cs b/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/ShellDescriptorService.cs index 4a13fec5..2a15c560 100644 --- a/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/ShellDescriptorService.cs +++ b/source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/ShellDescriptorService.cs @@ -1,7 +1,6 @@ -using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Application; +using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Application; using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Infrastructure; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasEnvironment.Providers; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry.Providers; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin; using AAS.TwinEngine.DataEngine.DomainModel.AasRegistry; @@ -11,8 +10,6 @@ public class ShellDescriptorService( ITemplateProvider templateProvider, IShellDescriptorDataHandler shellDescriptorDataHandler, IPluginDataHandler pluginDataHandler, - IAasRegistryProvider aasRegistryProvider, - ILogger logger, IPluginManifestConflictHandler pluginManifestConflictHandler) : IShellDescriptorService { public async Task GetAllShellDescriptorsAsync(int? limit, string? cursor, CancellationToken cancellationToken) @@ -72,105 +69,4 @@ public class ShellDescriptorService( throw new InvalidUserInputException(ex); } } - - public async Task SyncShellDescriptorsAsync(CancellationToken cancellationToken) - { - try - { - var existingDescriptors = await aasRegistryProvider.GetAllAsync(cancellationToken).ConfigureAwait(false); - if (existingDescriptors == null) - { - logger.LogError("AAS Registry returned null. Sync skipped."); - return; - } - - var pluginManifests = pluginManifestConflictHandler.Manifests; - - var pluginMetadata = await pluginDataHandler.GetDataForAllShellDescriptorsAsync(null, null, pluginManifests, cancellationToken).ConfigureAwait(false); - if (pluginMetadata == null) - { - logger.LogError("Plugin metadata unavailable. Sync skipped."); - return; - } - - if (existingDescriptors.Any(d => string.IsNullOrWhiteSpace(d.Id))) - { - logger.LogError("One or more registry descriptors have missing IDs: {@Descriptors}", existingDescriptors); - return; - } - - if (pluginMetadata.ShellDescriptors.Any(m => string.IsNullOrWhiteSpace(m.Id))) - { - logger.LogError("One or more plugin metadata entries have missing IDs: {@Metadata}", pluginMetadata); - return; - } - - var existingDescriptorsMap = existingDescriptors.ToDictionary(d => d.Id!); - var pluginMetadataMap = pluginMetadata.ShellDescriptors.ToDictionary(m => m.Id!); - - await CreateOrUpdateShellDescriptorsAsync(existingDescriptorsMap!, pluginMetadata.ShellDescriptors, cancellationToken).ConfigureAwait(false); - await DeleteMissingShellDescriptorsAsync(existingDescriptors, pluginMetadataMap!, cancellationToken).ConfigureAwait(false); - } - catch (Exception ex) - { - logger.LogError(ex, "Unexpected error during ShellDescriptor synchronization."); - } - } - - private async Task CreateOrUpdateShellDescriptorsAsync( - Dictionary existingDescriptorsMap, - IList pluginMetadata, - CancellationToken cancellationToken) - { - foreach (var metadata in pluginMetadata) - { - try - { - if (existingDescriptorsMap.TryGetValue(metadata.Id!, out var existingDescriptor)) - { - var updatedDescriptor = shellDescriptorDataHandler.FillOut(existingDescriptor, metadata); - await aasRegistryProvider.PutAsync(existingDescriptor.Id!, updatedDescriptor, cancellationToken).ConfigureAwait(false); - } - else - { - var template = await templateProvider.GetShellDescriptorsTemplateAsync(cancellationToken).ConfigureAwait(false); - var newDescriptor = shellDescriptorDataHandler.FillOut(template, metadata); - await aasRegistryProvider.CreateAsync(newDescriptor, cancellationToken).ConfigureAwait(false); - } - } - catch (Exception ex) - { - logger.LogError(ex, "Unhandled error while processing descriptor with ID '{Id}'", metadata.Id); - continue; - } - } - } - - private async Task DeleteMissingShellDescriptorsAsync( - List existingDescriptors, - Dictionary pluginMetadataMap, - CancellationToken cancellationToken) - { - var missingShellDescriptorsIds = existingDescriptors - .Select(descriptor => descriptor.Id) - .Where(id => !string.IsNullOrWhiteSpace(id) && !pluginMetadataMap.ContainsKey(id)).ToList(); - - if (missingShellDescriptorsIds.Count == 0) - { - logger.LogInformation("No missing shell descriptors found to delete."); - return; - } - foreach (var descriptorId in missingShellDescriptorsIds) - { - try - { - await aasRegistryProvider.DeleteByIdAsync(descriptorId!, cancellationToken).ConfigureAwait(false); - } - catch (Exception ex) - { - logger.LogError(ex, "Unexpected error while deleting descriptor with ID '{Id}'", descriptorId); - continue; - } - } - } } diff --git a/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Config/AasRegistryPreComputed.cs b/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Config/AasRegistryPreComputed.cs deleted file mode 100644 index 0c4a666f..00000000 --- a/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Config/AasRegistryPreComputed.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Config; - -public class AasRegistryPreComputed -{ - public const string Section = "AasRegistryPreComputed"; - - public required string ShellDescriptorCron { get; set; } - - public required bool IsPreComputed { get; set; } -} diff --git a/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/AasRegistryProvider.cs b/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/AasRegistryProvider.cs deleted file mode 100644 index 3b8999d1..00000000 --- a/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/AasRegistryProvider.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System.Text; -using System.Text.Json; - -using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Infrastructure; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Extensions; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry.Providers; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin.Config; -using AAS.TwinEngine.DataEngine.DomainModel.AasRegistry; -using AAS.TwinEngine.DataEngine.Infrastructure.Http.Clients; -using AAS.TwinEngine.DataEngine.Infrastructure.Shared; - -using Microsoft.Extensions.Options; - -namespace AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Services; - -public class AasRegistryProvider(ILogger logger, ICreateClient clientFactory, IOptions aasEnvironment) : IAasRegistryProvider -{ - private readonly string _aasRegistryPath = aasEnvironment.Value.AasRegistryPath; - private const string HttpClientName = AasEnvironmentConfig.AasRegistryHttpClientName; - - public async Task> GetAllAsync(CancellationToken cancellationToken) - { - var url = $"{_aasRegistryPath}"; - - var content = await SendGetRequestAndReadContentAsync(url, cancellationToken).ConfigureAwait(false); - - using var doc = JsonDocument.Parse(content); - if (!doc.RootElement.TryGetProperty("result", out var resultElement)) - { - logger.LogError("Invalid JSON structure in response."); - throw new ResponseParsingException(); - } - - return JsonSerializer.Deserialize>(resultElement.GetRawText(), JsonSerializationOptions.Serialization) ?? []; - } - - public async Task GetByIdAsync(string aasIdentifier, CancellationToken cancellationToken) - { - var encodedAasIdentifier = aasIdentifier.EncodeBase64Url(); - - var url = $"{_aasRegistryPath}/{encodedAasIdentifier}"; - - var content = await SendGetRequestAndReadContentAsync(url, cancellationToken).ConfigureAwait(false); - - return DeserializeContent(content, "shell descriptor", url); - } - - public async Task PutAsync(string aasIdentifier, ShellDescriptor shellDescriptorData, CancellationToken cancellationToken) - { - var encodedAasIdentifier = aasIdentifier.EncodeBase64Url(); - - var url = $"{_aasRegistryPath}/{encodedAasIdentifier}"; - - await SendRequestWithBodyAsync(HttpMethod.Put, url, shellDescriptorData, cancellationToken).ConfigureAwait(false); - } - - public async Task DeleteByIdAsync(string aasIdentifier, CancellationToken cancellationToken) - { - var encodedAasIdentifier = aasIdentifier.EncodeBase64Url(); - - var url = $"{_aasRegistryPath}/{encodedAasIdentifier}"; - - var relativeUri = new Uri(url, UriKind.Relative); - - var client = clientFactory.CreateClient(HttpClientName); - - logger.LogInformation("Sending HTTP DELETE request to {Url}", url); - - var response = await client.DeleteAsync(relativeUri, cancellationToken).ConfigureAwait(false); - - await HandleResponseAsync(response, $"delete ShellDescriptor for {aasIdentifier}", url, cancellationToken).ConfigureAwait(false); - } - - public async Task CreateAsync(ShellDescriptor shellDescriptorData, CancellationToken cancellationToken) => await SendRequestWithBodyAsync(HttpMethod.Post, _aasRegistryPath, shellDescriptorData, cancellationToken).ConfigureAwait(false); - - private async Task SendGetRequestAndReadContentAsync(string url, CancellationToken cancellationToken) - { - logger.LogInformation("Sending HTTP GET request to {Url}", url); - var relativeUri = new Uri(url, UriKind.Relative); - - var client = clientFactory.CreateClient(HttpClientName); - var response = await client.GetAsync(relativeUri, cancellationToken).ConfigureAwait(false); - - if (response.IsSuccessStatusCode) - { - return await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - - var error = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - logger.LogError("GET failed: {StatusCode}, {Error}", response.StatusCode, error); - switch (response.StatusCode) - { - case System.Net.HttpStatusCode.NotFound: - logger.LogError("Requested resource could not be found. Endpoint: {Url}", url); - throw new ResourceNotFoundException(); - - case System.Net.HttpStatusCode.Unauthorized: - case System.Net.HttpStatusCode.Forbidden: - logger.LogError("Unauthorized access. Endpoint: {Url}", url); - throw new ServiceAuthorizationException(); - - case System.Net.HttpStatusCode.RequestTimeout: - logger.LogError("Request timed out. Endpoint: {Url}", url); - throw new RequestTimeoutException(); - - default: - logger.LogError("Validation error encountered. Endpoint: {Url}", url); - throw new ValidationFailedException(); - } - } - - private async Task SendRequestWithBodyAsync(HttpMethod method, string url, ShellDescriptor data, CancellationToken cancellationToken) - { - var client = clientFactory.CreateClient(HttpClientName); - var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json"); - - logger.LogInformation("Sending HTTP {Method} request to {Url}", method, url); - - using var request = new HttpRequestMessage(method, url); - request.Content = content; - var response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false); - - await HandleResponseAsync(response, $"{method} ShellDescriptor", url, cancellationToken).ConfigureAwait(false); - } - - private async Task HandleResponseAsync(HttpResponseMessage response, string action, string url, CancellationToken cancellationToken) - { - if (response.IsSuccessStatusCode) - { - logger.LogInformation("Successfully completed action: {Action}", action); - return; - } - - var error = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - logger.LogError("Failed action. Status: {StatusCode}, Response: {Error}", response.StatusCode, error); - - throw response.StatusCode switch - { - System.Net.HttpStatusCode.NotFound => new ResourceNotFoundException(), - System.Net.HttpStatusCode.Unauthorized or System.Net.HttpStatusCode.Forbidden => - new ServiceAuthorizationException(), - System.Net.HttpStatusCode.BadRequest => new ValidationFailedException(), - _ => new RequestTimeoutException() - }; - } - - private static T DeserializeContent(string content, string context, string url) - { - try - { - return JsonSerializer.Deserialize(content) ?? throw new InvalidOperationException($"Failed to deserialize {context}."); - } - catch - { - throw new ResponseParsingException(); - } - } -} diff --git a/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/ShellDescriptorSyncHosted.cs b/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/ShellDescriptorSyncHosted.cs deleted file mode 100644 index edbac98c..00000000 --- a/source/AAS.TwinEngine.DataEngine/Infrastructure/Providers/AasRegistryProvider/Services/ShellDescriptorSyncHosted.cs +++ /dev/null @@ -1,76 +0,0 @@ -using AAS.TwinEngine.DataEngine.ApplicationLogic.Exceptions.Infrastructure; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry; -using AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Config; - -using Cronos; - -using Microsoft.Extensions.Options; - -namespace AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Services; - -public class ShellDescriptorSyncHosted( - IServiceScopeFactory scopeFactory, - IOptions config, - ILogger logger) : BackgroundService -{ - private readonly CronExpression _cronExpression = CronExpression.Parse(config.Value.ShellDescriptorCron, CronFormat.IncludeSeconds); - private readonly bool _isPreComputed = config.Value.IsPreComputed; - private readonly TimeZoneInfo _timeZone = TimeZoneInfo.Local; - - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - logger.LogInformation("ShellDescriptor Cron sync started."); - - while (!stoppingToken.IsCancellationRequested) - { - var next = _cronExpression.GetNextOccurrence(DateTimeOffset.UtcNow, _timeZone); - if (!next.HasValue) - { - logger.LogWarning("Cron expression returned no next occurrence."); - break; - } - - var delay = next.Value - DateTimeOffset.UtcNow; - if (delay > TimeSpan.Zero) - { - try - { - await Task.Delay(delay, stoppingToken).ConfigureAwait(false); - } - catch (TaskCanceledException ex) - { - logger.LogInformation(ex, "Task delay was canceled. Stopping execution loop."); - break; - } - } - - try - { - await RunOnceAsync(stoppingToken).ConfigureAwait(false); - } - catch (HttpRequestException) - { - throw new ResourceNotFoundException(); - } - catch (TaskCanceledException) - { - throw new RequestTimeoutException(); - } - } - } - - public async Task RunOnceAsync(CancellationToken cancellationToken) - { - if (!_isPreComputed) - { - logger.LogInformation("Skipping ShellDescriptor sync as Pre-Computed set to false."); - return; - } - - using var scope = scopeFactory.CreateScope(); - var syncService = scope.ServiceProvider.GetRequiredService(); - - await syncService.SyncShellDescriptorsAsync(cancellationToken).ConfigureAwait(false); - logger.LogInformation("ShellDescriptor sync completed at {Time}", DateTimeOffset.UtcNow); - } -} diff --git a/source/AAS.TwinEngine.DataEngine/ServiceConfiguration/InfrastructureDependencyInjectionExtensions.cs b/source/AAS.TwinEngine.DataEngine/ServiceConfiguration/InfrastructureDependencyInjectionExtensions.cs index 18042452..4076cf68 100644 --- a/source/AAS.TwinEngine.DataEngine/ServiceConfiguration/InfrastructureDependencyInjectionExtensions.cs +++ b/source/AAS.TwinEngine.DataEngine/ServiceConfiguration/InfrastructureDependencyInjectionExtensions.cs @@ -1,5 +1,4 @@ using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasEnvironment.Providers; -using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRegistry.Providers; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin.Config; using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin.Helper; @@ -10,7 +9,6 @@ using AAS.TwinEngine.DataEngine.Infrastructure.Http.Config; using AAS.TwinEngine.DataEngine.Infrastructure.Http.Extensions; using AAS.TwinEngine.DataEngine.Infrastructure.Monitoring; -using AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Config; using AAS.TwinEngine.DataEngine.Infrastructure.Providers.AasRegistryProvider.Services; using AAS.TwinEngine.DataEngine.Infrastructure.Providers.PluginDataProvider.Config; using AAS.TwinEngine.DataEngine.Infrastructure.Providers.PluginDataProvider.Helper; @@ -41,7 +39,6 @@ public static void ConfigureInfrastructure(this IServiceCollection services, ICo _ = services.AddOptions().Bind(configuration.GetSection(Semantics.Section)).ValidateDataAnnotations().ValidateOnStart(); _ = services.AddHttpClientWithResilience(configuration, AasEnvironmentConfig.AasEnvironmentRepoHttpClientName, HttpRetryPolicyOptions.TemplateProvider, aasEnvironment?.AasEnvironmentRepositoryBaseUrl!); - _ = services.AddHttpClientWithResilience(configuration, AasEnvironmentConfig.AasRegistryHttpClientName, HttpRetryPolicyOptions.TemplateProvider, aasEnvironment?.AasRegistryBaseUrl!); _ = services.AddHttpClientWithResilience(configuration, AasEnvironmentConfig.SubmodelRegistryHttpClientName, HttpRetryPolicyOptions.SubmodelDescriptorProvider, aasEnvironment?.SubModelRegistryBaseUrl!); foreach (var plugin in plugins.Plugins) @@ -50,7 +47,6 @@ public static void ConfigureInfrastructure(this IServiceCollection services, ICo } _ = services.AddScoped(); - _ = services.AddScoped(); _ = services.AddScoped(); _ = services.AddScoped(); _ = services.AddScoped(); @@ -61,9 +57,7 @@ public static void ConfigureInfrastructure(this IServiceCollection services, ICo _ = services.Configure(HttpRetryPolicyOptions.TemplateProvider, configuration.GetSection($"{HttpRetryPolicyOptions.Section}:{HttpRetryPolicyOptions.TemplateProvider}")); _ = services.Configure(HttpRetryPolicyOptions.SubmodelDescriptorProvider, configuration.GetSection($"{HttpRetryPolicyOptions.Section}:{HttpRetryPolicyOptions.SubmodelDescriptorProvider}")); _ = services.Configure(configuration.GetSection(HttpRetryPolicyOptions.Section)); - _ = services.Configure(configuration.GetSection(AasRegistryPreComputed.Section)); _ = services.Configure(configuration.GetSection(MultiPluginConflictOptions.Section)); _ = services.AddSingleton(); - _ = services.AddHostedService(); } } diff --git a/source/AAS.TwinEngine.DataEngine/appsettings.development.json b/source/AAS.TwinEngine.DataEngine/appsettings.development.json index 071ae0f2..659c3b25 100644 --- a/source/AAS.TwinEngine.DataEngine/appsettings.development.json +++ b/source/AAS.TwinEngine.DataEngine/appsettings.development.json @@ -35,10 +35,6 @@ "AasxExportOptions": { "RootFolder": "aasx" }, - "AasRegistryPreComputed": { - "ShellDescriptorCron": "0 */3 * * * *", - "IsPreComputed": true - }, "TemplateMappingRules": { "SubmodelTemplateMappings": [ { diff --git a/source/AAS.TwinEngine.DataEngine/appsettings.json b/source/AAS.TwinEngine.DataEngine/appsettings.json index 3c8b7ace..6e3d5510 100644 --- a/source/AAS.TwinEngine.DataEngine/appsettings.json +++ b/source/AAS.TwinEngine.DataEngine/appsettings.json @@ -35,10 +35,6 @@ "AasxExportOptions": { "RootFolder": "aasx" }, - "AasRegistryPreComputed": { - "ShellDescriptorCron": "0 */3 * * * *", - "IsPreComputed": false - }, "TemplateMappingRules": { "SubmodelTemplateMappings": [ {