saturnin.protocol.iccp¶
Saturnin Internal Component Control Protocol (ICCP).
This protocol defines the messages and rules for communication between Saturnin components (like services or microservices) and their controllers. It handles lifecycle events (ready, stop, finished), configuration requests, and error reporting.
Enums¶
Classes¶
- class saturnin.protocol.iccp.ICCPMessage[source]¶
Bases:
MessageService Control Message.
- as_zmsg() TZMQMessage[source]¶
Returns message as sequence of ZMQ data frames.
- Returns:
A list of ZMQ frames representing the message. The first frame is the packed
MsgType. Subsequent frames are added based on the message type and its attributes.- Return type:
- copy() Message[source]¶
Returns copy of the message.
- Returns:
A new
ICCPMessageinstance with a deep copy of relevant attributes (likepeer,endpoints,config) based on the original message’smsg_type.- Return type:
- from_zmsg(zmsg: TZMQMessage) None[source]¶
Populate message data from sequence of ZMQ data frames.
- Parameters:
zmsg (TZMQMessage) – Sequence of ZMQ frames to be deserialized. The first frame is
the (always the packed MsgType. Subsequent frames depend on)
type (message)
- Raises:
InvalidMessageError – If message is not a valid protocol message.
- Return type:
None
- get_keys() Iterable[source]¶
Returns iterable of dictionary keys to be used with
Protocol.handlers. Keys must be provided in order of precedence (from more specific to general).- Return type:
- class saturnin.protocol.iccp._ICCP(*args, **kwargs)[source]¶
Bases:
ProtocolInternal Component Control Protocol (ICCP).
Used by Saturnin internally for component/controller transmissions.
- _ICCP__message_factory(zmsg: TypeAliasForwardRef('~saturnin.base.transport.TZMQMessage') | None = None) Message¶
Internal message factory
- Parameters:
zmsg (TypeAliasForwardRef('~saturnin.base.transport.TZMQMessage') | None)
- Return type:
- validate(zmsg: TZMQMessage) None[source]¶
Verifies that sequence of ZMQ data frames is a valid protocol message.
If this validation passes without exception, then
parse()of the same message must be successful as well.- Parameters:
zmsg (TZMQMessage) – ZeroMQ multipart message. Expects the first frame to be the packed
MsgType, followed by type-specific frames.- Raises:
InvalidMessageError – If ZMQ message is not a valid protocol message.
- Return type:
None
- class saturnin.protocol.iccp.ICCPComponent(*args, **kwargs)[source]¶
Bases:
_ICCPInternal Component Control Protocol (ICCP) - Component (client) side.
Used by Saturnin internally for component/controller transmissions.
- __init__(*, session_type: type[Session] = <class 'saturnin.base.transport.Session'>, with_traceback: bool = False)[source]¶
- accept_new_session(channel: Channel, routing_id: RoutingID, msg: ICCPMessage) bool[source]¶
Validates incoming message that initiated new session/transmission.
- Parameters:
channel (Channel) – Channel that received the message.
routing_id (RoutingID) – Routing ID of the sender.
msg (ICCPMessage) – Received message.
- Returns:
Always False (transmission must be initiated by Component).
- Return type:
- connect_with_session(channel: Channel) bool[source]¶
Called by
Channel.connect()to determine whether new session should be associated with connected peer.As ICCP require that connecting peers must send a message to initiate transmission, it always returns True.
- error_msg(exc: Exception) ICCPMessage[source]¶
Returns
ERRORcontrol message.- Parameters:
exc (Exception) – Exception to send.
- Return type:
- finished_msg(outcome: Outcome, details: None | Exception | list[str]) ICCPMessage[source]¶
Returns
FINISHEDcontrol message.- Parameters:
outcome (Outcome) – Outcome of componentn run.
details (None | Exception | list[str]) – Additional information about the outcome. If an
Exception, its traceback (ifwith_tracebackis True) or string, string representation is used. If alist[str], it’s used directly. IfNone, no details are included.
- Return type:
- handle_exception(channel: Channel, session: Session, msg: ICCPMessage, exc: Exception) None[source]¶
Event handler for
on_exception. Callson_stop_componentwith exception.- Parameters:
channel (Channel) – Channel associated with controller.
session (Session) – Session associated with controller.
msg (ICCPMessage) – Message sent by controller.
exc (Exception) – Exception to handle.
- Return type:
None
- handle_invalid_msg(channel: Channel, session: Session, exc: InvalidMessageError) None[source]¶
Event handler for
on_invalid_msg. Callson_stop_componentwith exception.- Parameters:
channel (Channel) – Channel associated with controller.
session (Session) – Session associated with controller.
exc (InvalidMessageError) – Exception raised.
- Return type:
None
- handle_request(channel: Channel, session: Session, msg: ICCPMessage) None[source]¶
Process
REQUESTmessage received from controller.Currently handles
Request.CONFIGUREby invoking theon_config_requestevent with the provided configuration. Sends anOKmessage back to the controller upon successful processing, or anERRORmessage if an exception occurs during theon_config_requesthandling.- Parameters:
channel (Channel) – The channel connected to the controller.
session (Session) – The session instance for this communication.
msg (ICCPMessage) – The received
ICCPMessagecontaining the request.
- Raises:
StopError – If sending the response (OK/ERROR) to the controller fails.
- Return type:
None
- handle_stop(channel: Channel, session: Session, msg: ICCPMessage) None[source]¶
Process
STOPmessage received from controller. Callson_stop_component.- Parameters:
channel (Channel) – Channel associated with controller.
session (Session) – Session associated with controller.
msg (ICCPMessage) – Received message.
- Return type:
None
- ok_msg() ICCPMessage[source]¶
Returns
OKcontrol message.- Return type:
- ready_msg(peer: PeerDescriptor, endpoints: dict[str, list[ZMQAddress]]) ICCPMessage[source]¶
Returns
READYcontrol message.- Parameters:
peer (PeerDescriptor) – Component descriptor.
endpoints (dict[str, list[ZMQAddress]]) – Component endpoints.
- Return type:
- wrong_message(channel: Channel, session: Session, msg: ICCPMessage) None[source]¶
Handle wrong message received from controller.
- Parameters:
channel (Channel) – Channel associated with controller.
session (Session) – Session associated with controller.
msg (ICCPMessage) – Message sent by controller.
- Return type:
None
Raises
StopError, which in turn callson_exceptionfromhandle_msg.
- on_config_request¶
eventsocketcalled when the controller requests reconfiguration.The handler should apply the new configuration. Any exception raised by this event handler will be caught and sent back to the controller as an
ERRORmessage.- Parameters:
config – The new configuration (
ConfigProto) provided by the controller.
- on_stop_component¶
eventsocketcalled when commponent should stop its operation.- Parameters:
exc – Exception that describes the reason why component should stop. If not provided, the component should stop on controller’s request.
- class saturnin.protocol.iccp.ICCPController(*args, **kwargs)[source]¶
Bases:
_ICCPInternal Component Control Protocol (ICCP) - Controller (server) side.
Used by Saturnin internally for component/controller transmissions.
- handle_exception(channel: Channel, session: Session, msg: ICCPMessage, exc: Exception) None[source]¶
Event handler for
on_exception. Callson_stop_controllerwith exception.- Parameters:
channel (Channel) – Channel associated with component.
session (Session) – Session associated with component.
msg (ICCPMessage) – Message sent by component.
exc (Exception) – Exception to handle.
- Return type:
None
- handle_invalid_msg(channel: Channel, session: Session, exc: InvalidMessageError) None[source]¶
Event handler for
on_invalid_msg. Callson_stop_controllerwith exception.- Parameters:
channel (Channel) – Channel associated with component.
session (Session) – Session associated with component.
exc (InvalidMessageError) – Exception raised.
- Return type:
None
- handle_oef(channel: Channel, session: Session, msg: ICCPMessage) ICCPMessage[source]¶
Process
OK/ERROR/FINISHEDmessages received from component. It simply returns the message.- Parameters:
channel (Channel) – Channel associated with component.
session (Session) – Session associated with component.
msg (ICCPMessage) – Message sent by component.
- Return type:
- handle_ready(channel: Channel, session: Session, msg: ICCPMessage) ICCPMessage[source]¶
Processes a
READYmessage received from a component.If this is the first
READYmessage for the session (indicated bysession.readynot being set), it marks the session as ready and returns the received message. This typically signals that the component is initialized and has provided its peer information and endpoints.- Parameters:
channel (Channel) – Channel associated with the component.
session (Session) – Session associated with the component.
msg (ICCPMessage) – The
READYmessage sent by the component.
- Returns:
The received
ICCPMessageif it’s the firstREADYfor this session.- Raises:
StopError – If a
READYmessage is received for a session already marked as ready, as this indicates an unexpected state.- Return type:
- request_config_msg(config: Config | None = None) ICCPMessage[source]¶
Returns
REQUEST.CONFIGcontrol message.- Parameters:
config (Config | None) – Optional
firebird.base.config.Configinstance containing the configuration for the component. IfNone, an empty configuration request is created.- Return type:
- stop_msg() ICCPMessage[source]¶
Returns
STOPcontrol message.- Return type:
- wrong_message(channel: Channel, session: Session, msg: ICCPMessage) None[source]¶
Handle wrong message received from component.
- Parameters:
channel (Channel) – Channel associated with component.
session (Session) – Session associated with component.
msg (ICCPMessage) – Message sent by component.
- Return type:
None
Raises
StopError, which in turn callson_exceptionfromhandle_msg.
- on_stop_controller¶
eventsocketcalled when controller should stop its operation due to error condition.- Parameters:
exc – Exception that describes the reason why component should stop.