From dbc484eda57d8a237889219e4c93e2bf24c9c21c Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Tue, 1 Nov 2022 01:09:20 +0100 Subject: [PATCH] CmdException* moved from Agent to models.AgentCmd (as inner/nested classes) --- CHANGELOG | 3 +++ VERSION | 2 +- privatedev/plugin/agent/AgentBasic.py | 3 ++- src/core/pyros_django/agent/Agent.py | 91 ++++++++----------------------------------------------------------------------------------- src/core/pyros_django/agent/AgentBasic.py | 3 ++- src/core/pyros_django/common/models.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 86 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 32cad2e..b7aa34f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +01-11-2022 (EP): v0.6.7.1 + - CmdException* moved from Agent to models.AgentCmd (as inner/nested classes) + 29-10-2022 (EP): v0.6.7.0 - Simplified agent v2 (async) algo - Added management of any exception occuring during execution of an agent specific ommand => becomes CmdExceptionExecError diff --git a/VERSION b/VERSION index 6620cc4..7762dcd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.7.0 \ No newline at end of file +0.6.7.1 \ No newline at end of file diff --git a/privatedev/plugin/agent/AgentBasic.py b/privatedev/plugin/agent/AgentBasic.py index aabf8dc..a77c50c 100755 --- a/privatedev/plugin/agent/AgentBasic.py +++ b/privatedev/plugin/agent/AgentBasic.py @@ -11,7 +11,8 @@ import sys ###from agent.Agent import Agent, build_agent sys.path.append("../../../..") #from src.core.pyros_django.common.models import AgentCmd -from src.core.pyros_django.agent.Agent import Agent, CmdExceptionExecError, build_agent +from src.core.pyros_django.agent.Agent import Agent, build_agent +#from src.core.pyros_django.common.models import AgentCmd from typing import List, Tuple, Union, Any diff --git a/src/core/pyros_django/agent/Agent.py b/src/core/pyros_django/agent/Agent.py index 39acd3c..540495c 100755 --- a/src/core/pyros_django/agent/Agent.py +++ b/src/core/pyros_django/agent/Agent.py @@ -153,11 +153,19 @@ import config.old_config as config_old #from config import * from common.models import AgentSurvey, AgentCmd, AgentLogs +CmdException = AgentCmd.CmdException +CmdExceptionUnknown = AgentCmd.CmdExceptionUnknown +CmdExceptionUnimplemented = AgentCmd.CmdExceptionUnimplemented +CmdExceptionBadArgs = AgentCmd.CmdExceptionBadArgs +CmdExceptionExecError = AgentCmd.CmdExceptionExecError +CmdExceptionExecKilled = AgentCmd.CmdExceptionExecKilled +CmdExceptionExecTimeout = AgentCmd.CmdExceptionExecTimeout #from config.configpyros import ConfigPyros from config.old_config.configpyros import ConfigPyros as ConfigPyrosOld from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig + #from dashboard.views import get_sunelev #from devices.TelescopeRemoteControlDefault import TelescopeRemoteControlDefault #from utils.JDManipulator import * @@ -255,89 +263,6 @@ class StoppableThreadEvenWhenSleeping(threading.Thread): ### # ================================================================= -# EXCEPTIONS classes -# ================================================================= -### - -class CmdException(Exception): - ''' Base class for all Agent command exceptions ''' - # pass - def __init__( self, cmd:Union[AgentCmd,str], msg:str=None): - self.cmd = cmd - self._msg = msg - self.cmd_name = cmd if isinstance(cmd,str) else cmd.name - @property - def msg(self): - msg = "EXCEPTION on command "+self.cmd_name - return msg if not self._msg else msg+': '+self._msg - # Default message if print exception - def __str__(self): - return self.msg - ''' - msg = "EXCEPTION on command "+self.cmd_name - return msg if not self.msg else msg+': '+self.msg - ''' - ''' - def __str__(self): - return f"The Agent command '{self.cmd.name}' is unknown to the agent" - #return f"({type(self).__name__}): Device Generic command has no implementation in the controller" - ''' - -# --- CMD PENDING (non running) EXCEPTIONS --- - -# @Override -class CmdExceptionUnknown(CmdException): - ''' Raised when a PENDING (non running) Agent (specific) cmd is NOT known by the agent ''' - # @Override - def __init__( self, cmd, msg:str=None): - super().__init__(cmd, msg if msg else "Unknown command") - #def __str__(self): return self.msg if self.msg else f"The Agent command '{self.cmd_name}' is unknown to the agent" - -# @Override -class CmdExceptionUnimplemented(CmdException): - ''' Raised when a PENDING (non running) Agent Specific cmd is known by the agent but not implemented ''' - # @Override - def __init__( self, cmd, msg:str=None): - super().__init__(cmd, msg if msg else "Command is known by the agent but not implemented") - #def __str__(self): return f"The Agent command '{self.cmd_name}' is known by the agent but not implemented" - -# @Override -class CmdExceptionBadArgs(CmdException): - ''' Raised when a PENDING (non running) Agent cmd has bad, missing, or too many argument(s) ''' - # @Override - def __init__( self, cmd, msg:str=None): - super().__init__(cmd, msg if msg else "Command has bad, missing, or too many argument(s)") - #def __str__(self): return f"The Agent command '{self.cmd_name}' has bad, missing, or too many argument(s)" - - -# --- CMD RUNNING EXCEPTIONS --- - -# @Override -class CmdExceptionExecError(CmdException): - ''' Raised when a RUNNING Agent cmd has had a running error ''' - # @Override - def __init__( self, cmd, msg:str=None): - super().__init__(cmd, msg if msg else "Error during Execution") - #def __str__(self): return f"The running Agent command '{self.cmd_name}' has had an error (during execution)" - -# @Override -class CmdExceptionExecTimeout(CmdException): - ''' Raised when a RUNNING Agent cmd is timeout ''' - # @Override - def __init__( self, cmd, msg:str=None): - super().__init__(cmd, msg if msg else "Execution is TIMEOUT") - #def __str__(self): return f"The running Agent command '{self.cmd_name}' is timeout" - -# @Override -class CmdExceptionExecKilled(CmdException): - ''' Raised when a RUNNING Agent cmd has been aborted (by another agent) ''' - # @Override - def __init__( self, cmd, msg:str=None): - super().__init__(cmd, msg if msg else "Command was KILLED during Execution (by another agent") - #def __str__(self): return f"The running Agent command '{self.cmd_name}' has been killed (by another agent)" - -### -# ================================================================= # class Agent # ================================================================= ### diff --git a/src/core/pyros_django/agent/AgentBasic.py b/src/core/pyros_django/agent/AgentBasic.py index aabf8dc..a77c50c 100755 --- a/src/core/pyros_django/agent/AgentBasic.py +++ b/src/core/pyros_django/agent/AgentBasic.py @@ -11,7 +11,8 @@ import sys ###from agent.Agent import Agent, build_agent sys.path.append("../../../..") #from src.core.pyros_django.common.models import AgentCmd -from src.core.pyros_django.agent.Agent import Agent, CmdExceptionExecError, build_agent +from src.core.pyros_django.agent.Agent import Agent, build_agent +#from src.core.pyros_django.common.models import AgentCmd from typing import List, Tuple, Union, Any diff --git a/src/core/pyros_django/common/models.py b/src/core/pyros_django/common/models.py index 21c93ea..2a21f1b 100644 --- a/src/core/pyros_django/common/models.py +++ b/src/core/pyros_django/common/models.py @@ -463,6 +463,92 @@ class AgentCmd(models.Model): See doc/models_Command_state_diag.pu for PlantUML state diagram """ + + ### + # ================================================================= + # EXCEPTIONS classes + # ================================================================= + ### + + class CmdException(Exception): + ''' Base class for all Agent command exceptions ''' + # pass + def __init__( self, cmd:Union[AgentCmd,str], msg:str=None): + self.cmd = cmd + self._msg = msg + self.cmd_name = cmd if isinstance(cmd,str) else cmd.name + @property + def msg(self): + msg = "EXCEPTION on command "+self.cmd_name + return msg if not self._msg else msg+': '+self._msg + # Default message if print exception + def __str__(self): + return self.msg + ''' + msg = "EXCEPTION on command "+self.cmd_name + return msg if not self.msg else msg+': '+self.msg + ''' + ''' + def __str__(self): + return f"The Agent command '{self.cmd.name}' is unknown to the agent" + #return f"({type(self).__name__}): Device Generic command has no implementation in the controller" + ''' + + # --- CMD PENDING (non running) EXCEPTIONS --- + + # @Override + class CmdExceptionUnknown(CmdException): + ''' Raised when a PENDING (non running) Agent (specific) cmd is NOT known by the agent ''' + # @Override + def __init__( self, cmd, msg:str=None): + super().__init__(cmd, msg if msg else "Unknown command") + #def __str__(self): return self.msg if self.msg else f"The Agent command '{self.cmd_name}' is unknown to the agent" + + # @Override + class CmdExceptionUnimplemented(CmdException): + ''' Raised when a PENDING (non running) Agent Specific cmd is known by the agent but not implemented ''' + # @Override + def __init__( self, cmd, msg:str=None): + super().__init__(cmd, msg if msg else "Command is known by the agent but not implemented") + #def __str__(self): return f"The Agent command '{self.cmd_name}' is known by the agent but not implemented" + + # @Override + class CmdExceptionBadArgs(CmdException): + ''' Raised when a PENDING (non running) Agent cmd has bad, missing, or too many argument(s) ''' + # @Override + def __init__( self, cmd, msg:str=None): + super().__init__(cmd, msg if msg else "Command has bad, missing, or too many argument(s)") + #def __str__(self): return f"The Agent command '{self.cmd_name}' has bad, missing, or too many argument(s)" + + + # --- CMD RUNNING EXCEPTIONS --- + + # @Override + class CmdExceptionExecError(CmdException): + ''' Raised when a RUNNING Agent cmd has had a running error ''' + # @Override + def __init__( self, cmd, msg:str=None): + super().__init__(cmd, msg if msg else "Error during Execution") + #def __str__(self): return f"The running Agent command '{self.cmd_name}' has had an error (during execution)" + + # @Override + class CmdExceptionExecTimeout(CmdException): + ''' Raised when a RUNNING Agent cmd is timeout ''' + # @Override + def __init__( self, cmd, msg:str=None): + super().__init__(cmd, msg if msg else "Execution is TIMEOUT") + #def __str__(self): return f"The running Agent command '{self.cmd_name}' is timeout" + + # @Override + class CmdExceptionExecKilled(CmdException): + ''' Raised when a RUNNING Agent cmd has been aborted (by another agent) ''' + # @Override + def __init__( self, cmd, msg:str=None): + super().__init__(cmd, msg if msg else "Command was KILLED during Execution (by another agent") + #def __str__(self): return f"The running Agent command '{self.cmd_name}' has been killed (by another agent)" + + + # -------------- Command CONSTANTS -------------- # Command status codes -- libgit2 0.21.2