-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add stop all robots button #1012
Closed
Closed
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1130a2a
Add stop all button functionality
aeshub 6ed28e9
Add stop all robots backend endpoints
mrica-equinor 87d1c71
Add stop all button on frontend
mrica-equinor af07f4c
Move entityframework interactions to scoped service
mrica-equinor 52c0c7c
Fix dismiss robots from safe zone functionality
mrica-equinor a7ecd05
Add ongoing mission to queue in emergency state
mrica-equinor e9a0b68
Fix formatting
andchiind cec2952
Update unit tests with new mocks and URLs
andchiind 3543709
Remove excess comments and code
andchiind c39e628
Fix stop all robots button on the frontend
aeshub 4a1e29f
Improve dismiss robots from safe zone
mrica-equinor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
using System.Globalization; | ||
using Api.Controllers.Models; | ||
using Api.Database.Models; | ||
using Api.Services; | ||
using Api.Services.Events; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
namespace Api.Controllers | ||
{ | ||
[ApiController] | ||
[Route("emergency-action")] | ||
public class EmergencyActionController : ControllerBase | ||
{ | ||
private readonly IAreaService _areaService; | ||
private readonly IEmergencyActionService _emergencyActionService; | ||
private readonly ILogger<EmergencyActionController> _logger; | ||
private readonly IRobotService _robotService; | ||
|
||
public EmergencyActionController(ILogger<EmergencyActionController> logger, IRobotService robotService, IAreaService areaService, IEmergencyActionService emergencyActionService) | ||
{ | ||
_logger = logger; | ||
_robotService = robotService; | ||
_areaService = areaService; | ||
_emergencyActionService = emergencyActionService; | ||
} | ||
|
||
/// <summary> | ||
/// This endpoint will abort the current running mission run and attempt to return the robot to a safe position in the | ||
/// area. The mission run queue for the robot will be frozen and no further missions will run until the emergency | ||
/// action has been reversed. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> The endpoint fires an event which is then processed to stop the robot and schedule the next mission </para> | ||
/// </remarks> | ||
[HttpPost] | ||
[Route("{robotId}/{installationCode}/{areaName}/abort-current-mission-and-go-to-safe-zone")] | ||
[Authorize(Roles = Role.User)] | ||
[ProducesResponseType(typeof(MissionRun), StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||
[ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
[ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||
public async Task<ActionResult> AbortCurrentMissionAndGoToSafeZone( | ||
[FromRoute] string robotId, | ||
[FromRoute] string installationCode, | ||
[FromRoute] string areaName) | ||
{ | ||
var robot = await _robotService.ReadById(robotId); | ||
if (robot == null) | ||
{ | ||
_logger.LogWarning("Could not find robot with id {Id}", robotId); | ||
return NotFound("Robot not found"); | ||
} | ||
|
||
var area = await _areaService.ReadByInstallationAndName(installationCode, areaName); | ||
if (area == null) | ||
{ | ||
_logger.LogError("Could not find area {AreaName} for installation code {InstallationCode}", areaName, installationCode); | ||
return NotFound("Area not found"); | ||
} | ||
|
||
_emergencyActionService.TriggerEmergencyButtonPressedForRobot(new EmergencyButtonPressedForRobotEventArgs(robot.Id, area.Id)); | ||
|
||
return Ok("Request to abort current mission and move robot back to safe position received"); | ||
} | ||
|
||
/// <summary> | ||
/// This endpoint will abort the current running mission run and attempt to return the robot to a safe position in the | ||
/// area. The mission run queue for the robot will be frozen and no further missions will run until the emergency | ||
/// action has been reversed. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> The endpoint fires an event which is then processed to stop the robot and schedule the next mission </para> | ||
/// </remarks> | ||
[HttpPost] | ||
[Route("{installationCode}/abort-current-missions-and-send-all-robots-to-safe-zone")] | ||
[Authorize(Roles = Role.User)] | ||
[ProducesResponseType(typeof(MissionRun), StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||
[ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
[ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||
public ActionResult AbortCurrentMissionAndSendAllRobotsToSafeZone( | ||
[FromRoute] string installationCode) | ||
{ | ||
|
||
var robots = _robotService.ReadAll().Result.ToList().FindAll(a => | ||
a.CurrentInstallation.ToLower(CultureInfo.CurrentCulture).Equals(installationCode.ToLower(CultureInfo.CurrentCulture), StringComparison.Ordinal) && | ||
a.CurrentArea != null); | ||
|
||
foreach (var robot in robots) | ||
{ | ||
_emergencyActionService.TriggerEmergencyButtonPressedForRobot(new EmergencyButtonPressedForRobotEventArgs(robot.Id, robot.CurrentArea!.Id)); | ||
|
||
} | ||
|
||
return Ok("Request to abort current mission and move all robots back to safe position received"); | ||
} | ||
|
||
/// <summary> | ||
/// This query will clear the emergency state that is introduced by aborting the current mission and returning to a | ||
/// safe zone. Clearing the emergency state means that mission runs that may be in the robots queue will start." | ||
/// </summary> | ||
[HttpPost] | ||
[Route("{robotId}/{installationCode}/{areaName}/clear-robot-emergency-state")] | ||
[Authorize(Roles = Role.User)] | ||
[ProducesResponseType(typeof(MissionRun), StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||
[ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
[ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||
public async Task<ActionResult> ClearEmergencyState( | ||
[FromRoute] string robotId, | ||
[FromRoute] string installationCode, | ||
[FromRoute] string areaName) | ||
{ | ||
var robot = await _robotService.ReadById(robotId); | ||
if (robot == null) | ||
{ | ||
_logger.LogWarning("Could not find robot with id {Id}", robotId); | ||
return NotFound("Robot not found"); | ||
} | ||
|
||
var area = await _areaService.ReadByInstallationAndName(installationCode, areaName); | ||
if (area == null) | ||
{ | ||
_logger.LogError("Could not find area {AreaName} for installation code {InstallationCode}", areaName, installationCode); | ||
return NotFound("Area not found"); | ||
} | ||
|
||
_emergencyActionService.TriggerEmergencyButtonDepressedForRobot(new EmergencyButtonPressedForRobotEventArgs(robot.Id, area.Id)); | ||
|
||
return Ok("Request to clear emergency state for robot was received"); | ||
} | ||
|
||
/// <summary> | ||
/// This query will clear the emergency state that is introduced by aborting the current mission and returning to a | ||
/// safe zone. Clearing the emergency state means that mission runs that may be in the robots queue will start." | ||
/// </summary> | ||
[HttpPost] | ||
[Route("{robotId}/clear-emergency-state")] | ||
[Authorize(Roles = Role.User)] | ||
[ProducesResponseType(typeof(MissionRun), StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||
[ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
[ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||
public async Task<ActionResult> ClearInstallationEmergencyState( | ||
[FromRoute] string robotId) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to clear emergency state for all robots |
||
var robot = await _robotService.ReadById(robotId); | ||
|
||
if (robot == null) | ||
{ | ||
_logger.LogWarning("Could not find robot with id {Id}", robotId); | ||
return NotFound("Robot not found"); | ||
} | ||
if (robot.CurrentInstallation == null) | ||
{ | ||
_logger.LogWarning("Could not find installation for robot with id {Id}", robotId); | ||
return NotFound("Installation not found"); | ||
} | ||
if (robot.CurrentArea == null) | ||
{ | ||
_logger.LogWarning("Could not find area for robot with id {Id}", robotId); | ||
return NotFound("Area not found"); | ||
} | ||
|
||
_emergencyActionService.TriggerEmergencyButtonDepressedForRobot(new EmergencyButtonPressedForRobotEventArgs(robot.Id, robot.CurrentArea!.Id)); | ||
|
||
return Ok("Request to clear emergency state for robot was received"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comments