Commit 0afcefa94134bd474d497cfe171384ac20ce6629

Authored by Jeremy
1 parent 86dd6e43
Exists in master and in 1 other branch dev

Reworked simulator architecture

Showing 42 changed files with 73 additions and 58 deletions   Show diff stats
@@ -85,11 +85,11 @@ case "$1" in @@ -85,11 +85,11 @@ case "$1" in
85 cd - 85 cd -
86 ;; 86 ;;
87 "simulator") 87 "simulator")
88 - scripts/simulator_launch.sh 88 + ../simulators/scripts/simulator_launch.sh
89 # python manage.py test --pattern="testRoutine*.py" --keepdb 89 # python manage.py test --pattern="testRoutine*.py" --keepdb
90 ;; 90 ;;
91 "kill_simulation") 91 "kill_simulation")
92 - scripts/kill_simulation.sh 92 + ../simulators/scripts/kill_simulation.sh
93 ;; 93 ;;
94 "sim") 94 "sim")
95 celery worker -A pyros -Q simulator_q -n pyros@simulator -c 1 & 95 celery worker -A pyros -Q simulator_q -n pyros@simulator -c 1 &
src/simulator/__init__.py renamed to simulators/__init__.py
src/simulator/alertSimulator/ALERTsimulator.py renamed to simulators/alert/ALERTsimulator.py
src/simulator/alertSimulator/__init__.py renamed to simulators/alert/__init__.py
simulators/Camera.py renamed to simulators/camera/Camera.py
@@ -2,10 +2,16 @@ import socket @@ -2,10 +2,16 @@ import socket
2 from enum import Enum 2 from enum import Enum
3 import time 3 import time
4 import os 4 import os
  5 +import sys
5 from random import randint 6 from random import randint
6 -from Device import Device  
7 7
8 -IMAGES_FOLDER = '../src/misc/images' 8 +PACKAGE_PARENT = '..'
  9 +SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
  10 +sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
  11 +
  12 +from device.Device import Device
  13 +
  14 +IMAGES_FOLDER = '../../src/misc/images'
9 15
10 EXPOSURE_TIME = 5 16 EXPOSURE_TIME = 5
11 SHUTTER_TIME = 3 17 SHUTTER_TIME = 3
simulators/CameraNIR.py renamed to simulators/camera/CameraNIR.py
@@ -5,7 +5,7 @@ import os @@ -5,7 +5,7 @@ import os
5 from random import randint 5 from random import randint
6 from Camera import Camera 6 from Camera import Camera
7 7
8 -IMAGES_FOLDER = '../src/misc/images' 8 +IMAGES_FOLDER = '../../src/misc/images'
9 9
10 EXPOSURE_TIME = 5 10 EXPOSURE_TIME = 5
11 SHUTTER_TIME = 3 11 SHUTTER_TIME = 3
simulators/CameraVIS.py renamed to simulators/camera/CameraVIS.py
src/simulator/plcSimulator/__init__.py renamed to simulators/camera/__init__.py
simulators/grammar.json renamed to simulators/config/grammar.json
simulators/config/s1.json 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +{
  2 + "Request" : {"id" : 1, "time" : 4}
  3 +}
simulators/socket_config.ini renamed to simulators/config/socket_config.ini
simulators/Device.py renamed to simulators/device/Device.py
@@ -3,9 +3,9 @@ import socket @@ -3,9 +3,9 @@ import socket
3 import json 3 import json
4 from pydoc import locate 4 from pydoc import locate
5 5
6 -IMAGES_FOLDER = '../src/images'  
7 -CONFIG_FILE = "socket_config.ini"  
8 -GRAMMAR_FILE = "grammar.json" 6 +IMAGES_FOLDER = '../../src/images'
  7 +CONFIG_FILE = "../config/socket_config.ini"
  8 +GRAMMAR_FILE = "../config/grammar.json"
9 9
10 class Device(): 10 class Device():
11 """ 11 """
src/simulator/userSimulator/migrations/__init__.py renamed to simulators/device/__init__.py
src/misc/fixtures/simulation/simulation.json renamed to simulators/fixtures/simulation.json
src/misc/fixtures/simulation/simulation1.json renamed to simulators/fixtures/simulation1.json
src/misc/fixtures/simulation/simulation2.json renamed to simulators/fixtures/simulation2.json
simulators/kill_all.sh deleted
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -ps aux | grep "python Telescope.py" | awk '{print $2}' | xargs kill -9  
2 -ps aux | grep "python CameraVIS.py" | awk '{print $2}' | xargs kill -9  
3 -ps aux | grep "python CameraNIR.py" | awk '{print $2}' | xargs kill -9  
4 -ps aux | grep "python PLC.py" | awk '{print $2}' | xargs kill -9  
simulators/PLC.py renamed to simulators/plc/PLC.py
1 import socket 1 import socket
2 from enum import Enum 2 from enum import Enum
3 -from Device import Device 3 +import os
  4 +import sys
  5 +
  6 +PACKAGE_PARENT = '..'
  7 +SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
  8 +sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
  9 +
  10 +from device.Device import Device
