#2151: utilise set_health_state method instead of directly changing software states
This commit is contained in:
@@ -3,7 +3,7 @@ from enum import Enum
|
||||
from typing import Any, Dict, Set
|
||||
|
||||
from primaite import getLogger
|
||||
from primaite.simulator.system.software import IOSoftware, SoftwareHealthState
|
||||
from primaite.simulator.system.software import IOSoftware
|
||||
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
@@ -38,9 +38,6 @@ class Application(IOSoftware):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.health_state_visible = SoftwareHealthState.UNUSED
|
||||
self.health_state_actual = SoftwareHealthState.UNUSED
|
||||
|
||||
def set_original_state(self):
|
||||
"""Sets the original state."""
|
||||
super().set_original_state()
|
||||
|
||||
@@ -196,7 +196,7 @@ class DatabaseService(Service):
|
||||
return {"status_code": 404, "data": False}
|
||||
elif query == "DELETE":
|
||||
if self.health_state_actual == SoftwareHealthState.GOOD:
|
||||
self.health_state_actual = SoftwareHealthState.COMPROMISED
|
||||
self.set_health_state(SoftwareHealthState.COMPROMISED)
|
||||
return {
|
||||
"status_code": 200,
|
||||
"type": "sql",
|
||||
|
||||
@@ -127,7 +127,7 @@ class Service(IOSoftware):
|
||||
self.operating_state = ServiceOperatingState.RUNNING
|
||||
# set software health state to GOOD if initially set to UNUSED
|
||||
if self.health_state_actual == SoftwareHealthState.UNUSED:
|
||||
self.health_state_actual = SoftwareHealthState.GOOD
|
||||
self.set_health_state(SoftwareHealthState.GOOD)
|
||||
|
||||
def pause(self) -> None:
|
||||
"""Pause the service."""
|
||||
|
||||
@@ -303,13 +303,13 @@ class IOSoftware(Software):
|
||||
"""
|
||||
# if over or at capacity, set to overwhelmed
|
||||
if len(self._connections) >= self.max_sessions:
|
||||
self.health_state_actual = SoftwareHealthState.OVERWHELMED
|
||||
self.set_health_state(SoftwareHealthState.OVERWHELMED)
|
||||
self.sys_log.error(f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity.")
|
||||
return False
|
||||
else:
|
||||
# if service was previously overwhelmed, set to good because there is enough space for connections
|
||||
if self.health_state_actual == SoftwareHealthState.OVERWHELMED:
|
||||
self.health_state_actual = SoftwareHealthState.GOOD
|
||||
self.set_health_state(SoftwareHealthState.GOOD)
|
||||
|
||||
# check that connection already doesn't exist
|
||||
if not self._connections.get(connection_id):
|
||||
|
||||
Reference in New Issue
Block a user