2023-08-03 21:30:13 +01:00
|
|
|
from abc import abstractmethod
|
|
|
|
|
from enum import Enum
|
|
|
|
|
from typing import Any, Dict, List
|
|
|
|
|
|
|
|
|
|
from primaite.simulator.system.software import IOSoftware
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ServiceOperatingState(Enum):
|
|
|
|
|
"""Enumeration of Service Operating States."""
|
|
|
|
|
|
|
|
|
|
RUNNING = 1
|
|
|
|
|
"The service is currently running."
|
2023-08-10 13:26:51 +01:00
|
|
|
STOPPED = 2
|
|
|
|
|
"The service is not running."
|
2023-08-03 21:30:13 +01:00
|
|
|
INSTALLING = 3
|
|
|
|
|
"The service is being installed or updated."
|
2023-08-10 13:26:51 +01:00
|
|
|
RESTARTING = 4
|
|
|
|
|
"The service is in the process of restarting."
|
|
|
|
|
PAUSED = 5
|
2023-08-03 21:30:13 +01:00
|
|
|
"The service is temporarily paused."
|
2023-08-10 13:26:51 +01:00
|
|
|
DISABLED = 6
|
2023-08-03 21:30:13 +01:00
|
|
|
"The service is disabled and cannot be started."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Service(IOSoftware):
|
|
|
|
|
"""
|
|
|
|
|
Represents a Service in the simulation environment.
|
|
|
|
|
|
|
|
|
|
Services are programs that run in the background and may perform input/output operations.
|
|
|
|
|
"""
|
2023-08-07 19:33:52 +01:00
|
|
|
|
2023-08-03 21:30:13 +01:00
|
|
|
operating_state: ServiceOperatingState
|
|
|
|
|
"The current operating state of the Service."
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def describe_state(self) -> Dict:
|
|
|
|
|
"""
|
2023-08-17 15:32:12 +01:00
|
|
|
Produce a dictionary describing the current state of this object.
|
2023-08-03 21:30:13 +01:00
|
|
|
|
2023-08-17 15:32:12 +01:00
|
|
|
Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation.
|
2023-08-03 21:30:13 +01:00
|
|
|
|
2023-08-17 15:32:12 +01:00
|
|
|
:return: Current state of this object and child objects.
|
2023-08-03 21:30:13 +01:00
|
|
|
:rtype: Dict
|
|
|
|
|
"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def apply_action(self, action: List[str]) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Applies a list of actions to the Service.
|
|
|
|
|
|
|
|
|
|
:param action: A list of actions to apply.
|
|
|
|
|
"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def reset_component_for_episode(self, episode: int):
|
|
|
|
|
"""
|
|
|
|
|
Resets the Service component for a new episode.
|
|
|
|
|
|
|
|
|
|
This method ensures the Service is ready for a new episode, including resetting any
|
|
|
|
|
stateful properties or statistics, and clearing any message queues.
|
|
|
|
|
"""
|
|
|
|
|
pass
|
|
|
|
|
|
2023-08-07 19:33:52 +01:00
|
|
|
def send(self, payload: Any, session_id: str, **kwargs) -> bool:
|
2023-08-03 21:30:13 +01:00
|
|
|
"""
|
2023-08-07 19:33:52 +01:00
|
|
|
Sends a payload to the SessionManager.
|
2023-08-03 21:30:13 +01:00
|
|
|
|
|
|
|
|
The specifics of how the payload is processed and whether a response payload
|
|
|
|
|
is generated should be implemented in subclasses.
|
|
|
|
|
|
|
|
|
|
:param payload: The payload to send.
|
|
|
|
|
:return: True if successful, False otherwise.
|
|
|
|
|
"""
|
|
|
|
|
pass
|
|
|
|
|
|
2023-08-07 19:33:52 +01:00
|
|
|
def receive(self, payload: Any, session_id: str, **kwargs) -> bool:
|
2023-08-03 21:30:13 +01:00
|
|
|
"""
|
|
|
|
|
Receives a payload from the SessionManager.
|
|
|
|
|
|
|
|
|
|
The specifics of how the payload is processed and whether a response payload
|
|
|
|
|
is generated should be implemented in subclasses.
|
|
|
|
|
|
|
|
|
|
:param payload: The payload to receive.
|
|
|
|
|
:return: True if successful, False otherwise.
|
|
|
|
|
"""
|
|
|
|
|
pass
|