4 11
5 class PLC(Device): 12 class PLC(Device):
6 13
src/simulator/plcSimulator/PLCsimulator.py renamed to simulators/plc/PLCsimulator.py
simulators/plc/__init__.py 0 → 100644
simulators/run_all.sh deleted
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
1 -SCRIPT_PATH=$0  
2 -SCRIPT_PATH=${SCRIPT_PATH%/*}  
3 -  
4 -./kill_all.sh  
5 -  
6 -source ../private/venv_py3_pyros/bin/activate  
7 -  
8 -python Telescope.py &  
9 -python CameraVIS.py &  
10 -python CameraNIR.py &  
11 -python PLC.py &  
12 -  
simulators/scripts/kill_all.sh 0 → 100755
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +ps aux | grep "python ../telescope/Telescope.py" | awk '{print $2}' | xargs kill -9
  2 +ps aux | grep "python ../camera/CameraVIS.py" | awk '{print $2}' | xargs kill -9
  3 +ps aux | grep "python ../camera/CameraNIR.py" | awk '{print $2}' | xargs kill -9
  4 +ps aux | grep "python ../plc/PLC.py" | awk '{print $2}' | xargs kill -9
src/scripts/kill_simulation.sh renamed to simulators/scripts/kill_simulation.sh
1 -SCRIPT_PATH=$0  
2 -SCRIPT_PATH=${SCRIPT_PATH%/*}  
3 -  
4 -cd $SCRIPT_PATH/..  
5 -  
6 #Reseting 1 #Reseting
7 sed -i -e "s/CELERY_TEST = True/CELERY_TEST = False/g" pyros/settings.py 2 sed -i -e "s/CELERY_TEST = True/CELERY_TEST = False/g" pyros/settings.py
8 -sed -i -e "s/.*SIMULATOR_VALUE = .*/SIMULATOR_VALUE = None/g" simulator/userSimulator/tasks.py 3 +sed -i -e "s/.*SIMULATOR_VALUE = .*/SIMULATOR_VALUE = None/g" userSimulator/tasks.py
9 4
10 #Kill web server 5 #Kill web server
11 fuser -k 8000/tcp 6 fuser -k 8000/tcp
simulators/scripts/run_all.sh 0 → 100755
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +SCRIPT_PATH=$0
  2 +SCRIPT_PATH=${SCRIPT_PATH%/*}
  3 +
  4 +./kill_all.sh
  5 +
  6 +cd ../../src/
  7 +
  8 +source ../private/venv_py3_pyros/bin/activate
  9 +
  10 +cd -
  11 +
  12 +python ../telescope/Telescope.py &
  13 +python ../camera/CameraVIS.py &
  14 +python ../camera/CameraNIR.py &
  15 +python ../plc/PLC.py &
src/scripts/simulator_launch.sh renamed to simulators/scripts/simulator_launch.sh
1 # setting 1 # setting
2 -SCRIPT_PATH=$0  
3 -SCRIPT_PATH=${SCRIPT_PATH%/*}  
4 2
5 -cd $SCRIPT_PATH/.. 3 +SIM_FIXTURES="../simulators/fixtures/"
  4 +SIM_PATH="../simulators/"
6 5
7 echo -n "Existing simulations : " 6 echo -n "Existing simulations : "
8 -ls misc/fixtures/simulation/ 7 +ls "$SIM_FIXTURES"
9 echo -n "Enter which simulation you want to launch : " 8 echo -n "Enter which simulation you want to launch : "
10 read -r line 9 read -r line
11 10
12 -if [ ! -f misc/fixtures/simulation/"$line" ]; then 11 +if [ ! -f "$SIM_FIXTURES"/"$line" ]; then
13 echo "This simulation doesn't exist" 12 echo "This simulation doesn't exist"
14 exit 13 exit
15 fi 14 fi
16 15
17 -sed -i -e "s/SIMULATOR_VALUE = None/SIMULATOR_VALUE = '$line'/g" simulator/userSimulator/tasks.py 16 +sed -i -e "s/SIMULATOR_VALUE = None/SIMULATOR_VALUE = '$line'/g" userSimulator/tasks.py
18 sed -i -e "s/CELERY_TEST = False/CELERY_TEST = True/g" pyros/settings.py 17 sed -i -e "s/CELERY_TEST = False/CELERY_TEST = True/g" pyros/settings.py
19 18
20 trap ctrl_c INT 19 trap ctrl_c INT
@@ -32,7 +31,7 @@ rm -f testdb.sqlite3 @@ -32,7 +31,7 @@ rm -f testdb.sqlite3
32 python manage.py migrate 31 python manage.py migrate
33 python manage.py loaddata misc/fixtures/initial_fixture.json 32 python manage.py loaddata misc/fixtures/initial_fixture.json
34 33
35 -python manage.py loaddata misc/fixtures/simulation/"$line" 34 +python manage.py loaddata "$SIM_FIXTURES"/"$line"
36 35
37 echo "----------------LAUNCHING WEB SERVER----------------" 36 echo "----------------LAUNCHING WEB SERVER----------------"
38 python manage.py runserver & 37 python manage.py runserver &
@@ -54,12 +53,12 @@ echo "" @@ -54,12 +53,12 @@ echo ""
54 read -n1 -r -p "Press any key to continue..." key 53 read -n1 -r -p "Press any key to continue..." key
55 54
56 #launch simulator workers 55 #launch simulator workers
57 -./scripts/start_simulator_worker.sh 2>&1 /dev/null 56 +./../simulators/scripts/start_simulator_worker.sh 2>&1 /dev/null
58 57
59 #launch simulators binaries 58 #launch simulators binaries
60 -python simulator/alertSimulator/ALERTsimulator.py "$line" & 59 +python "$SIM_PATH"/alert/ALERTsimulator.py "$line" &
61 ALERTPID=$! 60 ALERTPID=$!
62 -python simulator/plcSimulator/PLCsimulator.py "$line" & 61 +python "$SIM_PATH"/plc/PLCsimulator.py "$line" &
63 PLCPID=$! 62 PLCPID=$!
64 63
65 echo "" 64 echo ""
src/scripts/start_simulator_worker.sh renamed to simulators/scripts/start_simulator_worker.sh
1 # Kill and re-launch simulator workers 1 # Kill and re-launch simulator workers
2 2
3 -SCRIPT_PATH=$0  
4 -SCRIPT_PATH=${SCRIPT_PATH%/*}  
5 -  
6 -cd $SCRIPT_PATH/..  
7 -  
8 source ../private/venv_py3_pyros/bin/activate 3 source ../private/venv_py3_pyros/bin/activate
9 4
10 ./scripts/kill_celery_workers.sh 5 ./scripts/kill_celery_workers.sh
simulators/Telescope.py renamed to simulators/telescope/Telescope.py
1 import socket 1 import socket
2 from enum import Enum 2 from enum import Enum
3 import time 3 import time
4 -from Device import Device 4 +import os
  5 +import sys
  6 +
  7 +PACKAGE_PARENT = '..'
  8 +SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
  9 +sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
  10 +
  11 +from device.Device import Device
5 12
6 DOORS_TIME = 5 13 DOORS_TIME = 5
7 MOVE_TIME = 5 14 MOVE_TIME = 5
simulators/telescope/__init__.py 0 → 100644
src/devices/Device.py
@@ -4,8 +4,8 @@ import configparser @@ -4,8 +4,8 @@ import configparser
4 import json 4 import json
5 from pydoc import locate 5 from pydoc import locate
6 6
7 -CONFIG_FILE = "../simulators/socket_config.ini"  
8 -GRAMMAR_FILE = "../simulators/grammar.json" 7 +CONFIG_FILE = "../simulators/config/socket_config.ini"
  8 +GRAMMAR_FILE = "../simulators/config/grammar.json"
9 9
10 class DeviceController(): 10 class DeviceController():
11 ''' 11 '''
src/monitoring/tasks.py
@@ -20,9 +20,9 @@ class monitoring(Task): @@ -20,9 +20,9 @@ class monitoring(Task):
20 ''' 20 '''
21 Infinite task created at the program's start. 21 Infinite task created at the program's start.
22 It initilize all the external connections, and starts the alert_listener. 22 It initilize all the external connections, and starts the alert_listener.
23 - 23 +
24 This is the place to put the starting configurations. 24 This is the place to put the starting configurations.
25 - 25 +
26 Once the starting configurations are done, it becomes a loop that checks the PLC and instruments status. 26 Once the starting configurations are done, it becomes a loop that checks the PLC and instruments status.
27 It also handles the beginning and the end of the night, recalculating them at each end of night. 27 It also handles the beginning and the end of the night, recalculating them at each end of night.
28 ''' 28 '''
@@ -104,7 +104,7 @@ class monitoring(Task): @@ -104,7 +104,7 @@ class monitoring(Task):
104 Infinite loop for the different timers : 104 Infinite loop for the different timers :
105 - Every TIMER_CHECK seconds, check PLC and instruments status (+ analyse them and send them to the IC) 105 - Every TIMER_CHECK seconds, check PLC and instruments status (+ analyse them and send them to the IC)
106 - 2 minutes before the night start, make a scheduling 106 - 2 minutes before the night start, make a scheduling
107 - - At the end of the night, do calibration files and computes the next night limits + make a scheduling with the new schedule 107 + - At the end of the night, do calibration files and computes the next night limits + make a scheduling with the new schedule
108 ''' 108 '''
109 109
110 timer_status = TIMER_CHECK 110 timer_status = TIMER_CHECK
src/pyros/__init__.py
@@ -9,11 +9,11 @@ from django.conf import settings @@ -9,11 +9,11 @@ from django.conf import settings
9 @worker_ready.connect 9 @worker_ready.connect
10 def start_permanent_tasks(signal, sender): 10 def start_permanent_tasks(signal, sender):
11 import monitoring.tasks 11 import monitoring.tasks
12 - import simulator.userSimulator.tasks 12 + import userSimulator.tasks
13 13
14 print(sender.hostname) 14 print(sender.hostname)
15 if sender.hostname == "pyros@simulator": 15 if sender.hostname == "pyros@simulator":
16 - simulator.userSimulator.tasks.simulator.delay() 16 + userSimulator.tasks.simulator.delay()
17 17
18 if sender.hostname == "pyros@monitoring": 18 if sender.hostname == "pyros@monitoring":
19 monitoring.tasks.monitoring.delay() 19 monitoring.tasks.monitoring.delay()
src/pyros/settings.py
@@ -242,7 +242,7 @@ CELERY_IMPORTS = ( @@ -242,7 +242,7 @@ CELERY_IMPORTS = (
242 "monitoring.tasks", 242 "monitoring.tasks",
243 "observation_manager.tasks", 243 "observation_manager.tasks",
244 "scheduler.tasks", 244 "scheduler.tasks",
245 - "simulator.userSimulator.tasks", 245 + "userSimulator.tasks",
246 ) 246 )
247 247
248 # This config allows only 1 process / queue. We replace it by the -c option at celery workers creation. 248 # This config allows only 1 process / queue. We replace it by the -c option at celery workers creation.
@@ -278,7 +278,7 @@ CELERY_ROUTES = { @@ -278,7 +278,7 @@ CELERY_ROUTES = {
278 "observation_manager.tasks.execute_plan_nir": {"queue": "execute_plan_nir_q"}, 278 "observation_manager.tasks.execute_plan_nir": {"queue": "execute_plan_nir_q"},
279 "observation_manager.tasks.create_calibrations": {"queue": "create_calibrations_q"}, 279 "observation_manager.tasks.create_calibrations": {"queue": "create_calibrations_q"},
280 "scheduler.tasks.scheduling": {"queue": "scheduling_q"}, 280 "scheduler.tasks.scheduling": {"queue": "scheduling_q"},
281 - "simulator.userSimulator.tasks.simulator": {"queue": "simulator_q"}, 281 + "userSimulator.tasks.simulator": {"queue": "simulator_q"},
282 } 282 }
283 283
284 ''' Removes pickle warning ''' 284 ''' Removes pickle warning '''
src/scripts/celery_test.sh
@@ -37,7 +37,7 @@ python manage.py migrate @@ -37,7 +37,7 @@ python manage.py migrate
37 python manage.py loaddata misc/fixtures/initial_fixture.json 37 python manage.py loaddata misc/fixtures/initial_fixture.json
38 38
39 # Starts the simulators 39 # Starts the simulators
40 -cd ../simulators 2>&1 /dev/null 40 +cd ../simulators/scripts 2>&1 /dev/null
41 ./run_all.sh 41 ./run_all.sh
42 cd - 42 cd -
43 43
@@ -59,6 +59,6 @@ cd scripts/ @@ -59,6 +59,6 @@ cd scripts/
59 ./kill_celery_workers.sh 59 ./kill_celery_workers.sh
60 60
61 # Stops simulators 61 # Stops simulators
62 -cd ../../simulators 62 +cd ../../simulators/scripts/
63 ./kill_all.sh 63 ./kill_all.sh
64 cd - 64 cd -
src/simulator/userSimulator/__init__.py renamed to src/userSimulator/__init__.py
src/simulator/userSimulator/admin.py renamed to src/userSimulator/admin.py
src/simulator/userSimulator/apps.py renamed to src/userSimulator/apps.py
src/userSimulator/migrations/__init__.py 0 → 100644
src/simulator/userSimulator/models.py renamed to src/userSimulator/models.py
src/simulator/userSimulator/tasks.py renamed to src/userSimulator/tasks.py
src/simulator/userSimulator/tests.py renamed to src/userSimulator/tests.py
src/simulator/userSimulator/urls.py renamed to src/userSimulator/urls.py
src/simulator/userSimulator/views.py renamed to src/userSimulator/views.py