Skip to content
Snippets Groups Projects
Commit a7cb3a20 authored by Corné Lukken's avatar Corné Lukken
Browse files

Merge branch 'small-refactor-station-manager' into 'master'

Small refactor station state errors and objects

See merge request !892
parents 3abf55c2 8c37c4b2
Branches
No related tags found
1 merge request!892Small refactor station state errors and objects
...@@ -161,6 +161,7 @@ Next change the version in the following places: ...@@ -161,6 +161,7 @@ Next change the version in the following places:
# Release Notes # Release Notes
* 0.38.5 Unify exception handling for station manager
* 0.38.4 Fixed ordering in subband_frequency_R, which broke frequency calculations for HBA * 0.38.4 Fixed ordering in subband_frequency_R, which broke frequency calculations for HBA
* 0.38.3 Upgraded to JupyterLab v4 * 0.38.3 Upgraded to JupyterLab v4
* 0.38.2 Fixed polling of some attributes required by Metadata device * 0.38.2 Fixed polling of some attributes required by Metadata device
......
...@@ -185,4 +185,3 @@ resources (see [above](#clean-up-lingering-resources)). ...@@ -185,4 +185,3 @@ resources (see [above](#clean-up-lingering-resources)).
## unable to destroy resource Name: station, Type: network ## unable to destroy resource Name: station, Type: network
Solution: some containers are still running. Stop them, or force stop all containers using ``docker ps -q -a | xargs docker rm -f``. Solution: some containers are still running. Stop them, or force stop all containers using ``docker ps -q -a | xargs docker rm -f``.
0.38.4 0.38.5
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) # Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import logging import logging
from tango import DevFailed, Except from tango import DevFailed
from tangostationcontrol.states.station_state import StationState from tangostationcontrol.states.station_state import StationState
from tangostationcontrol.states.station_state_enum import StationStateEnum from tangostationcontrol.states.station_state_enum import StationStateEnum
...@@ -28,12 +28,9 @@ class HibernateState(StationState): ...@@ -28,12 +28,9 @@ class HibernateState(StationState):
from tangostationcontrol.states.off import OffState from tangostationcontrol.states.off import OffState
# not implemented -> call the correct state transition function # not implemented -> call the correct state transition function
self._station_manager.requested_station_state = OffState( new_state = OffState(self._station_manager, self._power_hierarchy)
self._station_manager, self._power_hierarchy self._station_manager.requested_station_state = new_state.state.name
).state.name self._station_manager.set_station_state(new_state)
self._station_manager.set_station_state(
OffState(self._station_manager, self._power_hierarchy)
)
async def station_standby(self): async def station_standby(self):
"""Transition HIBERNATE -> STANDBY""" """Transition HIBERNATE -> STANDBY"""
...@@ -46,11 +43,7 @@ class HibernateState(StationState): ...@@ -46,11 +43,7 @@ class HibernateState(StationState):
self._power_hierarchy.hibernate_to_standby, self._power_hierarchy.hibernate_to_standby,
) )
except DevFailed as exc: except DevFailed as exc:
error_string = self.get_transition_error_string(target_state) self.generate_transition_error(target_state, logger, exc)
logger.exception(error_string)
Except.re_throw_exception(
exc, "DevFailed", error_string, str(self._station_manager)
)
self._station_manager.set_station_state( self._station_manager.set_station_state(
StandbyState(self._station_manager, self._power_hierarchy) StandbyState(self._station_manager, self._power_hierarchy)
) )
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) # Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import logging import logging
from tango import DevFailed, Except from tango import DevFailed
from tangostationcontrol.states.station_state import StationState from tangostationcontrol.states.station_state import StationState
from tangostationcontrol.states.station_state_enum import StationStateEnum from tangostationcontrol.states.station_state_enum import StationStateEnum
...@@ -37,11 +37,7 @@ class OffState(StationState): ...@@ -37,11 +37,7 @@ class OffState(StationState):
self._power_hierarchy.off_to_hibernate, self._power_hierarchy.off_to_hibernate,
) )
except DevFailed as exc: except DevFailed as exc:
error_string = self.get_transition_error_string(target_state) self.generate_transition_error(target_state, logger, exc)
logger.exception(error_string)
Except.re_throw_exception(
exc, "DevFailed", error_string, str(self._station_manager)
)
self._station_manager.set_station_state( self._station_manager.set_station_state(
HibernateState(self._station_manager, self._power_hierarchy) HibernateState(self._station_manager, self._power_hierarchy)
) )
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) # Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import logging import logging
from tango import DevFailed, Except from tango import DevFailed
from tangostationcontrol.states.station_state import StationState from tangostationcontrol.states.station_state import StationState
from tangostationcontrol.states.station_state_enum import StationStateEnum from tangostationcontrol.states.station_state_enum import StationStateEnum
...@@ -38,11 +38,7 @@ class OnState(StationState): ...@@ -38,11 +38,7 @@ class OnState(StationState):
self._power_hierarchy.on_to_standby, self._power_hierarchy.on_to_standby,
) )
except DevFailed as exc: except DevFailed as exc:
error_string = self.get_transition_error_string(target_state) self.generate_transition_error(target_state, logger, exc)
logger.exception(error_string)
Except.re_throw_exception(
exc, "DevFailed", error_string, str(self._station_manager)
)
self._station_manager.set_station_state( self._station_manager.set_station_state(
StandbyState(self._station_manager, self._power_hierarchy) StandbyState(self._station_manager, self._power_hierarchy)
) )
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) # Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import logging import logging
from tango import DevFailed, Except from tango import DevFailed
from tangostationcontrol.states.station_state import StationState from tangostationcontrol.states.station_state import StationState
from tangostationcontrol.states.station_state_enum import StationStateEnum from tangostationcontrol.states.station_state_enum import StationStateEnum
...@@ -34,11 +34,7 @@ class StandbyState(StationState): ...@@ -34,11 +34,7 @@ class StandbyState(StationState):
self._power_hierarchy.standby_to_hibernate, self._power_hierarchy.standby_to_hibernate,
) )
except DevFailed as exc: except DevFailed as exc:
error_string = self.get_transition_error_string(target_state) self.generate_transition_error(target_state, logger, exc)
logger.exception(error_string)
Except.re_throw_exception(
exc, "DevFailed", error_string, str(self._station_manager)
)
self._station_manager.set_station_state( self._station_manager.set_station_state(
HibernateState(self._station_manager, self._power_hierarchy) HibernateState(self._station_manager, self._power_hierarchy)
) )
...@@ -54,11 +50,7 @@ class StandbyState(StationState): ...@@ -54,11 +50,7 @@ class StandbyState(StationState):
self._power_hierarchy.standby_to_on, self._power_hierarchy.standby_to_on,
) )
except DevFailed as exc: except DevFailed as exc:
error_string = self.get_transition_error_string(target_state) self.generate_transition_error(target_state, logger, exc)
logger.exception(error_string)
Except.re_throw_exception(
exc, "DevFailed", error_string, str(self._station_manager)
)
self._station_manager.set_station_state( self._station_manager.set_station_state(
OnState(self._station_manager, self._power_hierarchy) OnState(self._station_manager, self._power_hierarchy)
) )
...@@ -5,7 +5,8 @@ import logging ...@@ -5,7 +5,8 @@ import logging
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Callable, Awaitable from typing import Callable, Awaitable
from functools import wraps from functools import wraps
from tango import DevState, DeviceProxy
from tango import DevState, DeviceProxy, Except, DevFailed
from tangostationcontrol.states.station_state_enum import StationStateEnum from tangostationcontrol.states.station_state_enum import StationStateEnum
...@@ -71,11 +72,17 @@ class StationState(ABC): ...@@ -71,11 +72,17 @@ class StationState(ABC):
"""Return the timeout for a given station state""" """Return the timeout for a given station state"""
return cls.TIMEOUT_DICT[state] return cls.TIMEOUT_DICT[state]
def get_transition_error_string(self, target_state: StationStateEnum) -> str: def generate_transition_error(
"""Print standard transition error string""" self, target_state: StationStateEnum, log: logging.Logger, exc: DevFailed
return f"Station {self._station_manager.Station_Name} \ ):
"""Generate standardized error for state transistions"""
error_string = f"Station {self._station_manager.Station_Name} \
can not transition to {target_state.name} state. \ can not transition to {target_state.name} state. \
Current state is {self.state.name}" Current state is {self.state.name}"
log.exception(error_string)
Except.re_throw_exception(
exc, "DevFailed", error_string, str(self._station_manager)
)
def get_transition_current_state_error(self) -> None: def get_transition_current_state_error(self) -> None:
"""Log a warning message after performing a transition to """Log a warning message after performing a transition to
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment