Commit 6fbe2e20642c352105436bea574befbfaf308081
1 parent
69be5e68
Exists in
dev
last minute.com modif de Agent : nombreuses petites ameliorations et petits bugfixes
Showing
5 changed files
with
173 additions
and
108 deletions
Show diff stats
privatedev/config/tnc/computer_XYZ_EP.yml
pyros.py
... | ... | @@ -56,31 +56,31 @@ _previous_dir = None |
56 | 56 | # List of all agents that pyros can start, with this format : |
57 | 57 | # agent-name : agent-folder-name |
58 | 58 | AGENTS = { |
59 | - "agentM": "monitoring", | |
60 | - "agentSP": "scientific_programs", | |
61 | - "agentScheduler": "scheduler", | |
62 | - "agentImagesProcessor": "observation_manager", | |
63 | - "agentSST": "agent", | |
64 | - "agent": "agent", | |
65 | - "agent2": "agent", | |
66 | - "agentX": "agent", | |
67 | - "agentA": "agent", | |
68 | - "agentB": "agent", | |
69 | - "agentC": "agent", | |
59 | + "AgentM": "monitoring", | |
60 | + "AgentSP": "scientific_programs", | |
61 | + "AgentScheduler": "scheduler", | |
62 | + "AgentImagesProcessor": "observation_manager", | |
63 | + "AgentSST": "agent", | |
64 | + "Agent": "agent", | |
65 | + "Agent2": "agent", | |
66 | + "AgentX": "agent", | |
67 | + "AgentA": "agent", | |
68 | + "AgentB": "agent", | |
69 | + "AgentC": "agent", | |
70 | 70 | # "agentDevice" : "AgentDevice", |
71 | 71 | # "agentDeviceTelescopeGemini" : "AgentDeviceTelescopeGemini", |
72 | - "agentDeviceGemini": "AgentDeviceGemini", | |
73 | - "agentDeviceSBIG": "AgentDeviceSBIG", | |
74 | - "agentTelescopeRequester": "AgentTelescopeRequester", | |
75 | - "agentMultiRequester": "AgentMultiRequester", | |
72 | + "AgentDeviceGemini": "AgentDeviceGemini", | |
73 | + "AgentDeviceSBIG": "AgentDeviceSBIG", | |
74 | + "AgentTelescopeRequester": "AgentTelescopeRequester", | |
75 | + "AgentMultiRequester": "AgentMultiRequester", | |
76 | 76 | "webserver": "webserver", |
77 | 77 | "monitoring": "monitoring", |
78 | 78 | "majordome": "majordome", |
79 | 79 | #"scheduler": "scheduler", |
80 | 80 | "alert_manager": "alert_manager", |
81 | - "agentImagesProcessor_tnc_up1": "../../../privatedev/plugin/agent", | |
81 | + "AgentImagesProcessor_tnc_up1": "../../../privatedev/plugin/agent", | |
82 | 82 | "agentBasic": "agent", |
83 | - "agentTriton": "agent", | |
83 | + "AgentTriton": "agent", | |
84 | 84 | } |
85 | 85 | # AGENTS = ["agentX", "webserver", "monitoring", "majordome", "scheduler", "alert_manager"] |
86 | 86 | # AGENTS = ["all", "webserver", "monitoring", "majordome", "scheduler", "alert"] | ... | ... |
src/core/pyros_django/agent/Agent.py
... | ... | @@ -420,12 +420,12 @@ class Agent: |
420 | 420 | # ------------------------------- |
421 | 421 | |
422 | 422 | # This command has a validity of 0s and thus should be tagged as "expired" |
423 | - ("self set_mode ATTENTIVE", 0, "MODE = ATTENTIVE", CMD_STATUS.CMD_EXPIRED), | |
423 | + ("self set_mode ATTENTIVE", 0, "MODE is ATTENTIVE", CMD_STATUS.CMD_EXPIRED), | |
424 | 424 | |
425 | 425 | # Agent general command |
426 | - ("self set_mode ATTENTIVE", 200, "MODE = ATTENTIVE", CMD_STATUS.CMD_EXECUTED), | |
426 | + ("self set_mode ATTENTIVE", 200, "MODE is ATTENTIVE", CMD_STATUS.CMD_EXECUTED), | |
427 | 427 | # => should get "ATTENTIVE" |
428 | - ("self get_mode", 100, "MODE = ATTENTIVE", None), | |
428 | + ("self get_mode", 100, "MODE is ATTENTIVE", None), | |
429 | 429 | |
430 | 430 | # => should get "7" |
431 | 431 | ("self do_eval 3+5-1", 200, '7', None), |
... | ... | @@ -439,17 +439,17 @@ class Agent: |
439 | 439 | ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, '15.5', None), |
440 | 440 | |
441 | 441 | |
442 | - ("self set_mode ROUTINE", 200, "MODE = ROUTINE", None), | |
442 | + ("self set_mode ROUTINE", 200, "MODE is ROUTINE", None), | |
443 | 443 | # => should get "ROUTINE" |
444 | - ("self get_mode", 200, "MODE = ROUTINE", None), | |
444 | + ("self get_mode", 200, "MODE is ROUTINE", None), | |
445 | 445 | # Agent specific command => should be skipped (because not ATTENTIVE) |
446 | 446 | ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, "SKIPPED", None), |
447 | 447 | |
448 | 448 | # From now on, should not run anymore process_before/after |
449 | 449 | # => and should skip next specific commands |
450 | - ("self set_mode IDLE", 200, "MODE = IDLE", None), | |
450 | + ("self set_mode IDLE", 200, "MODE is IDLE", None), | |
451 | 451 | # => should get "IDLE" |
452 | - ("self get_mode", 200, "MODE = IDLE", None), | |
452 | + ("self get_mode", 200, "MODE is IDLE", None), | |
453 | 453 | # Agent specific command => should be skipped (because not ATTENTIVE) |
454 | 454 | ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, 'SKIPPED', None), |
455 | 455 | |
... | ... | @@ -537,34 +537,38 @@ class Agent: |
537 | 537 | #COMMANDS_PEREMPTION_HOURS = 48 |
538 | 538 | #COMMANDS_PEREMPTION_HOURS = 60/60 |
539 | 539 | |
540 | - name = "Generic Agent" | |
541 | - status = None | |
542 | - mode = None | |
540 | + ##name = "Generic Agent" | |
541 | + ##status = None | |
542 | + ##mode = None | |
543 | 543 | config = None |
544 | 544 | |
545 | + # MODE | |
546 | + #MODES = AgentSurvey.MODE_IDLE | |
547 | + # (('IDLE', 'IDLE'), ('ROUTINE', 'ROUTINE'), ('ATTENTIVE', 'ATTENTIVE')) | |
548 | + ''' | |
549 | + MODE_IDLE = "IDLE" | |
550 | + MODE_ROUTINE = "ROUTINE" | |
551 | + MODE_ATTENTIVE = "ATTENTIVE" | |
552 | + ''' | |
553 | + | |
545 | 554 | # STATUS |
555 | + #STATUSES = AgentSurvey.STATUS_CHOICES | |
556 | + # (('LAUNCHED', 'LAUNCHED'), ('INITIALIZING', 'INITIALIZING'), ('IN_MAIN_LOOP', 'IN_MAIN_LOOP'), | |
557 | + # ('IN_ROUTINE_BEFORE_PROCESS', 'IN_ROUTINE_BEFORE_PROCESS'), ('IN_GET_NEXT_COMMAND', 'IN_GET_NEXT_COMMAND'), | |
558 | + # ('IN_ROUTINE_AFTER_PROCESS', 'IN_ROUTINE_AFTER_PROCESS'), ('EXITING', 'EXITING') | |
559 | + ''' | |
546 | 560 | STATUS_LAUNCH = "LAUNCHED" |
547 | 561 | STATUS_INIT = "INITIALIZING" |
548 | 562 | STATUS_MAIN_LOOP = "IN_MAIN_LOOP" |
563 | + STATUS_ROUTINE_BEFORE_PROCESS = "IN_ROUTINE_BEFORE_PROCESS" | |
549 | 564 | STATUS_GET_NEXT_COMMAND = "IN_GET_NEXT_COMMAND" |
550 | - STATUS_GENERAL_PROCESS = "IN_GENERAL_PROCESS" | |
551 | - STATUS_ROUTINE_PROCESS = "IN_ROUTINE_PROCESS" | |
565 | + #STATUS_GENERAL_PROCESS = "IN_GENERAL_PROCESS" | |
566 | + STATUS_ROUTINE_AFTER_PROCESS = "IN_ROUTINE_AFTER_PROCESS" | |
552 | 567 | ###STATUS_SPECIFIC_PROCESS = "IN_SPECIFIC_PROCESS" |
553 | 568 | STATUS_EXIT = "EXITING" |
569 | + ''' | |
554 | 570 | |
555 | 571 | |
556 | - # MODE | |
557 | - # | |
558 | - # In all modes, the Agent listens to commands sent to him and executes Agent level GENERAL ones. | |
559 | - # - MODE_IDLE : "idle" mode, does nothing, only executes Agent level GENERAL commands (DO_RESTART, DO_EXIT, DO_ABORT, DO_FLUSH, SET_ACTIVE, ...) | |
560 | - # - MODE_ROUTINE : idem IDLE + executes routine process (before & after) | |
561 | - # - MODE_ATTENTIVE : idem ROUTINE + executes Agent level SPECIFIC commands (commands specific to this agent, that only this agent understands and can execute) | |
562 | - # | |
563 | - # Default mode is MODE_ATTENTIVE (most active mode) | |
564 | - MODE_IDLE = "IDLE" | |
565 | - MODE_ROUTINE = "ROUTINE" | |
566 | - MODE_ATTENTIVE = "ATTENTIVE" | |
567 | - | |
568 | 572 | ''' Moved to more central file : config.config_base |
569 | 573 | PYROS_DJANGO_BASE_DIR = Path("src/core/pyros_django") # pathlib |
570 | 574 | DEFAULT_CONFIG_FILE_NAME = "config_unit_simulunit1.xml" |
... | ... | @@ -608,8 +612,22 @@ class Agent: |
608 | 612 | # new obsconfig init for agent: |
609 | 613 | ##def __init__(self, RUN_IN_THREAD=True): |
610 | 614 | def __init__(self): |
615 | + | |
616 | + # Declaration of Instance attributes, default values | |
617 | + self.name = "Generic Agent" | |
618 | + self.status = None | |
619 | + self.mode = None | |
620 | + self.unit = None | |
621 | + self.TEST_COMMANDS = None | |
622 | + | |
623 | + #print(AgentSurvey.MODE_IDLE) | |
624 | + #sys.exit() | |
625 | + | |
611 | 626 | # Agent is by default in mode ATTENTIVE (most active mode) |
612 | - self.mode = self.MODE_ATTENTIVE | |
627 | + #self.mode = self.MODE_ATTENTIVE | |
628 | + self._set_mode_attentive() | |
629 | + #self._set_mode(MODES.) | |
630 | + | |
613 | 631 | log.addHandler(handler_filebyagent(logging.INFO, self.__class__.__name__)) |
614 | 632 | log.debug("start Agent init") |
615 | 633 | obs_config_file_path = os.environ["PATH_TO_OBSCONF_FILE"] |
... | ... | @@ -637,7 +655,7 @@ class Agent: |
637 | 655 | |
638 | 656 | self.TEST_COMMANDS = iter(self.TEST_COMMANDS_LIST) |
639 | 657 | ##self.RUN_IN_THREAD = RUN_IN_THREAD |
640 | - self._set_status(self.STATUS_LAUNCH) | |
658 | + self._set_status(AgentSurvey.STATUS_LAUNCH) | |
641 | 659 | ####self._set_idle() |
642 | 660 | |
643 | 661 | # Create 1st survey if none |
... | ... | @@ -651,8 +669,10 @@ class Agent: |
651 | 669 | self._agent_survey = AgentSurvey.objects.create( |
652 | 670 | name=self.name, |
653 | 671 | validity_duration=60, |
654 | - mode=self.mode, | |
655 | - status=self.status, | |
672 | + #mode=self.mode, | |
673 | + mode = self.get_mode(), | |
674 | + #status=self.status, | |
675 | + status=self.get_status(), | |
656 | 676 | iteration=-1 |
657 | 677 | ) |
658 | 678 | log.debug("Agent survey is" + str(self._agent_survey)) |
... | ... | @@ -1105,9 +1125,9 @@ class Agent: |
1105 | 1125 | |
1106 | 1126 | for i in range(3): print() |
1107 | 1127 | #self.printd("-"*80) |
1108 | - log.info("*"*73) | |
1109 | - log.info("*"*20 + f" MAIN LOOP ITERATION {self._iter_num} (START) " + "*"*20) | |
1110 | - log.info("*"*73 + '\n') | |
1128 | + log.info("*"*90) | |
1129 | + log.info("*"*20 + f" {self.name} : MAIN LOOP ITERATION {self._iter_num} (START) " + "*"*20) | |
1130 | + log.info("*"*90 + '\n') | |
1111 | 1131 | #self.print(f"Iteration {self._iter_num}") |
1112 | 1132 | |
1113 | 1133 | # EXIT because of nb of iterations ? |
... | ... | @@ -1137,7 +1157,7 @@ class Agent: |
1137 | 1157 | self.DO_MAIN_LOOP = False |
1138 | 1158 | return |
1139 | 1159 | |
1140 | - self._set_status(self.STATUS_MAIN_LOOP) | |
1160 | + self._set_status(AgentSurvey.STATUS_MAIN_LOOP) | |
1141 | 1161 | self.show_mode_and_status() |
1142 | 1162 | |
1143 | 1163 | self.main_loop_start() |
... | ... | @@ -1236,6 +1256,7 @@ class Agent: |
1236 | 1256 | # cmd.args => ['arg1','arg2',...] |
1237 | 1257 | #print("nom", cmd.name) |
1238 | 1258 | if cmd.name=="do_stop": |
1259 | + # by default = "asap" | |
1239 | 1260 | if cmd.args is None: cmd.full_name = "do_exit" |
1240 | 1261 | else: |
1241 | 1262 | arg = cmd.args[0] |
... | ... | @@ -1246,12 +1267,18 @@ class Agent: |
1246 | 1267 | #print(self.get_specific_cmds()) |
1247 | 1268 | #exit(0) |
1248 | 1269 | if cmd.name in ('do_restart_loop','do_exit','do_abort') : |
1270 | + #print(cmd) | |
1249 | 1271 | self.DO_MAIN_LOOP = False |
1250 | 1272 | if cmd.name == 'do_abort': |
1251 | 1273 | self._abort_current_running_cmd_if_exists() |
1252 | 1274 | self._cleanup_before_exit() |
1253 | 1275 | if cmd.name != 'do_restart_loop': |
1254 | 1276 | self.DO_RESTART_LOOP = False |
1277 | + self._set_status(AgentSurvey.STATUS_EXIT) | |
1278 | + # log last agent mode & status | |
1279 | + self._log_agent_state() | |
1280 | + #cmd.set_result('EXITING') | |
1281 | + | |
1255 | 1282 | return cmd |
1256 | 1283 | |
1257 | 1284 | # CASE 2 - AGENT SPECIFIC command |
... | ... | @@ -1308,7 +1335,7 @@ class Agent: |
1308 | 1335 | |
1309 | 1336 | def _cleanup_before_exit(self, stopper_agent_name:str=None): |
1310 | 1337 | if not stopper_agent_name: stopper_agent_name = self.name |
1311 | - self._set_status(self.STATUS_EXIT) | |
1338 | + #self._set_status(self.STATUS_EXIT) | |
1312 | 1339 | self._log_agent_state() |
1313 | 1340 | |
1314 | 1341 | log.info("Trying to stop cleanly") |
... | ... | @@ -1355,7 +1382,7 @@ class Agent: |
1355 | 1382 | print() |
1356 | 1383 | log.info("*"*10+ " ROUTINE PROCESSING BEFORE (START) "+ "*"*10+ '\n') |
1357 | 1384 | |
1358 | - self._set_status(self.STATUS_ROUTINE_PROCESS) | |
1385 | + self._set_status(AgentSurvey.STATUS_ROUTINE_BEFORE_PROCESS) | |
1359 | 1386 | self.routine_process_before_body() |
1360 | 1387 | print() |
1361 | 1388 | log.info("*"*10 + " ROUTINE PROCESSING BEFORE (END) "+ "*"*10) |
... | ... | @@ -1376,7 +1403,7 @@ class Agent: |
1376 | 1403 | print() |
1377 | 1404 | log.info("*"*10+ " ROUTINE PROCESSING AFTER (START) "+ "*"*10+ '\n') |
1378 | 1405 | |
1379 | - self._set_status(self.STATUS_ROUTINE_PROCESS) | |
1406 | + self._set_status(AgentSurvey.STATUS_ROUTINE_AFTER_PROCESS) | |
1380 | 1407 | self.routine_process_after_body() |
1381 | 1408 | print() |
1382 | 1409 | log.info("*"*10 + " ROUTINE PROCESSING AFTER (END) "+ "*"*10) |
... | ... | @@ -1470,7 +1497,8 @@ class Agent: |
1470 | 1497 | # |
1471 | 1498 | |
1472 | 1499 | def show_current_mode_and_status(self): |
1473 | - log.info(f"CURRENT MODE is {self.mode} (status is {self.status})") | |
1500 | + #log.info(f"CURRENT MODE is {self.mode} (status is {self.status})") | |
1501 | + log.info(f"CURRENT MODE is {self.get_mode()} (status is {self.get_status()})") | |
1474 | 1502 | # @deprecated |
1475 | 1503 | def show_mode_and_status(self): |
1476 | 1504 | self.show_current_mode_and_status() |
... | ... | @@ -1479,36 +1507,30 @@ class Agent: |
1479 | 1507 | # - STATUS MANAGEMENT |
1480 | 1508 | # |
1481 | 1509 | |
1482 | - def get_current_status(self): | |
1510 | + def get_status(self): | |
1483 | 1511 | return self.status |
1484 | 1512 | # @deprecated |
1485 | 1513 | def get_state(self): |
1486 | - return self.get_current_status() | |
1514 | + return self.get_status() | |
1487 | 1515 | |
1488 | - def _set_current_status(self, status:str): | |
1516 | + def _set_status(self, status:str): | |
1489 | 1517 | #self.printd(f"[{status}] (switching from status {self.status})") |
1490 | 1518 | log.debug(f"[{status}]") |
1491 | 1519 | self.status = status |
1492 | 1520 | return False |
1493 | - # @deprecated | |
1494 | - def _set_status(self, status:str): | |
1495 | - self._set_current_status(status) | |
1496 | 1521 | |
1497 | 1522 | |
1498 | 1523 | # |
1499 | 1524 | # - MODE MANAGEMENT |
1500 | 1525 | # |
1501 | 1526 | |
1502 | - def get_current_mode(self): | |
1503 | - return self.mode | |
1504 | - # @deprecated | |
1505 | 1527 | def get_mode(self): |
1506 | - return self.get_current_mode() | |
1528 | + return self.mode | |
1507 | 1529 | |
1508 | 1530 | # Test mode |
1509 | - def IS_MODE_IDLE(self): return self.mode == self.MODE_IDLE | |
1510 | - def IS_MODE_ROUTINE(self): return self.mode == self.MODE_ROUTINE | |
1511 | - def IS_MODE_ATTENTIVE(self): return self.mode == self.MODE_ATTENTIVE | |
1531 | + def IS_MODE_IDLE(self): return self.get_mode() == AgentSurvey.MODE_IDLE | |
1532 | + def IS_MODE_ROUTINE(self): return self.get_mode() == AgentSurvey.MODE_ROUTINE | |
1533 | + def IS_MODE_ATTENTIVE(self): return self.get_mode() == AgentSurvey.MODE_ATTENTIVE | |
1512 | 1534 | # @deprecated |
1513 | 1535 | def IS_IDLE(self): return self.IS_MODE_IDLE() |
1514 | 1536 | # @deprecated |
... | ... | @@ -1516,35 +1538,33 @@ class Agent: |
1516 | 1538 | # @deprecated |
1517 | 1539 | def IS_ATTENTIVE(self): return self.IS_MODE_ATTENTIVE() |
1518 | 1540 | |
1519 | - def _set_current_mode(self, mode:str): | |
1541 | + def _set_mode(self, mode:str): | |
1520 | 1542 | #self.printd(f"Switching from mode {self.mode} to mode {mode}") |
1521 | 1543 | log.info(f"[NEW MODE {mode}]") |
1522 | 1544 | self.mode = mode |
1523 | - # @deprecated | |
1524 | - def _set_mode(self, mode:str): | |
1525 | - self._set_current_mode(mode) | |
1526 | 1545 | |
1527 | 1546 | def _set_mode_idle(self): |
1528 | - self._set_mode(self.MODE_IDLE) | |
1547 | + self._set_mode(AgentSurvey.MODE_IDLE) | |
1529 | 1548 | # @deprecated |
1530 | 1549 | def set_idle(self): |
1531 | 1550 | self._set_mode_idle() |
1532 | 1551 | |
1533 | 1552 | def _set_mode_routine(self): |
1534 | - self._set_current_mode(self.MODE_ROUTINE) | |
1553 | + self._set_mode(AgentSurvey.MODE_ROUTINE) | |
1535 | 1554 | # @deprecated |
1536 | 1555 | def set_routine(self): |
1537 | 1556 | self._set_mode_routine() |
1538 | 1557 | |
1539 | 1558 | def _set_mode_attentive(self): |
1540 | - self._set_current_mode(self.MODE_ATTENTIVE) | |
1559 | + self._set_mode(AgentSurvey.MODE_ATTENTIVE) | |
1541 | 1560 | # @deprecated |
1542 | 1561 | def set_attentive(self): |
1543 | - self._set_mode_attentive | |
1544 | - | |
1562 | + self._set_mode_attentive() | |
1545 | 1563 | |
1564 | + ''' | |
1546 | 1565 | def die(self): |
1547 | - self._set_status(self.STATUS_EXIT) | |
1566 | + self._set_status(AgentSurvey.STATUS_EXIT) | |
1567 | + ''' | |
1548 | 1568 | |
1549 | 1569 | """ |
1550 | 1570 | suspend/resume |
... | ... | @@ -1582,8 +1602,8 @@ class Agent: |
1582 | 1602 | # all agent are active ? |
1583 | 1603 | |
1584 | 1604 | #mode = self.MODE_ACTIVE |
1585 | - mode = self.MODE_ATTENTIVE | |
1586 | - self._set_mode(mode) | |
1605 | + #mode = self.MODE_ATTENTIVE | |
1606 | + self._set_mode_attentive() | |
1587 | 1607 | return True |
1588 | 1608 | # old config |
1589 | 1609 | # def _set_mode_from_config(self, agent_name): |
... | ... | @@ -1614,7 +1634,7 @@ class Agent: |
1614 | 1634 | def init(self): |
1615 | 1635 | #log.debug("*** Initializing... ***") |
1616 | 1636 | log.info("*** INITIALIZING... ***") |
1617 | - self._set_status(self.STATUS_INIT) | |
1637 | + self._set_status(AgentSurvey.STATUS_INIT) | |
1618 | 1638 | if self.TEST_MODE: self.set_delay(2) |
1619 | 1639 | |
1620 | 1640 | |
... | ... | @@ -1732,8 +1752,8 @@ class Agent: |
1732 | 1752 | # only necessary when using process (not necessary with threads) |
1733 | 1753 | #with transaction.atomic(): |
1734 | 1754 | #self._agent_survey = AgentSurvey.objects.get(name=self.name) |
1735 | - self._agent_survey.mode = self.mode | |
1736 | - self._agent_survey.status = self.status | |
1755 | + self._agent_survey.mode = self.get_mode() | |
1756 | + self._agent_survey.status = self.get_status() | |
1737 | 1757 | self._agent_survey.iteration = self._iter_num |
1738 | 1758 | self._agent_survey.save() |
1739 | 1759 | #self._agent_survey.save(update_fields=["mode", "status"]) |
... | ... | @@ -1795,7 +1815,7 @@ class Agent: |
1795 | 1815 | which is relevant to this agent. |
1796 | 1816 | Commands are read in chronological order |
1797 | 1817 | """ |
1798 | - self._set_status(self.STATUS_GET_NEXT_COMMAND) | |
1818 | + self._set_status(AgentSurvey.STATUS_GET_NEXT_COMMAND) | |
1799 | 1819 | log.info("Looking for a new command to process (sent by another agent):") |
1800 | 1820 | |
1801 | 1821 | # 1) Get all pending commands for me (return if None) |
... | ... | @@ -1998,7 +2018,7 @@ class Agent: |
1998 | 2018 | result = None |
1999 | 2019 | |
2000 | 2020 | #if cmd_name in ("do_abort", "do_exit", "do_restart_init"): |
2001 | - if cmd_name in ("do_abort", "do_exit", "do_restart_loop"): | |
2021 | + if cmd_name in ("do_stop", "do_abort", "do_exit", "do_restart_loop"): | |
2002 | 2022 | #self.printd("Current pending commands are:") |
2003 | 2023 | #Command.show_commands(self._pending_commands) |
2004 | 2024 | log.info("Stopping/Aborting current executing command if exists:") |
... | ... | @@ -2018,7 +2038,7 @@ class Agent: |
2018 | 2038 | result = "I am now " + self.get_state() |
2019 | 2039 | |
2020 | 2040 | elif cmd_name == "get_mode": |
2021 | - result = "MODE = " + self.get_mode() | |
2041 | + result = "MODE is " + self.get_mode() | |
2022 | 2042 | |
2023 | 2043 | elif cmd_name == "set_mode": |
2024 | 2044 | #if not cmd_args: raise ValueError() |
... | ... | @@ -2029,7 +2049,7 @@ class Agent: |
2029 | 2049 | elif mode == "ATTENTIVE": self.set_attentive() |
2030 | 2050 | else: raise AgentCmdBadArgsException(cmd) |
2031 | 2051 | #cmd.set_result("I am now " + state) |
2032 | - result = "MODE = " + mode | |
2052 | + result = "MODE is " + mode | |
2033 | 2053 | #time.sleep(1) |
2034 | 2054 | #self.waitfor(1) |
2035 | 2055 | |
... | ... | @@ -2271,9 +2291,9 @@ class Agent: |
2271 | 2291 | def do_stop(self, when:str): |
2272 | 2292 | # PRIO |
2273 | 2293 | if when == "asap": |
2274 | - pass | |
2294 | + self.do_exit() | |
2275 | 2295 | if when == "now": |
2276 | - pass | |
2296 | + self.do_abort() | |
2277 | 2297 | # NOT PRIO |
2278 | 2298 | if when == "noprio": |
2279 | 2299 | pass |
... | ... | @@ -2439,7 +2459,7 @@ class Agent: |
2439 | 2459 | #assert(cmd.state == self._cmdts.expected_status) |
2440 | 2460 | actual=cmd.state |
2441 | 2461 | expected=self._cmdts.expected_status |
2442 | - assert actual==expected, f"Cmd result (='{actual}') is not as expected (='{expected}')" | |
2462 | + assert actual==expected, f"Cmd status (='{actual}') is not as expected (='{expected}')" | |
2443 | 2463 | |
2444 | 2464 | |
2445 | 2465 | def _TEST_test_routine_process(self): | ... | ... |
src/core/pyros_django/agent/AgentBasic.py
... | ... | @@ -5,9 +5,10 @@ import sys |
5 | 5 | ##import utils.Logger as L |
6 | 6 | |
7 | 7 | ##from .Agent import Agent |
8 | -sys.path.append("..") | |
9 | -from agent.Agent import Agent, build_agent | |
10 | - | |
8 | +##sys.path.append("..") | |
9 | +###from agent.Agent import Agent, build_agent | |
10 | +sys.path.append("../../../..") | |
11 | +from src.core.pyros_django.agent.Agent import Agent, build_agent | |
11 | 12 | |
12 | 13 | ##log = L.setupLogger("AgentXTaskLogger", "AgentX") |
13 | 14 | |
... | ... | @@ -31,7 +32,7 @@ class AgentBasic(Agent): |
31 | 32 | TEST_COMMANDS_LIST = [ |
32 | 33 | |
33 | 34 | # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status), |
34 | - ("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), | |
35 | + #("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), | |
35 | 36 | ("self do_specific1 2 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, '16.5', None), |
36 | 37 | |
37 | 38 | |
... | ... | @@ -57,11 +58,17 @@ class AgentBasic(Agent): |
57 | 58 | # ------------------------------- |
58 | 59 | |
59 | 60 | # This command has a validity of 0s and thus should be tagged as "expired" |
60 | - ("self set_mode ATTENTIVE", 0, "MODE = ATTENTIVE", Agent.CMD_STATUS.CMD_EXPIRED), | |
61 | + ("self set_mode ATTENTIVE", 0, "MODE is ATTENTIVE", Agent.CMD_STATUS.CMD_EXPIRED), | |
61 | 62 | # ("self set_mode ATTENTIVE", 0, "MODE = ATTENTIVE", AgentCmd.CMD_STATUS_CODES), |
62 | 63 | |
63 | 64 | # Agent general command |
64 | - ("self set_mode ATTENTIVE", 200, "MODE = ATTENTIVE", Agent.CMD_STATUS.CMD_EXECUTED), | |
65 | + ("self set_mode ROUTINE", 200, "MODE is ROUTINE", Agent.CMD_STATUS.CMD_EXECUTED), | |
66 | + ("self get_mode", 200, "MODE is ROUTINE", Agent.CMD_STATUS.CMD_EXECUTED), | |
67 | + ("self set_mode ATTENTIVE", 200, "MODE is ATTENTIVE", Agent.CMD_STATUS.CMD_EXECUTED), | |
68 | + ("self get_mode", 200, "MODE is ATTENTIVE", Agent.CMD_STATUS.CMD_EXECUTED), | |
69 | + | |
70 | + # End test | |
71 | + ("self do_stop asap", 200, "STOPPING", Agent.CMD_STATUS.CMD_EXECUTED), | |
65 | 72 | ] |
66 | 73 | |
67 | 74 | ... | ... |
src/core/pyros_django/common/models.py
... | ... | @@ -320,32 +320,69 @@ class AgentSurvey(models.Model): |
320 | 320 | | id | name | created | updated | validity_duration (default=1mn) | mode (active/idle) | status (launch/init/loop/exit/...) | |
321 | 321 | """ |
322 | 322 | |
323 | - # Statuses | |
323 | + # --- MODES --- | |
324 | + ''' | |
325 | + In all modes, the Agent listens to commands sent to him and executes Agent level GENERAL ones. | |
326 | + - MODE_IDLE : "idle" mode, does nothing, only executes Agent level GENERAL commands (DO_RESTART, DO_EXIT, DO_ABORT, DO_FLUSH, SET_ACTIVE, ...) | |
327 | + - MODE_ROUTINE : idem IDLE + executes routine process (before & after) | |
328 | + - MODE_ATTENTIVE : idem ROUTINE + executes Agent level SPECIFIC commands (commands specific to this agent, that only this agent understands and can execute) | |
329 | + Default mode is MODE_ATTENTIVE (most active mode) | |
330 | + ''' | |
331 | + #MODE_ACTIVE = "ACTIVE" | |
332 | + MODE_IDLE = "IDLE" | |
333 | + MODE_ROUTINE = "ROUTINE" | |
334 | + MODE_ATTENTIVE = "ATTENTIVE" | |
335 | + ''' | |
336 | + (MODE_ACTIVE, 'Active mode'), | |
337 | + (MODE_IDLE, 'Idle mode'), | |
338 | + ''' | |
339 | + ''' | |
340 | + (MODE_IDLE, 'IDLE'), | |
341 | + (MODE_ROUTINE, 'ROUTINE'), | |
342 | + (MODE_ATTENTIVE, 'ATTENTIVE'), | |
343 | + ''' | |
344 | + MODE_CHOICES = ( | |
345 | + (MODE_IDLE, MODE_IDLE), | |
346 | + (MODE_ROUTINE, MODE_ROUTINE), | |
347 | + (MODE_ATTENTIVE, MODE_ATTENTIVE), | |
348 | + ) | |
349 | + | |
350 | + | |
351 | + # --- STATUSES --- | |
352 | + | |
324 | 353 | #STATUSES = Choices('new', 'verified', 'published') |
325 | 354 | STATUS_LAUNCH = "LAUNCHED" |
326 | 355 | STATUS_INIT = "INITIALIZING" |
327 | 356 | STATUS_MAIN_LOOP = "IN_MAIN_LOOP" |
328 | - STATUS_PROCESS_LOOP = "IN_PROCESS_LOOP" | |
357 | + STATUS_ROUTINE_BEFORE_PROCESS = "IN_ROUTINE_BEF" | |
358 | + STATUS_GET_NEXT_COMMAND = "IN_GET_NEXT_CMD" | |
359 | + STATUS_ROUTINE_AFTER_PROCESS = "IN_ROUTINE_AFT" | |
329 | 360 | STATUS_EXIT = "EXITING" |
330 | 361 | # NEW |
331 | 362 | ##STATUS_RESTART = "RESTARTING" |
332 | - | |
333 | - # Modes | |
334 | - MODE_ACTIVE = "ACTIVE" | |
335 | - MODE_IDLE = "IDLE" | |
336 | - | |
337 | - MODE_CHOICES = ( | |
338 | - (MODE_ACTIVE, 'Active mode'), | |
339 | - (MODE_IDLE, 'Idle mode'), | |
340 | - ) | |
341 | - | |
363 | + #STATUS_GENERAL_PROCESS = "IN_GENERAL_PROCESS" | |
364 | + ###STATUS_SPECIFIC_PROCESS = "IN_SPECIFIC_PROCESS" | |
365 | + ''' | |
342 | 366 | STATUS_CHOICES = ( |
343 | 367 | (STATUS_LAUNCH, "LAUNCHED"), |
344 | 368 | (STATUS_INIT, "INITIALIZING"), |
345 | 369 | (STATUS_MAIN_LOOP, "IN_MAIN_LOOP"), |
346 | - (STATUS_PROCESS_LOOP, "IN_PROCESS_LOOP"), | |
370 | + (STATUS_ROUTINE_BEFORE_PROCESS, "IN_ROUTINE_BEF"), | |
371 | + (STATUS_GET_NEXT_COMMAND, "IN_GET_NEXT_CMD"), | |
372 | + (STATUS_ROUTINE_AFTER_PROCESS, "IN_ROUTINE_AFT"), | |
347 | 373 | (STATUS_EXIT, "EXITING"), |
348 | 374 | ) |
375 | + ''' | |
376 | + STATUS_CHOICES = ( | |
377 | + #(STATUS_LAUNCH, "LAUNCHED"), | |
378 | + (STATUS_LAUNCH, STATUS_LAUNCH), | |
379 | + (STATUS_INIT, STATUS_INIT), | |
380 | + (STATUS_MAIN_LOOP, STATUS_MAIN_LOOP), | |
381 | + (STATUS_ROUTINE_BEFORE_PROCESS, STATUS_ROUTINE_BEFORE_PROCESS), | |
382 | + (STATUS_GET_NEXT_COMMAND, STATUS_GET_NEXT_COMMAND), | |
383 | + (STATUS_ROUTINE_AFTER_PROCESS, STATUS_ROUTINE_AFTER_PROCESS), | |
384 | + (STATUS_EXIT, STATUS_EXIT), | |
385 | + ) | |
349 | 386 | |
350 | 387 | name = models.CharField(max_length=50, unique=True) |
351 | 388 | #name = models.CharField(max_length=50, blank=True, null=True, unique=True) |
... | ... | @@ -369,6 +406,7 @@ class AgentSurvey(models.Model): |
369 | 406 | |
370 | 407 | def __str__(self): |
371 | 408 | return (f"Agent {self.name} at {self.updated} in mode {self.mode} and status {self.status}") |
409 | + | |
372 | 410 | |
373 | 411 | |
374 | 412 | class Album(models.Model): | ... | ... |