#2151: utilise set_health_state method instead of directly changing software states

This commit is contained in:
Czar Echavez
2024-01-09 16:29:40 +00:00
parent 9eb0102069
commit a4d372d3eb
8 changed files with 45 additions and 22 deletions

View File

@@ -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()

View File

@@ -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",

View File

@@ -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."""

View File

@@ -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):