diff --git a/src/Serval.Client/Client.g.cs b/src/Serval.Client/Client.g.cs index d1987abc..643947a4 100644 --- a/src/Serval.Client/Client.g.cs +++ b/src/Serval.Client/Client.g.cs @@ -847,7 +847,7 @@ public partial interface ITranslationEnginesClient /// A valid engine type: SmtTransfer, Nmt, or Echo /// The queue depth for the specified engine type /// A server side error occurred. - System.Threading.Tasks.Task GetQueueDepthAsync(string engineType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetQueueAsync(string engineType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -1521,14 +1521,13 @@ public string BaseUrl /// A valid engine type: SmtTransfer, Nmt, or Echo /// The queue depth for the specified engine type /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetQueueDepthAsync(string engineType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetQueueAsync(string engineType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { if (engineType == null) throw new System.ArgumentNullException("engineType"); var urlBuilder_ = new System.Text.StringBuilder(); - urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/translation/engines/queues/{engineType}"); - urlBuilder_.Replace("{engineType}", System.Uri.EscapeDataString(ConvertToString(engineType, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/translation/engines/queues"); var client_ = _httpClient; var disposeClient_ = false; @@ -1536,6 +1535,10 @@ public string BaseUrl { using (var request_ = new System.Net.Http.HttpRequestMessage()) { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(engineType, _settings.Value); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -4116,8 +4119,11 @@ public partial class TranslationEngineConfig [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")] public partial class Queue { - [Newtonsoft.Json.JsonProperty("depth", Required = Newtonsoft.Json.Required.Always)] - public int Depth { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("size", Required = Newtonsoft.Json.Required.Always)] + public int Size { get; set; } = default!; + + [Newtonsoft.Json.JsonProperty("engineType", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? EngineType { get; set; } = default!; } diff --git a/src/Serval.Translation/Contracts/QueueDto.cs b/src/Serval.Translation/Contracts/QueueDto.cs index 76baa8fd..00fcffec 100644 --- a/src/Serval.Translation/Contracts/QueueDto.cs +++ b/src/Serval.Translation/Contracts/QueueDto.cs @@ -2,5 +2,6 @@ namespace Serval.Translation.Contracts; public class QueueDto { - public int Depth { get; set; } = default; + public int Size { get; set; } = default; + public string? EngineType {get; set;} } diff --git a/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval.Translation/Controllers/TranslationEnginesController.cs index f5ad4dd0..fcab346d 100644 --- a/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -192,19 +192,19 @@ public async Task DeleteAsync([NotNull] string id, CancellationTok /// The authenticated client cannot perform the operation /// A necessary service is currently unavailable. Check `/health` for more details. [Authorize(Scopes.ReadTranslationEngines)] - [HttpGet("queues/{engineType}")] + [HttpGet("queues")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] [ProducesResponseType(typeof(void), StatusCodes.Status503ServiceUnavailable)] - public async Task> GetQueueDepth( - [NotNull] string engineType, + public async Task> GetQueueAsync( + [FromBody] string engineType, CancellationToken cancellationToken ) { try { - return Map(await _engineService.GetQueueDepthAsync(engineType, cancellationToken)); + return Map(await _engineService.GetQueueAsync(engineType, cancellationToken)); } catch (InvalidOperationException ioe) { @@ -1030,7 +1030,7 @@ private static Build Map(Engine engine, TranslationBuildConfigDto source) return build; } - private QueueDto Map(Queue source) => new() { Depth = source.Depth }; + private QueueDto Map(Queue source) => new() { Size = source.Size, EngineType = source.EngineType }; private TranslationEngineDto Map(Engine source) { diff --git a/src/Serval.Translation/Models/Queue.cs b/src/Serval.Translation/Models/Queue.cs index 87863bb9..a4fd3782 100644 --- a/src/Serval.Translation/Models/Queue.cs +++ b/src/Serval.Translation/Models/Queue.cs @@ -2,5 +2,6 @@ namespace Serval.Translation.Models; public class Queue { - public int Depth { get; set; } = default; + public int Size { get; set; } = default; + public string? EngineType {get; set;} } diff --git a/src/Serval.Translation/Services/EngineService.cs b/src/Serval.Translation/Services/EngineService.cs index b68695af..e8c36af5 100644 --- a/src/Serval.Translation/Services/EngineService.cs +++ b/src/Serval.Translation/Services/EngineService.cs @@ -298,14 +298,14 @@ public Task DeleteAllCorpusFilesAsync(string dataFileId, CancellationToken cance ); } - public async Task GetQueueDepthAsync(string engineType, CancellationToken cancellationToken = default) + public async Task GetQueueAsync(string engineType, CancellationToken cancellationToken = default) { var client = _grpcClientFactory.CreateClient(engineType); GetQueueDepthResponse response = await client.GetQueueDepthAsync( new GetQueueDepthRequest { EngineType = engineType }, cancellationToken: cancellationToken ); - return new Queue { Depth = response.Depth }; + return new Queue { Size = response.Depth, EngineType = engineType }; } private Models.TranslationResult Map(V1.TranslationResult source) diff --git a/src/Serval.Translation/Services/IEngineService.cs b/src/Serval.Translation/Services/IEngineService.cs index 2b1e40ca..a3397eef 100644 --- a/src/Serval.Translation/Services/IEngineService.cs +++ b/src/Serval.Translation/Services/IEngineService.cs @@ -47,5 +47,5 @@ Task TrainSegmentPairAsync( Task DeleteAllCorpusFilesAsync(string dataFileId, CancellationToken cancellationToken = default); - Task GetQueueDepthAsync(string engineType, CancellationToken cancellationToken = default); + Task GetQueueAsync(string engineType, CancellationToken cancellationToken = default); } diff --git a/tests/Serval.E2ETests/ServalApiTests.cs b/tests/Serval.E2ETests/ServalApiTests.cs index 15857f6b..dea584fa 100644 --- a/tests/Serval.E2ETests/ServalApiTests.cs +++ b/tests/Serval.E2ETests/ServalApiTests.cs @@ -165,23 +165,19 @@ public async Task NmtQueueMultiple() builds += $"{JsonSerializer.Serialize(build)}\n"; } - builds += - "Depth = " + (await _helperClient.translationEnginesClient.GetQueueDepthAsync("Nmt")).Depth.ToString(); + builds += "Depth = " + (await _helperClient.translationEnginesClient.GetQueueAsync("Nmt")).Size.ToString(); //Status message of last started build says that there is at least one job ahead of it in the queue // (this variable due to how many jobs may already exist in the production queue from other Serval instances) TranslationBuild newestEngineCurrentBuild = await _helperClient.translationEnginesClient.GetCurrentBuildAsync( engineIds[NUM_ENGINES - 1] ); + Assert.NotNull(newestEngineCurrentBuild.QueueDepth, JsonSerializer.Serialize(newestEngineCurrentBuild)); Assert.Multiple(async () => { + Assert.That(newestEngineCurrentBuild.QueueDepth, Is.GreaterThan(0), message: builds); Assert.That( - newestEngineCurrentBuild.QueueDepth, - Is.GreaterThan(0), - message: builds - ); - Assert.That( - (await _helperClient.translationEnginesClient.GetQueueDepthAsync("Nmt")).Depth, + (await _helperClient.translationEnginesClient.GetQueueAsync("Nmt")).Size, Is.GreaterThanOrEqualTo(NUM_ENGINES - NUM_WORKERS) ); });