Skip to content

Commit

Permalink
add endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 committed Apr 12, 2024
1 parent 34fdc5f commit 0d8b0d2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/py/flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
CreateNodeResponse,
DeleteNodeRequest,
DeleteNodeResponse,
GetRunRequest,
GetRunResponse,
PingRequest,
PingResponse,
PullTaskInsRequest,
Expand Down Expand Up @@ -90,3 +92,13 @@ def PushTaskRes(
request=request,
state=self.state_factory.state(),
)

def GetRun(
self, request: GetRunRequest, context: grpc.ServicerContext
) -> GetRunResponse:
"""Get run information."""
log(INFO, "FleetServicer.GetRun")
return message_handler.get_run(
request=request,
state=self.state_factory.state(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
CreateNodeResponse,
DeleteNodeRequest,
DeleteNodeResponse,
GetRunRequest,
GetRunResponse,
PingRequest,
PingResponse,
PullTaskInsRequest,
Expand Down Expand Up @@ -101,3 +103,10 @@ def push_task_res(request: PushTaskResRequest, state: State) -> PushTaskResRespo
results={str(task_id): 0},
)
return response


def get_run(
request: GetRunRequest, state: State # pylint: disable=W0613
) -> GetRunResponse:
"""Get run information."""
return GetRunResponse()
30 changes: 30 additions & 0 deletions src/py/flwr/server/superlink/fleet/rest_rere/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
CreateNodeRequest,
DeleteNodeRequest,
GetRunRequest,
PingRequest,
PullTaskInsRequest,
PushTaskResRequest,
Expand Down Expand Up @@ -179,12 +180,41 @@ async def ping(request: Request) -> Response:
)


async def get_run(request: Request) -> Response:
"""GetRun."""
_check_headers(request.headers)

# Get the request body as raw bytes
get_run_request_bytes: bytes = await request.body()

# Deserialize ProtoBuf
get_run_request_proto = GetRunRequest()
get_run_request_proto.ParseFromString(get_run_request_bytes)

# Get state from app
state: State = app.state.STATE_FACTORY.state()

# Handle message
get_run_response_proto = message_handler.get_run(
request=get_run_request_proto, state=state
)

# Return serialized ProtoBuf
get_run_response_bytes = get_run_response_proto.SerializeToString()
return Response(
status_code=200,
content=get_run_response_bytes,
headers={"Content-Type": "application/protobuf"},
)


routes = [
Route("/api/v0/fleet/create-node", create_node, methods=["POST"]),
Route("/api/v0/fleet/delete-node", delete_node, methods=["POST"]),
Route("/api/v0/fleet/pull-task-ins", pull_task_ins, methods=["POST"]),
Route("/api/v0/fleet/push-task-res", push_task_res, methods=["POST"]),
Route("/api/v0/fleet/ping", ping, methods=["POST"]),
Route("/api/v0/fleet/get-run", get_run, methods=["POST"]),
]

app: Starlette = Starlette(
Expand Down

0 comments on commit 0d8b0d2

Please sign in to comment.