From 6cd48351eae3d4f9fbf0ece299937b454b83092f Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Fri, 22 Apr 2022 10:29:36 +0200 Subject: [PATCH] AgentScheduler is born (just a very modest beginning) --- Dockerfile | 2 ++ privatedev/config/tnc/observatory_tnc.yml | 11 ++++++++++- pyros.py | 14 ++++++++++++-- src/core/pyros_django/agent/Agent.py | 7 ++++--- src/core/pyros_django/scheduler/AgentScheduler.py | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 6 deletions(-) create mode 100755 src/core/pyros_django/scheduler/AgentScheduler.py diff --git a/Dockerfile b/Dockerfile index 8c12d09..9722549 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ FROM ubuntu:20.04 #FROM ubuntu:latest #FROM ubuntu:21.10 # with python3.9 #FROM ubuntu:18.04 +# Pour eviter le warning : debconf: delaying package configuration, since apt-utils is not installed +ARG DEBIAN_FRONTEND=noninteractive # Which glibc version ? # ./SHELL diff --git a/privatedev/config/tnc/observatory_tnc.yml b/privatedev/config/tnc/observatory_tnc.yml index 2ee0e8f..7307ebd 100644 --- a/privatedev/config/tnc/observatory_tnc.yml +++ b/privatedev/config/tnc/observatory_tnc.yml @@ -138,7 +138,15 @@ OBSERVATORY: device: TAROT_meteo protocol: private/plugin/agent_devices/plc_protocol.py is_real: False - + + - AGENT_DEVICE: + name: AgentScheduler + computer: MainComputer + path: private/plugin/agent_devices + device: TAROT_meteo + protocol: private/plugin/agent_devices/plc_protocol.py + is_real: False + - AGENT_DEVICE: name: mount computer: MainComputer @@ -245,6 +253,7 @@ OBSERVATORY: computer: MainComputer path: ~ + TOPOLOGY: SECURITY: diff --git a/pyros.py b/pyros.py index 18a7617..97fc929 100755 --- a/pyros.py +++ b/pyros.py @@ -52,14 +52,17 @@ _previous_dir = None AGENTS = { # "agentX" : "agent", + #"agentM": "AgentM", + #"agentSP": "AgentSP", + "agentM": "monitoring", + "agentSP": "scientific_programs", + "agentScheduler": "scheduler", "agent": "Agent", "agent2": "Agent", "agentX": "AgentX", "agentA": "AgentA", "agentB": "AgentB", "agentC": "AgentC", - "agentM": "AgentM", - "agentSP": "AgentSP", # "agentDevice" : "AgentDevice", # "agentDeviceTelescopeGemini" : "AgentDeviceTelescopeGemini", "agentDeviceGemini": "AgentDeviceGemini", @@ -908,12 +911,19 @@ def start(agent: str, configfile: str, observatory: str, unit: str): elif agent_name.startswith("agent"): # Run agent without actual commands sent to devices (FOR_REAL=False) # agentX.run(FOR_REAL=True) + ''' if agent_name == "agentM": os.chdir(PYROS_DJANGO_BASE_DIR+"/monitoring/") elif agent_name == "agentSP": os.chdir(PYROS_DJANGO_BASE_DIR+"/scientific_program/") + elif agent_name == "agentScheduler": + os.chdir(PYROS_DJANGO_BASE_DIR+"/scheduler/") else: os.chdir(PYROS_DJANGO_BASE_DIR+"/agent/") + ''' + if agent_name in ["agentM", "agentSP", "agentScheduler"]: + os.chdir(PYROS_DJANGO_BASE_DIR + os.sep + agent_folder) + # cmd = "-m AgentX" # cmd = f" Agent{agent_name[5:]}.py {configfile}" cmd = f"Agent{agent_name[5:]}.py" diff --git a/src/core/pyros_django/agent/Agent.py b/src/core/pyros_django/agent/Agent.py index 4ec4dae..4b41281 100755 --- a/src/core/pyros_django/agent/Agent.py +++ b/src/core/pyros_django/agent/Agent.py @@ -138,7 +138,8 @@ from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig ##from src.logpyros import LogPyros from device_controller.abstract_component.device_controller import ( - DCCNotFoundException, UnknownGenericCmdException, UnimplementedGenericCmdException, UnknownNativeCmdException + DCCNotFoundException, UnknownGenericCmdException, + UnimplementedGenericCmdException, UnknownNativeCmdException ) @@ -465,7 +466,7 @@ class Agent: log.debug("Agent survey is" + str(self._agent_survey)) #self.printd("Agent survey is", self._agent_survey) - ("end Agent init") + ("end Agent __init__") #def __init__(self, name:str="Agent", config_filename:str=None, RUN_IN_THREAD=True): @@ -922,7 +923,7 @@ class Agent: # Purge commands (every N iterations, delete old commands) N=5 if ((self._iter_num-1) % N) == 0: - log.info("Purging old commands if exists") + log.info("Purging expired commands if exists") #AgentCmd.purge_old_commands_for_agent(self.name) self._purge_old_commands_sent_to_me() diff --git a/src/core/pyros_django/scheduler/AgentScheduler.py b/src/core/pyros_django/scheduler/AgentScheduler.py new file mode 100755 index 0000000..35196a8 --- /dev/null +++ b/src/core/pyros_django/scheduler/AgentScheduler.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +import sys +##import utils.Logger as L +#import threading #, multiprocessing, os +import time + +#from django.db import transaction +#from common.models import Command + +sys.path.append("..") +sys.path.append("../../../..") +from src.core.pyros_django.agent.Agent import Agent, build_agent, log + +# PM 20190416 recycle code +from common.models import * + +##log = L.setupLogger("AgentXTaskLogger", "AgentX") + + + +class AgentScheduler(Agent): + + + # FOR TEST ONLY + # Run this agent in simulator mode + TEST_MODE = False + # Run the assertion tests at the end + TEST_WITH_FINAL_TEST = True + TEST_MAX_DURATION_SEC = None + #TEST_MAX_DURATION_SEC = 120 + + # PM 20190416 fucking config path starting: /home/patrick/Dev/PYROS/start_agent.py agentM + ##_path_data = 'config' + _path_data = 'config/old_config' + + log.debug("PLC instanciated") + + + + ''' + # Who should I send commands to ? + #TEST_COMMANDS_DEST = "myself" + TEST_COMMANDS_DEST = "AgentA" + # Scenario to be executed + TEST_COMMANDS_LIST = [ + "go_active", + "go_idle", + "go_active", + "go_idle", + "go_active", + "go_idle", + "exit", + ] + ''' + + """ + ================================================================= + FUNCTIONS RUN INSIDE MAIN THREAD + ================================================================= + """ + # old config + # @override + #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True): + # def __init__(self, config_filename=None, RUN_IN_THREAD=True): + # ##if name is None: name = self.__class__.__name__ + # super().__init__(config_filename, RUN_IN_THREAD) + + # new config (obsconfig) + def __init__(self, name:str=None, RUN_IN_THREAD=True): + if name is None: + name = self.__class__.__name__ + super().__init__(RUN_IN_THREAD) + # @override + def init(self): + super().init() + log.debug("end init()") + # --- Set the mode according the startmode value + ##agent_alias = self.__class__.__name__ + ##self.set_mode_from_config(agent_alias) + + ''' + # @override + def load_config(self): + super().load_config() + ''' + + ''' + # @override + def update_survey(self): + super().update_survey() + ''' + + ''' + # @override + def get_next_command(self): + return super().get_next_command() + ''' + + # @override + def do_log(self): + super().do_log() + + def replan_sequences(self): + print("start of sequences (re-)planning...") + time.sleep(5) + print("...end of sequences (re-)planning") + + # Note : called by _routine_process() in Agent + # @override + def routine_process_body(self): + log.debug("in routine_process_body()") + self.replan_sequences() + + ''' + # @override + def exec_specific_cmd_end(self, cmd:Command, from_thread=True): + super().exec_specific_cmd_end(cmd, from_thread) + ''' + + +if __name__ == "__main__": + + agent = build_agent(AgentScheduler) + print(agent) + agent.run() -- libgit2 0.21.2