From ce1fc773a90a1e38f0e0ce5eb5e779693d96535c Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 12 Sep 2022 15:17:21 -0700 Subject: [PATCH] implement not-implemented: GetInputContainerQueues (#2380) * implement not-implemented: GetInputContainerQueues * named tuple Co-authored-by: stas --- .../onefuzzlib/NotificationOperations.cs | 3 ++- .../ApiService/onefuzzlib/TaskOperations.cs | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ApiService/ApiService/onefuzzlib/NotificationOperations.cs b/src/ApiService/ApiService/onefuzzlib/NotificationOperations.cs index 0145d2f95..26d65075b 100644 --- a/src/ApiService/ApiService/onefuzzlib/NotificationOperations.cs +++ b/src/ApiService/ApiService/onefuzzlib/NotificationOperations.cs @@ -85,7 +85,8 @@ public class NotificationOperations : Orm, INotificationOperations // Nullability mismatch: We filter tuples where the containers are null return _context.TaskOperations.SearchStates(states: TaskStateHelper.AvailableStates) .Select(task => (task, _context.TaskOperations.GetInputContainerQueues(task.Config))) - .Where(taskTuple => taskTuple.Item2 != null)!; + .Where(taskTuple => taskTuple.Item2.IsOk && taskTuple.Item2.OkV != null) + .Select(x => (Task: x.Item1, Containers: x.Item2.OkV))!; } public async Async.Task> Create(Container container, NotificationTemplate config, bool replaceExisting) { diff --git a/src/ApiService/ApiService/onefuzzlib/TaskOperations.cs b/src/ApiService/ApiService/onefuzzlib/TaskOperations.cs index 0b084fe9e..e77a8764d 100644 --- a/src/ApiService/ApiService/onefuzzlib/TaskOperations.cs +++ b/src/ApiService/ApiService/onefuzzlib/TaskOperations.cs @@ -15,7 +15,7 @@ public interface ITaskOperations : IStatefulOrm { IAsyncEnumerable SearchStates(Guid? jobId = null, IEnumerable? states = null); - IEnumerable? GetInputContainerQueues(TaskConfig config); + Result?, TaskConfigError> GetInputContainerQueues(TaskConfig config); IAsyncEnumerable SearchExpired(); Async.Task MarkStopping(Task task); @@ -75,8 +75,17 @@ public class TaskOperations : StatefulOrm, ITas return QueryAsync(filter: queryString); } - public IEnumerable? GetInputContainerQueues(TaskConfig config) { - throw new NotImplementedException(); + public Result?, TaskConfigError> GetInputContainerQueues(TaskConfig config) { + + if (!Defs.TASK_DEFINITIONS.ContainsKey(config.Task.Type)) { + return Result?, TaskConfigError>.Error(new TaskConfigError($"unsupported task type: {config.Task.Type}")); + } + + var containerType = Defs.TASK_DEFINITIONS[config.Task.Type].MonitorQueue; + if (containerType is not null && config.Containers is not null) + return Result?, TaskConfigError>.Ok(config.Containers.Where(x => x.Type == containerType).Select(x => x.Name)); + else + return Result?, TaskConfigError>.Ok(null); } public IAsyncEnumerable SearchExpired() {