gRPC REST

This module implements bidirectional gRPC communication for mission management systems. Contains both server and client components for handling mission data and status updates.

Components

  • RestCommunicationService : gRPC service implementation for receiving mission statuses

  • run_rest_server : gRPC server startup and management

  • run_rest_client : gRPC client for mission submission

  • start_grpc_rest : Server thread management

Protocol Buffers

Uses generated code from: - rest_pb2(_grpc): For REST status communication - mission_pb2(_grpc): For mission data transmission

Example

Start server:

$ python grpc_rest.py

Send mission from client:
>>> from grpc_rest import run_rest_client
>>> run_rest_client('{"mission": "data"}', logger)
class grpc_rest.RestCommunicationService(*args: Any, **kwargs: Any)[source]

Bases: RestCommunicationServicer

gRPC service implementation for handling mission status updates.

Inherits from generated RestCommunicationServicer and implements the gRPC service methods.

Parameters:

rest_logger (logging.Logger) – Configured logger instance for service operations

Variables:

rest_logger (logging.Logger) – Logger instance for service operations

__init__(rest_logger)[source]

Initialize service with configured logger.

SendRest(request, context)[source]

Handle incoming mission status updates from Fleet Management.

Parameters:
  • request (rest_pb2.RestRequest) – Incoming gRPC request containing mission status data

  • context (grpc.ServicerContext) – gRPC connection context

Returns:

Response confirmation with status receipt acknowledgment

Return type:

rest_pb2.RestResponse

Raises:

grpc.RpcError – If connection issues occur during processing

Example

Typical status format:

mission_status = ["COMPLETED", "IN_PROGRESS", "FAILED"]
grpc_rest.run_rest_server(rest_logger)[source]

Start and maintain the gRPC server for REST communication.

Parameters:

rest_logger (logging.Logger) – Configured logger instance for server operations

Server Configuration: - Uses ThreadPoolExecutor with 10 worker threads - Listens on port 50052 - Runs indefinitely until keyboard interrupt

Note:

Blocks execution while running - typically started in separate thread

grpc_rest.run_rest_client(mission_json, rest_logger)[source]

Send mission data to Fleet Management system via gRPC.

Parameters:
  • mission_json (str) – Mission data in JSON string format

  • rest_logger (logging.Logger) – Configured logger instance for client operations

Returns:

Confirmation message from server or None on failure

Return type:

str | None

Raises:

grpc.RpcError – If connection to server fails

Example

Successful response:

"Mission received by Fleet Management: 12345"
grpc_rest.start_grpc_rest(rest_logger)[source]

Initialize and start gRPC server in background thread.

Parameters:

rest_logger (logging.Logger) – Configured logger instance for server operations

Note:

Server thread runs as daemon and will terminate with main process