Commit 6cd48351eae3d4f9fbf0ece299937b454b83092f

Authored by Etienne Pallier
1 parent b9068dc6
Exists in dev

AgentScheduler is born (just a very modest beginning)

Dockerfile
... ... @@ -3,6 +3,8 @@ FROM ubuntu:20.04
3 3 #FROM ubuntu:latest
4 4 #FROM ubuntu:21.10 # with python3.9
5 5 #FROM ubuntu:18.04
  6 +# Pour eviter le warning : debconf: delaying package configuration, since apt-utils is not installed
  7 +ARG DEBIAN_FRONTEND=noninteractive
6 8  
7 9 # Which glibc version ?
8 10 # ./SHELL
... ...
privatedev/config/tnc/observatory_tnc.yml
... ... @@ -138,7 +138,15 @@ OBSERVATORY:
138 138 device: TAROT_meteo
139 139 protocol: private/plugin/agent_devices/plc_protocol.py
140 140 is_real: False
141   -
  141 +
  142 + - AGENT_DEVICE:
  143 + name: AgentScheduler
  144 + computer: MainComputer
  145 + path: private/plugin/agent_devices
  146 + device: TAROT_meteo
  147 + protocol: private/plugin/agent_devices/plc_protocol.py
  148 + is_real: False
  149 +
142 150 - AGENT_DEVICE:
143 151 name: mount
144 152 computer: MainComputer
... ... @@ -245,6 +253,7 @@ OBSERVATORY:
245 253 computer: MainComputer
246 254 path: ~
247 255  
  256 +
