Commit dbc484eda57d8a237889219e4c93e2bf24c9c21c
1 parent
fd76dc91
Exists in
dev
CmdException* moved from Agent to models.AgentCmd (as inner/nested classes)
Showing
6 changed files
with
102 additions
and
86 deletions
Show diff stats
CHANGELOG
1 | +01-11-2022 (EP): v0.6.7.1 | |
2 | + - CmdException* moved from Agent to models.AgentCmd (as inner/nested classes) | |
3 | + | |
1 | 4 | 29-10-2022 (EP): v0.6.7.0 |
2 | 5 | - Simplified agent v2 (async) algo |
3 | 6 | - Added management of any exception occuring during execution of an agent specific ommand => becomes CmdExceptionExecError | ... | ... |
VERSION
privatedev/plugin/agent/AgentBasic.py
... | ... | @@ -11,7 +11,8 @@ import sys |
11 | 11 | ###from agent.Agent import Agent, build_agent |
12 | 12 | sys.path.append("../../../..") |
13 | 13 | #from src.core.pyros_django.common.models import AgentCmd |
14 | -from src.core.pyros_django.agent.Agent import Agent, CmdExceptionExecError, build_agent | |
14 | +from src.core.pyros_django.agent.Agent import Agent, build_agent | |
15 | +#from src.core.pyros_django.common.models import AgentCmd | |
15 | 16 | |
16 | 17 | from typing import List, Tuple, Union, Any |
17 | 18 | ... | ... |
src/core/pyros_django/agent/Agent.py
... | ... | @@ -153,11 +153,19 @@ import config.old_config as config_old |
153 | 153 | #from config import * |
154 | 154 | |
155 | 155 | from common.models import AgentSurvey, AgentCmd, AgentLogs |
156 | +CmdException = AgentCmd.CmdException | |
157 | +CmdExceptionUnknown = AgentCmd.CmdExceptionUnknown | |
158 | +CmdExceptionUnimplemented = AgentCmd.CmdExceptionUnimplemented | |
159 | +CmdExceptionBadArgs = AgentCmd.CmdExceptionBadArgs | |
160 | +CmdExceptionExecError = AgentCmd.CmdExceptionExecError | |
161 | +CmdExceptionExecKilled = AgentCmd.CmdExceptionExecKilled | |
162 | +CmdExceptionExecTimeout = AgentCmd.CmdExceptionExecTimeout | |
156 | 163 | |
157 | 164 | #from config.configpyros import ConfigPyros |
158 | 165 | from config.old_config.configpyros import ConfigPyros as ConfigPyrosOld |
159 | 166 | from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig |
160 | 167 | |
168 | + | |
161 | 169 | #from dashboard.views import get_sunelev |
162 | 170 | #from devices.TelescopeRemoteControlDefault import TelescopeRemoteControlDefault |
163 | 171 | #from utils.JDManipulator import * |
... | ... | @@ -255,89 +263,6 @@ class StoppableThreadEvenWhenSleeping(threading.Thread): |
255 | 263 | |
256 | 264 | ### |
257 | 265 | # ================================================================= |
258 | -# EXCEPTIONS classes | |
259 | -# ================================================================= | |
260 | -### | |
261 | - | |
262 | -class CmdException(Exception): | |
263 | - ''' Base class for all Agent command exceptions ''' | |
264 | - # pass | |
265 | - def __init__( self, cmd:Union[AgentCmd,str], msg:str=None): | |
266 | - self.cmd = cmd | |
267 | - self._msg = msg | |
268 | - self.cmd_name = cmd if isinstance(cmd,str) else cmd.name | |
269 | - @property | |
270 | - def msg(self): | |
271 | - msg = "EXCEPTION on command "+self.cmd_name | |
272 | - return msg if not self._msg else msg+': '+self._msg | |
273 | - # Default message if print exception | |
274 | - def __str__(self): | |
275 | - return self.msg | |
276 | - ''' | |
277 | - msg = "EXCEPTION on command "+self.cmd_name | |
278 | - return msg if not self.msg else msg+': '+self.msg | |
279 | - ''' | |
280 | - ''' | |
281 | - def __str__(self): | |
282 | - return f"The Agent command '{self.cmd.name}' is unknown to the agent" | |
283 | - #return f"({type(self).__name__}): Device Generic command has no implementation in the controller" | |
284 | - ''' | |
285 | - | |
286 | -# --- CMD PENDING (non running) EXCEPTIONS --- | |
287 | - | |
288 | -# @Override | |
289 | -class CmdExceptionUnknown(CmdException): | |
290 | - ''' Raised when a PENDING (non running) Agent (specific) cmd is NOT known by the agent ''' | |
291 | - # @Override | |
292 | - def __init__( self, cmd, msg:str=None): | |
293 | - super().__init__(cmd, msg if msg else "Unknown command") | |
294 | - #def __str__(self): return self.msg if self.msg else f"The Agent command '{self.cmd_name}' is unknown to the agent" | |
295 | - | |
296 | -# @Override | |
297 | -class CmdExceptionUnimplemented(CmdException): | |
298 | - ''' Raised when a PENDING (non running) Agent Specific cmd is known by the agent but not implemented ''' | |
299 | - # @Override | |
300 | - def __init__( self, cmd, msg:str=None): | |
301 | - super().__init__(cmd, msg if msg else "Command is known by the agent but not implemented") | |
302 | - #def __str__(self): return f"The Agent command '{self.cmd_name}' is known by the agent but not implemented" | |
303 | - | |
304 | -# @Override | |
305 | -class CmdExceptionBadArgs(CmdException): | |
306 | - ''' Raised when a PENDING (non running) Agent cmd has bad, missing, or too many argument(s) ''' | |
307 | - # @Override | |
308 | - def __init__( self, cmd, msg:str=None): | |
309 | - super().__init__(cmd, msg if msg else "Command has bad, missing, or too many argument(s)") | |
310 | - #def __str__(self): return f"The Agent command '{self.cmd_name}' has bad, missing, or too many argument(s)" | |
311 | - | |
312 | - | |
313 | -# --- CMD RUNNING EXCEPTIONS --- | |
314 | - | |
315 | -# @Override | |
316 | -class CmdExceptionExecError(CmdException): | |
317 | - ''' Raised when a RUNNING Agent cmd has had a running error ''' | |
318 | - # @Override | |
319 | - def __init__( self, cmd, msg:str=None): | |
320 | - super().__init__(cmd, msg if msg else "Error during Execution") | |
321 | - #def __str__(self): return f"The running Agent command '{self.cmd_name}' has had an error (during execution)" | |
322 | - | |
323 | -# @Override | |
324 | -class CmdExceptionExecTimeout(CmdException): | |
325 | - ''' Raised when a RUNNING Agent cmd is timeout ''' | |
326 | - # @Override | |
327 | - def __init__( self, cmd, msg:str=None): | |
328 | - super().__init__(cmd, msg if msg else "Execution is TIMEOUT") | |
329 | - #def __str__(self): return f"The running Agent command '{self.cmd_name}' is timeout" | |
330 | - | |
331 | -# @Override | |
332 | -class CmdExceptionExecKilled(CmdException): | |
333 | - ''' Raised when a RUNNING Agent cmd has been aborted (by another agent) ''' | |
334 | - # @Override | |
335 | - def __init__( self, cmd, msg:str=None): | |
336 | - super().__init__(cmd, msg if msg else "Command was KILLED during Execution (by another agent") | |
337 | - #def __str__(self): return f"The running Agent command '{self.cmd_name}' has been killed (by another agent)" | |
338 | - | |
339 | -### | |
340 | -# ================================================================= | |
341 | 266 | # class Agent |
342 | 267 | # ================================================================= |
343 | 268 | ### | ... | ... |
src/core/pyros_django/agent/AgentBasic.py
... | ... | @@ -11,7 +11,8 @@ import sys |
11 | 11 | ###from agent.Agent import Agent, build_agent |
12 | 12 | sys.path.append("../../../..") |
13 | 13 | #from src.core.pyros_django.common.models import AgentCmd |
14 | -from src.core.pyros_django.agent.Agent import Agent, CmdExceptionExecError, build_agent | |
14 | +from src.core.pyros_django.agent.Agent import Agent, build_agent | |
15 | +#from src.core.pyros_django.common.models import AgentCmd | |
15 | 16 | |
16 | 17 | from typing import List, Tuple, Union, Any |
17 | 18 | ... | ... |
src/core/pyros_django/common/models.py
... | ... | @@ -463,6 +463,92 @@ class AgentCmd(models.Model): |
463 | 463 | See doc/models_Command_state_diag.pu for PlantUML state diagram |
464 | 464 | """ |
465 | 465 | |
466 | + | |
467 | + ### | |
468 | + # ================================================================= | |
469 | + # EXCEPTIONS classes | |
470 | + # ================================================================= | |
471 | + ### | |
472 | + | |
473 | + class CmdException(Exception): | |
474 | + ''' Base class for all Agent command exceptions ''' | |
475 | + # pass | |
476 | + def __init__( self, cmd:Union[AgentCmd,str], msg:str=None): | |
477 | + self.cmd = cmd | |
478 | + self._msg = msg | |
479 | + self.cmd_name = cmd if isinstance(cmd,str) else cmd.name | |
480 | + @property | |
481 | + def msg(self): | |
482 | + msg = "EXCEPTION on command "+self.cmd_name | |
483 | + return msg if not self._msg else msg+': '+self._msg | |
484 | + # Default message if print exception | |
485 | + def __str__(self): | |
486 | + return self.msg | |
487 | + ''' | |
488 | + msg = "EXCEPTION on command "+self.cmd_name | |
489 | + return msg if not self.msg else msg+': '+self.msg | |
490 | + ''' | |
491 | + ''' | |
492 | + def __str__(self): | |
493 | + return f"The Agent command '{self.cmd.name}' is unknown to the agent" | |
494 | + #return f"({type(self).__name__}): Device Generic command has no implementation in the controller" | |
495 | + ''' | |
496 | + | |
497 | + # --- CMD PENDING (non running) EXCEPTIONS --- | |
498 | + | |
499 | + # @Override | |
500 | + class CmdExceptionUnknown(CmdException): | |
501 | + ''' Raised when a PENDING (non running) Agent (specific) cmd is NOT known by the agent ''' | |
502 | + # @Override | |
503 | + def __init__( self, cmd, msg:str=None): | |
504 | + super().__init__(cmd, msg if msg else "Unknown command") | |
505 | + #def __str__(self): return self.msg if self.msg else f"The Agent command '{self.cmd_name}' is unknown to the agent" | |
506 | + | |
507 | + # @Override | |
508 | + class CmdExceptionUnimplemented(CmdException): | |
509 | + ''' Raised when a PENDING (non running) Agent Specific cmd is known by the agent but not implemented ''' | |
510 | + # @Override | |
511 | + def __init__( self, cmd, msg:str=None): | |
512 | + super().__init__(cmd, msg if msg else "Command is known by the agent but not implemented") | |
513 | + #def __str__(self): return f"The Agent command '{self.cmd_name}' is known by the agent but not implemented" | |
514 | + | |
515 | + # @Override | |
516 | + class CmdExceptionBadArgs(CmdException): | |
517 | + ''' Raised when a PENDING (non running) Agent cmd has bad, missing, or too many argument(s) ''' | |
518 | + # @Override | |
519 | + def __init__( self, cmd, msg:str=None): | |
520 | + super().__init__(cmd, msg if msg else "Command has bad, missing, or too many argument(s)") | |
521 | + #def __str__(self): return f"The Agent command '{self.cmd_name}' has bad, missing, or too many argument(s)" | |
522 | + | |
523 | + | |
524 | + # --- CMD RUNNING EXCEPTIONS --- | |
525 | + | |
526 | + # @Override | |
527 | + class CmdExceptionExecError(CmdException): | |
528 | + ''' Raised when a RUNNING Agent cmd has had a running error ''' | |
529 | + # @Override | |
530 | + def __init__( self, cmd, msg:str=None): | |
531 | + super().__init__(cmd, msg if msg else "Error during Execution") | |
532 | + #def __str__(self): return f"The running Agent command '{self.cmd_name}' has had an error (during execution)" | |
533 | + | |
534 | + # @Override | |
535 | + class CmdExceptionExecTimeout(CmdException): | |
536 | + ''' Raised when a RUNNING Agent cmd is timeout ''' | |
537 | + # @Override | |
538 | + def __init__( self, cmd, msg:str=None): | |
539 | + super().__init__(cmd, msg if msg else "Execution is TIMEOUT") | |
540 | + #def __str__(self): return f"The running Agent command '{self.cmd_name}' is timeout" | |
541 | + | |
542 | + # @Override | |
543 | + class CmdExceptionExecKilled(CmdException): | |
544 | + ''' Raised when a RUNNING Agent cmd has been aborted (by another agent) ''' | |
545 | + # @Override | |
546 | + def __init__( self, cmd, msg:str=None): | |
547 | + super().__init__(cmd, msg if msg else "Command was KILLED during Execution (by another agent") | |
548 | + #def __str__(self): return f"The running Agent command '{self.cmd_name}' has been killed (by another agent)" | |
549 | + | |
550 | + | |
551 | + | |
466 | 552 | # -------------- Command CONSTANTS -------------- |
467 | 553 | |
468 | 554 | # Command status codes | ... | ... |