-
Notifications
You must be signed in to change notification settings - Fork 807
Closed
Description
Refactor
Component(s) to be refactored
monkey_island.cc.resources.stop_agent_check
monkey_island.cc.resources.stop_all_agents
Explanation
In order to know whether or not an agent has been manually killed and should stop, two pieces of information are required:
- The time that the user sent the terminate signal
- The start time of the agent (if depth == 0) or it's progenitor (if depth > 0)
If the agent or its progenitor was started before the terminate signal was sent, it should stop. The logic looks something like:
def agent_terminated(agent: Agent) -> bool:
terminate_signal_time = self._simulation_repository.get_simuliation().terminate_signal_time
if terminate_signal_time is None:
return False
progenitor = self._agent_repository.get_progenitor(agent)
return progenitor.start_time <= stop_time
We can create an AgentSignals
model and an AgentSignalsService
to retrieve the status of those signals.
Currently, AgentSignals
will only contain terminate
, but we plan to add a signal to force kill agents in the future. Other signals can be easily added as the need arises.
AgentSignals
model
class AgentSignals(InfectionMonkeyBaseModel):
terminate: Optional[datetime]
AgentSignalsService
class AgentSignalsService:
def __init__(self, simulation_repository: ISimulationRepository):
...
def get_signals(self, agent: Agent) -> AgentSignals:
...
def on_terminate_agents_signal(self, timestamp: datetime):
...
Tasks
- Add
TERMINATE_AGENTS
toIslandEventTopic
(0d) @ilija-lazoroski - Add a field to the
Simulation
model that contains a timestamp of when the stop button was pressed (0d) @ilija-lazoroski - Add new
AgentSignalService
with stubbed methods that do nothing and/or return dummy data (0d) @ilija-lazoroski - Add
IAgentRepository.get_progenitor(descendant: Agent) -> agent
(0d) @ilija-lazoroski - Subscribe
AgentSignalsService.on_terminate_agents_signal
toTERMINATE_AGENTS
events. UpdateISimulationRepository
with the latest data. (0d) @ilija-lazoroski @cakekoa - Implement
AgentSignalsService.get_signals()
(See above logic to get started) (0d) @mssalvatore - Create a new resource for agent signals (
/api/agent-signals
) @cakekoa, @shreyamalviya (0d)- Implement
POST /api/agent-signals/terminate-all
(accepts a timestamp in the json body)- Publish
TERMINATE_AGENTS
with timestamp toIIslandEventQueue
- Publish
- Implement
GET /api/agent-signals/<AGENT_ID>
that returnsAgentSignals
- Implement
- Modify the agent's calls to
needs-to-stop
to callGET /api/agent-signals/<AGENT_ID>
(0d) @ilija-lazoroski- Add
get_agent_signals()
toIslandAPIClient
- Call
IslandAPIClient.get_agent_signals()
fromControlChannel
and check timestamp of terminate signal
- Add
- Modify the UI to call
POST /api/agent-signals/terminate-all
(0d) - @shreyamalviya - Remove
monkey_island.cc.resources.agent_controls
(0.25d) - @VakarisZ, @mssalvatore - Move
monkey_island.cc.models.AgentSignals
to common (0d) - @ilija-lazoroski