248 257 TOPOLOGY:
249 258  
250 259 SECURITY:
... ...
pyros.py
... ... @@ -52,14 +52,17 @@ _previous_dir = None
52 52  
53 53 AGENTS = {
54 54 # "agentX" : "agent",
  55 + #"agentM": "AgentM",
  56 + #"agentSP": "AgentSP",
  57 + "agentM": "monitoring",
  58 + "agentSP": "scientific_programs",
  59 + "agentScheduler": "scheduler",
55 60 "agent": "Agent",
56 61 "agent2": "Agent",
57 62 "agentX": "AgentX",
58 63 "agentA": "AgentA",
59 64 "agentB": "AgentB",
60 65 "agentC": "AgentC",
61   - "agentM": "AgentM",
62   - "agentSP": "AgentSP",
63 66 # "agentDevice" : "AgentDevice",
64 67 # "agentDeviceTelescopeGemini" : "AgentDeviceTelescopeGemini",
65 68 "agentDeviceGemini": "AgentDeviceGemini",
... ... @@ -908,12 +911,19 @@ def start(agent: str, configfile: str, observatory: str, unit: str):
908 911 elif agent_name.startswith("agent"):
909 912 # Run agent without actual commands sent to devices (FOR_REAL=False)
910 913 # agentX.run(FOR_REAL=True)
  914 + '''
911 915 if agent_name == "agentM":
912 916 os.chdir(PYROS_DJANGO_BASE_DIR+"/monitoring/")
913 917 elif agent_name == "agentSP":
914 918 os.chdir(PYROS_DJANGO_BASE_DIR+"/scientific_program/")
  919 + elif agent_name == "agentScheduler":
  920 + os.chdir(PYROS_DJANGO_BASE_DIR+"/scheduler/")
915 921 else:
916 922 os.chdir(PYROS_DJANGO_BASE_DIR+"/agent/")
  923 + '''
  924 + if agent_name in ["agentM", "agentSP", "agentScheduler"]:
  925 + os.chdir(PYROS_DJANGO_BASE_DIR + os.sep + agent_folder)
  926 +
917 927 # cmd = "-m AgentX"
918 928 # cmd = f" Agent{agent_name[5:]}.py {configfile}"
919 929 cmd = f"Agent{agent_name[5:]}.py"
... ...
src/core/pyros_django/agent/Agent.py
... ... @@ -138,7 +138,8 @@ from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig
138 138 ##from src.logpyros import LogPyros
139 139  
140 140 from device_controller.abstract_component.device_controller import (
141   - DCCNotFoundException, UnknownGenericCmdException, UnimplementedGenericCmdException, UnknownNativeCmdException
  141 + DCCNotFoundException, UnknownGenericCmdException,
  142 + UnimplementedGenericCmdException, UnknownNativeCmdException
142 143 )
143 144  
144 145  
... ... @@ -465,7 +466,7 @@ class Agent:
465 466 log.debug("Agent survey is" + str(self._agent_survey))
466 467 #self.printd("Agent survey is", self._agent_survey)
467 468  
468   - ("end Agent init")
  469 + ("end Agent __init__")
469 470  
470 471  
471 472 #def __init__(self, name:str="Agent", config_filename:str=None, RUN_IN_THREAD=True):
... ... @@ -922,7 +923,7 @@ class Agent:
922 923 # Purge commands (every N iterations, delete old commands)
923 924 N=5
924 925 if ((self._iter_num-1) % N) == 0:
925   - log.info("Purging old commands if exists")
  926 + log.info("Purging expired commands if exists")
926 927 #AgentCmd.purge_old_commands_for_agent(self.name)
927 928 self._purge_old_commands_sent_to_me()
928 929  
... ...
src/core/pyros_django/scheduler/AgentScheduler.py 0 โ†’ 100755
... ... @@ -0,0 +1,126 @@
  1 +#!/usr/bin/env python3
  2 +
  3 +import sys
  4 +##import utils.Logger as L
  5 +#import threading #, multiprocessing, os
  6 +import time
  7 +
  8 +#from django.db import transaction
  9 +#from common.models import Command
  10 +
  11 +sys.path.append("..")
  12 +sys.path.append("../../../..")
  13 +from src.core.pyros_django.agent.Agent import Agent, build_agent, log
  14 +
  15 +# PM 20190416 recycle code
  16 +from common.models import *
  17 +
  18 +##log = L.setupLogger("AgentXTaskLogger", "AgentX")
  19 +
  20 +
  21 +
  22 +class AgentScheduler(Agent):
  23 +
  24 +
  25 + # FOR TEST ONLY
  26 + # Run this agent in simulator mode
  27 + TEST_MODE = False
  28 + # Run the assertion tests at the end
  29 + TEST_WITH_FINAL_TEST = True
  30 + TEST_MAX_DURATION_SEC = None
  31 + #TEST_MAX_DURATION_SEC = 120
  32 +
  33 + # PM 20190416 fucking config path starting: /home/patrick/Dev/PYROS/start_agent.py agentM
  34 + ##_path_data = 'config'
  35 + _path_data = 'config/old_config'
  36 +
  37 + log.debug("PLC instanciated")
  38 +
  39 +
  40 +
  41 + '''
  42 + # Who should I send commands to ?
  43 + #TEST_COMMANDS_DEST = "myself"
  44 + TEST_COMMANDS_DEST = "AgentA"
  45 + # Scenario to be executed
  46 + TEST_COMMANDS_LIST = [
  47 + "go_active",
  48 + "go_idle",
  49 + "go_active",
  50 + "go_idle",
  51 + "go_active",
  52 + "go_idle",
  53 + "exit",
  54 + ]
  55 + '''
  56 +
  57 + """
  58 + =================================================================
  59 + FUNCTIONS RUN INSIDE MAIN THREAD
  60 + =================================================================
  61 + """
  62 + # old config
  63 + # @override
  64 + #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True):
  65 + # def __init__(self, config_filename=None, RUN_IN_THREAD=True):
  66 + # ##if name is None: name = self.__class__.__name__
  67 + # super().__init__(config_filename, RUN_IN_THREAD)
  68 +
  69 + # new config (obsconfig)
  70 + def __init__(self, name:str=None, RUN_IN_THREAD=True):
  71 + if name is None:
  72 + name = self.__class__.__name__
  73 + super().__init__(RUN_IN_THREAD)
  74 + # @override
  75 + def init(self):
  76 + super().init()
  77 + log.debug("end init()")
  78 + # --- Set the mode according the startmode value
  79 + ##agent_alias = self.__class__.__name__
  80 + ##self.set_mode_from_config(agent_alias)
  81 +
  82 + '''
  83 + # @override
  84 + def load_config(self):
  85 + super().load_config()
  86 + '''
  87 +
  88 + '''
  89 + # @override
  90 + def update_survey(self):
  91 + super().update_survey()
  92 + '''
  93 +
  94 + '''
  95 + # @override
  96 + def get_next_command(self):
  97 + return super().get_next_command()
  98 + '''
  99 +
  100 + # @override
  101 + def do_log(self):
  102 + super().do_log()
  103 +
  104 + def replan_sequences(self):
  105 + print("start of sequences (re-)planning...")
  106 + time.sleep(5)
  107 + print("...end of sequences (re-)planning")
  108 +
  109 + # Note : called by _routine_process() in Agent
  110 + # @override
  111 + def routine_process_body(self):
  112 + log.debug("in routine_process_body()")
  113 + self.replan_sequences()
  114 +
  115 + '''
  116 + # @override
  117 + def exec_specific_cmd_end(self, cmd:Command, from_thread=True):
  118 + super().exec_specific_cmd_end(cmd, from_thread)
  119 + '''
  120 +
  121 +
  122 +if __name__ == "__main__":
  123 +
  124 + agent = build_agent(AgentScheduler)
  125 + print(agent)
  126 + agent.run()
... ...