Skip to content

Commit 0f018f7

Browse files
asher-pem-armLuke Beardsmore
andcommitted
remote/coordinator: add GetPlace RPC
Add a unary GetPlace RPC for fetching a single place by name instead of requiring callers to fetch and scan the full GetPlaces response. Return INVALID_ARGUMENT when no name is provided or when the requested place does not exist. Signed-off-by: Asher Pemberton <asher.pemberton@arm.com> Reviewed-by: Asher Pemberton <asher.pemberton@arm.com> # gatekeeper Co-authored-by: Luke Beardsmore <luke.beardsmore2@arm.com>
1 parent 4d2b773 commit 0f018f7

6 files changed

Lines changed: 498 additions & 166 deletions

File tree

labgrid/remote/coordinator.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,21 @@ async def AllowPlace(self, request, context):
981981
def _get_places(self):
982982
return {k: v.asdict() for k, v in self.places.items()}
983983

984+
@locked
985+
async def GetPlace(self, request, context):
986+
name = request.name
987+
logging.debug("GetPlace name=%s", name)
988+
if not name or not isinstance(name, str):
989+
await context.abort(grpc.StatusCode.INVALID_ARGUMENT, "name was not a string")
990+
try:
991+
place = self.places[name]
992+
return labgrid_coordinator_pb2.GetPlaceResponse(place=place.as_pb2())
993+
except KeyError:
994+
await context.abort(grpc.StatusCode.INVALID_ARGUMENT, f"Place {name} does not exist")
995+
except Exception:
996+
logging.exception("error during get place")
997+
await context.abort(grpc.StatusCode.INTERNAL, "internal error")
998+
984999
@locked
9851000
async def GetPlaces(self, unused_request, unused_context):
9861001
logging.debug("GetPlaces")

labgrid/remote/generated/labgrid_coordinator_pb2.py

Lines changed: 107 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

labgrid/remote/generated/labgrid_coordinator_pb2.pyi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from google.protobuf.internal import containers as _containers
22
from google.protobuf import descriptor as _descriptor
33
from google.protobuf import message as _message
4-
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
4+
from collections.abc import Iterable as _Iterable, Mapping as _Mapping
5+
from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union
56

67
DESCRIPTOR: _descriptor.FileDescriptor
78

@@ -174,6 +175,18 @@ class DeletePlaceResponse(_message.Message):
174175
__slots__ = ()
175176
def __init__(self) -> None: ...
176177

178+
class GetPlaceRequest(_message.Message):
179+
__slots__ = ("name",)
180+
NAME_FIELD_NUMBER: _ClassVar[int]
181+
name: str
182+
def __init__(self, name: _Optional[str] = ...) -> None: ...
183+
184+
class GetPlaceResponse(_message.Message):
185+
__slots__ = ("place",)
186+
PLACE_FIELD_NUMBER: _ClassVar[int]
187+
place: Place
188+
def __init__(self, place: _Optional[_Union[Place, _Mapping]] = ...) -> None: ...
189+
177190
class GetPlacesRequest(_message.Message):
178191
__slots__ = ()
179192
def __init__(self) -> None: ...

0 commit comments

Comments
 (0)