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
Task dependencies

Refactor
Component(s) to be refactored
monkey_island.cc.resources.stop_agent_checkmonkey_island.cc.resources.stop_all_agentsExplanation
In order to know whether or not an agent has been manually killed and should stop, two pieces of information are required:
If the agent or its progenitor was started before the terminate signal was sent, it should stop. The logic looks something like:
We can create an
AgentSignalsmodel and anAgentSignalsServiceto retrieve the status of those signals.Currently,
AgentSignalswill only containterminate, but we plan to add a signal to force kill agents in the future. Other signals can be easily added as the need arises.AgentSignalsmodelAgentSignalsServiceTasks
TERMINATE_AGENTStoIslandEventTopic(0d) @ilija-lazoroskiSimulationmodel that contains a timestamp of when the stop button was pressed (0d) @ilija-lazoroskiAgentSignalServicewith stubbed methods that do nothing and/or return dummy data (0d) @ilija-lazoroskiIAgentRepository.get_progenitor(descendant: Agent) -> agent(0d) @ilija-lazoroskiAgentSignalsService.on_terminate_agents_signaltoTERMINATE_AGENTSevents. UpdateISimulationRepositorywith the latest data. (0d) @ilija-lazoroski @cakekoaAgentSignalsService.get_signals()(See above logic to get started) (0d) @mssalvatore/api/agent-signals) @cakekoa, @shreyamalviya (0d)POST /api/agent-signals/terminate-all(accepts a timestamp in the json body)TERMINATE_AGENTSwith timestamp toIIslandEventQueueGET /api/agent-signals/<AGENT_ID>that returnsAgentSignalsneeds-to-stopto callGET /api/agent-signals/<AGENT_ID>(0d) @ilija-lazoroskiget_agent_signals()toIslandAPIClientIslandAPIClient.get_agent_signals()fromControlChanneland check timestamp of terminate signalPOST /api/agent-signals/terminate-all(0d) - @shreyamalviyamonkey_island.cc.resources.agent_controls(0.25d) - @VakarisZ, @mssalvatoremonkey_island.cc.models.AgentSignalsto common (0d) - @ilija-lazoroskiTask dependencies