Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Remove some response-only properties from the Task model #2335

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions src/ApiService/ApiService/Functions/Tasks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;

Expand Down Expand Up @@ -31,20 +32,36 @@ private async Async.Task<HttpResponseData> Get(HttpRequestData req) {
return await _context.RequestHandling.NotOk(req, request.ErrorV, "task get");
}

if (request.OkV.TaskId != null) {
var task = await _context.TaskOperations.GetByTaskId(request.OkV.TaskId.Value);
if (request.OkV.TaskId is Guid taskId) {
var task = await _context.TaskOperations.GetByTaskId(taskId);
if (task == null) {
return await _context.RequestHandling.NotOk(req, new Error(ErrorCode.INVALID_REQUEST, new[] { "unable to find task"
}), "task get");

return await _context.RequestHandling.NotOk(
req,
new Error(
ErrorCode.INVALID_REQUEST,
new[] { "unable to find task" }),
"task get");
}
task.Nodes = await _context.NodeTasksOperations.GetNodeAssignments(request.OkV.TaskId.Value).ToListAsync();
task.Events = await _context.TaskEventOperations.GetSummary(request.OkV.TaskId.Value).ToListAsync();

var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(task);
return response;

var (nodes, events) = await (
_context.NodeTasksOperations.GetNodeAssignments(taskId).ToListAsync().AsTask(),
_context.TaskEventOperations.GetSummary(taskId).ToListAsync().AsTask());

var result = new TaskSearchResult(
JobId: task.JobId,
TaskId: task.TaskId,
State: task.State,
Os: task.Os,
Config: task.Config,
Error: task.Error,
Auth: task.Auth,
Heartbeat: task.Heartbeat,
EndTime: task.EndTime,
UserInfo: task.UserInfo,
Nodes: nodes,
Events: events);

return await RequestHandling.Ok(req, result);
}

var tasks = await _context.TaskOperations.SearchAll().ToListAsync();
Expand Down
2 changes: 0 additions & 2 deletions src/ApiService/ApiService/OneFuzzTypes/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ public record Task(
DateTimeOffset? Heartbeat = null,
DateTimeOffset? EndTime = null,
UserInfo? UserInfo = null) : StatefulEntityBase<TaskState>(State) {
public List<TaskEventSummary> Events { get; set; } = new List<TaskEventSummary>();
public List<NodeAssignment> Nodes { get; set; } = new List<NodeAssignment>();
}

public record TaskEvent(
Expand Down
15 changes: 15 additions & 0 deletions src/ApiService/ApiService/OneFuzzTypes/Responses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public record NodeSearchResult(
bool DebugKeepNode
) : BaseResponse();

public record TaskSearchResult(
Guid JobId,
Guid TaskId,
TaskState State,
Os Os,
TaskConfig Config,
Error? Error,
Authentication? Auth,
DateTimeOffset? Heartbeat,
DateTimeOffset? EndTime,
UserInfo? UserInfo,
List<TaskEventSummary> Events,
List<NodeAssignment> Nodes
) : BaseResponse();

public record BoolResult(
bool Result
) : BaseResponse();
Expand Down