From c9fbf730f7506123ec94c0699103ab5620ad44df Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Fri, 18 Oct 2024 16:28:23 +0100 Subject: [PATCH 01/10] Added serval release version to translation build --- docker-compose.yml | 2 +- .../src/Serval.ApiServer/ServalSettings.cs | 6 ++++ src/Serval/src/Serval.ApiServer/Startup.cs | 1 + .../src/Serval.ApiServer/appsettings.json | 3 ++ src/Serval/src/Serval.Client/Client.g.cs | 3 ++ .../Configuration/ServalSettings.cs | 6 ++++ .../Contracts/TranslationBuildDto.cs | 1 + .../TranslationEnginesController.cs | 7 +++-- .../src/Serval.Translation/Models/Build.cs | 1 + .../test/Serval.E2ETests/ServalApiTests.cs | 29 +++++++++++++++++++ 10 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/Serval/src/Serval.ApiServer/ServalSettings.cs create mode 100644 src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs diff --git a/docker-compose.yml b/docker-compose.yml index 8592c6e7..6e568f99 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -182,4 +182,4 @@ services: '/bin/sh', '-c', 'mongod --quiet --replSet myRS --bind_ip 0.0.0.0 & sleep 2s; mongosh --host localhost:27017 --eval '' config = { "_id" : "myRS", "members" : [{"_id" : 0,"host" : "mongo:27017"}] }; rs.initiate(config, { force: true }); '' ; sleep infinity' - ] + ] \ No newline at end of file diff --git a/src/Serval/src/Serval.ApiServer/ServalSettings.cs b/src/Serval/src/Serval.ApiServer/ServalSettings.cs new file mode 100644 index 00000000..20205b01 --- /dev/null +++ b/src/Serval/src/Serval.ApiServer/ServalSettings.cs @@ -0,0 +1,6 @@ +namespace Serval.ApiServer; + +public class ServalSettings +{ + public string ReleaseVersion { get; set; } = "1.0.0"; // Default value +} diff --git a/src/Serval/src/Serval.ApiServer/Startup.cs b/src/Serval/src/Serval.ApiServer/Startup.cs index d4c5a3cd..a3856962 100644 --- a/src/Serval/src/Serval.ApiServer/Startup.cs +++ b/src/Serval/src/Serval.ApiServer/Startup.cs @@ -213,6 +213,7 @@ public void ConfigureServices(IServiceCollection services) .AddOpenTelemetry() .WithMetrics(opts => opts.AddAspNetCoreInstrumentation().AddPrometheusExporter()); } + services.Configure(Configuration.GetSection("ServalSettings")); services.Configure(Configuration.GetSection("Bugsnag")); services.AddBugsnag(); } diff --git a/src/Serval/src/Serval.ApiServer/appsettings.json b/src/Serval/src/Serval.ApiServer/appsettings.json index 496183ef..6b55a2d9 100644 --- a/src/Serval/src/Serval.ApiServer/appsettings.json +++ b/src/Serval/src/Serval.ApiServer/appsettings.json @@ -14,5 +14,8 @@ "LogLevel": { "System.Net.Http.HttpClient": "Warning" } + }, + "ServalSettings": { + "ReleaseVersion": "1.0.0" } } \ No newline at end of file diff --git a/src/Serval/src/Serval.Client/Client.g.cs b/src/Serval/src/Serval.Client/Client.g.cs index 7cfa2548..aa136b3a 100644 --- a/src/Serval/src/Serval.Client/Client.g.cs +++ b/src/Serval/src/Serval.Client/Client.g.cs @@ -9838,6 +9838,9 @@ public partial class TranslationBuild [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public object? Options { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("servalReleaseVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? ServalReleaseVersion { get; set; } = default!; + } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")] diff --git a/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs b/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs new file mode 100644 index 00000000..ab173fe1 --- /dev/null +++ b/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs @@ -0,0 +1,6 @@ +namespace Serval.Shared.Configuration; + +public class ServalSettings +{ + public string ReleaseVersion { get; set; } = "1.0.0"; // Default value +} diff --git a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs index 741ff4ba..bf77741a 100644 --- a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -27,4 +27,5 @@ public record TranslationBuildDto /// } /// public object? Options { get; init; } + public string? ServalReleaseVersion { get; init; } } diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index 8fb394ae..891a52e4 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -10,7 +10,8 @@ public class TranslationEnginesController( IPretranslationService pretranslationService, IOptionsMonitor apiOptions, IUrlService urlService, - ILogger logger + ILogger logger, + IOptions servalSettingsOptions ) : ServalControllerBase(authService) { private static readonly JsonSerializerOptions ObjectJsonSerializerOptions = @@ -22,6 +23,7 @@ ILogger logger private readonly IOptionsMonitor _apiOptions = apiOptions; private readonly IUrlService _urlService = urlService; private readonly ILogger _logger = logger; + private readonly ServalSettings _servalSettings = servalSettingsOptions.Value; /// /// Get all translation engines @@ -1534,7 +1536,8 @@ private TranslationBuildDto Map(Build source) QueueDepth = source.QueueDepth, State = source.State, DateFinished = source.DateFinished, - Options = source.Options + Options = source.Options, + ServalReleaseVersion = _servalSettings.ReleaseVersion }; } diff --git a/src/Serval/src/Serval.Translation/Models/Build.cs b/src/Serval/src/Serval.Translation/Models/Build.cs index 2c67ba79..e12607b2 100644 --- a/src/Serval/src/Serval.Translation/Models/Build.cs +++ b/src/Serval/src/Serval.Translation/Models/Build.cs @@ -15,4 +15,5 @@ public record Build : IEntity public JobState State { get; init; } = JobState.Pending; public DateTime? DateFinished { get; init; } public IReadOnlyDictionary? Options { get; init; } + public string? ServalReleaseVersion { get; set; } } diff --git a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs index d4899775..a58534b2 100644 --- a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs +++ b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs @@ -46,6 +46,35 @@ public async Task GetEchoPretranslate() Assert.That(pretranslations, Has.Count.GreaterThan(1)); } + [Test] + public async Task GetServalReleaseVersion() + { + string engineId = await _helperClient.CreateNewEngineAsync("Echo", "es", "es", "Echo2"); + string[] books = ["1JN.txt", "2JN.txt"]; + await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", false); + books = ["3JN.txt"]; + string corpusId = await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", true); + await _helperClient.BuildEngineAsync(engineId); + IList pretranslations = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync( + engineId, + corpusId + ); + Assert.That(pretranslations, Has.Count.GreaterThan(1)); + TranslationBuild build = await _helperClient.TranslationEnginesClient.GetCurrentBuildAsync(engineId); + Assert.That( + build.ServalReleaseVersion, + Is.Not.Null.And.Not.Empty, + "Serval release version should not be null or empty." + ); + + var hasServalReleaseVersionProperty = typeof(TranslationBuild).GetProperty("ServalReleaseVersion") != null; + Assert.That( + hasServalReleaseVersionProperty, + Is.True, + "ServalReleaseVersion property should exist in the build." + ); + } + [Test] public async Task GetSmtTranslation() { From 9d955516ed0c731286db66bfae114ec50fad7c4d Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Mon, 21 Oct 2024 17:39:36 +0100 Subject: [PATCH 02/10] Made requested changes --- .../src/Serval.ApiServer/ServalSettings.cs | 6 ---- src/Serval/src/Serval.ApiServer/Startup.cs | 1 - src/Serval/src/Serval.Client/Client.g.cs | 4 +-- .../Serval.Shared/Configuration/ApiOptions.cs | 1 + .../Configuration/ServalSettings.cs | 6 ---- .../Contracts/TranslationBuildDto.cs | 2 +- .../TranslationEnginesController.cs | 8 ++--- .../src/Serval.Translation/Models/Build.cs | 2 +- .../TranslationEngineTests.cs | 13 +++++++-- .../test/Serval.E2ETests/ServalApiTests.cs | 29 ------------------- 10 files changed, 19 insertions(+), 53 deletions(-) delete mode 100644 src/Serval/src/Serval.ApiServer/ServalSettings.cs delete mode 100644 src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs diff --git a/src/Serval/src/Serval.ApiServer/ServalSettings.cs b/src/Serval/src/Serval.ApiServer/ServalSettings.cs deleted file mode 100644 index 20205b01..00000000 --- a/src/Serval/src/Serval.ApiServer/ServalSettings.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Serval.ApiServer; - -public class ServalSettings -{ - public string ReleaseVersion { get; set; } = "1.0.0"; // Default value -} diff --git a/src/Serval/src/Serval.ApiServer/Startup.cs b/src/Serval/src/Serval.ApiServer/Startup.cs index a3856962..d4c5a3cd 100644 --- a/src/Serval/src/Serval.ApiServer/Startup.cs +++ b/src/Serval/src/Serval.ApiServer/Startup.cs @@ -213,7 +213,6 @@ public void ConfigureServices(IServiceCollection services) .AddOpenTelemetry() .WithMetrics(opts => opts.AddAspNetCoreInstrumentation().AddPrometheusExporter()); } - services.Configure(Configuration.GetSection("ServalSettings")); services.Configure(Configuration.GetSection("Bugsnag")); services.AddBugsnag(); } diff --git a/src/Serval/src/Serval.Client/Client.g.cs b/src/Serval/src/Serval.Client/Client.g.cs index aa136b3a..3cf330b0 100644 --- a/src/Serval/src/Serval.Client/Client.g.cs +++ b/src/Serval/src/Serval.Client/Client.g.cs @@ -9838,8 +9838,8 @@ public partial class TranslationBuild [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public object? Options { get; set; } = default!; - [Newtonsoft.Json.JsonProperty("servalReleaseVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? ServalReleaseVersion { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("servalVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? ServalVersion { get; set; } = default!; } diff --git a/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs b/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs index 9a998b72..e476ce32 100644 --- a/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs +++ b/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs @@ -6,4 +6,5 @@ public class ApiOptions public TimeSpan DefaultHttpRequestTimeout { get; set; } = TimeSpan.FromSeconds(58); // must be less than 60 seconds Cloudflare timeout public TimeSpan LongPollTimeout { get; set; } = TimeSpan.FromSeconds(40); // must be less than DefaultHttpRequestTimeout + public string ServalVersion { get; set; } = "1.0.0"; // Default value } diff --git a/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs b/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs deleted file mode 100644 index ab173fe1..00000000 --- a/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Serval.Shared.Configuration; - -public class ServalSettings -{ - public string ReleaseVersion { get; set; } = "1.0.0"; // Default value -} diff --git a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs index bf77741a..ab57d910 100644 --- a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -27,5 +27,5 @@ public record TranslationBuildDto /// } /// public object? Options { get; init; } - public string? ServalReleaseVersion { get; init; } + public string? ServalVersion { get; init; } } diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index 891a52e4..21a88369 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -10,8 +10,7 @@ public class TranslationEnginesController( IPretranslationService pretranslationService, IOptionsMonitor apiOptions, IUrlService urlService, - ILogger logger, - IOptions servalSettingsOptions + ILogger logger ) : ServalControllerBase(authService) { private static readonly JsonSerializerOptions ObjectJsonSerializerOptions = @@ -23,7 +22,8 @@ IOptions servalSettingsOptions private readonly IOptionsMonitor _apiOptions = apiOptions; private readonly IUrlService _urlService = urlService; private readonly ILogger _logger = logger; - private readonly ServalSettings _servalSettings = servalSettingsOptions.Value; + + // private readonly ServalSettings _servalSettings = apiOptions.Value; /// /// Get all translation engines @@ -1537,7 +1537,7 @@ private TranslationBuildDto Map(Build source) State = source.State, DateFinished = source.DateFinished, Options = source.Options, - ServalReleaseVersion = _servalSettings.ReleaseVersion + ServalVersion = _apiOptions.CurrentValue.ServalVersion }; } diff --git a/src/Serval/src/Serval.Translation/Models/Build.cs b/src/Serval/src/Serval.Translation/Models/Build.cs index e12607b2..a83bb590 100644 --- a/src/Serval/src/Serval.Translation/Models/Build.cs +++ b/src/Serval/src/Serval.Translation/Models/Build.cs @@ -15,5 +15,5 @@ public record Build : IEntity public JobState State { get; init; } = JobState.Pending; public DateTime? DateFinished { get; init; } public IReadOnlyDictionary? Options { get; init; } - public string? ServalReleaseVersion { get; set; } + public string? ServalVersion { get; set; } } diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index d5bb79f3..ccf961bf 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -7,7 +7,7 @@ namespace Serval.ApiServer; [TestFixture] [Category("Integration")] -public class TranslationEngineTests +public class TranslationEngineTests(IOptionsMonitor apiOptions, TranslationEngineTests.TestEnvironment env) { private static readonly TranslationCorpusConfig TestCorpusConfig = new() @@ -83,8 +83,9 @@ public class TranslationEngineTests private const string TARGET_CORPUS_ID = "cc0000000000000000000003"; private const string DOES_NOT_EXIST_ENGINE_ID = "e00000000000000000000004"; private const string DOES_NOT_EXIST_CORPUS_ID = "c00000000000000000000001"; + private readonly IOptionsMonitor _apiOptions = apiOptions; - private TestEnvironment _env; + private TestEnvironment _env = env; [SetUp] public async Task SetUp() @@ -1407,6 +1408,12 @@ public async Task StartBuildForEngineByIdAsync(IEnumerable scope, int ex build = await client.GetCurrentBuildAsync(engineId); Assert.That(build, Is.Not.Null); + + // Fetch and assert ServalVersion from ApiOptions + // ApiOptions apiOptions = _env.GetRequiredService>().CurrentValue; + Assert.That(_apiOptions.CurrentValue.ServalVersion, Is.Not.Null); + // Assert.That(apiOptions.ServalVersion, Is.EqualTo("expected_version")); // Replace with the actual expected version + break; case 400: case 403: @@ -2032,7 +2039,7 @@ public void TearDown() _env.Dispose(); } - private class TestEnvironment : DisposableBase + public class TestEnvironment : DisposableBase { private readonly IServiceScope _scope; private readonly MongoClient _mongoClient; diff --git a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs index a58534b2..d4899775 100644 --- a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs +++ b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs @@ -46,35 +46,6 @@ public async Task GetEchoPretranslate() Assert.That(pretranslations, Has.Count.GreaterThan(1)); } - [Test] - public async Task GetServalReleaseVersion() - { - string engineId = await _helperClient.CreateNewEngineAsync("Echo", "es", "es", "Echo2"); - string[] books = ["1JN.txt", "2JN.txt"]; - await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", false); - books = ["3JN.txt"]; - string corpusId = await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", true); - await _helperClient.BuildEngineAsync(engineId); - IList pretranslations = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync( - engineId, - corpusId - ); - Assert.That(pretranslations, Has.Count.GreaterThan(1)); - TranslationBuild build = await _helperClient.TranslationEnginesClient.GetCurrentBuildAsync(engineId); - Assert.That( - build.ServalReleaseVersion, - Is.Not.Null.And.Not.Empty, - "Serval release version should not be null or empty." - ); - - var hasServalReleaseVersionProperty = typeof(TranslationBuild).GetProperty("ServalReleaseVersion") != null; - Assert.That( - hasServalReleaseVersionProperty, - Is.True, - "ServalReleaseVersion property should exist in the build." - ); - } - [Test] public async Task GetSmtTranslation() { From 2e98455e6d53e7a6233a36608293bce3dcabc74d Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Mon, 21 Oct 2024 20:54:01 +0100 Subject: [PATCH 03/10] Fixed constructor issue --- .../TranslationEngineTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index ccf961bf..54119fdc 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -7,7 +7,7 @@ namespace Serval.ApiServer; [TestFixture] [Category("Integration")] -public class TranslationEngineTests(IOptionsMonitor apiOptions, TranslationEngineTests.TestEnvironment env) +public class TranslationEngineTests { private static readonly TranslationCorpusConfig TestCorpusConfig = new() @@ -83,9 +83,8 @@ public class TranslationEngineTests(IOptionsMonitor apiOptions, Tran private const string TARGET_CORPUS_ID = "cc0000000000000000000003"; private const string DOES_NOT_EXIST_ENGINE_ID = "e00000000000000000000004"; private const string DOES_NOT_EXIST_CORPUS_ID = "c00000000000000000000001"; - private readonly IOptionsMonitor _apiOptions = apiOptions; - private TestEnvironment _env = env; + private TestEnvironment _env; [SetUp] public async Task SetUp() @@ -1411,7 +1410,7 @@ public async Task StartBuildForEngineByIdAsync(IEnumerable scope, int ex // Fetch and assert ServalVersion from ApiOptions // ApiOptions apiOptions = _env.GetRequiredService>().CurrentValue; - Assert.That(_apiOptions.CurrentValue.ServalVersion, Is.Not.Null); + Assert.That(_env.ApiOptions.CurrentValue.ServalVersion, Is.Not.Null); // Assert.That(apiOptions.ServalVersion, Is.EqualTo("expected_version")); // Replace with the actual expected version break; @@ -2043,6 +2042,7 @@ public class TestEnvironment : DisposableBase { private readonly IServiceScope _scope; private readonly MongoClient _mongoClient; + public readonly IOptionsMonitor ApiOptions; public TestEnvironment() { @@ -2053,6 +2053,7 @@ public TestEnvironment() Factory = new ServalWebApplicationFactory(); _scope = Factory.Services.CreateScope(); Engines = _scope.ServiceProvider.GetRequiredService>(); + ApiOptions = _scope.ServiceProvider.GetRequiredService>(); DataFiles = _scope.ServiceProvider.GetRequiredService>(); Corpora = _scope.ServiceProvider.GetRequiredService>(); Pretranslations = _scope.ServiceProvider.GetRequiredService< From 4f5c3d86943423a035ad02dcc325f5879b85e472 Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Wed, 23 Oct 2024 13:32:09 +0100 Subject: [PATCH 04/10] Used deployment version --- src/Serval/src/Serval.Client/Client.g.cs | 4 ++-- src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs | 1 - .../src/Serval.Translation/Contracts/TranslationBuildDto.cs | 3 ++- .../Controllers/TranslationEnginesController.cs | 5 ++++- src/Serval/src/Serval.Translation/Models/Build.cs | 2 +- .../TranslationEngineTests.cs | 4 +++- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Serval/src/Serval.Client/Client.g.cs b/src/Serval/src/Serval.Client/Client.g.cs index 3cf330b0..b10b41c7 100644 --- a/src/Serval/src/Serval.Client/Client.g.cs +++ b/src/Serval/src/Serval.Client/Client.g.cs @@ -9838,8 +9838,8 @@ public partial class TranslationBuild [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public object? Options { get; set; } = default!; - [Newtonsoft.Json.JsonProperty("servalVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? ServalVersion { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("deploymentVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? DeploymentVersion { get; set; } = default!; } diff --git a/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs b/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs index e476ce32..9a998b72 100644 --- a/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs +++ b/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs @@ -6,5 +6,4 @@ public class ApiOptions public TimeSpan DefaultHttpRequestTimeout { get; set; } = TimeSpan.FromSeconds(58); // must be less than 60 seconds Cloudflare timeout public TimeSpan LongPollTimeout { get; set; } = TimeSpan.FromSeconds(40); // must be less than DefaultHttpRequestTimeout - public string ServalVersion { get; set; } = "1.0.0"; // Default value } diff --git a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs index ab57d910..1c644365 100644 --- a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -27,5 +27,6 @@ public record TranslationBuildDto /// } /// public object? Options { get; init; } - public string? ServalVersion { get; init; } + public string? DeploymentVersion { get; init; } + // public string? ServalVersion { get; init; } } diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index 21a88369..fa2a72e2 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -9,6 +9,7 @@ public class TranslationEnginesController( IBuildService buildService, IPretranslationService pretranslationService, IOptionsMonitor apiOptions, + IConfiguration configuration, IUrlService urlService, ILogger logger ) : ServalControllerBase(authService) @@ -22,6 +23,7 @@ ILogger logger private readonly IOptionsMonitor _apiOptions = apiOptions; private readonly IUrlService _urlService = urlService; private readonly ILogger _logger = logger; + private readonly IConfiguration _configuration = configuration; // private readonly ServalSettings _servalSettings = apiOptions.Value; @@ -1537,7 +1539,8 @@ private TranslationBuildDto Map(Build source) State = source.State, DateFinished = source.DateFinished, Options = source.Options, - ServalVersion = _apiOptions.CurrentValue.ServalVersion + // ServalVersion = _apiOptions.CurrentValue.ServalVersion + DeploymentVersion = _configuration.GetValue("DeploymentVersion") }; } diff --git a/src/Serval/src/Serval.Translation/Models/Build.cs b/src/Serval/src/Serval.Translation/Models/Build.cs index a83bb590..0a61be12 100644 --- a/src/Serval/src/Serval.Translation/Models/Build.cs +++ b/src/Serval/src/Serval.Translation/Models/Build.cs @@ -15,5 +15,5 @@ public record Build : IEntity public JobState State { get; init; } = JobState.Pending; public DateTime? DateFinished { get; init; } public IReadOnlyDictionary? Options { get; init; } - public string? ServalVersion { get; set; } + public string? DeploymentVersion { get; set; } } diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index 54119fdc..ee576517 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -1408,9 +1408,11 @@ public async Task StartBuildForEngineByIdAsync(IEnumerable scope, int ex build = await client.GetCurrentBuildAsync(engineId); Assert.That(build, Is.Not.Null); + Assert.That(build.DeploymentVersion, Is.EqualTo("1.6.3")); // Replace with actual expected version + // Fetch and assert ServalVersion from ApiOptions // ApiOptions apiOptions = _env.GetRequiredService>().CurrentValue; - Assert.That(_env.ApiOptions.CurrentValue.ServalVersion, Is.Not.Null); + // Assert.That(_env.ApiOptions.CurrentValue.ServalVersion, Is.Not.Null); // Assert.That(apiOptions.ServalVersion, Is.EqualTo("expected_version")); // Replace with the actual expected version break; From f7ca69700fcb2dd9ebbff19dc2851078a42d7533 Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Wed, 23 Oct 2024 14:27:24 +0100 Subject: [PATCH 05/10] Checking if test will pass --- .../Controllers/TranslationEnginesController.cs | 8 +++++--- src/Serval/src/Serval.Translation/Models/Build.cs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index fa2a72e2..d8f9a244 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -9,7 +9,7 @@ public class TranslationEnginesController( IBuildService buildService, IPretranslationService pretranslationService, IOptionsMonitor apiOptions, - IConfiguration configuration, + // IConfiguration configuration, IUrlService urlService, ILogger logger ) : ServalControllerBase(authService) @@ -23,7 +23,8 @@ ILogger logger private readonly IOptionsMonitor _apiOptions = apiOptions; private readonly IUrlService _urlService = urlService; private readonly ILogger _logger = logger; - private readonly IConfiguration _configuration = configuration; + + // private readonly IConfiguration _configuration = configuration; // private readonly ServalSettings _servalSettings = apiOptions.Value; @@ -1540,7 +1541,8 @@ private TranslationBuildDto Map(Build source) DateFinished = source.DateFinished, Options = source.Options, // ServalVersion = _apiOptions.CurrentValue.ServalVersion - DeploymentVersion = _configuration.GetValue("DeploymentVersion") + // DeploymentVersion = _configuration.GetValue("DeploymentVersion") + DeploymentVersion = source.DeploymentVersion }; } diff --git a/src/Serval/src/Serval.Translation/Models/Build.cs b/src/Serval/src/Serval.Translation/Models/Build.cs index 0a61be12..54bf038b 100644 --- a/src/Serval/src/Serval.Translation/Models/Build.cs +++ b/src/Serval/src/Serval.Translation/Models/Build.cs @@ -15,5 +15,5 @@ public record Build : IEntity public JobState State { get; init; } = JobState.Pending; public DateTime? DateFinished { get; init; } public IReadOnlyDictionary? Options { get; init; } - public string? DeploymentVersion { get; set; } + public string DeploymentVersion { get; set; } = "1.6.3"; } From e9c9871c5498b01185b5ad17001688a01b9a09ea Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Wed, 23 Oct 2024 19:05:03 +0100 Subject: [PATCH 06/10] Modification to use deployment version properly --- .../Contracts/TranslationBuildDto.cs | 1 - .../Controllers/TranslationEnginesController.cs | 15 ++++++--------- src/Serval/src/Serval.Translation/Models/Build.cs | 2 +- .../TranslationEngineTests.cs | 7 +------ 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs index 1c644365..eb009161 100644 --- a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -28,5 +28,4 @@ public record TranslationBuildDto /// public object? Options { get; init; } public string? DeploymentVersion { get; init; } - // public string? ServalVersion { get; init; } } diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index d8f9a244..fd4c4713 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -9,7 +9,7 @@ public class TranslationEnginesController( IBuildService buildService, IPretranslationService pretranslationService, IOptionsMonitor apiOptions, - // IConfiguration configuration, + IConfiguration configuration, IUrlService urlService, ILogger logger ) : ServalControllerBase(authService) @@ -24,10 +24,6 @@ ILogger logger private readonly IUrlService _urlService = urlService; private readonly ILogger _logger = logger; - // private readonly IConfiguration _configuration = configuration; - - // private readonly ServalSettings _servalSettings = apiOptions.Value; - /// /// Get all translation engines /// @@ -1316,15 +1312,18 @@ private Engine Map(TranslationEngineConfigDto source) }; } - private static Build Map(Engine engine, TranslationBuildConfigDto source) + private Build Map(Engine engine, TranslationBuildConfigDto source) { + string deploymentVersion = configuration.GetValue("DeploymentVersion") ?? "Unknown"; + return new Build { EngineRef = engine.Id, Name = source.Name, Pretranslate = Map(engine, source.Pretranslate), TrainOn = Map(engine, source.TrainOn), - Options = Map(source.Options) + Options = Map(source.Options), + DeploymentVersion = deploymentVersion }; } @@ -1540,8 +1539,6 @@ private TranslationBuildDto Map(Build source) State = source.State, DateFinished = source.DateFinished, Options = source.Options, - // ServalVersion = _apiOptions.CurrentValue.ServalVersion - // DeploymentVersion = _configuration.GetValue("DeploymentVersion") DeploymentVersion = source.DeploymentVersion }; } diff --git a/src/Serval/src/Serval.Translation/Models/Build.cs b/src/Serval/src/Serval.Translation/Models/Build.cs index 54bf038b..b0ccdf2e 100644 --- a/src/Serval/src/Serval.Translation/Models/Build.cs +++ b/src/Serval/src/Serval.Translation/Models/Build.cs @@ -15,5 +15,5 @@ public record Build : IEntity public JobState State { get; init; } = JobState.Pending; public DateTime? DateFinished { get; init; } public IReadOnlyDictionary? Options { get; init; } - public string DeploymentVersion { get; set; } = "1.6.3"; + public string? DeploymentVersion { get; set; } = "Unknown"; } diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index ee576517..fec5ed45 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -1408,12 +1408,7 @@ public async Task StartBuildForEngineByIdAsync(IEnumerable scope, int ex build = await client.GetCurrentBuildAsync(engineId); Assert.That(build, Is.Not.Null); - Assert.That(build.DeploymentVersion, Is.EqualTo("1.6.3")); // Replace with actual expected version - - // Fetch and assert ServalVersion from ApiOptions - // ApiOptions apiOptions = _env.GetRequiredService>().CurrentValue; - // Assert.That(_env.ApiOptions.CurrentValue.ServalVersion, Is.Not.Null); - // Assert.That(apiOptions.ServalVersion, Is.EqualTo("expected_version")); // Replace with the actual expected version + Assert.That(build.DeploymentVersion, Is.Not.Null); break; case 400: From 5734697830cd2e60b70f603d8b751490eb6423f9 Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Thu, 24 Oct 2024 12:16:10 +0100 Subject: [PATCH 07/10] Made edits to the PR --- src/Serval/src/Serval.Translation/Models/Build.cs | 2 +- .../TranslationEngineTests.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Serval/src/Serval.Translation/Models/Build.cs b/src/Serval/src/Serval.Translation/Models/Build.cs index b0ccdf2e..57162048 100644 --- a/src/Serval/src/Serval.Translation/Models/Build.cs +++ b/src/Serval/src/Serval.Translation/Models/Build.cs @@ -15,5 +15,5 @@ public record Build : IEntity public JobState State { get; init; } = JobState.Pending; public DateTime? DateFinished { get; init; } public IReadOnlyDictionary? Options { get; init; } - public string? DeploymentVersion { get; set; } = "Unknown"; + public string? DeploymentVersion { get; init; } } diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index fec5ed45..1c7043e5 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -2039,7 +2039,8 @@ public class TestEnvironment : DisposableBase { private readonly IServiceScope _scope; private readonly MongoClient _mongoClient; - public readonly IOptionsMonitor ApiOptions; + + // public readonly IOptionsMonitor ApiOptions; public TestEnvironment() { @@ -2050,7 +2051,7 @@ public TestEnvironment() Factory = new ServalWebApplicationFactory(); _scope = Factory.Services.CreateScope(); Engines = _scope.ServiceProvider.GetRequiredService>(); - ApiOptions = _scope.ServiceProvider.GetRequiredService>(); + // ApiOptions = _scope.ServiceProvider.GetRequiredService>(); DataFiles = _scope.ServiceProvider.GetRequiredService>(); Corpora = _scope.ServiceProvider.GetRequiredService>(); Pretranslations = _scope.ServiceProvider.GetRequiredService< From dcc19b0f94d29ac26ca79c381d70592466fb2f16 Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Thu, 24 Oct 2024 17:23:10 +0100 Subject: [PATCH 08/10] Removed commented code --- .../TranslationEngineTests.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index 1c7043e5..ea337ab1 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -2040,8 +2040,6 @@ public class TestEnvironment : DisposableBase private readonly IServiceScope _scope; private readonly MongoClient _mongoClient; - // public readonly IOptionsMonitor ApiOptions; - public TestEnvironment() { var clientSettings = new MongoClientSettings { LinqProvider = LinqProvider.V2 }; @@ -2051,7 +2049,6 @@ public TestEnvironment() Factory = new ServalWebApplicationFactory(); _scope = Factory.Services.CreateScope(); Engines = _scope.ServiceProvider.GetRequiredService>(); - // ApiOptions = _scope.ServiceProvider.GetRequiredService>(); DataFiles = _scope.ServiceProvider.GetRequiredService>(); Corpora = _scope.ServiceProvider.GetRequiredService>(); Pretranslations = _scope.ServiceProvider.GetRequiredService< From 37e5a45f6f356fded32d88372b7a86ee47b88b0a Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Fri, 25 Oct 2024 15:12:37 +0100 Subject: [PATCH 09/10] refactored code to reflect suggestions --- src/Serval/src/Serval.ApiServer/appsettings.json | 3 --- .../Controllers/TranslationEnginesController.cs | 9 +++++---- .../TranslationEngineTests.cs | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Serval/src/Serval.ApiServer/appsettings.json b/src/Serval/src/Serval.ApiServer/appsettings.json index 6b55a2d9..496183ef 100644 --- a/src/Serval/src/Serval.ApiServer/appsettings.json +++ b/src/Serval/src/Serval.ApiServer/appsettings.json @@ -14,8 +14,5 @@ "LogLevel": { "System.Net.Http.HttpClient": "Warning" } - }, - "ServalSettings": { - "ReleaseVersion": "1.0.0" } } \ No newline at end of file diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index fd4c4713..f8e7755a 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -1047,9 +1047,12 @@ public async Task> StartBuildAsync( CancellationToken cancellationToken ) { + string deploymentVersion = configuration.GetValue("deploymentVersion") ?? "Unknown"; + Engine engine = await _engineService.GetAsync(id, cancellationToken); await AuthorizeAsync(engine); - Build build = Map(engine, buildConfig); + Build build = Map(engine, buildConfig, deploymentVersion); + await _engineService.StartBuildAsync(build, cancellationToken); TranslationBuildDto dto = Map(build); @@ -1312,10 +1315,8 @@ private Engine Map(TranslationEngineConfigDto source) }; } - private Build Map(Engine engine, TranslationBuildConfigDto source) + private static Build Map(Engine engine, TranslationBuildConfigDto source, string deploymentVersion) { - string deploymentVersion = configuration.GetValue("DeploymentVersion") ?? "Unknown"; - return new Build { EngineRef = engine.Id, diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index ea337ab1..1726353f 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -2035,7 +2035,7 @@ public void TearDown() _env.Dispose(); } - public class TestEnvironment : DisposableBase + private class TestEnvironment : DisposableBase { private readonly IServiceScope _scope; private readonly MongoClient _mongoClient; From 8c791547d3367ff8eb584f7ff82b71923dd1d8b6 Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Fri, 1 Nov 2024 16:53:10 +0100 Subject: [PATCH 10/10] Made Iconfiguration read only property --- .../Controllers/TranslationEnginesController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index f8e7755a..aeb87b96 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -23,6 +23,7 @@ ILogger logger private readonly IOptionsMonitor _apiOptions = apiOptions; private readonly IUrlService _urlService = urlService; private readonly ILogger _logger = logger; + private readonly IConfiguration _configuration = configuration; /// /// Get all translation engines @@ -1047,7 +1048,7 @@ public async Task> StartBuildAsync( CancellationToken cancellationToken ) { - string deploymentVersion = configuration.GetValue("deploymentVersion") ?? "Unknown"; + string deploymentVersion = _configuration.GetValue("deploymentVersion") ?? "Unknown"; Engine engine = await _engineService.GetAsync(id, cancellationToken); await AuthorizeAsync(engine);