Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store error strings from isar #894

Closed
wants to merge 4 commits into from
Closed
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
14 changes: 8 additions & 6 deletions backend/api/Controllers/MissionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ IStidService stidService
/// </remarks>
[HttpGet("runs")]
[Authorize(Roles = Role.Any)]
[ProducesResponseType(typeof(IList<MissionRun>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(IList<MissionRunDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<IList<MissionRun>>> GetMissionRuns(
public async Task<ActionResult<IList<MissionRunDto>>> GetMissionRuns(
[FromQuery] MissionRunQueryStringParameters parameters
)
{
Expand Down Expand Up @@ -102,7 +102,9 @@ [FromQuery] MissionRunQueryStringParameters parameters
JsonSerializer.Serialize(metadata)
);

return Ok(missionRuns);
var missionRunDtos = missionRuns.Select(m => new MissionRunDto(m));

return Ok(missionRunDtos);
}

/// <summary>
Expand Down Expand Up @@ -157,17 +159,17 @@ [FromQuery] MissionDefinitionQueryStringParameters parameters
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("runs/{id}")]
[ProducesResponseType(typeof(MissionRun), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(MissionRunDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MissionRun>> GetMissionRunById([FromRoute] string id)
public async Task<ActionResult<MissionRunDto>> GetMissionRunById([FromRoute] string id)
{
var missioRun = await _missionRunService.ReadById(id);
if (missioRun == null)
return NotFound($"Could not find mission run with id {id}");
return Ok(missioRun);
return Ok(new MissionRunDto(missioRun));
}

/// <summary>
Expand Down
45 changes: 45 additions & 0 deletions backend/api/Controllers/Models/InspectionDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Api.Database.Models;

#pragma warning disable CS8618
namespace Api.Controllers.Models
{
public class InspectionDto
{
public InspectionDto(Inspection inspection)
{
Id = inspection.Id;
IsarStepId = inspection.IsarStepId;
Status = inspection.Status;
IsCompleted = inspection.IsCompleted;
InspectionType = inspection.InspectionType;
VideoDuration = inspection.VideoDuration;
AnalysisTypes = inspection.AnalysisTypes;
InspectionUrl = inspection.InspectionUrl;
Error = inspection.GetError();
StartTime = inspection.StartTime;
EndTime = inspection.EndTime;
}

public string Id { get; set; }

public string? IsarStepId { get; set; }

public InspectionStatus Status { get; set; }

public bool IsCompleted { get; set; }

public InspectionType InspectionType { get; set; }

public float? VideoDuration { get; set; }

public string? AnalysisTypes { get; set; }

public string? InspectionUrl { get; set; }

public string? Error { get; set; }

public DateTimeOffset? StartTime { get; private set; }

public DateTimeOffset? EndTime { get; private set; }
}
}
65 changes: 65 additions & 0 deletions backend/api/Controllers/Models/MissionRunDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Api.Database.Models;

#pragma warning disable CS8618
namespace Api.Controllers.Models
{
public class MissionRunDto
{
public MissionRunDto(MissionRun mission)
{
Id = mission.Id;
IsarMissionId = mission.IsarMissionId;
Name = mission.Name;
Description = mission.Description;
StatusReason = mission.StatusReason;
Comment = mission.Comment;
InstallationCode = mission.InstallationCode;
Robot = mission.Robot;
Status = mission.Status;
IsCompleted = mission.IsCompleted;
MapMetadata = mission.MapMetadata;
Error = mission.GetError(); // TODO: rethink whether nested errors are needed here
DesiredStartTime = mission.DesiredStartTime;
StartTime = mission.StartTime;
EndTime = mission.EndTime;
EstimatedDuration = mission.EstimatedDuration;
Tasks = mission.Tasks.Select(t => new MissionTaskDto(t)).ToList();
}

public string Id { get; set; }

public int? EchoMissionId { get; set; }

public string? IsarMissionId { get; set; }

public string Name { get; set; }

public string? Description { get; set; }

public string? StatusReason { get; set; }

public string? Comment { get; set; }

public string InstallationCode { get; set; }

public Robot Robot { get; set; }

public MissionStatus Status { get; set; }

public bool IsCompleted { get; set; }

public MapMetadata? MapMetadata { get; set; }

public string? Error { get; set; }

public DateTimeOffset DesiredStartTime { get; set; }

public DateTimeOffset? StartTime { get; private set; }

public DateTimeOffset? EndTime { get; private set; }

public uint? EstimatedDuration { get; set; }

public IList<MissionTaskDto> Tasks { get; set; }
}
}
57 changes: 57 additions & 0 deletions backend/api/Controllers/Models/MissionTaskDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Api.Database.Models;

#pragma warning disable CS8618
namespace Api.Controllers.Models
{
public class MissionTaskDto
{
public MissionTaskDto(MissionTask task)
{
Id = task.Id;
IsarTaskId = task.IsarTaskId;
TaskOrder = task.TaskOrder;
TagId = task.TagId;
Description = task.Description;
EchoTagLink = task.EchoTagLink;
InspectionTarget = task.InspectionTarget;
RobotPose = task.RobotPose;
EchoPoseId = task.EchoPoseId;
Status = task.Status;
IsCompleted = task.IsCompleted;
Error = task.GetError(); // TODO: rethink whether nested errors are needed here
StartTime = task.StartTime;
EndTime = task.EndTime;
Inspections = task.Inspections.Select(i => new InspectionDto(i)).ToList();
}

public string Id { get; set; }

public string? IsarTaskId { get; set; }

public int TaskOrder { get; set; }

public string? TagId { get; set; }

public string? Description { get; set; }

public Uri? EchoTagLink { get; set; }

public Position InspectionTarget { get; set; }

public Pose RobotPose { get; set; }

public int? EchoPoseId { get; set; }

public Database.Models.TaskStatus Status { get; set; }

public bool IsCompleted { get; set; }

public string? Error { get; set; }

public DateTimeOffset? StartTime { get; private set; }

public DateTimeOffset? EndTime { get; private set; }

public IList<InspectionDto> Inspections { get; set; }
}
}
7 changes: 7 additions & 0 deletions backend/api/Controllers/RobotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ [FromRoute] string missionRunId
return NotFound("Mission not found");
}

string? missionRunError = missionRun.GetError();
if (missionRunError != null)
{
_logger.LogError(new MissionException(missionRunError), $"Error in ISAR mission: {missionRunError}");
return StatusCode(StatusCodes.Status502BadGateway, $"Error in ISAR mission: {missionRunError}");
}

IsarMission isarMission;
try
{
Expand Down
14 changes: 14 additions & 0 deletions backend/api/Database/Models/Inspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations.Schema;
using Api.Controllers.Models;
using Api.Services.Models;
using Api.Utilities;
using Microsoft.EntityFrameworkCore;

#pragma warning disable CS8618
Expand Down Expand Up @@ -52,6 +53,19 @@ or InspectionStatus.Successful
[MaxLength(250)]
public string? InspectionUrl { get; set; }

public string? ErrorReason { get; set; }

public string? ErrorDescription { get; set; }

public string? GetError()
{
if (ErrorReason != null)
{
return IsarErrorHandling.MapIsarError(ErrorReason);
}
return null;
}

public DateTimeOffset? StartTime { get; private set; }

public DateTimeOffset? EndTime { get; private set; }
Expand Down
31 changes: 31 additions & 0 deletions backend/api/Database/Models/MissionRun.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Api.Services.Models;
using Api.Utilities;

#pragma warning disable CS8618
namespace Api.Database.Models
Expand Down Expand Up @@ -77,6 +78,36 @@ or MissionStatus.PartiallySuccessful

public MapMetadata? MapMetadata { get; set; }

public string? ErrorReason { get; set; }

public string? ErrorDescription { get; set; }

public bool HasNestedError()
{
if (ErrorReason != null)
{
return true;
}
else
{
foreach (var task in Tasks)
{
if (task.HasNestedError())
return true;
}
}
return false;
}

public string? GetError()
{
if (ErrorReason != null)
{
return IsarErrorHandling.MapIsarError(ErrorReason);
}
return null;
}

public DateTimeOffset? StartTime { get; private set; }

public DateTimeOffset? EndTime { get; private set; }
Expand Down
31 changes: 31 additions & 0 deletions backend/api/Database/Models/MissionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations.Schema;
using Api.Controllers.Models;
using Api.Services.Models;
using Api.Utilities;
using Microsoft.EntityFrameworkCore;

#pragma warning disable CS8618
Expand Down Expand Up @@ -62,6 +63,36 @@ or TaskStatus.Successful
or TaskStatus.Failed
or TaskStatus.PartiallySuccessful;

public string? ErrorReason { get; set; }

public string? ErrorDescription { get; set; }

public bool HasNestedError()
{
if (ErrorReason != null)
{
return true;
}
else
{
foreach (var inspection in Inspections)
{
if (inspection.GetError() != null)
return true;
}
}
return false;
}

public string? GetError()
{
if (ErrorReason != null)
{
return IsarErrorHandling.MapIsarError(ErrorReason);
}
return null;
}

public DateTimeOffset? StartTime { get; private set; }

public DateTimeOffset? EndTime { get; private set; }
Expand Down
12 changes: 9 additions & 3 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ private async void OnMissionUpdate(object? sender, MqttReceivedArgs mqttArgs)

var flotillaMissionRun = await missionRunService.UpdateMissionRunStatusByIsarMissionId(
isarMission.MissionId,
status
status,
isarMission.ErrorReason,
isarMission.ErrorDescription
);

if (flotillaMissionRun is null)
Expand Down Expand Up @@ -369,7 +371,9 @@ private async void OnTaskUpdate(object? sender, MqttReceivedArgs mqttArgs)
bool success = await missionRunService.UpdateTaskStatusByIsarTaskId(
task.MissionId,
task.TaskId,
status
status,
task.ErrorReason,
task.ErrorDescription
);

if (success)
Expand Down Expand Up @@ -417,7 +421,9 @@ private async void OnStepUpdate(object? sender, MqttReceivedArgs mqttArgs)
step.MissionId,
step.TaskId,
step.StepId,
status
status,
step.ErrorReason,
step.ErrorDescription
);

if (success)
Expand Down
6 changes: 6 additions & 0 deletions backend/api/MQTT/MessageModels/IsarMission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ public class IsarMissionMessage : MqttMessage

[JsonPropertyName("timestamp")]
public DateTime Timestamp { get; set; }

[JsonPropertyName("error_reason")]
public string ErrorReason { get; set; }

[JsonPropertyName("error_description")]
public string ErrorDescription { get; set; }
}
}
Loading