Browse Source

Add engine_cfg to watchdog

Watch changes to engine config via watchdog. When the file is
modified, watchdog picks it up, verifies if the current engine
is disabled, and if yes, take steps in stop_engine(), to stop
the engine. That function is currently empty, will be filled in
in future commits

Change-Id: If3e2e952009f2f8a610459645c4403c77581e717
Pranesh Pandurangan 4 years ago
parent
commit
b41ea8a81f
1 changed files with 15 additions and 2 deletions
  1. 15
    2
      entropy/engine.py

+ 15
- 2
entropy/engine.py View File

@@ -20,6 +20,7 @@ import datetime
20 20
 import logging
21 21
 import operator
22 22
 import os
23
+import tempfile
23 24
 
24 25
 from concurrent import futures as cf
25 26
 import croniter
@@ -40,6 +41,8 @@ class Engine(object):
40 41
         utils.reset_logger(logging.getLogger())
41 42
         Engine.set_logger(**cfg_data)
42 43
         # constants
44
+        # Well known file where all engines are stored.
45
+        self.engine_cfg = os.path.join(tempfile.gettempdir(), 'engines.cfg')
43 46
         # TODO(praneshp): Hardcode for now, could/should be cmdline input
44 47
         self.max_workers = 8
45 48
         self._engine_cfg_data = cfg_data
@@ -65,7 +68,8 @@ class Engine(object):
65 68
         self.futures = []
66 69
         self.run_queue = collections.deque()
67 70
         # Private variables
68
-        self._watchdog_event_fn = {self.repair_cfg: self.repair_modified}
71
+        self._watchdog_event_fn = {self.repair_cfg: self.repair_modified,
72
+                                   self.engine_cfg: self.engine_disabled}
69 73
         # Private variables to keep track of repair scripts.
70 74
         self._repairs = []
71 75
         self._known_routing_keys = set()
@@ -192,13 +196,22 @@ class Engine(object):
192 196
             LOG.exception("Could not run serializer for %s at %s",
193 197
                           self.name, current_time)
194 198
 
199
+    def engine_disabled(self):
200
+        engine_config = dict(utils.load_yaml(self.engine_cfg))[self.name]
201
+        if not engine_config['enabled']:
202
+            self.stop_engine()
203
+
204
+    def stop_engine(self):
205
+        pass
206
+
195 207
     def repair_modified(self):
196 208
         LOG.info('Repair configuration changed')
197 209
         self.futures.extend(self.start_react_scripts())
198 210
 
199 211
     def start_watchdog(self):
200 212
         LOG.debug('Watchdog mapping is: ', self._watchdog_event_fn)
201
-        dirs_to_watch = [utils.get_filename_and_path(self.repair_cfg)[0]]
213
+        dirs_to_watch = [utils.get_filename_and_path(x)[0] for x in
214
+                         self.engine_cfg, self.repair_cfg]
202 215
         return utils.watch_dir_for_change(dirs_to_watch,
203 216
                                           self._watchdog_event_fn)
204 217
 

Loading…
Cancel
Save