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

Decouple deprecated from robot status #1492

Merged
merged 5 commits into from
Apr 2, 2024
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
4 changes: 0 additions & 4 deletions backend/api.test/Client/MissionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ public async Task ScheduleDuplicateCustomMissionDefinitions()
SerialNumber = "GetNextRun",
RobotType = RobotType.Robot,
Status = RobotStatus.Available,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallationCode = installationCode,
Expand Down Expand Up @@ -506,7 +505,6 @@ public async Task GetNextRun()
SerialNumber = "GetNextRun",
RobotType = RobotType.Robot,
Status = RobotStatus.Available,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallationCode = installation.InstallationCode,
Expand Down Expand Up @@ -689,7 +687,6 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission()
SerialNumber = "GetNextRun",
RobotType = RobotType.Robot,
Status = RobotStatus.Available,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallationCode = otherInstallation.InstallationCode,
Expand Down Expand Up @@ -757,7 +754,6 @@ public async Task MissionFailsIfRobotIsNotInSameDeckAsMission()
SerialNumber = "GetMissionFailsIfRobotIsNotInSameDeckAsMission",
RobotType = RobotType.Robot,
Status = RobotStatus.Available,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallationCode = installation.InstallationCode,
Expand Down
1 change: 0 additions & 1 deletion backend/api.test/Client/RobotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation()
SerialNumber = "GetNextRun",
RobotType = RobotType.Robot,
Status = RobotStatus.Available,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallationCode = wrongInstallation.InstallationCode,
Expand Down
1 change: 0 additions & 1 deletion backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public async Task<Robot> NewRobot(RobotStatus status, Installation installation,
VideoStreams = new List<CreateVideoStreamQuery>(),
Host = "localhost",
Port = 3000,
IsarConnected = true,
Status = status
};

Expand Down
1 change: 0 additions & 1 deletion backend/api.test/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public async Task Create()
RobotType = RobotType.Robot,
Host = "",
Port = 1,
IsarConnected = true,
Status = RobotStatus.Available
};

Expand Down
2 changes: 0 additions & 2 deletions backend/api/Controllers/Models/CreateRobotQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public struct CreateRobotQuery

public int Port { get; set; }

public bool IsarConnected { get; set; }

public RobotStatus Status { get; set; }
}
}
3 changes: 3 additions & 0 deletions backend/api/Controllers/Models/RobotResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class RobotResponse

public bool IsarConnected { get; set; }

public bool Deprecated { get; set; }

public bool MissionQueueFrozen { get; set; }

public RobotStatus Status { get; set; }
Expand Down Expand Up @@ -60,6 +62,7 @@ public RobotResponse(Robot robot)
Host = robot.Host;
Port = robot.Port;
IsarConnected = robot.IsarConnected;
Deprecated = robot.Deprecated;
MissionQueueFrozen = robot.MissionQueueFrozen;
Status = robot.Status;
Pose = robot.Pose;
Expand Down
56 changes: 56 additions & 0 deletions backend/api/Controllers/RobotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,54 @@ [FromBody] UpdateRobotQuery query
}
}

/// <summary>
/// Updates deprecated field of a robot in the database
/// </summary>
/// <remarks>
/// </remarks>
/// <response code="200"> The robot was successfully updated </response>
/// <response code="404"> There was no robot with the given ID in the database </response>
[HttpPut]
[Authorize(Roles = Role.Admin)]
[Route("{id}/deprecated/{deprecated}")]
[ProducesResponseType(typeof(RobotResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<RobotResponse>> UpdateRobotDeprecated(
[FromRoute] string id,
[FromRoute] bool deprecated
)
{
logger.LogInformation("Updating deprecated on robot with id={Id} to deprecated={Deprecated}", id, deprecated);

try
{
var robot = await robotService.ReadById(id);
if (robot == null)
{
string errorMessage = $"No robot with id: {id} could be found";
logger.LogError("{Message}", errorMessage);
return NotFound(errorMessage);
}

Robot updatedRobot;
updatedRobot = await robotService.UpdateDeprecated(id, deprecated);

var robotResponse = new RobotResponse(updatedRobot);
logger.LogInformation("Successful updated deprecated on robot to database");

return Ok(robotResponse);
}
catch (Exception e)
{
logger.LogError(e, "Error while updating robot with id={Id}", id);
throw;
}
}

/// <summary>
/// Deletes the robot with the specified id from the database
/// </summary>
Expand Down Expand Up @@ -590,6 +638,14 @@ [FromRoute] string armPosition
logger.LogWarning("{Message}", errorMessage);
return Conflict(errorMessage);
}

if (robot.Deprecated)
{
string errorMessage = $"Robot {robotId} is deprecated ({robot.Status}) and cannot run missions";
logger.LogWarning("{Message}", errorMessage);
return Conflict(errorMessage);
}

try { await isarService.StartMoveArm(robot, armPosition); }
catch (HttpRequestException e)
{
Expand Down
3 changes: 0 additions & 3 deletions backend/api/Database/Context/InitDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ private static List<Robot> GetRobots()
Name = "R2-D2",
SerialNumber = "D2",
Status = RobotStatus.Available,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallation = installations[0],
Expand All @@ -298,7 +297,6 @@ private static List<Robot> GetRobots()
IsarId = "c68b679d-308b-460f-9fe0-87eaadbd1234",
SerialNumber = "SS79",
Status = RobotStatus.Busy,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallation = installations[0],
Expand All @@ -312,7 +310,6 @@ private static List<Robot> GetRobots()
IsarId = "c68b679d-308b-460f-9fe0-87eaadbd5678",
SerialNumber = "Earth616",
Status = RobotStatus.Available,
IsarConnected = true,
Host = "localhost",
Port = 3000,
CurrentInstallation = installations[0],
Expand Down
10 changes: 7 additions & 3 deletions backend/api/Database/Models/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public Robot()
Name = "defaultId";
SerialNumber = "defaultSerialNumber";
Status = RobotStatus.Offline;
IsarConnected = false;
IsarConnected = true;
Deprecated = false;
Host = "localhost";
Port = 3000;
Pose = new Pose();
Expand Down Expand Up @@ -41,7 +42,8 @@ public Robot(CreateRobotQuery createQuery, Installation installation, Area? area
VideoStreams = videoStreams;
Host = createQuery.Host;
Port = createQuery.Port;
IsarConnected = createQuery.IsarConnected;
IsarConnected = true;
Deprecated = false;
Status = createQuery.Status;
Pose = new Pose();
}
Expand Down Expand Up @@ -95,6 +97,9 @@ public bool IsRobotBatteryLevelHighEnoughToStartMissions()
[Required]
public bool IsarConnected { get; set; }

[Required]
public bool Deprecated { get; set; }
Eddasol marked this conversation as resolved.
Show resolved Hide resolved

[Required]
public bool MissionQueueFrozen { get; set; }

Expand Down Expand Up @@ -128,6 +133,5 @@ public enum RobotStatus
Busy,
Offline,
Blocked,
Deprecated
}
}
1 change: 0 additions & 1 deletion backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private async void OnIsarRobotInfo(object? sender, MqttReceivedArgs mqttArgs)
Host = isarRobotInfo.Host,
Port = isarRobotInfo.Port,
Status = RobotStatus.Available,
IsarConnected = true
};

var newRobot = await robotService.CreateFromQuery(robotQuery);
Expand Down
Loading
Loading