Skip to content

Commit

Permalink
Added serval release version to translation build
Browse files Browse the repository at this point in the history
  • Loading branch information
mudiagaobrikisil committed Oct 18, 2024
1 parent 261dde1 commit 937c563
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
]
6 changes: 6 additions & 0 deletions src/Serval/src/Serval.ApiServer/ServalSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Serval.ApiServer;

public class ServalSettings
{
public string ReleaseVersion { get; set; } = "1.0.0"; // Default value
}
1 change: 1 addition & 0 deletions src/Serval/src/Serval.ApiServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public void ConfigureServices(IServiceCollection services)
.AddOpenTelemetry()
.WithMetrics(opts => opts.AddAspNetCoreInstrumentation().AddPrometheusExporter());
}
services.Configure<Serval.Shared.Configuration.ServalSettings>(Configuration.GetSection("ServalSettings"));
services.Configure<Bugsnag.Configuration>(Configuration.GetSection("Bugsnag"));
services.AddBugsnag();
}
Expand Down
3 changes: 3 additions & 0 deletions src/Serval/src/Serval.ApiServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"LogLevel": {
"System.Net.Http.HttpClient": "Warning"
}
},
"ServalSettings": {
"ReleaseVersion": "1.0.0"
}
}
3 changes: 3 additions & 0 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9816,6 +9816,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))")]
Expand Down
6 changes: 6 additions & 0 deletions src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Serval.Shared.Configuration;

public class ServalSettings
{
public string ReleaseVersion { get; set; } = "1.0.0"; // Default value
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public record TranslationBuildDto
/// }
/// </example>
public object? Options { get; init; }
public string? ServalReleaseVersion { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class TranslationEnginesController(
IPretranslationService pretranslationService,
IOptionsMonitor<ApiOptions> apiOptions,
IUrlService urlService,
ILogger<TranslationEnginesController> logger
ILogger<TranslationEnginesController> logger,
IOptions<ServalSettings> servalSettingsOptions
) : ServalControllerBase(authService)
{
private static readonly JsonSerializerOptions ObjectJsonSerializerOptions =
Expand All @@ -22,6 +23,7 @@ ILogger<TranslationEnginesController> logger
private readonly IOptionsMonitor<ApiOptions> _apiOptions = apiOptions;
private readonly IUrlService _urlService = urlService;
private readonly ILogger<TranslationEnginesController> _logger = logger;
private readonly ServalSettings _servalSettings = servalSettingsOptions.Value;

/// <summary>
/// Get all translation engines
Expand Down Expand Up @@ -1505,7 +1507,8 @@ private TranslationBuildDto Map(Build source)
QueueDepth = source.QueueDepth,
State = source.State,
DateFinished = source.DateFinished,
Options = source.Options
Options = source.Options,
ServalReleaseVersion = _servalSettings.ReleaseVersion
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Translation/Models/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public record Build : IEntity
public JobState State { get; init; } = JobState.Pending;
public DateTime? DateFinished { get; init; }
public IReadOnlyDictionary<string, object>? Options { get; init; }
public string? ServalReleaseVersion { get; set; }
}
29 changes: 29 additions & 0 deletions src/Serval/test/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pretranslation> 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()
{
Expand Down

0 comments on commit 937c563

Please sign in to comment.