-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mock_uss] Reorganize mock_uss flight functionality (#294)
Reorganize mock_uss flight functionality
- Loading branch information
1 parent
7fb0ef7
commit 345ff7c
Showing
21 changed files
with
131 additions
and
104 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mock_uss: ASTM F3548-21 | ||
|
||
[ASTM F3548-21](http://astm.org/f3548-21.html) standardizes UTM interoperability between USSs to achieve strategic coordination and communicate constraints. This folder enables [mock_uss](..) to comply with the Strategic Conflict Detection requirements from that standard. |
File renamed without changes.
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,3 @@ | ||
# mock_uss: flight_planner | ||
|
||
This folder contains materials implementing [InterUSS's flight_planning automated testing interface](https://github.com/interuss/automated_testing_interfaces/tree/main/flight_planning) by [mock_uss](..). |
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,3 @@ | ||
# mock_uss: flights | ||
|
||
This folder contains materials related to generic handling of user-requested flights by [mock_uss](..). |
Empty file.
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,47 @@ | ||
import time | ||
from datetime import datetime | ||
from typing import Callable | ||
|
||
from monitoring.mock_uss.flights.database import FlightRecord, db, DEADLOCK_TIMEOUT | ||
|
||
|
||
def lock_flight(flight_id: str, log: Callable[[str], None]) -> FlightRecord: | ||
# If this is a change to an existing flight, acquire lock to that flight | ||
log(f"Acquiring lock for flight {flight_id}") | ||
deadline = datetime.utcnow() + DEADLOCK_TIMEOUT | ||
while True: | ||
with db as tx: | ||
if flight_id in tx.flights: | ||
# This is an existing flight being modified | ||
existing_flight = tx.flights[flight_id] | ||
if existing_flight and not existing_flight.locked: | ||
log("Existing flight locked for update") | ||
existing_flight.locked = True | ||
break | ||
else: | ||
log("Request is for a new flight (lock established)") | ||
tx.flights[flight_id] = None | ||
existing_flight = None | ||
break | ||
# We found an existing flight but it was locked; wait for it to become | ||
# available | ||
time.sleep(0.5) | ||
|
||
if datetime.utcnow() > deadline: | ||
raise RuntimeError( | ||
f"Deadlock in inject_flight while attempting to gain access to flight {flight_id}" | ||
) | ||
return existing_flight | ||
|
||
|
||
def release_flight_lock(flight_id: str, log: Callable[[str], None]) -> None: | ||
with db as tx: | ||
if flight_id in tx.flights: | ||
if tx.flights[flight_id]: | ||
# FlightRecord was a true existing flight | ||
log(f"Releasing lock on existing flight_id {flight_id}") | ||
tx.flights[flight_id].locked = False | ||
else: | ||
# FlightRecord was just a placeholder for a new flight | ||
log(f"Releasing placeholder for existing flight_id {flight_id}") | ||
del tx.flights[flight_id] |
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,3 @@ | ||
# mock_uss: scd_injection | ||
|
||
This folder contains material related to the deprecated [InterUSS scd automated testing interface](https://github.com/interuss/automated_testing_interfaces/tree/main/scd). |
Empty file.
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,6 @@ | ||
from monitoring.mock_uss import webapp | ||
|
||
|
||
@webapp.route("/scdsc/status") | ||
def scdsc_status(): | ||
return "scd flight injection API ok" |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
# mock_uss: uspace | ||
|
||
This folder contains materials allowing mock_uss to emulate behaviors required in U-space. |
Empty file.
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,14 @@ | ||
from monitoring.mock_uss.f3548v21.flight_planning import PlanningError | ||
from monitoring.monitorlib.uspace import problems_with_flight_authorisation | ||
from uas_standards.interuss.automated_testing.scd.v1 import api as scd_api | ||
|
||
|
||
def validate_request(req_body: scd_api.InjectFlightRequest) -> None: | ||
"""Raise a PlannerError if the request is not valid. | ||
Args: | ||
req_body: Information about the requested flight. | ||
""" | ||
problems = problems_with_flight_authorisation(req_body.flight_authorisation) | ||
if problems: | ||
raise PlanningError(", ".join(problems)) |