Skip to content

Commit

Permalink
rename server_id -> participant_id
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmis committed Oct 20, 2023
1 parent e12193c commit ebc73de
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 99 deletions.
16 changes: 8 additions & 8 deletions monitoring/monitorlib/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Query(ImplicitDict):
request: RequestDescription
response: ResponseDescription

server_id: Optional[str]
participant_id: Optional[str]
"""If specified, identifier of the USS/participant hosting the server involved in this query."""

query_type: Optional[QueryType]
Expand Down Expand Up @@ -273,16 +273,16 @@ def describe_query(
resp: requests.Response,
initiated_at: datetime.datetime,
query_type: Optional[QueryType] = None,
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> Query:
query = Query(
request=describe_request(resp.request, initiated_at),
response=describe_response(resp),
)
if query_type is not None:
query.query_type = query_type
if server_id is not None:
query.server_id = server_id
if participant_id is not None:
query.participant_id = participant_id
return query


Expand All @@ -291,7 +291,7 @@ def query_and_describe(
verb: str,
url: str,
query_type: Optional[QueryType] = None,
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
**kwargs,
) -> Query:
"""Attempt to perform a query, and then describe the results of that attempt.
Expand All @@ -304,7 +304,7 @@ def query_and_describe(
verb: HTTP verb to perform at the specified URL.
url: URL to query.
query_type: If specified, the known type of query that this is.
server_id: If specified, the participant identifier of the server being queried.
participant_id: If specified, the participant identifier of the server being queried.
**kwargs: Any keyword arguments that should be applied to the <session>.request method when invoking it.
Returns:
Expand Down Expand Up @@ -340,7 +340,7 @@ def query_and_describe(
client.request(verb, url, **req_kwargs),
t0,
query_type=query_type,
server_id=server_id,
participant_id=participant_id,
)
except (requests.Timeout, urllib3.exceptions.ReadTimeoutError) as e:
failure_message = f"query_and_describe attempt {attempt + 1} from PID {os.getpid()} to {verb} {url} failed with timeout {type(e).__name__}: {str(e)}"
Expand Down Expand Up @@ -370,7 +370,7 @@ def query_and_describe(
elapsed_s=(t1 - t0).total_seconds(),
reported=StringBasedDateTime(t1),
),
server_id=server_id,
participant_id=participant_id,
)
if query_type is not None:
result.query_type = query_type
Expand Down
68 changes: 40 additions & 28 deletions monitoring/monitorlib/fetch/rid.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ def query_flights(
session: UTMClientSession,
area: s2sphere.LatLngRect,
include_recent_positions: bool = True,
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> FetchedUSSFlights:
return uss_flights(
self.flights_url,
area,
include_recent_positions,
self.rid_version,
session,
server_id=server_id,
participant_id=participant_id,
)


Expand Down Expand Up @@ -640,13 +640,25 @@ def success(self) -> bool:
def errors(self) -> List[str]:
raise NotImplementedError("RIDQuery.errors must be overriden")

def set_server_id(self, server_id: str):
@property
def participant_id(self) -> Optional[str]:
if self.rid_version == RIDVersion.f3411_19:
return self.v19_query.participant_id
elif self.rid_version == RIDVersion.f3411_22a:
return self.v22a_query.participant_id
else:
raise NotImplementedError(
f"Cannot retrieve participant_id using RID version {self.rid_version}"
)

@participant_id.setter
def participant_id(self, participant_id: str) -> None:
if self.v19_query is not None:
self.v19_query.server_id = server_id
self.v19_query.participant_id = participant_id
elif self.v22a_query is not None:
self.v22a_query.server_id = server_id
self.v22a_query.participant_id = participant_id
else:
raise NotImplementedError(f"Cannot set server_id")
raise NotImplementedError(f"Cannot set participant_id")


class FetchedISA(RIDQuery):
Expand Down Expand Up @@ -722,7 +734,7 @@ def isa(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> FetchedISA:
if rid_version == RIDVersion.f3411_19:
op = v19.api.OPERATIONS[v19.api.OperationID.GetIdentificationServiceArea]
Expand All @@ -733,7 +745,7 @@ def isa(
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
participant_id=participant_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -745,7 +757,7 @@ def isa(
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
participant_id=participant_id,
)
)
else:
Expand Down Expand Up @@ -857,7 +869,7 @@ def isas(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> FetchedISAs:
url_time_params = ""
if start_time is not None:
Expand All @@ -875,7 +887,7 @@ def isas(
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
participant_id=participant_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -888,7 +900,7 @@ def isas(
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
participant_id=participant_id,
)
)
else:
Expand Down Expand Up @@ -965,7 +977,7 @@ def uss_flights(
include_recent_positions: bool,
rid_version: RIDVersion,
session: UTMClientSession,
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> FetchedUSSFlights:
if rid_version == RIDVersion.f3411_19:
query = fetch.query_and_describe(
Expand All @@ -984,7 +996,7 @@ def uss_flights(
else "false",
},
scope=v19.constants.Scope.Read,
server_id=server_id,
participant_id=participant_id,
)
query.query_type = QueryType.F3411v19Flights
return FetchedUSSFlights(v19_query=query)
Expand All @@ -1005,7 +1017,7 @@ def uss_flights(
flights_url,
params=params,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
participant_id=participant_id,
)
query.query_type = QueryType.F3411v22aFlights
return FetchedUSSFlights(v22a_query=query)
Expand Down Expand Up @@ -1092,11 +1104,11 @@ def flight_details(
enhanced_details: bool,
rid_version: RIDVersion,
session: UTMClientSession,
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> FetchedUSSFlightDetails:
url = f"{flights_url}/{flight_id}/details"
if rid_version == RIDVersion.f3411_19:
kwargs = {"server_id": server_id}
kwargs = {"participant_id": participant_id}
if enhanced_details:
kwargs["params"] = {"enhanced": "true"}
kwargs["scope"] = (
Expand All @@ -1112,7 +1124,7 @@ def flight_details(
"GET",
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
participant_id=participant_id,
)
return FetchedUSSFlightDetails(v22a_query=query)
else:
Expand Down Expand Up @@ -1164,7 +1176,7 @@ def all_flights(
session: UTMClientSession,
dss_base_url: str = "",
enhanced_details: bool = False,
dss_server_id: Optional[str] = None,
dss_participant_id: Optional[str] = None,
) -> FetchedFlights:
t = datetime.datetime.utcnow()
isa_list = isas(
Expand All @@ -1174,7 +1186,7 @@ def all_flights(
rid_version,
session,
dss_base_url,
server_id=dss_server_id,
participant_id=dss_participant_id,
)

uss_flight_queries: Dict[str, FetchedUSSFlights] = {}
Expand All @@ -1188,7 +1200,7 @@ def all_flights(
session,
# Note that we have no clue at this point which participant the flights_url is for,
# this can only be determined later by comparing injected and observed flights.
server_id=None,
participant_id=None,
)
uss_flight_queries[flights_url] = flights_for_url

Expand All @@ -1200,7 +1212,7 @@ def all_flights(
enhanced_details,
rid_version,
session,
server_id=None,
participant_id=None,
)
uss_flight_details_queries[flight.id] = details

Expand Down Expand Up @@ -1278,7 +1290,7 @@ def subscription(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> FetchedSubscription:
if rid_version == RIDVersion.f3411_19:
op = v19.api.OPERATIONS[v19.api.OperationID.GetSubscription]
Expand All @@ -1289,7 +1301,7 @@ def subscription(
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
participant_id=participant_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -1301,7 +1313,7 @@ def subscription(
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
participant_id=participant_id,
)
)
else:
Expand Down Expand Up @@ -1385,7 +1397,7 @@ def subscriptions(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> FetchedSubscriptions:
if rid_version == RIDVersion.f3411_19:
op = v19.api.OPERATIONS[v19.api.OperationID.SearchSubscriptions]
Expand All @@ -1396,7 +1408,7 @@ def subscriptions(
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
participant_id=participant_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -1408,7 +1420,7 @@ def subscriptions(
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
participant_id=participant_id,
)
)
else:
Expand Down
Loading

0 comments on commit ebc73de

Please sign in to comment.