#1947: Add ability for all simcomponents to be scanned - sets up ability for service, files, folders and nodes to be scanned
This commit is contained in:
@@ -200,6 +200,10 @@ class SimComponent(BaseModel):
|
|||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
def scan(self) -> None:
|
||||||
|
"""Update the visible statuses of the SimComponent."""
|
||||||
|
pass
|
||||||
|
|
||||||
def apply_action(self, action: List[str], context: Dict = {}) -> None:
|
def apply_action(self, action: List[str], context: Dict = {}) -> None:
|
||||||
"""
|
"""
|
||||||
Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings.
|
Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
from primaite import getLogger
|
from primaite import getLogger
|
||||||
from primaite.simulator.core import Action, ActionManager
|
from primaite.simulator.core import Action, ActionManager
|
||||||
@@ -34,6 +34,10 @@ class Service(IOSoftware):
|
|||||||
|
|
||||||
operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED
|
operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED
|
||||||
"The current operating state of the Service."
|
"The current operating state of the Service."
|
||||||
|
|
||||||
|
visible_operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED
|
||||||
|
"The visible operating state of the service."
|
||||||
|
|
||||||
restart_duration: int = 5
|
restart_duration: int = 5
|
||||||
"How many timesteps does it take to restart this service."
|
"How many timesteps does it take to restart this service."
|
||||||
_restart_countdown: Optional[int] = None
|
_restart_countdown: Optional[int] = None
|
||||||
@@ -41,6 +45,7 @@ class Service(IOSoftware):
|
|||||||
|
|
||||||
def _init_action_manager(self) -> ActionManager:
|
def _init_action_manager(self) -> ActionManager:
|
||||||
am = super()._init_action_manager()
|
am = super()._init_action_manager()
|
||||||
|
am.add_action("scan", Action(func=lambda request, context: self.scan()))
|
||||||
am.add_action("stop", Action(func=lambda request, context: self.stop()))
|
am.add_action("stop", Action(func=lambda request, context: self.stop()))
|
||||||
am.add_action("start", Action(func=lambda request, context: self.start()))
|
am.add_action("start", Action(func=lambda request, context: self.start()))
|
||||||
am.add_action("pause", Action(func=lambda request, context: self.pause()))
|
am.add_action("pause", Action(func=lambda request, context: self.pause()))
|
||||||
@@ -72,44 +77,13 @@ class Service(IOSoftware):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def send(
|
def scan(self) -> None:
|
||||||
self,
|
"""Update the service visible states."""
|
||||||
payload: Any,
|
# update parent states
|
||||||
session_id: Optional[str] = None,
|
super().scan()
|
||||||
**kwargs,
|
|
||||||
) -> bool:
|
|
||||||
"""
|
|
||||||
Sends a payload to the SessionManager.
|
|
||||||
|
|
||||||
The specifics of how the payload is processed and whether a response payload
|
# update the visible operating state
|
||||||
is generated should be implemented in subclasses.
|
self.visible_operating_state = self.operating_state
|
||||||
|
|
||||||
:param: payload: The payload to send.
|
|
||||||
:param: session_id: The id of the session
|
|
||||||
|
|
||||||
:return: True if successful, False otherwise.
|
|
||||||
"""
|
|
||||||
self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id)
|
|
||||||
|
|
||||||
def receive(
|
|
||||||
self,
|
|
||||||
payload: Any,
|
|
||||||
session_id: Optional[str] = None,
|
|
||||||
**kwargs,
|
|
||||||
) -> bool:
|
|
||||||
"""
|
|
||||||
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 send.
|
|
||||||
:param: session_id: The id of the session
|
|
||||||
|
|
||||||
:return: True if successful, False otherwise.
|
|
||||||
"""
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def stop(self) -> None:
|
def stop(self) -> None:
|
||||||
"""Stop the service."""
|
"""Stop the service."""
|
||||||
|
|||||||
@@ -221,7 +221,9 @@ class IOSoftware(Software):
|
|||||||
:param kwargs: Additional keyword arguments specific to the implementation.
|
:param kwargs: Additional keyword arguments specific to the implementation.
|
||||||
:return: True if the payload was successfully sent, False otherwise.
|
:return: True if the payload was successfully sent, False otherwise.
|
||||||
"""
|
"""
|
||||||
|
self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id, **kwargs)
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def receive(self, payload: Any, session_id: str, **kwargs) -> bool:
|
def receive(self, payload: Any, session_id: str, **kwargs) -> bool:
|
||||||
"""
|
"""
|
||||||
Receives a payload from the SessionManager.
|
Receives a payload from the SessionManager.
|
||||||
|
|||||||
Reference in New Issue
Block a user